walletsvrcmds.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. // Copyright (c) 2014 The btcsuite developers
  2. // Copyright (c) 2019 Caleb James DeLisle
  3. // Use of this source code is governed by an ISC
  4. // license that can be found in the LICENSE file.
  5. // NOTE: This file is intended to house the RPC commands that are supported by
  6. // a wallet server.
  7. package btcjson
  8. // AddMultisigAddressCmd defines the addmutisigaddress JSON-RPC command.
  9. type AddMultisigAddressCmd struct {
  10. NRequired int
  11. Keys []string
  12. }
  13. type AddP2shScriptCmd struct {
  14. Script string
  15. Segwit bool
  16. }
  17. // AddWitnessAddressCmd defines the addwitnessaddress JSON-RPC command.
  18. type AddWitnessAddressCmd struct {
  19. Address string
  20. }
  21. // NewAddWitnessAddressCmd returns a new instance which can be used to issue a
  22. // addwitnessaddress JSON-RPC command.
  23. func NewAddWitnessAddressCmd(address string) *AddWitnessAddressCmd {
  24. return &AddWitnessAddressCmd{
  25. Address: address,
  26. }
  27. }
  28. // CreateMultisigCmd defines the createmultisig JSON-RPC command.
  29. type CreateMultisigCmd struct {
  30. NRequired int
  31. Keys []string
  32. }
  33. // NewCreateMultisigCmd returns a new instance which can be used to issue a
  34. // createmultisig JSON-RPC command.
  35. func NewCreateMultisigCmd(nRequired int, keys []string) *CreateMultisigCmd {
  36. return &CreateMultisigCmd{
  37. NRequired: nRequired,
  38. Keys: keys,
  39. }
  40. }
  41. // DumpPrivKeyCmd defines the dumpprivkey JSON-RPC command.
  42. type DumpPrivKeyCmd struct {
  43. Address string
  44. }
  45. // NewDumpPrivKeyCmd returns a new instance which can be used to issue a
  46. // dumpprivkey JSON-RPC command.
  47. func NewDumpPrivKeyCmd(address string) *DumpPrivKeyCmd {
  48. return &DumpPrivKeyCmd{
  49. Address: address,
  50. }
  51. }
  52. // GetAddressBalances defines the getaddressbalances JSON-RPC command.
  53. type GetAddressBalancesCmd struct {
  54. MinConf *int `jsonrpcdefault:"1"`
  55. ShowZeroBalance *bool
  56. }
  57. type GetWalletSeedCmd struct{}
  58. type GetSecretCmd struct {
  59. Name string
  60. }
  61. type ResyncCmd struct {
  62. FromHeight *int32
  63. ToHeight *int32
  64. Addresses *[]string
  65. DropDb *bool
  66. }
  67. type StopResyncCmd struct{}
  68. // GetBalanceCmd defines the getbalance JSON-RPC command.
  69. type GetBalanceCmd struct {
  70. MinConf *int `jsonrpcdefault:"1"`
  71. }
  72. type GetNetworkStewardVoteCmd struct{}
  73. // GetNewAddressCmd defines the getnewaddress JSON-RPC command.
  74. type GetNewAddressCmd struct {
  75. Legacy *bool
  76. }
  77. // GetReceivedByAddressCmd defines the getreceivedbyaddress JSON-RPC command.
  78. type GetReceivedByAddressCmd struct {
  79. Address string
  80. MinConf *int `jsonrpcdefault:"1"`
  81. }
  82. // NewGetReceivedByAddressCmd returns a new instance which can be used to issue
  83. // a getreceivedbyaddress JSON-RPC command.
  84. //
  85. // The parameters which are pointers indicate they are optional. Passing nil
  86. // for optional parameters will use the default value.
  87. func NewGetReceivedByAddressCmd(address string, minConf *int) *GetReceivedByAddressCmd {
  88. return &GetReceivedByAddressCmd{
  89. Address: address,
  90. MinConf: minConf,
  91. }
  92. }
  93. // GetTransactionCmd defines the gettransaction JSON-RPC command.
  94. type GetTransactionCmd struct {
  95. Txid string
  96. IncludeWatchOnly *bool `jsonrpcdefault:"false"`
  97. }
  98. // NewGetTransactionCmd returns a new instance which can be used to issue a
  99. // gettransaction JSON-RPC command.
  100. //
  101. // The parameters which are pointers indicate they are optional. Passing nil
  102. // for optional parameters will use the default value.
  103. func NewGetTransactionCmd(txHash string, includeWatchOnly *bool) *GetTransactionCmd {
  104. return &GetTransactionCmd{
  105. Txid: txHash,
  106. IncludeWatchOnly: includeWatchOnly,
  107. }
  108. }
  109. // ImportPrivKeyCmd defines the importprivkey JSON-RPC command.
  110. type ImportPrivKeyCmd struct {
  111. PrivKey string
  112. Label *string
  113. Rescan *bool `jsonrpcdefault:"true"`
  114. Legacy *bool `jsonrpcdefault:"false"`
  115. }
  116. // NewImportPrivKeyCmd returns a new instance which can be used to issue a
  117. // importprivkey JSON-RPC command.
  118. //
  119. // The parameters which are pointers indicate they are optional. Passing nil
  120. // for optional parameters will use the default value.
  121. func NewImportPrivKeyCmd(privKey string, label *string, rescan *bool) *ImportPrivKeyCmd {
  122. return &ImportPrivKeyCmd{
  123. PrivKey: privKey,
  124. Label: label,
  125. Rescan: rescan,
  126. }
  127. }
  128. // ListLockUnspentCmd defines the listlockunspent JSON-RPC command.
  129. type ListLockUnspentCmd struct{}
  130. // NewListLockUnspentCmd returns a new instance which can be used to issue a
  131. // listlockunspent JSON-RPC command.
  132. func NewListLockUnspentCmd() *ListLockUnspentCmd {
  133. return &ListLockUnspentCmd{}
  134. }
  135. // ListReceivedByAddressCmd defines the listreceivedbyaddress JSON-RPC command.
  136. type ListReceivedByAddressCmd struct {
  137. MinConf *int `jsonrpcdefault:"1"`
  138. IncludeEmpty *bool `jsonrpcdefault:"false"`
  139. IncludeWatchOnly *bool `jsonrpcdefault:"false"`
  140. }
  141. // NewListReceivedByAddressCmd returns a new instance which can be used to issue
  142. // a listreceivedbyaddress JSON-RPC command.
  143. //
  144. // The parameters which are pointers indicate they are optional. Passing nil
  145. // for optional parameters will use the default value.
  146. func NewListReceivedByAddressCmd(minConf *int, includeEmpty, includeWatchOnly *bool) *ListReceivedByAddressCmd {
  147. return &ListReceivedByAddressCmd{
  148. MinConf: minConf,
  149. IncludeEmpty: includeEmpty,
  150. IncludeWatchOnly: includeWatchOnly,
  151. }
  152. }
  153. // ListSinceBlockCmd defines the listsinceblock JSON-RPC command.
  154. type ListSinceBlockCmd struct {
  155. BlockHash *string
  156. TargetConfirmations *int `jsonrpcdefault:"1"`
  157. IncludeWatchOnly *bool `jsonrpcdefault:"false"`
  158. }
  159. // NewListSinceBlockCmd returns a new instance which can be used to issue a
  160. // listsinceblock JSON-RPC command.
  161. //
  162. // The parameters which are pointers indicate they are optional. Passing nil
  163. // for optional parameters will use the default value.
  164. func NewListSinceBlockCmd(blockHash *string, targetConfirms *int, includeWatchOnly *bool) *ListSinceBlockCmd {
  165. return &ListSinceBlockCmd{
  166. BlockHash: blockHash,
  167. TargetConfirmations: targetConfirms,
  168. IncludeWatchOnly: includeWatchOnly,
  169. }
  170. }
  171. // ListTransactionsCmd defines the listtransactions JSON-RPC command.
  172. type ListTransactionsCmd struct {
  173. Count *int `jsonrpcdefault:"10"`
  174. From *int `jsonrpcdefault:"0"`
  175. }
  176. // ListUnspentCmd defines the listunspent JSON-RPC command.
  177. type ListUnspentCmd struct {
  178. MinConf *int `jsonrpcdefault:"1"`
  179. MaxConf *int `jsonrpcdefault:"9999999"`
  180. Addresses *[]string
  181. }
  182. // NewListUnspentCmd returns a new instance which can be used to issue a
  183. // listunspent JSON-RPC command.
  184. //
  185. // The parameters which are pointers indicate they are optional. Passing nil
  186. // for optional parameters will use the default value.
  187. func NewListUnspentCmd(minConf, maxConf *int, addresses *[]string) *ListUnspentCmd {
  188. return &ListUnspentCmd{
  189. MinConf: minConf,
  190. MaxConf: maxConf,
  191. Addresses: addresses,
  192. }
  193. }
  194. // LockUnspentCmd defines the lockunspent JSON-RPC command.
  195. type LockUnspentCmd struct {
  196. Unlock bool
  197. Transactions []TransactionInput
  198. LockName *string
  199. }
  200. // NewLockUnspentCmd returns a new instance which can be used to issue a
  201. // lockunspent JSON-RPC command.
  202. func NewLockUnspentCmd(unlock bool, transactions []TransactionInput) *LockUnspentCmd {
  203. return &LockUnspentCmd{
  204. Unlock: unlock,
  205. Transactions: transactions,
  206. }
  207. }
  208. // SendFromCmd defines the sendfrom JSON-RPC command.
  209. type SendFromCmd struct {
  210. ToAddress string
  211. Amount float64 // In BTC
  212. FromAddresses *[]string
  213. MinConf *int `jsonrpcdefault:"1"`
  214. Comment *string
  215. CommentTo *string
  216. MaxInputs *int
  217. MinHeight *int
  218. }
  219. // NewSendFromCmd returns a new instance which can be used to issue a sendfrom
  220. // JSON-RPC command.
  221. //
  222. // The parameters which are pointers indicate they are optional. Passing nil
  223. // for optional parameters will use the default value.
  224. func NewSendFromCmd(fromAddresses *[]string, toAddress string, amount float64, minConf *int, comment, commentTo *string) *SendFromCmd {
  225. return &SendFromCmd{
  226. FromAddresses: fromAddresses,
  227. ToAddress: toAddress,
  228. Amount: amount,
  229. MinConf: minConf,
  230. Comment: comment,
  231. CommentTo: commentTo,
  232. MinHeight: nil,
  233. }
  234. }
  235. type CreateTransactionCmd struct {
  236. ToAddress string
  237. Amount float64
  238. FromAddresses *[]string
  239. ElectrumFormat *bool
  240. ChangeAddress *string
  241. InputMinHeight *int
  242. MinConf *int `jsonrpcdefault:"1"`
  243. Vote *bool
  244. MaxInputs *int
  245. AutoLock *string
  246. }
  247. // SendManyCmd defines the sendmany JSON-RPC command.
  248. type SendManyCmd struct {
  249. Amounts map[string]float64 `jsonrpcusage:"{\"address\":amount,...}"` // In BTC
  250. FromAddresses *[]string
  251. MinConf *int `jsonrpcdefault:"1"`
  252. Comment *string
  253. MaxInputs *int
  254. }
  255. // NewSendManyCmd returns a new instance which can be used to issue a sendmany
  256. // JSON-RPC command.
  257. //
  258. // The parameters which are pointers indicate they are optional. Passing nil
  259. // for optional parameters will use the default value.
  260. func NewSendManyCmd(fromAddresses *[]string, amounts map[string]float64, minConf *int, comment *string) *SendManyCmd {
  261. return &SendManyCmd{
  262. FromAddresses: fromAddresses,
  263. Amounts: amounts,
  264. MinConf: minConf,
  265. Comment: comment,
  266. }
  267. }
  268. // SendToAddressCmd defines the sendtoaddress JSON-RPC command.
  269. type SendToAddressCmd struct {
  270. Address string
  271. Amount float64
  272. Comment *string
  273. CommentTo *string
  274. }
  275. // NewSendToAddressCmd returns a new instance which can be used to issue a
  276. // sendtoaddress JSON-RPC command.
  277. //
  278. // The parameters which are pointers indicate they are optional. Passing nil
  279. // for optional parameters will use the default value.
  280. func NewSendToAddressCmd(address string, amount float64, comment, commentTo *string) *SendToAddressCmd {
  281. return &SendToAddressCmd{
  282. Address: address,
  283. Amount: amount,
  284. Comment: comment,
  285. CommentTo: commentTo,
  286. }
  287. }
  288. // SetTxFeeCmd defines the settxfee JSON-RPC command.
  289. type SetTxFeeCmd struct {
  290. Amount float64 // In BTC
  291. }
  292. // NewSetTxFeeCmd returns a new instance which can be used to issue a settxfee
  293. // JSON-RPC command.
  294. func NewSetTxFeeCmd(amount float64) *SetTxFeeCmd {
  295. return &SetTxFeeCmd{
  296. Amount: amount,
  297. }
  298. }
  299. // SignMessageCmd defines the signmessage JSON-RPC command.
  300. type SignMessageCmd struct {
  301. Address string
  302. Message string
  303. }
  304. // NewSignMessageCmd returns a new instance which can be used to issue a
  305. // signmessage JSON-RPC command.
  306. func NewSignMessageCmd(address, message string) *SignMessageCmd {
  307. return &SignMessageCmd{
  308. Address: address,
  309. Message: message,
  310. }
  311. }
  312. // RawTxInput models the data needed for raw transaction input that is used in
  313. // the SignRawTransactionCmd struct.
  314. type RawTxInput struct {
  315. Txid string `json:"txid"`
  316. Vout uint32 `json:"vout"`
  317. ScriptPubKey string `json:"scriptPubKey"`
  318. RedeemScript string `json:"redeemScript"`
  319. }
  320. // SignRawTransactionCmd defines the signrawtransaction JSON-RPC command.
  321. type SignRawTransactionCmd struct {
  322. RawTx string
  323. Inputs *[]RawTxInput
  324. PrivKeys *[]string
  325. Flags *string `jsonrpcdefault:"\"ALL\""`
  326. }
  327. // NewSignRawTransactionCmd returns a new instance which can be used to issue a
  328. // signrawtransaction JSON-RPC command.
  329. //
  330. // The parameters which are pointers indicate they are optional. Passing nil
  331. // for optional parameters will use the default value.
  332. func NewSignRawTransactionCmd(hexEncodedTx string, inputs *[]RawTxInput, privKeys *[]string, flags *string) *SignRawTransactionCmd {
  333. return &SignRawTransactionCmd{
  334. RawTx: hexEncodedTx,
  335. Inputs: inputs,
  336. PrivKeys: privKeys,
  337. Flags: flags,
  338. }
  339. }
  340. // WalletLockCmd defines the walletlock JSON-RPC command.
  341. type WalletLockCmd struct{}
  342. // NewWalletLockCmd returns a new instance which can be used to issue a
  343. // walletlock JSON-RPC command.
  344. func NewWalletLockCmd() *WalletLockCmd {
  345. return &WalletLockCmd{}
  346. }
  347. // WalletPassphraseCmd defines the walletpassphrase JSON-RPC command.
  348. type WalletPassphraseCmd struct {
  349. Passphrase string
  350. Timeout int64
  351. }
  352. // NewWalletPassphraseCmd returns a new instance which can be used to issue a
  353. // walletpassphrase JSON-RPC command.
  354. func NewWalletPassphraseCmd(passphrase string, timeout int64) *WalletPassphraseCmd {
  355. return &WalletPassphraseCmd{
  356. Passphrase: passphrase,
  357. Timeout: timeout,
  358. }
  359. }
  360. // WalletPassphraseChangeCmd defines the walletpassphrase JSON-RPC command.
  361. type WalletPassphraseChangeCmd struct {
  362. OldPassphrase string
  363. NewPassphrase string
  364. }
  365. // NewWalletPassphraseChangeCmd returns a new instance which can be used to
  366. // issue a walletpassphrasechange JSON-RPC command.
  367. func NewWalletPassphraseChangeCmd(oldPassphrase, newPassphrase string) *WalletPassphraseChangeCmd {
  368. return &WalletPassphraseChangeCmd{
  369. OldPassphrase: oldPassphrase,
  370. NewPassphrase: newPassphrase,
  371. }
  372. }
  373. type WalletMempoolCmd struct{}
  374. // SetNetworkStewardVoteCmd is the argument to the wallet command setnetworkstewardvote
  375. type SetNetworkStewardVoteCmd struct {
  376. VoteFor *string `json:"votefor"`
  377. VoteAgainst *string `json:"voteagainst"`
  378. }
  379. func init() {
  380. // The commands in this file are only usable with a wallet server.
  381. flags := UFWalletOnly
  382. MustRegisterCmd("addmultisigaddress", (*AddMultisigAddressCmd)(nil), flags)
  383. MustRegisterCmd("addp2shscript", (*AddP2shScriptCmd)(nil), flags)
  384. MustRegisterCmd("addwitnessaddress", (*AddWitnessAddressCmd)(nil), flags)
  385. MustRegisterCmd("createmultisig", (*CreateMultisigCmd)(nil), flags)
  386. MustRegisterCmd("createtransaction", (*CreateTransactionCmd)(nil), flags)
  387. MustRegisterCmd("getaddressbalances", (*GetAddressBalancesCmd)(nil), flags)
  388. MustRegisterCmd("resync", (*ResyncCmd)(nil), flags)
  389. MustRegisterCmd("stopresync", (*StopResyncCmd)(nil), flags)
  390. MustRegisterCmd("dumpprivkey", (*DumpPrivKeyCmd)(nil), flags)
  391. MustRegisterCmd("getbalance", (*GetBalanceCmd)(nil), flags)
  392. MustRegisterCmd("getnetworkstewardvote", (*GetNetworkStewardVoteCmd)(nil), flags)
  393. MustRegisterCmd("getnewaddress", (*GetNewAddressCmd)(nil), flags)
  394. MustRegisterCmd("getreceivedbyaddress", (*GetReceivedByAddressCmd)(nil), flags)
  395. MustRegisterCmd("gettransaction", (*GetTransactionCmd)(nil), flags)
  396. MustRegisterCmd("getwalletseed", (*GetWalletSeedCmd)(nil), flags)
  397. MustRegisterCmd("getsecret", (*GetSecretCmd)(nil), flags)
  398. MustRegisterCmd("importprivkey", (*ImportPrivKeyCmd)(nil), flags)
  399. MustRegisterCmd("listlockunspent", (*ListLockUnspentCmd)(nil), flags)
  400. MustRegisterCmd("listreceivedbyaddress", (*ListReceivedByAddressCmd)(nil), flags)
  401. MustRegisterCmd("listsinceblock", (*ListSinceBlockCmd)(nil), flags)
  402. MustRegisterCmd("listtransactions", (*ListTransactionsCmd)(nil), flags)
  403. MustRegisterCmd("listunspent", (*ListUnspentCmd)(nil), flags)
  404. MustRegisterCmd("lockunspent", (*LockUnspentCmd)(nil), flags)
  405. MustRegisterCmd("sendfrom", (*SendFromCmd)(nil), flags)
  406. MustRegisterCmd("sendmany", (*SendManyCmd)(nil), flags)
  407. MustRegisterCmd("sendtoaddress", (*SendToAddressCmd)(nil), flags)
  408. MustRegisterCmd("setnetworkstewardvote", (*SetNetworkStewardVoteCmd)(nil), flags)
  409. MustRegisterCmd("settxfee", (*SetTxFeeCmd)(nil), flags)
  410. MustRegisterCmd("signmessage", (*SignMessageCmd)(nil), flags)
  411. MustRegisterCmd("signrawtransaction", (*SignRawTransactionCmd)(nil), flags)
  412. MustRegisterCmd("walletlock", (*WalletLockCmd)(nil), flags)
  413. MustRegisterCmd("walletpassphrase", (*WalletPassphraseCmd)(nil), flags)
  414. MustRegisterCmd("walletpassphrasechange", (*WalletPassphraseChangeCmd)(nil), flags)
  415. MustRegisterCmd("walletmempool", (*WalletMempoolCmd)(nil), flags)
  416. }