2015-03-26 21:30:42 -07:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-04-07 11:44:25 -07:00
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
2015-04-01 17:30:16 -07:00
|
|
|
"github.com/tendermint/tendermint/types"
|
2016-02-08 00:48:58 -08:00
|
|
|
tmsp "github.com/tendermint/tmsp/types"
|
2015-03-26 21:30:42 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-02-08 00:48:58 -08:00
|
|
|
// NOTE: tx must be signed
|
|
|
|
func BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
|
|
|
err := mempoolReactor.BroadcastTx(tx, nil)
|
2015-03-26 21:30:42 -07:00
|
|
|
if err != nil {
|
2015-03-28 23:10:05 -07:00
|
|
|
return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
2015-11-01 11:34:08 -08:00
|
|
|
return &ctypes.ResultBroadcastTx{}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
|
|
|
|
2016-02-08 00:48:58 -08:00
|
|
|
// Note: tx must be signed
|
|
|
|
func BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
2016-02-08 15:38:18 -08:00
|
|
|
resCh := make(chan *tmsp.Response, 1)
|
2016-02-08 00:48:58 -08:00
|
|
|
err := mempoolReactor.BroadcastTx(tx, func(res *tmsp.Response) {
|
|
|
|
resCh <- res
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
|
|
|
|
}
|
|
|
|
res := <-resCh
|
2016-05-14 12:33:27 -04:00
|
|
|
r := res.GetCheckTx()
|
2016-02-08 00:48:58 -08:00
|
|
|
return &ctypes.ResultBroadcastTx{
|
2016-05-14 12:33:27 -04:00
|
|
|
Code: r.Code,
|
|
|
|
Data: r.Data,
|
|
|
|
Log: r.Log,
|
2016-02-08 00:48:58 -08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func UnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) {
|
2016-03-06 15:08:32 -08:00
|
|
|
txs := mempoolReactor.Mempool.Reap(0)
|
2016-02-14 17:00:33 -08:00
|
|
|
return &ctypes.ResultUnconfirmedTxs{len(txs), txs}, nil
|
2015-04-25 13:26:36 -07:00
|
|
|
}
|
2016-03-05 20:59:51 -05:00
|
|
|
|
|
|
|
func NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) {
|
2016-03-07 18:38:05 -05:00
|
|
|
return &ctypes.ResultUnconfirmedTxs{N: mempoolReactor.Mempool.Size()}, nil
|
2016-03-05 20:59:51 -05:00
|
|
|
}
|