ethereumex 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) 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 +6 -0
  6. data/CODE_OF_CONDUCT.md +13 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE +45 -0
  9. data/LICENSE.txt +44 -0
  10. data/README.md +138 -0
  11. data/Rakefile +6 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +7 -0
  14. data/contracts/AccountingLib.sol +112 -0
  15. data/contracts/AuditorInterface.sol +4 -0
  16. data/contracts/AuditorRegistry.sol +14 -0
  17. data/contracts/CustodianInterface.sol +27 -0
  18. data/contracts/CustodianRegistry.sol +40 -0
  19. data/contracts/DigixConfiguration.sol +68 -0
  20. data/contracts/Directory.sol +67 -0
  21. data/contracts/DoublyLinked.sol +54 -0
  22. data/contracts/GenericInterface.sol +56 -0
  23. data/contracts/GenericRegistry.sol +15 -0
  24. data/contracts/Gold.sol +105 -0
  25. data/contracts/GoldRegistry.sol +82 -0
  26. data/contracts/GoldTokenLedger.sol +3 -0
  27. data/contracts/Interface.sol +27 -0
  28. data/contracts/Minter.sol +3 -0
  29. data/contracts/Recaster.sol +3 -0
  30. data/contracts/Testing.sol +59 -0
  31. data/contracts/VendorInterface.sol +82 -0
  32. data/contracts/VendorRegistry.sol +39 -0
  33. data/contracts/classic/Digixbot.sol +106 -0
  34. data/contracts/classic/DigixbotConfiguration.sol +62 -0
  35. data/contracts/classic/DigixbotEthereum.sol +86 -0
  36. data/contracts/classic/DigixbotUsers.sol +103 -0
  37. data/contracts/classic/Gold.sol +497 -0
  38. data/contracts/classic/GoldRegistry.sol +503 -0
  39. data/contracts/classic/GoldTokenLedger.sol +560 -0
  40. data/contracts/classic/GoldTokenMinter.sol +607 -0
  41. data/contracts/classic/ParticipantRegistry.sol +94 -0
  42. data/contracts/classic/QueueSample.sol +54 -0
  43. data/ethereumex.gemspec +35 -0
  44. data/lib/ethereumex.rb +21 -0
  45. data/lib/ethereumex/client.rb +68 -0
  46. data/lib/ethereumex/contract.rb +223 -0
  47. data/lib/ethereumex/contract_event.rb +24 -0
  48. data/lib/ethereumex/contract_initializer.rb +54 -0
  49. data/lib/ethereumex/deployment.rb +45 -0
  50. data/lib/ethereumex/formatter.rb +164 -0
  51. data/lib/ethereumex/function.rb +20 -0
  52. data/lib/ethereumex/function_input.rb +13 -0
  53. data/lib/ethereumex/function_output.rb +14 -0
  54. data/lib/ethereumex/http_client.rb +35 -0
  55. data/lib/ethereumex/initializer.rb +27 -0
  56. data/lib/ethereumex/ipc_client.rb +35 -0
  57. data/lib/ethereumex/project_initializer.rb +28 -0
  58. data/lib/ethereumex/transaction.rb +30 -0
  59. data/lib/ethereumex/version.rb +3 -0
  60. metadata +188 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ae2372da989b09a15234526d760b6ab825e924f
