mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-17 15:11:21 +00:00
rpc: fix getHeight
This commit is contained in:
@ -193,7 +193,8 @@ func BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, e
|
|||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
func Block(heightPtr *int64) (*ctypes.ResultBlock, error) {
|
func Block(heightPtr *int64) (*ctypes.ResultBlock, error) {
|
||||||
height, _, err := getHeight(blockStore, heightPtr)
|
storeHeight := blockStore.Height()
|
||||||
|
height, err := getHeight(storeHeight, heightPtr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -274,7 +275,8 @@ func Block(heightPtr *int64) (*ctypes.ResultBlock, error) {
|
|||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
func Commit(heightPtr *int64) (*ctypes.ResultCommit, error) {
|
func Commit(heightPtr *int64) (*ctypes.ResultCommit, error) {
|
||||||
height, storeHeight, err := getHeight(blockStore, heightPtr)
|
storeHeight := blockStore.Height()
|
||||||
|
height, err := getHeight(storeHeight, heightPtr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -327,7 +329,8 @@ func Commit(heightPtr *int64) (*ctypes.ResultCommit, error) {
|
|||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
func BlockResults(heightPtr *int64) (*ctypes.ResultBlockResults, error) {
|
func BlockResults(heightPtr *int64) (*ctypes.ResultBlockResults, error) {
|
||||||
height, _, err := getHeight(blockStore, heightPtr)
|
storeHeight := blockStore.Height()
|
||||||
|
height, err := getHeight(storeHeight, heightPtr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -346,18 +349,16 @@ func BlockResults(heightPtr *int64) (*ctypes.ResultBlockResults, error) {
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHeight(blockStore types.BlockStore, heightPtr *int64) (reqHeight int64, storeHeight int64, err error) {
|
func getHeight(storeHeight int64, heightPtr *int64) (int64, error) {
|
||||||
storeHeight = blockStore.Height()
|
|
||||||
if heightPtr != nil {
|
if heightPtr != nil {
|
||||||
reqHeight = *heightPtr
|
height := *heightPtr
|
||||||
if reqHeight <= 0 {
|
if height <= 0 {
|
||||||
return 0, 0, fmt.Errorf("Height must be greater than 0")
|
return 0, fmt.Errorf("Height must be greater than 0")
|
||||||
}
|
}
|
||||||
if reqHeight > storeHeight {
|
if height > storeHeight {
|
||||||
return 0, 0, fmt.Errorf("Height must be less than or equal to the current blockchain height")
|
return 0, fmt.Errorf("Height must be less than or equal to the current blockchain height")
|
||||||
}
|
}
|
||||||
} else {
|
return height, nil
|
||||||
reqHeight = blockStore.Height()
|
|
||||||
}
|
}
|
||||||
return reqHeight, storeHeight, nil
|
return storeHeight, nil
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,8 @@ import (
|
|||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
func Validators(heightPtr *int64) (*ctypes.ResultValidators, error) {
|
func Validators(heightPtr *int64) (*ctypes.ResultValidators, error) {
|
||||||
height, _, err := getHeight(blockStore, heightPtr)
|
storeHeight := blockStore.Height()
|
||||||
|
height, err := getHeight(storeHeight, heightPtr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user