ethereum.rb 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,14 @@
|
|
1
|
+
contract AuditorRegistry {
|
2
|
+
|
3
|
+
address config;
|
4
|
+
Directory.AddressBoolMap auditors;
|
5
|
+
|
6
|
+
function CustodianRegistry(address _conf) {
|
7
|
+
config = _conf;
|
8
|
+
}
|
9
|
+
|
10
|
+
function isAuditor(address _audt) public returns (bool) {
|
11
|
+
return Directory.contains(auditors, _audt);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import "contracts/Interface.sol";
|
2
|
+
import "contracts/Gold.sol";
|
3
|
+
import "contracts/GoldRegistry.sol";
|
4
|
+
|
5
|
+
contract CustodianInterface is Interface {
|
6
|
+
|
7
|
+
function CustodianInterface(address _config) {
|
8
|
+
owner = msg.sender;
|
9
|
+
config = _config;
|
10
|
+
}
|
11
|
+
|
12
|
+
function receiveFromVendor(address _gold, bytes32 _doc) ifemployee {
|
13
|
+
GoldRegistry(goldRegistry()).receiveFromVendor(_gold, _doc);
|
14
|
+
}
|
15
|
+
|
16
|
+
function transferCustodian(address _gold, address _cstdn) ifemployee {
|
17
|
+
}
|
18
|
+
|
19
|
+
function isRedeemable(address _gold) public returns (bool) {
|
20
|
+
return true;
|
21
|
+
}
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import "contracts/Directory.sol";
|
2
|
+
import "contracts/GenericRegistry.sol";
|
3
|
+
|
4
|
+
contract CustodianRegistry is GenericRegistry {
|
5
|
+
|
6
|
+
Directory.AddressBoolMap custodians;
|
7
|
+
|
8
|
+
struct Custodian {
|
9
|
+
bytes32 name;
|
10
|
+
}
|
11
|
+
|
12
|
+
mapping (address => Custodian) custodianNames;
|
13
|
+
|
14
|
+
function CustodianRegistry(address _conf) {
|
15
|
+
config = _conf;
|
16
|
+
}
|
17
|
+
|
18
|
+
function register(address _acct) ifadmin {
|
19
|
+
if (!Directory.insert(custodians, _acct))
|
20
|
+
throw;
|
21
|
+
}
|
22
|
+
|
23
|
+
function unregister(address _acct) ifadmin {
|
24
|
+
if (!Directory.remove(custodians, _acct))
|
25
|
+
throw;
|
26
|
+
}
|
27
|
+
|
28
|
+
function setCustodianName(address _cstdn, bytes32 _name) ifadmin {
|
29
|
+
custodianNames[_cstdn].name = _name;
|
30
|
+
}
|
31
|
+
|
32
|
+
function getCustodianName(address _cstdn) public returns (bytes32) {
|
33
|
+
return custodianNames[_cstdn].name;
|
34
|
+
}
|
35
|
+
|
36
|
+
function isCustodian(address _cust) public returns (bool) {
|
37
|
+
return Directory.contains(custodians, _cust);
|
38
|
+
}
|
39
|
+
|
40
|
+
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
contract DigixConfiguration {
|
2
|
+
|
3
|
+
address owner;
|
4
|
+
Directory.AddressBoolMap admins;
|
5
|
+
|
6
|
+
mapping (bytes32 => address) configaddr;
|
7
|
+
mapping (bytes32 => uint256) configint;
|
8
|
+
|
9
|
+
event SetOwner(address indexed owner, address indexed by);
|
10
|
+
event AddConfigEntryA(bytes32 indexed key, address indexed val, address indexed by);
|
11
|
+
event AddConfigEntryI(bytes32 indexed key, uint256 indexed val, address indexed by);
|
12
|
+
event RegisterAdmin(address indexed account, address indexed by);
|
13
|
+
event UnregisterAdmin(address indexed account, address indexed by);
|
14
|
+
|
15
|
+
function DigixConfiguration() {
|
16
|
+
owner = msg.sender;
|
17
|
+
}
|
18
|
+
|
19
|
+
modifier ifowner { if(msg.sender == owner) _ }
|
20
|
+
modifier ifadmin { if((msg.sender == owner) || isAdmin(msg.sender)) _ }
|
21
|
+
|
22
|
+
function getOwner() public constant returns (address) {
|
23
|
+
return owner;
|
24
|
+
}
|
25
|
+
|
26
|
+
function setOwner(address _newowner) ifowner {
|
27
|
+
address _oldaddress = owner;
|
28
|
+
owner = _newowner;
|
29
|
+
SetOwner(_newowner, msg.sender);
|
30
|
+
}
|
31
|
+
|
32
|
+
function addConfigEntryAddr(bytes32 _key, address _val) ifowner {
|
33
|
+
address _oldaddress = configaddr[_key];
|
34
|
+
configaddr[_key] = _val;
|
35
|
+
AddConfigEntryA(_key, _val, msg.sender);
|
36
|
+
}
|
37
|
+
|
38
|
+
function getConfigEntryAddr(bytes32 _key) public constant returns (address) {
|
39
|
+
return configaddr[_key];
|
40
|
+
}
|
41
|
+
|
42
|
+
function addConfigEntryInt(bytes32 _key, uint256 _val) ifowner {
|
43
|
+
uint256 _oldaddress = configint[_key];
|
44
|
+
configint[_key] = _val;
|
45
|
+
AddConfigEntryI(_key, _val, msg.sender);
|
46
|
+
}
|
47
|
+
|
48
|
+
function getConfigEntryInt(bytes32 _key) public constant returns (uint256) {
|
49
|
+
return configint[_key];
|
50
|
+
}
|
51
|
+
|
52
|
+
function registerAdmin(address _acct) ifowner {
|
53
|
+
if (!Directory.insert(admins, _acct))
|
54
|
+
throw;
|
55
|
+
RegisterAdmin(_acct, msg.sender);
|
56
|
+
}
|
57
|
+
|
58
|
+
function unregisterAdmin(address _acct) ifowner {
|
59
|
+
if (!Directory.remove(admins, _acct))
|
60
|
+
throw;
|
61
|
+
UnregisterAdmin(_acct, msg.sender);
|
62
|
+
}
|
63
|
+
|
64
|
+
function isAdmin(address _acct) public returns (bool) {
|
65
|
+
return Directory.contains(admins, _acct);
|
66
|
+
}
|
67
|
+
|
68
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
library Directory {
|
2
|
+
|
3
|
+
struct AddressBytesMap { mapping(address => bytes32) bytesentries; }
|
4
|
+
|
5
|
+
struct AddressAddressMap { mapping(address => address) addrentries; }
|
6
|
+
|
7
|
+
struct AddressBoolMap { mapping(address => bool) boolentries; }
|
8
|
+
|
9
|
+
function insert(AddressBytesMap storage self, address key, bytes32 val) returns (bool) {
|
10
|
+
if (self.bytesentries[key] == val) return false;
|
11
|
+
self.bytesentries[key] = val;
|
12
|
+
return true;
|
13
|
+
}
|
14
|
+
|
15
|
+
function insert(AddressBoolMap storage self, address key) returns (bool) {
|
16
|
+
if (self.boolentries[key]) return false;
|
17
|
+
self.boolentries[key] = true;
|
18
|
+
return true;
|
19
|
+
}
|
20
|
+
|
21
|
+
function insert(AddressAddressMap storage self, address key, address val) returns (bool) {
|
22
|
+
if (self.addrentries[key] == val) return false;
|
23
|
+
self.addrentries[key] = val;
|
24
|
+
return true;
|
25
|
+
}
|
26
|
+
|
27
|
+
function remove(AddressBytesMap storage self, address key) returns (bool) {
|
28
|
+
if (self.bytesentries[key] == 0x0) return false;
|
29
|
+
self.bytesentries[key] = 0x0;
|
30
|
+
return true;
|
31
|
+
}
|
32
|
+
|
33
|
+
function remove(AddressBoolMap storage self, address key) returns (bool) {
|
34
|
+
if (!self.boolentries[key]) return false;
|
35
|
+
self.boolentries[key] = false;
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
|
39
|
+
function remove(AddressAddressMap storage self, address key) returns (bool) {
|
40
|
+
if (self.addrentries[key] == 0x0000000000000000000000000000000000000000) return false;
|
41
|
+
self.addrentries[key] = 0x0000000000000000000000000000000000000000;
|
42
|
+
return true;
|
43
|
+
}
|
44
|
+
|
45
|
+
function contains(AddressBytesMap storage self, address key) returns (bool) {
|
46
|
+
if (self.bytesentries[key] != 0x0) return true;
|
47
|
+
}
|
48
|
+
|
49
|
+
function contains(AddressBoolMap storage self, address key) returns (bool) {
|
50
|
+
return self.boolentries[key];
|
51
|
+
}
|
52
|
+
|
53
|
+
function contains(AddressAddressMap storage self, address key) returns (bool) {
|
54
|
+
if (self.addrentries[key] != 0x0000000000000000000000000000000000000000) return true;
|
55
|
+
}
|
56
|
+
|
57
|
+
function containsAndMatches(AddressBytesMap storage self, address key, bytes32 val) returns (bool) {
|
58
|
+
return (self.bytesentries[key] == val);
|
59
|
+
}
|
60
|
+
|
61
|
+
function containsAndMatches(AddressAddressMap storage self, address key, address val) returns (bool) {
|
62
|
+
return (self.addrentries[key] == val);
|
63
|
+
}
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
library DoublyLinked {
|
2
|
+
|
3
|
+
struct List {
|
4
|
+
uint80 first;
|
5
|
+
uint80 last;
|
6
|
+
uint80 count;
|
7
|
+
Item[] items;
|
8
|
+
}
|
9
|
+
|
10
|
+
uint80 constant None = uint80(-1);
|
11
|
+
|
12
|
+
struct Item {
|
13
|
+
uint80 prev;
|
14
|
+
uint80 next;
|
15
|
+
bytes32 data;
|
16
|
+
}
|
17
|
+
|
18
|
+
function append(List storage self, bytes32 _data) {
|
19
|
+
var index = self.items.push(Item({prev: self.last, next: None, data: _data}));
|
20
|
+
if (self.last == None)
|
21
|
+
{
|
22
|
+
if (self.first != None || self.count != 0) throw;
|
23
|
+
self.first = self.last = uint80(index - 1);
|
24
|
+
self.count = 1;
|
25
|
+
}
|
26
|
+
else
|
27
|
+
{
|
28
|
+
self.items[self.last].next = uint80(index - 1);
|
29
|
+
self.last = uint80(index - 1);
|
30
|
+
self.count ++;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
function remove(List storage self, uint80 _index) {
|
35
|
+
Item item = self.items[_index];
|
36
|
+
if (item.prev == None)
|
37
|
+
self.first = item.next;
|
38
|
+
if (item.next == None)
|
39
|
+
self.last = item.prev;
|
40
|
+
if (item.prev != None)
|
41
|
+
self.items[item.prev].next = item.next;
|
42
|
+
if (item.next != None)
|
43
|
+
self.items[item.next].prev = item.prev;
|
44
|
+
delete self.items[_index];
|
45
|
+
self.count++;
|
46
|
+
}
|
47
|
+
|
48
|
+
// Iterator interface
|
49
|
+
function iterate_start(List storage self) returns (uint80) { return self.first; }
|
50
|
+
function iterate_valid(List storage self, uint80 _index) returns (bool) { return _index < self.items.length; }
|
51
|
+
function iterate_prev(List storage self, uint80 _index) returns (uint80) { return self.items[_index].prev; }
|
52
|
+
function iterate_next(List storage self, uint80 _index) returns (uint80) { return self.items[_index].next; }
|
53
|
+
function iterate_get(List storage self, uint80 _index) returns (bytes32) { return self.items[_index].data; }
|
54
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import "contracts/Directory.sol";
|
2
|
+
import "contracts/DoublyLinked.sol";
|
3
|
+
import "contracts/DigixConfiguration.sol";
|
4
|
+
import "contracts/VendorRegistry.sol";
|
5
|
+
import "contracts/CustodianRegistry.sol";
|
6
|
+
import "contracts/AuditorRegistry.sol";
|
7
|
+
|
8
|
+
contract GenericInterface {
|
9
|
+
|
10
|
+
address config;
|
11
|
+
address owner;
|
12
|
+
|
13
|
+
function getConfigAddress() public returns (address) {
|
14
|
+
return config;
|
15
|
+
}
|
16
|
+
|
17
|
+
function goldRegistry() public returns (address) {
|
18
|
+
return DigixConfiguration(config).getConfigEntryAddr("registry/gold");
|
19
|
+
}
|
20
|
+
|
21
|
+
function vendorRegistry() public returns (address) {
|
22
|
+
return DigixConfiguration(config).getConfigEntryAddr("registry/vendor");
|
23
|
+
}
|
24
|
+
|
25
|
+
function custodianRegistry() public returns (address) {
|
26
|
+
return DigixConfiguration(config).getConfigEntryAddr("registry/custodian");
|
27
|
+
}
|
28
|
+
|
29
|
+
function auditorRegistry() public returns (address) {
|
30
|
+
return DigixConfiguration(config).getConfigEntryAddr("registry/auditor");
|
31
|
+
}
|
32
|
+
|
33
|
+
function isGoldRegistry(address _greg) public returns (bool) {
|
34
|
+
return (goldRegistry() == _greg);
|
35
|
+
}
|
36
|
+
|
37
|
+
function isCustodian(address _cust) public returns (bool) {
|
38
|
+
return CustodianRegistry(custodianRegistry()).isCustodian(_cust);
|
39
|
+
}
|
40
|
+
|
41
|
+
function isAuditor(address _adtr) public returns (bool) {
|
42
|
+
return AuditorRegistry(auditorRegistry()).isAuditor(_adtr);
|
43
|
+
}
|
44
|
+
|
45
|
+
function isVendor(address _vndr) public returns (bool) {
|
46
|
+
return VendorRegistry(vendorRegistry()).isVendor(_vndr);
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
modifier ifvendor { if(isVendor(msg.sender)) _ }
|
51
|
+
modifier ifowner { if(msg.sender == owner) _ }
|
52
|
+
modifier ifcustodian { if(isCustodian(msg.sender)) _ }
|
53
|
+
modifier ifauditor { if(isAuditor(msg.sender)) _ }
|
54
|
+
modifier ifgoldregistry { if(isGoldRegistry(msg.sender)) _ }
|
55
|
+
|
56
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
contract GenericRegistry {
|
2
|
+
|
3
|
+
address config;
|
4
|
+
|
5
|
+
function isAdmin(address _acct) public returns (bool) {
|
6
|
+
return DigixConfiguration(config).isAdmin(_acct);
|
7
|
+
}
|
8
|
+
|
9
|
+
function getConfigAddress() public returns (address) {
|
10
|
+
return config;
|
11
|
+
}
|
12
|
+
|
13
|
+
modifier ifadmin { if(isAdmin(msg.sender)) _ }
|
14
|
+
|
15
|
+
}
|
data/contracts/Gold.sol
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
import "contracts/GenericInterface.sol";
|
2
|
+
import "contracts/GoldRegistry.sol";
|
3
|
+
|
4
|
+
contract Gold is GenericInterface {
|
5
|
+
|
6
|
+
uint256 weight;
|
7
|
+
uint256 serial;
|
8
|
+
uint256 lastStoragePayment;
|
9
|
+
uint256 base;
|
10
|
+
uint256 auditCount;
|
11
|
+
bool registered;
|
12
|
+
bool active;
|
13
|
+
|
14
|
+
modifier ifowner { if(owner == msg.sender) _ }
|
15
|
+
modifier ifcansend { if(canSend()) _ }
|
16
|
+
modifier ifunregistered { if(registered == false) _ }
|
17
|
+
|
18
|
+
event GoldAuditReport(bool indexed passed, address indexed document, address indexed auditor);
|
19
|
+
|
20
|
+
function Gold(address _conf, uint256 _wt) {
|
21
|
+
base = 1000000000;
|
22
|
+
owner = msg.sender;
|
23
|
+
config = _conf;
|
24
|
+
auditCount = 0;
|
25
|
+
weight = base * _wt;
|
26
|
+
registered = false;
|
27
|
+
active = false;
|
28
|
+
lastStoragePayment = block.timestamp;
|
29
|
+
}
|
30
|
+
|
31
|
+
function register(address _owner) ifgoldregistry {
|
32
|
+
owner = _owner;
|
33
|
+
}
|
34
|
+
|
35
|
+
function activate() ifgoldregistry {
|
36
|
+
active = true;
|
37
|
+
}
|
38
|
+
|
39
|
+
function getCalculatedFees() public returns (uint256) {
|
40
|
+
uint256 _totalfee = 0;
|
41
|
+
uint256 _dayseconds = 60; // 86400 seconds buy for testing we set to one minute
|
42
|
+
uint256 _lp = lastStoragePayment;
|
43
|
+
uint256 _wt = weight;
|
44
|
+
uint256 _dailyRatePpb = getStorageRate();
|
45
|
+
uint256 _startRun = block.timestamp;
|
46
|
+
while ((_startRun - _lp) > _dayseconds) {
|
47
|
+
uint256 _calculatedFee = ((_wt * _dailyRatePpb) / base);
|
48
|
+
_wt -= _calculatedFee;
|
49
|
+
_totalfee += _calculatedFee;
|
50
|
+
_lp += _dayseconds;
|
51
|
+
}
|
52
|
+
return _totalfee;
|
53
|
+
}
|
54
|
+
|
55
|
+
function mint() ifowner ifcansend {
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
function transferOwner(address _recipient) ifowner ifcansend {
|
60
|
+
owner = _recipient;
|
61
|
+
}
|
62
|
+
|
63
|
+
function getOwner() public returns (address) {
|
64
|
+
return owner;
|
65
|
+
}
|
66
|
+
|
67
|
+
function getLastStoragePayDate() public returns (uint256) {
|
68
|
+
return lastStoragePayment;
|
69
|
+
}
|
70
|
+
|
71
|
+
function getStorageRate() public returns (uint256) {
|
72
|
+
return DigixConfiguration(config).getConfigEntryInt("rates/storage");
|
73
|
+
}
|
74
|
+
|
75
|
+
function getWeightMinusFees() public returns (uint256) {
|
76
|
+
return (weight - getCalculatedFees());
|
77
|
+
}
|
78
|
+
|
79
|
+
function hasFees() public returns (bool) {
|
80
|
+
return (getCalculatedFees() > 0);
|
81
|
+
}
|
82
|
+
|
83
|
+
function isActive() public returns (bool) {
|
84
|
+
return active;
|
85
|
+
}
|
86
|
+
|
87
|
+
function isYellow() public returns (bool) {
|
88
|
+
uint256 daylength = 60;
|
89
|
+
return ((block.timestamp - lastStoragePayment) > (daylength * 30));
|
90
|
+
}
|
91
|
+
|
92
|
+
function isRed() public returns (bool) {
|
93
|
+
uint256 daylength = 60;
|
94
|
+
return ((block.timestamp - lastStoragePayment) > (daylength * 90));
|
95
|
+
}
|
96
|
+
|
97
|
+
function canSend() public returns (bool) {
|
98
|
+
return (!isRed());
|
99
|
+
}
|
100
|
+
|
101
|
+
function getWeight() public returns (uint256) {
|
102
|
+
return weight;
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|