ethereum.rb 2.0.8 → 2.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d44fa6975ccab8a2bdf50c15d4ee88740bd8c95
4
- data.tar.gz: 9e49ac4b565a4dc53ab0e0230a3e5efc80ef0dd0
3
+ metadata.gz: 6b37350a4448636d876aaeb83825c01b2903b4e8
4
+ data.tar.gz: ec8e0b741ce6d4f3a7b4ed1125d5e34ebb0f522a
5
5
  SHA512:
6
- metadata.gz: 5ba25561adbf97eb5f446701baa37f494fdfceb7e66e585205b1e638a0fa9b45a45b32a23f84200690311b058eb28f839e28f1256d59a0fab7060f4bbfe45171
7
- data.tar.gz: 1fac810a2532aacbca80928b9022778b2646c637b0ba669094df6a65f7640d01c72469e2c76a432b0a37f7b4a02288030bb3ce6ba939ad04ee7c253aefc40379
6
+ metadata.gz: 7cfdc7e200941bf4876eb809f7929e9cd8a110f75eec933660814027891c3e56e2c024571587720be515e8549c90bfa6fb3d52e0bfd27c277c3bfb999b76b7f1
7
+ data.tar.gz: 53b4188861d6f9f901bbcdcce2f7d9c7f22525633b42281ad4ff5ea047d2ac7e802892f8ce2a5af0f7834f20c0257a6fa75760b990fba632b1293901b5b636af
@@ -2,6 +2,7 @@ module Ethereum
2
2
  class Contract
3
3
 
4
4
  attr_reader :address
5
+ attr_accessor :key
5
6
  attr_accessor :gas, :gas_price
6
7
  attr_accessor :code, :name, :abi, :class_object, :sender, :deployment, :client
7
8
  attr_accessor :events, :functions, :constructor_inputs
@@ -44,15 +45,32 @@ module Ethereum
44
45
  end
45
46
  end
46
47
 
47
- def deploy(*params)
48
+ def deploy_payload(params)
48
49
  if @constructor_inputs.present?
49
- raise "Missing constructor parameter" and return if params.length != @constructor_inputs.length
50
+ raise ArgumentError, "Wrong number of arguments in a constructor" and return if params.length != @constructor_inputs.length
50
51
  end
51
52
  deploy_arguments = @encoder.encode_arguments(@constructor_inputs, params)
52
- payload = "0x" + @code + deploy_arguments
53
- args = add_gas_options_args({from: sender, data: payload})
54
- tx = @client.eth_send_transaction(args)["result"]
55
- raise IOError, "Failed to deploy, did you unlock #{sender} account? Transaction hash: #{tx}" if tx.nil? || tx == "0x0000000000000000000000000000000000000000000000000000000000000000"
53
+ "0x" + @code + deploy_arguments
54
+ end
55
+
56
+ def deploy_args(params)
57
+ add_gas_options_args({from: sender, data: deploy_payload(params)})
58
+ end
59
+
60
+ def send_transaction(tx_args)
61
+ if key
62
+ Eth.configure { |c| c.chain_id = @client.net_version["result"].to_i }
63
+ tx = Eth::Tx.new({ from: key.address, to: main_address, value: value, data: data, nonce: 0, gas_limit: 1_000_000, gas_price: gas_price})
64
+ tx.sign key
65
+ else
66
+ @client.eth_send_transaction(tx_args)["result"]
67
+ end
68
+ end
69
+
70
+ def deploy(*params)
71
+ tx = send_transaction(deploy_args(params))
72
+ tx_failed = tx.nil? || tx == "0x0000000000000000000000000000000000000000000000000000000000000000"
73
+ raise IOError, "Failed to deploy, did you unlock #{sender} account? Transaction hash: #{tx}" if tx_failed
56
74
  @deployment = Ethereum::Deployment.new(tx, @client)
57
75
  end
58
76
 
@@ -67,22 +85,22 @@ module Ethereum
67
85
  end
68
86
 
69
87
  def estimate(*params)
70
- deploy_arguments = ""
71
- if @constructor_inputs.present?
72
- raise "Wrong number of arguments in a constructor" and return if params.length != @constructor_inputs.length
73
- deploy_arguments = @encoder.encode_arguments(@constructor_inputs, params)
74
- end
75
- deploy_payload = @code + deploy_arguments
76
- result = @client.eth_estimate_gas({from: @sender, data: "0x" + deploy_payload})
88
+ result = @client.eth_estimate_gas(deploy_args(params))
77
89
  @decoder.decode_int(result["result"])
78
90
  end
79
91
 
92
+ def call_payload(fun, args)
93
+ "0x" + fun.signature + @encoder.encode_arguments(fun.inputs, args)
94
+ end
95
+
96
+ def call_args(fun, args)
97
+ add_gas_options_args({to: @address, from: @sender, data: call_payload(fun, args)})
98
+ end
99
+
80
100
  def call_raw(fun, *args)
81
- payload = fun.signature + @encoder.encode_arguments(fun.inputs, args)
82
- raw_result = @client.eth_call({to: @address, from: @sender, data: "0x" + payload})
83
- raw_result = raw_result["result"]
101
+ raw_result = @client.eth_call(call_args(fun, args))["result"]
84
102
  output = @decoder.decode_arguments(fun.outputs, raw_result)
85
- return {data: "0x" + payload, raw: raw_result, formatted: output}
103
+ return {data: call_payload(fun, args), raw: raw_result, formatted: output}
86
104
  end
87
105
 
88
106
  def call(fun, *args)
@@ -95,10 +113,8 @@ module Ethereum
95
113
  end
96
114
 
97
115
  def transact(fun, *args)
98
- payload = fun.signature + @encoder.encode_arguments(fun.inputs, args)
99
- args = {to: @address, from: @sender, data: "0x" + payload}
100
- txid = @client.eth_send_transaction(add_gas_options_args(args))["result"]
101
- return Ethereum::Transaction.new(txid, @client, payload, args)
116
+ tx = send_transaction(call_args(fun, args))
117
+ return Ethereum::Transaction.new(tx, @client, call_payload(fun, args), args)
102
118
  end
103
119
 
104
120
  def transact_and_wait(fun, *args)
@@ -153,6 +169,7 @@ module Ethereum
153
169
  create_event_proxies
154
170
  class_methods = Class.new do
155
171
  extend Forwardable
172
+ def_delegators :parent, :deploy_payload, :deploy_args, :call_payload, :call_args
156
173
  def_delegators :parent, :gas, :gas_price, :gas=, :gas_price=
157
174
  def_delegators :parent, :abi, :deployment, :events
158
175
  def_delegators :parent, :estimate, :deploy, :deploy_and_wait
@@ -1,3 +1,3 @@
1
1
  module Ethereum
2
- VERSION = "2.0.8"
2
+ VERSION = "2.0.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ethereum.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Kirejczyk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-03 00:00:00.000000000 Z
11
+ date: 2017-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler