MCPcopy Create free account
hub / github.com/chain/Core / getBlockRPC

Method getBlockRPC

core/rpc.go:18–30  ·  view source on GitHub ↗

getBlockRPC returns the block at the requested height. If successful, it always returns at least one block, waiting if necessary until one is created. It is an error to request blocks very far in the future.

(ctx context.Context, height uint64)

Source from the content-addressed store, hash-verified

16// waiting if necessary until one is created.
17// It is an error to request blocks very far in the future.
18func (a *API) getBlockRPC(ctx context.Context, height uint64) (chainjson.HexBytes, error) {
19 err := <-a.chain.BlockSoonWaiter(ctx, height)
20 if err != nil {
21 return nil, errors.Wrapf(err, "waiting for block at height %d", height)
22 }
23
24 rawBlock, err := a.store.GetRawBlock(ctx, height)
25 if err != nil {
26 return nil, err
27 }
28
29 return rawBlock, nil
30}
31
32type snapshotInfoResp struct {
33 Height uint64 `json:"height"`

Callers 1

TestGetBlockFunction · 0.95

Calls 2

BlockSoonWaiterMethod · 0.80
GetRawBlockMethod · 0.80

Tested by 1

TestGetBlockFunction · 0.76