-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[api] eth_getBlobSidecar #4371
[api] eth_getBlobSidecar #4371
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
"strconv" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/core/vm" | ||
"github.com/ethereum/go-ethereum/eth/tracers" | ||
|
||
|
@@ -180,6 +182,8 @@ | |
|
||
// Track tracks the api call | ||
Track(ctx context.Context, start time.Time, method string, size int64, success bool) | ||
// BlobSidecarsByHeight returns blob sidecars by height | ||
BlobSidecarsByHeight(height uint64) ([]*apitypes.BlobSidecarResult, error) | ||
} | ||
|
||
// coreService implements the CoreService interface | ||
|
@@ -1213,6 +1217,58 @@ | |
}, nil | ||
} | ||
|
||
func (core *coreService) BlobSidecarsByHeight(height uint64) ([]*apitypes.BlobSidecarResult, error) { | ||
header, err := core.bc.BlockHeaderByHeight(height) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res := make([]*apitypes.BlobSidecarResult, 0) | ||
blobs, txHashes, err := core.getBlobSidecars(height) | ||
if err != nil { | ||
return nil, err | ||
} | ||
txIndices := make([]uint64, 0) | ||
for _, txHash := range txHashes { | ||
_, _, index, err := core.ActionByActionHash(txHash) | ||
if err != nil { | ||
return nil, err | ||
} | ||
txIndices = append(txIndices, uint64(index)) | ||
} | ||
blkHash := header.HashBlock() | ||
for i, blob := range blobs { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move L1232 to here, get the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
res = append(res, &apitypes.BlobSidecarResult{ | ||
BlobSidecar: blob, | ||
BlockNumber: height, | ||
BlockHash: common.BytesToHash(blkHash[:]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just keep same as bsc. IMO, this design is to use same structure for getSidercarByBlock and getSidercarByTx |
||
TxIndex: txIndices[i], | ||
TxHash: common.BytesToHash(txHashes[i][:]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do the conversion in line 1230 and save them in local variables. |
||
}) | ||
} | ||
return res, nil | ||
} | ||
|
||
func (core *coreService) getBlobSidecars(height uint64) ([]*types.BlobTxSidecar, []hash.Hash256, error) { | ||
blobs, txHashStr, err := core.dao.GetBlobsByHeight(height) | ||
switch errors.Cause(err) { | ||
case nil: | ||
case db.ErrNotExist: | ||
return nil, nil, errors.Wrapf(ErrNotFound, "failed to find blobs by height %d", height) | ||
default: | ||
return nil, nil, err | ||
} | ||
txHashes := make([]hash.Hash256, 0) | ||
txIndexes := make([]uint64, 0) | ||
for _, hashStr := range txHashStr { | ||
txHash, err := hash.HexStringToHash256(hashStr) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
txHashes = append(txHashes, txHash) | ||
} | ||
return blobs, txHashes, nil | ||
} | ||
|
||
func (core *coreService) getGravityChainStartHeight(epochHeight uint64) (uint64, error) { | ||
gravityChainStartHeight := epochHeight | ||
if pp := poll.FindProtocol(core.registry); pp != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,6 +232,8 @@ func (svr *web3Handler) handleWeb3Req(ctx context.Context, web3Req *gjson.Result | |
res, err = svr.subscribe(sc, web3Req, writer) | ||
case "eth_unsubscribe": | ||
res, err = svr.unsubscribe(web3Req) | ||
case "eth_getBlobSidecars": | ||
res, err = svr.getBlobSidecars(web3Req) | ||
//TODO: enable debug api after archive mode is supported | ||
// case "debug_traceTransaction": | ||
// res, err = svr.traceTransaction(ctx, web3Req) | ||
|
@@ -982,6 +984,26 @@ func (svr *web3Handler) unsubscribe(in *gjson.Result) (interface{}, error) { | |
return chainListener.RemoveResponder(id.String()) | ||
} | ||
|
||
func (svr *web3Handler) getBlobSidecars(in *gjson.Result) (interface{}, error) { | ||
blkNum := in.Get("params.0") | ||
if !blkNum.Exists() { | ||
return nil, errInvalidFormat | ||
} | ||
num, err := svr.parseBlockNumber(blkNum.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res, err := svr.coreService.BlobSidecarsByHeight(num) | ||
switch errors.Cause(err) { | ||
case nil: | ||
return res, nil | ||
case ErrNotFound: | ||
return nil, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, just like getBlock and getTransaction |
||
default: | ||
return nil, err | ||
} | ||
} | ||
|
||
func (svr *web3Handler) traceTransaction(ctx context.Context, in *gjson.Result) (interface{}, error) { | ||
actHash, options := in.Get("params.0"), in.Get("params.1") | ||
if !actHash.Exists() { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to L1238
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed