MCPcopy Create free account
hub / github.com/CPChain/chain / StateAndHeaderByNumber

Method StateAndHeaderByNumber

protocols/cpc/api_backend.go:92–110  ·  view source on GitHub ↗
(ctx context.Context, blockNr rpc.BlockNumber, isPrivate bool)

Source from the content-addressed store, hash-verified

90}
91
92func (b *APIBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber, isPrivate bool) (*state.StateDB, *types.Header, error) {
93 // Pending state is only known by the miner
94 if blockNr == rpc.PendingBlockNumber {
95 block, state := b.cpc.miner.Pending()
96 return state, block.Header(), nil
97 }
98 // Otherwise resolve the block number and return its state
99 header, err := b.HeaderByNumber(ctx, blockNr)
100 if header == nil || err != nil {
101 return nil, nil, err
102 }
103 var stateDb *state.StateDB
104 if isPrivate {
105 stateDb, err = b.cpc.BlockChain().StatePrivAt(header.StateRoot)
106 } else {
107 stateDb, err = b.cpc.BlockChain().StateAt(header.StateRoot)
108 }
109 return stateDb, header, err
110}
111
112func (b *APIBackend) GetBlock(ctx context.Context, hash common.Hash) (*types.Block, error) {
113 return b.cpc.blockchain.GetBlockByHash(hash), nil

Callers

nothing calls this directly

Calls 6

HeaderByNumberMethod · 0.95
HeaderMethod · 0.80
StatePrivAtMethod · 0.80
PendingMethod · 0.65
BlockChainMethod · 0.65
StateAtMethod · 0.65

Tested by

no test coverage detected