1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2019-2025 PureStake Inc.
// This file is part of Moonbeam.

// Moonbeam is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Moonbeam is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.

//! Types for tracing all Ethereum transactions of a block.

use super::serialization::*;
use serde::Serialize;

use ethereum_types::{H160, H256, U256};
use parity_scale_codec::{Decode, Encode};
use sp_std::vec::Vec;

/// Block transaction trace.
#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct BlockTransactionTrace {
	#[serde(serialize_with = "h256_0x_serialize")]
	pub tx_hash: H256,
	pub result: crate::types::single::TransactionTrace,
	#[serde(skip_serializing)]
	pub tx_position: u32,
}

#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TransactionTrace {
	#[serde(flatten)]
	pub action: TransactionTraceAction,
	#[serde(serialize_with = "h256_0x_serialize")]
	pub block_hash: H256,
	pub block_number: u32,
	#[serde(flatten)]
	pub output: TransactionTraceOutput,
	pub subtraces: u32,
	pub trace_address: Vec<u32>,
	#[serde(serialize_with = "h256_0x_serialize")]
	pub transaction_hash: H256,
	pub transaction_position: u32,
}

#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
#[serde(rename_all = "camelCase", tag = "type", content = "action")]
pub enum TransactionTraceAction {
	#[serde(rename_all = "camelCase")]
	Call {
		call_type: super::CallType,
		from: H160,
		gas: U256,
		#[serde(serialize_with = "bytes_0x_serialize")]
		input: Vec<u8>,
		to: H160,
		value: U256,
	},
	#[serde(rename_all = "camelCase")]
	Create {
		creation_method: super::CreateType,
		from: H160,
		gas: U256,
		#[serde(serialize_with = "bytes_0x_serialize")]
		init: Vec<u8>,
		value: U256,
	},
	#[serde(rename_all = "camelCase")]
	Suicide {
		address: H160,
		balance: U256,
		refund_address: H160,
	},
}

#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum TransactionTraceOutput {
	Result(TransactionTraceResult),
	Error(#[serde(serialize_with = "string_serialize")] Vec<u8>),
}

#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
#[serde(rename_all = "camelCase", untagged)]
pub enum TransactionTraceResult {
	#[serde(rename_all = "camelCase")]
	Call {
		gas_used: U256,
		#[serde(serialize_with = "bytes_0x_serialize")]
		output: Vec<u8>,
	},
	#[serde(rename_all = "camelCase")]
	Create {
		address: H160,
		#[serde(serialize_with = "bytes_0x_serialize")]
		code: Vec<u8>,
		gas_used: U256,
	},
	Suicide,
}