-
Notifications
You must be signed in to change notification settings - Fork 27
/
Post_Factory.sol
65 lines (52 loc) · 2.03 KB
/
Post_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
63
64
65
pragma solidity ^0.5.0;
import "../modules/Factory.sol";
import "./Post.sol";
contract Post_Factory is Factory {
constructor(address instanceRegistry) public {
// deploy template contract
address templateContract = address(new Post());
// set instance type
bytes4 instanceType = bytes4(keccak256(bytes('Post')));
// set initdataABI
string memory initdataABI = '(address,bytes,bytes,bytes)';
// initialize factory params
Factory._initialize(instanceRegistry, templateContract, instanceType, initdataABI);
}
event ExplicitInitData(address operator, bytes proofHash, bytes staticMetadata, bytes variableMetadata);
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,
bytes memory proofHash,
bytes memory staticMetadata,
bytes memory variableMetadata
) = abi.decode(initdata, (address,bytes,bytes,bytes));
// call explicit create
instance = createExplicit(operator, proofHash, staticMetadata, variableMetadata);
}
function createExplicit(
address operator,
bytes memory proofHash,
bytes memory staticMetadata,
bytes memory variableMetadata
) public returns (address instance) {
// declare template in memory
Post template;
// construct the data payload used when initializing the new contract.
bytes memory callData = abi.encodeWithSelector(
template.initialize.selector, // selector
operator,
proofHash,
staticMetadata,
variableMetadata
);
// deploy instance
instance = Factory._create(callData);
// emit event
emit ExplicitInitData(operator, proofHash, staticMetadata, variableMetadata);
}
}