moonbeam_client_evm_tracing/types/
block.rs

1// Copyright 2019-2025 PureStake Inc.
2// This file is part of Moonbeam.
3
4// Moonbeam is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Moonbeam is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Types for tracing all Ethereum transactions of a block.
18
19use super::serialization::*;
20use serde::Serialize;
21
22use ethereum_types::{H160, H256, U256};
23use parity_scale_codec::{Decode, Encode};
24use sp_std::vec::Vec;
25
26/// Block transaction trace.
27#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
28#[serde(rename_all = "camelCase")]
29pub struct BlockTransactionTrace {
30    #[serde(serialize_with = "h256_0x_serialize")]
31    pub tx_hash: H256,
32    pub result: crate::types::single::TransactionTrace,
33    #[serde(skip_serializing)]
34    pub tx_position: u32,
35}
36
37#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
38#[serde(rename_all = "camelCase")]
39pub struct TransactionTrace {
40    #[serde(flatten)]
41    pub action: TransactionTraceAction,
42    #[serde(serialize_with = "h256_0x_serialize")]
43    pub block_hash: H256,
44    pub block_number: u32,
45    #[serde(flatten)]
46    pub output: TransactionTraceOutput,
47    pub subtraces: u32,
48    pub trace_address: Vec<u32>,
49    #[serde(serialize_with = "h256_0x_serialize")]
50    pub transaction_hash: H256,
51    pub transaction_position: u32,
52}
53
54#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
55#[serde(rename_all = "camelCase", tag = "type", content = "action")]
56pub enum TransactionTraceAction {
57    #[serde(rename_all = "camelCase")]
58    Call {
59        call_type: super::CallType,
60        from: H160,
61        gas: U256,
62        #[serde(serialize_with = "bytes_0x_serialize")]
63        input: Vec<u8>,
64        to: H160,
65        value: U256,
66    },
67    #[serde(rename_all = "camelCase")]
68    Create {
69        creation_method: super::CreateType,
70        from: H160,
71        gas: U256,
72        #[serde(serialize_with = "bytes_0x_serialize")]
73        init: Vec<u8>,
74        value: U256,
75    },
76    #[serde(rename_all = "camelCase")]
77    Suicide {
78        address: H160,
79        balance: U256,
80        refund_address: H160,
81    },
82}
83
84#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
85#[serde(rename_all = "camelCase")]
86pub enum TransactionTraceOutput {
87    Result(TransactionTraceResult),
88    Error(#[serde(serialize_with = "string_serialize")] Vec<u8>),
89}
90
91#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
92#[serde(rename_all = "camelCase", untagged)]
93pub enum TransactionTraceResult {
94    #[serde(rename_all = "camelCase")]
95    Call {
96        gas_used: U256,
97        #[serde(serialize_with = "bytes_0x_serialize")]
98        output: Vec<u8>,
99    },
100    #[serde(rename_all = "camelCase")]
101    Create {
102        address: H160,
103        #[serde(serialize_with = "bytes_0x_serialize")]
104        code: Vec<u8>,
105        gas_used: U256,
106    },
107    Suicide,
108}