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, ""),
|
"genesis": rpc.NewRPCFunc(GenesisResult, ""),
|
||||||
"block": rpc.NewRPCFunc(BlockResult, "height"),
|
"block": rpc.NewRPCFunc(BlockResult, "height"),
|
||||||
"commit": rpc.NewRPCFunc(CommitResult, "height"),
|
"commit": rpc.NewRPCFunc(CommitResult, "height"),
|
||||||
"tx": rpc.NewRPCFunc(TxResult, "hash,prove"),
|
"tx": rpc.NewRPCFunc(TxResult, "hash,height,index,prove"),
|
||||||
"validators": rpc.NewRPCFunc(ValidatorsResult, ""),
|
"validators": rpc.NewRPCFunc(ValidatorsResult, ""),
|
||||||
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
|
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
|
||||||
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
|
"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
|
// 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
|
// transaction is in the mempool, invalidated, or was not send in the first
|
||||||
// place.
|
// place.
|
||||||
func TxResult(hash []byte, prove bool) (ctypes.TMResult, error) {
|
func TxResult(hash []byte, height, index int, prove bool) (ctypes.TMResult, error) {
|
||||||
return Tx(hash, prove)
|
return Tx(hash, height, index, prove)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BroadcastTxCommitResult(tx []byte) (ctypes.TMResult, error) {
|
func BroadcastTxCommitResult(tx []byte) (ctypes.TMResult, error) {
|
||||||
|
@ -3,11 +3,18 @@ package core
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
abci "github.com/tendermint/abci/types"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
"github.com/tendermint/tendermint/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)
|
r, err := txIndexer.Tx(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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)
|
return &ctypes.ResultTx{}, fmt.Errorf("Tx (%X) not found", hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
block := blockStore.LoadBlock(int(r.Height))
|
height = int(r.Height) // XXX
|
||||||
tx := block.Data.Txs[int(r.Index)]
|
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
|
var proof types.TxProof
|
||||||
if prove {
|
if prove {
|
||||||
proof = block.Data.Txs.Proof(int(r.Index))
|
proof = block.Data.Txs.Proof(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ctypes.ResultTx{
|
return &ctypes.ResultTx{
|
||||||
Height: r.Height,
|
Height: height,
|
||||||
Index: r.Index,
|
Index: index,
|
||||||
DeliverTx: r.DeliverTx,
|
DeliverTx: deliverTx,
|
||||||
Tx: tx,
|
Tx: tx,
|
||||||
Proof: proof,
|
Proof: proof,
|
||||||
}, nil
|
}, nil
|
||||||
|
Reference in New Issue
Block a user