etherlite 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: d8da5b22ad0f7b8dd87c4513e7bc4e8ea71462e2
4
- data.tar.gz: 053ecfcd4d1233cb41ec6883ad7f24ea5fa962b0
3
+ metadata.gz: b26ef9659e1ea23ddedd3959500bcf341cde07b4
4
+ data.tar.gz: 05edd2b33d17ceb66a7461d8e6d9f9dc06935057
5
5
  SHA512:
6
- metadata.gz: d3911d293c3a523876cbd5afc799e90f4c635c0f2ca186ccd8ce637f735a1643ba3204e0d106fef06d345f42157b4afb956957a4a07f4f2efee634f44adba7b0
7
- data.tar.gz: 366a51cfe7e7ef58400e837a61ef222c340e44f60d2dfe7050051a99018ff5adf38d3632b9b4c8b7e6f940c76f6bc21a23be9424ba91a418b398f5bb9b627bb4
6
+ metadata.gz: 962d4b0f389a0824a48de67397cb69f96d8f46da2be0d9a1551f320e2a13d8f1a1b4234594d54347d0b269adbd61ecbb8d2d570c07533987560117a644da2b4c
7
+ data.tar.gz: 0196cf0b26cd6ad397bee4f1d24b2dab1c512fc7de247fbebc860d2bbb5dfd16df141f04f1b68a9b08a03eb7431eac1d625fd9d7189da1c3e12abe7eac34aa84
@@ -33,6 +33,10 @@ module Etherlite::Account
33
33
  raise NotSupportedError, 'transactions are not supported by this kind of account'
34
34
  end
35
35
 
36
+ def ==(_other)
37
+ normalized_address == _other.normalized_address
38
+ end
39
+
36
40
  private
37
41
 
38
42
  def call_constant(_target, _function, _params, _options)
@@ -6,12 +6,8 @@ module Etherlite
6
6
  end
7
7
 
8
8
  def get_balance(block: :latest)
9
- Etherlite::Utils.hex_to_uint(
10
- connection.ipc_call(
11
- :eth_getBalance,
12
- json_encoded_address,
13
- Etherlite::Utils.encode_block_param(block)
14
- )
9
+ connection.eth_get_balance(
10
+ json_encoded_address, Etherlite::Utils.encode_block_param(block)
15
11
  )
16
12
  end
17
13
 
@@ -12,6 +12,22 @@ module Etherlite
12
12
  connection.eth_gas_price
13
13
  end
14
14
 
15
+ def get_transaction(_hash)
16
+ load_transaction(_hash).refresh
17
+ end
18
+
19
+ def load_transaction(_hash)
20
+ Transaction.new(connection, _hash)
21
+ end
22
+
23
+ def load_account(from_pk: nil)
24
+ Etherlite::Account::PrivateKey.new connection, from_pk
25
+ end
26
+
27
+ def load_address(_address)
28
+ Etherlite::Address.new(connection, Etherlite::Utils.normalize_address_param(_address))
29
+ end
30
+
15
31
  def register_account(_passphrase)
16
32
  address = connection.ipc_call(:personal_newAccount, _passphrase)
17
33
  Etherlite::Account::Local.new @connection, Etherlite::Utils.normalize_address(address)
@@ -28,7 +44,12 @@ module Etherlite
28
44
  end
29
45
 
30
46
  def account_from_pk(_pk)
31
- Etherlite::Account::PrivateKey.new connection, _pk
47
+ Etherlite.logger.warn(
48
+ "use of 'account_from_pk' is deprecated and will be removed in next version, \
49
+ use 'load_account' instead"
50
+ )
51
+
52
+ load_account(from_pk: _pk)
32
53
  end
33
54
 
34
55
  def_delegators :default_account, :unlock, :lock, :normalized_address, :transfer_to, :call
@@ -17,6 +17,10 @@ module Etherlite
17
17
  Etherlite::Utils.hex_to_uint ipc_call(:eth_getTransactionCount, _address, _block)
18
18
  end
19
19
 
20
+ def eth_get_balance(_address, _block = 'latest')
21
+ Etherlite::Utils.hex_to_uint ipc_call(:eth_getBalance, _address, _block)
22
+ end
23
+
20
24
  def eth_call(_params, _block = 'latest')
21
25
  ipc_call(:eth_call, _params, _block)
22
26
  end
@@ -24,7 +24,7 @@ module Etherlite::Abi
24
24
  private
25
25
 
26
26
  def unlinked_binary
27
- @artifact['unlinked_binary'] || ''
27
+ @artifact['unlinked_binary'] || @artifact['bytecode'] || ''
28
28
  end
29
29
 
30
30
  def abi_definitions
@@ -10,11 +10,25 @@ module Etherlite
10
10
 
11
11
  def refresh
12
12
  @receipt = @connection.eth_get_transaction_receipt(@tx_hash) || {}
13
- mined?
13
+ self
14
+ end
15
+
16
+ def removed?
17
+ @receipt.nil?
18
+ end
19
+
20
+ def succeeded?
21
+ !removed? && @receipt['status'] == 1
14
22
  end
15
23
 
16
24
  def mined?
17
- @receipt.key? 'blockNumber'
25
+ !removed? && @receipt.key?('blockNumber')
26
+ end
27
+
28
+ def confirmations
29
+ return 0 unless mined?
30
+
31
+ @connection.eth_block_number - block_number
18
32
  end
19
33
 
20
34
  def gas_used
@@ -31,7 +45,8 @@ module Etherlite
31
45
 
32
46
  def wait_for_block(timeout: 120)
33
47
  start = Time.now
34
- while !refresh
48
+ while !refresh.mined?
49
+ return false if removed?
35
50
  return false if Time.now - start > timeout
36
51
  sleep 1
37
52
  end
@@ -14,6 +14,9 @@ module Etherlite::Types
14
14
  end
15
15
 
16
16
  def encode(_value)
17
+ raise ArgumentError, "invalid argument type for 'bytes'" unless _value.is_a? ::String
18
+
19
+ _value.unpack('H*').first.rjust(64, '0')
17
20
  end
18
21
  end
19
22
  end
@@ -1,3 +1,3 @@
1
1
  module Etherlite
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Baixas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-29 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: digest-sha3