/
50_replicator.sol
68 lines (55 loc) · 1.53 KB
/
50_replicator.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
66
67
68
contract ReplicatorB {
address creator;
uint blockCreatedOn;
function Replicator()
{
creator = msg.sender;
// next = new ReplicatorA(); // Replicator B can't instantiate A because it doesn't yet know about A
// At the time of this writing (Sept 2015), It's impossible to create cyclical relationships
// either with self-replicating contracts or A-B-A-B
blockCreatedOn = block.number;
}
function getBlockCreatedOn() constant returns (uint)
{
return blockCreatedOn;
}
/**********
Standard kill() function to recover funds
**********/
function kill()
{
if (msg.sender == creator)
{
suicide(creator); // kills this contract and sends remaining funds back to creator
}
}
}
contract ReplicatorA {
address creator;
address baddress;
uint blockCreatedOn;
function Replicator()
{
creator = msg.sender;
baddress = new ReplicatorB(); // This works just fine because A already knows about B
blockCreatedOn = block.number;
}
function getBAddress() constant returns (address)
{
return baddress;
}
function getBlockCreatedOn() constant returns (uint)
{
return blockCreatedOn;
}
/**********
Standard kill() function to recover funds
**********/
function kill()
{
if (msg.sender == creator)
{
suicide(creator); // kills this contract and sends remaining funds back to creator
}
}
}