Browse Source

/tx can take height+index or hash

pull/412/head
Ethan Buchman 8 years ago
parent
commit
df35989742
2 changed files with 32 additions and 16 deletions
  1. +3
    -3
      rpc/core/routes.go
  2. +29
    -13
      rpc/core/tx.go

+ 3
- 3
rpc/core/routes.go View File

@ -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) {


+ 29
- 13
rpc/core/tx.go View File

@ -3,32 +3,48 @@ 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) {
r, err := txIndexer.Tx(hash)
if err != nil {
return nil, err
}
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
}
if r == nil {
return &ctypes.ResultTx{}, fmt.Errorf("Tx (%X) not found", hash)
}
if r == nil {
return &ctypes.ResultTx{}, fmt.Errorf("Tx (%X) not found", hash)
height = int(r.Height) // XXX
index = int(r.Index)
deliverTx = r.DeliverTx
}
block := blockStore.LoadBlock(int(r.Height))
tx := block.Data.Txs[int(r.Index)]
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


Loading…
Cancel
Save