etherlite 0.4.2 → 0.5.0

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: 7d5972b71c09d1bb9d1a3f732b8c1b5fe0057ad46c0159c1c93e5fbe690ef695
4
- data.tar.gz: 3b4fc972adac1ecbf23b7188040e8ba729d136ef89f51a4045d9c2339725ff34
3
+ metadata.gz: 3e2219e30428821c5866a33aa415a4ab4217b3b6f66eaa20f4bd701f64070cdc
4
+ data.tar.gz: df7c5c3d51712a08cd3aabc203ebfc4a0daa853610666d0d111f166e1607cf73
5
5
  SHA512:
6
- metadata.gz: 6b594fc27d066ecd3ee27025f990996d9badc2bc37efc9b770bfad55cf8a96b2779fb61a59d1dbb214de5905bff3863fa7b9975b145f94a9e88521e9055838d0
7
- data.tar.gz: 416610c6eb6f4466c5aee182147ee8bc456b8aaaf851cf5a1644bde4583df980a3dcaa822c92617e25393bdf145386200366f284c0310fcb13b283032f7a4a94
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
- nonce_options = _options.slice(:replace, :nonce)
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 with_next_nonce_for(_normalized_address, replace: false, nonce: nil)
21
- @@nonce_mutex.synchronize do
22
- return yield nonce if nonce.present?
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
- next_nonce = last_nonce_for(_normalized_address)
25
- next_nonce += 1 if next_nonce.negative? || !replace # if first tx, don't replace
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 next_nonce
29
- @@nonce_cache[_normalized_address] = next_nonce if caching_enabled?
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.
@@ -1,3 +1,3 @@
1
1
  module Etherlite
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
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.2
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-08 00:00:00.000000000 Z
11
+ date: 2021-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: digest-sha3