mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
internal/ethapi: minor cleanups
This commit is contained in:
parent
76e3a3686f
commit
38d1d128d9
2 changed files with 33 additions and 54 deletions
|
|
@ -1501,10 +1501,7 @@ func (api *TransactionAPI) SendTransaction(ctx context.Context, args Transaction
|
|||
}
|
||||
|
||||
// Set some sanity defaults and terminate on failure
|
||||
config := setDefaultConfig{
|
||||
skipGasEstimation: false,
|
||||
}
|
||||
if err := args.setDefaults(ctx, api.b, config); err != nil {
|
||||
if err := args.setDefaults(ctx, api.b, sidecarConfig{}); err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
// Assemble the transaction and sign with the wallet
|
||||
|
|
@ -1522,8 +1519,7 @@ func (api *TransactionAPI) SendTransaction(ctx context.Context, args Transaction
|
|||
// processing (signing + broadcast).
|
||||
func (api *TransactionAPI) FillTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) {
|
||||
// Set some sanity defaults and terminate on failure
|
||||
config := setDefaultConfig{
|
||||
skipGasEstimation: false,
|
||||
config := sidecarConfig{
|
||||
blobSidecarAllowed: true,
|
||||
blobSidecarVersion: types.BlobSidecarVersion0,
|
||||
}
|
||||
|
|
@ -1600,10 +1596,6 @@ func (api *TransactionAPI) SignTransaction(ctx context.Context, args Transaction
|
|||
if args.Nonce == nil {
|
||||
return nil, errors.New("nonce not specified")
|
||||
}
|
||||
config := setDefaultConfig{
|
||||
skipGasEstimation: false,
|
||||
blobSidecarAllowed: true,
|
||||
}
|
||||
sidecarVersion := types.BlobSidecarVersion0
|
||||
if len(args.Blobs) > 0 {
|
||||
chainHead := api.b.CurrentHeader()
|
||||
|
|
@ -1612,8 +1604,11 @@ func (api *TransactionAPI) SignTransaction(ctx context.Context, args Transaction
|
|||
sidecarVersion = types.BlobSidecarVersion1
|
||||
}
|
||||
}
|
||||
config.blobSidecarVersion = sidecarVersion
|
||||
|
||||
config := sidecarConfig{
|
||||
blobSidecarAllowed: true,
|
||||
blobSidecarVersion: sidecarVersion,
|
||||
}
|
||||
if err := args.setDefaults(ctx, api.b, config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -1671,10 +1666,7 @@ func (api *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs,
|
|||
if sendArgs.Nonce == nil {
|
||||
return common.Hash{}, errors.New("missing transaction nonce in transaction spec")
|
||||
}
|
||||
config := setDefaultConfig{
|
||||
skipGasEstimation: false,
|
||||
}
|
||||
if err := sendArgs.setDefaults(ctx, api.b, config); err != nil {
|
||||
if err := sendArgs.setDefaults(ctx, api.b, sidecarConfig{}); err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
matchTx := sendArgs.ToTransaction(types.LegacyTxType)
|
||||
|
|
|
|||
|
|
@ -91,21 +91,16 @@ func (args *TransactionArgs) data() []byte {
|
|||
return nil
|
||||
}
|
||||
|
||||
// setDefaultConfig defines the options for deriving missing fields of transactions.
|
||||
type setDefaultConfig struct {
|
||||
// sidecarConfig defines the options for deriving missing fields of transactions.
|
||||
type sidecarConfig struct {
|
||||
// This configures whether blobs are allowed to be passed and
|
||||
// the associated sidecar version should be attached.
|
||||
blobSidecarAllowed bool
|
||||
blobSidecarVersion byte
|
||||
|
||||
// skipGasEstimation is the flag whether the gas estimation is skipped.
|
||||
// this flag should only be used in the scenarios that a precise gas limit
|
||||
// is not critical, e.g., in non-transaction calls.
|
||||
skipGasEstimation bool
|
||||
}
|
||||
|
||||
// setDefaults fills in default values for unspecified tx fields.
|
||||
func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, config setDefaultConfig) error {
|
||||
func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, config sidecarConfig) error {
|
||||
if err := args.setBlobTxSidecar(ctx, config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -146,13 +141,6 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, config
|
|||
}
|
||||
|
||||
if args.Gas == nil {
|
||||
if config.skipGasEstimation {
|
||||
gas := hexutil.Uint64(b.RPCGasCap())
|
||||
if gas == 0 {
|
||||
gas = hexutil.Uint64(math.MaxUint64 / 2)
|
||||
}
|
||||
args.Gas = &gas
|
||||
} else {
|
||||
// These fields are immutable during the estimation, safe to
|
||||
// pass the pointer directly.
|
||||
data := args.data()
|
||||
|
|
@ -176,7 +164,6 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, config
|
|||
args.Gas = &estimated
|
||||
log.Trace("Estimate gas usage automatically", "gas", args.Gas)
|
||||
}
|
||||
}
|
||||
|
||||
// If chain id is provided, ensure it matches the local chain id. Otherwise, set the local
|
||||
// chain id as the default.
|
||||
|
|
@ -292,7 +279,7 @@ func (args *TransactionArgs) setLondonFeeDefaults(ctx context.Context, head *typ
|
|||
}
|
||||
|
||||
// setBlobTxSidecar adds the blob tx
|
||||
func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config setDefaultConfig) error {
|
||||
func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config sidecarConfig) error {
|
||||
// No blobs, we're done.
|
||||
if args.Blobs == nil {
|
||||
return nil
|
||||
|
|
@ -311,7 +298,7 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config setDef
|
|||
return errors.New(`blob commitments provided while proofs were not`)
|
||||
}
|
||||
|
||||
// len(blobs) == len(commitments) == len(proofs) == len(hashes)
|
||||
// len(blobs) == len(commitments) == len(hashes)
|
||||
n := len(args.Blobs)
|
||||
if args.BlobHashes != nil && len(args.BlobHashes) != n {
|
||||
return fmt.Errorf("number of blobs and hashes mismatch (have=%d, want=%d)", len(args.BlobHashes), n)
|
||||
|
|
|
|||
Loading…
Reference in a new issue