2017-04-10 17:18:22 -04:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2017-04-12 18:18:17 -04:00
|
|
|
"fmt"
|
|
|
|
|
2017-04-10 17:18:22 -04:00
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
2017-04-12 18:55:00 -04:00
|
|
|
"github.com/tendermint/tendermint/types"
|
2017-04-10 17:18:22 -04:00
|
|
|
)
|
|
|
|
|
2017-04-12 18:55:00 -04:00
|
|
|
func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
2017-04-10 17:18:22 -04:00
|
|
|
r, err := txIndexer.Tx(hash)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-04-12 18:18:17 -04:00
|
|
|
|
|
|
|
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)]
|
|
|
|
|
2017-04-12 18:55:00 -04:00
|
|
|
var proof types.TxProof
|
|
|
|
if prove {
|
|
|
|
proof = block.Data.Txs.Proof(int(r.Index))
|
|
|
|
}
|
|
|
|
|
2017-04-12 18:18:17 -04:00
|
|
|
return &ctypes.ResultTx{
|
|
|
|
Height: r.Height,
|
|
|
|
Index: r.Index,
|
|
|
|
DeliverTx: r.DeliverTx,
|
|
|
|
Tx: tx,
|
2017-04-12 18:55:00 -04:00
|
|
|
Proof: proof,
|
2017-04-12 18:18:17 -04:00
|
|
|
}, nil
|
2017-04-10 17:18:22 -04:00
|
|
|
}
|