tendermint/rpc/tendermint/core/tx.go

44 lines
862 B
Go
Raw Normal View History

package core
import (
2017-04-12 15:18:17 -07:00
"fmt"
ctypes "github.com/tendermint/tendermint/rpc/tendermint/core/types"
"github.com/tendermint/tendermint/state/txindex/null"
2017-04-12 15:55:00 -07:00
"github.com/tendermint/tendermint/types"
)
func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
2017-04-13 10:47:48 -07:00
// if index is disabled, return error
if _, ok := txIndexer.(*null.TxIndex); ok {
return nil, fmt.Errorf("Transaction indexing is disabled.")
2017-04-13 13:04:20 -07:00
}
r, err := txIndexer.Get(hash)
if err != nil {
return nil, err
2017-04-13 13:04:20 -07:00
}
if r == nil {
return nil, fmt.Errorf("Tx (%X) not found", hash)
2017-04-13 12:18:58 -07:00
}
height := int(r.Height) // XXX
index := int(r.Index)
2017-04-12 15:18:17 -07:00
2017-04-12 15:55:00 -07:00
var proof types.TxProof
if prove {
block := blockStore.LoadBlock(height)
2017-04-13 10:47:48 -07:00
proof = block.Data.Txs.Proof(index)
2017-04-12 15:55:00 -07:00
}
2017-04-12 15:18:17 -07:00
return &ctypes.ResultTx{
2017-04-13 13:04:20 -07:00
Height: height,
Index: index,
TxResult: r.Result,
Tx: r.Tx,
2017-04-13 13:04:20 -07:00
Proof: proof,
2017-04-12 15:18:17 -07:00
}, nil
}