etherlite 0.4.0 → 0.5.2

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: bbd613d95d4aaec97652278de22e3599754a18979185f8a0eeaea0ef6db3e3c4
4
- data.tar.gz: c21fe17680a4b4cc82eceedbd413df822da0c9475b9ee4c58f9ba124a481d82e
3
+ metadata.gz: 6bd7c04f60e0b06abbc63f817737ef0deea013791b885151d41f1789d57092a5
4
+ data.tar.gz: dbd6bf87f3e54a7e7c855e6e6bcf14226f5b708c5d8789c7b80b52e931f0dffc
5
5
  SHA512:
6
- metadata.gz: 202253e8cea38ae5b51977e130e442cdcc5fb4563f93dd5da802e6dbc8e86e154e08a4b13fc50f05b17c17ba4541d8a9adb6406aee7fb05f79e90fde8e8da594
7
- data.tar.gz: 1cbca94d66686e94db2ff819f4d21f6c64035a6004ab56d9d641ab02895ea8dbdb00495a120f4813c75cf00a9d1e0d4efe8e1655f2d23cb907615c0cf60102f6
6
+ metadata.gz: 2afa891466239576519823c40b146196ecd64f1ec9ff2afb20bac2b3b5010f2d4fe79dbc2811c83e461d3005b917dc405163f2e06556126f9af3644aea22a50f
7
+ data.tar.gz: cd7ce4b0800fe121a0ba5b9ed0e7c86de252101f3186d9504c4f69df0d0dde6300ba885762feb4f76f41ccd2981e1dacc75f1234ae01876324be8ffb6527d492
@@ -39,7 +39,7 @@ module Etherlite::Account
39
39
  end
40
40
 
41
41
  def send_transaction(_options = {})
42
- raise NotSupportedError, 'transactions are not supported by this kind of account'
42
+ raise Etherlite::NotSupportedError, 'transactions are not supported by this kind of account'
43
43
  end
44
44
 
45
45
  def ==(_other)
@@ -50,7 +50,6 @@ module Etherlite::Account
50
50
 
51
51
  def call_constant(_target, _function, _params, _options)
52
52
  params = {
53
- from: json_encoded_address,
54
53
  to: Etherlite::Utils.encode_address_param(_target),
55
54
  data: _function.encode(_params)
56
55
  }
@@ -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
@@ -53,7 +53,11 @@ module Etherlite
53
53
  end
54
54
 
55
55
  def default_account
56
- @default_account ||= load_default_account
56
+ @default_account ||= (accounts.first || anonymous_account)
57
+ end
58
+
59
+ def anonymous_account
60
+ @anonymous_account ||= Etherlite::Account::Anonymous.new(connection)
57
61
  end
58
62
 
59
63
  def account_from_pk(_pk)
@@ -66,13 +70,6 @@ use 'load_account' instead"
66
70
  end
67
71
 
68
72
  def_delegators :default_account, :unlock, :lock, :normalized_address, :transfer_to, :call
69
-
70
- private
71
-
72
- def load_default_account
73
- # TODO: consider configuring a global PK and allow the default account to use it
74
- accounts.first || Etherlite::Account::Anonymous.new(connection)
75
- end
76
73
  end
77
74
  end
78
75
  end
@@ -81,9 +81,21 @@ module Etherlite::Abi
81
81
  )
82
82
  end,
83
83
  (_definition['outputs'] || []).map { |input| LoadType.for signature: input['type'] },
84
- _definition.fetch('payable', false),
85
- _definition.fetch('constant', false)
84
+ function_payable?(_definition),
85
+ function_constant?(_definition)
86
86
  )
87
87
  end
88
+
89
+ def function_payable?(_definition)
90
+ return _definition['payable'] if _definition.key? 'payable'
91
+
92
+ _definition['stateMutability'] == 'payable'
93
+ end
94
+
95
+ def function_constant?(_definition)
96
+ return _definition['constant'] if _definition.key? 'constant'
97
+
98
+ _definition['stateMutability'] == 'pure' || _definition['stateMutability'] == 'view'
99
+ end
88
100
  end
89
101
  end
@@ -23,6 +23,7 @@ module Etherlite::Contract
23
23
 
24
24
  def self.decode(_connection, _json)
25
25
  new(
26
+ _json['blockHash'],
26
27
  _json['blockNumber'].nil? ? nil : Etherlite::Utils.hex_to_uint(_json['blockNumber']),
27
28
  _json['transactionHash'],
28
29
  Etherlite::Address.new(_connection, Etherlite::Utils.normalize_address(_json['address'])),
@@ -30,9 +31,10 @@ module Etherlite::Contract
30
31
  )
31
32
  end
32
33
 
33
- attr_reader :block_number, :tx_hash, :address, :attributes
34
+ attr_reader :block_hash, :block_number, :tx_hash, :address, :attributes
34
35
 
35
- def initialize(_block_number, _tx_hash, _address, _attributes)
36
+ def initialize(_block_hash, _block_number, _tx_hash, _address, _attributes)
37
+ @block_hash = _block_hash
36
38
  @block_number = _block_number
37
39
  @tx_hash = _tx_hash
38
40
  @address = _address
@@ -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.
@@ -45,6 +45,12 @@ module Etherlite
45
45
  Utils.hex_to_uint(original['blockNumber'])
46
46
  end
47
47
 
48
+ def block_hash
49
+ return nil unless mined?
50
+
51
+ original['blockHash']
52
+ end
53
+
48
54
  def confirmations
49
55
  return 0 unless mined?
50
56
 
@@ -1,3 +1,3 @@
1
1
  module Etherlite
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.2"
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.0
4
+ version: 0.5.2
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-05-05 00:00:00.000000000 Z
11
+ date: 2021-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: digest-sha3