Class: Web3::Eth::Debug::TransactionCallTrace

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/web3/eth/debug/transaction_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(raw, traceAddress = [], parent = nil) ⇒ TransactionCallTrace

Returns a new instance of TransactionCallTrace.



8
9
10
11
12
13
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 8

def initialize raw, traceAddress = [], parent = nil
  @raw_data = raw
  @traceAddress = traceAddress
  @parent = parent
  @calls = raw['calls'] ? raw['calls'].each_with_index.map{|c,i| TransactionCallTrace.new c, (traceAddress + [i]), self } : []
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



7
8
9
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 7

def calls
  @calls
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 7

def parent
  @parent
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



7
8
9
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 7

def raw_data
  @raw_data
end

#traceAddressObject (readonly)

Returns the value of attribute traceAddress.



7
8
9
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 7

def traceAddress
  @traceAddress
end

Instance Method Details

#actionObject



20
21
22
23
24
25
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 20

def action
  {
      'callType' => type.downcase,
      'address' => ( suicide? ? parent.smart_contract : raw_data['to'])
  }
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



93
94
95
96
97
98
99
100
101
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 93

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



31
32
33
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 31

def creates
  (type=='CREATE' || type=='CREATE2') ? to : nil
end

#errorObject



83
84
85
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 83

def error
  raw_data['error']
end

#fromObject



47
48
49
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 47

def from
  raw_data['from']
end

#gasObject



63
64
65
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 63

def gas
  from_hex raw_data['gas']
end

#gas_usedObject



67
68
69
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 67

def gas_used
  from_hex raw_data['gasUsed']
end

#inputObject



71
72
73
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 71

def input
  raw_data['input']
end

#method_hashObject



35
36
37
38
39
40
41
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 35

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

#outputObject



75
76
77
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 75

def output
  raw_data['output']
end

#smart_contractObject



27
28
29
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 27

def smart_contract
  ['STATICCALL','CALL'].include?(type) ? to : from
end

#success?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 87

def success?
  !raw_data['error']
end

#suicide?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 43

def suicide?
  type=='SELFDESTRUCT'
end

#timeObject



79
80
81
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 79

def time
  raw_data['time']
end

#toObject



51
52
53
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 51

def to
  raw_data['to']
end

#typeObject

CALL STATICCALL DELEGATECALL CREATE SELFDESTRUCT



16
17
18
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 16

def type
  raw_data['type']
end

#value_ethObject



59
60
61
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 59

def value_eth
  wei_to_ether value_wei
end

#value_weiObject



55
56
57
# File 'lib/web3/eth/debug/transaction_call_trace.rb', line 55

def value_wei
  from_hex raw_data['value']
end