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.

44 lines
1.3 KiB

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