Skip to content

Commit bb1f7eb

Browse files
authored
signer/core/apitypes: remove dependency on internal/ethapi (ethereum#23362)
1 parent d02c605 commit bb1f7eb

File tree

1 file changed

+53
-16
lines changed

1 file changed

+53
-16
lines changed

signer/core/apitypes/types.go

+53-16
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ package apitypes
1919
import (
2020
"encoding/json"
2121
"fmt"
22+
"math/big"
2223
"strings"
2324

2425
"github.com/ethereum/go-ethereum/common"
2526
"github.com/ethereum/go-ethereum/common/hexutil"
2627
"github.com/ethereum/go-ethereum/core/types"
27-
"github.com/ethereum/go-ethereum/internal/ethapi"
2828
)
2929

3030
type ValidationInfo struct {
@@ -97,23 +97,60 @@ func (args SendTxArgs) String() string {
9797
return err.Error()
9898
}
9999

100+
// ToTransaction converts the arguments to a transaction.
100101
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-
}
113102
// Add the To-field, if specified
103+
var to *common.Address
114104
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+
}
117154
}
118-
return txArgs.ToTransaction()
155+
return types.NewTx(data)
119156
}

0 commit comments

Comments
 (0)