From 41c6ed8b6ffd9b76a53b07f214856c537c3ccd66 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Wed, 31 Jan 2018 15:04:54 +0100 Subject: [PATCH] Implement getrawmempool rpc message --- bitcoin/bitcoinrpc.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bitcoin/bitcoinrpc.go b/bitcoin/bitcoinrpc.go index 43d6dad7..7fd3f3e0 100644 --- a/bitcoin/bitcoinrpc.go +++ b/bitcoin/bitcoinrpc.go @@ -56,6 +56,17 @@ type resGetBlockCount struct { Result uint32 `json:"result"` } +// getrawmempool + +type cmdGetMempool struct { + Method string `json:"method"` +} + +type resGetMempool struct { + Error *RPCError `json:"error"` + Result []string `json:"result"` +} + // getblockheader type cmdGetBlockHeader struct { @@ -308,6 +319,23 @@ func (b *BitcoinRPC) GetBlockFull(hash string) (*Block, error) { return &res.Result, nil } +// GetMempool returns transactions in mempool. +func (b *BitcoinRPC) GetMempool() ([]string, error) { + glog.V(1).Info("rpc: getrawmempool") + + res := resGetMempool{} + req := cmdGetMempool{Method: "getrawmempool"} + err := b.call(&req, &res) + + if err != nil { + return nil, err + } + if res.Error != nil { + return nil, res.Error + } + return res.Result, nil +} + // GetTransaction returns a transaction by the transaction ID. func (b *BitcoinRPC) GetTransaction(txid string) (*Tx, error) { glog.V(1).Info("rpc: getrawtransaction ", txid)