ethlite 0.2.5 → 0.3.0

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
  SHA256:
3
- metadata.gz: 3cd659223f8049ca63302c5bb595da6faf483d29d776ed747b5970dde11b415e
4
- data.tar.gz: fde6fca03683dac98d474d82bc520a82dc45e74b08eaabbc0c521e2635ca3d3b
3
+ metadata.gz: f4c28e1b125fefa2964c88a020a14de2d0e95c412e16f50ba5a329382465ccf8
4
+ data.tar.gz: 324e941a6825091bbf88539eb31acd03b80e8732c61442580a092bbdefe4e845
5
5
  SHA512:
6
- metadata.gz: 050226ff51c20a38cb8f1db254e246a555d07baf8a6e12766985850400749a463698e89818780cd031e5ed3cab6bb05e2afae37588149084160138d5e6783e0f
7
- data.tar.gz: 0d16770efc489cf88f08ec8ef471563905b2197c1d8330c58558348f1a9076dd717f654b5c221ea78052d31855bb458105c79f2f7ec1021a04451a202088b722
6
+ metadata.gz: df7dae52f733638a324dceb46371e1ecf6043f75515dc75ced197dfe1e24194b91e75f693f441861a122294e5d2408338584ee2b41a94ff64a277c0739fc9f8f
7
+ data.tar.gz: 171eea690f22474462316642eea60971eed702b6604681c3126b5900a134c196eb7cd07111d304086410e3ff46ccf7d73c61b2570c3430e563502ee6bf7e55ba
data/Manifest.txt CHANGED
@@ -5,10 +5,10 @@ Rakefile
5
5
  lib/digest/keccak.rb
6
6
  lib/digest/sha3.rb
7
7
  lib/ethlite.rb
8
- lib/ethlite/abi/abi_coder.rb
8
+ lib/ethlite/abi/codec.rb
9
9
  lib/ethlite/abi/type.rb
10
- lib/ethlite/abi/utils.rb
11
10
  lib/ethlite/constant.rb
12
11
  lib/ethlite/contract.rb
12
+ lib/ethlite/utils.rb
13
13
  lib/ethlite/version.rb
14
14
  lib/jsonrpc/jsonrpc.rb
data/README.md CHANGED
@@ -44,7 +44,7 @@ token_ids = (0..9)
44
44
  token_ids.each do |token_id|
45
45
 
46
46
  puts "==> calling tokenURI(#{token_id})..."
