From df25a22469f1a14586c3227b4b0c6c1608fec372 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 5 Mar 2016 20:59:51 -0500 Subject: [PATCH] rpc: num_unconfirmed_txs (avoid sending txs back) --- rpc/core/mempool.go | 5 +++++ rpc/core/routes.go | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/rpc/core/mempool.go b/rpc/core/mempool.go index e5a34026c..e10c72660 100644 --- a/rpc/core/mempool.go +++ b/rpc/core/mempool.go @@ -39,3 +39,8 @@ func UnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) { txs := mempoolReactor.Mempool.Reap(0) return &ctypes.ResultUnconfirmedTxs{len(txs), txs}, nil } + +func NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) { + txs := mempoolReactor.Mempool.Reap() + return &ctypes.ResultUnconfirmedTxs{len(txs), txs[:0]}, nil +} diff --git a/rpc/core/routes.go b/rpc/core/routes.go index 53604c0fc..5a4987da5 100644 --- a/rpc/core/routes.go +++ b/rpc/core/routes.go @@ -22,6 +22,7 @@ var Routes = map[string]*rpc.RPCFunc{ "broadcast_tx_sync": rpc.NewRPCFunc(BroadcastTxSyncResult, "tx"), "broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"), "unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""), + "num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxsResult, ""), "unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"), } @@ -114,6 +115,14 @@ func UnconfirmedTxsResult() (ctypes.TMResult, error) { } } +func NumUnconfirmedTxsResult() (ctypes.TMResult, error) { + if r, err := NumUnconfirmedTxs(); err != nil { + return nil, err + } else { + return r, nil + } +} + func BroadcastTxSyncResult(tx []byte) (ctypes.TMResult, error) { if r, err := BroadcastTxSync(tx); err != nil { return nil, err