Class: EvmClient::Transaction

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

Constant Summary collapse

DEFAULT_TIMEOUT =
300.seconds
DEFAULT_STEP =
5.seconds

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, connection, data, input_parameters = []) ⇒ Transaction

Returns a new instance of Transaction.



10
11
12
13
14
15
16
# File 'lib/evm_client/transaction.rb', line 10

def initialize(id, connection, data, input_parameters = [])
  @mined = false
  @connection = connection
  @id = id
  @input = data
  @input_parameters = input_parameters
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



8
9
10
# File 'lib/evm_client/transaction.rb', line 8

def connection
  @connection
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/evm_client/transaction.rb', line 8

def id
  @id
end

#inputObject

Returns the value of attribute input.



8
9
10
# File 'lib/evm_client/transaction.rb', line 8

def input
  @input
end

#input_parametersObject

Returns the value of attribute input_parameters.



8
9
10
# File 'lib/evm_client/transaction.rb', line 8

def input_parameters
  @input_parameters
end

#minedObject

Returns the value of attribute mined.



8
9
10
# File 'lib/evm_client/transaction.rb', line 8

def mined
  @mined
end

Class Method Details

.from_blockchain(address, connection = IpcClient.new) ⇒ Object



37
38
39
# File 'lib/evm_client/transaction.rb', line 37

def self.from_blockchain(address, connection = IpcClient.new)
  Transaction.new(address, connection, nil, nil)
end

Instance Method Details

#addressObject



18
19
20
# File 'lib/evm_client/transaction.rb', line 18

def address
  @id
end

#mined?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/evm_client/transaction.rb', line 22

def mined?
  return true if @mined
  tx = @connection.eth_get_transaction_by_hash(@id)
  @mined = !tx.nil? && !tx["result"].nil? && tx["result"]["blockNumber"].present?
end

#wait_for_miner(timeout: DEFAULT_TIMEOUT, step: DEFAULT_STEP) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/evm_client/transaction.rb', line 28

def wait_for_miner(timeout: DEFAULT_TIMEOUT, step: DEFAULT_STEP)
  start_time = Time.now
  loop do
    raise Timeout::Error if ((Time.now - start_time) > timeout)
    return true if self.mined?
    sleep step
  end
end