web3-eth 0.2.24 → 0.2.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/web3/eth/abi/abi_coder.rb +23 -2
- data/lib/web3/eth/contract.rb +47 -2
- data/lib/web3/eth/transaction.rb +1 -13
- data/lib/web3/eth/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33bd4cdb2606f3062e84ccbc4429052a3dce2def
|
4
|
+
data.tar.gz: 1fa19d0bcfde6f6d467f295940353f7250a3c99b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dae87035bfeeaa1b67978281030a052a23f0caf52db741d2b387effff6543dd2d31d99a6bb8155c93ac602457e4d5cbd84c8e35d756364b3b7c28c2463575655
|
7
|
+
data.tar.gz: b3fb6aab3c77c4b3362e688b64ef846e08c735fdb50d16842a0c10ac30f931716f94f0caf311a7ccdfe6cc0d4a06d73c451b1fc4609282c8a213f0d84a77bc3a
|
@@ -192,10 +192,15 @@ module Web3::Eth::Abi
|
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
|
+
|
196
|
+
def min_data_size types
|
197
|
+
types.size*32
|
198
|
+
end
|
199
|
+
|
195
200
|
##
|
196
201
|
# Decodes multiple arguments using the head/tail mechanism.
|
197
202
|
#
|
198
|
-
def decode_abi
|
203
|
+
def decode_abi types, data, raise_errors = false
|
199
204
|
parsed_types = types.map {|t| Type.parse(t) }
|
200
205
|
|
201
206
|
outputs = [nil] * types.size
|
@@ -207,8 +212,17 @@ module Web3::Eth::Abi
|
|
207
212
|
# If a type is static, grab the data directly, otherwise record its
|
208
213
|
# start position
|
209
214
|
if t.dynamic?
|
215
|
+
|
216
|
+
if raise_errors && pos>data.size-1
|
217
|
+
raise DecodingError, "Position out of bounds #{pos}>#{data.size-1}"
|
218
|
+
end
|
219
|
+
|
210
220
|
start_positions[i] = Utils.big_endian_to_int(data[pos, 32])
|
211
221
|
|
222
|
+
if raise_errors && start_positions[i]>data.size-1
|
223
|
+
raise DecodingError, "Start position out of bounds #{start_positions[i]}>#{data.size-1}"
|
224
|
+
end
|
225
|
+
|
212
226
|
j = i - 1
|
213
227
|
while j >= 0 && start_positions[j].nil?
|
214
228
|
start_positions[j] = start_positions[i]
|
@@ -230,7 +244,10 @@ module Web3::Eth::Abi
|
|
230
244
|
j -= 1
|
231
245
|
end
|
232
246
|
|
233
|
-
|
247
|
+
if raise_errors && pos > data.size
|
248
|
+
raise DecodingError, "Not enough data for head"
|
249
|
+
end
|
250
|
+
|
234
251
|
|
235
252
|
parsed_types.each_with_index do |t, i|
|
236
253
|
if t.dynamic?
|
@@ -241,6 +258,10 @@ module Web3::Eth::Abi
|
|
241
258
|
end
|
242
259
|
end
|
243
260
|
|
261
|
+
if raise_errors && outputs.include?(nil)
|
262
|
+
raise DecodingError, "Not all data can be parsed"
|
263
|
+
end
|
264
|
+
|
244
265
|
parsed_types.zip(outputs).map {|(type, out)| decode_type(type, out) }
|
245
266
|
end
|
246
267
|
alias :decode :decode_abi
|
data/lib/web3/eth/contract.rb
CHANGED
@@ -103,6 +103,52 @@ module Web3
|
|
103
103
|
|
104
104
|
end
|
105
105
|
|
106
|
+
class ContractConstructor < ContractMethod
|
107
|
+
|
108
|
+
def initialize abi
|
109
|
+
super abi
|
110
|
+
end
|
111
|
+
|
112
|
+
def parse_method_args transaction
|
113
|
+
return [] if input_types.empty?
|
114
|
+
|
115
|
+
input = transaction.input
|
116
|
+
|
117
|
+
d = fetch_constructor_data input
|
118
|
+
result = (d && !d.empty? && try_parse(d))
|
119
|
+
|
120
|
+
unless result
|
121
|
+
start = input.length-1-min_data_size(input_types)
|
122
|
+
while start>=0 && !result
|
123
|
+
result = try_parse input, start
|
124
|
+
start -= 1
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
result
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
CONSTRUCTOR_SEQ = /a165627a7a72305820\w{64}0029(\w*)$/
|
134
|
+
def fetch_constructor_data input
|
135
|
+
data = input[CONSTRUCTOR_SEQ,1]
|
136
|
+
while data && (d = data[CONSTRUCTOR_SEQ,1])
|
137
|
+
data = d
|
138
|
+
end
|
139
|
+
data
|
140
|
+
end
|
141
|
+
|
142
|
+
def try_parse input, start = 0
|
143
|
+
d = start==0 ? input : input.slice(start, input.length-start-1)
|
144
|
+
decode_abi input_types, [d].pack('H*'), true
|
145
|
+
rescue Exception => err
|
146
|
+
nil
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
|
106
152
|
attr_reader :web3_rpc, :abi, :functions, :events, :constructor, :functions_by_hash, :events_by_hash
|
107
153
|
|
108
154
|
def initialize abi, web_rpc = nil
|
@@ -168,8 +214,7 @@ module Web3
|
|
168
214
|
@events[method.name] = method
|
169
215
|
@events_by_hash[method.signature_hash] = method
|
170
216
|
when 'constructor'
|
171
|
-
|
172
|
-
@constructor = method
|
217
|
+
@constructor = ContractConstructor.new(a)
|
173
218
|
end
|
174
219
|
}
|
175
220
|
end
|
data/lib/web3/eth/transaction.rb
CHANGED
@@ -26,9 +26,7 @@ module Web3
|
|
26
26
|
# suffix # 0xa1 0x65 'b' 'z' 'z' 'r' '0' 0x58 0x20 <32 bytes swarm hash> 0x00 0x29
|
27
27
|
# look http://solidity.readthedocs.io/en/latest/metadata.html for details
|
28
28
|
def call_input_data
|
29
|
-
if
|
30
|
-
fetch_constructor_data input
|
31
|
-
elsif input && input.length>10
|
29
|
+
if input && input.length>10
|
32
30
|
input[10..input.length]
|
33
31
|
else
|
34
32
|
[]
|
@@ -57,16 +55,6 @@ module Web3
|
|
57
55
|
wei_to_ether from_hex gasPrice
|
58
56
|
end
|
59
57
|
|
60
|
-
private
|
61
|
-
|
62
|
-
CONSTRUCTOR_SEQ = /a165627a7a72305820\w{64}0029(\w*)$/
|
63
|
-
def fetch_constructor_data input
|
64
|
-
data = input[CONSTRUCTOR_SEQ,1]
|
65
|
-
while data && (d = data[CONSTRUCTOR_SEQ,1])
|
66
|
-
data = d
|
67
|
-
end
|
68
|
-
data
|
69
|
-
end
|
70
58
|
|
71
59
|
end
|
72
60
|
end
|
data/lib/web3/eth/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web3-eth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- studnev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rlp
|