ethlite 0.2.5 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cd659223f8049ca63302c5bb595da6faf483d29d776ed747b5970dde11b415e
4
- data.tar.gz: fde6fca03683dac98d474d82bc520a82dc45e74b08eaabbc0c521e2635ca3d3b
3
+ metadata.gz: a91770dc04d591bf88353b4783080812f1659a7f679f09636b656a1a8d9ac7b7
4
+ data.tar.gz: 626dda3168008abf7743526be783722292af40633c4acbe1bea4ea649f77a602
5
5
  SHA512:
6
- metadata.gz: 050226ff51c20a38cb8f1db254e246a555d07baf8a6e12766985850400749a463698e89818780cd031e5ed3cab6bb05e2afae37588149084160138d5e6783e0f
7
- data.tar.gz: 0d16770efc489cf88f08ec8ef471563905b2197c1d8330c58558348f1a9076dd717f654b5c221ea78052d31855bb458105c79f2f7ec1021a04451a202088b722
6
+ metadata.gz: 31b7dce9e0b71c4ea56697272d731541ecd58fdbfac6d5a3ddc949f7d47263340fda578d37403f788ecc02b7b08152d75107fd856f4af54b256c1cbb52b55ab2
7
+ data.tar.gz: 852410528fc380e40cff8fd4eafd49a2697947d2b2a4ab73b6210c88c87c45ecfdd2c44c296dd473cb7a5e5c7d175625d774e3fb6f88a45da7f3356af2b21ea6
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
  ```
@@ -8,13 +8,7 @@ module Ethlite
8
8
  #
9
9
  # @see https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
10
10
  #
11
- module AbiCoder
12
-
13
- extend self
14
-
15
- include Constant
16
-
17
-
11
+ class Codec
18
12
  class EncodingError < StandardError; end
19
13
  class DecodingError < StandardError; end
20
14
  class ValueError < StandardError; end
@@ -43,7 +37,6 @@ module Ethlite
43
37
 
44
38
  "#{head}#{tail}"
45
39
  end
46
- alias :encode :encode_abi
47
40
 
48
41
  ##
49
42
  # Encodes a single value (static or dynamic).
@@ -263,7 +256,7 @@ module Ethlite
263
256
 
264
257
  parsed_types.zip(outputs).map {|(type, out)| decode_type(type, out) }
265
258
  end
266
- alias :decode :decode_abi
259
+
267
260
 
268
261
  def zero_padding data, pos, count, start_positions
269
262
  if pos >= data.size
@@ -416,8 +409,25 @@ module Ethlite
416
409
  raise EncodingError, "Cannot decode int: #{n}"
417
410
  end
418
411
  end
412
+ end # class Codec
413
+
414
+
415
+
416
+
417
+
418
+
419
+ def self.codec
420
+ @codec ||= Codec.new
421
+ end
422
+
423
+ def self.encode_abi(types, args)
424
+ codec.encode_abi( types, args )
425
+ end
426
+
427
+ def self.decode_abi(types, data, raise_errors = false)
428
+ codec.decode_abi( types, data, raise_errors )
429
+ end
419
430
 
420
- end
421
431
 
422
432
  end # module Abi
423
433
  end # module Ethlite
@@ -117,8 +117,8 @@ module Ethlite
117
117
  def subtype
118
118
  @subtype ||= self.class.new(base, sub, dims[0...-1])
119
119
  end
120
+ end # class Type
120
121
 
121
- end
122
122
 
123
123
  class Tuple < Type
124
124
 
@@ -193,7 +193,7 @@ module Ethlite
193
193
  def subtype
194
194
  @subtype ||= Tuple.new(types, dims[0...-1])
195
195
  end
196
- end
196
+ end # class Tuple
197
197
 
198
198
 
199
199
  end # module Abi
@@ -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,7 @@
1
1
  module Ethlite
2
- module Abi
3
- module Utils
4
2
 
5
- extend self
6
-
7
- include Constant
8
3
 
4
+ module UtilHelper
9
5
  ##
10
6
  # Not the keccak in sha3, although it's underlying lib named SHA3
11
7
  #
@@ -214,16 +210,17 @@ module Abi
214
210
  end
215
211
  end
216
212
 
217
-
218
- def function_signature method_name, arg_types
219
- "#{method_name}(#{arg_types.join(',')})"
213
+ def signature_hash( signature, length=8 )
214
+ encode_hex( keccak256(signature) )[0...length]
220
215
  end
221
216
 
222
- def signature_hash signature, length=64
223
- encode_hex(keccak256(signature))[0...length]
224
- end
225
- end
217
+ end # module UtilHelper
218
+
219
+
220
+
221
+ module Utils
222
+ extend UtilHelper
223
+ end
226
224
 
227
- end # module Abi
228
225
  end # module Ethlite
229
226
 
@@ -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 = 1
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,14 +1,14 @@
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-21 00:00:00.000000000 Z
11
+ date: 2022-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocos
@@ -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