Skip to content

Commit

Permalink
internal/ethapi: add optional parameter for blobSidecars (#2467)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlacfzy committed May 16, 2024
1 parent 6b8cbbe commit 5edd032
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
8 changes: 4 additions & 4 deletions ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ 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, fullBlob bool) ([]*types.BlobTxSidecar, error) {
func (ec *Client) BlobSidecars(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.BlobTxSidecar, error) {
var r []*types.BlobTxSidecar
err := ec.c.CallContext(ctx, &r, "eth_getBlobSidecars", blockNrOrHash.String(), fullBlob)
err := ec.c.CallContext(ctx, &r, "eth_getBlobSidecars", blockNrOrHash.String(), true)
if err == nil && r == nil {
return nil, ethereum.NotFound
}
return r, err
}

// BlobSidecarByTxHash return a sidecar of a given blob transaction
func (ec *Client) BlobSidecarByTxHash(ctx context.Context, hash common.Hash, fullBlob bool) (*types.BlobTxSidecar, error) {
func (ec *Client) BlobSidecarByTxHash(ctx context.Context, hash common.Hash) (*types.BlobTxSidecar, error) {
var r *types.BlobTxSidecar
err := ec.c.CallContext(ctx, &r, "eth_getBlockSidecarByTxHash", hash, fullBlob)
err := ec.c.CallContext(ctx, &r, "eth_getBlockSidecarByTxHash", hash, true)
if err == nil && r == nil {
return nil, ethereum.NotFound
}
Expand Down
16 changes: 12 additions & 4 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,11 @@ func (s *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.
return result, nil
}

func (s *BlockChainAPI) GetBlobSidecars(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, fullBlob bool) ([]map[string]interface{}, error) {
func (s *BlockChainAPI) GetBlobSidecars(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, fullBlob *bool) ([]map[string]interface{}, error) {
showBlob := true
if fullBlob != nil {
showBlob = *fullBlob
}
header, err := s.b.HeaderByNumberOrHash(ctx, blockNrOrHash)
if header == nil || err != nil {
// When the block doesn't exist, the RPC method should return JSON null
Expand All @@ -1023,12 +1027,16 @@ func (s *BlockChainAPI) GetBlobSidecars(ctx context.Context, blockNrOrHash rpc.B
}
result := make([]map[string]interface{}, len(blobSidecars))
for i, sidecar := range blobSidecars {
result[i] = marshalBlobSidecar(sidecar, fullBlob)
result[i] = marshalBlobSidecar(sidecar, showBlob)
}
return result, nil
}

func (s *BlockChainAPI) GetBlobSidecarByTxHash(ctx context.Context, hash common.Hash, fullBlob bool) (map[string]interface{}, error) {
func (s *BlockChainAPI) GetBlobSidecarByTxHash(ctx context.Context, hash common.Hash, fullBlob *bool) (map[string]interface{}, error) {
showBlob := true
if fullBlob != nil {
showBlob = *fullBlob
}
txTarget, blockHash, _, Index := rawdb.ReadTransaction(s.b.ChainDb(), hash)
if txTarget == nil {
return nil, nil
Expand All @@ -1045,7 +1053,7 @@ func (s *BlockChainAPI) GetBlobSidecarByTxHash(ctx context.Context, hash common.
}
for _, sidecar := range blobSidecars {
if sidecar.TxIndex == Index {
return marshalBlobSidecar(sidecar, fullBlob), nil
return marshalBlobSidecar(sidecar, showBlob), nil
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,7 @@ func TestRPCGetBlobSidecars(t *testing.T) {
result interface{}
err error
)
result, err = api.GetBlobSidecars(context.Background(), tt.test, tt.fullBlob)
result, err = api.GetBlobSidecars(context.Background(), tt.test, &tt.fullBlob)
if err != nil {
t.Errorf("test %d: want no error, have %v", i, err)
continue
Expand Down Expand Up @@ -2254,7 +2254,7 @@ func TestGetBlobSidecarByTxHash(t *testing.T) {
fullBlob: true,
file: "block-with-blobSidecars",
},
// 4. block show part blobs
// 5. block show part blobs
{
test: txHashs[6],
fullBlob: false,
Expand All @@ -2267,7 +2267,7 @@ func TestGetBlobSidecarByTxHash(t *testing.T) {
result interface{}
err error
)
result, err = api.GetBlobSidecarByTxHash(context.Background(), tt.test, tt.fullBlob)
result, err = api.GetBlobSidecarByTxHash(context.Background(), tt.test, &tt.fullBlob)
if err != nil {
t.Errorf("test %d: want no error, have %v", i, err)
continue
Expand Down

0 comments on commit 5edd032

Please sign in to comment.