You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
851 B

  1. package core
  2. import (
  3. "fmt"
  4. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  5. "github.com/tendermint/tendermint/state/txindex/null"
  6. "github.com/tendermint/tendermint/types"
  7. )
  8. func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
  9. // if index is disabled, return error
  10. if _, ok := txIndexer.(*null.TxIndex); ok {
  11. return nil, fmt.Errorf("Transaction indexing is disabled.")
  12. }
  13. r, err := txIndexer.Get(hash)
  14. if err != nil {
  15. return nil, err
  16. }
  17. if r == nil {
  18. return nil, fmt.Errorf("Tx (%X) not found", hash)
  19. }
  20. height := int(r.Height) // XXX
  21. index := int(r.Index)
  22. var proof types.TxProof
  23. if prove {
  24. block := blockStore.LoadBlock(height)
  25. proof = block.Data.Txs.Proof(index)
  26. }
  27. return &ctypes.ResultTx{
  28. Height: height,
  29. Index: index,
  30. TxResult: r.Result,
  31. Tx: r.Tx,
  32. Proof: proof,
  33. }, nil
  34. }