ethereum.rb 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.travis.yml +26 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +183 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/install_parity +29 -0
- data/bin/setup +7 -0
- data/contracts/AccountingLib.sol +112 -0
- data/contracts/AuditorInterface.sol +4 -0
- data/contracts/AuditorRegistry.sol +14 -0
- data/contracts/CustodianInterface.sol +27 -0
- data/contracts/CustodianRegistry.sol +40 -0
- data/contracts/DigixConfiguration.sol +68 -0
- data/contracts/Directory.sol +67 -0
- data/contracts/DoublyLinked.sol +54 -0
- data/contracts/GenericInterface.sol +56 -0
- data/contracts/GenericRegistry.sol +15 -0
- data/contracts/Gold.sol +105 -0
- data/contracts/GoldRegistry.sol +82 -0
- data/contracts/GoldTokenLedger.sol +3 -0
- data/contracts/Interface.sol +27 -0
- data/contracts/Minter.sol +3 -0
- data/contracts/Recaster.sol +3 -0
- data/contracts/Testing.sol +59 -0
- data/contracts/VendorInterface.sol +82 -0
- data/contracts/VendorRegistry.sol +39 -0
- data/contracts/classic/Digixbot.sol +106 -0
- data/contracts/classic/DigixbotConfiguration.sol +62 -0
- data/contracts/classic/DigixbotEthereum.sol +86 -0
- data/contracts/classic/DigixbotUsers.sol +103 -0
- data/contracts/classic/Gold.sol +497 -0
- data/contracts/classic/GoldRegistry.sol +503 -0
- data/contracts/classic/GoldTokenLedger.sol +560 -0
- data/contracts/classic/GoldTokenMinter.sol +607 -0
- data/contracts/classic/ParticipantRegistry.sol +94 -0
- data/contracts/classic/QueueSample.sol +54 -0
- data/ethereum.gemspec +35 -0
- data/lib/ethereum.rb +24 -0
- data/lib/ethereum/client.rb +97 -0
- data/lib/ethereum/contract.rb +266 -0
- data/lib/ethereum/contract_event.rb +25 -0
- data/lib/ethereum/contract_initializer.rb +54 -0
- data/lib/ethereum/deployment.rb +49 -0
- data/lib/ethereum/formatter.rb +172 -0
- data/lib/ethereum/function.rb +20 -0
- data/lib/ethereum/function_input.rb +13 -0
- data/lib/ethereum/function_output.rb +14 -0
- data/lib/ethereum/http_client.rb +38 -0
- data/lib/ethereum/initializer.rb +27 -0
- data/lib/ethereum/ipc_client.rb +46 -0
- data/lib/ethereum/project_initializer.rb +28 -0
- data/lib/ethereum/railtie.rb +10 -0
- data/lib/ethereum/singleton.rb +39 -0
- data/lib/ethereum/solidity.rb +47 -0
- data/lib/ethereum/transaction.rb +36 -0
- data/lib/ethereum/version.rb +3 -0
- data/lib/tasks/ethereum_contract.rake +27 -0
- data/lib/tasks/ethereum_node.rake +51 -0
- data/lib/tasks/ethereum_test.rake +32 -0
- data/lib/tasks/ethereum_transaction.rake +24 -0
- metadata +198 -0
@@ -0,0 +1,607 @@
|
|
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
|
+
|
498
|
+
|
499
|
+
contract GoldTokenLedger {
|
500
|
+
|
501
|
+
mapping (address => uint256) balances;
|
502
|
+
|
503
|
+
address owner;
|
504
|
+
address minter;
|
505
|
+
|
506
|
+
modifier ifowner { if (msg.sender == owner) _ }
|
507
|
+
modifier ifminter { if (msg.sender == minter) _ }
|
508
|
+
|
509
|
+
event GoldTokenSendEvent(address indexed _sender, address indexed _recipient, uint _amount);
|
510
|
+
event GoldTokenMintEvent(address indexed _goldcontract, address indexed _recipient, uint _amount);
|
511
|
+
event SetMinterEvent(address indexed _minter, uint indexed _time);
|
512
|
+
|
513
|
+
|
514
|
+
function GoldTokenLedger() {
|
515
|
+
owner = msg.sender;
|
516
|
+
}
|
517
|
+
|
518
|
+
function setMinter(address maddr) ifowner {
|
519
|
+
minter = maddr;
|
520
|
+
SetMinterEvent(maddr, block.timestamp);
|
521
|
+
}
|
522
|
+
|
523
|
+
function getMinter() returns (address maddr) {
|
524
|
+
maddr = minter;
|
525
|
+
}
|
526
|
+
|
527
|
+
function getOwner() returns (address oaddr) {
|
528
|
+
oaddr = owner;
|
529
|
+
}
|
530
|
+
|
531
|
+
function setOwner() returns (address oaddr) {
|
532
|
+
oaddr = owner;
|
533
|
+
}
|
534
|
+
|
535
|
+
function getBalance(address user) returns (uint balance) {
|
536
|
+
return balances[user];
|
537
|
+
}
|
538
|
+
|
539
|
+
function sendToken(uint256 amount, address recipient) {
|
540
|
+
if (balances[msg.sender] >= amount) {
|
541
|
+
balances[msg.sender] -= amount;
|
542
|
+
balances[recipient] += amount;
|
543
|
+
GoldTokenSendEvent(msg.sender, recipient, amount);
|
544
|
+
}
|
545
|
+
}
|
546
|
+
|
547
|
+
function mint(uint256 amount, address recipient) ifminter {
|
548
|
+
balances[recipient] += amount;
|
549
|
+
GoldTokenMintEvent(msg.sender, recipient, amount);
|
550
|
+
}
|
551
|
+
|
552
|
+
}
|
553
|
+
|
554
|
+
|
555
|
+
contract GoldTokenMinter {
|
556
|
+
|
557
|
+
address owner;
|
558
|
+
address ledger;
|
559
|
+
uint basefeepermille;
|
560
|
+
|
561
|
+
modifier onlyowner { if (msg.sender == owner) _ }
|
562
|
+
|
563
|
+
event GoldMinterEvent(address indexed _g, address indexed _u, uint indexed _a);
|
564
|
+
|
565
|
+
function GoldTokenMinter() {
|
566
|
+
owner = msg.sender;
|
567
|
+
basefeepermille = 13;
|
568
|
+
}
|
569
|
+
|
570
|
+
function setConfig(address laddr, uint fee) onlyowner {
|
571
|
+
ledger = laddr;
|
572
|
+
basefeepermille = fee;
|
573
|
+
}
|
574
|
+
|
575
|
+
function getLedger() returns (address) {
|
576
|
+
return ledger;
|
577
|
+
}
|
578
|
+
|
579
|
+
function calculateAmount(address goldaddr) returns (uint amount) {
|
580
|
+
Gold usergold = Gold(goldaddr);
|
581
|
+
var goldweight = usergold.getGoldDataWeight();
|
582
|
+
var weightpm = goldweight * 1000;
|
583
|
+
var feepm = goldweight * basefeepermille;
|
584
|
+
var feecalcpm = weightpm - feepm;
|
585
|
+
var amountpm = feecalcpm / 10;
|
586
|
+
amount = uint(amountpm);
|
587
|
+
}
|
588
|
+
|
589
|
+
function mint(address goldaddr) {
|
590
|
+
GoldTokenLedger digixgoldledger = GoldTokenLedger(ledger);
|
591
|
+
address recipient = msg.sender;
|
592
|
+
uint amount = calculateAmount(goldaddr);
|
593
|
+
if (amount <= 0)
|
594
|
+
return;
|
595
|
+
else
|
596
|
+
digixgoldledger.mint(amount, recipient);
|
597
|
+
}
|
598
|
+
|
599
|
+
}
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
//#include [ParticipantRegistry]
|
604
|
+
//#include [GoldRegistry]
|
605
|
+
//#include [Gold]
|
606
|
+
//#include [GoldTokenLedger]
|
607
|
+
//#include [GoldTokenMinter]
|