evm_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +26 -0
  3. data/.gitignore +13 -0
  4. data/.rspec +2 -0
  5. data/.ruby-gemset +1 -0
  6. data/.travis.yml +32 -0
  7. data/CODE_OF_CONDUCT.md +13 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE +22 -0
  10. data/LICENSE.txt +21 -0
  11. data/PREREQUISITES.md +75 -0
  12. data/README.md +665 -0
  13. data/Rakefile +11 -0
  14. data/bin/console +14 -0
  15. data/bin/install_parity +22 -0
  16. data/bin/setup +7 -0
  17. data/contracts/AccountingLib.sol +112 -0
  18. data/contracts/AuditorInterface.sol +4 -0
  19. data/contracts/AuditorRegistry.sol +14 -0
  20. data/contracts/CustodianInterface.sol +27 -0
  21. data/contracts/CustodianRegistry.sol +40 -0
  22. data/contracts/DigixConfiguration.sol +68 -0
  23. data/contracts/Directory.sol +67 -0
  24. data/contracts/DoublyLinked.sol +54 -0
  25. data/contracts/GenericInterface.sol +56 -0
  26. data/contracts/GenericRegistry.sol +15 -0
  27. data/contracts/Gold.sol +105 -0
  28. data/contracts/GoldRegistry.sol +82 -0
  29. data/contracts/GoldTokenLedger.sol +3 -0
  30. data/contracts/Interface.sol +27 -0
  31. data/contracts/Minter.sol +3 -0
  32. data/contracts/Recaster.sol +3 -0
  33. data/contracts/Testing.sol +59 -0
  34. data/contracts/VendorInterface.sol +82 -0
  35. data/contracts/VendorRegistry.sol +39 -0
  36. data/contracts/classic/Digixbot.sol +106 -0
  37. data/contracts/classic/DigixbotConfiguration.sol +62 -0
  38. data/contracts/classic/DigixbotEthereum.sol +86 -0
  39. data/contracts/classic/DigixbotUsers.sol +103 -0
  40. data/contracts/classic/Gold.sol +497 -0
  41. data/contracts/classic/GoldRegistry.sol +503 -0
  42. data/contracts/classic/GoldTokenLedger.sol +560 -0
  43. data/contracts/classic/GoldTokenMinter.sol +607 -0
  44. data/contracts/classic/ParticipantRegistry.sol +94 -0
  45. data/contracts/classic/QueueSample.sol +54 -0
  46. data/evm_client.gemspec +36 -0
  47. data/lib/evm_client.rb +15 -0
  48. data/lib/evm_client/abi.rb +32 -0
  49. data/lib/evm_client/client.rb +146 -0
  50. data/lib/evm_client/contract.rb +341 -0
  51. data/lib/evm_client/contract_event.rb +32 -0
  52. data/lib/evm_client/contract_initializer.rb +54 -0
  53. data/lib/evm_client/decoder.rb +99 -0
  54. data/lib/evm_client/deployment.rb +49 -0
  55. data/lib/evm_client/encoder.rb +118 -0
  56. data/lib/evm_client/event_log.rb +88 -0
  57. data/lib/evm_client/explorer_url_helper.rb +25 -0
  58. data/lib/evm_client/formatter.rb +146 -0
  59. data/lib/evm_client/function.rb +40 -0
  60. data/lib/evm_client/function_input.rb +14 -0
  61. data/lib/evm_client/function_output.rb +14 -0
  62. data/lib/evm_client/http_client.rb +44 -0
  63. data/lib/evm_client/initializer.rb +27 -0
  64. data/lib/evm_client/ipc_client.rb +57 -0
  65. data/lib/evm_client/project_initializer.rb +28 -0
  66. data/lib/evm_client/railtie.rb +12 -0
  67. data/lib/evm_client/singleton.rb +39 -0
  68. data/lib/evm_client/solidity.rb +40 -0
  69. data/lib/evm_client/transaction.rb +41 -0
  70. data/lib/evm_client/version.rb +3 -0
  71. data/lib/tasks/ethereum_contract.rake +27 -0
  72. data/lib/tasks/ethereum_node.rake +52 -0
  73. data/lib/tasks/ethereum_test.rake +32 -0
  74. data/lib/tasks/ethereum_transaction.rake +24 -0
  75. metadata +219 -0
