ethlite 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +3 -4
- data/lib/digest/{keccak256.rb → keccak.rb} +32 -18
- data/lib/digest/sha3.rb +31 -21
- data/lib/ethlite/abi/abi_coder.rb +3 -0
- data/lib/ethlite/abi/type.rb +10 -13
- data/lib/ethlite/abi/utils.rb +5 -7
- data/lib/ethlite/{abi/constant.rb → constant.rb} +22 -3
- data/lib/ethlite/contract.rb +38 -19
- data/lib/ethlite/version.rb +1 -1
- data/lib/ethlite.rb +30 -5
- data/lib/{ethlite/rpc.rb → jsonrpc/jsonrpc.rb} +16 -7
- metadata +5 -6
- data/lib/ethlite/abi/exceptions.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed8e8c05d930dceca2c2bf5f4b2e21ebeaaef68309b0c16474b47df667da2a89
|
4
|
+
data.tar.gz: 203ef7c86aa93e602028b1e0450e70c1c2c3a1388273263ce1e90fc503a18b08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1527a1fccb6908164d7744e0b06772c48a18f2f67bc60068f72c7577f512d2de295e9dfe8d917c5ca3c724963396cfb02ddff0aac6611be65d79575aaa90c34f
|
7
|
+
data.tar.gz: 92f93f217349b9ef33b1fc1ec7c0da36e50d172e2b44e06b9b8281d008fc770b4da081ad64f46e2be1819bbb7fa423dbe14a6519da4ddae6f782d9ea9f056108
|
data/Manifest.txt
CHANGED
@@ -2,15 +2,14 @@ CHANGELOG.md
|
|
2
2
|
Manifest.txt
|
3
3
|
README.md
|
4
4
|
Rakefile
|
5
|
-
lib/digest/
|
5
|
+
lib/digest/keccak.rb
|
6
6
|
lib/digest/sha3.rb
|
7
7
|
lib/ethlite.rb
|
8
8
|
lib/ethlite/abi/abi_coder.rb
|
9
|
-
lib/ethlite/abi/constant.rb
|
10
|
-
lib/ethlite/abi/exceptions.rb
|
11
9
|
lib/ethlite/abi/type.rb
|
12
10
|
lib/ethlite/abi/utils.rb
|
11
|
+
lib/ethlite/constant.rb
|
13
12
|
lib/ethlite/contract.rb
|
14
|
-
lib/ethlite/rpc.rb
|
15
13
|
lib/ethlite/utility.rb
|
16
14
|
lib/ethlite/version.rb
|
15
|
+
lib/jsonrpc/jsonrpc.rb
|
@@ -8,8 +8,15 @@
|
|
8
8
|
## require 'digest'
|
9
9
|
|
10
10
|
|
11
|
+
|
12
|
+
##
|
13
|
+
# note: use KeccakLite (or KeccakZero? KeccakSHA3?) instead of Keccak
|
14
|
+
# to allow usage of native w/ c-extension Keccak and "lite" version
|
15
|
+
|
16
|
+
|
17
|
+
|
11
18
|
module Digest
|
12
|
-
class
|
19
|
+
class KeccakLite < Digest::Class
|
13
20
|
PILN = [10, 7, 11, 17, 18, 3, 5, 16,
|
14
21
|
8, 21, 24, 4, 15, 23, 19, 13,
|
15
22
|
12, 2, 20, 14, 22, 9, 6, 1]
|
@@ -27,16 +34,18 @@ module Digest
|
|
27
34
|
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
|
28
35
|
0x8000000000008080, 0x0000000080000001, 0x8000000080008008]
|
29
36
|
|
30
|
-
|
31
|
-
|
37
|
+
## note: changed initialize to use param hash_size = 512
|
38
|
+
## do NOT hard-code only 256 bit
|
39
|
+
def initialize( hash_size = 512 )
|
40
|
+
@size = hash_size / 8
|
32
41
|
@buffer = ''
|
33
42
|
end
|
34
43
|
|
35
|
-
def << s
|
44
|
+
def <<( s )
|
36
45
|
@buffer << s
|
37
46
|
self
|
38
47
|
end
|
39
|
-
|
48
|
+
alias_method :update, :<<
|
40
49
|
|
41
50
|
def reset
|
42
51
|
@buffer.clear
|
@@ -44,37 +53,40 @@ module Digest
|
|
44
53
|
end
|
45
54
|
|
46
55
|
def finish
|
47
|
-
s = Array.new 25, 0
|
56
|
+
s = Array.new( 25, 0 )
|
48
57
|
width = 200 - @size * 2
|
58
|
+
|
59
|
+
### note: padding changed in final FIPS PUB 202 standard
|
60
|
+
## from "\x01" to "\x06"
|
49
61
|
padding = "\x01"
|
50
62
|
|
51
63
|
buffer = @buffer
|
52
64
|
buffer << padding << "\0" * (width - buffer.size % width)
|
53
65
|
buffer[-1] = (buffer[-1].ord | 0x80).chr
|
54
66
|
|
55
|
-
0.step buffer.size - 1, width do |j|
|
56
|
-
quads = buffer[j, width].unpack 'Q*'
|
67
|
+
0.step( buffer.size - 1, width ) do |j|
|
68
|
+
quads = buffer[j, width].unpack( 'Q*' )
|
57
69
|
(width / 8).times do |i|
|
58
70
|
s[i] ^= quads[i]
|
59
71
|
end
|
60
72
|
|
61
|
-
|
73
|
+
_keccak( s )
|
62
74
|
end
|
63
75
|
|
64
76
|
s.pack('Q*')[0, @size]
|
65
77
|
end
|
66
78
|
|
67
79
|
private
|
68
|
-
def
|
69
|
-
24.times.each_with_object [] do |round, a|
|
80
|
+
def _keccak( s )
|
81
|
+
24.times.each_with_object( [] ) do |round, a|
|
70
82
|
# Theta
|
71
83
|
5.times do |i|
|
72
84
|
a[i] = s[i] ^ s[i + 5] ^ s[i + 10] ^ s[i + 15] ^ s[i + 20]
|
73
85
|
end
|
74
86
|
|
75
87
|
5.times do |i|
|
76
|
-
t = a[(i + 4) % 5] ^
|
77
|
-
0.step 24, 5 do |j|
|
88
|
+
t = a[(i + 4) % 5] ^ _rotate(a[(i + 1) % 5], 1)
|
89
|
+
0.step( 24, 5 ) do |j|
|
78
90
|
s[j + i] ^= t
|
79
91
|
end
|
80
92
|
end
|
@@ -84,12 +96,12 @@ module Digest
|
|
84
96
|
24.times do |i|
|
85
97
|
j = PILN[i]
|
86
98
|
a[0] = s[j]
|
87
|
-
s[j] =
|
99
|
+
s[j] = _rotate( t, ROTC[i] )
|
88
100
|
t = a[0]
|
89
101
|
end
|
90
102
|
|
91
103
|
# Chi
|
92
|
-
0.step 24, 5 do |j|
|
104
|
+
0.step( 24, 5 ) do |j|
|
93
105
|
5.times do |i|
|
94
106
|
a[i] = s[j + i]
|
95
107
|
end
|
@@ -104,8 +116,10 @@ module Digest
|
|
104
116
|
end
|
105
117
|
end
|
106
118
|
|
107
|
-
def
|
119
|
+
def _rotate( x, y )
|
108
120
|
(x << y | x >> 64 - y) & (1 << 64) - 1
|
109
121
|
end
|
110
|
-
|
111
|
-
|
122
|
+
|
123
|
+
|
124
|
+
end # class KeccakLite
|
125
|
+
end # module Digest
|
data/lib/digest/sha3.rb
CHANGED
@@ -6,8 +6,13 @@
|
|
6
6
|
|
7
7
|
## require 'digest'
|
8
8
|
|
9
|
+
##
|
10
|
+
# note: use SHA3Lite (or SHA3Zero? ZeroSHA3?) instead of SHA3
|
11
|
+
# to allow usage of native w/ c-extension SHA3 and "lite" version
|
12
|
+
|
13
|
+
|
9
14
|
module Digest
|
10
|
-
class
|
15
|
+
class SHA3Lite < Digest::Class
|
11
16
|
PILN = [10, 7, 11, 17, 18, 3, 5, 16,
|
12
17
|
8, 21, 24, 4, 15, 23, 19, 13,
|
13
18
|
12, 2, 20, 14, 22, 9, 6, 1]
|
@@ -25,16 +30,16 @@ module Digest
|
|
25
30
|
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
|
26
31
|
0x8000000000008080, 0x0000000080000001, 0x8000000080008008]
|
27
32
|
|
28
|
-
def initialize hash_size = 512
|
29
|
-
@size
|
30
|
-
@buffer = ''
|
33
|
+
def initialize( hash_size = 512 )
|
34
|
+
@size = hash_size / 8
|
35
|
+
@buffer = '' ## todo/check: make sure buffer is with encoding BINARY - why? why not?
|
31
36
|
end
|
32
37
|
|
33
|
-
def << s
|
38
|
+
def <<( s )
|
34
39
|
@buffer << s
|
35
40
|
self
|
36
41
|
end
|
37
|
-
|
42
|
+
alias_method :update, :<<
|
38
43
|
|
39
44
|
def reset
|
40
45
|
@buffer.clear
|
@@ -42,36 +47,40 @@ module Digest
|
|
42
47
|
end
|
43
48
|
|
44
49
|
def finish
|
45
|
-
s = Array.new 25, 0
|
50
|
+
s = Array.new( 25, 0 )
|
46
51
|
width = 200 - @size * 2
|
47
52
|
|
53
|
+
### note: padding changed in final FIPS PUB 202 standard
|
54
|
+
## from "\x01" to "\x06"
|
55
|
+
padding = "\x06"
|
56
|
+
|
48
57
|
buffer = @buffer
|
49
|
-
buffer <<
|
58
|
+
buffer << padding << "\0" * (width - buffer.size % width)
|
50
59
|
buffer[-1] = (buffer[-1].ord | 0x80).chr
|
51
60
|
|
52
|
-
0.step buffer.size - 1, width do |j|
|
53
|
-
quads = buffer[j, width].unpack 'Q*'
|
61
|
+
0.step( buffer.size - 1, width ) do |j|
|
62
|
+
quads = buffer[j, width].unpack( 'Q*' )
|
54
63
|
(width / 8).times do |i|
|
55
64
|
s[i] ^= quads[i]
|
56
65
|
end
|
57
66
|
|
58
|
-
|
67
|
+
_keccak( s )
|
59
68
|
end
|
60
69
|
|
61
70
|
s.pack('Q*')[0, @size]
|
62
71
|
end
|
63
72
|
|
64
|
-
|
65
|
-
def
|
66
|
-
24.times.each_with_object [] do |round, a|
|
73
|
+
private
|
74
|
+
def _keccak( s )
|
75
|
+
24.times.each_with_object( [] ) do |round, a|
|
67
76
|
# Theta
|
68
77
|
5.times do |i|
|
69
78
|
a[i] = s[i] ^ s[i + 5] ^ s[i + 10] ^ s[i + 15] ^ s[i + 20]
|
70
79
|
end
|
71
80
|
|
72
81
|
5.times do |i|
|
73
|
-
t = a[(i + 4) % 5] ^
|
74
|
-
0.step 24, 5 do |j|
|
82
|
+
t = a[(i + 4) % 5] ^ _rotate(a[(i + 1) % 5], 1)
|
83
|
+
0.step( 24, 5 ) do |j|
|
75
84
|
s[j + i] ^= t
|
76
85
|
end
|
77
86
|
end
|
@@ -81,12 +90,12 @@ module Digest
|
|
81
90
|
24.times do |i|
|
82
91
|
j = PILN[i]
|
83
92
|
a[0] = s[j]
|
84
|
-
s[j] =
|
93
|
+
s[j] = _rotate( t, ROTC[i] )
|
85
94
|
t = a[0]
|
86
95
|
end
|
87
96
|
|
88
97
|
# Chi
|
89
|
-
0.step 24, 5 do |j|
|
98
|
+
0.step( 24, 5 ) do |j|
|
90
99
|
5.times do |i|
|
91
100
|
a[i] = s[j + i]
|
92
101
|
end
|
@@ -101,8 +110,9 @@ module Digest
|
|
101
110
|
end
|
102
111
|
end
|
103
112
|
|
104
|
-
def
|
113
|
+
def _rotate( x, y )
|
105
114
|
(x << y | x >> 64 - y) & (1 << 64) - 1
|
106
115
|
end
|
107
|
-
|
108
|
-
end
|
116
|
+
|
117
|
+
end # class SHA3Lite
|
118
|
+
end # module Digest
|
data/lib/ethlite/abi/type.rb
CHANGED
@@ -2,17 +2,16 @@ module Ethlite
|
|
2
2
|
module Abi
|
3
3
|
class Type
|
4
4
|
|
5
|
-
class ParseError < StandardError;
|
6
|
-
|
5
|
+
class ParseError < StandardError; end
|
6
|
+
|
7
7
|
|
8
|
-
class <<self
|
9
8
|
##
|
10
9
|
# Crazy regexp to seperate out base type component (eg. uint), size (eg.
|
11
10
|
# 256, 128x128, nil), array component (eg. [], [45], nil)
|
12
11
|
#
|
13
|
-
def parse(type)
|
12
|
+
def self.parse( type )
|
14
13
|
|
15
|
-
return parse('uint256')
|
14
|
+
return parse('uint256') if type=='trcToken'
|
16
15
|
|
17
16
|
if type =~ /^\((.*)\)((\[[0-9]*\])*)/
|
18
17
|
return Tuple.parse $1, $2.scan(/\[[0-9]*\]/)
|
@@ -56,10 +55,10 @@ module Ethlite
|
|
56
55
|
new(base, sub, dims.map {|x| x[1...-1].to_i})
|
57
56
|
end
|
58
57
|
|
59
|
-
def size_type
|
58
|
+
def self.size_type
|
60
59
|
@size_type ||= new('uint', 256, [])
|
61
60
|
end
|
62
|
-
|
61
|
+
|
63
62
|
|
64
63
|
attr :base, :sub, :dims
|
65
64
|
|
@@ -69,7 +68,7 @@ module Ethlite
|
|
69
68
|
# @param dims [Array[Integer]] dimensions of array type, e.g. [1,2,0]
|
70
69
|
# for uint256[1][2][], [] for non-array type
|
71
70
|
#
|
72
|
-
def initialize(base, sub, dims)
|
71
|
+
def initialize( base, sub, dims )
|
73
72
|
@base = base
|
74
73
|
@sub = sub
|
75
74
|
@dims = dims
|
@@ -123,7 +122,7 @@ module Ethlite
|
|
123
122
|
|
124
123
|
class Tuple < Type
|
125
124
|
|
126
|
-
def self.parse types, dims
|
125
|
+
def self.parse( types, dims )
|
127
126
|
|
128
127
|
depth = 0
|
129
128
|
collected = []
|
@@ -156,7 +155,8 @@ module Ethlite
|
|
156
155
|
end
|
157
156
|
|
158
157
|
attr_reader :types, :parsed_types
|
159
|
-
|
158
|
+
|
159
|
+
def initialize( types, dims )
|
160
160
|
super('tuple', '', dims)
|
161
161
|
@types = types
|
162
162
|
@parsed_types = types.map{|t| Type.parse t}
|
@@ -188,14 +188,11 @@ module Ethlite
|
|
188
188
|
subtype.dynamic? ? nil : dims.last * subtype.size
|
189
189
|
end
|
190
190
|
end
|
191
|
-
|
192
|
-
|
193
191
|
end
|
194
192
|
|
195
193
|
def subtype
|
196
194
|
@subtype ||= Tuple.new(types, dims[0...-1])
|
197
195
|
end
|
198
|
-
|
199
196
|
end
|
200
197
|
|
201
198
|
|
data/lib/ethlite/abi/utils.rb
CHANGED
@@ -12,16 +12,16 @@ module Abi
|
|
12
12
|
def keccak256(x)
|
13
13
|
# Digest::SHA3.new(256).digest(x)
|
14
14
|
## Digest::Keccak.digest(x, 256)
|
15
|
-
Digest::
|
15
|
+
Digest::KeccakLite.new(256).digest( x )
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
## check where required / in use - what for?
|
18
|
+
## todo/check where required / in use - what for?
|
20
19
|
def keccak512(x)
|
21
20
|
# Digest::SHA3.new(512).digest(x)
|
22
|
-
Digest::Keccak.digest(x, 512)
|
21
|
+
# Digest::Keccak.digest(x, 512)
|
22
|
+
Digest::KeccakLite.new(512).digest( x )
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
|
26
26
|
def keccak256_rlp(x)
|
27
27
|
keccak256 RLP.encode(x)
|
@@ -218,8 +218,6 @@ module Abi
|
|
218
218
|
def signature_hash signature, length=64
|
219
219
|
encode_hex(keccak256(signature))[0...length]
|
220
220
|
end
|
221
|
-
|
222
|
-
|
223
221
|
end
|
224
222
|
|
225
223
|
end # module Abi
|
@@ -1,6 +1,5 @@
|
|
1
1
|
|
2
2
|
module Ethlite
|
3
|
-
module Abi
|
4
3
|
module Constant
|
5
4
|
|
6
5
|
BYTE_EMPTY = "".freeze
|
@@ -20,13 +19,33 @@ module Ethlite
|
|
20
19
|
|
21
20
|
HASH_ZERO = ("\x00"*32).freeze
|
22
21
|
|
22
|
+
|
23
23
|
PUBKEY_ZERO = ("\x00"*32).freeze
|
24
24
|
PRIVKEY_ZERO = ("\x00"*32).freeze
|
25
25
|
PRIVKEY_ZERO_HEX = ('0'*64).freeze
|
26
26
|
|
27
27
|
CONTRACT_CODE_SIZE_LIMIT = 0x6000
|
28
28
|
|
29
|
-
end
|
30
29
|
|
31
|
-
|
30
|
+
=begin
|
31
|
+
# The RLP short length limit.
|
32
|
+
SHORT_LENGTH_LIMIT = 56.freeze
|
33
|
+
|
34
|
+
# The RLP long length limit.
|
35
|
+
LONG_LENGTH_LIMIT = (256 ** 8).freeze
|
36
|
+
|
37
|
+
# The RLP primitive type offset.
|
38
|
+
PRIMITIVE_PREFIX_OFFSET = 0x80.freeze
|
39
|
+
|
40
|
+
# The RLP array type offset.
|
41
|
+
LIST_PREFIX_OFFSET = 0xc0.freeze
|
42
|
+
|
43
|
+
# The binary encoding is ASCII (8-bit).
|
44
|
+
BINARY_ENCODING = "ASCII-8BIT".freeze
|
45
|
+
|
46
|
+
# Infinity as constant for convenience.
|
47
|
+
INFINITY = (1.0 / 0.0).freeze
|
48
|
+
|
49
|
+
=end
|
50
|
+
end # module Constant
|
32
51
|
end # module Ethlite
|
data/lib/ethlite/contract.rb
CHANGED
@@ -2,6 +2,35 @@
|
|
2
2
|
class ContractMethod
|
3
3
|
include Utility
|
4
4
|
|
5
|
+
|
6
|
+
def self.parse_abi( abi )
|
7
|
+
## convenience helper - auto-convert to json if string passed in
|
8
|
+
abi = JSON.parse( abi ) if abi.is_a?( String )
|
9
|
+
|
10
|
+
name = abi['name']
|
11
|
+
constant = !!abi['constant'] || abi['stateMutability']=='view'
|
12
|
+
input_types = abi['inputs'] ? abi['inputs'].map{|a| _parse_component_type( a ) } : []
|
13
|
+
output_types = abi['outputs'] ? abi['outputs'].map{|a| _parse_component_type( a ) } : []
|
14
|
+
type = abi['type'] || 'function'
|
15
|
+
|
16
|
+
new( name, inputs: input_types,
|
17
|
+
outputs: output_types,
|
18
|
+
constant: constant,
|
19
|
+
type: type )
|
20
|
+
end
|
21
|
+
|
22
|
+
def self._parse_component_type( argument )
|
23
|
+
if argument['type'] =~ /^tuple((\[[0-9]*\])*)/
|
24
|
+
argument['components'] ? "(#{argument['components'].collect{ |c| _parse_component_type( c ) }.join(',')})#{$1}"
|
25
|
+
: "()#{$1}"
|
26
|
+
else
|
27
|
+
argument['type']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
5
34
|
attr_reader :abi,
|
6
35
|
:signature,
|
7
36
|
:name,
|
@@ -10,29 +39,19 @@
|
|
10
39
|
:output_types,
|
11
40
|
:constant
|
12
41
|
|
13
|
-
def initialize(
|
14
|
-
|
15
|
-
|
42
|
+
def initialize( name, inputs:,
|
43
|
+
outputs: [],
|
44
|
+
constant: true,
|
45
|
+
type: 'function' )
|
46
|
+
@name = name
|
47
|
+
@constant = constant
|
48
|
+
@input_types = inputs
|
49
|
+
@output_types = outputs
|
16
50
|
|
17
|
-
@abi = abi
|
18
|
-
@name = abi['name']
|
19
|
-
@constant = !!abi['constant'] || abi['stateMutability']=='view'
|
20
|
-
@input_types = abi['inputs'] ? abi['inputs'].map{|a| parse_component_type a } : []
|
21
|
-
@output_types = abi['outputs'] ? abi['outputs'].map{|a| parse_component_type a } : nil
|
22
51
|
@signature = Abi::Utils.function_signature( @name, @input_types )
|
23
|
-
@signature_hash = Abi::Utils.signature_hash( @signature,
|
52
|
+
@signature_hash = Abi::Utils.signature_hash( @signature, type=='event' ? 64 : 8)
|
24
53
|
end
|
25
54
|
|
26
|
-
def parse_component_type( argument )
|
27
|
-
if argument['type'] =~ /^tuple((\[[0-9]*\])*)/
|
28
|
-
argument['components'] ? "(#{argument['components'].collect{|c| parse_component_type( c ) }.join(',')})#{$1}"
|
29
|
-
: "()#{$1}"
|
30
|
-
else
|
31
|
-
argument['type']
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
55
|
def do_call( rpc, contract_address, args )
|
37
56
|
data = '0x' + @signature_hash + Abi::Utils.encode_hex(
|
38
57
|
Abi::AbiCoder.encode_abi(@input_types, args) )
|
data/lib/ethlite/version.rb
CHANGED
data/lib/ethlite.rb
CHANGED
@@ -13,29 +13,54 @@ require 'digest'
|
|
13
13
|
require 'rlp' ## gem rlp - see https://rubygems.org/gems/rlp
|
14
14
|
|
15
15
|
## bundled require 'digest/keccak' ## gem keccak - see https://rubygems.org/gems/keccak
|
16
|
-
|
16
|
+
require_relative 'digest/keccak'
|
17
|
+
require_relative 'digest/sha3'
|
17
18
|
|
19
|
+
require_relative 'jsonrpc/jsonrpc'
|
18
20
|
|
19
21
|
|
20
22
|
|
21
23
|
## our own code
|
22
24
|
require_relative 'ethlite/version' # note: let version always go first
|
23
25
|
|
26
|
+
require_relative 'ethlite/constant'
|
27
|
+
|
24
28
|
|
25
29
|
require_relative 'ethlite/abi/type'
|
26
|
-
require_relative 'ethlite/abi/constant'
|
27
|
-
require_relative 'ethlite/abi/exceptions'
|
28
30
|
require_relative 'ethlite/abi/utils'
|
29
31
|
require_relative 'ethlite/abi/abi_coder'
|
30
32
|
|
31
33
|
|
32
|
-
require_relative 'ethlite/rpc'
|
33
|
-
|
34
34
|
require_relative 'ethlite/utility'
|
35
35
|
require_relative 'ethlite/contract'
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
+
|
40
|
+
module Ethlite
|
41
|
+
class Configuration
|
42
|
+
def rpc() @rpc || JsonRpc.new( ENV['INFURA_URI'] ); end
|
43
|
+
def rpc=(value)
|
44
|
+
@rpc = if value.is_a?( String )
|
45
|
+
JsonRpc.new( value ) ## auto-wrap in (built-in/simple) jsonrpc client/serverproxy
|
46
|
+
else
|
47
|
+
value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end # class Configuration
|
51
|
+
|
52
|
+
|
53
|
+
## lets you use
|
54
|
+
## Ethlite.configure do |config|
|
55
|
+
## config.rpc = Ethlite::Rpc.new( ENV['INFURA_URI'] )
|
56
|
+
## end
|
57
|
+
def self.configure() yield( config ); end
|
58
|
+
def self.config() @config ||= Configuration.new; end
|
59
|
+
end # module Ethlite
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
39
64
|
## add convenience alternate spelling
|
40
65
|
EthLite = Ethlite
|
41
66
|
|
@@ -1,12 +1,20 @@
|
|
1
|
-
module Ethlite
|
2
1
|
|
3
|
-
|
2
|
+
###
|
3
|
+
# simple JsonRpc client
|
4
|
+
#
|
5
|
+
# see https://www.jsonrpc.org/specification
|
6
|
+
# https://en.wikipedia.org/wiki/JSON-RPC
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
class JsonRpc
|
4
11
|
def initialize( uri )
|
5
12
|
@client_id = Random.rand( 10000000 )
|
6
13
|
|
7
14
|
@uri = URI.parse( uri )
|
8
15
|
end
|
9
16
|
|
17
|
+
|
10
18
|
def request( method, params=[] )
|
11
19
|
opts = {}
|
12
20
|
if @uri.instance_of?( URI::HTTPS )
|
@@ -29,9 +37,12 @@
|
|
29
37
|
request.body = json
|
30
38
|
response = http.request( request )
|
31
39
|
|
32
|
-
|
40
|
+
unless response.kind_of?( Net::HTTPOK )
|
41
|
+
raise "Error code #{response.code} on request #{@uri.to_s} #{request.body}"
|
42
|
+
end
|
43
|
+
|
33
44
|
|
34
|
-
body = JSON.parse(response.body, max_nesting: 1500)
|
45
|
+
body = JSON.parse( response.body, max_nesting: 1500 )
|
35
46
|
|
36
47
|
if body['result']
|
37
48
|
body['result']
|
@@ -42,7 +53,5 @@
|
|
42
53
|
end
|
43
54
|
end
|
44
55
|
end
|
45
|
-
|
46
|
-
|
47
|
-
end # module Ethlite
|
56
|
+
end # class JsonRpc
|
48
57
|
|
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.
|
4
|
+
version: 0.2.3
|
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-
|
11
|
+
date: 2022-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cocos
|
@@ -86,18 +86,17 @@ files:
|
|
86
86
|
- Manifest.txt
|
87
87
|
- README.md
|
88
88
|
- Rakefile
|
89
|
-
- lib/digest/
|
89
|
+
- lib/digest/keccak.rb
|
90
90
|
- lib/digest/sha3.rb
|
91
91
|
- lib/ethlite.rb
|
92
92
|
- lib/ethlite/abi/abi_coder.rb
|
93
|
-
- lib/ethlite/abi/constant.rb
|
94
|
-
- lib/ethlite/abi/exceptions.rb
|
95
93
|
- lib/ethlite/abi/type.rb
|
96
94
|
- lib/ethlite/abi/utils.rb
|
95
|
+
- lib/ethlite/constant.rb
|
97
96
|
- lib/ethlite/contract.rb
|
98
|
-
- lib/ethlite/rpc.rb
|
99
97
|
- lib/ethlite/utility.rb
|
100
98
|
- lib/ethlite/version.rb
|
99
|
+
- lib/jsonrpc/jsonrpc.rb
|
101
100
|
homepage: https://github.com/pixelartexchange/artbase
|
102
101
|
licenses:
|
103
102
|
- Public Domain
|
@@ -1,29 +0,0 @@
|
|
1
|
-
|
2
|
-
module Ethlite
|
3
|
-
module Abi
|
4
|
-
|
5
|
-
class DeprecatedError < StandardError; end
|
6
|
-
class ChecksumError < StandardError; end
|
7
|
-
class FormatError < StandardError; end
|
8
|
-
class ValidationError < StandardError; end
|
9
|
-
class ValueError < StandardError; end
|
10
|
-
class AssertError < StandardError; end
|
11
|
-
|
12
|
-
class UnknownParentError < StandardError; end
|
13
|
-
class InvalidBlock < ValidationError; end
|
14
|
-
class InvalidUncles < ValidationError; end
|
15
|
-
|
16
|
-
class InvalidTransaction < ValidationError; end
|
17
|
-
class UnsignedTransactionError < InvalidTransaction; end
|
18
|
-
class InvalidNonce < InvalidTransaction; end
|
19
|
-
class InsufficientStartGas < InvalidTransaction; end
|
20
|
-
class InsufficientBalance < InvalidTransaction; end
|
21
|
-
class BlockGasLimitReached < InvalidTransaction; end
|
22
|
-
|
23
|
-
class InvalidSPVProof < ValidationError; end
|
24
|
-
|
25
|
-
class ContractCreationFailed < StandardError; end
|
26
|
-
class TransactionFailed < StandardError; end
|
27
|
-
|
28
|
-
end # module Abi
|
29
|
-
end # module Ethlite
|