rpc: better arg validation for /tx

This commit is contained in:
Ethan Buchman
2017-04-13 15:18:58 -04:00
parent b33a7c46ce
commit c848056438

View File

@ -29,9 +29,13 @@ func Tx(hash []byte, height, index int, prove bool) (*ctypes.ResultTx, error) {
deliverTx = r.DeliverTx
}
if height <= 0 || height > blockStore.Height() {
return nil, fmt.Errorf("Invalid height (%d) for blockStore at height %d", height, blockStore.Height())
}
block := blockStore.LoadBlock(height)
if index >= len(block.Data.Txs) {
if index < 0 || index >= len(block.Data.Txs) {
return nil, fmt.Errorf("Index (%d) is out of range for block (%d) with %d txs", index, height, len(block.Data.Txs))
}
tx := block.Data.Txs[index]