ethclient: fix BlobSidecars api (#2656)
This commit is contained in:
parent
6cb4be4ebf
commit
c46d7e8bd8
@ -2,10 +2,12 @@ package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
||||
@ -53,3 +55,40 @@ func (s *BlobSidecar) SanityCheck(blockNumber *big.Int, blockHash common.Hash) e
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *BlobSidecar) MarshalJSON() ([]byte, error) {
|
||||
fields := map[string]interface{}{
|
||||
"blockHash": s.BlockHash,
|
||||
"blockNumber": hexutil.EncodeUint64(s.BlockNumber.Uint64()),
|
||||
"txHash": s.TxHash,
|
||||
"txIndex": hexutil.EncodeUint64(s.TxIndex),
|
||||
}
|
||||
fields["blobSidecar"] = s.BlobTxSidecar
|
||||
return json.Marshal(fields)
|
||||
}
|
||||
|
||||
func (s *BlobSidecar) UnmarshalJSON(input []byte) error {
|
||||
type blobSidecar struct {
|
||||
BlobSidecar BlobTxSidecar `json:"blobSidecar"`
|
||||
BlockNumber *hexutil.Big `json:"blockNumber"`
|
||||
BlockHash common.Hash `json:"blockHash"`
|
||||
TxIndex *hexutil.Big `json:"txIndex"`
|
||||
TxHash common.Hash `json:"txHash"`
|
||||
}
|
||||
var blob blobSidecar
|
||||
if err := json.Unmarshal(input, &blob); err != nil {
|
||||
return err
|
||||
}
|
||||
s.BlobTxSidecar = blob.BlobSidecar
|
||||
if blob.BlockNumber == nil {
|
||||
return errors.New("missing required field 'blockNumber' for BlobSidecar")
|
||||
}
|
||||
s.BlockNumber = blob.BlockNumber.ToInt()
|
||||
s.BlockHash = blob.BlockHash
|
||||
if blob.TxIndex == nil {
|
||||
return errors.New("missing required field 'txIndex' for BlobSidecar")
|
||||
}
|
||||
s.TxIndex = blob.TxIndex.ToInt().Uint64()
|
||||
s.TxHash = blob.TxHash
|
||||
return nil
|
||||
}
|
||||
|
@ -131,8 +131,8 @@ func (ec *Client) BlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumb
|
||||
}
|
||||
|
||||
// BlobSidecars return the Sidecars of a given block number or hash.
|
||||
func (ec *Client) BlobSidecars(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.BlobTxSidecar, error) {
|
||||
var r []*types.BlobTxSidecar
|
||||
func (ec *Client) BlobSidecars(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.BlobSidecar, error) {
|
||||
var r []*types.BlobSidecar
|
||||
err := ec.c.CallContext(ctx, &r, "eth_getBlobSidecars", blockNrOrHash.String())
|
||||
if err == nil && r == nil {
|
||||
return nil, ethereum.NotFound
|
||||
@ -141,8 +141,8 @@ func (ec *Client) BlobSidecars(ctx context.Context, blockNrOrHash rpc.BlockNumbe
|
||||
}
|
||||
|
||||
// BlobSidecarByTxHash return a sidecar of a given blob transaction
|
||||
func (ec *Client) BlobSidecarByTxHash(ctx context.Context, hash common.Hash) (*types.BlobTxSidecar, error) {
|
||||
var r *types.BlobTxSidecar
|
||||
func (ec *Client) BlobSidecarByTxHash(ctx context.Context, hash common.Hash) (*types.BlobSidecar, error) {
|
||||
var r *types.BlobSidecar
|
||||
err := ec.c.CallContext(ctx, &r, "eth_getBlobSidecarByTxHash", hash)
|
||||
if err == nil && r == nil {
|
||||
return nil, ethereum.NotFound
|
||||
|
Loading…
Reference in New Issue
Block a user