From 89dd247d931019fb75fb0da233441d903ba5d6c0 Mon Sep 17 00:00:00 2001 From: Eric Saupe Date: Fri, 3 Feb 2017 23:29:36 -0700 Subject: [PATCH 1/6] Fixed issues with missing method names Seeing many methods that want eth_ prepended to them. Fixed it in various spots as well as changed #send_transaction to #send_single --- lib/ethereum/contract.rb | 24 ++++++++++++------------ lib/ethereum/contract_initializer.rb | 2 +- lib/ethereum/initializer.rb | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/ethereum/contract.rb b/lib/ethereum/contract.rb index ce6594a..402fc5d 100644 --- a/lib/ethereum/contract.rb +++ b/lib/ethereum/contract.rb @@ -11,7 +11,7 @@ def initialize(name, code, abi) @events = [] @constructor_inputs = @abi.detect {|x| x["type"] == "constructor"}["inputs"] rescue nil @abi.select {|x| x["type"] == "function" }.each do |abifun| - @functions << Ethereum::Function.new(abifun) + @functions << Ethereum::Function.new(abifun) end @abi.select {|x| x["type"] == "event" }.each do |abievt| @events << Ethereum::ContractEvent.new(abievt) @@ -43,7 +43,7 @@ def build(connection) end end deploy_payload = deploy_code + deploy_arguments - deploytx = connection.send_transaction({from: self.sender, gas: self.gas, gasPrice: self.gas_price, data: "0x" + deploy_payload})["result"] + deploytx = connection.send_single({from: self.sender, gas: self.gas, gasPrice: self.gas_price, data: "0x" + deploy_payload})["result"] instance_variable_set("@deployment", Ethereum::Deployment.new(deploytx, connection)) end @@ -66,7 +66,7 @@ def build(connection) end define_method :at do |addr| - instance_variable_set("@address", addr) + instance_variable_set("@address", addr) self.events.each do |event| event.set_address(addr) event.set_client(connection) @@ -82,7 +82,7 @@ def build(connection) end define_method :sender do - instance_variable_get("@sender") || connection.coinbase["result"] + instance_variable_get("@sender") || connection.eth_coinbase["result"] end define_method :set_gas_price do |gp| @@ -97,7 +97,7 @@ def build(connection) instance_variable_set("@gas", gas) end - define_method :gas do + define_method :gas do instance_variable_get("@gas") || 3000000 end @@ -119,11 +119,11 @@ def build(connection) logs["result"].each do |result| inputs = evt.input_types outputs = inputs.zip(result["topics"][1..-1]) - data = {blockNumber: result["blockNumber"].hex, transactionHash: result["transactionHash"], blockHash: result["blockHash"], transactionIndex: result["transactionIndex"].hex, topics: []} + data = {blockNumber: result["blockNumber"].hex, transactionHash: result["transactionHash"], blockHash: result["blockHash"], transactionIndex: result["transactionIndex"].hex, topics: []} outputs.each do |output| data[:topics] << formatter.from_payload(output) end - collection << data + collection << data end return collection end @@ -135,11 +135,11 @@ def build(connection) logs["result"].each do |result| inputs = evt.input_types outputs = inputs.zip(result["topics"][1..-1]) - data = {blockNumber: result["blockNumber"].hex, transactionHash: result["transactionHash"], blockHash: result["blockHash"], transactionIndex: result["transactionIndex"].hex, topics: []} + data = {blockNumber: result["blockNumber"].hex, transactionHash: result["transactionHash"], blockHash: result["blockHash"], transactionIndex: result["transactionIndex"].hex, topics: []} outputs.each do |output| data[:topics] << formatter.from_payload(output) end - collection << data + collection << data end return collection end @@ -178,9 +178,9 @@ def build(connection) define_method call_function_name do |*args| data = self.send(call_raw_function_name, *args) output = data[:formatted] - if output.length == 1 + if output.length == 1 return output[0] - else + else return output end end @@ -195,7 +195,7 @@ def build(connection) arg_types.zip(args).each do |arg| payload << formatter.to_payload(arg) end - txid = connection.send_transaction({to: self.address, from: self.sender, data: "0x" + payload.join(), gas: self.gas, gasPrice: self.gas_price})["result"] + txid = connection.send_single({to: self.address, from: self.sender, data: "0x" + payload.join(), gas: self.gas, gasPrice: self.gas_price})["result"] return Ethereum::Transaction.new(txid, self.connection, payload.join(), args) end diff --git a/lib/ethereum/contract_initializer.rb b/lib/ethereum/contract_initializer.rb index f2cedd8..9cf6ced 100644 --- a/lib/ethereum/contract_initializer.rb +++ b/lib/ethereum/contract_initializer.rb @@ -40,7 +40,7 @@ def link_libraries end def build(connection) - @contract = Ethereum::Contract.new(@name, @binary, @abi) + @contract = Ethereum::Contract.new(@name, @binary, @abi) @contract.build(connection) end diff --git a/lib/ethereum/initializer.rb b/lib/ethereum/initializer.rb index bb0da4b..5cc7d51 100644 --- a/lib/ethereum/initializer.rb +++ b/lib/ethereum/initializer.rb @@ -6,12 +6,12 @@ class Initializer def initialize(file, client = Ethereum::IpcClient.new) @file = File.read(file) @client = client - sol_output = @client.compile_solidity(@file) + sol_output = @client.eth_compile_solidity(@file) contracts = sol_output["result"].keys @contracts = [] contracts.each do |contract| - abi = sol_output["result"][contract]["info"]["abiDefinition"] - name = contract + abi = sol_output["result"][contract]["info"]["abiDefinition"] + name = contract.sub(':', '') code = sol_output["result"][contract]["code"] @contracts << Ethereum::Contract.new(name, code, abi) end From f826a8a69b3952bb57610d58693e0e664b4b5731 Mon Sep 17 00:00:00 2001 From: Eric Saupe Date: Mon, 6 Feb 2017 21:41:36 -0700 Subject: [PATCH 2/6] Fixed compile error on SimpleNameRegistry.sol --- spec/fixtures/SimpleNameRegistry.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/fixtures/SimpleNameRegistry.sol b/spec/fixtures/SimpleNameRegistry.sol index 2b35ba8..2626d63 100644 --- a/spec/fixtures/SimpleNameRegistry.sol +++ b/spec/fixtures/SimpleNameRegistry.sol @@ -9,7 +9,7 @@ contract SimpleNameRegistry { bytes16 public fifth; bytes32 public sixth; - modifier ifowner { if (msg.sender == owner) _ } + modifier ifowner { if (msg.sender == owner) _; } function SimpleNameRegistry() { owner = msg.sender; @@ -63,4 +63,4 @@ contract SimpleContract { function SimpleContract() { owner = msg.sender; } -} \ No newline at end of file +} From d0d5de90398f8b0c132f6833c72c1d8590d186a8 Mon Sep 17 00:00:00 2001 From: Eric Saupe Date: Mon, 6 Feb 2017 21:42:03 -0700 Subject: [PATCH 3/6] Fixed issue where payload was not in json --- lib/ethereum/contract.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ethereum/contract.rb b/lib/ethereum/contract.rb index 402fc5d..b956371 100644 --- a/lib/ethereum/contract.rb +++ b/lib/ethereum/contract.rb @@ -43,7 +43,7 @@ def build(connection) end end deploy_payload = deploy_code + deploy_arguments - deploytx = connection.send_single({from: self.sender, gas: self.gas, gasPrice: self.gas_price, data: "0x" + deploy_payload})["result"] + deploytx = connection.send_single({from: self.sender, gas: self.gas, gasPrice: self.gas_price, data: "0x" + deploy_payload}.to_json)["result"] instance_variable_set("@deployment", Ethereum::Deployment.new(deploytx, connection)) end From 5a2da680db26b92f953312e22385d3d151fce530 Mon Sep 17 00:00:00 2001 From: Eric Saupe Date: Mon, 6 Feb 2017 21:42:34 -0700 Subject: [PATCH 4/6] Fixed spec issues with version and client connection --- spec/client_spec.rb | 2 +- spec/ethereum_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 728a1db..510d326 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -10,7 +10,7 @@ describe 'IpcClient' do before(:each) do - @client = Ethereum::IpcClient.new("#{ENV['HOME']}/EtherDev/data/geth.ipc") + @client = Ethereum::IpcClient.new("#{ENV['HOME']}/.ethereum/testnet/geth.ipc") end it 'should work' do diff --git a/spec/ethereum_spec.rb b/spec/ethereum_spec.rb index c930683..9b90340 100644 --- a/spec/ethereum_spec.rb +++ b/spec/ethereum_spec.rb @@ -3,22 +3,22 @@ describe Ethereum do before(:all) do - @client = Ethereum::HttpClient.new("172.16.135.102", "8545") + @client = Ethereum::HttpClient.new("localhost", "8545") @formatter = Ethereum::Formatter.new end describe "Ethereum Version" do it 'has a version number' do - expect(Ethereum::VERSION).to eq("0.4.90") + expect(Ethereum::VERSION).to eq("1.5.2") end end - + describe "Deployment" do it "should deploy a contract with parameters" do @init = Ethereum::Initializer.new("#{ENV['PWD']}/spec/fixtures/ContractWithParams.sol", @client) @init.build_all @contract_with_params = ContractWithParams.new - @coinbase = @contract_with_params.connection.coinbase["result"] + @coinbase = @contract_with_params.connection.eth_coinbase["result"] @contract_with_params.deploy_and_wait(60, @coinbase) address = @contract_with_params.call_get_setting__ expect(address).to eq(@coinbase) From 61ab8053c350badeab5ee15ced289349700f835a Mon Sep 17 00:00:00 2001 From: Eric Saupe Date: Mon, 6 Feb 2017 21:45:04 -0700 Subject: [PATCH 5/6] Reverted IP for client in spec --- spec/ethereum_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/ethereum_spec.rb b/spec/ethereum_spec.rb index 9b90340..4dd2f8d 100644 --- a/spec/ethereum_spec.rb +++ b/spec/ethereum_spec.rb @@ -3,7 +3,7 @@ describe Ethereum do before(:all) do - @client = Ethereum::HttpClient.new("localhost", "8545") + @client = Ethereum::HttpClient.new("172.16.135.102", "8545") @formatter = Ethereum::Formatter.new end From 60d659e75575d24a18bbb05e7aa0dc1b2de06065 Mon Sep 17 00:00:00 2001 From: Eric Saupe Date: Tue, 7 Feb 2017 22:51:03 -0700 Subject: [PATCH 6/6] Fixed issues where methods were not using eth_ --- lib/ethereum/contract.rb | 15 ++++++++++++--- lib/ethereum/deployment.rb | 14 +++++++------- spec/ethereum_spec.rb | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/ethereum/contract.rb b/lib/ethereum/contract.rb index b956371..0479b56 100644 --- a/lib/ethereum/contract.rb +++ b/lib/ethereum/contract.rb @@ -43,7 +43,16 @@ def build(connection) end end deploy_payload = deploy_code + deploy_arguments - deploytx = connection.send_single({from: self.sender, gas: self.gas, gasPrice: self.gas_price, data: "0x" + deploy_payload}.to_json)["result"] + tx_payload = { + jsonrpc: "2.0", + method: "eth_sendTransaction", + params: [{ + from: self.sender, + data: deploy_payload + }], + id: connection.get_id + }.to_json + deploytx = JSON.parse(connection.send_single(tx_payload))["result"] instance_variable_set("@deployment", Ethereum::Deployment.new(deploytx, connection)) end @@ -169,7 +178,7 @@ def build(connection) arg_types.zip(args).each do |arg| payload << formatter.to_payload(arg) end - raw_result = connection.call({to: self.address, from: self.sender, data: payload.join()})["result"] + raw_result = connection.eth_call({to: self.address, from: self.sender, data: "0x" + payload.join()})["result"] formatted_result = fun.outputs.collect {|x| x.type }.zip(raw_result.gsub(/^0x/,'').scan(/.{64}/)) output = formatted_result.collect {|x| formatter.from_payload(x) } return {data: "0x" + payload.join(), raw: raw_result, formatted: output} @@ -195,7 +204,7 @@ def build(connection) arg_types.zip(args).each do |arg| payload << formatter.to_payload(arg) end - txid = connection.send_single({to: self.address, from: self.sender, data: "0x" + payload.join(), gas: self.gas, gasPrice: self.gas_price})["result"] + txid = connection.send_single({to: self.address, from: self.sender, data: "0x" + payload.join(), gas: self.gas, gasPrice: self.gas_price}.to_json)["result"] return Ethereum::Transaction.new(txid, self.connection, payload.join(), args) end diff --git a/lib/ethereum/deployment.rb b/lib/ethereum/deployment.rb index 97e6e06..c5f13a8 100644 --- a/lib/ethereum/deployment.rb +++ b/lib/ethereum/deployment.rb @@ -14,29 +14,29 @@ def initialize(txid, connection) def mined? return true if @mined - @mined = @connection.get_transaction_by_hash(@id)["result"]["blockNumber"].present? rescue nil + @mined = @connection.eth_get_transaction_by_hash(@id)["result"]["blockNumber"].present? rescue nil @mined ||= false end def has_address? return true if @contract_address.present? - return false unless self.mined? - @contract_address ||= @connection.get_transaction_receipt(@id)["result"]["contractAddress"] + return false unless self.mined? + @contract_address ||= @connection.eth_get_transaction_receipt(@id)["result"]["contractAddress"] return @contract_address.present? end def deployed? return true if @valid_deployment return false unless self.has_address? - @valid_deployment = @connection.get_code(@contract_address)["result"] != "0x" + @valid_deployment = @connection.eth_get_transaction_receipt(@contract_address)["result"] != "0x" end def wait_for_deployment(timeout = 1500.seconds) start_time = Time.now while self.deployed? == false - raise "Transaction #{@id} timed out." if ((Time.now - start_time) > timeout) - sleep 5 - return true if self.deployed? + raise "Transaction #{@id} timed out." if ((Time.now - start_time) > timeout) + sleep 5 + return true if self.deployed? end end diff --git a/spec/ethereum_spec.rb b/spec/ethereum_spec.rb index 4dd2f8d..9b90340 100644 --- a/spec/ethereum_spec.rb +++ b/spec/ethereum_spec.rb @@ -3,7 +3,7 @@ describe Ethereum do before(:all) do - @client = Ethereum::HttpClient.new("172.16.135.102", "8545") + @client = Ethereum::HttpClient.new("localhost", "8545") @formatter = Ethereum::Formatter.new end