-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy path21_self_deploy.sol
41 lines (34 loc) · 1001 Bytes
/
21_self_deploy.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
pragma tvm-solidity >= 0.72.0;
pragma AbiHeader expire;
// This sample shows how the contract can deploy another contract of the same type
contract SelfDeployer {
uint static m_value;
address static m_parent;
uint m_depth;
mapping(address => bool) m_chilred;
constructor(uint _depth) {
require(
(tvm.pubkey() != 0 && tvm.pubkey() == msg.pubkey()) ||
(msg.sender == m_parent)
);
tvm.accept();
m_depth = _depth;
}
modifier onlyOwner {
require(tvm.pubkey() != 0 && tvm.pubkey() == msg.pubkey());
tvm.accept();
_;
}
function deploy(uint _value) onlyOwner external returns (address addr) {
TvmCell code = tvm.code();
addr = new SelfDeployer{
value: 2 ever,
code: code,
varInit: {
m_value: _value,
m_parent: address(this)
}
}(m_depth + 1);
m_chilred[addr] = true;
}
}