mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-18 07:31:20 +00:00
add UnconfirmedTxs/NumUnconfirmedTxs methods to HTTP/Local clients (#2964)
This commit is contained in:
committed by
Anton Kaliaev
parent
df32ea4be5
commit
2594cec116
@ -19,6 +19,7 @@ Special thanks to external contributors on this release:
|
|||||||
### FEATURES:
|
### FEATURES:
|
||||||
|
|
||||||
### IMPROVEMENTS:
|
### IMPROVEMENTS:
|
||||||
|
- [rpc] Add `UnconfirmedTxs(limit)` and `NumUnconfirmedTxs()` methods to HTTP/Local clients (@danil-lashin)
|
||||||
|
|
||||||
### BUG FIXES:
|
### BUG FIXES:
|
||||||
- [kv indexer] \#2912 don't ignore key when executing CONTAINS
|
- [kv indexer] \#2912 don't ignore key when executing CONTAINS
|
||||||
|
@ -109,6 +109,24 @@ func (c *HTTP) broadcastTX(route string, tx types.Tx) (*ctypes.ResultBroadcastTx
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *HTTP) UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error) {
|
||||||
|
result := new(ctypes.ResultUnconfirmedTxs)
|
||||||
|
_, err := c.rpc.Call("unconfirmed_txs", map[string]interface{}{"limit": limit}, result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "unconfirmed_txs")
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *HTTP) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) {
|
||||||
|
result := new(ctypes.ResultUnconfirmedTxs)
|
||||||
|
_, err := c.rpc.Call("num_unconfirmed_txs", map[string]interface{}{}, result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "num_unconfirmed_txs")
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) {
|
func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) {
|
||||||
result := new(ctypes.ResultNetInfo)
|
result := new(ctypes.ResultNetInfo)
|
||||||
_, err := c.rpc.Call("net_info", map[string]interface{}{}, result)
|
_, err := c.rpc.Call("net_info", map[string]interface{}{}, result)
|
||||||
|
@ -93,3 +93,9 @@ type NetworkClient interface {
|
|||||||
type EventsClient interface {
|
type EventsClient interface {
|
||||||
types.EventBusSubscriber
|
types.EventBusSubscriber
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MempoolClient shows us data about current mempool state.
|
||||||
|
type MempoolClient interface {
|
||||||
|
UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
|
||||||
|
NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
|
||||||
|
}
|
||||||
|
@ -76,6 +76,14 @@ func (Local) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
|||||||
return core.BroadcastTxSync(tx)
|
return core.BroadcastTxSync(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (Local) UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error) {
|
||||||
|
return core.UnconfirmedTxs(limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Local) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) {
|
||||||
|
return core.NumUnconfirmedTxs()
|
||||||
|
}
|
||||||
|
|
||||||
func (Local) NetInfo() (*ctypes.ResultNetInfo, error) {
|
func (Local) NetInfo() (*ctypes.ResultNetInfo, error) {
|
||||||
return core.NetInfo()
|
return core.NetInfo()
|
||||||
}
|
}
|
||||||
|
@ -281,6 +281,42 @@ func TestBroadcastTxCommit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnconfirmedTxs(t *testing.T) {
|
||||||
|
_, _, tx := MakeTxKV()
|
||||||
|
|
||||||
|
mempool := node.MempoolReactor().Mempool
|
||||||
|
_ = mempool.CheckTx(tx, nil)
|
||||||
|
|
||||||
|
for i, c := range GetClients() {
|
||||||
|
mc, ok := c.(client.MempoolClient)
|
||||||
|
require.True(t, ok, "%d", i)
|
||||||
|
txs, err := mc.UnconfirmedTxs(1)
|
||||||
|
require.Nil(t, err, "%d: %+v", i, err)
|
||||||
|
assert.Exactly(t, types.Txs{tx}, types.Txs(txs.Txs))
|
||||||
|
}
|
||||||
|
|
||||||
|
mempool.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNumUnconfirmedTxs(t *testing.T) {
|
||||||
|
_, _, tx := MakeTxKV()
|
||||||
|
|
||||||
|
mempool := node.MempoolReactor().Mempool
|
||||||
|
_ = mempool.CheckTx(tx, nil)
|
||||||
|
mempoolSize := mempool.Size()
|
||||||
|
|
||||||
|
for i, c := range GetClients() {
|
||||||
|
mc, ok := c.(client.MempoolClient)
|
||||||
|
require.True(t, ok, "%d", i)
|
||||||
|
res, err := mc.NumUnconfirmedTxs()
|
||||||
|
require.Nil(t, err, "%d: %+v", i, err)
|
||||||
|
|
||||||
|
assert.Equal(t, mempoolSize, res.N)
|
||||||
|
}
|
||||||
|
|
||||||
|
mempool.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
func TestTx(t *testing.T) {
|
func TestTx(t *testing.T) {
|
||||||
// first we broadcast a tx
|
// first we broadcast a tx
|
||||||
c := getHTTPClient()
|
c := getHTTPClient()
|
||||||
|
Reference in New Issue
Block a user