Class: Web3::Eth::CallTrace

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/web3ethereum/call_trace.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(trace_data) ⇒ CallTrace

Returns a new instance of CallTrace.



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

def initialize trace_data
  @raw_data = trace_data

  trace_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/call_trace.rb', line 8

def raw_data
  @raw_data
end

Instance Method Details

#balance_etherObject



77
78
79
# File 'lib/web3ethereum/call_trace.rb', line 77

def balance_ether
  wei_to_ether action['balance'].to_i(16)
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



62
63
64
65
66
67
68
69
70
# File 'lib/web3ethereum/call_trace.rb', line 62

def call_input_data
  if creates && input
    input[/a165627a7a72305820\w{64}0029(\w*)/,1]
  elsif input && input.length>10
    input[10..input.length]
  else
    []
  end
end

#createsObject



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

def creates
  action && result && action['init'] && result['address']
end

#fromObject



28
29
30
# File 'lib/web3ethereum/call_trace.rb', line 28

def from
  action['from']
end

#gas_usedObject



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

def gas_used
  result && from_hex(result['gasUsed'])
end

#inputObject



36
37
38
# File 'lib/web3ethereum/call_trace.rb', line 36

def input
  action['input'] || action['init']
end

#method_hashObject



48
49
50
51
52
53
54
# File 'lib/web3ethereum/call_trace.rb', line 48

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

#outputObject



40
41
42
# File 'lib/web3ethereum/call_trace.rb', line 40

def output
  result && result['output']
end

#success?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/web3ethereum/call_trace.rb', line 81

def success?
  !raw_data['error']
end

#suicide?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/web3ethereum/call_trace.rb', line 73

def suicide?
  type=='suicide'
end

#toObject



32
33
34
# File 'lib/web3ethereum/call_trace.rb', line 32

def to
  action['to']
end

#value_ethObject



24
25
26
# File 'lib/web3ethereum/call_trace.rb', line 24

def value_eth
  wei_to_ether from_hex action['value']
end

#value_weiObject



20
21
22
# File 'lib/web3ethereum/call_trace.rb', line 20

def value_wei
  from_hex action['value']
end