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
109
110
111
112
113
114
115
// Copyright 2019-2024 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use super::*;
pub use crate::eth::{
    EthTx, EIP_1559_TX_TYPE, EIP_LEGACY_TX_TYPE, ETH_LEGACY_HOMESTEAD_TX_CHAIN_ID,
};

impl From<EthLegacyHomesteadTxArgs> for ApiEthTx {
    fn from(
        EthLegacyHomesteadTxArgs {
            nonce,
            gas_price,
            gas_limit,
            to,
            value,
            input,
            v,
            r,
            s,
        }: EthLegacyHomesteadTxArgs,
    ) -> Self {
        Self {
            chain_id: ETH_LEGACY_HOMESTEAD_TX_CHAIN_ID.into(),
            r#type: EIP_LEGACY_TX_TYPE.into(),
            nonce: nonce.into(),
            gas_price: Some(gas_price.into()),
            gas: gas_limit.into(),
            to,
            value: value.into(),
            input: input.into(),
            v: v.into(),
            r: r.into(),
            s: s.into(),
            ..Default::default()
        }
    }
}

impl From<EthLegacyEip155TxArgs> for ApiEthTx {
    fn from(
        EthLegacyEip155TxArgs {
            chain_id,
            nonce,
            gas_price,
            gas_limit,
            to,
            value,
            input,
            v,
            r,
            s,
        }: EthLegacyEip155TxArgs,
    ) -> Self {
        Self {
            chain_id: chain_id.into(),
            r#type: EIP_LEGACY_TX_TYPE.into(),
            nonce: nonce.into(),
            gas_price: Some(gas_price.into()),
            gas: gas_limit.into(),
            to,
            value: value.into(),
            input: input.into(),
            v: v.into(),
            r: r.into(),
            s: s.into(),
            ..Default::default()
        }
    }
}

impl From<EthEip1559TxArgs> for ApiEthTx {
    fn from(
        EthEip1559TxArgs {
            chain_id,
            nonce,
            to,
            value,
            max_fee_per_gas,
            max_priority_fee_per_gas,
            gas_limit,
            input,
            v,
            r,
            s,
        }: EthEip1559TxArgs,
    ) -> Self {
        Self {
            chain_id: chain_id.into(),
            r#type: EIP_1559_TX_TYPE.into(),
            nonce: nonce.into(),
            gas: gas_limit.into(),
            to,
            value: value.into(),
            max_fee_per_gas: Some(max_fee_per_gas.into()),
            max_priority_fee_per_gas: Some(max_priority_fee_per_gas.into()),
            input: input.into(),
            v: v.into(),
            r: r.into(),
            s: s.into(),
            ..Default::default()
        }
    }
}

impl From<EthTx> for ApiEthTx {
    fn from(value: EthTx) -> Self {
        use EthTx::*;
        match value {
            Homestead(tx) => (*tx).into(),
            Eip1559(tx) => (*tx).into(),
            Eip155(tx) => (*tx).into(),
        }
    }
}