Search documentation of Cartouche

# Cartouche.TraceCall (Cartouche v0.1.2)

Copy Markdown View Source

Represents an Ethereum `eth_callMany` trace, which contains information about the call graph of the speculative execution of several transactions.

See `Cartouche.RPC.trace_call_many` for getting traces from an Ethereum JSON-RPC host.

Note: `state_diff` and `vm_trace` are currently not supported and left `nil`

See also:

- Infura docs: https://docs.infura.io/api/networks/ethereum/json-rpc-methods/trace-methods/trace_callmany

## Summary

### Types

t()

### Functions

deserialize(map)

Deserializes a single of trace result from `trace_callMany`.

deserialize_many(trace_calls)

Deserializes an array of trace results from `trace_callMany`.

serialize(trace_call)

Deserializes a single of trace result from `trace_callMany`.

## Types

# t()

    @type t() :: %Cartouche.TraceCall{
      output: binary(),
      state_diff: nil,
      trace: [Cartouche.Trace.t()],
      vm_trace: nil
    }

## Functions

# deserialize(map)

    @spec deserialize(map()) :: t() | no_return()

Deserializes a single of trace result from `trace_callMany`.

## Examples

    iex> use Cartouche.Hex
    iex> %{
    ...>   "output" => "0x",
    ...>   "stateDiff" => nil,
    ...>   "trace" => [
    ...>     %{
    ...>       "action" => %{
    ...>         "callType" => "call",
    ...>         "from" => "0x0000000000000000000000000000000000000000",
    ...>         "gas" => "0x1dcd0f58",
    ...>         "input" =>
    ...>           "0xd1692f56000000000000000000000000142da9114e5a98e015aa95afca0585e84832a612000000000000000000000000142da9114e5a98e015aa95afca0585e84832a6120000000000000000000000000000000000000000000000000000000000000000",
    ...>         "to" => "0x13172ee393713fba9925a9a752341ebd31e8d9a7",
    ...>         "value" => "0x0"
    ...>       },
    ...>       "error" => "Reverted",
    ...>       "result" => %{"gasUsed" => "0x1d55dd47", "output" => "0x"},
    ...>       "subtraces" => 1,
    ...>       "traceAddress" => [],
    ...>       "type" => "call"
    ...>     },
    ...>     %{
    ...>       "action" => %{
    ...>         "from" => "0x13172ee393713fba9925a9a752341ebd31e8d9a7",
    ...>         "gas" => "0x1d555c99",
    ...>         "init" =>
    ...>           " ",
    ...>         "value" => "0x0"
    ...>       },
    ...>       "error" => "contract address collision",
    ...>       "result" => nil,
    ...>       "subtraces" => 0,
    ...>       "traceAddress" => [0],
    ...>       "type" => "create"
    ...>     }
    ...>   ],
    ...>   "vmTrace" => nil
    ...> }
    ...> |> Cartouche.TraceCall.deserialize()
    %Cartouche.TraceCall{
      output: "",
      state_diff: nil,
      trace: [
        %Cartouche.Trace{
          action: %Cartouche.Trace.Action{
            call_type: "call",
            init: nil,
            from: ~h[0x0000000000000000000000000000000000000000],
            gas: 499_978_072,
            input: ~h[0xd1692f56000000000000000000000000142da9114e5a98e015aa95afca0585e84832a612000000000000000000000000142da9114e5a98e015aa95afca0585e84832a6120000000000000000000000000000000000000000000000000000000000000000],
            to: ~h[0x13172ee393713fba9925a9a752341ebd31e8d9a7],
            value: 0
          },
          block_hash: nil,
          block_number: nil,
          gas_used: 492_166_471,
          error: "Reverted",
          output: "",
          result_code: nil,
          result_address: nil,
          subtraces: 1,
          trace_address: [],
          transaction_hash: nil,
          transaction_position: nil,
          type: "call"
        },
        %Cartouche.Trace{
          action: %Cartouche.Trace.Action{
            call_type: nil,
            init: ~h[ ],
            from: ~h[0x13172ee393713fba9925a9a752341ebd31e8d9a7],
            gas: 492_133_529,
            input: nil,
            to: nil,
            value: 0
          },
          block_hash: nil,
          block_number: nil,
          gas_used: nil,
          error: "contract address collision",
          output: nil,
          result_code: nil,
          result_address: nil,
          subtraces: 0,
          trace_address: [0],
          transaction_hash: nil,
          transaction_position: nil,
          type: "create"
        }
      ],
      vm_trace: nil
    }