@@ -0,0 +1,39 @@
1
+ import "contracts/GenericRegistry.sol";
2
+
3
+ contract VendorRegistry is GenericRegistry {
4
+
5
+ Directory.AddressBoolMap vendors;
6
+
7
+ struct Vendor {
8
+ bytes32 name;
9
+ }
10
+
11
+ mapping (address => Vendor) vendorNames;
12
+
13
+ function VendorRegistry(address _conf) {
14
+ config = _conf;
15
+ }
16
+
17
+ function register(address _acct) ifadmin {
18
+ if (!Directory.insert(vendors, _acct))
19
+ throw;
20
+ }
21
+
22
+ function unregister(address _acct) ifadmin {
23
+ if (!Directory.remove(vendors, _acct))
24
+ throw;
25
+ }
26
+
27
+ function isVendor(address _acct) public returns (bool) {
28
+ return Directory.contains(vendors, _acct);
29
+ }
30
+
31
+ function setVendorName(address _vendor, bytes32 _name) ifadmin {
32
+ vendorNames[_vendor].name = _name;
33
+ }
34
+
35
+ function getVendorName(address _vendor) public returns (bytes32) {
36
+ return vendorNames[_vendor].name;
37
+ }
38
+
39
+ }
@@ -0,0 +1,106 @@
1
+ import "contracts/DigixbotUsers.sol";
2
+ import "contracts/DigixbotConfiguration.sol";
3
+
4
+ contract Coin {
5
+ function getBotContract() returns(address );
6
+ function getUserId(address _address) returns(bytes32 );
7
+ function withdrawCoin(bytes32 _user,uint256 _amount);
8
+ function depositCoin(bytes32 _uid,uint256 _amt);
9
+ function getBalance(bytes32 _uid) returns(uint256 );
10
+ function totalBalance() returns(uint256 );
11
+ function getConfig() returns(address );
12
+ function getUsersContract() returns(address );
13
+ function sendCoin(bytes32 _sender,bytes32 _recipient,uint256 _amt);
14
+ }
15
+
16
+ contract Digixbot {
17
+ address owner;
18
+ address config;
19
+
20
+ function Digixbot(address _config) {
21
+ owner = msg.sender;
22
+ config = _config;
23
+ }
24
+
25
+ modifier ifowner { if(msg.sender == owner) _ }
26
+
27
+ function getConfig() public returns (address) {
28
+ return config;
29
+ }
30
+
31
+ function addUser(bytes32 _userid) ifowner {
32
+ DigixbotUsers(getUsersContract()).addUser(_userid);
33
+ }
34
+
35
+ function setUserAccount(bytes32 _userid, address _account) ifowner {
36
+ bool _acctlock = accountLockCheck(_userid);
37
+ if (_acctlock == false) {
38
+ DigixbotUsers(getUsersContract()).setUserAccount(_userid, _account);
39
+ }
40
+ }
41
+
42
+ function getUserAccount(bytes32 _userid) public returns (address) {
43
+ return DigixbotUsers(getUsersContract()).getUserAccount(_userid);
44
+ }
45
+
46
+ function getUsersContract() public returns (address) {
47
+ return DigixbotConfiguration(config).getUsersContract();
48
+ }
49
+
50
+ function getCoinWallet(bytes4 _coin) public returns(address) {
51
+ return DigixbotConfiguration(config).getCoinWallet(_coin);
52
+ }
53
+
54
+ function userCheck(bytes32 _id) public returns(bool) {
55
+ return DigixbotUsers(getUsersContract()).userCheck(_id);
56
+ }
57
+
58
+ function sendCoin(bytes4 _coin, bytes32 _from, bytes32 _to, uint _amount) ifowner {
59
+ bool _tiplock = tipLockCheck(_from);
60
+ if (_tiplock == false) {
61
+ Coin(getCoinWallet(_coin)).sendCoin(_from, _to, _amount);
62
+ }
63
+ }
64
+
65
+ function withdrawCoin(bytes4 _coin, bytes32 _userid, uint _amount) ifowner {
66
+ Coin(getCoinWallet(_coin)).withdrawCoin(_userid, _amount);
67
+ }
68
+
69
+ function getCoinBalance(bytes4 _coin, bytes32 _userid) public returns(uint) {
70
+ return Coin(getCoinWallet(_coin)).getBalance(_userid);
71
+ }
72
+
73
+ function getTotalBalance(bytes4 _coin) public returns(uint) {
74
+ return Coin(getCoinWallet(_coin)).totalBalance();
75
+ }
76
+
77
+ function accountLockCheck(bytes32 _id) public returns (bool) {
78
+ return DigixbotUsers(getUsersContract()).accountLockCheck(_id);
79
+ }
80
+
81
+ function tipLockCheck(bytes32 _id) public returns (bool) {
82
+ return DigixbotUsers(getUsersContract()).tipLockCheck(_id);
83
+ }
84
+
85
+ function lockAccount(bytes32 _id) ifowner {
86
+ DigixbotUsers(getUsersContract()).lockAccount(_id);
87
+ }
88
+
89
+ function lockTip(bytes32 _id) ifowner {
90
+ DigixbotUsers(getUsersContract()).lockTip(_id);
91
+ }
92
+
93
+ function unlockAccount() {
94
+ address _userscontract = getUsersContract();
95
+ bytes32 _userid = DigixbotUsers(_userscontract).getUserId(msg.sender);
96
+ DigixbotUsers(_userscontract).unlockAccount(_userid);
97
+ }
98
+
99
+ function unlockTip() {
100
+ address _userscontract = getUsersContract();
101
+ bytes32 _userid = DigixbotUsers(_userscontract).getUserId(msg.sender);
102
+ DigixbotUsers(_userscontract).unlockTip(_userid);
103
+ }
104
+
105
+
106
+ }
@@ -0,0 +1,62 @@
1
+ contract DigixbotConfiguration {
2
+
3
+ struct Coin {
4
+ bytes4 name;
5
+ address wallet;
6
+ bool locked;
7
+ }
8
+
9
+ address owner;
10
+ address botcontract;
11
+ address userscontract;
12
+ bool locked;
13
+
14
+ mapping(bytes4 => Coin) coins;
15
+
16
+ modifier ifowner { if (msg.sender == owner) _ }
17
+ modifier unlesslocked { if (locked == false) _ }
18
+
19
+ function DigixbotConfiguration() {
20
+ owner = msg.sender;
21
+ locked = false;
22
+ }
23
+
24
+ function getOwner() public constant returns (address) {
25
+ return owner;
26
+ }
27
+
28
+ function setBotContract(address _botcontract) ifowner unlesslocked {
29
+ botcontract = _botcontract;
30
+ }
31
+
32
+ function getBotContract() public returns (address) {
33
+ return botcontract;
34
+ }
35
+
36
+ function setUsersContract(address _userscontract) ifowner unlesslocked {
37
+ userscontract = _userscontract;
38
+ }
39
+
40
+ function getUsersContract() public returns (address) {
41
+ return userscontract;
42
+ }
43
+
44
+ function lockConfiguration() ifowner {
45
+ locked = true;
46
+ }
47
+
48
+ function addCoin(bytes4 _name, address _wallet) ifowner {
49
+ Coin _cta = coins[_name];
50
+ if (_cta.locked == false) {
51
+ _cta.name = _name;
52
+ _cta.wallet = _wallet;
53
+ _cta.locked = true;
54
+ }
55
+ }
56
+
57
+ function getCoinWallet(bytes4 _coin) public constant returns (address) {
58
+ return coins[_coin].wallet;
59
+ }
60
+
61
+ }
62
+
@@ -0,0 +1,86 @@
1
+ import "contracts/DigixbotConfiguration.sol";
2
+ import "contracts/DigixbotUsers.sol";
3
+
4
+ contract DigixbotEthereum {
5
+
6
+ address config;
7
+
8
+ mapping(bytes32 => uint) balances;
9
+
10
+ event UserIdLogger(bytes32 indexed _debug);
11
+
12
+ function DigixbotEthereum(address _config) {
13
+ config = _config;
14
+ }
15
+
16
+ function() {
17
+ bytes32 _userid = getUserId(msg.sender);
18
+ UserIdLogger(_userid);
19
+ balances[_userid] += msg.value;
20
+ }
21
+
22
+ function depositCoin(bytes32 _userid, uint _amount) ifbot {
23
+ balances[_userid] += _amount;
24
+ }
25
+
26
+ function getConfig() public returns (address) {
27
+ return config;
28
+ }
29
+
30
+ function getUsersContract() public returns (address) {
31
+ return DigixbotConfiguration(config).getUsersContract();
32
+ }
33
+
34
+ function getBotContract() public returns (address) {
35
+ return DigixbotConfiguration(config).getBotContract();
36
+ }
37
+
38
+ function getUserId(address _address) public returns (bytes32) {
39
+ return DigixbotUsers(getUsersContract()).getUserId(_address);
40
+ }
41
+
42
+ function getUserAccount(bytes32 _userid) public returns(address) {
43
+ return DigixbotUsers(getUsersContract()).getUserAccount(_userid);
44
+ }
45
+
46
+ modifier ifbot { if (msg.sender == getBotContract()) _ }
47
+ modifier ifusers { if (msg.sender == getUsersContract()) _ }
48
+
49
+ function sendCoin(bytes32 _sender, bytes32 _recipient, uint _amt) ifbot {
50
+ if (_amt >= 100000000000000000) {
51
+ if (balances[_sender] >= _amt) {
52
+ balances[_sender] -= _amt;
53
+ balances[_recipient] += _amt;
54
+ }
55
+ }
56
+ }
57
+
58
+ function withdrawCoin(bytes32 _user, uint _amount) ifbot {
59
+ address _requester = getUserAccount(_user);
60
+ if (_requester != 0x0000000000000000000000000000000000000000) {
61
+ if (_amount >= 1000000000000000000) {
62
+ if (balances[_user] >= _amount) {
63
+ balances[_user] -= _amount;
64
+ _requester.send(_amount);
65
+ }
66
+ }
67
+ }
68
+ }
69
+
70
+ function withdrawCoinExt(uint _amount) {
71
+ bytes32 _requester = getUserId(msg.sender);
72
+ if (balances[_requester] >= _amount) {
73
+ balances[_requester] -= _amount;
74
+ address(msg.sender).send(_amount);
75
+ }
76
+ }
77
+
78
+ function getBalance(bytes32 _uid) public returns (uint) {
79
+ return balances[_uid];
80
+ }
81
+
82
+ function totalBalance() public returns (uint) {
83
+ return this.balance;
84
+ }
85
+
86
+ }
@@ -0,0 +1,103 @@
1
+ contract DigixbotUsers {
2
+
3
+ struct User {
4
+ bytes32 id;
5
+ address account;
6
+ bool configured;
7
+ bool lockaccount;
8
+ bool locktip;
9
+ }
10
+
11
+ address owner;
12
+ address config;
13
+
14
+ mapping(bytes32 => User) users;
15
+ mapping(address => bytes32) ids;
16
+
17
+ event EventLog(uint indexed _eventType, bytes32 indexed _eventData);
18
+ enum EventTypes { AddUser, SetAccount }
19
+
20
+ function DigixbotUsers(address _config) {
21
+ owner = msg.sender;
22
+ config = _config;
23
+ }
24
+
25
+ function getOwner() public returns (address) {
26
+ return owner;
27
+ }
28
+
29
+ function getConfig() public returns (address) {
30
+ return config;
31
+ }
32
+
33
+ function getBotContract() public returns (address) {
34
+ return DigixbotConfiguration(config).getBotContract();
35
+ }
36
+
37
+ modifier ifowner { if (msg.sender == owner) _ }
38
+ modifier ifbot { if (msg.sender == getBotContract()) _ }
39
+
40
+ function addUser(bytes32 _id) ifbot {
41
+ users[_id].id = _id;
42
+ users[_id].configured = true;
43
+ users[_id].lockaccount = false;
44
+ users[_id].locktip = false;
45
+ EventLog(uint(EventTypes.AddUser), _id);
46
+ }
47
+
48
+ function userCheck(bytes32 _id) public returns (bool) {
49
+ return users[_id].configured;
50
+ }
51
+
52
+ function setUserAccount(bytes32 _id, address _account) ifbot {
53
+ bool _acctlock = accountLockCheck(_id);
54
+ if (_acctlock == false) {
55
+ users[_id].account = _account;
56
+ ids[_account] = _id;
57
+ EventLog(uint(EventTypes.SetAccount), _id);
58
+ }
59
+ }
60
+
61
+ function accountLockCheck(bytes32 _id) public returns (bool) {
62
+ return users[_id].lockaccount;
63
+ }
64
+
65
+ function lockAccount(bytes32 _id) ifbot {
66
+ if (userAddressCheck(_id) == true) {
67
+ users[_id].lockaccount = true;
68
+ }
69
+ }
70
+
71
+ function userAddressCheck(bytes32 _id) public returns (bool) {
72
+ address _user = getUserAccount(_id);
73
+ return _user != 0x0000000000000000000000000000000000000000;
74
+ }
75
+
76
+ function unlockAccount(bytes32 _id) ifbot {
77
+ users[_id].lockaccount = false;
78
+ }
79
+
80
+ function tipLockCheck(bytes32 _id) public returns (bool) {
81
+ return users[_id].locktip;
82
+ }
83
+
84
+ function lockTip(bytes32 _id) ifbot {
85
+ if (userAddressCheck(_id) == true) {
86
+ users[_id].locktip = true;
87
+ }
88
+ }
89
+
90
+ function unlockTip(bytes32 _id) ifbot {
91
+ users[_id].locktip = false;
92
+ }
93
+
94
+ function getUserId(address _account) public returns (bytes32) {
95
+ return ids[_account];
96
+ }
97
+
98
+ function getUserAccount(bytes32 _id) public returns (address) {
99
+ return users[_id].account;
100
+ }
101
+
102
+ }
103
+
@@ -0,0 +1,497 @@
1
+ contract ParticipantRegistry {
2
+
3
+ enum ParticipantTypes { Admin, Vendor, Custodian, Auditor }
4
+ struct ParticipantDatabase {
5
+ mapping (address => bool) auditors;
6
+ mapping (address => bool) vendors;
7
+ mapping (address => bool) custodians;
8
+ mapping (address => bool) registrars;
9
+ }
10
+
11
+ address owner;
12
+ ParticipantDatabase participantdb;
13
+
14
+ event AddParticipant(address indexed participant, uint indexed participanttype);
15
+ event RemoveParticipant(address indexed participant, uint indexed participanttype);
16
+
17
+ modifier ifowner { if (msg.sender == owner) _ }
18
+ modifier ifregistrar { if ((participantdb.registrars[tx.origin]) || (tx.origin == owner)) _ }
19
+ modifier onlyvendor { if (isVendor(tx.origin) == true) _ }
20
+ modifier onlycustodian { if (isCustodian(tx.origin) == true) _ }
21
+ modifier onlyauditor { if (isAuditor(tx.origin) == true) _ }
22
+
23
+ function ParticipantRegistry() {
24
+ owner = msg.sender;
25
+ }
26
+
27
+ function getOwner() returns (address oa) {
28
+ oa = owner;
29
+ }
30
+
31
+ function setOwner(address nown) ifowner {
32
+ owner = nown;
33
+ }
34
+
35
+ function registerAdmin(address regraddr) ifowner {
36
+ participantdb.registrars[regraddr] = true;
37
+ AddParticipant(regraddr, uint(ParticipantTypes.Admin));
38
+ }
39
+
40
+ function unregisterAdmin(address regraddr) ifowner {
41
+ participantdb.registrars[regraddr] = false;
42
+ RemoveParticipant(regraddr, uint(ParticipantTypes.Admin));
43
+ }
44
+
45
+ function registerVendor(address vendoraddress) ifregistrar {
46
+ participantdb.vendors[vendoraddress] = true;
47
+ AddParticipant(vendoraddress, uint(ParticipantTypes.Vendor));
48
+ }
49
+
50
+ function unregisterVendor(address vendoraddress) ifregistrar {
51
+ participantdb.vendors[vendoraddress] = false;
52
+ RemoveParticipant(vendoraddress, uint(ParticipantTypes.Vendor));
53
+ }
54
+
55
+ function registerCustodian(address custodianaddress) ifregistrar {
56
+ participantdb.custodians[custodianaddress] = true;
57
+ AddParticipant(custodianaddress, uint(ParticipantTypes.Custodian));
58
+ }
59
+
60
+ function unregisterCustodian(address custodianaddress) ifregistrar {
61
+ participantdb.custodians[custodianaddress] = false;
62
+ RemoveParticipant(custodianaddress, uint(ParticipantTypes.Custodian));
63
+ }
64
+
65
+ function registerAuditor(address auditoraddress) ifregistrar {
66
+ participantdb.auditors[auditoraddress] = true;
67
+ AddParticipant(auditoraddress, uint(ParticipantTypes.Auditor));
68
+ }
69
+
70
+ function unregisterAuditor(address auditoraddress) ifregistrar {
71
+ participantdb.auditors[auditoraddress] = false;
72
+ RemoveParticipant(auditoraddress, uint(ParticipantTypes.Auditor));
73
+ }
74
+
75
+ function isVendor(address vendoraddress) returns (bool) {
76
+ return participantdb.vendors[vendoraddress];
77
+ }
78
+
79
+ function isCustodian(address custodianaddress) returns (bool) {
80
+ return participantdb.custodians[custodianaddress];
81
+ }
82
+
83
+ function isAuditor(address auditoraddress) returns (bool) {
84
+ return participantdb.auditors[auditoraddress];
85
+ }
86
+
87
+ function isRegistrar(address regraddr) returns (bool) {
88
+ return participantdb.registrars[regraddr];
89
+ }
90
+ }
91
+
92
+ contract GoldRegistry {
93
+
94
+ address owner;
95
+ address participantregistry;
96
+
97
+ enum GoldStatusCodes { PendingVerification, Active, RedemptionQueue, Redeemed, Minted }
98
+
99
+ struct Audit {
100
+ uint id;
101
+ uint time;
102
+ bool pass;
103
+ address auditor;
104
+ bytes32 extradata;
105
+ bytes32 documentation;
106
+ }
107
+
108
+ struct GoldStatus {
109
+ uint code;
110
+ bool vendorverify;
111
+ bool custodianverify;
112
+ bool minted;
113
+ uint auditcount;
114
+ bool registered;
115
+ uint lastauditid;
116
+ Audit lastaudit;
117
+ mapping (uint => Audit) audits;
118
+ }
119
+
120
+ struct GoldInfo {
121
+ address vendor;
122
+ address custodian;
123
+ uint weight;
124
+ bytes32 serial;
125
+ bytes32 sku;
126
+ bytes32 documentation;
127
+ }
128
+
129
+ struct GoldData {
130
+ bool initialized;
131
+ bool minted;
132
+ uint weight;
133
+ bytes32 serial;
134
+ bytes32 sku;
135
+ bytes32 documentation;
136
+ }
137
+
138
+ struct RegistryData {
139
+ bool initialized;
140
+ bool registered;
141
+ address registry;
142
+ address vendor;
143
+ address custodian;
144
+ address minter;
145
+ }
146
+
147
+ mapping (address => GoldStatus) goldstatusdb;
148
+ mapping (address => GoldInfo) goldinfodb;
149
+
150
+ modifier ifowner { if (msg.sender == owner) _ }
151
+
152
+ event GoldPurchase(address indexed gold, address indexed buyer, uint weight);
153
+ event GoldRedemption(address indexed gold);
154
+ event VendorVerification(address indexed gold, address indexed vendor, uint indexed time);
155
+ event CustodianVerification(address indexed gold, address indexed custodian, uint indexed time);
156
+ event CustodianTransfer(address indexed gold, address indexed oldcustodian, address indexed newcustodian);
157
+ event AuditEvent(address indexed gold, address indexed auditor, uint indexed lastauditid);
158
+
159
+ function GoldRegistry() {
160
+ owner = msg.sender;
161
+ }
162
+
163
+ function setConfiguration(address pr) ifowner {
164
+ participantregistry = pr;
165
+ }
166
+
167
+ function getOwner() returns (address o) {
168
+ o = owner;
169
+ }
170
+
171
+ function setOwner(address nown) ifowner {
172
+ owner = nown;
173
+ }
174
+
175
+ function getParticipantRegistry() returns (address pr) {
176
+ pr = participantregistry;
177
+ }
178
+
179
+ function checkCustodian() returns (bool ccheck) {
180
+ ParticipantRegistry prg = ParticipantRegistry(participantregistry);
181
+ ccheck = prg.isCustodian(tx.origin);
182
+ }
183
+
184
+ function checkVendor() returns (bool vcheck) {
185
+ ParticipantRegistry prg = ParticipantRegistry(participantregistry);
186
+ vcheck = prg.isVendor(tx.origin);
187
+ }
188
+
189
+ function checkAuditor() returns (bool acheck) {
190
+ ParticipantRegistry prg = ParticipantRegistry(participantregistry);
191
+ acheck = prg.isAuditor(tx.origin);
192
+ }
193
+
194
+ function checkRegistrar() returns (bool rcheck) {
195
+ ParticipantRegistry prg = ParticipantRegistry(participantregistry);
196
+ rcheck = prg.isRegistrar(tx.origin);
197
+ }
198
+
199
+ modifier ifregistrar { if (checkRegistrar() == true) _ }
200
+ modifier ifvendor { if (checkVendor() == true) _ }
201
+ modifier ifcustodian { if (checkCustodian() == true) _ }
202
+ modifier ifauditor { if (checkAuditor() == true) _ }
203
+
204
+ function registerGold() ifregistrar {
205
+ GoldInfo gidb = goldinfodb[msg.sender];
206
+ GoldStatus gsdb = goldstatusdb[msg.sender];
207
+ Gold gld = Gold(msg.sender);
208
+ if (gsdb.registered == true) return;
209
+ gidb.vendor = gld.registryRequestVendor();
210
+ gidb.custodian = gld.registryRequestCustodian();
211
+ gidb.weight = gld.registryRequestWeight();
212
+ gidb.serial = gld.registryRequestSerialNumber();
213
+ gidb.sku = gld.registryRequestSku();
214
+ gidb.documentation = gld.registryRequestDocumentation();
215
+ gsdb.vendorverify = false;
216
+ gsdb.custodianverify = false;
217
+ gsdb.minted = false;
218
+ gsdb.registered = true;
219
+ }
220
+
221
+ function getGoldStatusCode(address gaddr) returns (uint gsc) {
222
+ GoldStatus gsdb = goldstatusdb[gaddr];
223
+ gsc = gsdb.code;
224
+ }
225
+
226
+ function getGoldStatusVendorverify(address gaddr) returns (bool gsvv) {
227
+ GoldStatus gsdb = goldstatusdb[gaddr];
228
+ gsvv = gsdb.vendorverify;
229
+ }
230
+
231
+ function getGoldStatusCustodianverify(address gaddr) returns (bool gscv) {
232
+ GoldStatus gsdb = goldstatusdb[gaddr];
233
+ gscv = gsdb.custodianverify;
234
+ }
235
+
236
+ function getGoldStatusMinted(address gaddr) returns (bool gsms) {
237
+ GoldStatus gsdb = goldstatusdb[gaddr];
238
+ gsms = gsdb.minted;
239
+ }
240
+
241
+ function getGoldStatusAuditcount(address gaddr) returns (uint gsac) {
242
+ GoldStatus gsdb = goldstatusdb[gaddr];
243
+ gsac = gsdb.auditcount;
244
+ }
245
+
246
+ function getGoldStatusRegistered(address gaddr) returns (bool gsrs) {
247
+ GoldStatus gsdb = goldstatusdb[gaddr];
248
+ gsrs = gsdb.registered;
249
+ }
250
+
251
+ function getGoldStatusLastauditid(address gaddr) returns (uint gsla) {
252
+ GoldStatus gsdb = goldstatusdb[gaddr];
253
+ gsla = gsdb.lastauditid;
254
+ }
255
+
256
+ function getGoldInfoVendor(address gaddr) returns (address giva) {
257
+ GoldInfo gidb = goldinfodb[gaddr];
258
+ giva = gidb.vendor;
259
+ }
260
+
261
+ function getGoldInfoCustodian(address gaddr) returns (address gica) {
262
+ GoldInfo gidb = goldinfodb[gaddr];
263
+ gica = gidb.custodian;
264
+ }
265
+
266
+ function getGoldInfoWeight(address gaddr) returns (uint giwt) {
267
+ GoldInfo gidb = goldinfodb[gaddr];
268
+ giwt = gidb.weight;
269
+ }
270
+
271
+ function getGoldInfoSerial(address gaddr) returns (bytes32 gisn) {
272
+ GoldInfo gidb = goldinfodb[gaddr];
273
+ gisn = gidb.serial;
274
+ }
275
+
276
+ function getGoldInfoSku(address gaddr) returns (bytes32 gisk) {
277
+ GoldInfo gidb = goldinfodb[gaddr];
278
+ gisk = gidb.sku;
279
+ }
280
+
281
+ function getGoldInfoDocumentation(address gaddr) returns (bytes32 gidc) {
282
+ GoldInfo gidb = goldinfodb[gaddr];
283
+ gidc = gidb.documentation;
284
+ }
285
+
286
+ function getLastAuditId(address gaddr) returns (uint ai) {
287
+ GoldStatus gsdb = goldstatusdb[gaddr];
288
+ Audit laud = gsdb.lastaudit;
289
+ ai = laud.id;
290
+ }
291
+
292
+ function getLastAuditTime(address gaddr) returns (uint at) {
293
+ GoldStatus gsdb = goldstatusdb[gaddr];
294
+ Audit laud = gsdb.lastaudit;
295
+ at = laud.time;
296
+ }
297
+
298
+ function getLastAuditPass(address gaddr) returns (bool ap) {
299
+ GoldStatus gsdb = goldstatusdb[gaddr];
300
+ Audit laud = gsdb.lastaudit;
301
+ ap = laud.pass;
302
+ }
303
+
304
+ function getLastAuditAuditor(address gaddr) returns (address aa) {
305
+ GoldStatus gsdb = goldstatusdb[gaddr];
306
+ Audit laud = gsdb.lastaudit;
307
+ aa = laud.auditor;
308
+ }
309
+
310
+ function getLastAuditExtradata(address gaddr) returns (bytes32 ae) {
311
+ GoldStatus gsdb = goldstatusdb[gaddr];
312
+ Audit laud = gsdb.lastaudit;
313
+ ae = laud.extradata;
314
+ }
315
+
316
+ function getLastAuditDocumentation(address gaddr) returns (bytes32 ad) {
317
+ GoldStatus gsdb = goldstatusdb[gaddr];
318
+ Audit laud = gsdb.lastaudit;
319
+ ad = laud.documentation;
320
+ }
321
+
322
+ function custodianVerify(address gaddr) ifcustodian {
323
+ GoldStatus gsdb = goldstatusdb[gaddr];
324
+ gsdb.custodianverify = true;
325
+ CustodianVerification(gaddr, tx.origin, block.timestamp);
326
+ }
327
+
328
+ function vendorVerify(address gaddr) ifvendor {
329
+ GoldStatus gsdb = goldstatusdb[gaddr];
330
+ gsdb.vendorverify = true;
331
+ VendorVerification(gaddr, tx.origin, block.timestamp);
332
+ }
333
+
334
+ function custodianTransfer(address gaddr, address ncaddr) ifcustodian {
335
+ GoldInfo gidb = goldinfodb[gaddr];
336
+ GoldStatus gsdb = goldstatusdb[gaddr];
337
+ gidb.custodian = ncaddr;
338
+ gsdb.custodianverify = false;
339
+ CustodianTransfer(gaddr, tx.origin, ncaddr);
340
+ }
341
+
342
+ function auditReport(address gaddr, bool ares, bytes32 ed, bytes32 doc) ifauditor {
343
+ GoldInfo gidb = goldinfodb[gaddr];
344
+ GoldStatus gsdb = goldstatusdb[gaddr];
345
+ gsdb.auditcount++;
346
+ uint auditcount = gsdb.auditcount;
347
+ Audit adt = gsdb.audits[auditcount];
348
+ gsdb.lastaudit = Audit({id: auditcount, time: block.timestamp, pass: ares, auditor: tx.origin, extradata: ed, documentation: doc});
349
+ adt = gsdb.lastaudit;
350
+ AuditEvent(gaddr, tx.origin, auditcount);
351
+ }
352
+
353
+ }
354
+
355
+ contract Gold {
356
+
357
+ struct GoldData {
358
+ bool initialized;
359
+ bool minted;
360
+ uint weight;
361
+ bytes32 serial;
362
+ bytes32 sku;
363
+ bytes32 documentation;
364
+ }
365
+
366
+ struct RegistryData {
367
+ bool initialized;
368
+ bool registered;
369
+ address registry;
370
+ address vendor;
371
+ address custodian;
372
+ address minter;
373
+ }
374
+
375
+ address owner;
376
+ GoldData golddata;
377
+ RegistryData registrydata;
378
+
379
+ event SendGoldEvent(address indexed gold, address indexed recipient);
380
+
381
+ modifier ifowner { if (msg.sender == owner) _ }
382
+
383
+ function Gold() {
384
+ owner = msg.sender;
385
+ golddata.minted = false;
386
+ golddata.initialized = false;
387
+ registrydata.initialized = false;
388
+ }
389
+
390
+ function getOwner() returns (address oaddr) {
391
+ oaddr = owner;
392
+ }
393
+
394
+ function initGoldData(uint wt, bytes32 sn, bytes32 sk, bytes32 doc) ifowner {
395
+ if (golddata.initialized == true) return;
396
+ golddata = GoldData({initialized: true, minted: false, weight: wt, serial: sn, sku: sk, documentation: doc});
397
+ }
398
+
399
+ function initRegistryData(address raddr, address vaddr, address caddr) ifowner {
400
+ if (registrydata.initialized == true) return;
401
+ registrydata = RegistryData({initialized: true, registered: false, registry: raddr, vendor: vaddr, custodian: caddr, minter: address(this)});
402
+ GoldRegistry goldregistry = GoldRegistry(raddr);
403
+ }
404
+
405
+ function sendRegistration() {
406
+ if ((registrydata.initialized == true) && (golddata.initialized == true)) {
407
+ GoldRegistry gr = goldRegistry();
408
+ gr.registerGold();
409
+ registrydata.registered = true;
410
+ }
411
+ }
412
+
413
+ function registryRequestCustodian() public returns (address caddr) {
414
+ caddr = registrydata.custodian;
415
+ }
416
+
417
+ function registryRequestVendor() public returns (address vaddr) {
418
+ vaddr = registrydata.vendor;
419
+ }
420
+
421
+ function registryRequestWeight() public returns (uint wt) {
422
+ wt = golddata.weight;
423
+ }
424
+
425
+ function registryRequestSerialNumber() public returns (bytes32 sn) {
426
+ sn = golddata.serial;
427
+ }
428
+
429
+ function registryRequestSku() public returns (bytes32 sk) {
430
+ sk = golddata.sku;
431
+ }
432
+
433
+ function registryRequestDocumentation() public returns (bytes32 doc) {
434
+ doc = golddata.documentation;
435
+ }
436
+
437
+ function getGoldDataInitialized() returns (bool gdis) {
438
+ gdis = golddata.initialized;
439
+ }
440
+
441
+ function getGoldDataMinted() returns (bool gdms) {
442
+ gdms = golddata.minted;
443
+ }
444
+
445
+ function getGoldDataWeight() returns (uint gdwt) {
446
+ gdwt = golddata.weight;
447
+ }
448
+
449
+ function getGoldDataSerial() returns (bytes32 gdsn) {
450
+ gdsn = golddata.serial;
451
+ }
452
+
453
+ function getGoldDataSku() returns (bytes32 gdsk) {
454
+ gdsk = golddata.sku;
455
+ }
456
+
457
+ function getGoldDataDocumentation() returns (bytes32 gddc) {
458
+ gddc = golddata.documentation;
459
+ }
460
+
461
+ function getRegistryDataInitialized() returns (bool rdis) {
462
+ rdis = registrydata.initialized;
463
+ }
464
+
465
+ function getRegistryDataRegistered() returns (bool rdrs) {
466
+ rdrs = registrydata.registered;
467
+ }
468
+
469
+ function getRegistryDataRegistry() returns (address rdrg) {
470
+ rdrg = registrydata.registry;
471
+ }
472
+
473
+ function getRegistryDataVendor() returns (address rdva) {
474
+ rdva = registrydata.vendor;
475
+ }
476
+
477
+ function getRegistryDataCustodian() returns (address rdca) {
478
+ rdca = registrydata.custodian;
479
+ }
480
+
481
+ function getRegistryDataMinter() returns (address rdma) {
482
+ rdma = registrydata.minter;
483
+ }
484
+
485
+ function sendToMinter(uint minttype) ifowner {
486
+ owner = registrydata.minter;
487
+ golddata.minted = true;
488
+ // Notifiy minter contract
489
+ }
490
+
491
+ function goldRegistry() returns (GoldRegistry gr) {
492
+ gr = GoldRegistry(registrydata.registry);
493
+ }
494
+
495
+
496
+ }
497
+