diff --git a/btcjson/chainsvrresults.go b/btcjson/chainsvrresults.go
index 168d0034..c0efd7cd 100644
--- a/btcjson/chainsvrresults.go
+++ b/btcjson/chainsvrresults.go
@@ -122,6 +122,13 @@ type GetBlockTemplateResult struct {
RejectReasion string `json:"reject-reason,omitempty"`
}
+// GetMempoolInfoResult models the data returned from the getmempoolinfo
+// command.
+type GetMempoolInfoResult struct {
+ Size int64 `json:"size"`
+ Bytes int64 `json:"bytes"`
+}
+
// GetNetworkInfoResult models the data returned from the getnetworkinfo
// command.
type GetNetworkInfoResult struct {
diff --git a/docs/json_rpc_api.md b/docs/json_rpc_api.md
index 7d3620f4..7c1192ef 100644
--- a/docs/json_rpc_api.md
+++ b/docs/json_rpc_api.md
@@ -162,21 +162,22 @@ the method name for further details such as parameter and return information.
|12|[getgenerate](#getgenerate)|N|Return if the server is set to generate coins (mine) or not.|
|13|[gethashespersec](#gethashespersec)|N|Returns a recent hashes per second performance measurement while generating coins (mining).|
|14|[getinfo](#getinfo)|Y|Returns a JSON object containing various state info.|
-|15|[getmininginfo](#getmininginfo)|N|Returns a JSON object containing mining-related information.|
-|16|[getnettotals](#getnettotals)|Y|Returns a JSON object containing network traffic statistics.|
-|17|[getnetworkhashps](#getnetworkhashps)|Y|Returns the estimated network hashes per second for the block heights provided by the parameters.|
-|18|[getpeerinfo](#getpeerinfo)|N|Returns information about each connected network peer as an array of json objects.|
-|19|[getrawmempool](#getrawmempool)|Y|Returns an array of hashes for all of the transactions currently in the memory pool.|
-|20|[getrawtransaction](#getrawtransaction)|Y|Returns information about a transaction given its hash.|
-|21|[getwork](#getwork)|N|Returns formatted hash data to work on or checks and submits solved data.
NOTE: Since btcd does not have the wallet integrated to provide payment addresses, btcd must be configured via the `--miningaddr` option to provide which payment addresses to pay created blocks to for this RPC to function.|
-|22|[help](#help)|Y|Returns a list of all commands or help for a specified command.|
-|23|[ping](#ping)|N|Queues a ping to be sent to each connected peer.|
-|24|[sendrawtransaction](#sendrawtransaction)|Y|Submits the serialized, hex-encoded transaction to the local peer and relays it to the network.
btcd does not yet implement the `allowhighfees` parameter, so it has no effect|
-|25|[setgenerate](#setgenerate) |N|Set the server to generate coins (mine) or not.
NOTE: Since btcd does not have the wallet integrated to provide payment addresses, btcd must be configured via the `--miningaddr` option to provide which payment addresses to pay created blocks to for this RPC to function.|
-|26|[stop](#stop)|N|Shutdown btcd.|
-|27|[submitblock](#submitblock)|Y|Attempts to submit a new serialized, hex-encoded block to the network.|
-|28|[validateaddress](#validateaddress)|Y|Verifies the given address is valid. NOTE: Since btcd does not have a wallet integrated, btcd will only return whether the address is valid or not.|
-|29|[verifychain](#verifychain)|N|Verifies the block chain database.|
+|15|[getmempoolinfo](#getmempoolinfo)|N|Returns a JSON object containing mempool-related information.|
+|16|[getmininginfo](#getmininginfo)|N|Returns a JSON object containing mining-related information.|
+|17|[getnettotals](#getnettotals)|Y|Returns a JSON object containing network traffic statistics.|
+|18|[getnetworkhashps](#getnetworkhashps)|Y|Returns the estimated network hashes per second for the block heights provided by the parameters.|
+|19|[getpeerinfo](#getpeerinfo)|N|Returns information about each connected network peer as an array of json objects.|
+|20|[getrawmempool](#getrawmempool)|Y|Returns an array of hashes for all of the transactions currently in the memory pool.|
+|21|[getrawtransaction](#getrawtransaction)|Y|Returns information about a transaction given its hash.|
+|22|[getwork](#getwork)|N|Returns formatted hash data to work on or checks and submits solved data.
NOTE: Since btcd does not have the wallet integrated to provide payment addresses, btcd must be configured via the `--miningaddr` option to provide which payment addresses to pay created blocks to for this RPC to function.|
+|23|[help](#help)|Y|Returns a list of all commands or help for a specified command.|
+|24|[ping](#ping)|N|Queues a ping to be sent to each connected peer.|
+|25|[sendrawtransaction](#sendrawtransaction)|Y|Submits the serialized, hex-encoded transaction to the local peer and relays it to the network.
btcd does not yet implement the `allowhighfees` parameter, so it has no effect|
+|26|[setgenerate](#setgenerate) |N|Set the server to generate coins (mine) or not.
NOTE: Since btcd does not have the wallet integrated to provide payment addresses, btcd must be configured via the `--miningaddr` option to provide which payment addresses to pay created blocks to for this RPC to function.|
+|27|[stop](#stop)|N|Shutdown btcd.|
+|28|[submitblock](#submitblock)|Y|Attempts to submit a new serialized, hex-encoded block to the network.|
+|29|[validateaddress](#validateaddress)|Y|Verifies the given address is valid. NOTE: Since btcd does not have a wallet integrated, btcd will only return whether the address is valid or not.|
+|30|[verifychain](#verifychain)|N|Verifies the block chain database.|
**5.2 Method Details**
@@ -352,6 +353,18 @@ the method name for further details such as parameter and return information.
|Example Return|`{`
`"version": 70000`
`"protocolversion": 70001, `
`"blocks": 298963,`
`"timeoffset": 0,`
`"connections": 17,`
`"proxy": "",`
`"difficulty": 8000872135.97,`
`"testnet": false,`
`"relayfee": 0.00001,`
`}`|
[Return to Overview](#MethodOverview)
+***
+
+
+| | |
+|---|---|
+|Method|getmempoolinfo|
+|Parameters|None|
+|Description|Returns a JSON object containing mempool-related information.|
+|Returns|`{ (json object)`
`"bytes": n, (numeric) size in bytes of the mempool`
`"size": n, (numeric) number of transactions in the mempool`
`}`|
+Example Return|`{`
`"bytes": 310768,`
`"size": 157,`
`}`|
+[Return to Overview](#MethodOverview)
+
***
diff --git a/rpcserver.go b/rpcserver.go
index 797eadef..58fcf657 100644
--- a/rpcserver.go
+++ b/rpcserver.go
@@ -146,6 +146,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{
"getgenerate": handleGetGenerate,
"gethashespersec": handleGetHashesPerSec,
"getinfo": handleGetInfo,
+ "getmempoolinfo": handleGetMempoolInfo,
"getmininginfo": handleGetMiningInfo,
"getnettotals": handleGetNetTotals,
"getnetworkhashps": handleGetNetworkHashPS,
@@ -1938,6 +1939,23 @@ func handleGetInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (in
return ret, nil
}
+// handleGetMempoolInfo implements the getmempoolinfo command.
+func handleGetMempoolInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
+ txD := s.server.txMemPool.TxDescs()
+
+ var numBytes int64
+ for _, desc := range txD {
+ numBytes += int64(desc.Tx.MsgTx().SerializeSize())
+ }
+
+ ret := &btcjson.GetMempoolInfoResult{
+ Size: int64(len(txD)),
+ Bytes: numBytes,
+ }
+
+ return ret, nil
+}
+
// handleGetMiningInfo implements the getmininginfo command. We only return the
// fields that are not related to wallet functionality.
func handleGetMiningInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
diff --git a/rpcserverhelp.go b/rpcserverhelp.go
index f14250e0..4f44b8e9 100644
--- a/rpcserverhelp.go
+++ b/rpcserverhelp.go
@@ -288,6 +288,13 @@ var helpDescsEnUS = map[string]string{
// GetInfoCmd help.
"getinfo--synopsis": "Returns a JSON object containing various state info.",
+ // GetMempoolInfoCmd help.
+ "getmempoolinfo--synopsis": "Returns memory pool information",
+
+ // GetMempoolInfoResult help.
+ "getmempoolinforesult-bytes": "Size in bytes of the mempool",
+ "getmempoolinforesult-size": "Number of transactions in the mempool",
+
// GetMiningInfoResult help.
"getmininginforesult-blocks": "Height of the latest best block",
"getmininginforesult-currentblocksize": "Size of the latest best block",
@@ -540,6 +547,7 @@ var rpcResultTypes = map[string][]interface{}{
"getgenerate": []interface{}{(*bool)(nil)},
"gethashespersec": []interface{}{(*float64)(nil)},
"getinfo": []interface{}{(*btcjson.InfoChainResult)(nil)},
+ "getmempoolinfo": []interface{}{(*btcjson.GetMempoolInfoResult)(nil)},
"getmininginfo": []interface{}{(*btcjson.GetMiningInfoResult)(nil)},
"getnettotals": []interface{}{(*btcjson.GetNetTotalsResult)(nil)},
"getnetworkhashps": []interface{}{(*int64)(nil)},