mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Update api.go
This commit is contained in:
parent
ffe9dc97e5
commit
2f86408c81
1 changed files with 29 additions and 28 deletions
|
|
@ -1645,49 +1645,50 @@ func (api *TransactionAPI) currentBlobSidecarVersion() byte {
|
||||||
return types.BlobSidecarVersion0
|
return types.BlobSidecarVersion0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convertLegacyBlobSidecar upgrades legacy blob sidecar proofs to the current version.
|
||||||
|
func (api *TransactionAPI) convertLegacyBlobSidecar(tx *types.Transaction) (*types.Transaction, error) {
|
||||||
|
sc := tx.BlobTxSidecar()
|
||||||
|
if sc == nil {
|
||||||
|
return tx, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if sc.Version != types.BlobSidecarVersion0 || api.currentBlobSidecarVersion() != types.BlobSidecarVersion1 {
|
||||||
|
return tx, nil
|
||||||
|
}
|
||||||
|
if err := sc.ToV1(); err != nil {
|
||||||
|
return nil, fmt.Errorf("blob sidecar conversion failed: %v", err)
|
||||||
|
}
|
||||||
|
return tx.WithBlobTxSidecar(sc), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// decodeRawTransaction unmarshals the binary transaction and upgrades any legacy blob sidecars.
|
||||||
|
func (api *TransactionAPI) decodeRawTransaction(input hexutil.Bytes) (*types.Transaction, error) {
|
||||||
|
tx := new(types.Transaction)
|
||||||
|
if err := tx.UnmarshalBinary(input); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return api.convertLegacyBlobSidecar(tx)
|
||||||
|
}
|
||||||
|
|
||||||
// SendRawTransaction will add the signed transaction to the transaction pool.
|
// SendRawTransaction will add the signed transaction to the transaction pool.
|
||||||
// The sender is responsible for signing the transaction and using the correct nonce.
|
// 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) {
|
func (api *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (common.Hash, error) {
|
||||||
tx := new(types.Transaction)
|
tx, err := api.decodeRawTransaction(input)
|
||||||
if err := tx.UnmarshalBinary(input); err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return SubmitTransaction(ctx, api.b, tx)
|
return SubmitTransaction(ctx, api.b, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendRawTransactionSync will add the signed transaction to the transaction pool
|
// SendRawTransactionSync will add the signed transaction to the transaction pool
|
||||||
// and wait until the transaction has been included in a block and return the receipt, or the timeout.
|
// and wait until the transaction has been included in a block and return the receipt, or the timeout.
|
||||||
func (api *TransactionAPI) SendRawTransactionSync(ctx context.Context, input hexutil.Bytes, timeoutMs *hexutil.Uint64) (map[string]interface{}, error) {
|
func (api *TransactionAPI) SendRawTransactionSync(ctx context.Context, input hexutil.Bytes, timeoutMs *hexutil.Uint64) (map[string]interface{}, error) {
|
||||||
tx := new(types.Transaction)
|
tx, err := api.decodeRawTransaction(input)
|
||||||
if err := tx.UnmarshalBinary(input); err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ch := make(chan core.ChainEvent, 128)
|
ch := make(chan core.ChainEvent, 128)
|
||||||
sub := api.b.SubscribeChainEvent(ch)
|
sub := api.b.SubscribeChainEvent(ch)
|
||||||
defer sub.Unsubscribe()
|
defer sub.Unsubscribe()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue