mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-21 08:51:32 +00:00
/tx can take height+index or hash
This commit is contained in:
@ -19,7 +19,7 @@ var Routes = map[string]*rpc.RPCFunc{
|
||||
"genesis": rpc.NewRPCFunc(GenesisResult, ""),
|
||||
"block": rpc.NewRPCFunc(BlockResult, "height"),
|
||||
"commit": rpc.NewRPCFunc(CommitResult, "height"),
|
||||
"tx": rpc.NewRPCFunc(TxResult, "hash,prove"),
|
||||
"tx": rpc.NewRPCFunc(TxResult, "hash,height,index,prove"),
|
||||
"validators": rpc.NewRPCFunc(ValidatorsResult, ""),
|
||||
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
|
||||
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
|
||||
@ -100,8 +100,8 @@ func NumUnconfirmedTxsResult() (ctypes.TMResult, error) {
|
||||
// Tx allow user to query the transaction results. `nil` could mean the
|
||||
// transaction is in the mempool, invalidated, or was not send in the first
|
||||
// place.
|
||||
func TxResult(hash []byte, prove bool) (ctypes.TMResult, error) {
|
||||
return Tx(hash, prove)
|
||||
func TxResult(hash []byte, height, index int, prove bool) (ctypes.TMResult, error) {
|
||||
return Tx(hash, height, index, prove)
|
||||
}
|
||||
|
||||
func BroadcastTxCommitResult(tx []byte) (ctypes.TMResult, error) {
|
||||
|
@ -3,11 +3,18 @@ package core
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
abci "github.com/tendermint/abci/types"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
||||
func Tx(hash []byte, height, index int, prove bool) (*ctypes.ResultTx, error) {
|
||||
var deliverTx abci.ResponseDeliverTx
|
||||
if len(hash) > 0 {
|
||||
if height != 0 || index != 0 {
|
||||
return nil, fmt.Errorf("Invalid args. If hash is provided, height and index should not be")
|
||||
}
|
||||
|
||||
r, err := txIndexer.Tx(hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -17,18 +24,27 @@ func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
||||
return &ctypes.ResultTx{}, fmt.Errorf("Tx (%X) not found", hash)
|
||||
}
|
||||
|
||||
block := blockStore.LoadBlock(int(r.Height))
|
||||
tx := block.Data.Txs[int(r.Index)]
|
||||
height = int(r.Height) // XXX
|
||||
index = int(r.Index)
|
||||
deliverTx = r.DeliverTx
|
||||
}
|
||||
|
||||
block := blockStore.LoadBlock(height)
|
||||
|
||||
if 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]
|
||||
|
||||
var proof types.TxProof
|
||||
if prove {
|
||||
proof = block.Data.Txs.Proof(int(r.Index))
|
||||
proof = block.Data.Txs.Proof(index)
|
||||
}
|
||||
|
||||
return &ctypes.ResultTx{
|
||||
Height: r.Height,
|
||||
Index: r.Index,
|
||||
DeliverTx: r.DeliverTx,
|
||||
Height: height,
|
||||
Index: index,
|
||||
DeliverTx: deliverTx,
|
||||
Tx: tx,
|
||||
Proof: proof,
|
||||
}, nil
|
||||
|
Reference in New Issue
Block a user