Update api.go

This commit is contained in:
conomist 2026-01-08 21:02:58 +01:00 committed by GitHub
parent f51870e40e
commit b726df7c20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1645,6 +1645,23 @@ func (api *TransactionAPI) currentBlobSidecarVersion() byte {
return types.BlobSidecarVersion0
}
// normalizeBlobSidecar converts legacy blob transaction sidecars to the
// current version when required. It returns the possibly-updated transaction.
func (api *TransactionAPI) normalizeBlobSidecar(tx *types.Transaction) (*types.Transaction, error) {
sc := tx.BlobTxSidecar()
if sc == nil {
return tx, nil
}
exp := api.currentBlobSidecarVersion()
if sc.Version == types.BlobSidecarVersion0 && exp == types.BlobSidecarVersion1 {
if err := sc.ToV1(); err != nil {
return nil, fmt.Errorf("blob sidecar conversion failed: %v", err)
}
tx = tx.WithBlobTxSidecar(sc)
}
return tx, nil
}
// SendRawTransaction will add the signed transaction to the transaction pool.
// The sender is responsible for signing the transaction and using the correct nonce.
func (api *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (common.Hash, error) {
@ -1655,17 +1672,12 @@ func (api *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil
// Convert legacy blob transaction proofs.
// TODO: remove in go-ethereum v1.17.x
if sc := tx.BlobTxSidecar(); sc != nil {
exp := api.currentBlobSidecarVersion()
if sc.Version == types.BlobSidecarVersion0 && exp == types.BlobSidecarVersion1 {
if err := sc.ToV1(); err != nil {
return common.Hash{}, fmt.Errorf("blob sidecar conversion failed: %v", err)
}
tx = tx.WithBlobTxSidecar(sc)
}
converted, err := api.normalizeBlobSidecar(tx)
if err != nil {
return common.Hash{}, err
}
return SubmitTransaction(ctx, api.b, tx)
return SubmitTransaction(ctx, api.b, converted)
}
// SendRawTransactionSync will add the signed transaction to the transaction pool
@ -1678,21 +1690,16 @@ func (api *TransactionAPI) SendRawTransactionSync(ctx context.Context, input hex
// Convert legacy blob transaction proofs.
// TODO: remove in go-ethereum v1.17.x
if sc := tx.BlobTxSidecar(); sc != nil {
exp := api.currentBlobSidecarVersion()
if sc.Version == types.BlobSidecarVersion0 && exp == types.BlobSidecarVersion1 {
if err := sc.ToV1(); err != nil {
return nil, fmt.Errorf("blob sidecar conversion failed: %v", err)
}
tx = tx.WithBlobTxSidecar(sc)
}
converted, err := api.normalizeBlobSidecar(tx)
if err != nil {
return nil, err
}
ch := make(chan core.ChainEvent, 128)
sub := api.b.SubscribeChainEvent(ch)
defer sub.Unsubscribe()
hash, err := SubmitTransaction(ctx, api.b, tx)
hash, err := SubmitTransaction(ctx, api.b, converted)
if err != nil {
return nil, err
}