You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.3 KiB

  1. package core
  2. import (
  3. "fmt"
  4. . "github.com/tendermint/go-common"
  5. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  6. "github.com/tendermint/tendermint/types"
  7. )
  8. //-----------------------------------------------------------------------------
  9. func BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) {
  10. if maxHeight == 0 {
  11. maxHeight = blockStore.Height()
  12. } else {
  13. maxHeight = MinInt(blockStore.Height(), maxHeight)
  14. }
  15. if minHeight == 0 {
  16. minHeight = MaxInt(1, maxHeight-20)
  17. }
  18. log.Debug("BlockchainInfoHandler", "maxHeight", maxHeight, "minHeight", minHeight)
  19. blockMetas := []*types.BlockMeta{}
  20. for height := maxHeight; height >= minHeight; height-- {
  21. blockMeta := blockStore.LoadBlockMeta(height)
  22. blockMetas = append(blockMetas, blockMeta)
  23. }
  24. return &ctypes.ResultBlockchainInfo{blockStore.Height(), blockMetas}, nil
  25. }
  26. //-----------------------------------------------------------------------------
  27. func Block(height int) (*ctypes.ResultBlock, error) {
  28. if height == 0 {
  29. return nil, fmt.Errorf("Height must be greater than 0")
  30. }
  31. if height > blockStore.Height() {
  32. return nil, fmt.Errorf("Height must be less than the current blockchain height")
  33. }
  34. blockMeta := blockStore.LoadBlockMeta(height)
  35. block := blockStore.LoadBlock(height)
  36. return &ctypes.ResultBlock{blockMeta, block}, nil
  37. }