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,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
+ }
@@ -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
+ }
@@ -0,0 +1,82 @@
1
+ import "contracts/DigixConfiguration.sol";
2
+ import "contracts/GenericInterface.sol";
3
+ import "contracts/Gold.sol";
4
+
5
+ contract GoldRegistry is GenericInterface {
6
+
7
+ address config;
8
+
9
+ Directory.AddressBoolMap entries;
10
+ Directory.AddressAddressMap custodianPending;
11
+
12
+ struct Asset {
13
+ address vendor;
14
+ address custodian;
15
+ bytes32 vendorDoc;
16
+ bytes32 custodianDoc;
17
+ }
18
+
19
+ mapping (address => Directory.AddressBoolMap) vendorAssets;
20
+ mapping (address => Directory.AddressBoolMap) custodianAssets;
21
+ mapping (address => Asset) registeredAssets;
22
+
23
+ function GoldRegistry(address _conf) {
24
+ config = _conf;
25
+ }
26
+
27
+ event AddGold(address indexed gold, address indexed vendor);
28
+ event CustodianAssignment(address indexed gold, address indexed custodian, address indexed vendor);
29
+ event RemoveGold(address indexed gold, address indexed custodian);
30
+
31
+ function registerGold(address _gold, address _owner, bytes32 _doc) ifvendor {
32
+ if (!Directory.insert(entries, _gold)) throw;
33
+ if (!Directory.insert(vendorAssets[msg.sender], _gold)) throw;
34
+ Asset _asset = registeredAssets[_gold];
35
+ _asset.vendor = msg.sender;
36
+ _asset.vendorDoc = _doc;
37
+ Gold(_gold).register(_owner);
38
+ }
39
+
40
+ function isRegistered(address _gold) public returns (bool) {
41
+ return Directory.contains(entries, _gold);
42
+ }
43
+
44
+ function isVendorOf(address _gold, address _vndr) public returns (bool) {
45
+ return Directory.contains(vendorAssets[_vndr], _gold);
46
+ }
47
+
48
+ function isCustodianOf(address _gold, address _cstdn) public returns (bool) {
49
+ return Directory.contains(custodianAssets[_cstdn], _gold);
50
+ }
51
+
52
+ function delegateCustodian(address _gold, address _cstdn) ifvendor {
53
+ if (isVendorOf(_gold, msg.sender)) {
54
+ if (!Directory.insert(custodianPending, _gold, _cstdn)) throw;
55
+ CustodianAssignment(_gold, _cstdn, msg.sender);
56
+ }
57
+ }
58
+
59
+ function receiveFromVendor(address _gold, bytes32 _doc) ifcustodian {
60
+ if (Directory.containsAndMatches(custodianPending, _gold, msg.sender)) {
61
+ if (!Directory.remove(custodianPending, _gold)) throw;
62
+ if (!Directory.insert(custodianAssets[msg.sender], _gold)) throw;
63
+ Asset _asset = registeredAssets[_gold];
64
+ _asset.custodian = msg.sender;
65
+ _asset.custodianDoc = _doc;
66
+ Gold(_gold).activate();
67
+ }
68
+ }
69
+
70
+ function submitAudit(address _gold, bytes32 _doc, bool _passed) ifauditor {
71
+
72
+ }
73
+
74
+ function requestRedemption(address _gold) ifowner {
75
+
76
+ }
77
+
78
+ function markRedeemed(address _gold) ifcustodian {
79
+
80
+ }
81
+
82
+ }
@@ -0,0 +1,3 @@
1
+ contract GoldTokenLedger {
2
+
3
+ }
@@ -0,0 +1,27 @@
1
+ import "contracts/GenericInterface.sol";
2
+
3
+ contract Interface is GenericInterface {
4
+
5
+ address owner;
6
+
7
+ Directory.AddressBoolMap employees;
8
+
9
+ modifier ifowner { if(owner == msg.sender) _ }
10
+ modifier ifemployee { if(isEmployee(msg.sender)) _ }
11
+ modifier ifemployeeorigin { if(isEmployee(tx.origin)) _ }
12
+
13
+ function registerEmployee(address _acct) ifowner {
14
+ if (!Directory.insert(employees, _acct))
15
+ throw;
16
+ }
17
+
18
+ function unregisterEmployee(address _acct) ifowner {
19
+ if (!Directory.remove(employees, _acct))
20
+ throw;
21
+ }
22
+
23
+ function isEmployee(address _acct) public returns (bool) {
24
+ return Directory.contains(employees, _acct);
25
+ }
26
+
27
+ }
@@ -0,0 +1,3 @@
1
+ contract Minter {
2
+
3
+ }
@@ -0,0 +1,3 @@
1
+ contract Recaster {
2
+
3
+ }
@@ -0,0 +1,59 @@
1
+ import "contracts/AccountingLib.sol";
2
+
3
+ contract TestAccounting {
4
+ AccountingLib.Bank bank;
5
+ /*
6
+ * Account Management API
7
+ */
8
+ function getAccountBalance(address accountAddress) constant public returns (uint) {
9
+ return bank.accountBalances[accountAddress];
10
+ }
11
+
12
+ function deposit() public {
13
+ deposit(msg.sender);
14
+ }
15
+
16
+ function deposit(address accountAddress) public {
17
+ /*
18
+ * Public API for depositing funds in a specified account.
19
+ */
20
+ AccountingLib.deposit(bank, accountAddress, msg.value);
21
+ AccountingLib.Deposit(msg.sender, accountAddress, msg.value);
22
+ }
23
+
24
+ function addFunds(uint value) public {
25
+ addFunds(msg.sender, value);
26
+ }
27
+
28
+ function addFunds(address accountAddress, uint value) public {
29
+ AccountingLib.addFunds(bank, accountAddress, value);
30
+ }
31
+
32
+ function withdraw(uint value) public {
33
+ /*
34
+ * Public API for withdrawing funds.
35
+ */
36
+ if (AccountingLib.withdraw(bank, msg.sender, value)) {
37
+ AccountingLib.Withdrawal(msg.sender, value);
38
+ }
39
+ else {
40
+ AccountingLib.InsufficientFunds(msg.sender, value, bank.accountBalances[msg.sender]);
41
+ }
42
+ }
43
+
44
+ function deductFunds(uint value) public {
45
+ deductFunds(msg.sender, value);
46
+ }
47
+
48
+ function deductFunds(address accountAddress, uint value) public {
49
+ AccountingLib.deductFunds(bank, accountAddress, value);
50
+ }
51
+
52
+ function setAccountBalance(uint value) public {
53
+ setAccountBalance(msg.sender, value);
54
+ }
55
+
56
+ function setAccountBalance(address accountAddress, uint value) public {
57
+ bank.accountBalances[accountAddress] = value;
58
+ }
59
+ }
@@ -0,0 +1,82 @@
1
+ import "contracts/Interface.sol";
2
+ import "contracts/Gold.sol";
3
+ import "contracts/GoldRegistry.sol";
4
+ import "contracts/DoublyLinked.sol";
5
+
6
+ contract VendorInterface is Interface {
7
+
8
+ DoublyLinked.List openOrders;
9
+
10
+ enum OrderStatus { Open, Cancelled, Completed }
11
+
12
+ struct Order {
13
+ bytes32 sku;
14
+ address buyer;
15
+ uint status;
16
+ }
17
+
18
+ mapping (bytes32 => Order) orders;
19
+
20
+ function VendorInterface(address _config) {
21
+ owner = msg.sender;
22
+ config = _config;
23
+ }
24
+
25
+ function registerGold(address _asset, address _owner, bytes32 _doc) ifemployee {
26
+ GoldRegistry(goldRegistry()).registerGold(_asset, _owner, _doc);
27
+ }
28
+
29
+ function delegateCustodian(address _asset, address _cstdn) ifemployee {
30
+ GoldRegistry(goldRegistry()).delegateCustodian(_asset, _cstdn);
31
+ }
32
+
33
+ function append(bytes32 _data) {
34
+ DoublyLinked.append(openOrders, _data);
35
+ }
36
+
37
+ function createOrder(bytes32 _orderId, bytes32 _sku, address _buyer) {
38
+ Order _order = orders[_orderId];
39
+ _order.sku = _sku;
40
+ _order.buyer = _buyer;
41
+ _order.status = uint(OrderStatus.Open);
42
+ DoublyLinked.append(openOrders, _orderId);
43
+ }
44
+
45
+ function start() returns (uint80) {
46
+ return DoublyLinked.iterate_start(openOrders);
47
+ }
48
+
49
+ function getOrder(uint80 _idx) returns (bytes32 _orderId, bytes32 _sku, address _buyer) {
50
+ _orderId = DoublyLinked.iterate_get(openOrders, _idx);
51
+ _sku = orders[_orderId].sku;
52
+ _buyer = orders[_orderId].buyer;
53
+ }
54
+
55
+ function next(uint80 _idx) returns(uint80) {
56
+ return DoublyLinked.iterate_next(openOrders, _idx);
57
+ }
58
+
59
+ function valid(uint80 _idx) returns(bool) {
60
+ return DoublyLinked.iterate_valid(openOrders, _idx);
61
+ }
62
+
63
+ function prev(uint80 _idx) returns(uint80) {
64
+ return DoublyLinked.iterate_prev(openOrders, _idx);
65
+ }
66
+
67
+ function processOrder(bytes32 _orderId) returns (bool success) {
68
+ var it = DoublyLinked.iterate_start(openOrders);
69
+ while (DoublyLinked.iterate_valid(openOrders, it)) {
70
+ if (DoublyLinked.iterate_get(openOrders, it) == _orderId) {
71
+ DoublyLinked.remove(openOrders, it);
72
+ orders[_orderId].status = uint(OrderStatus.Completed);
73
+ return true;
74
+ }
75
+ it = DoublyLinked.iterate_next(openOrders, it);
76
+ }
77
+ return false;
78
+ }
79
+
80
+ }
81
+
82
+