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