/ vendor / github.com / btcsuite / btcd / rpcserverhelp.go
rpcserverhelp.go
  1  // Copyright (c) 2015-2017 The btcsuite developers
  2  // Copyright (c) 2015-2017 The Decred developers
  3  // Use of this source code is governed by an ISC
  4  // license that can be found in the LICENSE file.
  5  
  6  package main
  7  
  8  import (
  9  	"errors"
 10  	"sort"
 11  	"strings"
 12  	"sync"
 13  
 14  	"github.com/btcsuite/btcd/btcjson"
 15  )
 16  
 17  // helpDescsEnUS defines the English descriptions used for the help strings.
 18  var helpDescsEnUS = map[string]string{
 19  	// DebugLevelCmd help.
 20  	"debuglevel--synopsis": "Dynamically changes the debug logging level.\n" +
 21  		"The levelspec can either a debug level or of the form:\n" +
 22  		"<subsystem>=<level>,<subsystem2>=<level2>,...\n" +
 23  		"The valid debug levels are trace, debug, info, warn, error, and critical.\n" +
 24  		"The valid subsystems are AMGR, ADXR, BCDB, BMGR, BTCD, CHAN, DISC, PEER, RPCS, SCRP, SRVR, and TXMP.\n" +
 25  		"Finally the keyword 'show' will return a list of the available subsystems.",
 26  	"debuglevel-levelspec":   "The debug level(s) to use or the keyword 'show'",
 27  	"debuglevel--condition0": "levelspec!=show",
 28  	"debuglevel--condition1": "levelspec=show",
 29  	"debuglevel--result0":    "The string 'Done.'",
 30  	"debuglevel--result1":    "The list of subsystems",
 31  
 32  	// AddNodeCmd help.
 33  	"addnode--synopsis": "Attempts to add or remove a persistent peer.",
 34  	"addnode-addr":      "IP address and port of the peer to operate on",
 35  	"addnode-subcmd":    "'add' to add a persistent peer, 'remove' to remove a persistent peer, or 'onetry' to try a single connection to a peer",
 36  
 37  	// NodeCmd help.
 38  	"node--synopsis":     "Attempts to add or remove a peer.",
 39  	"node-subcmd":        "'disconnect' to remove all matching non-persistent peers, 'remove' to remove a persistent peer, or 'connect' to connect to a peer",
 40  	"node-target":        "Either the IP address and port of the peer to operate on, or a valid peer ID.",
 41  	"node-connectsubcmd": "'perm' to make the connected peer a permanent one, 'temp' to try a single connect to a peer",
 42  
 43  	// TransactionInput help.
 44  	"transactioninput-txid": "The hash of the input transaction",
 45  	"transactioninput-vout": "The specific output of the input transaction to redeem",
 46  
 47  	// CreateRawTransactionCmd help.
 48  	"createrawtransaction--synopsis": "Returns a new transaction spending the provided inputs and sending to the provided addresses.\n" +
 49  		"The transaction inputs are not signed in the created transaction.\n" +
 50  		"The signrawtransaction RPC command provided by wallet must be used to sign the resulting transaction.",
 51  	"createrawtransaction-inputs":         "The inputs to the transaction",
 52  	"createrawtransaction-amounts":        "JSON object with the destination addresses as keys and amounts as values",
 53  	"createrawtransaction-amounts--key":   "address",
 54  	"createrawtransaction-amounts--value": "n.nnn",
 55  	"createrawtransaction-amounts--desc":  "The destination address as the key and the amount in BTC as the value",
 56  	"createrawtransaction-locktime":       "Locktime value; a non-zero value will also locktime-activate the inputs",
 57  	"createrawtransaction--result0":       "Hex-encoded bytes of the serialized transaction",
 58  
 59  	// ScriptSig help.
 60  	"scriptsig-asm": "Disassembly of the script",
 61  	"scriptsig-hex": "Hex-encoded bytes of the script",
 62  
 63  	// PrevOut help.
 64  	"prevout-addresses": "previous output addresses",
 65  	"prevout-value":     "previous output value",
 66  
 67  	// VinPrevOut help.
 68  	"vinprevout-coinbase":    "The hex-encoded bytes of the signature script (coinbase txns only)",
 69  	"vinprevout-txid":        "The hash of the origin transaction (non-coinbase txns only)",
 70  	"vinprevout-vout":        "The index of the output being redeemed from the origin transaction (non-coinbase txns only)",
 71  	"vinprevout-scriptSig":   "The signature script used to redeem the origin transaction as a JSON object (non-coinbase txns only)",
 72  	"vinprevout-txinwitness": "The witness stack of the passed input, encoded as a JSON string array",
 73  	"vinprevout-prevOut":     "Data from the origin transaction output with index vout.",
 74  	"vinprevout-sequence":    "The script sequence number",
 75  
 76  	// Vin help.
 77  	"vin-coinbase":    "The hex-encoded bytes of the signature script (coinbase txns only)",
 78  	"vin-txid":        "The hash of the origin transaction (non-coinbase txns only)",
 79  	"vin-vout":        "The index of the output being redeemed from the origin transaction (non-coinbase txns only)",
 80  	"vin-scriptSig":   "The signature script used to redeem the origin transaction as a JSON object (non-coinbase txns only)",
 81  	"vin-txinwitness": "The witness used to redeem the input encoded as a string array of its items",
 82  	"vin-sequence":    "The script sequence number",
 83  
 84  	// ScriptPubKeyResult help.
 85  	"scriptpubkeyresult-asm":       "Disassembly of the script",
 86  	"scriptpubkeyresult-hex":       "Hex-encoded bytes of the script",
 87  	"scriptpubkeyresult-reqSigs":   "The number of required signatures",
 88  	"scriptpubkeyresult-type":      "The type of the script (e.g. 'pubkeyhash')",
 89  	"scriptpubkeyresult-addresses": "The bitcoin addresses associated with this script",
 90  
 91  	// Vout help.
 92  	"vout-value":        "The amount in BTC",
 93  	"vout-n":            "The index of this transaction output",
 94  	"vout-scriptPubKey": "The public key script used to pay coins as a JSON object",
 95  
 96  	// TxRawDecodeResult help.
 97  	"txrawdecoderesult-txid":     "The hash of the transaction",
 98  	"txrawdecoderesult-version":  "The transaction version",
 99  	"txrawdecoderesult-locktime": "The transaction lock time",
100  	"txrawdecoderesult-vin":      "The transaction inputs as JSON objects",
101  	"txrawdecoderesult-vout":     "The transaction outputs as JSON objects",
102  
103  	// DecodeRawTransactionCmd help.
104  	"decoderawtransaction--synopsis": "Returns a JSON object representing the provided serialized, hex-encoded transaction.",
105  	"decoderawtransaction-hextx":     "Serialized, hex-encoded transaction",
106  
107  	// DecodeScriptResult help.
108  	"decodescriptresult-asm":       "Disassembly of the script",
109  	"decodescriptresult-reqSigs":   "The number of required signatures",
110  	"decodescriptresult-type":      "The type of the script (e.g. 'pubkeyhash')",
111  	"decodescriptresult-addresses": "The bitcoin addresses associated with this script",
112  	"decodescriptresult-p2sh":      "The script hash for use in pay-to-script-hash transactions (only present if the provided redeem script is not already a pay-to-script-hash script)",
113  
114  	// DecodeScriptCmd help.
115  	"decodescript--synopsis": "Returns a JSON object with information about the provided hex-encoded script.",
116  	"decodescript-hexscript": "Hex-encoded script",
117  
118  	// GenerateCmd help
119  	"generate--synopsis": "Generates a set number of blocks (simnet or regtest only) and returns a JSON\n" +
120  		" array of their hashes.",
121  	"generate-numblocks": "Number of blocks to generate",
122  	"generate--result0":  "The hashes, in order, of blocks generated by the call",
123  
124  	// GetAddedNodeInfoResultAddr help.
125  	"getaddednodeinforesultaddr-address":   "The ip address for this DNS entry",
126  	"getaddednodeinforesultaddr-connected": "The connection 'direction' (inbound/outbound/false)",
127  
128  	// GetAddedNodeInfoResult help.
129  	"getaddednodeinforesult-addednode": "The ip address or domain of the added peer",
130  	"getaddednodeinforesult-connected": "Whether or not the peer is currently connected",
131  	"getaddednodeinforesult-addresses": "DNS lookup and connection information about the peer",
132  
133  	// GetAddedNodeInfo help.
134  	"getaddednodeinfo--synopsis":   "Returns information about manually added (persistent) peers.",
135  	"getaddednodeinfo-dns":         "Specifies whether the returned data is a JSON object including DNS and connection information, or just a list of added peers",
136  	"getaddednodeinfo-node":        "Only return information about this specific peer instead of all added peers",
137  	"getaddednodeinfo--condition0": "dns=false",
138  	"getaddednodeinfo--condition1": "dns=true",
139  	"getaddednodeinfo--result0":    "List of added peers",
140  
141  	// GetBestBlockResult help.
142  	"getbestblockresult-hash":   "Hex-encoded bytes of the best block hash",
143  	"getbestblockresult-height": "Height of the best block",
144  
145  	// GetBestBlockCmd help.
146  	"getbestblock--synopsis": "Get block height and hash of best block in the main chain.",
147  	"getbestblock--result0":  "Get block height and hash of best block in the main chain.",
148  
149  	// GetBestBlockHashCmd help.
150  	"getbestblockhash--synopsis": "Returns the hash of the of the best (most recent) block in the longest block chain.",
151  	"getbestblockhash--result0":  "The hex-encoded block hash",
152  
153  	// GetBlockCmd help.
154  	"getblock--synopsis":   "Returns information about a block given its hash.",
155  	"getblock-hash":        "The hash of the block",
156  	"getblock-verbose":     "Specifies the block is returned as a JSON object instead of hex-encoded string",
157  	"getblock-verbosetx":   "Specifies that each transaction is returned as a JSON object and only applies if the verbose flag is true (btcd extension)",
158  	"getblock--condition0": "verbose=false",
159  	"getblock--condition1": "verbose=true",
160  	"getblock--result0":    "Hex-encoded bytes of the serialized block",
161  
162  	// GetBlockChainInfoCmd help.
163  	"getblockchaininfo--synopsis": "Returns information about the current blockchain state and the status of any active soft-fork deployments.",
164  
165  	// GetBlockChainInfoResult help.
166  	"getblockchaininforesult-chain":                 "The name of the chain the daemon is on (testnet, mainnet, etc)",
167  	"getblockchaininforesult-blocks":                "The number of blocks in the best known chain",
168  	"getblockchaininforesult-headers":               "The number of headers that we've gathered for in the best known chain",
169  	"getblockchaininforesult-bestblockhash":         "The block hash for the latest block in the main chain",
170  	"getblockchaininforesult-difficulty":            "The current chain difficulty",
171  	"getblockchaininforesult-mediantime":            "The median time from the PoV of the best block in the chain",
172  	"getblockchaininforesult-verificationprogress":  "An estimate for how much of the best chain we've verified",
173  	"getblockchaininforesult-pruned":                "A bool that indicates if the node is pruned or not",
174  	"getblockchaininforesult-pruneheight":           "The lowest block retained in the current pruned chain",
175  	"getblockchaininforesult-chainwork":             "The total cumulative work in the best chain",
176  	"getblockchaininforesult-softforks":             "The status of the super-majority soft-forks",
177  	"getblockchaininforesult-bip9_softforks":        "JSON object describing active BIP0009 deployments",
178  	"getblockchaininforesult-bip9_softforks--key":   "bip9_softforks",
179  	"getblockchaininforesult-bip9_softforks--value": "An object describing a particular BIP009 deployment",
180  	"getblockchaininforesult-bip9_softforks--desc":  "The status of any defined BIP0009 soft-fork deployments",
181  
182  	// SoftForkDescription help.
183  	"softforkdescription-reject":  "The current activation status of the softfork",
184  	"softforkdescription-version": "The block version that signals enforcement of this softfork",
185  	"softforkdescription-id":      "The string identifier for the soft fork",
186  	"-status":                     "A bool which indicates if the soft fork is active",
187  
188  	// TxRawResult help.
189  	"txrawresult-hex":           "Hex-encoded transaction",
190  	"txrawresult-txid":          "The hash of the transaction",
191  	"txrawresult-version":       "The transaction version",
192  	"txrawresult-locktime":      "The transaction lock time",
193  	"txrawresult-vin":           "The transaction inputs as JSON objects",
194  	"txrawresult-vout":          "The transaction outputs as JSON objects",
195  	"txrawresult-blockhash":     "Hash of the block the transaction is part of",
196  	"txrawresult-confirmations": "Number of confirmations of the block",
197  	"txrawresult-time":          "Transaction time in seconds since 1 Jan 1970 GMT",
198  	"txrawresult-blocktime":     "Block time in seconds since the 1 Jan 1970 GMT",
199  	"txrawresult-size":          "The size of the transation in bytes",
200  	"txrawresult-vsize":         "The virtual size of the transaction in bytes",
201  	"txrawresult-hash":          "The wtxid of the transaction",
202  
203  	// SearchRawTransactionsResult help.
204  	"searchrawtransactionsresult-hex":           "Hex-encoded transaction",
205  	"searchrawtransactionsresult-txid":          "The hash of the transaction",
206  	"searchrawtransactionsresult-hash":          "The wxtid of the transaction",
207  	"searchrawtransactionsresult-version":       "The transaction version",
208  	"searchrawtransactionsresult-locktime":      "The transaction lock time",
209  	"searchrawtransactionsresult-vin":           "The transaction inputs as JSON objects",
210  	"searchrawtransactionsresult-vout":          "The transaction outputs as JSON objects",
211  	"searchrawtransactionsresult-blockhash":     "Hash of the block the transaction is part of",
212  	"searchrawtransactionsresult-confirmations": "Number of confirmations of the block",
213  	"searchrawtransactionsresult-time":          "Transaction time in seconds since 1 Jan 1970 GMT",
214  	"searchrawtransactionsresult-blocktime":     "Block time in seconds since the 1 Jan 1970 GMT",
215  	"searchrawtransactionsresult-size":          "The size of the transaction in bytes",
216  	"searchrawtransactionsresult-vsize":         "The virtual size of the transaction in bytes",
217  
218  	// GetBlockVerboseResult help.
219  	"getblockverboseresult-hash":              "The hash of the block (same as provided)",
220  	"getblockverboseresult-confirmations":     "The number of confirmations",
221  	"getblockverboseresult-size":              "The size of the block",
222  	"getblockverboseresult-height":            "The height of the block in the block chain",
223  	"getblockverboseresult-version":           "The block version",
224  	"getblockverboseresult-versionHex":        "The block version in hexidecimal",
225  	"getblockverboseresult-merkleroot":        "Root hash of the merkle tree",
226  	"getblockverboseresult-tx":                "The transaction hashes (only when verbosetx=false)",
227  	"getblockverboseresult-rawtx":             "The transactions as JSON objects (only when verbosetx=true)",
228  	"getblockverboseresult-time":              "The block time in seconds since 1 Jan 1970 GMT",
229  	"getblockverboseresult-nonce":             "The block nonce",
230  	"getblockverboseresult-bits":              "The bits which represent the block difficulty",
231  	"getblockverboseresult-difficulty":        "The proof-of-work difficulty as a multiple of the minimum difficulty",
232  	"getblockverboseresult-previousblockhash": "The hash of the previous block",
233  	"getblockverboseresult-nextblockhash":     "The hash of the next block (only if there is one)",
234  	"getblockverboseresult-strippedsize":      "The size of the block without witness data",
235  	"getblockverboseresult-weight":            "The weight of the block",
236  
237  	// GetBlockCountCmd help.
238  	"getblockcount--synopsis": "Returns the number of blocks in the longest block chain.",
239  	"getblockcount--result0":  "The current block count",
240  
241  	// GetBlockHashCmd help.
242  	"getblockhash--synopsis": "Returns hash of the block in best block chain at the given height.",
243  	"getblockhash-index":     "The block height",
244  	"getblockhash--result0":  "The block hash",
245  
246  	// GetBlockHeaderCmd help.
247  	"getblockheader--synopsis":   "Returns information about a block header given its hash.",
248  	"getblockheader-hash":        "The hash of the block",
249  	"getblockheader-verbose":     "Specifies the block header is returned as a JSON object instead of hex-encoded string",
250  	"getblockheader--condition0": "verbose=false",
251  	"getblockheader--condition1": "verbose=true",
252  	"getblockheader--result0":    "The block header hash",
253  
254  	// GetBlockHeaderVerboseResult help.
255  	"getblockheaderverboseresult-hash":              "The hash of the block (same as provided)",
256  	"getblockheaderverboseresult-confirmations":     "The number of confirmations",
257  	"getblockheaderverboseresult-height":            "The height of the block in the block chain",
258  	"getblockheaderverboseresult-version":           "The block version",
259  	"getblockheaderverboseresult-versionHex":        "The block version in hexidecimal",
260  	"getblockheaderverboseresult-merkleroot":        "Root hash of the merkle tree",
261  	"getblockheaderverboseresult-time":              "The block time in seconds since 1 Jan 1970 GMT",
262  	"getblockheaderverboseresult-nonce":             "The block nonce",
263  	"getblockheaderverboseresult-bits":              "The bits which represent the block difficulty",
264  	"getblockheaderverboseresult-difficulty":        "The proof-of-work difficulty as a multiple of the minimum difficulty",
265  	"getblockheaderverboseresult-previousblockhash": "The hash of the previous block",
266  	"getblockheaderverboseresult-nextblockhash":     "The hash of the next block (only if there is one)",
267  
268  	// TemplateRequest help.
269  	"templaterequest-mode":         "This is 'template', 'proposal', or omitted",
270  	"templaterequest-capabilities": "List of capabilities",
271  	"templaterequest-longpollid":   "The long poll ID of a job to monitor for expiration; required and valid only for long poll requests ",
272  	"templaterequest-sigoplimit":   "Number of signature operations allowed in blocks (this parameter is ignored)",
273  	"templaterequest-sizelimit":    "Number of bytes allowed in blocks (this parameter is ignored)",
274  	"templaterequest-maxversion":   "Highest supported block version number (this parameter is ignored)",
275  	"templaterequest-target":       "The desired target for the block template (this parameter is ignored)",
276  	"templaterequest-data":         "Hex-encoded block data (only for mode=proposal)",
277  	"templaterequest-workid":       "The server provided workid if provided in block template (not applicable)",
278  
279  	// GetBlockTemplateResultTx help.
280  	"getblocktemplateresulttx-data":    "Hex-encoded transaction data (byte-for-byte)",
281  	"getblocktemplateresulttx-hash":    "Hex-encoded transaction hash (little endian if treated as a 256-bit number)",
282  	"getblocktemplateresulttx-depends": "Other transactions before this one (by 1-based index in the 'transactions'  list) that must be present in the final block if this one is",
283  	"getblocktemplateresulttx-fee":     "Difference in value between transaction inputs and outputs (in Satoshi)",
284  	"getblocktemplateresulttx-sigops":  "Total number of signature operations as counted for purposes of block limits",
285  	"getblocktemplateresulttx-weight":  "The weight of the transaction",
286  
287  	// GetBlockTemplateResultAux help.
288  	"getblocktemplateresultaux-flags": "Hex-encoded byte-for-byte data to include in the coinbase signature script",
289  
290  	// GetBlockTemplateResult help.
291  	"getblocktemplateresult-bits":                       "Hex-encoded compressed difficulty",
292  	"getblocktemplateresult-curtime":                    "Current time as seen by the server (recommended for block time); must fall within mintime/maxtime rules",
293  	"getblocktemplateresult-height":                     "Height of the block to be solved",
294  	"getblocktemplateresult-previousblockhash":          "Hex-encoded big-endian hash of the previous block",
295  	"getblocktemplateresult-sigoplimit":                 "Number of sigops allowed in blocks ",
296  	"getblocktemplateresult-sizelimit":                  "Number of bytes allowed in blocks",
297  	"getblocktemplateresult-transactions":               "Array of transactions as JSON objects",
298  	"getblocktemplateresult-version":                    "The block version",
299  	"getblocktemplateresult-coinbaseaux":                "Data that should be included in the coinbase signature script",
300  	"getblocktemplateresult-coinbasetxn":                "Information about the coinbase transaction",
301  	"getblocktemplateresult-coinbasevalue":              "Total amount available for the coinbase in Satoshi",
302  	"getblocktemplateresult-workid":                     "This value must be returned with result if provided (not provided)",
303  	"getblocktemplateresult-longpollid":                 "Identifier for long poll request which allows monitoring for expiration",
304  	"getblocktemplateresult-longpolluri":                "An alternate URI to use for long poll requests if provided (not provided)",
305  	"getblocktemplateresult-submitold":                  "Not applicable",
306  	"getblocktemplateresult-target":                     "Hex-encoded big-endian number which valid results must be less than",
307  	"getblocktemplateresult-expires":                    "Maximum number of seconds (starting from when the server sent the response) this work is valid for",
308  	"getblocktemplateresult-maxtime":                    "Maximum allowed time",
309  	"getblocktemplateresult-mintime":                    "Minimum allowed time",
310  	"getblocktemplateresult-mutable":                    "List of mutations the server explicitly allows",
311  	"getblocktemplateresult-noncerange":                 "Two concatenated hex-encoded big-endian 32-bit integers which represent the valid ranges of nonces the miner may scan",
312  	"getblocktemplateresult-capabilities":               "List of server capabilities including 'proposal' to indicate support for block proposals",
313  	"getblocktemplateresult-reject-reason":              "Reason the proposal was invalid as-is (only applies to proposal responses)",
314  	"getblocktemplateresult-default_witness_commitment": "The witness commitment itself. Will be populated if the block has witness data",
315  	"getblocktemplateresult-weightlimit":                "The current limit on the max allowed weight of a block",
316  
317  	// GetBlockTemplateCmd help.
318  	"getblocktemplate--synopsis": "Returns a JSON object with information necessary to construct a block to mine or accepts a proposal to validate.\n" +
319  		"See BIP0022 and BIP0023 for the full specification.",
320  	"getblocktemplate-request":     "Request object which controls the mode and several parameters",
321  	"getblocktemplate--condition0": "mode=template",
322  	"getblocktemplate--condition1": "mode=proposal, rejected",
323  	"getblocktemplate--condition2": "mode=proposal, accepted",
324  	"getblocktemplate--result1":    "An error string which represents why the proposal was rejected or nothing if accepted",
325  
326  	// GetConnectionCountCmd help.
327  	"getconnectioncount--synopsis": "Returns the number of active connections to other peers.",
328  	"getconnectioncount--result0":  "The number of connections",
329  
330  	// GetCurrentNetCmd help.
331  	"getcurrentnet--synopsis": "Get bitcoin network the server is running on.",
332  	"getcurrentnet--result0":  "The network identifer",
333  
334  	// GetDifficultyCmd help.
335  	"getdifficulty--synopsis": "Returns the proof-of-work difficulty as a multiple of the minimum difficulty.",
336  	"getdifficulty--result0":  "The difficulty",
337  
338  	// GetGenerateCmd help.
339  	"getgenerate--synopsis": "Returns if the server is set to generate coins (mine) or not.",
340  	"getgenerate--result0":  "True if mining, false if not",
341  
342  	// GetHashesPerSecCmd help.
343  	"gethashespersec--synopsis": "Returns a recent hashes per second performance measurement while generating coins (mining).",
344  	"gethashespersec--result0":  "The number of hashes per second",
345  
346  	// InfoChainResult help.
347  	"infochainresult-version":         "The version of the server",
348  	"infochainresult-protocolversion": "The latest supported protocol version",
349  	"infochainresult-blocks":          "The number of blocks processed",
350  	"infochainresult-timeoffset":      "The time offset",
351  	"infochainresult-connections":     "The number of connected peers",
352  	"infochainresult-proxy":           "The proxy used by the server",
353  	"infochainresult-difficulty":      "The current target difficulty",
354  	"infochainresult-testnet":         "Whether or not server is using testnet",
355  	"infochainresult-relayfee":        "The minimum relay fee for non-free transactions in BTC/KB",
356  	"infochainresult-errors":          "Any current errors",
357  
358  	// InfoWalletResult help.
359  	"infowalletresult-version":         "The version of the server",
360  	"infowalletresult-protocolversion": "The latest supported protocol version",
361  	"infowalletresult-walletversion":   "The version of the wallet server",
362  	"infowalletresult-balance":         "The total bitcoin balance of the wallet",
363  	"infowalletresult-blocks":          "The number of blocks processed",
364  	"infowalletresult-timeoffset":      "The time offset",
365  	"infowalletresult-connections":     "The number of connected peers",
366  	"infowalletresult-proxy":           "The proxy used by the server",
367  	"infowalletresult-difficulty":      "The current target difficulty",
368  	"infowalletresult-testnet":         "Whether or not server is using testnet",
369  	"infowalletresult-keypoololdest":   "Seconds since 1 Jan 1970 GMT of the oldest pre-generated key in the key pool",
370  	"infowalletresult-keypoolsize":     "The number of new keys that are pre-generated",
371  	"infowalletresult-unlocked_until":  "The timestamp in seconds since 1 Jan 1970 GMT that the wallet is unlocked for transfers, or 0 if the wallet is locked",
372  	"infowalletresult-paytxfee":        "The transaction fee set in BTC/KB",
373  	"infowalletresult-relayfee":        "The minimum relay fee for non-free transactions in BTC/KB",
374  	"infowalletresult-errors":          "Any current errors",
375  
376  	// GetHeadersCmd help.
377  	"getheaders--synopsis":     "Returns block headers starting with the first known block hash from the request",
378  	"getheaders-blocklocators": "JSON array of hex-encoded hashes of blocks.  Headers are returned starting from the first known hash in this list",
379  	"getheaders-hashstop":      "Block hash to stop including block headers for; if not found, all headers to the latest known block are returned.",
380  	"getheaders--result0":      "Serialized block headers of all located blocks, limited to some arbitrary maximum number of hashes (currently 2000, which matches the wire protocol headers message, but this is not guaranteed)",
381  
382  	// GetInfoCmd help.
383  	"getinfo--synopsis": "Returns a JSON object containing various state info.",
384  
385  	// GetMempoolInfoCmd help.
386  	"getmempoolinfo--synopsis": "Returns memory pool information",
387  
388  	// GetMempoolInfoResult help.
389  	"getmempoolinforesult-bytes": "Size in bytes of the mempool",
390  	"getmempoolinforesult-size":  "Number of transactions in the mempool",
391  
392  	// GetMiningInfoResult help.
393  	"getmininginforesult-blocks":             "Height of the latest best block",
394  	"getmininginforesult-currentblocksize":   "Size of the latest best block",
395  	"getmininginforesult-currentblockweight": "Weight of the latest best block",
396  	"getmininginforesult-currentblocktx":     "Number of transactions in the latest best block",
397  	"getmininginforesult-difficulty":         "Current target difficulty",
398  	"getmininginforesult-errors":             "Any current errors",
399  	"getmininginforesult-generate":           "Whether or not server is set to generate coins",
400  	"getmininginforesult-genproclimit":       "Number of processors to use for coin generation (-1 when disabled)",
401  	"getmininginforesult-hashespersec":       "Recent hashes per second performance measurement while generating coins",
402  	"getmininginforesult-networkhashps":      "Estimated network hashes per second for the most recent blocks",
403  	"getmininginforesult-pooledtx":           "Number of transactions in the memory pool",
404  	"getmininginforesult-testnet":            "Whether or not server is using testnet",
405  
406  	// GetMiningInfoCmd help.
407  	"getmininginfo--synopsis": "Returns a JSON object containing mining-related information.",
408  
409  	// GetNetworkHashPSCmd help.
410  	"getnetworkhashps--synopsis": "Returns the estimated network hashes per second for the block heights provided by the parameters.",
411  	"getnetworkhashps-blocks":    "The number of blocks, or -1 for blocks since last difficulty change",
412  	"getnetworkhashps-height":    "Perform estimate ending with this height or -1 for current best chain block height",
413  	"getnetworkhashps--result0":  "Estimated hashes per second",
414  
415  	// GetNetTotalsCmd help.
416  	"getnettotals--synopsis": "Returns a JSON object containing network traffic statistics.",
417  
418  	// GetNetTotalsResult help.
419  	"getnettotalsresult-totalbytesrecv": "Total bytes received",
420  	"getnettotalsresult-totalbytessent": "Total bytes sent",
421  	"getnettotalsresult-timemillis":     "Number of milliseconds since 1 Jan 1970 GMT",
422  
423  	// GetPeerInfoResult help.
424  	"getpeerinforesult-id":             "A unique node ID",
425  	"getpeerinforesult-addr":           "The ip address and port of the peer",
426  	"getpeerinforesult-addrlocal":      "Local address",
427  	"getpeerinforesult-services":       "Services bitmask which represents the services supported by the peer",
428  	"getpeerinforesult-relaytxes":      "Peer has requested transactions be relayed to it",
429  	"getpeerinforesult-lastsend":       "Time the last message was received in seconds since 1 Jan 1970 GMT",
430  	"getpeerinforesult-lastrecv":       "Time the last message was sent in seconds since 1 Jan 1970 GMT",
431  	"getpeerinforesult-bytessent":      "Total bytes sent",
432  	"getpeerinforesult-bytesrecv":      "Total bytes received",
433  	"getpeerinforesult-conntime":       "Time the connection was made in seconds since 1 Jan 1970 GMT",
434  	"getpeerinforesult-timeoffset":     "The time offset of the peer",
435  	"getpeerinforesult-pingtime":       "Number of microseconds the last ping took",
436  	"getpeerinforesult-pingwait":       "Number of microseconds a queued ping has been waiting for a response",
437  	"getpeerinforesult-version":        "The protocol version of the peer",
438  	"getpeerinforesult-subver":         "The user agent of the peer",
439  	"getpeerinforesult-inbound":        "Whether or not the peer is an inbound connection",
440  	"getpeerinforesult-startingheight": "The latest block height the peer knew about when the connection was established",
441  	"getpeerinforesult-currentheight":  "The current height of the peer",
442  	"getpeerinforesult-banscore":       "The ban score",
443  	"getpeerinforesult-feefilter":      "The requested minimum fee a transaction must have to be announced to the peer",
444  	"getpeerinforesult-syncnode":       "Whether or not the peer is the sync peer",
445  
446  	// GetPeerInfoCmd help.
447  	"getpeerinfo--synopsis": "Returns data about each connected network peer as an array of json objects.",
448  
449  	// GetRawMempoolVerboseResult help.
450  	"getrawmempoolverboseresult-size":             "Transaction size in bytes",
451  	"getrawmempoolverboseresult-fee":              "Transaction fee in bitcoins",
452  	"getrawmempoolverboseresult-time":             "Local time transaction entered pool in seconds since 1 Jan 1970 GMT",
453  	"getrawmempoolverboseresult-height":           "Block height when transaction entered the pool",
454  	"getrawmempoolverboseresult-startingpriority": "Priority when transaction entered the pool",
455  	"getrawmempoolverboseresult-currentpriority":  "Current priority",
456  	"getrawmempoolverboseresult-depends":          "Unconfirmed transactions used as inputs for this transaction",
457  	"getrawmempoolverboseresult-vsize":            "The virtual size of a transaction",
458  
459  	// GetRawMempoolCmd help.
460  	"getrawmempool--synopsis":   "Returns information about all of the transactions currently in the memory pool.",
461  	"getrawmempool-verbose":     "Returns JSON object when true or an array of transaction hashes when false",
462  	"getrawmempool--condition0": "verbose=false",
463  	"getrawmempool--condition1": "verbose=true",
464  	"getrawmempool--result0":    "Array of transaction hashes",
465  
466  	// GetRawTransactionCmd help.
467  	"getrawtransaction--synopsis":   "Returns information about a transaction given its hash.",
468  	"getrawtransaction-txid":        "The hash of the transaction",
469  	"getrawtransaction-verbose":     "Specifies the transaction is returned as a JSON object instead of a hex-encoded string",
470  	"getrawtransaction--condition0": "verbose=false",
471  	"getrawtransaction--condition1": "verbose=true",
472  	"getrawtransaction--result0":    "Hex-encoded bytes of the serialized transaction",
473  
474  	// GetTxOutResult help.
475  	"gettxoutresult-bestblock":     "The block hash that contains the transaction output",
476  	"gettxoutresult-confirmations": "The number of confirmations",
477  	"gettxoutresult-value":         "The transaction amount in BTC",
478  	"gettxoutresult-scriptPubKey":  "The public key script used to pay coins as a JSON object",
479  	"gettxoutresult-version":       "The transaction version",
480  	"gettxoutresult-coinbase":      "Whether or not the transaction is a coinbase",
481  
482  	// GetTxOutCmd help.
483  	"gettxout--synopsis":      "Returns information about an unspent transaction output..",
484  	"gettxout-txid":           "The hash of the transaction",
485  	"gettxout-vout":           "The index of the output",
486  	"gettxout-includemempool": "Include the mempool when true",
487  
488  	// HelpCmd help.
489  	"help--synopsis":   "Returns a list of all commands or help for a specified command.",
490  	"help-command":     "The command to retrieve help for",
491  	"help--condition0": "no command provided",
492  	"help--condition1": "command specified",
493  	"help--result0":    "List of commands",
494  	"help--result1":    "Help for specified command",
495  
496  	// PingCmd help.
497  	"ping--synopsis": "Queues a ping to be sent to each connected peer.\n" +
498  		"Ping times are provided by getpeerinfo via the pingtime and pingwait fields.",
499  
500  	// SearchRawTransactionsCmd help.
501  	"searchrawtransactions--synopsis": "Returns raw data for transactions involving the passed address.\n" +
502  		"Returned transactions are pulled from both the database, and transactions currently in the mempool.\n" +
503  		"Transactions pulled from the mempool will have the 'confirmations' field set to 0.\n" +
504  		"Usage of this RPC requires the optional --addrindex flag to be activated, otherwise all responses will simply return with an error stating the address index has not yet been built.\n" +
505  		"Similarly, until the address index has caught up with the current best height, all requests will return an error response in order to avoid serving stale data.",
506  	"searchrawtransactions-address":     "The Bitcoin address to search for",
507  	"searchrawtransactions-verbose":     "Specifies the transaction is returned as a JSON object instead of hex-encoded string",
508  	"searchrawtransactions--condition0": "verbose=0",
509  	"searchrawtransactions--condition1": "verbose=1",
510  	"searchrawtransactions-skip":        "The number of leading transactions to leave out of the final response",
511  	"searchrawtransactions-count":       "The maximum number of transactions to return",
512  	"searchrawtransactions-vinextra":    "Specify that extra data from previous output will be returned in vin",
513  	"searchrawtransactions-reverse":     "Specifies that the transactions should be returned in reverse chronological order",
514  	"searchrawtransactions-filteraddrs": "Address list.  Only inputs or outputs with matching address will be returned",
515  	"searchrawtransactions--result0":    "Hex-encoded serialized transaction",
516  
517  	// SendRawTransactionCmd help.
518  	"sendrawtransaction--synopsis":     "Submits the serialized, hex-encoded transaction to the local peer and relays it to the network.",
519  	"sendrawtransaction-hextx":         "Serialized, hex-encoded signed transaction",
520  	"sendrawtransaction-allowhighfees": "Whether or not to allow insanely high fees (btcd does not yet implement this parameter, so it has no effect)",
521  	"sendrawtransaction--result0":      "The hash of the transaction",
522  
523  	// SetGenerateCmd help.
524  	"setgenerate--synopsis":    "Set the server to generate coins (mine) or not.",
525  	"setgenerate-generate":     "Use true to enable generation, false to disable it",
526  	"setgenerate-genproclimit": "The number of processors (cores) to limit generation to or -1 for default",
527  
528  	// StopCmd help.
529  	"stop--synopsis": "Shutdown btcd.",
530  	"stop--result0":  "The string 'btcd stopping.'",
531  
532  	// SubmitBlockOptions help.
533  	"submitblockoptions-workid": "This parameter is currently ignored",
534  
535  	// SubmitBlockCmd help.
536  	"submitblock--synopsis":   "Attempts to submit a new serialized, hex-encoded block to the network.",
537  	"submitblock-hexblock":    "Serialized, hex-encoded block",
538  	"submitblock-options":     "This parameter is currently ignored",
539  	"submitblock--condition0": "Block successfully submitted",
540  	"submitblock--condition1": "Block rejected",
541  	"submitblock--result1":    "The reason the block was rejected",
542  
543  	// ValidateAddressResult help.
544  	"validateaddresschainresult-isvalid": "Whether or not the address is valid",
545  	"validateaddresschainresult-address": "The bitcoin address (only when isvalid is true)",
546  
547  	// ValidateAddressCmd help.
548  	"validateaddress--synopsis": "Verify an address is valid.",
549  	"validateaddress-address":   "Bitcoin address to validate",
550  
551  	// VerifyChainCmd help.
552  	"verifychain--synopsis": "Verifies the block chain database.\n" +
553  		"The actual checks performed by the checklevel parameter are implementation specific.\n" +
554  		"For btcd this is:\n" +
555  		"checklevel=0 - Look up each block and ensure it can be loaded from the database.\n" +
556  		"checklevel=1 - Perform basic context-free sanity checks on each block.",
557  	"verifychain-checklevel": "How thorough the block verification is",
558  	"verifychain-checkdepth": "The number of blocks to check",
559  	"verifychain--result0":   "Whether or not the chain verified",
560  
561  	// VerifyMessageCmd help.
562  	"verifymessage--synopsis": "Verify a signed message.",
563  	"verifymessage-address":   "The bitcoin address to use for the signature",
564  	"verifymessage-signature": "The base-64 encoded signature provided by the signer",
565  	"verifymessage-message":   "The signed message",
566  	"verifymessage--result0":  "Whether or not the signature verified",
567  
568  	// -------- Websocket-specific help --------
569  
570  	// Session help.
571  	"session--synopsis":       "Return details regarding a websocket client's current connection session.",
572  	"sessionresult-sessionid": "The unique session ID for a client's websocket connection.",
573  
574  	// NotifyBlocksCmd help.
575  	"notifyblocks--synopsis": "Request notifications for whenever a block is connected or disconnected from the main (best) chain.",
576  
577  	// StopNotifyBlocksCmd help.
578  	"stopnotifyblocks--synopsis": "Cancel registered notifications for whenever a block is connected or disconnected from the main (best) chain.",
579  
580  	// NotifyNewTransactionsCmd help.
581  	"notifynewtransactions--synopsis": "Send either a txaccepted or a txacceptedverbose notification when a new transaction is accepted into the mempool.",
582  	"notifynewtransactions-verbose":   "Specifies which type of notification to receive. If verbose is true, then the caller receives txacceptedverbose, otherwise the caller receives txaccepted",
583  
584  	// StopNotifyNewTransactionsCmd help.
585  	"stopnotifynewtransactions--synopsis": "Stop sending either a txaccepted or a txacceptedverbose notification when a new transaction is accepted into the mempool.",
586  
587  	// NotifyReceivedCmd help.
588  	"notifyreceived--synopsis": "Send a recvtx notification when a transaction added to mempool or appears in a newly-attached block contains a txout pkScript sending to any of the passed addresses.\n" +
589  		"Matching outpoints are automatically registered for redeemingtx notifications.",
590  	"notifyreceived-addresses": "List of address to receive notifications about",
591  
592  	// StopNotifyReceivedCmd help.
593  	"stopnotifyreceived--synopsis": "Cancel registered receive notifications for each passed address.",
594  	"stopnotifyreceived-addresses": "List of address to cancel receive notifications for",
595  
596  	// OutPoint help.
597  	"outpoint-hash":  "The hex-encoded bytes of the outpoint hash",
598  	"outpoint-index": "The index of the outpoint",
599  
600  	// NotifySpentCmd help.
601  	"notifyspent--synopsis": "Send a redeemingtx notification when a transaction spending an outpoint appears in mempool (if relayed to this btcd instance) and when such a transaction first appears in a newly-attached block.",
602  	"notifyspent-outpoints": "List of transaction outpoints to monitor.",
603  
604  	// StopNotifySpentCmd help.
605  	"stopnotifyspent--synopsis": "Cancel registered spending notifications for each passed outpoint.",
606  	"stopnotifyspent-outpoints": "List of transaction outpoints to stop monitoring.",
607  
608  	// LoadTxFilterCmd help.
609  	"loadtxfilter--synopsis": "Load, add to, or reload a websocket client's transaction filter for mempool transactions, new blocks and rescanblocks.",
610  	"loadtxfilter-reload":    "Load a new filter instead of adding data to an existing one",
611  	"loadtxfilter-addresses": "Array of addresses to add to the transaction filter",
612  	"loadtxfilter-outpoints": "Array of outpoints to add to the transaction filter",
613  
614  	// Rescan help.
615  	"rescan--synopsis": "Rescan block chain for transactions to addresses.\n" +
616  		"When the endblock parameter is omitted, the rescan continues through the best block in the main chain.\n" +
617  		"Rescan results are sent as recvtx and redeemingtx notifications.\n" +
618  		"This call returns once the rescan completes.",
619  	"rescan-beginblock": "Hash of the first block to begin rescanning",
620  	"rescan-addresses":  "List of addresses to include in the rescan",
621  	"rescan-outpoints":  "List of transaction outpoints to include in the rescan",
622  	"rescan-endblock":   "Hash of final block to rescan",
623  
624  	// RescanBlocks help.
625  	"rescanblocks--synopsis":   "Rescan blocks for transactions matching the loaded transaction filter.",
626  	"rescanblocks-blockhashes": "List of hashes to rescan.  Each next block must be a child of the previous.",
627  	"rescanblocks--result0":    "List of matching blocks.",
628  
629  	// RescannedBlock help.
630  	"rescannedblock-hash":         "Hash of the matching block.",
631  	"rescannedblock-transactions": "List of matching transactions, serialized and hex-encoded.",
632  
633  	// Uptime help.
634  	"uptime--synopsis": "Returns the total uptime of the server.",
635  	"uptime--result0":  "The number of seconds that the server has been running",
636  
637  	// Version help.
638  	"version--synopsis":       "Returns the JSON-RPC API version (semver)",
639  	"version--result0--desc":  "Version objects keyed by the program or API name",
640  	"version--result0--key":   "Program or API name",
641  	"version--result0--value": "Object containing the semantic version",
642  
643  	// VersionResult help.
644  	"versionresult-versionstring": "The JSON-RPC API version (semver)",
645  	"versionresult-major":         "The major component of the JSON-RPC API version",
646  	"versionresult-minor":         "The minor component of the JSON-RPC API version",
647  	"versionresult-patch":         "The patch component of the JSON-RPC API version",
648  	"versionresult-prerelease":    "Prerelease info about the current build",
649  	"versionresult-buildmetadata": "Metadata about the current build",
650  }
651  
652  // rpcResultTypes specifies the result types that each RPC command can return.
653  // This information is used to generate the help.  Each result type must be a
654  // pointer to the type (or nil to indicate no return value).
655  var rpcResultTypes = map[string][]interface{}{
656  	"addnode":               nil,
657  	"createrawtransaction":  {(*string)(nil)},
658  	"debuglevel":            {(*string)(nil), (*string)(nil)},
659  	"decoderawtransaction":  {(*btcjson.TxRawDecodeResult)(nil)},
660  	"decodescript":          {(*btcjson.DecodeScriptResult)(nil)},
661  	"generate":              {(*[]string)(nil)},
662  	"getaddednodeinfo":      {(*[]string)(nil), (*[]btcjson.GetAddedNodeInfoResult)(nil)},
663  	"getbestblock":          {(*btcjson.GetBestBlockResult)(nil)},
664  	"getbestblockhash":      {(*string)(nil)},
665  	"getblock":              {(*string)(nil), (*btcjson.GetBlockVerboseResult)(nil)},
666  	"getblockcount":         {(*int64)(nil)},
667  	"getblockhash":          {(*string)(nil)},
668  	"getblockheader":        {(*string)(nil), (*btcjson.GetBlockHeaderVerboseResult)(nil)},
669  	"getblocktemplate":      {(*btcjson.GetBlockTemplateResult)(nil), (*string)(nil), nil},
670  	"getblockchaininfo":     {(*btcjson.GetBlockChainInfoResult)(nil)},
671  	"getconnectioncount":    {(*int32)(nil)},
672  	"getcurrentnet":         {(*uint32)(nil)},
673  	"getdifficulty":         {(*float64)(nil)},
674  	"getgenerate":           {(*bool)(nil)},
675  	"gethashespersec":       {(*float64)(nil)},
676  	"getheaders":            {(*[]string)(nil)},
677  	"getinfo":               {(*btcjson.InfoChainResult)(nil)},
678  	"getmempoolinfo":        {(*btcjson.GetMempoolInfoResult)(nil)},
679  	"getmininginfo":         {(*btcjson.GetMiningInfoResult)(nil)},
680  	"getnettotals":          {(*btcjson.GetNetTotalsResult)(nil)},
681  	"getnetworkhashps":      {(*int64)(nil)},
682  	"getpeerinfo":           {(*[]btcjson.GetPeerInfoResult)(nil)},
683  	"getrawmempool":         {(*[]string)(nil), (*btcjson.GetRawMempoolVerboseResult)(nil)},
684  	"getrawtransaction":     {(*string)(nil), (*btcjson.TxRawResult)(nil)},
685  	"gettxout":              {(*btcjson.GetTxOutResult)(nil)},
686  	"node":                  nil,
687  	"help":                  {(*string)(nil), (*string)(nil)},
688  	"ping":                  nil,
689  	"searchrawtransactions": {(*string)(nil), (*[]btcjson.SearchRawTransactionsResult)(nil)},
690  	"sendrawtransaction":    {(*string)(nil)},
691  	"setgenerate":           nil,
692  	"stop":                  {(*string)(nil)},
693  	"submitblock":           {nil, (*string)(nil)},
694  	"uptime":                {(*int64)(nil)},
695  	"validateaddress":       {(*btcjson.ValidateAddressChainResult)(nil)},
696  	"verifychain":           {(*bool)(nil)},
697  	"verifymessage":         {(*bool)(nil)},
698  	"version":               {(*map[string]btcjson.VersionResult)(nil)},
699  
700  	// Websocket commands.
701  	"loadtxfilter":              nil,
702  	"session":                   {(*btcjson.SessionResult)(nil)},
703  	"notifyblocks":              nil,
704  	"stopnotifyblocks":          nil,
705  	"notifynewtransactions":     nil,
706  	"stopnotifynewtransactions": nil,
707  	"notifyreceived":            nil,
708  	"stopnotifyreceived":        nil,
709  	"notifyspent":               nil,
710  	"stopnotifyspent":           nil,
711  	"rescan":                    nil,
712  	"rescanblocks":              {(*[]btcjson.RescannedBlock)(nil)},
713  }
714  
715  // helpCacher provides a concurrent safe type that provides help and usage for
716  // the RPC server commands and caches the results for future calls.
717  type helpCacher struct {
718  	sync.Mutex
719  	usage      string
720  	methodHelp map[string]string
721  }
722  
723  // rpcMethodHelp returns an RPC help string for the provided method.
724  //
725  // This function is safe for concurrent access.
726  func (c *helpCacher) rpcMethodHelp(method string) (string, error) {
727  	c.Lock()
728  	defer c.Unlock()
729  
730  	// Return the cached method help if it exists.
731  	if help, exists := c.methodHelp[method]; exists {
732  		return help, nil
733  	}
734  
735  	// Look up the result types for the method.
736  	resultTypes, ok := rpcResultTypes[method]
737  	if !ok {
738  		return "", errors.New("no result types specified for method " +
739  			method)
740  	}
741  
742  	// Generate, cache, and return the help.
743  	help, err := btcjson.GenerateHelp(method, helpDescsEnUS, resultTypes...)
744  	if err != nil {
745  		return "", err
746  	}
747  	c.methodHelp[method] = help
748  	return help, nil
749  }
750  
751  // rpcUsage returns one-line usage for all support RPC commands.
752  //
753  // This function is safe for concurrent access.
754  func (c *helpCacher) rpcUsage(includeWebsockets bool) (string, error) {
755  	c.Lock()
756  	defer c.Unlock()
757  
758  	// Return the cached usage if it is available.
759  	if c.usage != "" {
760  		return c.usage, nil
761  	}
762  
763  	// Generate a list of one-line usage for every command.
764  	usageTexts := make([]string, 0, len(rpcHandlers))
765  	for k := range rpcHandlers {
766  		usage, err := btcjson.MethodUsageText(k)
767  		if err != nil {
768  			return "", err
769  		}
770  		usageTexts = append(usageTexts, usage)
771  	}
772  
773  	// Include websockets commands if requested.
774  	if includeWebsockets {
775  		for k := range wsHandlers {
776  			usage, err := btcjson.MethodUsageText(k)
777  			if err != nil {
778  				return "", err
779  			}
780  			usageTexts = append(usageTexts, usage)
781  		}
782  	}
783  
784  	sort.Sort(sort.StringSlice(usageTexts))
785  	c.usage = strings.Join(usageTexts, "\n")
786  	return c.usage, nil
787  }
788  
789  // newHelpCacher returns a new instance of a help cacher which provides help and
790  // usage for the RPC server commands and caches the results for future calls.
791  func newHelpCacher() *helpCacher {
792  	return &helpCacher{
793  		methodHelp: make(map[string]string),
794  	}
795  }