# deserialize_many(trace_calls)

    @spec deserialize_many([map()]) :: [t()] | no_return()

Deserializes an array of trace results from `trace_callMany`.

## Examples

    iex> use Cartouche.Hex
    iex> [
    ...>   %{
    ...>     "output" => "0x",
    ...>     "stateDiff" => nil,
    ...>     "trace" => [
    ...>       %{
    ...>         "action" => %{
    ...>           "callType" => "call",
    ...>           "from" => "0x0000000000000000000000000000000000000000",
    ...>           "gas" => "0x1dcd0f58",
    ...>           "input" =>
    ...>             "0xd1692f56000000000000000000000000142da9114e5a98e015aa95afca0585e84832a612000000000000000000000000142da9114e5a98e015aa95afca0585e84832a6120000000000000000000000000000000000000000000000000000000000000000",
    ...>           "to" => "0x13172ee393713fba9925a9a752341ebd31e8d9a7",
    ...>           "value" => "0x0"
    ...>         },
    ...>         "error" => "Reverted",
    ...>         "result" => %{"gasUsed" => "0x1d55dd47", "output" => "0x"},
    ...>         "subtraces" => 1,
    ...>         "traceAddress" => [],
    ...>         "type" => "call"
    ...>       },
    ...>       %{
    ...>         "action" => %{
    ...>           "from" => "0x13172ee393713fba9925a9a752341ebd31e8d9a7",
    ...>           "gas" => "0x1d555c99",
    ...>           "init" =>
    ...>             " ",
    ...>           "value" => "0x0"
    ...>         },
    ...>         "error" => "contract address collision",
    ...>         "result" => nil,
    ...>         "subtraces" => 0,
    ...>         "traceAddress" => [0],
    ...>         "type" => "create"
    ...>       }
    ...>     ],
    ...>     "vmTrace" => nil
    ...>   },
    ...>   %{
    ...>     "output" => "0x00000000000000000000000079edbc4f3a6aa2266cd469cc544501743be8b078",
    ...>     "stateDiff" => nil,
    ...>     "trace" => [
    ...>       %{
    ...>         "action" => %{
    ...>           "callType" => "call",
    ...>           "from" => "0x0000000000000000000000000000000000000000",
    ...>           "gas" => "0x1dcc91bc",
    ...>           "input" =>
    ...>             " ",
    ...>           "to" => "0x2926631647877e9a84bb7e3a0821d643bf8d63c0",
    ...>           "value" => "0x0"
    ...>         },
    ...>         "result" => %{
    ...>           "gasUsed" => "0x10ca",
    ...>           "output" => "0x00000000000000000000000079edbc4f3a6aa2266cd469cc544501743be8b078"
    ...>         },
    ...>         "subtraces" => 0,
    ...>         "traceAddress" => [],
    ...>         "type" => "call"
    ...>       }
    ...>     ],
    ...>     "vmTrace" => nil
    ...>   },
    ...>   %{
    ...>     "output" => "0x82b42900",
    ...>     "stateDiff" => nil,
    ...>     "trace" => [
    ...>       %{
    ...>         "action" => %{
    ...>           "callType" => "call",
    ...>           "from" => "0x0000000000000000000000000000000000000000",
    ...>           "gas" => "0x1dcd0b70",
    ...>           "input" =>
    ...>             " ",
    ...>           "to" => "0x6e995746b61c48c5bdf58fc788b1aea08dfb7e43",
    ...>           "value" => "0x0"
    ...>         },
    ...>         "error" => "Reverted",
    ...>         "result" => %{"gasUsed" => "0x106a", "output" => "0x82b42900"},
    ...>         "subtraces" => 1,
    ...>         "traceAddress" => [],
    ...>         "type" => "call"
    ...>       },
    ...>       %{
    ...>         "action" => %{
    ...>           "callType" => "delegatecall",
    ...>           "from" => "0x6e995746b61c48c5bdf58fc788b1aea08dfb7e43",
    ...>           "gas" => "0x1d55cc7b",
    ...>           "input" =>
    ...>             " ",
    ...>           "to" => "0x49e5d261e95f6a02505078bb339fecb210a0b634",
    ...>           "value" => "0x0"
    ...>         },
    ...>         "error" => "Reverted",
    ...>         "result" => %{"gasUsed" => "0x552", "output" => "0x82b42900"},
    ...>         "subtraces" => 1,
    ...>         "traceAddress" => [0],
    ...>         "type" => "call"
    ...>       },
    ...>       %{
    ...>         "action" => %{
    ...>           "callType" => "staticcall",
    ...>           "from" => "0x6e995746b61c48c5bdf58fc788b1aea08dfb7e43",
    ...>           "gas" => "0x1ce0725a",
    ...>           "input" => "0xc34c08e5",
    ...>           "to" => "0x6e995746b61c48c5bdf58fc788b1aea08dfb7e43",
    ...>           "value" => "0x0"
    ...>         },
    ...>         "result" => %{
    ...>           "gasUsed" => "0xbe",
    ...>           "output" => "0x000000000000000000000000142da9114e5a98e015aa95afca0585e84832a612"
    ...>         },
    ...>         "subtraces" => 0,
    ...>         "traceAddress" => [0, 0],
    ...>         "type" => "call"
    ...>       }
    ...>     ],
    ...>     "vmTrace" => nil
    ...>   }
    ...> ]
    ...> |> Cartouche.TraceCall.deserialize_many()
    [
      %Cartouche.TraceCall{
        output: "",
        state_diff: nil,
        trace: [
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: "call",
              init: nil,
              from: ~h[0x0000000000000000000000000000000000000000],
              gas: 499_978_072,
              input: ~h[0xd1692f56000000000000000000000000142da9114e5a98e015aa95afca0585e84832a612000000000000000000000000142da9114e5a98e015aa95afca0585e84832a6120000000000000000000000000000000000000000000000000000000000000000],
              to: ~h[0x13172EE393713FBA9925A9A752341EBD31E8D9A7],
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: 492_166_471,
            error: "Reverted",
            output: "",
            result_code: nil,
            result_address: nil,
            subtraces: 1,
            trace_address: [],
            transaction_hash: nil,
            transaction_position: nil,
            type: "call"
          },
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: nil,
              init: ~h[ ],
              from: ~h[0x13172EE393713FBA9925A9A752341EBD31E8D9A7],
              gas: 492_133_529,
              input: nil,
              to: nil,
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: nil,
            error: "contract address collision",
            output: nil,
            result_code: nil,
            result_address: nil,
            subtraces: 0,
            trace_address: [0],
            transaction_hash: nil,
            transaction_position: nil,
            type: "create"
          }
        ],
        vm_trace: nil
      },
      %Cartouche.TraceCall{
        output: ~h[0x00000000000000000000000079EDBC4F3A6AA2266CD469CC544501743BE8B078],
        state_diff: nil,
        trace: [
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: "call",
              init: nil,
              from: ~h[0x0000000000000000000000000000000000000000],
              gas: 499_945_916,
              input: ~h[ ],
              to: ~h[0x2926631647877E9A84BB7E3A0821D643BF8D63C0],
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: 4298,
            error: nil,
            output: ~h[0x00000000000000000000000079EDBC4F3A6AA2266CD469CC544501743BE8B078],
            result_code: nil,
            result_address: nil,
            subtraces: 0,
            trace_address: [],
            transaction_hash: nil,
            transaction_position: nil,
            type: "call"
          }
        ],
        vm_trace: nil
      },
      %Cartouche.TraceCall{
        output: <<130, 180, 41, 0>>,
        state_diff: nil,
        trace: [
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: "call",
              init: nil,
              from: ~h[0x0000000000000000000000000000000000000000],
              gas: 499_977_072,
              input: ~h[ ],
              to: ~h[0x6E995746B61C48C5BDF58FC788B1AEA08DFB7E43],
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: 4202,
            error: "Reverted",
            output: <<130, 180, 41, 0>>,
            result_code: nil,
            result_address: nil,
            subtraces: 1,
            trace_address: [],
            transaction_hash: nil,
            transaction_position: nil,
            type: "call"
          },
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: "delegatecall",
              init: nil,
              from: ~h[0x6E995746B61C48C5BDF58FC788B1AEA08DFB7E43],
              gas: 492_162_171,
              input: ~h[ ],
              to: ~h[0x49E5D261E95F6A02505078BB339FECB210A0B634],
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: 1362,
            error: "Reverted",
            output: <<130, 180, 41, 0>>,
            result_code: nil,
            result_address: nil,
            subtraces: 1,
            trace_address: [0],
            transaction_hash: nil,
            transaction_position: nil,
            type: "call"
          },
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: "staticcall",
              init: nil,
              from: ~h[0x6E995746B61C48C5BDF58FC788B1AEA08DFB7E43],
              gas: 484_471_386,
              input: <<195, 76, 8, 229>>,
              to: ~h[0x6E995746B61C48C5BDF58FC788B1AEA08DFB7E43],
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: 190,
            error: nil,
            output: ~h[0x000000000000000000000000142DA9114E5A98E015AA95AFCA0585E84832A612],
            result_code: nil,
            result_address: nil,
            subtraces: 0,
            trace_address: [0, 0],
            transaction_hash: nil,
            transaction_position: nil,
            type: "call"
          }
        ],
        vm_trace: nil
      }
    ]

