etherlite 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/etherlite/account/private_key.rb +19 -15
- data/lib/etherlite/nonce_manager.rb +13 -7
- data/lib/etherlite/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e2219e30428821c5866a33aa415a4ab4217b3b6f66eaa20f4bd701f64070cdc
|
4
|
+
data.tar.gz: df7c5c3d51712a08cd3aabc203ebfc4a0daa853610666d0d111f166e1607cf73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba8e3b442d736af75785838a131a02c02a6075c67fe1126f4ba60bc0ae24df2fb37924bf253fd9bf846f71fb91f6ebff35edb6fa6bc7fd322824bd2ea593122a
|
7
|
+
data.tar.gz: 9d6c0edd407d09be73e90a2ad3bd53d323f7297073bfff84fd22f6a0f6a4a844ff3c11080b6a142ccb17d1e2823123d71abaa5f6f91c079fb320fe5b9a9e1fd7
|
@@ -8,23 +8,27 @@ module Etherlite
|
|
8
8
|
super _connection, Etherlite::Utils.normalize_address(@key.address)
|
9
9
|
end
|
10
10
|
|
11
|
+
def build_raw_transaction(_options = {})
|
12
|
+
nonce = nonce_manager.next_nonce_for(normalized_address, _options.slice(:replace, :nonce))
|
13
|
+
|
14
|
+
tx = Eth::Tx.new(
|
15
|
+
value: _options.fetch(:value, 0),
|
16
|
+
data: _options.fetch(:data, ''),
|
17
|
+
gas_limit: _options.fetch(:gas, 90_000),
|
18
|
+
gas_price: _options.fetch(:gas_price, gas_price),
|
19
|
+
to: (Etherlite::Utils.encode_address_param(_options[:to]) if _options.key?(:to)),
|
20
|
+
nonce: nonce
|
21
|
+
)
|
22
|
+
|
23
|
+
sign_with_connection_chain tx
|
24
|
+
|
25
|
+
tx
|
26
|
+
end
|
27
|
+
|
11
28
|
def send_transaction(_options = {})
|
12
|
-
|
13
|
-
|
14
|
-
nonce_manager.with_next_nonce_for(normalized_address, nonce_options) do |nonce|
|
15
|
-
tx = Eth::Tx.new(
|
16
|
-
value: _options.fetch(:value, 0),
|
17
|
-
data: _options.fetch(:data, ''),
|
18
|
-
gas_limit: _options.fetch(:gas, 90_000),
|
19
|
-
gas_price: _options.fetch(:gas_price, gas_price),
|
20
|
-
to: (Etherlite::Utils.encode_address_param(_options[:to]) if _options.key?(:to)),
|
21
|
-
nonce: nonce
|
22
|
-
)
|
23
|
-
|
24
|
-
# Since eth gem does not allow configuration of chains for every tx, we need
|
25
|
-
# to globally configure it before signing. This is not thread safe so a mutex is needed.
|
26
|
-
sign_with_connection_chain tx
|
29
|
+
tx = build_raw_transaction(_options)
|
27
30
|
|
31
|
+
nonce_manager.with_next_nonce_for(normalized_address, nonce: tx.nonce) do |nonce|
|
28
32
|
Etherlite::Transaction.new @connection, @connection.eth_send_raw_transaction(tx.hex)
|
29
33
|
end
|
30
34
|
end
|
@@ -17,16 +17,22 @@ module Etherlite
|
|
17
17
|
last_nonce
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
20
|
+
def next_nonce_for(_normalized_address, replace: false, nonce: nil)
|
21
|
+
if nonce.nil?
|
22
|
+
nonce = last_nonce_for(_normalized_address)
|
23
|
+
nonce += 1 if nonce.negative? || !replace # if first tx, don't replace
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
+
nonce
|
27
|
+
end
|
28
|
+
|
29
|
+
def with_next_nonce_for(_normalized_address, _options = {})
|
30
|
+
@@nonce_mutex.synchronize do
|
31
|
+
nonce = next_nonce_for(_normalized_address, _options)
|
26
32
|
|
27
33
|
begin
|
28
|
-
result = yield
|
29
|
-
@@nonce_cache[_normalized_address] =
|
34
|
+
result = yield nonce
|
35
|
+
@@nonce_cache[_normalized_address] = nonce if caching_enabled?
|
30
36
|
return result
|
31
37
|
rescue
|
32
38
|
# if yield fails, cant be sure about transaction status so must rely again on observing.
|
data/lib/etherlite/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etherlite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignacio Baixas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: digest-sha3
|