@@ -19,12 +19,12 @@ package apitypes
19
19
import (
20
20
"encoding/json"
21
21
"fmt"
22
+ "math/big"
22
23
"strings"
23
24
24
25
"github.com/ethereum/go-ethereum/common"
25
26
"github.com/ethereum/go-ethereum/common/hexutil"
26
27
"github.com/ethereum/go-ethereum/core/types"
27
- "github.com/ethereum/go-ethereum/internal/ethapi"
28
28
)
29
29
30
30
type ValidationInfo struct {
@@ -97,23 +97,60 @@ func (args SendTxArgs) String() string {
97
97
return err .Error ()
98
98
}
99
99
100
+ // ToTransaction converts the arguments to a transaction.
100
101
func (args * SendTxArgs ) ToTransaction () * types.Transaction {
101
- txArgs := ethapi.TransactionArgs {
102
- Gas : & args .Gas ,
103
- GasPrice : args .GasPrice ,
104
- MaxFeePerGas : args .MaxFeePerGas ,
105
- MaxPriorityFeePerGas : args .MaxPriorityFeePerGas ,
106
- Value : & args .Value ,
107
- Nonce : & args .Nonce ,
108
- Data : args .Data ,
109
- Input : args .Input ,
110
- AccessList : args .AccessList ,
111
- ChainID : args .ChainID ,
112
- }
113
102
// Add the To-field, if specified
103
+ var to * common.Address
114
104
if args .To != nil {
115
- to := args .To .Address ()
116
- txArgs .To = & to
105
+ dstAddr := args .To .Address ()
106
+ to = & dstAddr
107
+ }
108
+
109
+ var input []byte
110
+ if args .Input != nil {
111
+ input = * args .Input
112
+ } else if args .Data != nil {
113
+ input = * args .Data
114
+ }
115
+
116
+ var data types.TxData
117
+ switch {
118
+ case args .MaxFeePerGas != nil :
119
+ al := types.AccessList {}
120
+ if args .AccessList != nil {
121
+ al = * args .AccessList
122
+ }
123
+ data = & types.DynamicFeeTx {
124
+ To : to ,
125
+ ChainID : (* big .Int )(args .ChainID ),
126
+ Nonce : uint64 (args .Nonce ),
127
+ Gas : uint64 (args .Gas ),
128
+ GasFeeCap : (* big .Int )(args .MaxFeePerGas ),
129
+ GasTipCap : (* big .Int )(args .MaxPriorityFeePerGas ),
130
+ Value : (* big .Int )(& args .Value ),
131
+ Data : input ,
132
+ AccessList : al ,
133
+ }
134
+ case args .AccessList != nil :
135
+ data = & types.AccessListTx {
136
+ To : to ,
137
+ ChainID : (* big .Int )(args .ChainID ),
138
+ Nonce : uint64 (args .Nonce ),
139
+ Gas : uint64 (args .Gas ),
140
+ GasPrice : (* big .Int )(args .GasPrice ),
141
+ Value : (* big .Int )(& args .Value ),
142
+ Data : input ,
143
+ AccessList : * args .AccessList ,
144
+ }
145
+ default :
146
+ data = & types.LegacyTx {
147
+ To : to ,
148
+ Nonce : uint64 (args .Nonce ),
149
+ Gas : uint64 (args .Gas ),
150
+ GasPrice : (* big .Int )(args .GasPrice ),
151
+ Value : (* big .Int )(& args .Value ),
152
+ Data : input ,
153
+ }
117
154
}
118
- return txArgs . ToTransaction ( )
155
+ return types . NewTx ( data )
119
156
}
0 commit comments