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.

41 lines
1.1 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. return &ctypes.ResultBroadcastTx{
  28. Code: res.Code,
  29. Data: res.Data,
  30. Log: res.Log,
  31. }, nil
  32. }
  33. func UnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) {
  34. txs := mempoolReactor.Mempool.Reap()
  35. return &ctypes.ResultUnconfirmedTxs{len(txs), txs}, nil
  36. }