-
Notifications
You must be signed in to change notification settings - Fork 27
/
Feed_Factory.sol
62 lines (49 loc) · 1.89 KB
/
Feed_Factory.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
pragma solidity ^0.5.0;
import "../modules/Factory.sol";
import "./Feed.sol";
contract Feed_Factory is Factory {
constructor(address instanceRegistry) public {
// deploy template contract
address templateContract = address(new Feed());
// set instance type
bytes4 instanceType = bytes4(keccak256(bytes('Post')));
// set initdataABI
string memory initdataABI = '(address,address,bytes)';
// initialize factory params
Factory._initialize(instanceRegistry, templateContract, instanceType, initdataABI);
}
event ExplicitInitData(address operator, address postRegistry, bytes feedStaticMetadata);
function create(bytes memory callData) public returns (address instance) {
// deploy instance
instance = Factory._create(callData);
}
function createEncoded(bytes memory initdata) public returns (address instance) {
// decode initdata
(
address operator,
address postRegistry,
bytes memory feedStaticMetadata
) = abi.decode(initdata, (address,address,bytes));
// call explicit create
instance = createExplicit(operator, postRegistry, feedStaticMetadata);
}
function createExplicit(
address operator,
address postRegistry,
bytes memory feedStaticMetadata
) public returns (address instance) {
// declare template in memory
Feed template;
// construct the data payload used when initializing the new contract.
bytes memory callData = abi.encodeWithSelector(
template.initialize.selector, // selector
operator,
postRegistry,
feedStaticMetadata
);
// deploy instance
instance = Factory._create(callData);
// emit event
emit ExplicitInitData(operator, postRegistry, feedStaticMetadata);
}
}