47
- tokenURI = eth_call( contract_address,
47
+ tokenURI = eth_call( ETH_NODE, contract_address,
48
48
  'tokenURI', ['uint256'], ['string'],
49
49
  [token_id] )
50
50
  puts " ...returns: #{tokenURI}"
@@ -56,14 +56,15 @@ And the "magic" hand-coded to-the-metal `eth_call` machinery:
56
56
 
57
57
  ```ruby
58
58
  ## construct a json-rpc call from scratch
59
- def eth_call( contract_address,
59
+ def eth_call( rpc,
60
+ contract_address,
60
61
  name, inputs, outputs,
61
62
  args )
62
63
 
63
64
  ## binary encode method sig(nature)
64
65
  signature = "#{name}(#{inputs.join(',')})"
65
- signature_hash = Ethlite::Abi::Utils.encode_hex(
66
- Ethlite::Abi::Utils.keccak256(signature))[0..7]
66
+ signature_hash = Ethlite::Utils.encode_hex(
67
+ Ethlite::Utils.keccak256(signature))[0..7]
67
68
 
68
69
  pp signature
69
70
  # => "tokenURI(uint256)"
@@ -71,8 +72,8 @@ def eth_call( contract_address,
71
72
  # => "c87b56dd"
72
73
 
73
74
  ## binary encode method arg(ument)s
74
- args_encoded = Ethlite::Abi::Utils.encode_hex(
75
- Ethlite::Abi::AbiCoder.encode_abi( inputs, args) )
75
+ args_encoded = Ethlite::Utils.encode_hex(
76
+ Ethlite::Abi.encode_abi( inputs, args) )
76
77
 
77
78
  data = '0x' + signature_hash + args_encoded
78
79
 
@@ -84,15 +85,15 @@ def eth_call( contract_address,
84
85
  ]
85
86
 
86
87
  ## do the json-rpc request
87
- response = ETH_NODE.request( method, params )
88
+ response = rpc.request( method, params )
88
89
 
89
90
  puts "response:"
90
91
  pp response
91
92
 
92
93
  ## decode binary result
93
- string_data = Ethlite::Abi::Utils.decode_hex(
94
- Ethlite::Abi::Utils.remove_0x_head(response))
95
- result = Ethlite::Abi::AbiCoder.decode_abi( outputs, string_data )
94
+ string_data = Ethlite::Utils.decode_hex(
95
+ Ethlite::Utils.remove_0x_head(response))
96
+ result = Ethlite::Abi.decode_abi( outputs, string_data )
96
97
  result.length == 1 ? result[0] : result
97
98
  end
98
99
  ```
@@ -2,19 +2,16 @@
2
2
 
3
3
  module Ethlite
4
4
  module Abi
5
+ extend self
5
6
 
6
7
  ##
7
8
  # Contract ABI encoding and decoding.
8
9
  #
9
10
  # @see https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
10
11
  #
11
- module AbiCoder
12
-
12
+ module Codec
13
13
  extend self
14
14
 
15
- include Constant
16
-
17
-
18
15
  class EncodingError < StandardError; end
19
16
  class DecodingError < StandardError; end
20
17
  class ValueError < StandardError; end
@@ -43,7 +40,6 @@ module Ethlite
43
40
 
44
41
  "#{head}#{tail}"
45
42
  end
46
- alias :encode :encode_abi
47
43
 
48
44
  ##
49
45
  # Encodes a single value (static or dynamic).
@@ -263,7 +259,7 @@ module Ethlite
263
259
 
264
260
  parsed_types.zip(outputs).map {|(type, out)| decode_type(type, out) }
265
261
  end
266
- alias :decode :decode_abi
262
+
267
263
 
268
264
  def zero_padding data, pos, count, start_positions
269
265
  if pos >= data.size
@@ -416,8 +412,21 @@ module Ethlite
416
412
  raise EncodingError, "Cannot decode int: #{n}"
417
413
  end
418
414
  end
415
+ end # module Codec
416
+
417
+
418
+
419
+
420
+
421
+
422
+ def encode_abi(types, args)
423
+ Codec.encode_abi( types, args )
424
+ end
425
+
426
+ def decode_abi(types, data, raise_errors = false)
427
+ Codec.decode_abi( types, data, raise_errors )
428
+ end
419
429
 
420
- end
421
430
 
422
431
  end # module Abi
423
432
  end # module Ethlite
@@ -1,6 +1,5 @@
1
1
 
2
2
  module Ethlite
3
- module Constant
4
3
 
5
4
 
6
5
  ## todo/check - use encoding -ascii-8bit for source file or ? - why? why not?
@@ -33,6 +32,4 @@ module Ethlite
33
32
 
34
33
  CONTRACT_CODE_SIZE_LIMIT = 0x6000
35
34
 
36
-
37
- end # module Constant
38
35
  end # module Ethlite
@@ -9,12 +9,10 @@
9
9
  constant = !!abi['constant'] || abi['stateMutability']=='view'
10
10
  input_types = abi['inputs'] ? abi['inputs'].map{|a| _parse_component_type( a ) } : []
11
11
  output_types = abi['outputs'] ? abi['outputs'].map{|a| _parse_component_type( a ) } : []
12
- type = abi['type'] || 'function'
13
12
 
14
13
  new( name, inputs: input_types,
15
14
  outputs: output_types,
16
- constant: constant,
17
- type: type )
15
+ constant: constant )
18
16
  end
19
17
 
20
18
  def self._parse_component_type( argument )
@@ -38,20 +36,19 @@
38
36
 
39
37
  def initialize( name, inputs:,
40
38
  outputs: [],
41
- constant: true,
42
- type: 'function' )
39
+ constant: true )
43
40
  @name = name
