diff --git a/rpc/core/abci.go b/rpc/core/abci.go index a9955d1a5..8f135ba26 100644 --- a/rpc/core/abci.go +++ b/rpc/core/abci.go @@ -9,7 +9,7 @@ import ( ) // ABCIQuery queries the application for some information. -// More: https://tendermint.com/rpc/#/ABCI/abci_query +// More: https://docs.tendermint.com/master/rpc/#/ABCI/abci_query func ABCIQuery( ctx *rpctypes.Context, path string, @@ -31,7 +31,7 @@ func ABCIQuery( } // ABCIInfo gets some info about the application. -// More: https://tendermint.com/rpc/#/ABCI/abci_info +// More: https://docs.tendermint.com/master/rpc/#/ABCI/abci_info func ABCIInfo(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) { resInfo, err := proxyAppQuery.InfoSync(proxy.RequestInfo) if err != nil { diff --git a/rpc/core/blocks.go b/rpc/core/blocks.go index 777981b06..e340d4dfb 100644 --- a/rpc/core/blocks.go +++ b/rpc/core/blocks.go @@ -12,9 +12,8 @@ import ( // BlockchainInfo gets block headers for minHeight <= height <= maxHeight. // Block headers are returned in descending order (highest first). -// More: https://tendermint.com/rpc/#/Info/blockchain +// More: https://docs.tendermint.com/master/rpc/#/Info/blockchain func BlockchainInfo(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { - // maximum 20 block metas const limit int64 = 20 var err error @@ -68,7 +67,7 @@ func filterMinMax(height, min, max, limit int64) (int64, int64, error) { // Block gets block at a given height. // If no height is provided, it will fetch the latest block. -// More: https://tendermint.com/rpc/#/Info/block +// More: https://docs.tendermint.com/master/rpc/#/Info/block func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error) { storeHeight := blockStore.Height() height, err := getHeight(storeHeight, heightPtr) @@ -85,21 +84,20 @@ func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error) } // BlockByHash gets block by hash. -// More: https://tendermint.com/rpc/#/Info/block_by_hash +// More: https://docs.tendermint.com/master/rpc/#/Info/block_by_hash func BlockByHash(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error) { block := blockStore.LoadBlockByHash(hash) - height := block.Height - - blockMeta := blockStore.LoadBlockMeta(height) - if blockMeta == nil { - return &ctypes.ResultBlock{BlockID: types.BlockID{}, Block: block}, nil + if block == nil { + return &ctypes.ResultBlock{BlockID: types.BlockID{}, Block: nil}, nil } + // If block is not nil, then blockMeta can't be nil. + blockMeta := blockStore.LoadBlockMeta(block.Height) return &ctypes.ResultBlock{BlockID: blockMeta.BlockID, Block: block}, nil } // Commit gets block commit at a given height. // If no height is provided, it will fetch the commit for the latest block. -// More: https://tendermint.com/rpc/#/Info/commit +// More: https://docs.tendermint.com/master/rpc/#/Info/commit func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, error) { storeHeight := blockStore.Height() height, err := getHeight(storeHeight, heightPtr) @@ -107,7 +105,11 @@ func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, erro return nil, err } - header := blockStore.LoadBlockMeta(height).Header + blockMeta := blockStore.LoadBlockMeta(height) + if blockMeta == nil { + return nil, nil + } + header := blockMeta.Header // If the next block has not been committed yet, // use a non-canonical commit @@ -127,7 +129,7 @@ func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, erro // Results are for the height of the block containing the txs. // Thus response.results.deliver_tx[5] is the results of executing // getBlock(h).Txs[5] -// More: https://tendermint.com/rpc/#/Info/block_results +// More: https://docs.tendermint.com/master/rpc/#/Info/block_results func BlockResults(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlockResults, error) { storeHeight := blockStore.Height() height, err := getHeight(storeHeight, heightPtr) diff --git a/rpc/core/consensus.go b/rpc/core/consensus.go index 6a5a49e03..d88a6ba6a 100644 --- a/rpc/core/consensus.go +++ b/rpc/core/consensus.go @@ -13,7 +13,7 @@ import ( // If no height is provided, it will fetch the current validator set. // Note the validators are sorted by their address - this is the canonical // order for the validators in the set as used in computing their Merkle root. -// More: https://tendermint.com/rpc/#/Info/validators +// More: https://docs.tendermint.com/master/rpc/#/Info/validators func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ctypes.ResultValidators, error) { // The latest validator that we know is the // NextValidator of the last block. @@ -46,7 +46,7 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ct // DumpConsensusState dumps consensus state. // UNSTABLE -// More: https://tendermint.com/rpc/#/Info/dump_consensus_state +// More: https://docs.tendermint.com/master/rpc/#/Info/dump_consensus_state func DumpConsensusState(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error) { // Get Peer consensus states. peers := p2pPeers.Peers().List() @@ -88,7 +88,7 @@ func ConsensusState(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error) // ConsensusParams gets the consensus parameters at the given block height. // If no height is provided, it will fetch the current consensus params. -// More: https://tendermint.com/rpc/#/Info/consensus_params +// More: https://docs.tendermint.com/master/rpc/#/Info/consensus_params func ConsensusParams(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultConsensusParams, error) { height := consensusState.GetState().LastBlockHeight + 1 height, err := getHeight(height, heightPtr) diff --git a/rpc/core/events.go b/rpc/core/events.go index 49bf7be5d..2a4d042fc 100644 --- a/rpc/core/events.go +++ b/rpc/core/events.go @@ -13,7 +13,7 @@ import ( ) // Subscribe for events via WebSocket. -// More: https://tendermint.com/rpc/#/Websocket/subscribe +// More: https://docs.tendermint.com/master/rpc/#/Websocket/subscribe func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, error) { addr := ctx.RemoteAddr() @@ -72,7 +72,7 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er } // Unsubscribe from events via WebSocket. -// More: https://tendermint.com/rpc/#/Websocket/unsubscribe +// More: https://docs.tendermint.com/master/rpc/#/Websocket/unsubscribe func Unsubscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultUnsubscribe, error) { addr := ctx.RemoteAddr() logger.Info("Unsubscribe from query", "remote", addr, "query", query) @@ -88,7 +88,7 @@ func Unsubscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultUnsubscribe } // UnsubscribeAll from all events via WebSocket. -// More: https://tendermint.com/rpc/#/Websocket/unsubscribe_all +// More: https://docs.tendermint.com/master/rpc/#/Websocket/unsubscribe_all func UnsubscribeAll(ctx *rpctypes.Context) (*ctypes.ResultUnsubscribe, error) { addr := ctx.RemoteAddr() logger.Info("Unsubscribe from all", "remote", addr) diff --git a/rpc/core/evidence.go b/rpc/core/evidence.go index 7edda8b57..4ae138e7e 100644 --- a/rpc/core/evidence.go +++ b/rpc/core/evidence.go @@ -7,7 +7,7 @@ import ( ) // BroadcastEvidence broadcasts evidence of the misbehavior. -// More: https://tendermint.com/rpc/#/Info/broadcast_evidence +// More: https://docs.tendermint.com/master/rpc/#/Info/broadcast_evidence func BroadcastEvidence(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) { err := evidencePool.AddEvidence(ev) if err != nil { diff --git a/rpc/core/health.go b/rpc/core/health.go index 3d4f70dd1..eb715bea0 100644 --- a/rpc/core/health.go +++ b/rpc/core/health.go @@ -7,7 +7,7 @@ import ( // Health gets node health. Returns empty result (200 OK) on success, no // response - in case of an error. -// More: https://tendermint.com/rpc/#/Info/health +// More: https://docs.tendermint.com/master/rpc/#/Info/health func Health(ctx *rpctypes.Context) (*ctypes.ResultHealth, error) { return &ctypes.ResultHealth{}, nil } diff --git a/rpc/core/mempool.go b/rpc/core/mempool.go index 03123d057..28b73ab33 100644 --- a/rpc/core/mempool.go +++ b/rpc/core/mempool.go @@ -19,7 +19,7 @@ import ( // BroadcastTxAsync returns right away, with no response. Does not wait for // CheckTx nor DeliverTx results. -// More: https://tendermint.com/rpc/#/Tx/broadcast_tx_async +// More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_async func BroadcastTxAsync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { err := mempool.CheckTx(tx, nil, mempl.TxInfo{}) @@ -31,7 +31,7 @@ func BroadcastTxAsync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadca // BroadcastTxSync returns with the response from CheckTx. Does not wait for // DeliverTx result. -// More: https://tendermint.com/rpc/#/Tx/broadcast_tx_sync +// More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_sync func BroadcastTxSync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { resCh := make(chan *abci.Response, 1) err := mempool.CheckTx(tx, func(res *abci.Response) { @@ -51,7 +51,7 @@ func BroadcastTxSync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcas } // BroadcastTxCommit returns with the responses from CheckTx and DeliverTx. -// More: https://tendermint.com/rpc/#/Tx/broadcast_tx_commit +// More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_commit func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { subscriber := ctx.RemoteAddr() @@ -129,7 +129,7 @@ func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadc // UnconfirmedTxs gets unconfirmed transactions (maximum ?limit entries) // including their number. -// More: https://tendermint.com/rpc/#/Info/unconfirmed_txs +// More: https://docs.tendermint.com/master/rpc/#/Info/unconfirmed_txs func UnconfirmedTxs(ctx *rpctypes.Context, limit int) (*ctypes.ResultUnconfirmedTxs, error) { // reuse per_page validator limit = validatePerPage(limit) @@ -143,7 +143,7 @@ func UnconfirmedTxs(ctx *rpctypes.Context, limit int) (*ctypes.ResultUnconfirmed } // NumUnconfirmedTxs gets number of unconfirmed transactions. -// More: https://tendermint.com/rpc/#/Info/num_unconfirmed_txs +// More: https://docs.tendermint.com/master/rpc/#/Info/num_unconfirmed_txs func NumUnconfirmedTxs(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error) { return &ctypes.ResultUnconfirmedTxs{ Count: mempool.Size(), diff --git a/rpc/core/net.go b/rpc/core/net.go index 6f3e4bb7f..4a3d67d4f 100644 --- a/rpc/core/net.go +++ b/rpc/core/net.go @@ -11,7 +11,7 @@ import ( ) // NetInfo returns network info. -// More: https://tendermint.com/rpc/#/Info/net_info +// More: https://docs.tendermint.com/master/rpc/#/Info/net_info func NetInfo(ctx *rpctypes.Context) (*ctypes.ResultNetInfo, error) { peersList := p2pPeers.Peers().List() peers := make([]ctypes.Peer, 0, len(peersList)) @@ -69,7 +69,7 @@ func UnsafeDialPeers(ctx *rpctypes.Context, peers []string, persistent bool) (*c } // Genesis returns genesis file. -// More: https://tendermint.com/rpc/#/Info/genesis +// More: https://docs.tendermint.com/master/rpc/#/Info/genesis func Genesis(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error) { return &ctypes.ResultGenesis{Genesis: genDoc}, nil } diff --git a/rpc/core/status.go b/rpc/core/status.go index 36c521f30..e6438009a 100644 --- a/rpc/core/status.go +++ b/rpc/core/status.go @@ -14,7 +14,7 @@ import ( // Status returns Tendermint status including node info, pubkey, latest block // hash, app hash, block height and time. -// More: https://tendermint.com/rpc/#/Info/status +// More: https://docs.tendermint.com/master/rpc/#/Info/status func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { var latestHeight int64 if consensusReactor.FastSync() { @@ -22,6 +22,7 @@ func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { } else { latestHeight = consensusState.GetLastHeight() } + var ( latestBlockMeta *types.BlockMeta latestBlockHash tmbytes.HexBytes diff --git a/rpc/core/tx.go b/rpc/core/tx.go index 26d5364f4..f3cd54e4f 100644 --- a/rpc/core/tx.go +++ b/rpc/core/tx.go @@ -15,9 +15,8 @@ import ( // Tx allows you to query the transaction results. `nil` could mean the // transaction is in the mempool, invalidated, or was not sent in the first // place. -// More: https://tendermint.com/rpc/#/Info/tx +// More: https://docs.tendermint.com/master/rpc/#/Info/tx func Tx(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error) { - // if index is disabled, return error if _, ok := txIndexer.(*null.TxIndex); ok { return nil, fmt.Errorf("transaction indexing is disabled") @@ -53,7 +52,7 @@ func Tx(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error // TxSearch allows you to query for multiple transactions results. It returns a // list of transactions (maximum ?per_page entries) and the total count. -// More: https://tendermint.com/rpc/#/Info/tx_search +// More: https://docs.tendermint.com/master/rpc/#/Info/tx_search func TxSearch(ctx *rpctypes.Context, query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error) { // if index is disabled, return error if _, ok := txIndexer.(*null.TxIndex); ok {