github.com/btcsuite/btcd@v0.24.0/btcjson/walletsvrcmds.go (about) 1 // Copyright (c) 2014-2020 The btcsuite developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 // NOTE: This file is intended to house the RPC commands that are supported by 6 // a wallet server. 7 8 package btcjson 9 10 import ( 11 "encoding/hex" 12 "encoding/json" 13 "fmt" 14 15 "github.com/btcsuite/btcd/btcutil" 16 ) 17 18 // AddMultisigAddressCmd defines the addmutisigaddress JSON-RPC command. 19 type AddMultisigAddressCmd struct { 20 NRequired int 21 Keys []string 22 Account *string 23 } 24 25 // NewAddMultisigAddressCmd returns a new instance which can be used to issue a 26 // addmultisigaddress JSON-RPC command. 27 // 28 // The parameters which are pointers indicate they are optional. Passing nil 29 // for optional parameters will use the default value. 30 func NewAddMultisigAddressCmd(nRequired int, keys []string, account *string) *AddMultisigAddressCmd { 31 return &AddMultisigAddressCmd{ 32 NRequired: nRequired, 33 Keys: keys, 34 Account: account, 35 } 36 } 37 38 // AddWitnessAddressCmd defines the addwitnessaddress JSON-RPC command. 39 type AddWitnessAddressCmd struct { 40 Address string 41 } 42 43 // NewAddWitnessAddressCmd returns a new instance which can be used to issue a 44 // addwitnessaddress JSON-RPC command. 45 func NewAddWitnessAddressCmd(address string) *AddWitnessAddressCmd { 46 return &AddWitnessAddressCmd{ 47 Address: address, 48 } 49 } 50 51 // CreateMultisigCmd defines the createmultisig JSON-RPC command. 52 type CreateMultisigCmd struct { 53 NRequired int 54 Keys []string 55 } 56 57 // NewCreateMultisigCmd returns a new instance which can be used to issue a 58 // createmultisig JSON-RPC command. 59 func NewCreateMultisigCmd(nRequired int, keys []string) *CreateMultisigCmd { 60 return &CreateMultisigCmd{ 61 NRequired: nRequired, 62 Keys: keys, 63 } 64 } 65 66 // CreateWalletCmd defines the createwallet JSON-RPC command. 67 type CreateWalletCmd struct { 68 WalletName string 69 DisablePrivateKeys *bool `jsonrpcdefault:"false"` 70 Blank *bool `jsonrpcdefault:"false"` 71 Passphrase *string `jsonrpcdefault:"\"\""` 72 AvoidReuse *bool `jsonrpcdefault:"false"` 73 } 74 75 // NewCreateWalletCmd returns a new instance which can be used to issue a 76 // createwallet JSON-RPC command. 77 func NewCreateWalletCmd(walletName string, disablePrivateKeys *bool, 78 blank *bool, passphrase *string, avoidReuse *bool) *CreateWalletCmd { 79 return &CreateWalletCmd{ 80 WalletName: walletName, 81 DisablePrivateKeys: disablePrivateKeys, 82 Blank: blank, 83 Passphrase: passphrase, 84 AvoidReuse: avoidReuse, 85 } 86 } 87 88 // DumpPrivKeyCmd defines the dumpprivkey JSON-RPC command. 89 type DumpPrivKeyCmd struct { 90 Address string 91 } 92 93 // NewDumpPrivKeyCmd returns a new instance which can be used to issue a 94 // dumpprivkey JSON-RPC command. 95 func NewDumpPrivKeyCmd(address string) *DumpPrivKeyCmd { 96 return &DumpPrivKeyCmd{ 97 Address: address, 98 } 99 } 100 101 // EncryptWalletCmd defines the encryptwallet JSON-RPC command. 102 type EncryptWalletCmd struct { 103 Passphrase string 104 } 105 106 // NewEncryptWalletCmd returns a new instance which can be used to issue a 107 // encryptwallet JSON-RPC command. 108 func NewEncryptWalletCmd(passphrase string) *EncryptWalletCmd { 109 return &EncryptWalletCmd{ 110 Passphrase: passphrase, 111 } 112 } 113 114 // EstimateSmartFeeMode defines the different fee estimation modes available 115 // for the estimatesmartfee JSON-RPC command. 116 type EstimateSmartFeeMode string 117 118 var ( 119 EstimateModeUnset EstimateSmartFeeMode = "UNSET" 120 EstimateModeEconomical EstimateSmartFeeMode = "ECONOMICAL" 121 EstimateModeConservative EstimateSmartFeeMode = "CONSERVATIVE" 122 ) 123 124 // EstimateSmartFeeCmd defines the estimatesmartfee JSON-RPC command. 125 type EstimateSmartFeeCmd struct { 126 ConfTarget int64 127 EstimateMode *EstimateSmartFeeMode `jsonrpcdefault:"\"CONSERVATIVE\""` 128 } 129 130 // NewEstimateSmartFeeCmd returns a new instance which can be used to issue a 131 // estimatesmartfee JSON-RPC command. 132 func NewEstimateSmartFeeCmd(confTarget int64, mode *EstimateSmartFeeMode) *EstimateSmartFeeCmd { 133 return &EstimateSmartFeeCmd{ 134 ConfTarget: confTarget, EstimateMode: mode, 135 } 136 } 137 138 // EstimateFeeCmd defines the estimatefee JSON-RPC command. 139 type EstimateFeeCmd struct { 140 NumBlocks int64 141 } 142 143 // NewEstimateFeeCmd returns a new instance which can be used to issue a 144 // estimatefee JSON-RPC command. 145 func NewEstimateFeeCmd(numBlocks int64) *EstimateFeeCmd { 146 return &EstimateFeeCmd{ 147 NumBlocks: numBlocks, 148 } 149 } 150 151 // EstimatePriorityCmd defines the estimatepriority JSON-RPC command. 152 type EstimatePriorityCmd struct { 153 NumBlocks int64 154 } 155 156 // NewEstimatePriorityCmd returns a new instance which can be used to issue a 157 // estimatepriority JSON-RPC command. 158 func NewEstimatePriorityCmd(numBlocks int64) *EstimatePriorityCmd { 159 return &EstimatePriorityCmd{ 160 NumBlocks: numBlocks, 161 } 162 } 163 164 // GetAccountCmd defines the getaccount JSON-RPC command. 165 type GetAccountCmd struct { 166 Address string 167 } 168 169 // NewGetAccountCmd returns a new instance which can be used to issue a 170 // getaccount JSON-RPC command. 171 func NewGetAccountCmd(address string) *GetAccountCmd { 172 return &GetAccountCmd{ 173 Address: address, 174 } 175 } 176 177 // GetAccountAddressCmd defines the getaccountaddress JSON-RPC command. 178 type GetAccountAddressCmd struct { 179 Account string 180 } 181 182 // NewGetAccountAddressCmd returns a new instance which can be used to issue a 183 // getaccountaddress JSON-RPC command. 184 func NewGetAccountAddressCmd(account string) *GetAccountAddressCmd { 185 return &GetAccountAddressCmd{ 186 Account: account, 187 } 188 } 189 190 // GetAddressesByAccountCmd defines the getaddressesbyaccount JSON-RPC command. 191 type GetAddressesByAccountCmd struct { 192 Account string 193 } 194 195 // NewGetAddressesByAccountCmd returns a new instance which can be used to issue 196 // a getaddressesbyaccount JSON-RPC command. 197 func NewGetAddressesByAccountCmd(account string) *GetAddressesByAccountCmd { 198 return &GetAddressesByAccountCmd{ 199 Account: account, 200 } 201 } 202 203 // GetAddressInfoCmd defines the getaddressinfo JSON-RPC command. 204 type GetAddressInfoCmd struct { 205 Address string 206 } 207 208 // NewGetAddressInfoCmd returns a new instance which can be used to issue a 209 // getaddressinfo JSON-RPC command. 210 func NewGetAddressInfoCmd(address string) *GetAddressInfoCmd { 211 return &GetAddressInfoCmd{ 212 Address: address, 213 } 214 } 215 216 // GetBalanceCmd defines the getbalance JSON-RPC command. 217 type GetBalanceCmd struct { 218 Account *string 219 MinConf *int `jsonrpcdefault:"1"` 220 } 221 222 // NewGetBalanceCmd returns a new instance which can be used to issue a 223 // getbalance JSON-RPC command. 224 // 225 // The parameters which are pointers indicate they are optional. Passing nil 226 // for optional parameters will use the default value. 227 func NewGetBalanceCmd(account *string, minConf *int) *GetBalanceCmd { 228 return &GetBalanceCmd{ 229 Account: account, 230 MinConf: minConf, 231 } 232 } 233 234 // GetBalancesCmd defines the getbalances JSON-RPC command. 235 type GetBalancesCmd struct{} 236 237 // NewGetBalancesCmd returns a new instance which can be used to issue a 238 // getbalances JSON-RPC command. 239 func NewGetBalancesCmd() *GetBalancesCmd { 240 return &GetBalancesCmd{} 241 } 242 243 // GetNewAddressCmd defines the getnewaddress JSON-RPC command. 244 type GetNewAddressCmd struct { 245 Account *string 246 AddressType *string 247 } 248 249 // NewGetNewAddressCmd returns a new instance which can be used to issue a 250 // getnewaddress JSON-RPC command. 251 // 252 // The parameters which are pointers indicate they are optional. Passing nil 253 // for optional parameters will use the default value. 254 func NewGetNewAddressCmd(account, addrType *string) *GetNewAddressCmd { 255 return &GetNewAddressCmd{ 256 Account: account, 257 AddressType: addrType, 258 } 259 } 260 261 // GetRawChangeAddressCmd defines the getrawchangeaddress JSON-RPC command. 262 type GetRawChangeAddressCmd struct { 263 Account *string 264 AddressType *string 265 } 266 267 // NewGetRawChangeAddressCmd returns a new instance which can be used to issue a 268 // getrawchangeaddress JSON-RPC command. 269 // 270 // The parameters which are pointers indicate they are optional. Passing nil 271 // for optional parameters will use the default value. 272 func NewGetRawChangeAddressCmd(account, addrType *string) *GetRawChangeAddressCmd { 273 return &GetRawChangeAddressCmd{ 274 Account: account, 275 AddressType: addrType, 276 } 277 } 278 279 // GetReceivedByAccountCmd defines the getreceivedbyaccount JSON-RPC command. 280 type GetReceivedByAccountCmd struct { 281 Account string 282 MinConf *int `jsonrpcdefault:"1"` 283 } 284 285 // NewGetReceivedByAccountCmd returns a new instance which can be used to issue 286 // a getreceivedbyaccount JSON-RPC command. 287 // 288 // The parameters which are pointers indicate they are optional. Passing nil 289 // for optional parameters will use the default value. 290 func NewGetReceivedByAccountCmd(account string, minConf *int) *GetReceivedByAccountCmd { 291 return &GetReceivedByAccountCmd{ 292 Account: account, 293 MinConf: minConf, 294 } 295 } 296 297 // GetReceivedByAddressCmd defines the getreceivedbyaddress JSON-RPC command. 298 type GetReceivedByAddressCmd struct { 299 Address string 300 MinConf *int `jsonrpcdefault:"1"` 301 } 302 303 // NewGetReceivedByAddressCmd returns a new instance which can be used to issue 304 // a getreceivedbyaddress JSON-RPC command. 305 // 306 // The parameters which are pointers indicate they are optional. Passing nil 307 // for optional parameters will use the default value. 308 func NewGetReceivedByAddressCmd(address string, minConf *int) *GetReceivedByAddressCmd { 309 return &GetReceivedByAddressCmd{ 310 Address: address, 311 MinConf: minConf, 312 } 313 } 314 315 // GetTransactionCmd defines the gettransaction JSON-RPC command. 316 type GetTransactionCmd struct { 317 Txid string 318 IncludeWatchOnly *bool `jsonrpcdefault:"false"` 319 } 320 321 // NewGetTransactionCmd returns a new instance which can be used to issue a 322 // gettransaction JSON-RPC command. 323 // 324 // The parameters which are pointers indicate they are optional. Passing nil 325 // for optional parameters will use the default value. 326 func NewGetTransactionCmd(txHash string, includeWatchOnly *bool) *GetTransactionCmd { 327 return &GetTransactionCmd{ 328 Txid: txHash, 329 IncludeWatchOnly: includeWatchOnly, 330 } 331 } 332 333 // GetWalletInfoCmd defines the getwalletinfo JSON-RPC command. 334 type GetWalletInfoCmd struct{} 335 336 // NewGetWalletInfoCmd returns a new instance which can be used to issue a 337 // getwalletinfo JSON-RPC command. 338 func NewGetWalletInfoCmd() *GetWalletInfoCmd { 339 return &GetWalletInfoCmd{} 340 } 341 342 // BackupWalletCmd defines the backupwallet JSON-RPC command 343 type BackupWalletCmd struct { 344 Destination string 345 } 346 347 // NewBackupWalletCmd returns a new instance which can be used to issue a 348 // backupwallet JSON-RPC command 349 func NewBackupWalletCmd(destination string) *BackupWalletCmd { 350 return &BackupWalletCmd{Destination: destination} 351 } 352 353 // UnloadWalletCmd defines the unloadwallet JSON-RPC command 354 type UnloadWalletCmd struct { 355 WalletName *string 356 } 357 358 // NewUnloadWalletCmd returns a new instance which can be used to issue a 359 // unloadwallet JSON-RPC command. 360 func NewUnloadWalletCmd(walletName *string) *UnloadWalletCmd { 361 return &UnloadWalletCmd{WalletName: walletName} 362 } 363 364 // LoadWalletCmd defines the loadwallet JSON-RPC command 365 type LoadWalletCmd struct { 366 WalletName string 367 } 368 369 // NewLoadWalletCmd returns a new instance which can be used to issue a 370 // loadwallet JSON-RPC command 371 func NewLoadWalletCmd(walletName string) *LoadWalletCmd { 372 return &LoadWalletCmd{WalletName: walletName} 373 } 374 375 // ImportPrivKeyCmd defines the importprivkey JSON-RPC command. 376 type ImportPrivKeyCmd struct { 377 PrivKey string 378 Label *string 379 Rescan *bool `jsonrpcdefault:"true"` 380 } 381 382 // NewImportPrivKeyCmd returns a new instance which can be used to issue a 383 // importprivkey JSON-RPC command. 384 // 385 // The parameters which are pointers indicate they are optional. Passing nil 386 // for optional parameters will use the default value. 387 func NewImportPrivKeyCmd(privKey string, label *string, rescan *bool) *ImportPrivKeyCmd { 388 return &ImportPrivKeyCmd{ 389 PrivKey: privKey, 390 Label: label, 391 Rescan: rescan, 392 } 393 } 394 395 // KeyPoolRefillCmd defines the keypoolrefill JSON-RPC command. 396 type KeyPoolRefillCmd struct { 397 NewSize *uint `jsonrpcdefault:"100"` 398 } 399 400 // NewKeyPoolRefillCmd returns a new instance which can be used to issue a 401 // keypoolrefill JSON-RPC command. 402 // 403 // The parameters which are pointers indicate they are optional. Passing nil 404 // for optional parameters will use the default value. 405 func NewKeyPoolRefillCmd(newSize *uint) *KeyPoolRefillCmd { 406 return &KeyPoolRefillCmd{ 407 NewSize: newSize, 408 } 409 } 410 411 // ListAccountsCmd defines the listaccounts JSON-RPC command. 412 type ListAccountsCmd struct { 413 MinConf *int `jsonrpcdefault:"1"` 414 } 415 416 // NewListAccountsCmd returns a new instance which can be used to issue a 417 // listaccounts JSON-RPC command. 418 // 419 // The parameters which are pointers indicate they are optional. Passing nil 420 // for optional parameters will use the default value. 421 func NewListAccountsCmd(minConf *int) *ListAccountsCmd { 422 return &ListAccountsCmd{ 423 MinConf: minConf, 424 } 425 } 426 427 // ListAddressGroupingsCmd defines the listaddressgroupings JSON-RPC command. 428 type ListAddressGroupingsCmd struct{} 429 430 // NewListAddressGroupingsCmd returns a new instance which can be used to issue 431 // a listaddressgroupoings JSON-RPC command. 432 func NewListAddressGroupingsCmd() *ListAddressGroupingsCmd { 433 return &ListAddressGroupingsCmd{} 434 } 435 436 // ListLockUnspentCmd defines the listlockunspent JSON-RPC command. 437 type ListLockUnspentCmd struct{} 438 439 // NewListLockUnspentCmd returns a new instance which can be used to issue a 440 // listlockunspent JSON-RPC command. 441 func NewListLockUnspentCmd() *ListLockUnspentCmd { 442 return &ListLockUnspentCmd{} 443 } 444 445 // ListReceivedByAccountCmd defines the listreceivedbyaccount JSON-RPC command. 446 type ListReceivedByAccountCmd struct { 447 MinConf *int `jsonrpcdefault:"1"` 448 IncludeEmpty *bool `jsonrpcdefault:"false"` 449 IncludeWatchOnly *bool `jsonrpcdefault:"false"` 450 } 451 452 // NewListReceivedByAccountCmd returns a new instance which can be used to issue 453 // a listreceivedbyaccount JSON-RPC command. 454 // 455 // The parameters which are pointers indicate they are optional. Passing nil 456 // for optional parameters will use the default value. 457 func NewListReceivedByAccountCmd(minConf *int, includeEmpty, includeWatchOnly *bool) *ListReceivedByAccountCmd { 458 return &ListReceivedByAccountCmd{ 459 MinConf: minConf, 460 IncludeEmpty: includeEmpty, 461 IncludeWatchOnly: includeWatchOnly, 462 } 463 } 464 465 // ListReceivedByAddressCmd defines the listreceivedbyaddress JSON-RPC command. 466 type ListReceivedByAddressCmd struct { 467 MinConf *int `jsonrpcdefault:"1"` 468 IncludeEmpty *bool `jsonrpcdefault:"false"` 469 IncludeWatchOnly *bool `jsonrpcdefault:"false"` 470 } 471 472 // NewListReceivedByAddressCmd returns a new instance which can be used to issue 473 // a listreceivedbyaddress JSON-RPC command. 474 // 475 // The parameters which are pointers indicate they are optional. Passing nil 476 // for optional parameters will use the default value. 477 func NewListReceivedByAddressCmd(minConf *int, includeEmpty, includeWatchOnly *bool) *ListReceivedByAddressCmd { 478 return &ListReceivedByAddressCmd{ 479 MinConf: minConf, 480 IncludeEmpty: includeEmpty, 481 IncludeWatchOnly: includeWatchOnly, 482 } 483 } 484 485 // ListSinceBlockCmd defines the listsinceblock JSON-RPC command. 486 type ListSinceBlockCmd struct { 487 BlockHash *string 488 TargetConfirmations *int `jsonrpcdefault:"1"` 489 IncludeWatchOnly *bool `jsonrpcdefault:"false"` 490 } 491 492 // NewListSinceBlockCmd returns a new instance which can be used to issue a 493 // listsinceblock JSON-RPC command. 494 // 495 // The parameters which are pointers indicate they are optional. Passing nil 496 // for optional parameters will use the default value. 497 func NewListSinceBlockCmd(blockHash *string, targetConfirms *int, includeWatchOnly *bool) *ListSinceBlockCmd { 498 return &ListSinceBlockCmd{ 499 BlockHash: blockHash, 500 TargetConfirmations: targetConfirms, 501 IncludeWatchOnly: includeWatchOnly, 502 } 503 } 504 505 // ListTransactionsCmd defines the listtransactions JSON-RPC command. 506 type ListTransactionsCmd struct { 507 Account *string 508 Count *int `jsonrpcdefault:"10"` 509 From *int `jsonrpcdefault:"0"` 510 IncludeWatchOnly *bool `jsonrpcdefault:"false"` 511 } 512 513 // NewListTransactionsCmd returns a new instance which can be used to issue a 514 // listtransactions JSON-RPC command. 515 // 516 // The parameters which are pointers indicate they are optional. Passing nil 517 // for optional parameters will use the default value. 518 func NewListTransactionsCmd(account *string, count, from *int, includeWatchOnly *bool) *ListTransactionsCmd { 519 return &ListTransactionsCmd{ 520 Account: account, 521 Count: count, 522 From: from, 523 IncludeWatchOnly: includeWatchOnly, 524 } 525 } 526 527 // ListUnspentCmd defines the listunspent JSON-RPC command. 528 type ListUnspentCmd struct { 529 MinConf *int `jsonrpcdefault:"1"` 530 MaxConf *int `jsonrpcdefault:"9999999"` 531 Addresses *[]string 532 } 533 534 // NewListUnspentCmd returns a new instance which can be used to issue a 535 // listunspent JSON-RPC command. 536 // 537 // The parameters which are pointers indicate they are optional. Passing nil 538 // for optional parameters will use the default value. 539 func NewListUnspentCmd(minConf, maxConf *int, addresses *[]string) *ListUnspentCmd { 540 return &ListUnspentCmd{ 541 MinConf: minConf, 542 MaxConf: maxConf, 543 Addresses: addresses, 544 } 545 } 546 547 // LockUnspentCmd defines the lockunspent JSON-RPC command. 548 type LockUnspentCmd struct { 549 Unlock bool 550 Transactions []TransactionInput 551 } 552 553 // NewLockUnspentCmd returns a new instance which can be used to issue a 554 // lockunspent JSON-RPC command. 555 func NewLockUnspentCmd(unlock bool, transactions []TransactionInput) *LockUnspentCmd { 556 return &LockUnspentCmd{ 557 Unlock: unlock, 558 Transactions: transactions, 559 } 560 } 561 562 // MoveCmd defines the move JSON-RPC command. 563 type MoveCmd struct { 564 FromAccount string 565 ToAccount string 566 Amount float64 // In BTC 567 MinConf *int `jsonrpcdefault:"1"` 568 Comment *string 569 } 570 571 // NewMoveCmd returns a new instance which can be used to issue a move JSON-RPC 572 // command. 573 // 574 // The parameters which are pointers indicate they are optional. Passing nil 575 // for optional parameters will use the default value. 576 func NewMoveCmd(fromAccount, toAccount string, amount float64, minConf *int, comment *string) *MoveCmd { 577 return &MoveCmd{ 578 FromAccount: fromAccount, 579 ToAccount: toAccount, 580 Amount: amount, 581 MinConf: minConf, 582 Comment: comment, 583 } 584 } 585 586 // SendFromCmd defines the sendfrom JSON-RPC command. 587 type SendFromCmd struct { 588 FromAccount string 589 ToAddress string 590 Amount float64 // In BTC 591 MinConf *int `jsonrpcdefault:"1"` 592 Comment *string 593 CommentTo *string 594 } 595 596 // NewSendFromCmd returns a new instance which can be used to issue a sendfrom 597 // JSON-RPC command. 598 // 599 // The parameters which are pointers indicate they are optional. Passing nil 600 // for optional parameters will use the default value. 601 func NewSendFromCmd(fromAccount, toAddress string, amount float64, minConf *int, comment, commentTo *string) *SendFromCmd { 602 return &SendFromCmd{ 603 FromAccount: fromAccount, 604 ToAddress: toAddress, 605 Amount: amount, 606 MinConf: minConf, 607 Comment: comment, 608 CommentTo: commentTo, 609 } 610 } 611 612 // SendManyCmd defines the sendmany JSON-RPC command. 613 type SendManyCmd struct { 614 FromAccount string 615 Amounts map[string]float64 `jsonrpcusage:"{\"address\":amount,...}"` // In BTC 616 MinConf *int `jsonrpcdefault:"1"` 617 Comment *string 618 } 619 620 // NewSendManyCmd returns a new instance which can be used to issue a sendmany 621 // JSON-RPC command. 622 // 623 // The parameters which are pointers indicate they are optional. Passing nil 624 // for optional parameters will use the default value. 625 func NewSendManyCmd(fromAccount string, amounts map[string]float64, minConf *int, comment *string) *SendManyCmd { 626 return &SendManyCmd{ 627 FromAccount: fromAccount, 628 Amounts: amounts, 629 MinConf: minConf, 630 Comment: comment, 631 } 632 } 633 634 // SendToAddressCmd defines the sendtoaddress JSON-RPC command. 635 type SendToAddressCmd struct { 636 Address string 637 Amount float64 638 Comment *string 639 CommentTo *string 640 } 641 642 // NewSendToAddressCmd returns a new instance which can be used to issue a 643 // sendtoaddress JSON-RPC command. 644 // 645 // The parameters which are pointers indicate they are optional. Passing nil 646 // for optional parameters will use the default value. 647 func NewSendToAddressCmd(address string, amount float64, comment, commentTo *string) *SendToAddressCmd { 648 return &SendToAddressCmd{ 649 Address: address, 650 Amount: amount, 651 Comment: comment, 652 CommentTo: commentTo, 653 } 654 } 655 656 // SetAccountCmd defines the setaccount JSON-RPC command. 657 type SetAccountCmd struct { 658 Address string 659 Account string 660 } 661 662 // NewSetAccountCmd returns a new instance which can be used to issue a 663 // setaccount JSON-RPC command. 664 func NewSetAccountCmd(address, account string) *SetAccountCmd { 665 return &SetAccountCmd{ 666 Address: address, 667 Account: account, 668 } 669 } 670 671 // SetTxFeeCmd defines the settxfee JSON-RPC command. 672 type SetTxFeeCmd struct { 673 Amount float64 // In BTC 674 } 675 676 // NewSetTxFeeCmd returns a new instance which can be used to issue a settxfee 677 // JSON-RPC command. 678 func NewSetTxFeeCmd(amount float64) *SetTxFeeCmd { 679 return &SetTxFeeCmd{ 680 Amount: amount, 681 } 682 } 683 684 // SignMessageCmd defines the signmessage JSON-RPC command. 685 type SignMessageCmd struct { 686 Address string 687 Message string 688 } 689 690 // NewSignMessageCmd returns a new instance which can be used to issue a 691 // signmessage JSON-RPC command. 692 func NewSignMessageCmd(address, message string) *SignMessageCmd { 693 return &SignMessageCmd{ 694 Address: address, 695 Message: message, 696 } 697 } 698 699 // RawTxInput models the data needed for raw transaction input that is used in 700 // the SignRawTransactionCmd struct. 701 type RawTxInput struct { 702 Txid string `json:"txid"` 703 Vout uint32 `json:"vout"` 704 ScriptPubKey string `json:"scriptPubKey"` 705 RedeemScript string `json:"redeemScript"` 706 } 707 708 // SignRawTransactionCmd defines the signrawtransaction JSON-RPC command. 709 type SignRawTransactionCmd struct { 710 RawTx string 711 Inputs *[]RawTxInput 712 PrivKeys *[]string 713 Flags *string `jsonrpcdefault:"\"ALL\""` 714 } 715 716 // NewSignRawTransactionCmd returns a new instance which can be used to issue a 717 // signrawtransaction JSON-RPC command. 718 // 719 // The parameters which are pointers indicate they are optional. Passing nil 720 // for optional parameters will use the default value. 721 func NewSignRawTransactionCmd(hexEncodedTx string, inputs *[]RawTxInput, privKeys *[]string, flags *string) *SignRawTransactionCmd { 722 return &SignRawTransactionCmd{ 723 RawTx: hexEncodedTx, 724 Inputs: inputs, 725 PrivKeys: privKeys, 726 Flags: flags, 727 } 728 } 729 730 // RawTxWitnessInput models the data needed for raw transaction input that is used in 731 // the SignRawTransactionWithWalletCmd struct. The RedeemScript is required for P2SH inputs, 732 // the WitnessScript is required for P2WSH or P2SH-P2WSH witness scripts, and the Amount is 733 // required for Segwit inputs. Otherwise, those fields can be left blank. 734 type RawTxWitnessInput struct { 735 Txid string `json:"txid"` 736 Vout uint32 `json:"vout"` 737 ScriptPubKey string `json:"scriptPubKey"` 738 RedeemScript *string `json:"redeemScript,omitempty"` 739 WitnessScript *string `json:"witnessScript,omitempty"` 740 Amount *float64 `json:"amount,omitempty"` // In BTC 741 } 742 743 // SignRawTransactionWithWalletCmd defines the signrawtransactionwithwallet JSON-RPC command. 744 type SignRawTransactionWithWalletCmd struct { 745 RawTx string 746 Inputs *[]RawTxWitnessInput 747 SigHashType *string `jsonrpcdefault:"\"ALL\""` 748 } 749 750 // NewSignRawTransactionWithWalletCmd returns a new instance which can be used to issue a 751 // signrawtransactionwithwallet JSON-RPC command. 752 // 753 // The parameters which are pointers indicate they are optional. Passing nil 754 // for optional parameters will use the default value. 755 func NewSignRawTransactionWithWalletCmd(hexEncodedTx string, inputs *[]RawTxWitnessInput, sigHashType *string) *SignRawTransactionWithWalletCmd { 756 return &SignRawTransactionWithWalletCmd{ 757 RawTx: hexEncodedTx, 758 Inputs: inputs, 759 SigHashType: sigHashType, 760 } 761 } 762 763 // WalletLockCmd defines the walletlock JSON-RPC command. 764 type WalletLockCmd struct{} 765 766 // NewWalletLockCmd returns a new instance which can be used to issue a 767 // walletlock JSON-RPC command. 768 func NewWalletLockCmd() *WalletLockCmd { 769 return &WalletLockCmd{} 770 } 771 772 // WalletPassphraseCmd defines the walletpassphrase JSON-RPC command. 773 type WalletPassphraseCmd struct { 774 Passphrase string 775 Timeout int64 776 } 777 778 // NewWalletPassphraseCmd returns a new instance which can be used to issue a 779 // walletpassphrase JSON-RPC command. 780 func NewWalletPassphraseCmd(passphrase string, timeout int64) *WalletPassphraseCmd { 781 return &WalletPassphraseCmd{ 782 Passphrase: passphrase, 783 Timeout: timeout, 784 } 785 } 786 787 // WalletPassphraseChangeCmd defines the walletpassphrase JSON-RPC command. 788 type WalletPassphraseChangeCmd struct { 789 OldPassphrase string 790 NewPassphrase string 791 } 792 793 // NewWalletPassphraseChangeCmd returns a new instance which can be used to 794 // issue a walletpassphrasechange JSON-RPC command. 795 func NewWalletPassphraseChangeCmd(oldPassphrase, newPassphrase string) *WalletPassphraseChangeCmd { 796 return &WalletPassphraseChangeCmd{ 797 OldPassphrase: oldPassphrase, 798 NewPassphrase: newPassphrase, 799 } 800 } 801 802 // TimestampOrNow defines a type to represent a timestamp value in seconds, 803 // since epoch. 804 // 805 // The value can either be a integer, or the string "now". 806 // 807 // NOTE: Interpretation of the timestamp value depends upon the specific 808 // JSON-RPC command, where it is used. 809 type TimestampOrNow struct { 810 Value interface{} 811 } 812 813 // MarshalJSON implements the json.Marshaler interface for TimestampOrNow 814 func (t TimestampOrNow) MarshalJSON() ([]byte, error) { 815 return json.Marshal(t.Value) 816 } 817 818 // UnmarshalJSON implements the json.Unmarshaler interface for TimestampOrNow 819 func (t *TimestampOrNow) UnmarshalJSON(data []byte) error { 820 var unmarshalled interface{} 821 if err := json.Unmarshal(data, &unmarshalled); err != nil { 822 return err 823 } 824 825 switch v := unmarshalled.(type) { 826 case float64: 827 t.Value = int(v) 828 case string: 829 if v != "now" { 830 return fmt.Errorf("invalid timestamp value: %v", unmarshalled) 831 } 832 t.Value = v 833 default: 834 return fmt.Errorf("invalid timestamp value: %v", unmarshalled) 835 } 836 return nil 837 } 838 839 // ScriptPubKeyAddress represents an address, to be used in conjunction with 840 // ScriptPubKey. 841 type ScriptPubKeyAddress struct { 842 Address string `json:"address"` 843 } 844 845 // ScriptPubKey represents a script (as a string) or an address 846 // (as a ScriptPubKeyAddress). 847 type ScriptPubKey struct { 848 Value interface{} 849 } 850 851 // MarshalJSON implements the json.Marshaler interface for ScriptPubKey 852 func (s ScriptPubKey) MarshalJSON() ([]byte, error) { 853 return json.Marshal(s.Value) 854 } 855 856 // UnmarshalJSON implements the json.Unmarshaler interface for ScriptPubKey 857 func (s *ScriptPubKey) UnmarshalJSON(data []byte) error { 858 var unmarshalled interface{} 859 if err := json.Unmarshal(data, &unmarshalled); err != nil { 860 return err 861 } 862 863 switch v := unmarshalled.(type) { 864 case string: 865 s.Value = v 866 case map[string]interface{}: 867 s.Value = ScriptPubKeyAddress{Address: v["address"].(string)} 868 default: 869 return fmt.Errorf("invalid scriptPubKey value: %v", unmarshalled) 870 } 871 return nil 872 } 873 874 // DescriptorRange specifies the limits of a ranged Descriptor. 875 // 876 // Descriptors are typically ranged when specified in the form of generic HD 877 // chain paths. 878 // 879 // Example of a ranged descriptor: pkh(tpub.../*) 880 // 881 // The value can be an int to specify the end of the range, or the range 882 // itself, as []int{begin, end}. 883 type DescriptorRange struct { 884 Value interface{} 885 } 886 887 // MarshalJSON implements the json.Marshaler interface for DescriptorRange 888 func (r DescriptorRange) MarshalJSON() ([]byte, error) { 889 return json.Marshal(r.Value) 890 } 891 892 // UnmarshalJSON implements the json.Unmarshaler interface for DescriptorRange 893 func (r *DescriptorRange) UnmarshalJSON(data []byte) error { 894 var unmarshalled interface{} 895 if err := json.Unmarshal(data, &unmarshalled); err != nil { 896 return err 897 } 898 899 switch v := unmarshalled.(type) { 900 case float64: 901 r.Value = int(v) 902 case []interface{}: 903 if len(v) != 2 { 904 return fmt.Errorf("expected [begin,end] integer range, got: %v", unmarshalled) 905 } 906 r.Value = []int{ 907 int(v[0].(float64)), 908 int(v[1].(float64)), 909 } 910 default: 911 return fmt.Errorf("invalid descriptor range value: %v", unmarshalled) 912 } 913 return nil 914 } 915 916 // ImportMultiRequest defines the request struct to be passed to the 917 // ImportMultiCmd, as an array. 918 type ImportMultiRequest struct { 919 // Descriptor to import, in canonical form. If using Descriptor, do not 920 // also provide ScriptPubKey, RedeemScript, WitnessScript, PubKeys, or Keys. 921 Descriptor *string `json:"desc,omitempty"` 922 923 // Script/address to import. Should not be provided if using Descriptor. 924 ScriptPubKey *ScriptPubKey `json:"scriptPubKey,omitempty"` 925 926 // Creation time of the key in seconds since epoch (Jan 1 1970 GMT), or 927 // the string "now" to substitute the current synced blockchain time. 928 // 929 // The timestamp of the oldest key will determine how far back blockchain 930 // rescans need to begin for missing wallet transactions. 931 // 932 // Specifying "now" bypasses scanning. Useful for keys that are known to 933 // never have been used. 934 // 935 // Specifying 0 scans the entire blockchain. 936 Timestamp TimestampOrNow `json:"timestamp"` 937 938 // Allowed only if the ScriptPubKey is a P2SH or P2SH-P2WSH 939 // address/scriptPubKey. 940 RedeemScript *string `json:"redeemscript,omitempty"` 941 942 // Allowed only if the ScriptPubKey is a P2SH-P2WSH or P2WSH 943 // address/scriptPubKey. 944 WitnessScript *string `json:"witnessscript,omitempty"` 945 946 // Array of strings giving pubkeys to import. They must occur in P2PKH or 947 // P2WPKH scripts. They are not required when the private key is also 948 // provided (see Keys). 949 PubKeys *[]string `json:"pubkeys,omitempty"` 950 951 // Array of strings giving private keys to import. The corresponding 952 // public keys must occur in the output or RedeemScript. 953 Keys *[]string `json:"keys,omitempty"` 954 955 // If the provided Descriptor is ranged, this specifies the end 956 // (as an int) or the range (as []int{begin, end}) to import. 957 Range *DescriptorRange `json:"range,omitempty"` 958 959 // States whether matching outputs should be treated as not incoming 960 // payments (also known as change). 961 Internal *bool `json:"internal,omitempty"` 962 963 // States whether matching outputs should be considered watchonly. 964 // 965 // If an address/script is imported without all of the private keys 966 // required to spend from that address, set this field to true. 967 // 968 // If all the private keys are provided and the address/script is 969 // spendable, set this field to false. 970 WatchOnly *bool `json:"watchonly,omitempty"` 971 972 // Label to assign to the address. Only allowed when Internal is false. 973 Label *string `json:"label,omitempty"` 974 975 // States whether imported public keys should be added to the keypool for 976 // when users request new addresses. Only allowed when wallet private keys 977 // are disabled. 978 KeyPool *bool `json:"keypool,omitempty"` 979 } 980 981 // ImportMultiRequest defines the options struct, provided to the 982 // ImportMultiCmd as a pointer argument. 983 type ImportMultiOptions struct { 984 Rescan bool `json:"rescan"` // Rescan the blockchain after all imports 985 } 986 987 // ImportMultiCmd defines the importmulti JSON-RPC command. 988 type ImportMultiCmd struct { 989 Requests []ImportMultiRequest 990 Options *ImportMultiOptions 991 } 992 993 // NewImportMultiCmd returns a new instance which can be used to issue 994 // an importmulti JSON-RPC command. 995 // 996 // The parameters which are pointers indicate they are optional. Passing nil 997 // for optional parameters will use the default value. 998 func NewImportMultiCmd(requests []ImportMultiRequest, options *ImportMultiOptions) *ImportMultiCmd { 999 return &ImportMultiCmd{ 1000 Requests: requests, 1001 Options: options, 1002 } 1003 } 1004 1005 // PsbtInput represents an input to include in the PSBT created by the 1006 // WalletCreateFundedPsbtCmd command. 1007 type PsbtInput struct { 1008 Txid string `json:"txid"` 1009 Vout uint32 `json:"vout"` 1010 Sequence uint32 `json:"sequence"` 1011 } 1012 1013 // PsbtOutput represents an output to include in the PSBT created by the 1014 // WalletCreateFundedPsbtCmd command. 1015 type PsbtOutput map[string]interface{} 1016 1017 // NewPsbtOutput returns a new instance of a PSBT output to use with the 1018 // WalletCreateFundedPsbtCmd command. 1019 func NewPsbtOutput(address string, amount btcutil.Amount) PsbtOutput { 1020 return PsbtOutput{address: amount.ToBTC()} 1021 } 1022 1023 // NewPsbtDataOutput returns a new instance of a PSBT data output to use with 1024 // the WalletCreateFundedPsbtCmd command. 1025 func NewPsbtDataOutput(data []byte) PsbtOutput { 1026 return PsbtOutput{"data": hex.EncodeToString(data)} 1027 } 1028 1029 // WalletCreateFundedPsbtOpts represents the optional options struct provided 1030 // with a WalletCreateFundedPsbtCmd command. 1031 type WalletCreateFundedPsbtOpts struct { 1032 ChangeAddress *string `json:"changeAddress,omitempty"` 1033 ChangePosition *int64 `json:"changePosition,omitempty"` 1034 ChangeType *ChangeType `json:"change_type,omitempty"` 1035 IncludeWatching *bool `json:"includeWatching,omitempty"` 1036 LockUnspents *bool `json:"lockUnspents,omitempty"` 1037 FeeRate *float64 `json:"feeRate,omitempty"` 1038 SubtractFeeFromOutputs *[]int64 `json:"subtractFeeFromOutputs,omitempty"` 1039 Replaceable *bool `json:"replaceable,omitempty"` 1040 ConfTarget *int64 `json:"conf_target,omitempty"` 1041 EstimateMode *string `json:"estimate_mode,omitempty"` 1042 } 1043 1044 // WalletCreateFundedPsbtCmd defines the walletcreatefundedpsbt JSON-RPC command. 1045 type WalletCreateFundedPsbtCmd struct { 1046 Inputs []PsbtInput 1047 Outputs []PsbtOutput 1048 Locktime *uint32 1049 Options *WalletCreateFundedPsbtOpts 1050 Bip32Derivs *bool 1051 } 1052 1053 // NewWalletCreateFundedPsbtCmd returns a new instance which can be used to issue a 1054 // walletcreatefundedpsbt JSON-RPC command. 1055 func NewWalletCreateFundedPsbtCmd( 1056 inputs []PsbtInput, outputs []PsbtOutput, locktime *uint32, 1057 options *WalletCreateFundedPsbtOpts, bip32Derivs *bool, 1058 ) *WalletCreateFundedPsbtCmd { 1059 return &WalletCreateFundedPsbtCmd{ 1060 Inputs: inputs, 1061 Outputs: outputs, 1062 Locktime: locktime, 1063 Options: options, 1064 Bip32Derivs: bip32Derivs, 1065 } 1066 } 1067 1068 // WalletProcessPsbtCmd defines the walletprocesspsbt JSON-RPC command. 1069 type WalletProcessPsbtCmd struct { 1070 Psbt string 1071 Sign *bool `jsonrpcdefault:"true"` 1072 SighashType *string `jsonrpcdefault:"\"ALL\""` 1073 Bip32Derivs *bool 1074 } 1075 1076 // NewWalletProcessPsbtCmd returns a new instance which can be used to issue a 1077 // walletprocesspsbt JSON-RPC command. 1078 func NewWalletProcessPsbtCmd(psbt string, sign *bool, sighashType *string, bip32Derivs *bool) *WalletProcessPsbtCmd { 1079 return &WalletProcessPsbtCmd{ 1080 Psbt: psbt, 1081 Sign: sign, 1082 SighashType: sighashType, 1083 Bip32Derivs: bip32Derivs, 1084 } 1085 } 1086 1087 func init() { 1088 // The commands in this file are only usable with a wallet server. 1089 flags := UFWalletOnly 1090 1091 MustRegisterCmd("addmultisigaddress", (*AddMultisigAddressCmd)(nil), flags) 1092 MustRegisterCmd("addwitnessaddress", (*AddWitnessAddressCmd)(nil), flags) 1093 MustRegisterCmd("backupwallet", (*BackupWalletCmd)(nil), flags) 1094 MustRegisterCmd("createmultisig", (*CreateMultisigCmd)(nil), flags) 1095 MustRegisterCmd("createwallet", (*CreateWalletCmd)(nil), flags) 1096 MustRegisterCmd("dumpprivkey", (*DumpPrivKeyCmd)(nil), flags) 1097 MustRegisterCmd("encryptwallet", (*EncryptWalletCmd)(nil), flags) 1098 MustRegisterCmd("estimatesmartfee", (*EstimateSmartFeeCmd)(nil), flags) 1099 MustRegisterCmd("estimatefee", (*EstimateFeeCmd)(nil), flags) 1100 MustRegisterCmd("estimatepriority", (*EstimatePriorityCmd)(nil), flags) 1101 MustRegisterCmd("getaccount", (*GetAccountCmd)(nil), flags) 1102 MustRegisterCmd("getaccountaddress", (*GetAccountAddressCmd)(nil), flags) 1103 MustRegisterCmd("getaddressesbyaccount", (*GetAddressesByAccountCmd)(nil), flags) 1104 MustRegisterCmd("getaddressinfo", (*GetAddressInfoCmd)(nil), flags) 1105 MustRegisterCmd("getbalance", (*GetBalanceCmd)(nil), flags) 1106 MustRegisterCmd("getbalances", (*GetBalancesCmd)(nil), flags) 1107 MustRegisterCmd("getnewaddress", (*GetNewAddressCmd)(nil), flags) 1108 MustRegisterCmd("getrawchangeaddress", (*GetRawChangeAddressCmd)(nil), flags) 1109 MustRegisterCmd("getreceivedbyaccount", (*GetReceivedByAccountCmd)(nil), flags) 1110 MustRegisterCmd("getreceivedbyaddress", (*GetReceivedByAddressCmd)(nil), flags) 1111 MustRegisterCmd("gettransaction", (*GetTransactionCmd)(nil), flags) 1112 MustRegisterCmd("getwalletinfo", (*GetWalletInfoCmd)(nil), flags) 1113 MustRegisterCmd("importmulti", (*ImportMultiCmd)(nil), flags) 1114 MustRegisterCmd("importprivkey", (*ImportPrivKeyCmd)(nil), flags) 1115 MustRegisterCmd("keypoolrefill", (*KeyPoolRefillCmd)(nil), flags) 1116 MustRegisterCmd("listaccounts", (*ListAccountsCmd)(nil), flags) 1117 MustRegisterCmd("listaddressgroupings", (*ListAddressGroupingsCmd)(nil), flags) 1118 MustRegisterCmd("listlockunspent", (*ListLockUnspentCmd)(nil), flags) 1119 MustRegisterCmd("listreceivedbyaccount", (*ListReceivedByAccountCmd)(nil), flags) 1120 MustRegisterCmd("listreceivedbyaddress", (*ListReceivedByAddressCmd)(nil), flags) 1121 MustRegisterCmd("listsinceblock", (*ListSinceBlockCmd)(nil), flags) 1122 MustRegisterCmd("listtransactions", (*ListTransactionsCmd)(nil), flags) 1123 MustRegisterCmd("listunspent", (*ListUnspentCmd)(nil), flags) 1124 MustRegisterCmd("loadwallet", (*LoadWalletCmd)(nil), flags) 1125 MustRegisterCmd("lockunspent", (*LockUnspentCmd)(nil), flags) 1126 MustRegisterCmd("move", (*MoveCmd)(nil), flags) 1127 MustRegisterCmd("sendfrom", (*SendFromCmd)(nil), flags) 1128 MustRegisterCmd("sendmany", (*SendManyCmd)(nil), flags) 1129 MustRegisterCmd("sendtoaddress", (*SendToAddressCmd)(nil), flags) 1130 MustRegisterCmd("setaccount", (*SetAccountCmd)(nil), flags) 1131 MustRegisterCmd("settxfee", (*SetTxFeeCmd)(nil), flags) 1132 MustRegisterCmd("signmessage", (*SignMessageCmd)(nil), flags) 1133 MustRegisterCmd("signrawtransaction", (*SignRawTransactionCmd)(nil), flags) 1134 MustRegisterCmd("signrawtransactionwithwallet", (*SignRawTransactionWithWalletCmd)(nil), flags) 1135 MustRegisterCmd("unloadwallet", (*UnloadWalletCmd)(nil), flags) 1136 MustRegisterCmd("walletlock", (*WalletLockCmd)(nil), flags) 1137 MustRegisterCmd("walletpassphrase", (*WalletPassphraseCmd)(nil), flags) 1138 MustRegisterCmd("walletpassphrasechange", (*WalletPassphraseChangeCmd)(nil), flags) 1139 MustRegisterCmd("walletcreatefundedpsbt", (*WalletCreateFundedPsbtCmd)(nil), flags) 1140 MustRegisterCmd("walletprocesspsbt", (*WalletProcessPsbtCmd)(nil), flags) 1141 }