# serialize(trace_call)

    @spec serialize(t()) :: map()

Deserializes a single of trace result from `trace_callMany`.

## Examples

    iex> use Cartouche.Hex
    iex> %Cartouche.TraceCall{
    ...>   output: "",
    ...>   state_diff: nil,
    ...>   trace: [
    ...>     %Cartouche.Trace{
    ...>       action: %Cartouche.Trace.Action{
    ...>         call_type: "call",
    ...>         init: nil,
    ...>         from: ~h[0x0000000000000000000000000000000000000000],
    ...>         gas: 499_978_072,
    ...>         input: ~h[0xd1692f56000000000000000000000000142da9114e5a98e015aa95afca0585e84832a612000000000000000000000000142da9114e5a98e015aa95afca0585e84832a6120000000000000000000000000000000000000000000000000000000000000000],
    ...>         to: ~h[0x13172ee393713fba9925a9a752341ebd31e8d9a7],
    ...>         value: 0
    ...>       },
    ...>       block_hash: nil,
    ...>       block_number: nil,
    ...>       gas_used: 492_166_471,
    ...>       error: "Reverted",
    ...>       output: "",
    ...>       result_code: nil,
    ...>       result_address: nil,
    ...>       subtraces: 1,
    ...>       trace_address: [],
    ...>       transaction_hash: nil,
    ...>       transaction_position: nil,
    ...>       type: "call"
    ...>     },
    ...>     %Cartouche.Trace{
    ...>       action: %Cartouche.Trace.Action{
    ...>         call_type: nil,
    ...>         init: ~h[ ],
    ...>         from: ~h[0x13172ee393713fba9925a9a752341ebd31e8d9a7],
    ...>         gas: 492_133_529,
    ...>         input: nil,
    ...>         to: nil,
    ...>         value: 0
    ...>       },
    ...>       block_hash: nil,
    ...>       block_number: nil,
    ...>       gas_used: nil,
    ...>       error: "contract address collision",
    ...>       output: nil,
    ...>       result_code: nil,
    ...>       result_address: nil,
    ...>       subtraces: 0,
    ...>       trace_address: [0],
    ...>       transaction_hash: nil,
    ...>       transaction_position: nil,
    ...>       type: "create"
    ...>     }
    ...>   ],
    ...>   vm_trace: nil
    ...> }
    ...> |> Cartouche.TraceCall.serialize()
    %{
      output: "0x",
      stateDiff: nil,
      trace: [
        %{
          action: %{
            callType: "call",
            from: "0x0000000000000000000000000000000000000000",
            gas: "0x1DCD0F58",
            input:
              "0xd1692f56000000000000000000000000142da9114e5a98e015aa95afca0585e84832a612000000000000000000000000142da9114e5a98e015aa95afca0585e84832a6120000000000000000000000000000000000000000000000000000000000000000",
            to: "0x13172EE393713fbA9925A9A752341Ebd31e8D9a7",
            value: "0x0",
            init: nil
          },
          error: "Reverted",
          result: %{gasUsed: "0x1D55DD47", output: "0x", address: nil, code: nil},
          subtraces: 1,
          traceAddress: [],
          type: "call",
          blockHash: nil,
          blockNumber: nil,
          transactionHash: nil,
          transactionPosition: nil
        },
        %{
          action: %{
            from: "0x13172EE393713fbA9925A9A752341Ebd31e8D9a7",
            gas: "0x1D555C99",
            init:
              " ",
            value: "0x0",
            callType: nil,
            input: nil,
            to: nil
          },
          error: "contract address collision",
          result: %{code: nil, output: nil, address: nil, gasUsed: nil},
          subtraces: 0,
          traceAddress: [0],
          type: "create",
          blockHash: nil,
          blockNumber: nil,
          transactionHash: nil,
          transactionPosition: nil
        }
      ],
      vmTrace: nil
    }