web3-hpb 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b7e982320fc9431c55b9ed18807faf4feb1e959e70abf311a562e64aee2a5312
4
+ data.tar.gz: 38e2cd202a29c2e776b9d531a490a23107714e484601a428464e2e3e55bfbaae
5
+ SHA512:
6
+ metadata.gz: b05becc6a38e14f9a67da0e4810ca4b3fc09431b0dd07f82cd236bb0fac45eeaccc3aca5c8e706f7d4192aedadc5264872bc18d6029c3cbff9cd9c98f4ceb4aa
7
+ data.tar.gz: d034534dfc9031cb5cb4d6887a6c843cd7e93feabf482728dfc7b4071c1f0e9fda966be8dd69c24361a57bf768465fba639c1a11e7e469a516fe08ab13f2bdb2
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.2
7
+ before_install: gem install bundler -v 1.16.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sean.shen@hpb.io. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in web3-hpb.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ web3-hpb (0.0.2)
5
+ digest-sha3 (~> 1.1.0)
6
+ rlp (~> 0.7.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ digest-sha3 (1.1.0)
12
+ minitest (5.11.3)
13
+ rake (10.4.2)
14
+ rlp (0.7.3)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.14)
21
+ minitest (~> 5.0)
22
+ rake (~> 10.0)
23
+ web3-hpb!
24
+
25
+ BUNDLED WITH
26
+ 1.16.4
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # Web3::Hpb
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/web3/hpb`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'web3-hpb'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install web3-hpb
22
+
23
+ ## Usage
24
+
25
+ ### 连接
26
+ 初始化一个web3对象
27
+ ```ruby
28
+ web3 = Web3::Hpb::Rpc.new
29
+ ```
30
+ 默认配置为
31
+ ```ruby
32
+ web3 = Web3::Hpb::Rpc.new host: 'node.host.com',
33
+ port: 8545,
34
+ connect_options: { use_ssl: true, read_timeout: 120 }
35
+ ```
36
+
37
+ ### 使用hpb接口
38
+
39
+ ```
40
+ >> web3.hpb.blockNumber
41
+ 4376369
42
+
43
+ >> web3.hpb.getBalance '0x4c8a1996754c11ac255c747fdb36a4288d230541'
44
+ 3916.6597314456685
45
+
46
+ >> block = web3.hpb.getBlockByNumber 4376369
47
+ #<Web3::Hpb::Block:0x007f844d6f1138 @block_data={"author"=>"0x4c8a1996754c11ac255c797fdb36f4288d230541", ...
48
+
49
+ >> block.timestamp_time
50
+ 2017-10-17 12:51:36 +0300
51
+
52
+ >> block.transactions.count
53
+ 129
54
+
55
+ >> block.transactions[0].from
56
+ "0x4c8a199481ac255c747fdb36f4288d230541"
57
+
58
+ >> block.transactions[0].value_eth
59
+ 0.51896811
60
+
61
+ ```
62
+
63
+ ### 使用abi接口
64
+ ```
65
+ # creation of contract object
66
+ myContract = web3.hpb.contract(abi);
67
+
68
+ # initiate contract for an address
69
+ myContractInstance = myContract.at('0x57d180cbaffbc97237f572148fc1b283b68d8861');
70
+
71
+ # call constant function
72
+ result = myContractInstance.balanceOf('0x...'); # any constant method works
73
+ ```
74
+
75
+ ## Development
76
+
77
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
78
+
79
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
80
+
81
+ ## Contributing
82
+
83
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/web3-hpb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
84
+
85
+ ## Code of Conduct
86
+
87
+ Everyone interacting in the Web3::Hpb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/web3-hpb/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "web3/hpb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/web3/hpb.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "web3/hpb/version"
2
+ require "web3/hpb/abi/abi_coder"
3
+ require "web3/hpb/utility"
4
+ require "web3/hpb/block"
5
+ require "web3/hpb/transaction"
6
+ require "web3/hpb/contract"
7
+ require "web3/hpb/call_trace"
8
+ require "web3/hpb/log"
9
+ require "web3/hpb/transaction_receipt"
10
+ require "web3/hpb/hpb_module"
11
+ require "web3/hpb/trace_module"
12
+ require "web3/hpb/rpc"
@@ -0,0 +1,389 @@
1
+ # -*- encoding : ascii-8bit -*-
2
+
3
+ require 'web3/hpb/abi/type'
4
+ require 'web3/hpb/abi/constant'
5
+ require 'web3/hpb/abi/exceptions'
6
+ require 'web3/hpb/abi/utils'
7
+
8
+ module Web3::Hpb::Abi
9
+ ##
10
+ # abi的解码和编码
11
+ # Contract ABI encoding and decoding.
12
+ #
13
+ module AbiCoder
14
+ extend self
15
+
16
+ include Constant
17
+ class EncodingError < StandardError; end
18
+ class DecodingError < StandardError; end
19
+ class ValueOutOfBounds < ValueError; end
20
+
21
+ ##
22
+ # 使用head/tail机制编码多个参数
23
+ # Encodes multiple arguments using the head/tail mechanism.
24
+ #
25
+ def encode_abi(types, args)
26
+ parsed_types = types.map{ |t| Type.parse(t) }
27
+ head_size = (0...args.size)
28
+ .map{ |i| parsed_types[i].size || 32 }
29
+ .reduce(0, &:+)
30
+
31
+ head, tail = '', ''
32
+ args.each_with_index do |arg, i|
33
+ if parsed_types[i].dynamic?
34
+ head += encode_type(Type.size_type, head_size, tail.size)
35
+ tail += encode_type(parsed_types[i], arg)
36
+ else
37
+ head += encode_type(parsed_types[i], arg)
38
+ end
39
+ end
40
+
41
+ "#{head}#{tail}"
42
+ end
43
+
44
+ alias :encode :encode_abi
45
+
46
+ ##
47
+ # Encodes a single value (static or dynamic).
48
+ #
49
+ # @param type [HPB::ABI::Type] value type
50
+ # @param arg [Object] value
51
+ #
52
+ # @return [String] encoded bytes
53
+ #
54
+
55
+ def encode_type(type, arg)
56
+
57
+ if %w(string bytes).include?(type.base) && type.sub.empty?
58
+ encode_primitive_type(type, arg)
59
+ elsif type.dynamic?
60
+
61
+ raise ArgumentRrror, "arg must be an array" unless arg.instance_of?(Array)
62
+
63
+ head, tail = '', ''
64
+ if type.dims.last == 0
65
+ head += encode_type(Type.size_type, arg.size)
66
+ else
67
+ raise ArgumentError, "Wrong array size: found #{arg.size}, expecting #{type.dims.last}" unless arg.size == type.dims.last
68
+ end
69
+
70
+ sub_type = type.subtype
71
+ sub_size = type.subtype.size
72
+
73
+ arg.size.times do |i|
74
+ if sub_size.nil?
75
+ head += encode_type(Type.size_type, 32*arg.size + tail.size)
76
+ tail += encode_type(sub_type, arg[i])
77
+ else
78
+ head += encode_type(sub_type, arg[i])
79
+ end
80
+ end
81
+
82
+ "#{head}#{tail}"
83
+ else # static type
84
+ if type.dims.empty?
85
+ encode_primitive_type(type, arg)
86
+ else
87
+ arg.map { |x| encode_type(type.subtype, x) }.join
88
+ end
89
+ end
90
+ end
91
+
92
+ def encode_primitive_type(type, arg)
93
+ case type.base
94
+ when 'uint'
95
+ begin
96
+ real_size = type.sub.to_i
97
+ i = get_uint(arg)
98
+
99
+ raise ValueOutOfBounds, arg unless i >= 0 && i < 2**real_size
100
+ Utils.zpad_int(i)
101
+ rescue EncodingError
102
+ raise ValueOutOfBounds, arg
103
+ end
104
+ when 'bool'
105
+ raise ArgumentError, "arg is not bool: #{arg}" unless arg.instance_of?(TrueClass) || arg.instance_of?(FalseClass)
106
+ Utils.zpad_int(arg ? 1 : 0)
107
+ when 'int'
108
+ begin
109
+ real_size = type.sub.to_i
110
+ i = get_int(arg)
111
+
112
+ raise ValueOutOfBounds, arg unless i >= -2**(real_size-1) && i < 2**(real_size-1)
113
+ Utils.zpad_int(i % 2**type.sub.to_i)
114
+ rescue EncodingError
115
+ raise ValueOutOfBounds, arg
116
+ end
117
+ when 'ufixed'
118
+ high, low = type.sub.split('x').map(&:to_i)
119
+
120
+ raise ValueOutOfBounds, arg unless arg >= 0 && arg < 2**high
121
+ Utils.zpad_int((arg * 2**low).to_i)
122
+ when 'fixed'
123
+ high, low = type.sub.split('x').map(&:to_i)
124
+
125
+ raise ValueOutOfBounds, arg unless arg >= -2**(high - 1) && arg < 2**(high - 1)
126
+
127
+ i = (arg * 2**low).to_i
128
+ Utils.zpad_int(i % 2**(high+low))
129
+ when 'string'
130
+ if arg.encoding.name == 'UTF-8'
131
+ arg = arg.b
132
+ else
133
+ begin
134
+ arg.unpack('U*')
135
+ rescue ArgumentError
136
+ raise ValueError, "string must be UTF-8 encoded"
137
+ end
138
+ end
139
+
140
+ if type.sub.empty? # variable length type
141
+ raise ValueOutOfBounds, "Integer invalid or out of range: #{arg.size}" if arg.size >= TT256
142
+ size = Utils.zpad_int(arg.size)
143
+ value = Utils.rpad(arg, BYTE_ZERO, Utils.ceil32(arg.size))
144
+ "#{size}#{value}"
145
+ else # fixed length type
146
+ sub = type.sub.to_i
147
+ raise ValueOutOfBounds, "invalid string length #{sub}" if arg.size > sub
148
+ raise ValueOutOfBounds, "invalid string length #{sub}" if sub < 0 || sub > 32
149
+ Utils.rpad(arg, BYTE_ZERO, 32)
150
+ end
151
+ when 'bytes'
152
+ raise EncodingError, "Expecting string: #{arg}" unless arg.instance_of?(String)
153
+ arg = arg.b
154
+
155
+ if type.sub.empty? # variable length type
156
+ raise ValueOutOfBounds, "Integer invalid or out of range: #{arg.size}" if arg.size >= TT256
157
+ size = Utils.zpad_int(arg.size)
158
+ value = Utils.rpad(arg, BYTE_ZERO, Utils.ceil32(arg.size))
159
+ "#{size}#{value}"
160
+ else # fixed length type
161
+ sub = type.sub.to_i
162
+ raise ValueOutOfBounds, "invalid bytes length #{sub}" if arg.size > sub
163
+ raise ValueOutOfBounds, "invalid bytes length #{sub}" if sub < 0 || sub > 32
164
+ Utils.rpad(arg, BYTE_ZERO, 32)
165
+ end
166
+ when 'hash'
167
+ size = type.sub.to_i
168
+ raise EncodingError, "too long: #{arg}" unless size > 0 && size <= 32
169
+
170
+ if arg.is_a?(Integer)
171
+ Utils.zpad_int(arg)
172
+ elsif arg.size == size
173
+ Utils.zpad(arg, 32)
174
+ elsif arg.size == size * 2
175
+ Utils.zpad_hex(arg)
176
+ else
177
+ raise EncodingError, "Could not parse hash: #{arg}"
178
+ end
179
+ when 'address'
180
+ if arg.is_a?(Integer)
181
+ Utils.zpad_int(arg)
182
+ elsif arg.size == 20
183
+ Utils.zpad(arg, 32)
184
+ elsif arg.size == 40
185
+ Utils.zpad_hex(arg)
186
+ elsif arg.size == 42 && arg[0,2] == '0x'
187
+ Utils.zpad_hex(arg[2..-1])
188
+ else
189
+ raise EncodingError, "Could not parse address: #{arg}"
190
+ end
191
+ else
192
+ raise EncodingError, "Unhandled type: #{type.base} #{type.sub}"
193
+ end
194
+ end
195
+
196
+ ##
197
+ # Decodes multiple arguments using the head/tail mechanism.
198
+ #
199
+ def decode_abi(types, data)
200
+ parsed_types = types.map {|t| Type.parse(t) }
201
+
202
+ outputs = [nil] * types.size
203
+ start_positions = [nil] * types.size + [data.size]
204
+
205
+ # TODO: refactor, a reverse iteration will be better
206
+ pos = 0
207
+ parsed_types.each_with_index do |t, i|
208
+ # If a type is static, grab the data directly, otherwise record its
209
+ # start position
210
+ if t.dynamic?
211
+ start_positions[i] = Utils.big_endian_to_int(data[pos, 32])
212
+
213
+ j = i - 1
214
+ while j >= 0 && start_positions[j].nil?
215
+ start_positions[j] = start_positions[i]
216
+ j -= 1
217
+ end
218
+
219
+ pos += 32
220
+ else
221
+ outputs[i] = data[pos, t.size]
222
+ pos += t.size
223
+ end
224
+ end
225
+
226
+ # We add a start position equal to the length of the entire data for
227
+ # convenience.
228
+ j = types.size - 1
229
+ while j >= 0 && start_positions[j].nil?
230
+ start_positions[j] = start_positions[types.size]
231
+ j -= 1
232
+ end
233
+
234
+ #raise DecodingError, "Not enough data for head" unless pos <= data.size
235
+
236
+ parsed_types.each_with_index do |t, i|
237
+ if t.dynamic?
238
+ offset, next_offset = start_positions[i, 2]
239
+ outputs[i] = data[offset...next_offset]
240
+ end
241
+ end
242
+
243
+ parsed_types.zip(outputs).map {|(type, out)| decode_type(type, out) }
244
+ end
245
+
246
+ alias :decode :decode_abi
247
+
248
+ def decode_typed_data type_name, data
249
+ decode_primitive_type Type.parse(type_name), data
250
+ end
251
+
252
+ def decode_type(type, arg)
253
+ if %w(string bytes).include?(type.base) && type.sub.empty?
254
+ l = Utils.big_endian_to_int arg[0,32]
255
+ data = arg[32..-1]
256
+ data[0, l]
257
+ elsif type.dynamic?
258
+ l = Utils.big_endian_to_int arg[0,32]
259
+ subtype = type.subtype
260
+
261
+ if subtype.dynamic?
262
+ raise DecodingError, "Not enough data for head" unless arg.size >= 32 + 32*l
263
+
264
+ start_positions = (1..l).map {|i| Utils.big_endian_to_int arg[32*i, 32] }
265
+ start_positions.push arg.size
266
+
267
+ outputs = (0...l).map {|i| arg[start_positions[i]...start_positions[i+1]] }
268
+
269
+ outputs.map {|out| decode_type(subtype, out) }
270
+ else
271
+ (0...l).map {|i| decode_type(subtype, arg[32 + subtype.size*i, subtype.size]) }
272
+ end
273
+ elsif !type.dims.empty? # static-sized arrays
274
+ l = type.dims.last
275
+ subtype = type.subtype
276
+
277
+ (0...l).map {|i| decode_type(subtype, arg[subtype.size*i, subtype.size]) }
278
+ else
279
+ decode_primitive_type type, arg
280
+ end
281
+ end
282
+
283
+ def decode_primitive_type(type, data)
284
+ case type.base
285
+ when 'address'
286
+ Utils.encode_hex data[12..-1]
287
+ when 'string', 'bytes'
288
+ if type.sub.empty? # dynamic
289
+ if data.length==32
290
+ data[0..32]
291
+ else
292
+ size = Utils.big_endian_to_int data[0,32]
293
+ data[32..-1][0,size]
294
+ end
295
+ else # fixed
296
+ data[0, type.sub.to_i]
297
+ end
298
+ when 'hash'
299
+ data[(32 - type.sub.to_i), type.sub.to_i]
300
+ when 'uint'
301
+ Utils.big_endian_to_int data
302
+ when 'int'
303
+ u = Utils.big_endian_to_int data
304
+ u >= 2**(type.sub.to_i-1) ? (u - 2**type.sub.to_i) : u
305
+ when 'ufixed'
306
+ high, low = type.sub.split('x').map(&:to_i)
307
+ Utils.big_endian_to_int(data) * 1.0 / 2**low
308
+ when 'fixed'
309
+ high, low = type.sub.split('x').map(&:to_i)
310
+ u = Utils.big_endian_to_int data
311
+ i = u >= 2**(high+low-1) ? (u - 2**(high+low)) : u
312
+ i * 1.0 / 2**low
313
+ when 'bool'
314
+ data[-1] == BYTE_ONE
315
+ else
316
+ raise DecodingError, "Unknown primitive type: #{type.base}"
317
+ end
318
+ end
319
+
320
+ private
321
+
322
+ def get_uint(n)
323
+ case n
324
+ when Integer
325
+ raise EncodingError, "Number out of range: #{n}" if n > UINT_MAX || n < UINT_MIN
326
+ n
327
+ when String
328
+ i = if n.size == 40
329
+ Utils.decode_hex(n)
330
+ elsif n.size <= 32
331
+ n
332
+ else
333
+ raise EncodingError, "String too long: #{n}"
334
+ end
335
+ i = Utils.big_endian_to_int i
336
+
337
+ raise EncodingError, "Number out of range: #{i}" if i > UINT_MAX || i < UINT_MIN
338
+ i
339
+ when true
340
+ 1
341
+ when false, nil
342
+ 0
343
+ else
344
+ raise EncodingError, "Cannot decode uint: #{n}"
345
+ end
346
+ end
347
+
348
+ def get_int(n)
349
+ case n
350
+ when Integer
351
+ raise EncodingError, "Number out of range: #{n}" if n > INT_MAX || n < INT_MIN
352
+ n
353
+ when String
354
+ i = if n.size == 40
355
+ Utils.decode_hex(n)
356
+ elsif n.size <= 32
357
+ n
358
+ else
359
+ raise EncodingError, "String too long: #{n}"
360
+ end
361
+ i = Utils.big_endian_to_int i
362
+
363
+ i = i > INT_MAX ? (i-TT256) : i
364
+ raise EncodingError, "Number out of range: #{i}" if i > INT_MAX || i < INT_MIN
365
+ i
366
+ when true
367
+ 1
368
+ when false, nil
369
+ 0
370
+ else
371
+ raise EncodingError, "Cannot decode int: #{n}"
372
+ end
373
+ end
374
+
375
+ end
376
+ end
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+