referrerpolicy=no-referrer-when-downgrade

pallet_revive/evm/api/
block.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10//  http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18use super::{Bytes, Bytes8, Bytes256, HashesOrTransactionInfos};
19use alloc::vec::Vec;
20use codec::{Decode, Encode};
21use ethereum_types::*;
22use pallet_revive_types::runtime_api::*;
23use scale_info::TypeInfo;
24
25/// Block object
26#[derive(Debug, Default, Clone, Eq, PartialEq, TypeInfo, Encode, Decode)]
27#[allow(missing_docs)]
28pub struct Block {
29	/// Base fee per gas
30	pub base_fee_per_gas: U256,
31	/// Blob gas used
32	pub blob_gas_used: U256,
33	/// Difficulty
34	pub difficulty: U256,
35	/// Excess blob gas
36	pub excess_blob_gas: U256,
37	/// Extra data
38	pub extra_data: Bytes,
39	/// Gas limit
40	pub gas_limit: U256,
41	/// Gas used
42	pub gas_used: U256,
43	/// Hash
44	pub hash: H256,
45	/// Bloom filter
46	pub logs_bloom: Bytes256,
47	/// Coinbase
48	pub miner: Address,
49	/// Mix hash
50	pub mix_hash: H256,
51	/// Nonce
52	pub nonce: Bytes8,
53	/// Number
54	pub number: U256,
55	/// Parent Beacon Block Root
56	pub parent_beacon_block_root: Option<H256>,
57	/// Parent block hash
58	pub parent_hash: H256,
59	/// Receipts root
60	pub receipts_root: H256,
61	/// Requests root
62	pub requests_hash: Option<H256>,
63	/// Ommers hash
64	pub sha_3_uncles: H256,
65	/// Block size
66	pub size: U256,
67	/// State root
68	pub state_root: H256,
69	/// Timestamp
70	pub timestamp: U256,
71	/// Total difficulty
72	pub total_difficulty: Option<U256>,
73	pub transactions: HashesOrTransactionInfos,
74	/// Transactions root
75	pub transactions_root: H256,
76	/// Uncles
77	pub uncles: Vec<H256>,
78	/// Withdrawals
79	pub withdrawals: Vec<Withdrawal>,
80	/// Withdrawals root
81	pub withdrawals_root: H256,
82}
83
84impl From<Block> for BlockV1 {
85	fn from(value: Block) -> Self {
86		Self {
87			base_fee_per_gas: value.base_fee_per_gas,
88			blob_gas_used: value.blob_gas_used,
89			difficulty: value.difficulty,
90			excess_blob_gas: value.excess_blob_gas,
91			extra_data: value.extra_data,
92			gas_limit: value.gas_limit,
93			gas_used: value.gas_used,
94			hash: value.hash,
95			logs_bloom: value.logs_bloom,
96			miner: value.miner,
97			mix_hash: value.mix_hash,
98			nonce: value.nonce,
99			number: value.number,
100			parent_beacon_block_root: value.parent_beacon_block_root,
101			parent_hash: value.parent_hash,
102			receipts_root: value.receipts_root,
103			requests_hash: value.requests_hash,
104			sha_3_uncles: value.sha_3_uncles,
105			size: value.size,
106			state_root: value.state_root,
107			timestamp: value.timestamp,
108			total_difficulty: value.total_difficulty,
109			transactions: value.transactions.into(),
110			transactions_root: value.transactions_root,
111			uncles: value.uncles,
112			withdrawals: value.withdrawals.into_iter().map(Into::into).collect(),
113			withdrawals_root: value.withdrawals_root,
114		}
115	}
116}
117
118/// Validator withdrawal
119#[derive(Debug, Default, Clone, Eq, PartialEq, TypeInfo, Encode, Decode)]
120pub struct Withdrawal {
121	/// recipient address for withdrawal value
122	pub address: Address,
123	/// value contained in withdrawal
124	pub amount: U256,
125	/// index of withdrawal
126	pub index: U256,
127	/// index of validator that generated withdrawal
128	pub validator_index: U256,
129}
130
131impl From<Withdrawal> for WithdrawalV1 {
132	fn from(value: Withdrawal) -> Self {
133		Self {
134			address: value.address,
135			amount: value.amount,
136			index: value.index,
137			validator_index: value.validator_index,
138		}
139	}
140}