4
+ data.tar.gz: 1abaed4f1635fe315da207c5f12278998d75dcab
5
+ SHA512:
6
+ metadata.gz: 6f4a75d1aecdb525e9c1793699e2db424333f4d88a6c5de29f5004972ba693542fd0cb21a9051e35c4f9955ce05adb823f0bcb213b1160b1e7eaaae7c14e50f8
7
+ data.tar.gz: aff950a304b7c42c7077340933e53d9d5e65d3046806a4ad56b1c9f6b15121b2abed39fe39966782d7d7bbbe5a2007622e378f9db14472a4c66a8b3a47ea0f91
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.*.swp
11
+ /**/.*.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ rubythereum
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.10
4
+ - 2.2.1
5
+ - 2.2.3
6
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ethereumex.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,45 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 DigixGlobal Pte Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+
24
+ The MIT License (MIT)
25
+
26
+ Copyright (c) 2017 Shawn Cicoria
27
+
28
+ Permission is hereby granted, free of charge, to any person obtaining a copy
29
+ of this software and associated documentation files (the "Software"), to deal
30
+ in the Software without restriction, including without limitation the rights
31
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32
+ copies of the Software, and to permit persons to whom the Software is
33
+ furnished to do so, subject to the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be included in all
36
+ copies or substantial portions of the Software.
37
+
38
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44
+ SOFTWARE.
45
+
@@ -0,0 +1,44 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 DigixGlobal Pte Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+
24
+ The MIT License (MIT)
25
+
26
+ Copyright (c) 2017 Shawn Cicoria
27
+
28
+ Permission is hereby granted, free of charge, to any person obtaining a copy
29
+ of this software and associated documentation files (the "Software"), to deal
30
+ in the Software without restriction, including without limitation the rights
31
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32
+ copies of the Software, and to permit persons to whom the Software is
33
+ furnished to do so, subject to the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be included in
36
+ all copies or substantial portions of the Software.
37
+
38
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
44
+ THE SOFTWARE.
@@ -0,0 +1,138 @@
1
+ # Ethereum library for Ruby
2
+
3
+ A simple library for Ethereum.
4
+
5
+ ## Features
6
+
7
+ * Pure Ruby implementation
8
+ * IPC Client with batch calls support
9
+ * HTTP Client with batch calls support
10
+ * Compile and deploy Solidity contracts
11
+ * Deploy contracts with constructor parameters.
12
+ * Expose deployed contracts as Ruby classes
13
+ * Test solidity contracts with a Ruby testing framework of your choice
14
+ * Call and wait for the result of Solidity function calls.
15
+ * Contract events
16
+
17
+ ## Ruby Compatibility
18
+
19
+ * Ruby 2.x
20
+ * Ruby 1.9.x
21
+ * JRuby
22
+ * Rubinius
23
+
24
+ ## Requirements
25
+
26
+ We currently support UNIX/Linux environments and Windows IPC support on the roadmap.
27
+
28
+ You will need to have a properly working Ruby installation. We recommend [RVM](http://rvm.io/)
29
+
30
+ To use this library you will need to have a running Ethereum node with IPC support enabled (default). We currently support [Go-Ethereum client](https://github.com/ethereum/go-ethereum)
31
+
32
+ ## Installation
33
+
34
+ Add this line to your application's Gemfile:
35
+
36
+ ```ruby
37
+ gem 'ethereum'
38
+ ```
39
+
40
+ And then execute:
41
+
42
+ $ bundle
43
+
44
+ Or install it yourself as:
45
+
46
+ $ gem install ethereum
47
+
48
+ ## Basic Usage
49
+
50
+ ### IPC Client Connection
51
+
52
+ ```ruby
53
+ client = Ethereum::IpcClient.new("#{ENV['HOME']}/.ethereum_testnet/geth.ipc")
54
+ ```
55
+
56
+ ### Solidity contract compilation and deployment
57
+
58
+ ```ruby
59
+ init = Ethereum::Initializer.new("#{ENV['PWD']}/spec/fixtures/SimpleNameRegistry.sol", client)
60
+ init.build_all
61
+ simple_name_registry_instance = SimpleNameRegistry.new
62
+ simple_name_registry_instance.deploy_and_wait(60)
63
+ ```
64
+
65
+ ### Transacting and Calling Solidity Functions
66
+
67
+ Solidity functions are exposed using the following conventions:
68
+
69
+ ```
70
+ transact_[function_name](params)
71
+ transact_and_wait_[function_name](params)
72
+ call_[function_name](params)
73
+ ```
74
+
75
+ **Example Contract in Solidity**
76
+ ```
77
+ contract SimpleNameRegistry {
78
+
79
+ mapping (address => bool) public myMapping;
80
+
81
+ function register(address _a, bytes32 _b) {
82
+ }
83
+
84
+ function getSomeValue(address _x) public constant returns(bool b, address b) {
85
+ }
86
+
87
+ }
88
+ ```
89
+
90
+ ```ruby
91
+ simple_name_registry_instance.transact_and_wait_register("0x5b6cb65d40b0e27fab87a2180abcab22174a2d45", "minter.contract.dgx")
92
+ simple_name_registry_instance.transact_register("0x385acafdb80b71ae001f1dbd0d65e62ec2fff055", "anthony@eufemio.dgx")
93
+ simple_name_registry_instance.call_get_some_value("0x385acafdb80b71ae001f1dbd0d65e62ec2fff055")
94
+ simple_name_registry_instance.call_my_mapping("0x385acafdb80b71ae001f1dbd0d65e62ec2fff055")
95
+ ```
96
+
97
+ ### Run contracts using a different address
98
+
99
+ ```ruby
100
+ simple_name_registry_instance.as("0x0c0d99d3608a2d1d38bb1b28025e970d3910b1e1")
101
+ ```
102
+
103
+ ### Point contract instance to a previously deployed contract
104
+
105
+ ```ruby
106
+ simple_name_registry_instance.at("0x734533083b5fc0cd14b7cb8c8eb6ed0c9bd184d3")
107
+ ```
108
+
109
+ ## Roadmap
110
+
111
+ * Add Windows IPC Client (named pipes)
112
+ * Add support for creating and sending of raw transactions
113
+ * Offline account creation
114
+ * ContractTransaction class
115
+ * Add more examples
116
+ * API documentation
117
+ * Unit testing and contract testing examples. Use [web3.js](https://github.com/ethereum/web3.js) tests as a baseline.
118
+
119
+ ## Support
120
+
121
+ Please join our Gitter chat room or open a new issue in this repository
122
+
123
+ [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/DigixGlobal/ethereum-ruby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
124
+
125
+ ## Development
126
+
127
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
128
+
129
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
130
+
131
+ ## Contributing
132
+
133
+ Bug reports and pull requests are welcome on GitHub at https://github.com/DigixGlobal/ethereum-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
134
+
135
+ ## License
136
+
137
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
138
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ethereumex"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,112 @@
1
+ // Accounting v0.1
2
+
3
+ /// @title Accounting Lib - Accounting utilities
4
+ /// @author Piper Merriam - <pipermerriam@gmail.com>
5
+ library AccountingLib {
6
+ struct Bank {
7
+ mapping (address => uint) accountBalances;
8
+ }
9
+
10
+ /// @dev Low level method for adding funds to an account. Protects against overflow.
11
+ /// @param self The Bank instance to operate on.
12
+ /// @param accountAddress The address of the account the funds should be added to.
13
+ /// @param value The amount that should be added to the account.
14
+ function addFunds(Bank storage self, address accountAddress, uint value) public {
15
+ /*
16
+ * Helper function that should be used for any addition of
17
+ * account funds. It has error checking to prevent
18
+ * overflowing the account balance.
19
+ */
20
+ if (self.accountBalances[accountAddress] + value < self.accountBalances[accountAddress]) {
21
+ // Prevent Overflow.
22
+ throw;
23
+ }
24
+ self.accountBalances[accountAddress] += value;
25
+ }
26
+
27
+ event _Deposit(address indexed _from, address indexed accountAddress, uint value);
28
+
29
+ /// @dev Function wrapper around the _Deposit event so that it can be used by contracts. Can be used to log a deposit to an account.
30
+ /// @param _from The address that deposited the funds.
31
+ /// @param accountAddress The address of the account the funds were added to.
32
+ /// @param value The amount that was added to the account.
33
+ function Deposit(address _from, address accountAddress, uint value) public {
34
+ _Deposit(_from, accountAddress, value);
35
+ }
36
+
37
+ /// @dev Safe function for depositing funds. Returns boolean for whether the deposit was successful
38
+ /// @param self The Bank instance to operate on.
39
+ /// @param accountAddress The address of the account the funds should be added to.
40
+ /// @param value The amount that should be added to the account.
41
+ function deposit(Bank storage self, address accountAddress, uint value) public returns (bool) {
42
+ /*
43
+ * Public API for depositing funds in a specified account.
44
+ */
45
+ if (self.accountBalances[accountAddress] + value < self.accountBalances[accountAddress]) {
46
+ return false;
47
+ }
48
+ addFunds(self, accountAddress, value);
49
+ return true;
50
+ }
51
+
52
+ event _Withdrawal(address indexed accountAddress, uint value);
53
+
54
+ /// @dev Function wrapper around the _Withdrawal event so that it can be used by contracts. Can be used to log a withdrawl from an account.
55
+ /// @param accountAddress The address of the account the funds were withdrawn from.
56
+ /// @param value The amount that was withdrawn to the account.
57
+ function Withdrawal(address accountAddress, uint value) public {
58
+ _Withdrawal(accountAddress, value);
59
+ }
60
+
61
+ event _InsufficientFunds(address indexed accountAddress, uint value, uint balance);
62
+
63
+ /// @dev Function wrapper around the _InsufficientFunds event so that it can be used by contracts. Can be used to log a failed withdrawl from an account.
64
+ /// @param accountAddress The address of the account the funds were to be withdrawn from.
65
+ /// @param value The amount that was attempted to be withdrawn from the account.
66
+ /// @param balance The current balance of the account.
67
+ function InsufficientFunds(address accountAddress, uint value, uint balance) public {
68
+ _InsufficientFunds(accountAddress, value, balance);
69
+ }
70
+
71
+ /// @dev Low level method for removing funds from an account. Protects against underflow.
72
+ /// @param self The Bank instance to operate on.
73
+ /// @param accountAddress The address of the account the funds should be deducted from.
74
+ /// @param value The amount that should be deducted from the account.
75
+ function deductFunds(Bank storage self, address accountAddress, uint value) public {
76
+ /*
77
+ * Helper function that should be used for any reduction of
78
+ * account funds. It has error checking to prevent
79
+ * underflowing the account balance which would be REALLY bad.
80
+ */
81
+ if (value > self.accountBalances[accountAddress]) {
82
+ // Prevent Underflow.
83
+ throw;
84
+ }
85
+ self.accountBalances[accountAddress] -= value;
86
+ }
87
+
88
+ /// @dev Safe function for withdrawing funds. Returns boolean for whether the deposit was successful as well as sending the amount in ether to the account address.
89
+ /// @param self The Bank instance to operate on.
90
+ /// @param accountAddress The address of the account the funds should be withdrawn from.
91
+ /// @param value The amount that should be withdrawn from the account.
92
+ function withdraw(Bank storage self, address accountAddress, uint value) public returns (bool) {
93
+ /*
94
+ * Public API for withdrawing funds.
95
+ */
96
+ if (self.accountBalances[accountAddress] >= value) {
97
+ deductFunds(self, accountAddress, value);
98
+ if (!accountAddress.send(value)) {
99
+ // Potentially sending money to a contract that
100
+ // has a fallback function. So instead, try
101
+ // tranferring the funds with the call api.
102
+ if (!accountAddress.call.value(value)()) {
103
+ // Revert the entire transaction. No
104
+ // need to destroy the funds.
105
+ //throw;
106
+ }
107
+ }
108
+ return true;
109
+ }
110
+ return false;
111
+ }
112
+ }
@@ -0,0 +1,4 @@
1
+ contract AuditorInterface {
2
+ // publish audit on asset
3
+ // publish audit on holdings
4
+ }
@@ -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
+