/tx returns tx bytes

This commit is contained in:
Ethan Buchman 2017-04-12 18:18:17 -04:00
parent 7fbe8e47d4
commit 2a59cda77e
5 changed files with 32 additions and 21 deletions

View File

@ -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
}

View File

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

View File

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

View File

@ -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"`
}

View File

@ -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"`
}