44
41
  @constant = constant
45
42
  @input_types = inputs
46
43
  @output_types = outputs
47
-
48
- @signature = Abi::Utils.function_signature( @name, @input_types )
49
- @signature_hash = Abi::Utils.signature_hash( @signature, type=='event' ? 64 : 8)
44
+ @signature = "#{@name}(#{@input_types.join(',')})"
45
+ @signature_hash = Utils.signature_hash( @signature, 8 )
50
46
  end
51
47
 
48
+
52
49
  def do_call( rpc, contract_address, args )
53
- data = '0x' + @signature_hash + Abi::Utils.encode_hex(
54
- Abi::AbiCoder.encode_abi(@input_types, args) )
50
+ data = '0x' + @signature_hash + Utils.encode_hex(
51
+ Abi.encode_abi(@input_types, args) )
55
52
 
56
53
  method = 'eth_call'
57
54
  params = [{ to: contract_address,
@@ -63,11 +60,11 @@
63
60
  puts "response:"
64
61
  pp response
65
62
 
66
- string_data = Abi::Utils.decode_hex(
67
- Abi::Utils.remove_0x_head(response))
63
+ string_data = Utils.decode_hex(
64
+ Utils.remove_0x_head(response))
68
65
  return nil if string_data.empty?
69
66
 
70
- result = Abi::AbiCoder.decode_abi( @output_types, string_data )
67
+ result = Abi.decode_abi( @output_types, string_data )
71
68
  puts
72
69
  puts "result decode_abi:"
73
70
  pp result
@@ -1,11 +1,8 @@
1
1
  module Ethlite
2
- module Abi
3
- module Utils
2
+ module Utils
4
3
 
5
4
  extend self
6
5
 
7
- include Constant
8
-
9
6
  ##
10
7
  # Not the keccak in sha3, although it's underlying lib named SHA3
11
8
  #
@@ -215,15 +212,11 @@ module Abi
215
212
  end
216
213
 
217
214
 
218
- def function_signature method_name, arg_types
219
- "#{method_name}(#{arg_types.join(',')})"
220
- end
221
215
 
222
- def signature_hash signature, length=64
223
- encode_hex(keccak256(signature))[0...length]
216
+ def signature_hash( signature, length=8 )
217
+ encode_hex( keccak256(signature) )[0...length]
224
218
  end
225
- end
226
219
 
227
- end # module Abi
220
+ end # module Utils
228
221
  end # module Ethlite
229
222
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Ethlite
4
4
  MAJOR = 0
5
- MINOR = 2
6
- PATCH = 5
5
+ MINOR = 3
6
+ PATCH = 0
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
data/lib/ethlite.rb CHANGED
@@ -24,11 +24,11 @@ require_relative 'jsonrpc/jsonrpc'
24
24
  require_relative 'ethlite/version' # note: let version always go first
25
25
 
26
26
  require_relative 'ethlite/constant'
27
+ require_relative 'ethlite/utils'
27
28
 
28
29
 
29
30
  require_relative 'ethlite/abi/type'
30
- require_relative 'ethlite/abi/utils'
31
- require_relative 'ethlite/abi/abi_coder'
31
+ require_relative 'ethlite/abi/codec'
32
32
 
33
33
 
34
34
  require_relative 'ethlite/contract'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ethlite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -89,11 +89,11 @@ files:
89
89
  - lib/digest/keccak.rb
90
90
  - lib/digest/sha3.rb
91
91
  - lib/ethlite.rb
92
- - lib/ethlite/abi/abi_coder.rb
92
+ - lib/ethlite/abi/codec.rb
93
93
  - lib/ethlite/abi/type.rb
94
- - lib/ethlite/abi/utils.rb
95
94
  - lib/ethlite/constant.rb
96
95
  - lib/ethlite/contract.rb
96
+ - lib/ethlite/utils.rb
97
97
  - lib/ethlite/version.rb
98
98
  - lib/jsonrpc/jsonrpc.rb
99
99
  homepage: https://github.com/pixelartexchange/artbase