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.

46 lines
1018 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. // Tx allow user to query the transaction results. `nil` could mean the
  9. // transaction is in the mempool, invalidated, or was not send in the first
  10. // place.
  11. func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
  12. // if index is disabled, return error
  13. if _, ok := txIndexer.(*null.TxIndex); ok {
  14. return nil, fmt.Errorf("Transaction indexing is disabled.")
  15. }
  16. r, err := txIndexer.Get(hash)
  17. if err != nil {
  18. return nil, err
  19. }
  20. if r == nil {
  21. return nil, fmt.Errorf("Tx (%X) not found", hash)
  22. }
  23. height := int(r.Height) // XXX
  24. index := int(r.Index)
  25. var proof types.TxProof
  26. if prove {
  27. block := blockStore.LoadBlock(height)
  28. proof = block.Data.Txs.Proof(index)
  29. }
  30. return &ctypes.ResultTx{
  31. Height: height,
  32. Index: index,
  33. TxResult: r.Result.Result(),
  34. Tx: r.Tx,
  35. Proof: proof,
  36. }, nil
  37. }