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,40 @@
1
+ require 'tmpdir'
2
+ require 'open3'
3
+
4
+ module EvmClient
5
+ class CompilationError < StandardError;
6
+ def initialize(msg)
7
+ super
8
+ end
9
+ end
10
+
11
+ class Solidity
12
+
13
+ OUTPUT_REGEXP = /======= (\S*):(\S*) =======\s*Binary:\s*(\S*)\s*Contract JSON ABI\s*(.*)/
14
+
15
+ def initialize(bin_path = "solc")
16
+ @bin_path = bin_path
17
+ @args = "--bin --abi --optimize"
18
+ end
19
+
20
+ def compile(filename)
21
+ result = {}
22
+ execute_solc(filename).scan(OUTPUT_REGEXP).each do |match|
23
+ _file, name, bin, abi = match
24
+ result[name] = {}
25
+ result[name]["abi"] = abi
26
+ result[name]["bin"] = bin
27
+ end
28
+ result
29
+ end
30
+
31
+ private
32
+ def execute_solc(filename)
33
+ cmd = "#{@bin_path} #{@args} '#{filename}'"
34
+ out, stderr, status = Open3.capture3(cmd)
35
+ raise SystemCallError, "Unanable to run solc compliers" if status.exitstatus == 127
36
+ raise CompilationError, stderr unless status.exitstatus == 0
37
+ out
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,41 @@
1
+ module EvmClient
2
+
3
+ class Transaction
4
+
5
+ DEFAULT_TIMEOUT = 300.seconds
6
+ DEFAULT_STEP = 5.seconds
7
+
8
+ attr_accessor :id, :mined, :connection, :input, :input_parameters
9
+
10
+ def initialize(id, connection, data, input_parameters = [])
11
+ @mined = false
12
+ @connection = connection
13
+ @id = id
14
+ @input = data
15
+ @input_parameters = input_parameters
16
+ end
17
+
18
+ def address
19
+ @id
20
+ end
21
+
22
+ def mined?
23
+ return true if @mined
24
+ tx = @connection.eth_get_transaction_by_hash(@id)
25
+ @mined = !tx.nil? && !tx["result"].nil? && tx["result"]["blockNumber"].present?
26
+ end
27
+
28
+ def wait_for_miner(timeout: DEFAULT_TIMEOUT, step: DEFAULT_STEP)
29
+ start_time = Time.now
30
+ loop do
31
+ raise Timeout::Error if ((Time.now - start_time) > timeout)
32
+ return true if self.mined?
33
+ sleep step
34
+ end
35
+ end
36
+
37
+ def self.from_blockchain(address, connection = IpcClient.new)
38
+ Transaction.new(address, connection, nil, nil)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module EvmClient
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path("../../ethereum.rb", __FILE__)
2
+
3
+ namespace :ethereum do
4
+ namespace :contract do
5
+
6
+ desc "Compile a contract"
7
+ task :compile, [:path] do |_, args|
8
+ contract = EvmClient::Solidity.new.compile(args[:path])
9
+ puts "Contract abi:"
10
+ puts contract.map { |k, v| "#{k}: #{v["abi"]}" }.join("\n\n")
11
+ puts
12
+ puts "Contract binary code:"
13
+ puts contract.map { |k, v| "#{k}: #{v["bin"]}" }.join("\n\n")
14
+ puts
15
+ end
16
+
17
+ desc "Compile and deploy contract"
18
+ task :deploy, [:path] do |_, args|
19
+ puts "Deploing contract #{args[:path]}"
20
+ @works = EvmClient::Contract.create(file: args[:path])
21
+ @works.deploy_and_wait { puts "." }
22
+ address = @works.deployment.contract_address
23
+ puts "Contract deployed under address: #{address}"
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,52 @@
1
+ require 'open3'
2
+
3
+ namespace :ethereum do
4
+ namespace :node do
5
+
6
+ desc "Run testnet (goerli) node"
7
+ task :test do
8
+ args = "--chain testnet"
9
+ out, _, _ = Open3.capture3("parity #{args} account list")
10
+ account = out.split(/[\[\n\]]/)[0]
11
+ cmd = "parity #{args} --password ~/Library/Application\\ Support/io.parity.ethereum/pass --unlock #{account} --author #{account}"
12
+ puts cmd
13
+ system cmd
14
+ end
15
+
16
+ desc "Run production node"
17
+ task :run do
18
+ _, out, _ = Open3.capture3("parity account list")
19
+ account = out.split(/[\[,\]]/)[1]
20
+ system "parity --password ~/.parity/pass --unlock #{account} --author #{account} --no-jsonrpc"
21
+ end
22
+
23
+ desc "Mine ethereum testing environment for ethereum node"
24
+ task :mine do
25
+ cmd = "ethminer"
26
+ puts cmd
27
+ system cmd
28
+ end
29
+
30
+ desc "Check if node is syncing"
31
+ task :waitforsync do
32
+ formatter = EvmClient::Formatter.new
33
+ begin
34
+ loop do
35
+ result = EvmClient::Singleton.instance.eth_syncing["result"]
36
+ unless result
37
+ puts "Synced"
38
+ break
39
+ else
40
+ current = formatter.to_int(result["currentBlock"])
41
+ highest = formatter.to_int(result["highestBlock"])
42
+ puts "Syncing block: #{current}/#{highest}"
43
+ end
44
+ sleep 5
45
+ end
46
+ rescue
47
+ puts "Ethereum node not running?"
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,32 @@
1
+ namespace :ethereum do
2
+ namespace :test do
3
+
4
+ desc "Setup testing environment for ethereum node"
5
+ task :setup do
6
+ @client = EvmClient::Singleton.instance
7
+
8
+ network_id = @client.net_version["result"].to_i
9
+ raise "Error: Run your tests on goerli testnet. Use rake ethereum:node:test to run node. Net id: #{network_id}" if network_id != 5
10
+
11
+ accounts = @client.eth_accounts["result"]
12
+ if accounts.size > 0
13
+ puts "Account already exist, skipping this step"
14
+ else
15
+ puts "Creating account..."
16
+ `parity --chain testnet account new`
17
+ end
18
+
19
+ balance = @client.eth_get_balance(@client.default_account)["result"]
20
+ formatter = EvmClient::Formatter.new
21
+ balance = formatter.to_int(balance)
22
+ balance = formatter.from_wei(balance).to_f
23
+
24
+ if balance.to_f > 0.02
25
+ puts "Done. You're ready to run tests.\nTests will use ether from account: #{@client.default_account} with #{balance} ether"
26
+ else
27
+ puts "Not enough ether to run tests. \nYou have: #{balance} ether. \nYou need at least 0.02 ether to run tests.\nTransfer ether to account: #{@client.default_account}.\nThe easiest way to get ether is to use Ethereum Testnet Faucet."
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ require 'pp'
2
+ require File.expand_path("../../ethereum.rb", __FILE__)
3
+
4
+ namespace :ethereum do
5
+ namespace :transaction do
6
+
7
+ desc "Get info about transaction"
8
+ task :byhash, [:id] do |_, args|
9
+ @client = EvmClient::Singleton.instance
10
+ pp @client.eth_get_transaction_by_hash(args[:id])
11
+ end
12
+
13
+ desc "Send"
14
+ task :send, [:address, :amount] do |_, args|
15
+ @client = EvmClient::Singleton.instance
16
+ @formatter = EvmClient::Formatter.new
17
+ address = @formatter.to_address(args[:address])
18
+ value = @client.int_to_hex(@formatter.to_wei(args[:amount].to_f))
19
+ puts "Transfer from: #{@client.default_account} to: #{address}, amount: #{value}wei"
20
+ pp @client.eth_send_transaction({from: @client.default_account, to: address, value: value})
21
+ end
22
+
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evm_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - shideneyu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: eth
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '4.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: digest-sha3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.1'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.1'
111
+ description: EvmClient is Ruby Ethereum client using the JSON-RPC interface. Provides
112
+ interface for sending transactions, creating and interacting with contracts as well
113
+ as usefull toolkit to work with Ethereum node.
114
+ email:
115
+ - shideneyu@gmail.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
121
+ - ".gitignore"
122
+ - ".rspec"
123
+ - ".ruby-gemset"
124
+ - ".travis.yml"
125
+ - CODE_OF_CONDUCT.md
126
+ - Gemfile
127
+ - LICENSE
128
+ - LICENSE.txt
129
+ - PREREQUISITES.md
130
+ - README.md
131
+ - Rakefile
132
+ - bin/console
133
+ - bin/install_parity
134
+ - bin/setup
135
+ - contracts/AccountingLib.sol
136
+ - contracts/AuditorInterface.sol
137
+ - contracts/AuditorRegistry.sol
138
+ - contracts/CustodianInterface.sol
139
+ - contracts/CustodianRegistry.sol
140
+ - contracts/DigixConfiguration.sol
141
+ - contracts/Directory.sol
142
+ - contracts/DoublyLinked.sol
143
+ - contracts/GenericInterface.sol
144
+ - contracts/GenericRegistry.sol
145
+ - contracts/Gold.sol
146
+ - contracts/GoldRegistry.sol
147
+ - contracts/GoldTokenLedger.sol
148
+ - contracts/Interface.sol
149
+ - contracts/Minter.sol
150
+ - contracts/Recaster.sol
151
+ - contracts/Testing.sol
152
+ - contracts/VendorInterface.sol
153
+ - contracts/VendorRegistry.sol
154
+ - contracts/classic/Digixbot.sol
155
+ - contracts/classic/DigixbotConfiguration.sol
156
+ - contracts/classic/DigixbotEthereum.sol
157
+ - contracts/classic/DigixbotUsers.sol
158
+ - contracts/classic/Gold.sol
159
+ - contracts/classic/GoldRegistry.sol
160
+ - contracts/classic/GoldTokenLedger.sol
161
+ - contracts/classic/GoldTokenMinter.sol
162
+ - contracts/classic/ParticipantRegistry.sol
163
+ - contracts/classic/QueueSample.sol
164
+ - evm_client.gemspec
165
+ - lib/evm_client.rb
166
+ - lib/evm_client/abi.rb
167
+ - lib/evm_client/client.rb
168
+ - lib/evm_client/contract.rb
169
+ - lib/evm_client/contract_event.rb
170
+ - lib/evm_client/contract_initializer.rb
171
+ - lib/evm_client/decoder.rb
172
+ - lib/evm_client/deployment.rb
173
+ - lib/evm_client/encoder.rb
174
+ - lib/evm_client/event_log.rb
175
+ - lib/evm_client/explorer_url_helper.rb
176
+ - lib/evm_client/formatter.rb
177
+ - lib/evm_client/function.rb
178
+ - lib/evm_client/function_input.rb
179
+ - lib/evm_client/function_output.rb
180
+ - lib/evm_client/http_client.rb
181
+ - lib/evm_client/initializer.rb
182
+ - lib/evm_client/ipc_client.rb
183
+ - lib/evm_client/project_initializer.rb
184
+ - lib/evm_client/railtie.rb
185
+ - lib/evm_client/singleton.rb
186
+ - lib/evm_client/solidity.rb
187
+ - lib/evm_client/transaction.rb
188
+ - lib/evm_client/version.rb
189
+ - lib/tasks/ethereum_contract.rake
190
+ - lib/tasks/ethereum_node.rake
191
+ - lib/tasks/ethereum_test.rake
192
+ - lib/tasks/ethereum_transaction.rake
193
+ homepage: https://github.com/shideneyu/evm_client
194
+ licenses:
195
+ - MIT
196
+ metadata:
197
+ allowed_push_host: https://rubygems.org
198
+ post_install_message:
199
+ rdoc_options: []
200
+ require_paths:
201
+ - lib
202
+ - bin
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ requirements: []
214
+ rubyforge_project:
215
+ rubygems_version: 2.7.6.2
216
+ signing_key:
217
+ specification_version: 4
218
+ summary: Ruby Ethereum client using the JSON-RPC interface
219
+ test_files: []