ethereum.rb 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.travis.yml +26 -0
  6. data/CODE_OF_CONDUCT.md +13 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE +22 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +183 -0
  11. data/Rakefile +11 -0
  12. data/bin/console +14 -0
  13. data/bin/install_parity +29 -0
  14. data/bin/setup +7 -0
  15. data/contracts/AccountingLib.sol +112 -0
  16. data/contracts/AuditorInterface.sol +4 -0
  17. data/contracts/AuditorRegistry.sol +14 -0
  18. data/contracts/CustodianInterface.sol +27 -0
  19. data/contracts/CustodianRegistry.sol +40 -0
  20. data/contracts/DigixConfiguration.sol +68 -0
  21. data/contracts/Directory.sol +67 -0
  22. data/contracts/DoublyLinked.sol +54 -0
  23. data/contracts/GenericInterface.sol +56 -0
  24. data/contracts/GenericRegistry.sol +15 -0
  25. data/contracts/Gold.sol +105 -0
  26. data/contracts/GoldRegistry.sol +82 -0
  27. data/contracts/GoldTokenLedger.sol +3 -0
  28. data/contracts/Interface.sol +27 -0
  29. data/contracts/Minter.sol +3 -0
  30. data/contracts/Recaster.sol +3 -0
  31. data/contracts/Testing.sol +59 -0
  32. data/contracts/VendorInterface.sol +82 -0
  33. data/contracts/VendorRegistry.sol +39 -0
  34. data/contracts/classic/Digixbot.sol +106 -0
  35. data/contracts/classic/DigixbotConfiguration.sol +62 -0
  36. data/contracts/classic/DigixbotEthereum.sol +86 -0
  37. data/contracts/classic/DigixbotUsers.sol +103 -0
  38. data/contracts/classic/Gold.sol +497 -0
  39. data/contracts/classic/GoldRegistry.sol +503 -0
  40. data/contracts/classic/GoldTokenLedger.sol +560 -0
  41. data/contracts/classic/GoldTokenMinter.sol +607 -0
  42. data/contracts/classic/ParticipantRegistry.sol +94 -0
  43. data/contracts/classic/QueueSample.sol +54 -0
  44. data/ethereum.gemspec +35 -0
  45. data/lib/ethereum.rb +24 -0
  46. data/lib/ethereum/client.rb +97 -0
  47. data/lib/ethereum/contract.rb +266 -0
  48. data/lib/ethereum/contract_event.rb +25 -0
  49. data/lib/ethereum/contract_initializer.rb +54 -0
  50. data/lib/ethereum/deployment.rb +49 -0
  51. data/lib/ethereum/formatter.rb +172 -0
  52. data/lib/ethereum/function.rb +20 -0
  53. data/lib/ethereum/function_input.rb +13 -0
  54. data/lib/ethereum/function_output.rb +14 -0
  55. data/lib/ethereum/http_client.rb +38 -0
  56. data/lib/ethereum/initializer.rb +27 -0
  57. data/lib/ethereum/ipc_client.rb +46 -0
  58. data/lib/ethereum/project_initializer.rb +28 -0
  59. data/lib/ethereum/railtie.rb +10 -0
  60. data/lib/ethereum/singleton.rb +39 -0
  61. data/lib/ethereum/solidity.rb +47 -0
  62. data/lib/ethereum/transaction.rb +36 -0
  63. data/lib/ethereum/version.rb +3 -0
  64. data/lib/tasks/ethereum_contract.rake +27 -0
  65. data/lib/tasks/ethereum_node.rake +51 -0
  66. data/lib/tasks/ethereum_test.rake +32 -0
  67. data/lib/tasks/ethereum_transaction.rake +24 -0
  68. metadata +198 -0
@@ -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
+