Class: Web3::Eth::Transaction

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/web3ethereum/transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility

#from_hex, #hex, #remove_0x_head, #wei_to_ether

Constructor Details

#initialize(transaction_data) ⇒ Transaction

Returns a new instance of Transaction.



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

def initialize transaction_data
  @raw_data = transaction_data
  transaction_data.each do |k, v|
    self.instance_variable_set("@#{k}", v)
    self.class.send(:define_method, k, proc {self.instance_variable_get("@#{k}")})
  end
end

Instance Attribute Details

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



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

def raw_data
  @raw_data
end

Instance Method Details

#block_numberObject



38
39
40
41
42
# File 'lib/web3ethereum/transaction.rb', line 38

def block_number
  # if transaction is less than 12 seconds old, blockNumber will be nil
  # :. nil check before calling `to_hex` to avoid argument error
  blockNumber && from_hex(blockNumber)
end

#call_input_dataObject

suffix # 0xa1 0x65 ‘b’ ‘z’ ‘z’ ‘r’ ‘0’ 0x58 0x20 <32 bytes swarm hash> 0x00 0x29 look solidity.readthedocs.io/en/latest/metadata.html for details



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

def call_input_data
  if raw_data['creates'] && input
    fetch_constructor_data input
  elsif input && input.length>10
    input[10..input.length]
  else
    []
  end
end

#gas_limitObject



52
53
54
# File 'lib/web3ethereum/transaction.rb', line 52

def gas_limit
  from_hex gas
end

#gasPrice_ethObject



56
57
58
# File 'lib/web3ethereum/transaction.rb', line 56

def gasPrice_eth
  wei_to_ether from_hex gasPrice
end

#method_hashObject



18
19
20
21
22
23
24
# File 'lib/web3ethereum/transaction.rb', line 18

def method_hash
  if input && input.length>=10
    input[2...10]
  else
    nil
  end
end

#value_ethObject



48
49
50
# File 'lib/web3ethereum/transaction.rb', line 48

def value_eth
  wei_to_ether from_hex value
end

#value_weiObject



44
45
46
# File 'lib/web3ethereum/transaction.rb', line 44

def value_wei
  from_hex value
end