From bb1f7ebf203f40dae714a3b8445918cfcfc9a7db Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 23 Aug 2021 12:20:56 +0200 Subject: [PATCH] signer/core/apitypes: remove dependency on internal/ethapi (#23362) --- signer/core/apitypes/types.go | 69 +++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/signer/core/apitypes/types.go b/signer/core/apitypes/types.go index 591d253ab..625959219 100644 --- a/signer/core/apitypes/types.go +++ b/signer/core/apitypes/types.go @@ -19,12 +19,12 @@ package apitypes import ( "encoding/json" "fmt" + "math/big" "strings" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/internal/ethapi" ) type ValidationInfo struct { @@ -97,23 +97,60 @@ func (args SendTxArgs) String() string { return err.Error() } +// ToTransaction converts the arguments to a transaction. func (args *SendTxArgs) ToTransaction() *types.Transaction { - txArgs := ethapi.TransactionArgs{ - Gas: &args.Gas, - GasPrice: args.GasPrice, - MaxFeePerGas: args.MaxFeePerGas, - MaxPriorityFeePerGas: args.MaxPriorityFeePerGas, - Value: &args.Value, - Nonce: &args.Nonce, - Data: args.Data, - Input: args.Input, - AccessList: args.AccessList, - ChainID: args.ChainID, - } // Add the To-field, if specified + var to *common.Address if args.To != nil { - to := args.To.Address() - txArgs.To = &to + dstAddr := args.To.Address() + to = &dstAddr } - return txArgs.ToTransaction() + + var input []byte + if args.Input != nil { + input = *args.Input + } else if args.Data != nil { + input = *args.Data + } + + var data types.TxData + switch { + case args.MaxFeePerGas != nil: + al := types.AccessList{} + if args.AccessList != nil { + al = *args.AccessList + } + data = &types.DynamicFeeTx{ + To: to, + ChainID: (*big.Int)(args.ChainID), + Nonce: uint64(args.Nonce), + Gas: uint64(args.Gas), + GasFeeCap: (*big.Int)(args.MaxFeePerGas), + GasTipCap: (*big.Int)(args.MaxPriorityFeePerGas), + Value: (*big.Int)(&args.Value), + Data: input, + AccessList: al, + } + case args.AccessList != nil: + data = &types.AccessListTx{ + To: to, + ChainID: (*big.Int)(args.ChainID), + Nonce: uint64(args.Nonce), + Gas: uint64(args.Gas), + GasPrice: (*big.Int)(args.GasPrice), + Value: (*big.Int)(&args.Value), + Data: input, + AccessList: *args.AccessList, + } + default: + data = &types.LegacyTx{ + To: to, + Nonce: uint64(args.Nonce), + Gas: uint64(args.Gas), + GasPrice: (*big.Int)(args.GasPrice), + Value: (*big.Int)(&args.Value), + Data: input, + } + } + return types.NewTx(data) }