1
0
mirror of https://github.com/fluencelabs/tendermint synced 2025-07-15 04:21:45 +00:00
Files
.github
DOCKER
benchmarks
blockchain
cmd
config
consensus
docs
mempool
node
p2p
proxy
rpc
client
core
types
abci.go
blocks.go
consensus.go
dev.go
events.go
mempool.go
net.go
pipe.go
routes.go
status.go
tx.go
version.go
grpc
lib
test
scripts
state
test
types
version
.codecov.yml
.editorconfig
.gitignore
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
INSTALL.md
LICENSE
Makefile
README.md
Vagrantfile
circle.yml
glide.lock
glide.yaml
tendermint/rpc/core/blocks.go

76 lines
2.2 KiB
Go
Raw Normal View History

package core
import (
"fmt"
2017-05-02 11:53:32 +04:00
ctypes "github.com/tendermint/tendermint/rpc/core/types"
2015-04-01 17:30:16 -07:00
"github.com/tendermint/tendermint/types"
2017-05-02 11:53:32 +04:00
. "github.com/tendermint/tmlibs/common"
)
//-----------------------------------------------------------------------------
// Returns at most 20 blocks
func BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) {
if maxHeight == 0 {
maxHeight = blockStore.Height()
} else {
maxHeight = MinInt(blockStore.Height(), maxHeight)
}
if minHeight == 0 {
minHeight = MaxInt(1, maxHeight-20)
} else {
minHeight = MaxInt(minHeight, maxHeight-20)
}
2017-05-02 11:53:32 +04:00
logger.Debug("BlockchainInfoHandler", "maxHeight", maxHeight, "minHeight", minHeight)
blockMetas := []*types.BlockMeta{}
for height := maxHeight; height >= minHeight; height-- {
blockMeta := blockStore.LoadBlockMeta(height)
blockMetas = append(blockMetas, blockMeta)
}
return &ctypes.ResultBlockchainInfo{blockStore.Height(), blockMetas}, nil
}
//-----------------------------------------------------------------------------
2016-02-08 00:48:58 -08:00
func Block(height int) (*ctypes.ResultBlock, error) {
if height == 0 {
2015-07-11 18:01:21 -07:00
return nil, fmt.Errorf("Height must be greater than 0")
}
if height > blockStore.Height() {
2015-07-11 18:01:21 -07:00
return nil, fmt.Errorf("Height must be less than the current blockchain height")
}
blockMeta := blockStore.LoadBlockMeta(height)
block := blockStore.LoadBlock(height)
2016-02-08 00:48:58 -08:00
return &ctypes.ResultBlock{blockMeta, block}, nil
}
2017-02-09 22:44:43 -05:00
//-----------------------------------------------------------------------------
func Commit(height int) (*ctypes.ResultCommit, error) {
if height == 0 {
return nil, fmt.Errorf("Height must be greater than 0")
}
storeHeight := blockStore.Height()
if height > storeHeight {
return nil, fmt.Errorf("Height must be less than or equal to the current blockchain height")
}
2017-02-14 15:33:14 -05:00
header := blockStore.LoadBlockMeta(height).Header
2017-02-09 22:44:43 -05:00
// If the next block has not been committed yet,
// use a non-canonical commit
2017-02-16 15:35:34 -05:00
if height == storeHeight {
2017-02-09 22:44:43 -05:00
commit := blockStore.LoadSeenCommit(height)
2017-02-14 15:33:14 -05:00
return &ctypes.ResultCommit{header, commit, false}, nil
2017-02-09 22:44:43 -05:00
}
// Return the canonical commit (comes from the block at height+1)
commit := blockStore.LoadBlockCommit(height)
2017-02-14 15:33:14 -05:00
return &ctypes.ResultCommit{header, commit, true}, nil
2017-02-09 22:44:43 -05:00
}