From 6899c91ebed16b3cee91af6b5c1e73b5caa24cc1 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 12 Apr 2017 18:55:00 -0400 Subject: [PATCH] add optional 'prove' flag to /tx --- rpc/core/routes.go | 6 +++--- rpc/core/tx.go | 9 ++++++++- rpc/core/types/responses.go | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/rpc/core/routes.go b/rpc/core/routes.go index 8de828826..38e609601 100644 --- a/rpc/core/routes.go +++ b/rpc/core/routes.go @@ -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"), + "tx": rpc.NewRPCFunc(TxResult, "hash,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) (ctypes.TMResult, error) { - return Tx(hash) +func TxResult(hash []byte, prove bool) (ctypes.TMResult, error) { + return Tx(hash, prove) } func BroadcastTxCommitResult(tx []byte) (ctypes.TMResult, error) { diff --git a/rpc/core/tx.go b/rpc/core/tx.go index 5e066d0d8..14f87ece2 100644 --- a/rpc/core/tx.go +++ b/rpc/core/tx.go @@ -4,9 +4,10 @@ import ( "fmt" ctypes "github.com/tendermint/tendermint/rpc/core/types" + "github.com/tendermint/tendermint/types" ) -func Tx(hash []byte) (*ctypes.ResultTx, error) { +func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) { r, err := txIndexer.Tx(hash) if err != nil { return nil, err @@ -19,10 +20,16 @@ func Tx(hash []byte) (*ctypes.ResultTx, error) { block := blockStore.LoadBlock(int(r.Height)) tx := block.Data.Txs[int(r.Index)] + var proof types.TxProof + if prove { + proof = block.Data.Txs.Proof(int(r.Index)) + } + return &ctypes.ResultTx{ Height: r.Height, Index: r.Index, DeliverTx: r.DeliverTx, Tx: tx, + Proof: proof, }, nil } diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index f5dc5f1d7..9ed2383b2 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -83,6 +83,7 @@ type ResultTx struct { Index uint32 `json:"index"` DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"` Tx types.Tx `json:"tx"` + Proof types.TxProof `json:"proof,omitempty"` } type ResultUnconfirmedTxs struct {