internal/ethapi: add optional parameter for blobSidecars (#2467)
This commit is contained in:
parent
6b8cbbe172
commit
5edd032cdb
@ -131,9 +131,9 @@ 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
|
||||
}
|
||||
@ -141,9 +141,9 @@ 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, 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
|
||||
}
|
||||
|
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
@ -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,
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user