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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6b6babf0accf523a9f3bf96f2d284e522551eccb410ef2f13676eb756eb6a290
4
+ data.tar.gz: 01d5fb5797d134962d87342ea9a81ca96c0d640f17807323ec89d43d15500c54
5
+ SHA512:
6
+ metadata.gz: 4dc5d81a8e9d71decb9e42c5c25c38a2ade07524e4784000bca73756dde7a3c882b6138d2cdcb795b9d44af0e9e1ae9ab6a773b168790fc4abfe0cf867387384
7
+ data.tar.gz: 13b5e8085450aa2e7a3d3d163062ee276305a65448b90c6b1c8f0ccfaac263cd6f9010adbe646d178cf11379297e9faec24a5c226860c78b2164050754517d4e
@@ -0,0 +1,26 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: bug
6
+ assignees: kurotaky
7
+
8
+ ---
9
+
10
+ ### Steps to reproduce
11
+ <!-- Steps to reproduce the behavior -->
12
+
13
+ ### Expected behavior
14
+ <!-- Tell us what should happen -->
15
+
16
+ ### Actual behavior
17
+ <!-- Tell us what happens instead -->
18
+
19
+ ### System configuration
20
+ **Ruby version**:
21
+ **Solc version**:
22
+ **Parity version**:
23
+ **OS**:
24
+
25
+ ### Failure Logs
26
+ <!-- Please include any relevant log snippets or files here-->
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.*.swp
11
+ /**/.*.swp
12
+
13
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rubythereum
data/.travis.yml ADDED
@@ -0,0 +1,32 @@
1
+ dist: xenial
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.3
5
+ - 2.5.0
6
+ - 2.6
7
+ - 2.7
8
+ env:
9
+ - PARITY="2.5.12"
10
+ cache:
11
+ bundler: true
12
+ directories:
13
+ - ~/.parity
14
+ before_install:
15
+ - sudo bin/install_parity
16
+ - gem update --system
17
+ - gem install bundler
18
+ before_script:
19
+ - ./parity --warp --chain dev --password ~/.devpass --unlock 00a329c0648769a73afac7f9381e08fb43dbea72 --author 00a329c0648769a73afac7f9381e08fb43dbea72 daemon ~/.parity.pid --log-file ~/.parity.log
20
+ - sleep 5
21
+ - ./parity --chain dev account list
22
+ - cat ~/.parity.log
23
+ script:
24
+ - bundle exec rspec --tag ~blockchain && bundle exec rspec --tag blockchain
25
+ before_cache:
26
+ - killall parity
27
+ - sleep 3
28
+ after_script:
29
+ - cat /tmp/ethereum_ruby_http.log
30
+ notifications:
31
+ slack:
32
+ secure: is1TFfNJTX4VsDTu3zC5vIZ+Cowj0fQDFyqHPYxvuX60NHh8WBrjZ1qwnehTlLtC6d58EByxr+KVChCxrRdZ6IenpdXq+2Oz4IRS5I8tkvFbc8o30weBd7Umw3MzwTdSdoV0jQsyy395jYr3cxzJCBt+7tJRA93V8tN6yiHe8w7ImY3R20HKtLuE3ZWh3gjrAVx3u9fEolNBIuQvWl1jMl23ptizoHuesMCYgeehdtPxxOq/smKWN6Ds30hDG16lfEtSm8jxNjepMYZ/zGcHB/DCCRBgo5wHMmLzjCHL5mzf5YDr47gAtywXT7zpdMGbMep8H/QRR9kkCmp5o1FUzHx1CjFHIHCngwawBz6oy3/3jDIuLa3Z+SYHxbDHYZ3Xb8UKDrHl7IKF2dQ5fQRoxpaQ4mMAHbIQDyWp9kRwLljAX6cBDDjGF6/+TCn/BUE+KQZupBG79KymoFZlH7TYyKofHvcp7dcfSFyF8XKsHUglDSmISERbt/KN9zP2876o1ZDt+4HOzGM0lW6Z0nibhTdLHmzrA2fdxGpsJY7Eh6j9h7imgXP7rfCcXb3c4ib+XU1B2S1clmdyj/+03V+wLhvUqse5pBbQqTogr92gziLGKhDGBk4zz0q1a4D4y0qe79AA79R14VbdYC23+nehvpSW8gANfN4IcuX9srBCJjY=
@@ -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 ethereum.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
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
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
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.
data/PREREQUISITES.md ADDED
@@ -0,0 +1,75 @@
1
+ # Prerequisites
2
+
3
+ ## Compatibility and requirements
4
+
5
+ * Tested with parity 2.5, might work with geth and older parity, but was not tested.
6
+ * Tested with solc 0.5.16
7
+ * Ruby 2.x
8
+ * UNIX/Linux or OS X environment
9
+
10
+ ## Installing prerequisites
11
+
12
+ ### Ethereum node
13
+
14
+ Currently the only node supported by ethereum.rb is [parity](https://ethcore.io/parity.html). To install parity on mac simply:
15
+
16
+ $ brew tap ethcore/ethcore
17
+ $ brew install parity
18
+
19
+ To install parity on linux download latest package from [parity github](https://github.com/paritytech/parity/releases) and install on your computer.
20
+
21
+ It might work with [geth](https://github.com/ethereum/go-ethereum/wiki/geth) as well, but this configuration is not tested.
22
+
23
+ To work correctly ethereum.rb needs parity to have at least one wallet configured. Parity should automatically create one for you during installation.
24
+ You can see the list of wallets by calling:
25
+
26
+ $ parity account list
27
+
28
+ And create one with following command:
29
+
30
+ $ parity account new
31
+
32
+ ### Solidity complier
33
+
34
+ To be able to compile [solidity](https://github.com/ethereum/solidity) contracts you need to install solc compiler. Installation instructions are available [here](http://solidity.readthedocs.io/en/latest/installing-solidity.html).
35
+ To install on mac type:
36
+
37
+ $ brew install solidity --beta
38
+
39
+ In general get used to working on beta versions as ethereum ecosystem evolves quite fast.
40
+
41
+ ## Installation
42
+
43
+ Add this line to your application's Gemfile:
44
+
45
+ ```ruby
46
+ gem 'ethereum.rb'
47
+ ```
48
+
49
+ And then execute:
50
+
51
+ $ bundle
52
+
53
+ Or install it yourself as:
54
+
55
+ $ gem install ethereum.rb
56
+
57
+ ### Running a node
58
+
59
+ There is a rake task to run node on testnet network, that you can run from your application directory:
60
+
61
+ $ rake ethereum:node:test
62
+
63
+ It will run parity node, unlock the first account on the account list, but you need to supply it with password.
64
+ To do that adding create file containing password accessable from your parity folder, which should be one of the following:
65
+ * `/Users/You/AppData/Roaming/Parity/Ethereum` on Windows
66
+ * `/Users/you/Library/Application Support/io.parity.ethereum` on MacOS
67
+ * `/home/you/.local/share/parity` on Linux/Unix
68
+ * `/home/you/.parity` on Linux and MacOS for Parity versions older then 1.5.0
69
+
70
+ Warnning: Running a parity node with unlock wallet is a considerable security risk and should be avoided on production servers. Especially avoid running node with unlocked wallet and enabled json rpc server in http mode.
71
+
72
+ To send transaction on a testnet blockchain you will need test ether, you can get it at the following site.
73
+
74
+ * [Goerli Testnet Faucet](https://goerli-faucet.slock.it/)
75
+ * [Goerli: Authenticated Faucet](https://faucet.goerli.mudit.blog/)
data/README.md ADDED
@@ -0,0 +1,665 @@
1
+
2
+ # EvmClient
3
+
4
+ Ethereum Virtual Machine Client is a clone of [ethereum.rb](https://github.com/EthWorks/ethereum.rb), with less bugs and more features.
5
+
6
+ ## What's new
7
+
8
+
9
+
10
+ * Compatible with OpenEthereum
11
+ * Compatible with complex ABIs
12
+ * More tools to parse Events à la Web3Js
13
+ * Battle tested with Ethereum, Binance Chain and Polygon
14
+ * Can interact with old blockchain snapchots, if provided an old block as parameter
15
+
16
+
17
+
18
+ ## Installation
19
+
20
+
21
+ Using a RPC node is the prefered solution.
22
+
23
+ To install gem simply add this line to your application's Gemfile:
24
+
25
+
26
+ Using a RPC node is the prefered solution.
27
+
28
+ To install gem simply add this line to your application's Gemfile:
29
+
30
+
31
+
32
+ ```ruby
33
+
34
+ gem 'evm_client'
35
+
36
+ ```
37
+
38
+
39
+
40
+ And then execute:
41
+
42
+ ```shell
43
+ bundle
44
+ ```
45
+
46
+
47
+ Or install it yourself as:
48
+
49
+
50
+ ```
51
+ gem install ethereum.rb
52
+ ```
53
+
54
+ ## Basic Usage
55
+
56
+
57
+
58
+ You can create contract from solidity source and deploy it to the blockchain, with following code:
59
+
60
+
61
+
62
+ ```ruby
63
+
64
+ contract = EvmClient::Contract.create(file: "greeter.sol")
65
+
66
+ address = contract.deploy_and_wait("Hello from ethereum.rb!")
67
+
68
+ ```
69
+
70
+
71
+
72
+ Deployment may take up to couple of minutes. Once deployed you can start interacting with contract, e.g. calling it's methods:
73
+
74
+
75
+
76
+ ```ruby
77
+
78
+ contract.call.greet # => "Hello from ethereum.rb!"
79
+
80
+ ```
81
+
82
+
83
+
84
+ You can see example contract [greeter here](https://github.com/marekkirejczyk/ruby_ethereum_example/blob/master/contracts/greeter.sol).
85
+
86
+
87
+
88
+ > If contract method name uses camel case you must convert it to snake case when use call: `call.your_method`.
89
+
90
+
91
+ ## Smart contracts
92
+
93
+
94
+
95
+ ### Compile multiple contracts at once
96
+
97
+
98
+
99
+ If you want to complie multiple contracts at once, you can create new instances using newly declared ruby clasess:
100
+
101
+
102
+
103
+ ```ruby
104
+
105
+ EvmClient::Contract.create(file: "mycontracts.sol", client: client)
106
+
107
+ contract = MyContract1.new
108
+
109
+ contract = contract.deploy_and_wait
110
+
111
+ contract2 = MyContract2.new
112
+
113
+ contract2 = contract.deploy_and_wait
114
+
115
+ ```
116
+
117
+
118
+
119
+ All names used to name contract in solidity source will translate to name of classes in ruby (camelized).
120
+
121
+
122
+
123
+ Note: If class of given name exist it will be undefined first to avoid name collision.
124
+
125
+
126
+
127
+ ### Get contract from blockchain
128
+
129
+
130
+
131
+ The other way to obtain contract instance is get one that already exist in the blockchain. To do so you need a contract name, contract address and ABI definition.
132
+
133
+
134
+
135
+ ```ruby
136
+
137
+ contract = EvmClient::Contract.create(name: "MyContract", address: "0x01a4d1A62F01ED966646acBfA8BB0b59960D06dd ", abi: abi)
138
+
139
+ ```
140
+
141
+
142
+
143
+ Note that you need to specify contract name, that will be used to define new class in ruby, as it is not a part of ABI definition.
144
+
145
+
146
+
147
+ Alternatively you can obtain abi definition and name from contract source file:
148
+
149
+
150
+
151
+ ```ruby
152
+
153
+ contract = EvmClient::Contract.create(file: "MyContract.sol", address: "0x01a4d1A62F01ED966646acBfA8BB0b59960D06dd ")
154
+
155
+ ```
156
+
157
+
158
+
159
+ If you want to create new contract, that is not yet deployed from ABI definition you will need also to supply binary code:
160
+
161
+
162
+
163
+ ```ruby
164
+
165
+ contract = EvmClient::Contract.create(name: "MyContract", abi: abi, code: "...")
166
+
167
+ ```
168
+
169
+
170
+
171
+ ### Simple Truffle integration
172
+
173
+
174
+
175
+ If you use Truffle to build and deploy contracts, you can pick up the Truffle artifacts to initialize
176
+
177
+ a contract. For example, if you have a MyContract in the Truffle directory at `/my/truffle/project`:
178
+
179
+
180
+
181
+ ```ruby
182
+
183
+ contract = EvmClient::Contract.create(name: "MyContract", truffle: { paths: [ '/my/truffle/project' ] }, client: client, address: '0x01a4d1A62F01ED966646acBfA8BB0b59960D06dd')
184
+
185
+ ```
186
+
187
+
188
+
189
+ The contract factory will attempt to load the deployed address from the Truffle artifacts if the client's network is present:
190
+
191
+
192
+
193
+ ```ruby
194
+
195
+ contract = EvmClient::Contract.create(name: "MyContract", truffle: { paths: [ '/my/truffle/project' ] }, client: client)
196
+
197
+ ```
198
+
199
+
200
+
201
+ ### Interacting with contract
202
+
203
+
204
+
205
+ Functions defined in a contract are exposed using the following conventions:
206
+
207
+
208
+
209
+ ```ruby
210
+
211
+ contract.transact.[function_name](params)
212
+
213
+ contract.transact_and_wait.[function_name](params)
214
+
215
+ contract.call.[function_name](params)
216
+
217
+ ```
218
+
219
+
220
+
221
+ **Example Contract in Solidity**
222
+
223
+ ```
224
+
225
+ contract SimpleRegistry {
226
+
227
+ event LogRegister(bytes32 key, string value);
228
+
229
+ mapping (bytes32 => string) public registry;
230
+
231
+
232
+
233
+ function register(bytes32 key, string value) {
234
+
235
+ registry[key] = value;
236
+
237
+ LogRegister(key, value);
238
+
239
+ }
240
+
241
+
242
+
243
+ function get(bytes32 key) public constant returns(string) {
244
+
245
+ return registry[key];
246
+
247
+ }
248
+
249
+
250
+
251
+ }
252
+
253
+ ```
254
+
255
+
256
+
257
+ For contract above here is how to access it's methods:
258
+
259
+
260
+
261
+ ```ruby
262
+
263
+ contract.transact_and_wait.register("performer", "Beastie Boys")
264
+
265
+ ```
266
+
267
+
268
+
269
+ Will send transaction to the blockchain and wait for it to be mined.
270
+
271
+
272
+
273
+ ```ruby
274
+
275
+ contract.transact.register("performer", "Black Eyed Peas")
276
+
277
+ ```
278
+
279
+
280
+
281
+ Will send transaction to the blockchain return instantly.
282
+
283
+
284
+
285
+ ```ruby
286
+
287
+ contract.call.get("performer") # => "Black Eyed Peas"
288
+
289
+ ```
290
+
291
+
292
+
293
+ Will call method of the contract and return result.
294
+
295
+ Note that no transaction need to be send to the network as method is read-only.
296
+
297
+ On the other hand `register` method will change contract state, so you need to use `transact` or `transact_and_wait` to call it.
298
+
299
+
300
+
301
+ ### Receiving Contract Events
302
+
303
+ Using this example , you can fetch all of the `my_event_name` events:
304
+
305
+ ```ruby
306
+ event_name = 'my_event_name'
307
+ event_abi = contract.abi.find { |abi| abi['name'] == event_name.camelize }
308
+ sig = contract.parent.events.find { |e| e.name.to_s == event_name.camelize }.signature
309
+ topics = [encoder.ensure_prefix(sig)]
310
+ from_block_number = 1
311
+ from_block = "0x#{block_number.to_s(16)}"
312
+
313
+ response = client.eth_get_logs(
314
+ {
315
+ fromBlock: from_block,
316
+ toBlock: 'latest',
317
+ address: contract_address,
318
+ topics: topics
319
+ }
320
+ )
321
+
322
+ raw_events = response['result']
323
+
324
+
325
+
326
+ raw_events.map do |event|
327
+ ::EvmClient::EventLog.build(raw_response: event, contract: contract)
328
+ end
329
+ ```
330
+
331
+ What is being returned is a collection of `EventLog` containing all of the extracted and decoded data you would need.
332
+
333
+
334
+
335
+
336
+ ### IPC Client Connection
337
+
338
+
339
+
340
+ By default methods interacting with contracts will use default Json RPC Client that will handle connection to ethereum node.
341
+
342
+ Default client communicate via IPC. If you want to create custom client or use multiple clients you can create them yourself.
343
+
344
+
345
+
346
+ To create IPC client instance of simply create EvmClient::IpcClient:
347
+
348
+
349
+
350
+ ```ruby
351
+
352
+ client = EvmClient::IpcClient.new
353
+
354
+ ```
355
+
356
+
357
+
358
+ You can also customize it with path to ipc file path and logging flag:
359
+
360
+
361
+
362
+ ```ruby
363
+
364
+ client = EvmClient::IpcClient.new("~/.parity/mycustom.ipc", false)
365
+
366
+ ```
367
+
368
+
369
+
370
+ If no ipc file path given, IpcClient looks for ipc file in default locations for parity and geth.
371
+
372
+ The second argument is optional. If it is true then logging is on.
373
+
374
+
375
+
376
+ By default logging is on and logs are saved in "/tmp/ethereum_ruby_http.log".
377
+
378
+
379
+
380
+ To create Http client use following:
381
+
382
+
383
+
384
+ ```ruby
385
+
386
+ client = EvmClient::HttpClient.new('http://localhost:8545')
387
+
388
+ ```
389
+
390
+
391
+
392
+ You can supply client when creating a contract:
393
+
394
+
395
+
396
+ ```ruby
397
+
398
+ contract = EvmClient::Contract.create(client: client, ...)
399
+
400
+ ```
401
+
402
+
403
+
404
+ You can also obtain default client:
405
+
406
+
407
+
408
+ ```ruby
409
+
410
+ client = EvmClient::Singleton.instance
411
+
412
+ ```
413
+
414
+
415
+
416
+ ### Calling json rpc methods
417
+
418
+
419
+
420
+ Ethereum.rb allows you to interact directly with Ethereum node using json rpc api calls.
421
+
422
+ Api calls translates directly to client methods. E.g. to call `eth_gasPrice` method:
423
+
424
+
425
+
426
+ ```ruby
427
+
428
+ client.eth_gas_price # => {"jsonrpc"=>"2.0", "result"=>"0x4a817c800", "id"=>1}
429
+
430
+ ```
431
+
432
+
433
+
434
+ Note: methods are transated to underscore notation.
435
+
436
+
437
+
438
+ Full list of json rpc methods is available [here](https://github.com/ethereum/wiki/wiki/JSON-RPC#user-content-json-rpc-methods)
439
+
440
+
441
+
442
+ ### Signed transactions
443
+
444
+
445
+
446
+ Ethereum.rb supports signing transactions with key using [ruby-eth gem](https://github.com/se3000/ruby-eth).
447
+
448
+
449
+
450
+ To create a new key simply do the following:
451
+
452
+
453
+
454
+ ```ruby
455
+
456
+ key = Eth::Key.new
457
+
458
+ ```
459
+
460
+
461
+
462
+ Then you can use the key to deploy contracts and send transactions, i.e.:
463
+
464
+
465
+
466
+ ```ruby
467
+
468
+ contract = EvmClient::Contract.create(file: "...")
469
+
470
+ contract.key = key
471
+
472
+ contract.deploy_and_wait("Allo Allo!")
473
+
474
+ contract.transact_and_wait.set("greeting", "Aloha!")
475
+
476
+ ```
477
+
478
+
479
+
480
+ You can also transfer ether transfer using custom keys:
481
+
482
+
483
+
484
+ ```ruby
485
+
486
+ client.transfer(key, "0x342bcf27DCB234FAb8190e53E2d949d7b2C37411", amount)
487
+
488
+ client.transfer_and_wait(key, "0x949d7b2C37411eFB763fcDCB234FAb8190e53E2d", amount)
489
+
490
+ ```
491
+
492
+
493
+ ### Custom block
494
+
495
+ You need a full node which support archived data if you want to set a custom block.
496
+
497
+
498
+ ```ruby
499
+ client.block_number = 1
500
+ ```
501
+
502
+ ### Custom gas price and gas limit
503
+
504
+
505
+
506
+ You can change gas price or gas limit in the client:
507
+
508
+
509
+
510
+ ```ruby
511
+
512
+ client.gas_limit = 2_000_000_
513
+
514
+ client.gas_price = 24_000_000_000
515
+
516
+ ```
517
+
518
+
519
+
520
+ or per contract:
521
+
522
+ ```ruby
523
+
524
+ contract.gas_limit = 2_000_000_
525
+
526
+ contract.gas_price = 24_000_000_000
527
+
528
+ ```
529
+
530
+
531
+
532
+ ### Custom block
533
+
534
+
535
+
536
+ You can change the block used by the client. Defaulted at `'latest'` if not specified.
537
+
538
+ If the specified block is older than the latest, transactions are impossible, and only contract `call` are available, as the blockchain is immutable.
539
+
540
+
541
+
542
+ ```ruby
543
+
544
+ client.block_number = 12_596_089
545
+
546
+ ```
547
+
548
+
549
+
550
+
551
+ ## Utils
552
+
553
+
554
+
555
+ ### Url helpers for rails applications
556
+
557
+
558
+
559
+ Often in the application you want to link to blockchain explorer. This can be problematic if you want links to work with different networks (ropsten, mainnet, kovan) depending on environment you're working on.
560
+
561
+ Following helpers will generate link according to network connected:
562
+
563
+
564
+
565
+ ```ruby
566
+
567
+ link_to_tx("See the transaction", "0x3a4e53b01274b0ca9087750d96d8ba7f5b6b27bf93ac65f3174f48174469846d")
568
+
569
+ link_to_address("See the wallet", "0xE08cdFD4a1b2Ef5c0FC193877EC6A2Bb8f8Eb373")
570
+
571
+ ```
572
+
573
+ They use [etherscan.io](http://etherscan.io/) as a blockexplorer.
574
+
575
+
576
+
577
+ Note: Helpers work in rails environment only, works with rails 5.0+.
578
+
579
+
580
+
581
+ ### Utils rake tasks
582
+
583
+
584
+
585
+ There are couple of rake tasks to help in wallet maintenance, i.e.:
586
+
587
+
588
+
589
+ ```ruby
590
+
591
+ rake ethereum:contract:deploy[path] # Compile and deploy contract
592
+
593
+ rake ethereum:contract:compile[path] # Compile a contract
594
+
595
+ rake ethereum:transaction:byhash[id] # Get info about transaction
596
+
597
+ rake ethereum:transaction:send[address,amount] # Send [amount of] ether to an account
598
+
599
+ ```
600
+
601
+
602
+
603
+ ## Debbuging
604
+
605
+ Logs from communication between ruby app and node are available under following path:
606
+
607
+ ```
608
+
609
+ /tmp/ethereum_ruby_http.log
610
+
611
+ ```
612
+
613
+
614
+
615
+ ## Roadmap
616
+
617
+
618
+
619
+ * Rubydoc documentation
620
+
621
+
622
+
623
+ ## Development
624
+
625
+
626
+
627
+ Run `bin/console` for an interactive prompt that will allow you to experiment.
628
+
629
+
630
+
631
+ Make sure `rake ethereum:test:setup` passes before running tests.
632
+
633
+
634
+
635
+ Then, run `rake spec` to run the tests.
636
+
637
+
638
+
639
+ Test that do send transactions to blockchain are marked with `blockchain` tag. Good practice is to run first fast tests that use no ether and only if they pass, run slow tests that do spend ether. To do that use the following line:
640
+
641
+
642
+
643
+ ```bash
644
+
645
+ $ bundle exec rspec --tag ~blockchain && bundle exec rspec --tag blockchain
646
+
647
+ ```
648
+
649
+
650
+
651
+ You need ethereum node up and running for tests to pass and it needs to be working on testnet (Ropsten).
652
+
653
+
654
+
655
+ ## Acknowledgements and license
656
+
657
+
658
+
659
+ This library has been forked from [ethereum-ruby](https://github.com/DigixGlobal/ethereum-ruby) by DigixGlobal Pte Ltd (https://dgx.io).
660
+
661
+ This library has also been forked from [ethereum.rb](https://github.com/EthWorks/ethereum.rb) by [kurotaky](https://github.com/kurotaky)
662
+
663
+
664
+
665
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).