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
1.2 KiB

9 years ago
  1. package core
  2. import (
  3. "fmt"
  4. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  5. "github.com/tendermint/tendermint/types"
  6. tmsp "github.com/tendermint/tmsp/types"
  7. )
  8. //-----------------------------------------------------------------------------
  9. // NOTE: tx must be signed
  10. func BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
  11. err := mempoolReactor.BroadcastTx(tx, nil)
  12. if err != nil {
  13. return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
  14. }
  15. return &ctypes.ResultBroadcastTx{}, nil
  16. }
  17. // Note: tx must be signed
  18. func BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
  19. resCh := make(chan *tmsp.Response, 1)
  20. err := mempoolReactor.BroadcastTx(tx, func(res *tmsp.Response) {
  21. resCh <- res
  22. })
  23. if err != nil {
  24. return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
  25. }
  26. res := <-resCh
  27. r := res.GetCheckTx()
  28. return &ctypes.ResultBroadcastTx{
  29. Code: r.Code,
  30. Data: r.Data,
  31. Log: r.Log,
  32. }, nil
  33. }
  34. func UnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) {
  35. txs := mempoolReactor.Mempool.Reap(0)
  36. return &ctypes.ResultUnconfirmedTxs{len(txs), txs}, nil
  37. }
  38. func NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) {
  39. return &ctypes.ResultUnconfirmedTxs{N: mempoolReactor.Mempool.Size()}, nil
  40. }