diff --git a/core/types/blob_sidecar.go b/core/types/blob_sidecar.go index d4f63602d0..e4d518c193 100644 --- a/core/types/blob_sidecar.go +++ b/core/types/blob_sidecar.go @@ -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,34 @@ 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 (h *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 + } + h.BlobTxSidecar = blob.BlobSidecar + h.BlockNumber = blob.BlockNumber.ToInt() + h.BlockHash = blob.BlockHash + h.TxIndex = blob.TxIndex.ToInt().Uint64() + h.TxHash = blob.TxHash + return nil +} diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index bf26c79aa8..8cf50eb528 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -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