mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
internal: refactored ToTransaction of transaction args
This commit is contained in:
parent
791719a0fe
commit
c216ef56c3
4 changed files with 28 additions and 15 deletions
|
|
@ -970,7 +970,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
msg = args.ToMessage(vmctx.BaseFee, true, true)
|
msg = args.ToMessage(vmctx.BaseFee, true, true)
|
||||||
tx = args.ToTransaction(args.GasPrice == nil)
|
tx = args.ToTransaction(types.LegacyTxType)
|
||||||
traceConfig *TraceConfig
|
traceConfig *TraceConfig
|
||||||
)
|
)
|
||||||
// Lower the basefee to 0 to avoid breaking EVM
|
// Lower the basefee to 0 to avoid breaking EVM
|
||||||
|
|
|
||||||
|
|
@ -475,7 +475,7 @@ func (api *PersonalAccountAPI) signTransaction(ctx context.Context, args *Transa
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Assemble the transaction and sign with the wallet
|
// Assemble the transaction and sign with the wallet
|
||||||
tx := args.ToTransaction(false)
|
tx := args.ToTransaction(types.LegacyTxType)
|
||||||
|
|
||||||
return wallet.SignTxWithPassphrase(account, passwd, tx, api.b.ChainConfig().ChainID)
|
return wallet.SignTxWithPassphrase(account, passwd, tx, api.b.ChainConfig().ChainID)
|
||||||
}
|
}
|
||||||
|
|
@ -524,7 +524,7 @@ func (api *PersonalAccountAPI) SignTransaction(ctx context.Context, args Transac
|
||||||
return nil, errors.New("nonce not specified")
|
return nil, errors.New("nonce not specified")
|
||||||
}
|
}
|
||||||
// Before actually signing the transaction, ensure the transaction fee is reasonable.
|
// Before actually signing the transaction, ensure the transaction fee is reasonable.
|
||||||
tx := args.ToTransaction(false)
|
tx := args.ToTransaction(types.LegacyTxType)
|
||||||
if err := checkTxFee(tx.GasPrice(), tx.Gas(), api.b.RPCTxFeeCap()); err != nil {
|
if err := checkTxFee(tx.GasPrice(), tx.Gas(), api.b.RPCTxFeeCap()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1676,7 +1676,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
|
||||||
}
|
}
|
||||||
res, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.GasLimit))
|
res, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.GasLimit))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, nil, fmt.Errorf("failed to apply transaction: %v err: %v", args.ToTransaction(false).Hash(), err)
|
return nil, 0, nil, fmt.Errorf("failed to apply transaction: %v err: %v", args.ToTransaction(types.LegacyTxType).Hash(), err)
|
||||||
}
|
}
|
||||||
if tracer.Equal(prevTracer) {
|
if tracer.Equal(prevTracer) {
|
||||||
return accessList, res.UsedGas, res.Err, nil
|
return accessList, res.UsedGas, res.Err, nil
|
||||||
|
|
@ -1945,7 +1945,7 @@ func (api *TransactionAPI) SendTransaction(ctx context.Context, args Transaction
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
// Assemble the transaction and sign with the wallet
|
// Assemble the transaction and sign with the wallet
|
||||||
tx := args.ToTransaction(false)
|
tx := args.ToTransaction(types.LegacyTxType)
|
||||||
|
|
||||||
signed, err := wallet.SignTx(account, tx, api.b.ChainConfig().ChainID)
|
signed, err := wallet.SignTx(account, tx, api.b.ChainConfig().ChainID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -1965,7 +1965,7 @@ func (api *TransactionAPI) FillTransaction(ctx context.Context, args Transaction
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Assemble the transaction and obtain rlp
|
// Assemble the transaction and obtain rlp
|
||||||
tx := args.ToTransaction(false)
|
tx := args.ToTransaction(types.LegacyTxType)
|
||||||
data, err := tx.MarshalBinary()
|
data, err := tx.MarshalBinary()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -2033,7 +2033,7 @@ func (api *TransactionAPI) SignTransaction(ctx context.Context, args Transaction
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Before actually sign the transaction, ensure the transaction fee is reasonable.
|
// Before actually sign the transaction, ensure the transaction fee is reasonable.
|
||||||
tx := args.ToTransaction(false)
|
tx := args.ToTransaction(types.LegacyTxType)
|
||||||
if err := checkTxFee(tx.GasPrice(), tx.Gas(), api.b.RPCTxFeeCap()); err != nil {
|
if err := checkTxFee(tx.GasPrice(), tx.Gas(), api.b.RPCTxFeeCap()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -2091,7 +2091,7 @@ func (api *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs,
|
||||||
if err := sendArgs.setDefaults(ctx, api.b, false); err != nil {
|
if err := sendArgs.setDefaults(ctx, api.b, false); err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
matchTx := sendArgs.ToTransaction(false)
|
matchTx := sendArgs.ToTransaction(types.LegacyTxType)
|
||||||
|
|
||||||
// Before replacing the old transaction, ensure the _new_ transaction fee is reasonable.
|
// Before replacing the old transaction, ensure the _new_ transaction fee is reasonable.
|
||||||
var price = matchTx.GasPrice()
|
var price = matchTx.GasPrice()
|
||||||
|
|
@ -2121,7 +2121,7 @@ func (api *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs,
|
||||||
if gasLimit != nil && *gasLimit != 0 {
|
if gasLimit != nil && *gasLimit != 0 {
|
||||||
sendArgs.Gas = gasLimit
|
sendArgs.Gas = gasLimit
|
||||||
}
|
}
|
||||||
signedTx, err := api.sign(sendArgs.from(), sendArgs.ToTransaction(false))
|
signedTx, err := api.sign(sendArgs.from(), sendArgs.ToTransaction(types.LegacyTxType))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
||||||
if err := sim.sanitizeCall(&call, sim.state, header, blockContext, &gasUsed); err != nil {
|
if err := sim.sanitizeCall(&call, sim.state, header, blockContext, &gasUsed); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
tx := call.ToTransaction(call.GasPrice == nil)
|
tx := call.ToTransaction(types.DynamicFeeTxType)
|
||||||
txes[i] = tx
|
txes[i] = tx
|
||||||
tracer.reset(tx.Hash(), uint(i))
|
tracer.reset(tx.Hash(), uint(i))
|
||||||
// EoA check is always skipped, even in validation mode.
|
// EoA check is always skipped, even in validation mode.
|
||||||
|
|
|
||||||
|
|
@ -471,10 +471,23 @@ func (args *TransactionArgs) ToMessage(baseFee *big.Int, skipNonceCheck, skipEoA
|
||||||
|
|
||||||
// ToTransaction converts the arguments to a transaction.
|
// ToTransaction converts the arguments to a transaction.
|
||||||
// This assumes that setDefaults has been called.
|
// This assumes that setDefaults has been called.
|
||||||
func (args *TransactionArgs) ToTransaction(type2 bool) *types.Transaction {
|
func (args *TransactionArgs) ToTransaction(defaultType int) *types.Transaction {
|
||||||
var data types.TxData
|
usedType := types.LegacyTxType
|
||||||
switch {
|
switch {
|
||||||
case args.BlobHashes != nil:
|
case args.BlobHashes != nil || defaultType == types.BlobTxType:
|
||||||
|
usedType = types.BlobTxType
|
||||||
|
case args.MaxFeePerGas != nil || defaultType == types.DynamicFeeTxType:
|
||||||
|
usedType = types.DynamicFeeTxType
|
||||||
|
case args.AccessList != nil || defaultType == types.AccessListTxType:
|
||||||
|
usedType = types.AccessListTxType
|
||||||
|
}
|
||||||
|
// Make it possible to default to newer tx, but use legacy if gasprice is provided
|
||||||
|
if args.GasPrice != nil {
|
||||||
|
usedType = types.LegacyTxType
|
||||||
|
}
|
||||||
|
var data types.TxData
|
||||||
|
switch usedType {
|
||||||
|
case types.BlobTxType:
|
||||||
al := types.AccessList{}
|
al := types.AccessList{}
|
||||||
if args.AccessList != nil {
|
if args.AccessList != nil {
|
||||||
al = *args.AccessList
|
al = *args.AccessList
|
||||||
|
|
@ -500,7 +513,7 @@ func (args *TransactionArgs) ToTransaction(type2 bool) *types.Transaction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case args.MaxFeePerGas != nil || type2:
|
case types.DynamicFeeTxType:
|
||||||
al := types.AccessList{}
|
al := types.AccessList{}
|
||||||
if args.AccessList != nil {
|
if args.AccessList != nil {
|
||||||
al = *args.AccessList
|
al = *args.AccessList
|
||||||
|
|
@ -517,7 +530,7 @@ func (args *TransactionArgs) ToTransaction(type2 bool) *types.Transaction {
|
||||||
AccessList: al,
|
AccessList: al,
|
||||||
}
|
}
|
||||||
|
|
||||||
case args.AccessList != nil:
|
case types.AccessListTxType:
|
||||||
data = &types.AccessListTx{
|
data = &types.AccessListTx{
|
||||||
To: args.To,
|
To: args.To,
|
||||||
ChainID: (*big.Int)(args.ChainID),
|
ChainID: (*big.Int)(args.ChainID),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue