-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactory.sol
50 lines (35 loc) · 1.18 KB
/
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
pragma solidity ^0.4.13;
// MyFactory with MyObject
contract MyObject {
address public owner;
modifier onlyOwner{
require(msg.sender == owner);
_;
}
function changeOwner(address _newOwner) onlyOwner {
owner = _newOwner;
}
string public name;
MyObject public parentObject;
MyFactory public objectsFactory;
function MyObject(address _objectsFactory, address _parentObject, string _name) {
objectsFactory = MyFactory(_objectsFactory);
parentObject = MyObject(_parentObject);
name = _name;
owner = msg.sender;
}
function createClone(string _cloneName) returns (address) {
MyObject cloneObject = objectsFactory.createClone(this, _cloneName);
cloneObject.changeOwner(msg.sender);
NewCloneObject(address(cloneObject));
return address(cloneObject);
}
event NewCloneObject(address indexed _cloneObject);
}
contract MyFactory {
function createClone(address _parentToken, string _tokenName) returns (MyObject) {
MyObject newObject = new MyObject(this, _parentToken, _tokenName);
newObject.changeOwner(msg.sender);
return newObject;
}
}