Class: Etherlite::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/etherlite/transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_connection, _tx_hash) ⇒ Transaction

Returns a new instance of Transaction.



5
6
7
8
9
# File 'lib/etherlite/transaction.rb', line 5

def initialize(_connection, _tx_hash)
  @connection = _connection
  @tx_hash = _tx_hash
  @receipt = {}
end

Instance Attribute Details

#receiptObject (readonly)

Returns the value of attribute receipt.



3
4
5
# File 'lib/etherlite/transaction.rb', line 3

def receipt
  @receipt
end

#tx_hashObject (readonly)

Returns the value of attribute tx_hash.



3
4
5
# File 'lib/etherlite/transaction.rb', line 3

def tx_hash
  @tx_hash
end

Instance Method Details

#block_numberObject



24
25
26
# File 'lib/etherlite/transaction.rb', line 24

def block_number
  Utils.hex_to_uint @receipt['blockNumber']
end

#contract_addressObject



28
29
30
# File 'lib/etherlite/transaction.rb', line 28

def contract_address
  @receipt['contractAddress']
end

#gas_usedObject



20
21
22
# File 'lib/etherlite/transaction.rb', line 20

def gas_used
  Utils.hex_to_uint @receipt['gasUsed']
end

#mined?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/etherlite/transaction.rb', line 16

def mined?
  @receipt.key? 'blockNumber'
end

#refreshObject



11
12
13
14
# File 'lib/etherlite/transaction.rb', line 11

def refresh
  @receipt = @connection.eth_get_transaction_receipt(@tx_hash) || {}
  mined?
end

#wait_for_block(timeout: 120) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/etherlite/transaction.rb', line 32

def wait_for_block(timeout: 120)
  start = Time.now
  while !refresh
    return false if Time.now - start > timeout
    sleep 1
  end

  true
end