1
// Copyright 2019-2022 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

            
19
use super::serialization::*;
20
use serde::Serialize;
21

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

            
26
#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
27
#[serde(rename_all = "camelCase")]
28
pub struct TransactionTrace {
29
	#[serde(flatten)]
30
	pub action: TransactionTraceAction,
31
	#[serde(serialize_with = "h256_0x_serialize")]
32
	pub block_hash: H256,
33
	pub block_number: u32,
34
	#[serde(flatten)]
35
	pub output: TransactionTraceOutput,
36
	pub subtraces: u32,
37
	pub trace_address: Vec<u32>,
38
	#[serde(serialize_with = "h256_0x_serialize")]
39
	pub transaction_hash: H256,
40
	pub transaction_position: u32,
41
}
42

            
43
#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
44
#[serde(rename_all = "camelCase", tag = "type", content = "action")]
45
pub enum TransactionTraceAction {
46
	#[serde(rename_all = "camelCase")]
47
	Call {
48
		call_type: super::CallType,
49
		from: H160,
50
		gas: U256,
51
		#[serde(serialize_with = "bytes_0x_serialize")]
52
		input: Vec<u8>,
53
		to: H160,
54
		value: U256,
55
	},
56
	#[serde(rename_all = "camelCase")]
57
	Create {
58
		creation_method: super::CreateType,
59
		from: H160,
60
		gas: U256,
61
		#[serde(serialize_with = "bytes_0x_serialize")]
62
		init: Vec<u8>,
63
		value: U256,
64
	},
65
	#[serde(rename_all = "camelCase")]
66
	Suicide {
67
		address: H160,
68
		balance: U256,
69
		refund_address: H160,
70
	},
71
}
72

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

            
80
#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
81
#[serde(rename_all = "camelCase", untagged)]
82
pub enum TransactionTraceResult {
83
	#[serde(rename_all = "camelCase")]
84
	Call {
85
		gas_used: U256,
86
		#[serde(serialize_with = "bytes_0x_serialize")]
87
		output: Vec<u8>,
88
	},
89
	#[serde(rename_all = "camelCase")]
90
	Create {
91
		address: H160,
92
		#[serde(serialize_with = "bytes_0x_serialize")]
93
		code: Vec<u8>,
94
		gas_used: U256,
95
	},
96
	Suicide,
97
}