From 2a59cda77e05094f815d63fa34045282b472c704 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 12 Apr 2017 18:18:17 -0400 Subject: [PATCH] /tx returns tx bytes --- rpc/core/tx.go | 17 ++++++++++++++++- rpc/core/types/responses.go | 5 ++++- state/execution.go | 7 ++----- types/tx.go | 10 ++++++++++ types/tx_result.go | 14 -------------- 5 files changed, 32 insertions(+), 21 deletions(-) delete mode 100644 types/tx_result.go diff --git a/rpc/core/tx.go b/rpc/core/tx.go index bffeced7c..5e066d0d8 100644 --- a/rpc/core/tx.go +++ b/rpc/core/tx.go @@ -1,6 +1,8 @@ package core import ( + "fmt" + ctypes "github.com/tendermint/tendermint/rpc/core/types" ) @@ -9,5 +11,18 @@ func Tx(hash []byte) (*ctypes.ResultTx, error) { if err != nil { return nil, err } - return &ctypes.ResultTx{*r}, nil + + if r == nil { + return &ctypes.ResultTx{}, fmt.Errorf("Tx (%X) not found", hash) + } + + block := blockStore.LoadBlock(int(r.Height)) + tx := block.Data.Txs[int(r.Index)] + + return &ctypes.ResultTx{ + Height: r.Height, + Index: r.Index, + DeliverTx: r.DeliverTx, + Tx: tx, + }, nil } diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index 2ec762e36..8f6fb0ab7 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -78,7 +78,10 @@ type ResultBroadcastTxCommit struct { } type ResultTx struct { - types.TxResult + Height uint64 `json:"height"` + Index uint32 `json:"index"` + DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"` + Tx types.Tx `json:"tx"` } type ResultUnconfirmedTxs struct { diff --git a/state/execution.go b/state/execution.go index 545225be1..75903d402 100644 --- a/state/execution.go +++ b/state/execution.go @@ -242,11 +242,8 @@ func (s *State) ApplyBlock(eventCache types.Fireable, proxyAppConn proxy.AppConn batch := txindexer.NewBatch() for i, r := range txResults { - if r != nil { - tx := block.Txs[i] - // dd2e325f79f7e5f77788759d278c1d4b370c842e => {"height":2405, "index":0, ...} - batch.Index(tx.Hash(), *r) - } + tx := block.Txs[i] + batch.Index(tx.Hash(), *r) } s.TxIndexer.Batch(batch) diff --git a/types/tx.go b/types/tx.go index a67206d4e..d2b4ee8df 100644 --- a/types/tx.go +++ b/types/tx.go @@ -1,6 +1,7 @@ package types import ( + abci "github.com/tendermint/abci/types" "github.com/tendermint/go-merkle" ) @@ -30,3 +31,12 @@ func (txs Txs) Hash() []byte { return merkle.SimpleHashFromTwoHashes(left, right) } } + +// TxResult contains results of executing the transaction. +// +// One usage is indexing transaction results. +type TxResult struct { + Height uint64 `json:"height"` + Index uint32 `json:"index"` + DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"` +} diff --git a/types/tx_result.go b/types/tx_result.go deleted file mode 100644 index c1fc717d3..000000000 --- a/types/tx_result.go +++ /dev/null @@ -1,14 +0,0 @@ -package types - -import ( - abci "github.com/tendermint/abci/types" -) - -// TxResult contains results of executing the transaction. -// -// One usage is indexing transaction results. -type TxResult struct { - Height uint64 `json:"height"` - Index uint32 `json:"index"` - DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"` -}