forest/rpc/methods/eth/
eth_tx.rs

1// Copyright 2019-2025 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4use super::*;
5pub use crate::eth::{
6    EIP_1559_TX_TYPE, EIP_LEGACY_TX_TYPE, ETH_LEGACY_HOMESTEAD_TX_CHAIN_ID, EthTx,
7};
8
9impl From<EthLegacyHomesteadTxArgs> for ApiEthTx {
10    fn from(
11        EthLegacyHomesteadTxArgs {
12            nonce,
13            gas_price,
14            gas_limit,
15            to,
16            value,
17            input,
18            v,
19            r,
20            s,
21        }: EthLegacyHomesteadTxArgs,
22    ) -> Self {
23        Self {
24            chain_id: ETH_LEGACY_HOMESTEAD_TX_CHAIN_ID.into(),
25            r#type: EIP_LEGACY_TX_TYPE.into(),
26            nonce: nonce.into(),
27            gas_price: Some(gas_price.into()),
28            gas: gas_limit.into(),
29            to,
30            value: value.into(),
31            input: input.into(),
32            v: v.into(),
33            r: r.into(),
34            s: s.into(),
35            ..Default::default()
36        }
37    }
38}
39
40impl From<EthLegacyEip155TxArgs> for ApiEthTx {
41    fn from(
42        EthLegacyEip155TxArgs {
43            chain_id,
44            nonce,
45            gas_price,
46            gas_limit,
47            to,
48            value,
49            input,
50            v,
51            r,
52            s,
53        }: EthLegacyEip155TxArgs,
54    ) -> Self {
55        Self {
56            chain_id: chain_id.into(),
57            r#type: EIP_LEGACY_TX_TYPE.into(),
58            nonce: nonce.into(),
59            gas_price: Some(gas_price.into()),
60            gas: gas_limit.into(),
61            to,
62            value: value.into(),
63            input: input.into(),
64            v: v.into(),
65            r: r.into(),
66            s: s.into(),
67            ..Default::default()
68        }
69    }
70}
71
72impl From<EthEip1559TxArgs> for ApiEthTx {
73    fn from(
74        EthEip1559TxArgs {
75            chain_id,
76            nonce,
77            to,
78            value,
79            max_fee_per_gas,
80            max_priority_fee_per_gas,
81            gas_limit,
82            input,
83            v,
84            r,
85            s,
86        }: EthEip1559TxArgs,
87    ) -> Self {
88        Self {
89            chain_id: chain_id.into(),
90            r#type: EthUint64(EIP_1559_TX_TYPE.into()),
91            nonce: nonce.into(),
92            gas: gas_limit.into(),
93            to,
94            value: value.into(),
95            max_fee_per_gas: Some(max_fee_per_gas.into()),
96            max_priority_fee_per_gas: Some(max_priority_fee_per_gas.into()),
97            input: input.into(),
98            v: v.into(),
99            r: r.into(),
100            s: s.into(),
101            ..Default::default()
102        }
103    }
104}
105
106impl From<EthTx> for ApiEthTx {
107    fn from(value: EthTx) -> Self {
108        use EthTx::*;
109        match value {
110            Homestead(tx) => (*tx).into(),
111            Eip1559(tx) => (*tx).into(),
112            Eip155(tx) => (*tx).into(),
113        }
114    }
115}