github.com/lbryio/lbcd@v0.22.119/btcjson/chainsvrcmds.go (about) 1 // Copyright (c) 2014-2017 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 chain server. 7 8 package btcjson 9 10 import ( 11 "encoding/hex" 12 "encoding/json" 13 "fmt" 14 "reflect" 15 16 "github.com/lbryio/lbcd/wire" 17 ) 18 19 // AddNodeSubCmd defines the type used in the addnode JSON-RPC command for the 20 // sub command field. 21 type AddNodeSubCmd string 22 23 const ( 24 // ANAdd indicates the specified host should be added as a persistent 25 // peer. 26 ANAdd AddNodeSubCmd = "add" 27 28 // ANRemove indicates the specified peer should be removed. 29 ANRemove AddNodeSubCmd = "remove" 30 31 // ANOneTry indicates the specified host should try to connect once, 32 // but it should not be made persistent. 33 ANOneTry AddNodeSubCmd = "onetry" 34 ) 35 36 // AddNodeCmd defines the addnode JSON-RPC command. 37 type AddNodeCmd struct { 38 Addr string 39 SubCmd AddNodeSubCmd `jsonrpcusage:"\"add|remove|onetry\""` 40 } 41 42 // NewAddNodeCmd returns a new instance which can be used to issue an addnode 43 // JSON-RPC command. 44 func NewAddNodeCmd(addr string, subCmd AddNodeSubCmd) *AddNodeCmd { 45 return &AddNodeCmd{ 46 Addr: addr, 47 SubCmd: subCmd, 48 } 49 } 50 51 // ClearBannedCmd defines the clearbanned JSON-RPC command. 52 type ClearBannedCmd struct{} 53 54 // NewClearBannedCmd returns a new instance which can be used to issue an clearbanned 55 // JSON-RPC command. 56 func NewClearBannedCmd() *ClearBannedCmd { 57 return &ClearBannedCmd{} 58 } 59 60 // TransactionInput represents the inputs to a transaction. Specifically a 61 // transaction hash and output number pair. 62 type TransactionInput struct { 63 Txid string `json:"txid"` 64 Vout uint32 `json:"vout"` 65 } 66 67 // CreateRawTransactionCmd defines the createrawtransaction JSON-RPC command. 68 type CreateRawTransactionCmd struct { 69 Inputs []TransactionInput 70 Outputs map[string]interface{} `jsonrpcusage:"{\"address\":amount, \"data\":\"hex\", ...}"` 71 LockTime *int64 72 } 73 74 // NewCreateRawTransactionCmd returns a new instance which can be used to issue 75 // a createrawtransaction JSON-RPC command. 76 // 77 // Amounts are in BTC. Passing in nil and the empty slice as inputs is equivalent, 78 // both gets interpreted as the empty slice. 79 func NewCreateRawTransactionCmd(inputs []TransactionInput, outputs map[string]interface{}, 80 lockTime *int64) *CreateRawTransactionCmd { 81 // to make sure we're serializing this to the empty list and not null, we 82 // explicitly initialize the list 83 if inputs == nil { 84 inputs = []TransactionInput{} 85 } 86 return &CreateRawTransactionCmd{ 87 Inputs: inputs, 88 Outputs: outputs, 89 LockTime: lockTime, 90 } 91 } 92 93 // DecodeRawTransactionCmd defines the decoderawtransaction JSON-RPC command. 94 type DecodeRawTransactionCmd struct { 95 HexTx string 96 } 97 98 // NewDecodeRawTransactionCmd returns a new instance which can be used to issue 99 // a decoderawtransaction JSON-RPC command. 100 func NewDecodeRawTransactionCmd(hexTx string) *DecodeRawTransactionCmd { 101 return &DecodeRawTransactionCmd{ 102 HexTx: hexTx, 103 } 104 } 105 106 // DecodeScriptCmd defines the decodescript JSON-RPC command. 107 type DecodeScriptCmd struct { 108 HexScript string 109 } 110 111 // NewDecodeScriptCmd returns a new instance which can be used to issue a 112 // decodescript JSON-RPC command. 113 func NewDecodeScriptCmd(hexScript string) *DecodeScriptCmd { 114 return &DecodeScriptCmd{ 115 HexScript: hexScript, 116 } 117 } 118 119 // DeriveAddressesCmd defines the deriveaddresses JSON-RPC command. 120 type DeriveAddressesCmd struct { 121 Descriptor string 122 Range *DescriptorRange 123 } 124 125 // NewDeriveAddressesCmd returns a new instance which can be used to issue a 126 // deriveaddresses JSON-RPC command. 127 func NewDeriveAddressesCmd(descriptor string, descriptorRange *DescriptorRange) *DeriveAddressesCmd { 128 return &DeriveAddressesCmd{ 129 Descriptor: descriptor, 130 Range: descriptorRange, 131 } 132 } 133 134 // ChangeType defines the different output types to use for the change address 135 // of a transaction built by the node. 136 type ChangeType string 137 138 var ( 139 // ChangeTypeLegacy indicates a P2PKH change address type. 140 ChangeTypeLegacy ChangeType = "legacy" 141 // ChangeTypeP2SHSegWit indicates a P2WPKH-in-P2SH change address type. 142 ChangeTypeP2SHSegWit ChangeType = "p2sh-segwit" 143 // ChangeTypeBech32 indicates a P2WPKH change address type. 144 ChangeTypeBech32 ChangeType = "bech32" 145 ) 146 147 // FundRawTransactionOpts are the different options that can be passed to rawtransaction 148 type FundRawTransactionOpts struct { 149 ChangeAddress *string `json:"changeAddress,omitempty"` 150 ChangePosition *int `json:"changePosition,omitempty"` 151 ChangeType *ChangeType `json:"change_type,omitempty"` 152 IncludeWatching *bool `json:"includeWatching,omitempty"` 153 LockUnspents *bool `json:"lockUnspents,omitempty"` 154 FeeRate *float64 `json:"feeRate,omitempty"` // BTC/kB 155 SubtractFeeFromOutputs []int `json:"subtractFeeFromOutputs,omitempty"` 156 Replaceable *bool `json:"replaceable,omitempty"` 157 ConfTarget *int `json:"conf_target,omitempty"` 158 EstimateMode *EstimateSmartFeeMode `json:"estimate_mode,omitempty"` 159 } 160 161 // FundRawTransactionCmd defines the fundrawtransaction JSON-RPC command 162 type FundRawTransactionCmd struct { 163 HexTx string 164 Options FundRawTransactionOpts 165 IsWitness *bool 166 } 167 168 // NewFundRawTransactionCmd returns a new instance which can be used to issue 169 // a fundrawtransaction JSON-RPC command 170 func NewFundRawTransactionCmd(serializedTx []byte, opts FundRawTransactionOpts, isWitness *bool) *FundRawTransactionCmd { 171 return &FundRawTransactionCmd{ 172 HexTx: hex.EncodeToString(serializedTx), 173 Options: opts, 174 IsWitness: isWitness, 175 } 176 } 177 178 // GetAddedNodeInfoCmd defines the getaddednodeinfo JSON-RPC command. 179 type GetAddedNodeInfoCmd struct { 180 DNS bool 181 Node *string 182 } 183 184 // NewGetAddedNodeInfoCmd returns a new instance which can be used to issue a 185 // getaddednodeinfo JSON-RPC command. 186 // 187 // The parameters which are pointers indicate they are optional. Passing nil 188 // for optional parameters will use the default value. 189 func NewGetAddedNodeInfoCmd(dns bool, node *string) *GetAddedNodeInfoCmd { 190 return &GetAddedNodeInfoCmd{ 191 DNS: dns, 192 Node: node, 193 } 194 } 195 196 // GetBestBlockHashCmd defines the getbestblockhash JSON-RPC command. 197 type GetBestBlockHashCmd struct{} 198 199 // NewGetBestBlockHashCmd returns a new instance which can be used to issue a 200 // getbestblockhash JSON-RPC command. 201 func NewGetBestBlockHashCmd() *GetBestBlockHashCmd { 202 return &GetBestBlockHashCmd{} 203 } 204 205 // GetBlockCmd defines the getblock JSON-RPC command. 206 type GetBlockCmd struct { 207 Hash string 208 Verbosity *int `jsonrpcdefault:"1"` 209 } 210 211 // NewGetBlockCmd returns a new instance which can be used to issue a getblock 212 // JSON-RPC command. 213 // 214 // The parameters which are pointers indicate they are optional. Passing nil 215 // for optional parameters will use the default value. 216 func NewGetBlockCmd(hash string, verbosity *int) *GetBlockCmd { 217 return &GetBlockCmd{ 218 Hash: hash, 219 Verbosity: verbosity, 220 } 221 } 222 223 // GetBlockChainInfoCmd defines the getblockchaininfo JSON-RPC command. 224 type GetBlockChainInfoCmd struct{} 225 226 // NewGetBlockChainInfoCmd returns a new instance which can be used to issue a 227 // getblockchaininfo JSON-RPC command. 228 func NewGetBlockChainInfoCmd() *GetBlockChainInfoCmd { 229 return &GetBlockChainInfoCmd{} 230 } 231 232 // GetBlockCountCmd defines the getblockcount JSON-RPC command. 233 type GetBlockCountCmd struct{} 234 235 // NewGetBlockCountCmd returns a new instance which can be used to issue a 236 // getblockcount JSON-RPC command. 237 func NewGetBlockCountCmd() *GetBlockCountCmd { 238 return &GetBlockCountCmd{} 239 } 240 241 // FilterTypeName defines the type used in the getblockfilter JSON-RPC command for the 242 // filter type field. 243 type FilterTypeName string 244 245 const ( 246 // FilterTypeBasic is the basic filter type defined in BIP0158. 247 FilterTypeBasic FilterTypeName = "basic" 248 ) 249 250 // GetBlockFilterCmd defines the getblockfilter JSON-RPC command. 251 type GetBlockFilterCmd struct { 252 BlockHash string // The hash of the block 253 FilterType *FilterTypeName // The type name of the filter, default=basic 254 } 255 256 // NewGetBlockFilterCmd returns a new instance which can be used to issue a 257 // getblockfilter JSON-RPC command. 258 // 259 // The parameters which are pointers indicate they are optional. Passing nil 260 // for optional parameters will use the default value. 261 func NewGetBlockFilterCmd(blockHash string, filterType *FilterTypeName) *GetBlockFilterCmd { 262 return &GetBlockFilterCmd{ 263 BlockHash: blockHash, 264 FilterType: filterType, 265 } 266 } 267 268 // GetBlockHashCmd defines the getblockhash JSON-RPC command. 269 type GetBlockHashCmd struct { 270 Index int64 271 } 272 273 // NewGetBlockHashCmd returns a new instance which can be used to issue a 274 // getblockhash JSON-RPC command. 275 func NewGetBlockHashCmd(index int64) *GetBlockHashCmd { 276 return &GetBlockHashCmd{ 277 Index: index, 278 } 279 } 280 281 // GetBlockHeaderCmd defines the getblockheader JSON-RPC command. 282 type GetBlockHeaderCmd struct { 283 Hash string 284 Verbose *bool `jsonrpcdefault:"true"` 285 } 286 287 // NewGetBlockHeaderCmd returns a new instance which can be used to issue a 288 // getblockheader JSON-RPC command. 289 func NewGetBlockHeaderCmd(hash string, verbose *bool) *GetBlockHeaderCmd { 290 return &GetBlockHeaderCmd{ 291 Hash: hash, 292 Verbose: verbose, 293 } 294 } 295 296 // HashOrHeight defines a type that can be used as hash_or_height value in JSON-RPC commands. 297 type HashOrHeight struct { 298 Value interface{} 299 } 300 301 // MarshalJSON implements the json.Marshaler interface 302 func (h HashOrHeight) MarshalJSON() ([]byte, error) { 303 return json.Marshal(h.Value) 304 } 305 306 // UnmarshalJSON implements the json.Unmarshaler interface 307 func (h *HashOrHeight) UnmarshalJSON(data []byte) error { 308 var unmarshalled interface{} 309 if err := json.Unmarshal(data, &unmarshalled); err != nil { 310 return err 311 } 312 313 switch v := unmarshalled.(type) { 314 case float64: 315 h.Value = int(v) 316 case string: 317 h.Value = v 318 default: 319 return fmt.Errorf("invalid hash_or_height value: %v", unmarshalled) 320 } 321 322 return nil 323 } 324 325 // GetBlockStatsCmd defines the getblockstats JSON-RPC command. 326 type GetBlockStatsCmd struct { 327 HashOrHeight HashOrHeight 328 Stats *[]string 329 } 330 331 // NewGetBlockStatsCmd returns a new instance which can be used to issue a 332 // getblockstats JSON-RPC command. Either height or hash must be specified. 333 func NewGetBlockStatsCmd(hashOrHeight HashOrHeight, stats *[]string) *GetBlockStatsCmd { 334 return &GetBlockStatsCmd{ 335 HashOrHeight: hashOrHeight, 336 Stats: stats, 337 } 338 } 339 340 // TemplateRequest is a request object as defined in BIP22 341 // (https://en.bitcoin.it/wiki/BIP_0022), it is optionally provided as an 342 // pointer argument to GetBlockTemplateCmd. 343 type TemplateRequest struct { 344 Mode string `json:"mode,omitempty"` 345 Capabilities []string `json:"capabilities,omitempty"` 346 347 // Optional long polling. 348 LongPollID string `json:"longpollid,omitempty"` 349 350 // Optional template tweaking. SigOpLimit and SizeLimit can be int64 351 // or bool. 352 SigOpLimit interface{} `json:"sigoplimit,omitempty"` 353 SizeLimit interface{} `json:"sizelimit,omitempty"` 354 MaxVersion uint32 `json:"maxversion,omitempty"` 355 356 // Basic pool extension from BIP 0023. 357 Target string `json:"target,omitempty"` 358 359 // Block proposal from BIP 0023. Data is only provided when Mode is 360 // "proposal". 361 Data string `json:"data,omitempty"` 362 WorkID string `json:"workid,omitempty"` 363 364 // list of supported softfork deployments, by name 365 // Ref: https://en.bitcoin.it/wiki/BIP_0009#getblocktemplate_changes. 366 Rules []string `json:"rules,omitempty"` 367 } 368 369 // convertTemplateRequestField potentially converts the provided value as 370 // needed. 371 func convertTemplateRequestField(fieldName string, iface interface{}) (interface{}, error) { 372 switch val := iface.(type) { 373 case nil: 374 return nil, nil 375 case bool: 376 return val, nil 377 case float64: 378 if val == float64(int64(val)) { 379 return int64(val), nil 380 } 381 } 382 383 str := fmt.Sprintf("the %s field must be unspecified, a boolean, or "+ 384 "a 64-bit integer", fieldName) 385 return nil, makeError(ErrInvalidType, str) 386 } 387 388 // UnmarshalJSON provides a custom Unmarshal method for TemplateRequest. This 389 // is necessary because the SigOpLimit and SizeLimit fields can only be specific 390 // types. 391 func (t *TemplateRequest) UnmarshalJSON(data []byte) error { 392 type templateRequest TemplateRequest 393 394 request := (*templateRequest)(t) 395 if err := json.Unmarshal(data, &request); err != nil { 396 return err 397 } 398 399 // The SigOpLimit field can only be nil, bool, or int64. 400 val, err := convertTemplateRequestField("sigoplimit", request.SigOpLimit) 401 if err != nil { 402 return err 403 } 404 request.SigOpLimit = val 405 406 // The SizeLimit field can only be nil, bool, or int64. 407 val, err = convertTemplateRequestField("sizelimit", request.SizeLimit) 408 if err != nil { 409 return err 410 } 411 request.SizeLimit = val 412 413 return nil 414 } 415 416 // GetBlockTemplateCmd defines the getblocktemplate JSON-RPC command. 417 type GetBlockTemplateCmd struct { 418 Request *TemplateRequest 419 } 420 421 // NewGetBlockTemplateCmd returns a new instance which can be used to issue a 422 // getblocktemplate JSON-RPC command. 423 // 424 // The parameters which are pointers indicate they are optional. Passing nil 425 // for optional parameters will use the default value. 426 func NewGetBlockTemplateCmd(request *TemplateRequest) *GetBlockTemplateCmd { 427 return &GetBlockTemplateCmd{ 428 Request: request, 429 } 430 } 431 432 // GetCFilterCmd defines the getcfilter JSON-RPC command. 433 type GetCFilterCmd struct { 434 Hash string 435 FilterType wire.FilterType 436 } 437 438 // NewGetCFilterCmd returns a new instance which can be used to issue a 439 // getcfilter JSON-RPC command. 440 func NewGetCFilterCmd(hash string, filterType wire.FilterType) *GetCFilterCmd { 441 return &GetCFilterCmd{ 442 Hash: hash, 443 FilterType: filterType, 444 } 445 } 446 447 // GetCFilterHeaderCmd defines the getcfilterheader JSON-RPC command. 448 type GetCFilterHeaderCmd struct { 449 Hash string 450 FilterType wire.FilterType 451 } 452 453 // NewGetCFilterHeaderCmd returns a new instance which can be used to issue a 454 // getcfilterheader JSON-RPC command. 455 func NewGetCFilterHeaderCmd(hash string, 456 filterType wire.FilterType) *GetCFilterHeaderCmd { 457 return &GetCFilterHeaderCmd{ 458 Hash: hash, 459 FilterType: filterType, 460 } 461 } 462 463 // GetChainTipsCmd defines the getchaintips JSON-RPC command. 464 type GetChainTipsCmd struct{} 465 466 // NewGetChainTipsCmd returns a new instance which can be used to issue a 467 // getchaintips JSON-RPC command. 468 func NewGetChainTipsCmd() *GetChainTipsCmd { 469 return &GetChainTipsCmd{} 470 } 471 472 // GetChainTxStatsCmd defines the getchaintxstats JSON-RPC command. 473 type GetChainTxStatsCmd struct { 474 NBlocks *int32 475 BlockHash *string 476 } 477 478 // NewGetChainTxStatsCmd returns a new instance which can be used to issue a 479 // getchaintxstats JSON-RPC command. 480 // 481 // The parameters which are pointers indicate they are optional. Passing nil 482 // for optional parameters will use the default value. 483 func NewGetChainTxStatsCmd(nBlocks *int32, blockHash *string) *GetChainTxStatsCmd { 484 return &GetChainTxStatsCmd{ 485 NBlocks: nBlocks, 486 BlockHash: blockHash, 487 } 488 } 489 490 // GetConnectionCountCmd defines the getconnectioncount JSON-RPC command. 491 type GetConnectionCountCmd struct{} 492 493 // NewGetConnectionCountCmd returns a new instance which can be used to issue a 494 // getconnectioncount JSON-RPC command. 495 func NewGetConnectionCountCmd() *GetConnectionCountCmd { 496 return &GetConnectionCountCmd{} 497 } 498 499 // GetDescriptorInfoCmd defines the getdescriptorinfo JSON-RPC command. 500 type GetDescriptorInfoCmd struct { 501 Descriptor string 502 } 503 504 // NewGetDescriptorInfoCmd returns a new instance which can be used to issue a 505 // getdescriptorinfo JSON-RPC command. 506 func NewGetDescriptorInfoCmd(descriptor string) *GetDescriptorInfoCmd { 507 return &GetDescriptorInfoCmd{ 508 Descriptor: descriptor, 509 } 510 } 511 512 // GetDifficultyCmd defines the getdifficulty JSON-RPC command. 513 type GetDifficultyCmd struct{} 514 515 // NewGetDifficultyCmd returns a new instance which can be used to issue a 516 // getdifficulty JSON-RPC command. 517 func NewGetDifficultyCmd() *GetDifficultyCmd { 518 return &GetDifficultyCmd{} 519 } 520 521 // GetGenerateCmd defines the getgenerate JSON-RPC command. 522 type GetGenerateCmd struct{} 523 524 // NewGetGenerateCmd returns a new instance which can be used to issue a 525 // getgenerate JSON-RPC command. 526 func NewGetGenerateCmd() *GetGenerateCmd { 527 return &GetGenerateCmd{} 528 } 529 530 // GetHashesPerSecCmd defines the gethashespersec JSON-RPC command. 531 type GetHashesPerSecCmd struct{} 532 533 // NewGetHashesPerSecCmd returns a new instance which can be used to issue a 534 // gethashespersec JSON-RPC command. 535 func NewGetHashesPerSecCmd() *GetHashesPerSecCmd { 536 return &GetHashesPerSecCmd{} 537 } 538 539 // GetInfoCmd defines the getinfo JSON-RPC command. 540 type GetInfoCmd struct{} 541 542 // NewGetInfoCmd returns a new instance which can be used to issue a 543 // getinfo JSON-RPC command. 544 func NewGetInfoCmd() *GetInfoCmd { 545 return &GetInfoCmd{} 546 } 547 548 // GetMempoolEntryCmd defines the getmempoolentry JSON-RPC command. 549 type GetMempoolEntryCmd struct { 550 TxID string 551 } 552 553 // NewGetMempoolEntryCmd returns a new instance which can be used to issue a 554 // getmempoolentry JSON-RPC command. 555 func NewGetMempoolEntryCmd(txHash string) *GetMempoolEntryCmd { 556 return &GetMempoolEntryCmd{ 557 TxID: txHash, 558 } 559 } 560 561 // GetMempoolInfoCmd defines the getmempoolinfo JSON-RPC command. 562 type GetMempoolInfoCmd struct{} 563 564 // NewGetMempoolInfoCmd returns a new instance which can be used to issue a 565 // getmempool JSON-RPC command. 566 func NewGetMempoolInfoCmd() *GetMempoolInfoCmd { 567 return &GetMempoolInfoCmd{} 568 } 569 570 // GetMiningInfoCmd defines the getmininginfo JSON-RPC command. 571 type GetMiningInfoCmd struct{} 572 573 // NewGetMiningInfoCmd returns a new instance which can be used to issue a 574 // getmininginfo JSON-RPC command. 575 func NewGetMiningInfoCmd() *GetMiningInfoCmd { 576 return &GetMiningInfoCmd{} 577 } 578 579 // GetNetworkInfoCmd defines the getnetworkinfo JSON-RPC command. 580 type GetNetworkInfoCmd struct{} 581 582 // NewGetNetworkInfoCmd returns a new instance which can be used to issue a 583 // getnetworkinfo JSON-RPC command. 584 func NewGetNetworkInfoCmd() *GetNetworkInfoCmd { 585 return &GetNetworkInfoCmd{} 586 } 587 588 // GetNetTotalsCmd defines the getnettotals JSON-RPC command. 589 type GetNetTotalsCmd struct{} 590 591 // NewGetNetTotalsCmd returns a new instance which can be used to issue a 592 // getnettotals JSON-RPC command. 593 func NewGetNetTotalsCmd() *GetNetTotalsCmd { 594 return &GetNetTotalsCmd{} 595 } 596 597 // GetNetworkHashPSCmd defines the getnetworkhashps JSON-RPC command. 598 type GetNetworkHashPSCmd struct { 599 Blocks *int `jsonrpcdefault:"120"` 600 Height *int `jsonrpcdefault:"-1"` 601 } 602 603 // NewGetNetworkHashPSCmd returns a new instance which can be used to issue a 604 // getnetworkhashps JSON-RPC command. 605 // 606 // The parameters which are pointers indicate they are optional. Passing nil 607 // for optional parameters will use the default value. 608 func NewGetNetworkHashPSCmd(numBlocks, height *int) *GetNetworkHashPSCmd { 609 return &GetNetworkHashPSCmd{ 610 Blocks: numBlocks, 611 Height: height, 612 } 613 } 614 615 // GetNodeAddressesCmd defines the getnodeaddresses JSON-RPC command. 616 type GetNodeAddressesCmd struct { 617 Count *int32 `jsonrpcdefault:"1"` 618 } 619 620 // NewGetNodeAddressesCmd returns a new instance which can be used to issue a 621 // getnodeaddresses 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 NewGetNodeAddressesCmd(count *int32) *GetNodeAddressesCmd { 626 return &GetNodeAddressesCmd{ 627 Count: count, 628 } 629 } 630 631 // GetPeerInfoCmd defines the getpeerinfo JSON-RPC command. 632 type GetPeerInfoCmd struct{} 633 634 // NewGetPeerInfoCmd returns a new instance which can be used to issue a getpeer 635 // JSON-RPC command. 636 func NewGetPeerInfoCmd() *GetPeerInfoCmd { 637 return &GetPeerInfoCmd{} 638 } 639 640 // GetRawMempoolCmd defines the getmempool JSON-RPC command. 641 type GetRawMempoolCmd struct { 642 Verbose *bool `jsonrpcdefault:"false"` 643 } 644 645 // NewGetRawMempoolCmd returns a new instance which can be used to issue a 646 // getrawmempool JSON-RPC command. 647 // 648 // The parameters which are pointers indicate they are optional. Passing nil 649 // for optional parameters will use the default value. 650 func NewGetRawMempoolCmd(verbose *bool) *GetRawMempoolCmd { 651 return &GetRawMempoolCmd{ 652 Verbose: verbose, 653 } 654 } 655 656 // GetRawTransactionCmd defines the getrawtransaction JSON-RPC command. 657 // 658 // NOTE: This field is an int versus a bool to remain compatible with Bitcoin 659 // Core even though it really should be a bool. 660 type GetRawTransactionCmd struct { 661 Txid string 662 Verbose *bool `jsonrpcdefault:"false"` 663 } 664 665 // NewGetRawTransactionCmd returns a new instance which can be used to issue a 666 // getrawtransaction JSON-RPC command. 667 // 668 // The parameters which are pointers indicate they are optional. Passing nil 669 // for optional parameters will use the default value. 670 func NewGetRawTransactionCmd(txHash string, verbose *bool) *GetRawTransactionCmd { 671 return &GetRawTransactionCmd{ 672 Txid: txHash, 673 Verbose: verbose, 674 } 675 } 676 677 // GetTxOutCmd defines the gettxout JSON-RPC command. 678 type GetTxOutCmd struct { 679 Txid string 680 Vout uint32 681 IncludeMempool *bool `jsonrpcdefault:"true"` 682 } 683 684 // NewGetTxOutCmd returns a new instance which can be used to issue a gettxout 685 // JSON-RPC command. 686 // 687 // The parameters which are pointers indicate they are optional. Passing nil 688 // for optional parameters will use the default value. 689 func NewGetTxOutCmd(txHash string, vout uint32, includeMempool *bool) *GetTxOutCmd { 690 return &GetTxOutCmd{ 691 Txid: txHash, 692 Vout: vout, 693 IncludeMempool: includeMempool, 694 } 695 } 696 697 // GetTxOutProofCmd defines the gettxoutproof JSON-RPC command. 698 type GetTxOutProofCmd struct { 699 TxIDs []string 700 BlockHash *string 701 } 702 703 // NewGetTxOutProofCmd returns a new instance which can be used to issue a 704 // gettxoutproof JSON-RPC command. 705 // 706 // The parameters which are pointers indicate they are optional. Passing nil 707 // for optional parameters will use the default value. 708 func NewGetTxOutProofCmd(txIDs []string, blockHash *string) *GetTxOutProofCmd { 709 return &GetTxOutProofCmd{ 710 TxIDs: txIDs, 711 BlockHash: blockHash, 712 } 713 } 714 715 // GetTxOutSetInfoCmd defines the gettxoutsetinfo JSON-RPC command. 716 type GetTxOutSetInfoCmd struct{} 717 718 // NewGetTxOutSetInfoCmd returns a new instance which can be used to issue a 719 // gettxoutsetinfo JSON-RPC command. 720 func NewGetTxOutSetInfoCmd() *GetTxOutSetInfoCmd { 721 return &GetTxOutSetInfoCmd{} 722 } 723 724 // GetWorkCmd defines the getwork JSON-RPC command. 725 type GetWorkCmd struct { 726 Data *string 727 } 728 729 // NewGetWorkCmd returns a new instance which can be used to issue a getwork 730 // JSON-RPC command. 731 // 732 // The parameters which are pointers indicate they are optional. Passing nil 733 // for optional parameters will use the default value. 734 func NewGetWorkCmd(data *string) *GetWorkCmd { 735 return &GetWorkCmd{ 736 Data: data, 737 } 738 } 739 740 // HelpCmd defines the help JSON-RPC command. 741 type HelpCmd struct { 742 Command *string 743 } 744 745 // NewHelpCmd returns a new instance which can be used to issue a help JSON-RPC 746 // command. 747 // 748 // The parameters which are pointers indicate they are optional. Passing nil 749 // for optional parameters will use the default value. 750 func NewHelpCmd(command *string) *HelpCmd { 751 return &HelpCmd{ 752 Command: command, 753 } 754 } 755 756 // InvalidateBlockCmd defines the invalidateblock JSON-RPC command. 757 type InvalidateBlockCmd struct { 758 BlockHash string 759 } 760 761 // NewInvalidateBlockCmd returns a new instance which can be used to issue a 762 // invalidateblock JSON-RPC command. 763 func NewInvalidateBlockCmd(blockHash string) *InvalidateBlockCmd { 764 return &InvalidateBlockCmd{ 765 BlockHash: blockHash, 766 } 767 } 768 769 // ListBannedCmd defines the listbanned JSON-RPC command. 770 type ListBannedCmd struct{} 771 772 // NewListBannedCmd returns a new instance which can be used to issue a listbanned 773 // JSON-RPC command. 774 func NewListBannedCmd() *ListBannedCmd { 775 return &ListBannedCmd{} 776 } 777 778 // PingCmd defines the ping JSON-RPC command. 779 type PingCmd struct{} 780 781 // NewPingCmd returns a new instance which can be used to issue a ping JSON-RPC 782 // command. 783 func NewPingCmd() *PingCmd { 784 return &PingCmd{} 785 } 786 787 // PreciousBlockCmd defines the preciousblock JSON-RPC command. 788 type PreciousBlockCmd struct { 789 BlockHash string 790 } 791 792 // NewPreciousBlockCmd returns a new instance which can be used to issue a 793 // preciousblock JSON-RPC command. 794 func NewPreciousBlockCmd(blockHash string) *PreciousBlockCmd { 795 return &PreciousBlockCmd{ 796 BlockHash: blockHash, 797 } 798 } 799 800 // ReconsiderBlockCmd defines the reconsiderblock JSON-RPC command. 801 type ReconsiderBlockCmd struct { 802 BlockHash string 803 } 804 805 // NewReconsiderBlockCmd returns a new instance which can be used to issue a 806 // reconsiderblock JSON-RPC command. 807 func NewReconsiderBlockCmd(blockHash string) *ReconsiderBlockCmd { 808 return &ReconsiderBlockCmd{ 809 BlockHash: blockHash, 810 } 811 } 812 813 // SearchRawTransactionsCmd defines the searchrawtransactions JSON-RPC command. 814 type SearchRawTransactionsCmd struct { 815 Address string 816 Verbose *int `jsonrpcdefault:"1"` 817 Skip *int `jsonrpcdefault:"0"` 818 Count *int `jsonrpcdefault:"100"` 819 VinExtra *int `jsonrpcdefault:"0"` 820 Reverse *bool `jsonrpcdefault:"false"` 821 FilterAddrs *[]string 822 } 823 824 // NewSearchRawTransactionsCmd returns a new instance which can be used to issue a 825 // sendrawtransaction JSON-RPC command. 826 // 827 // The parameters which are pointers indicate they are optional. Passing nil 828 // for optional parameters will use the default value. 829 func NewSearchRawTransactionsCmd(address string, verbose, skip, count *int, vinExtra *int, reverse *bool, filterAddrs *[]string) *SearchRawTransactionsCmd { 830 return &SearchRawTransactionsCmd{ 831 Address: address, 832 Verbose: verbose, 833 Skip: skip, 834 Count: count, 835 VinExtra: vinExtra, 836 Reverse: reverse, 837 FilterAddrs: filterAddrs, 838 } 839 } 840 841 // AllowHighFeesOrMaxFeeRate defines a type that can either be the legacy 842 // allowhighfees boolean field or the new maxfeerate int field. 843 type AllowHighFeesOrMaxFeeRate struct { 844 Value interface{} 845 } 846 847 // String returns the string representation of this struct, used for printing 848 // the marshaled default value in the help text. 849 func (a AllowHighFeesOrMaxFeeRate) String() string { 850 b, _ := a.MarshalJSON() 851 return string(b) 852 } 853 854 // MarshalJSON implements the json.Marshaler interface 855 func (a AllowHighFeesOrMaxFeeRate) MarshalJSON() ([]byte, error) { 856 // The default value is false which only works with the legacy versions. 857 if a.Value == nil || 858 (reflect.ValueOf(a.Value).Kind() == reflect.Ptr && 859 reflect.ValueOf(a.Value).IsNil()) { 860 861 return json.Marshal(false) 862 } 863 864 return json.Marshal(a.Value) 865 } 866 867 // UnmarshalJSON implements the json.Unmarshaler interface 868 func (a *AllowHighFeesOrMaxFeeRate) UnmarshalJSON(data []byte) error { 869 if len(data) == 0 { 870 return nil 871 } 872 873 var unmarshalled interface{} 874 if err := json.Unmarshal(data, &unmarshalled); err != nil { 875 return err 876 } 877 878 switch v := unmarshalled.(type) { 879 case bool: 880 a.Value = Bool(v) 881 case float64: 882 a.Value = Int32(int32(v)) 883 default: 884 return fmt.Errorf("invalid allowhighfees or maxfeerate value: "+ 885 "%v", unmarshalled) 886 } 887 888 return nil 889 } 890 891 // SendRawTransactionCmd defines the sendrawtransaction JSON-RPC command. 892 type SendRawTransactionCmd struct { 893 HexTx string 894 FeeSetting *AllowHighFeesOrMaxFeeRate `jsonrpcdefault:"false"` 895 } 896 897 // NewSendRawTransactionCmd returns a new instance which can be used to issue a 898 // sendrawtransaction JSON-RPC command. 899 // 900 // The parameters which are pointers indicate they are optional. Passing nil 901 // for optional parameters will use the default value. 902 func NewSendRawTransactionCmd(hexTx string, allowHighFees *bool) *SendRawTransactionCmd { 903 return &SendRawTransactionCmd{ 904 HexTx: hexTx, 905 FeeSetting: &AllowHighFeesOrMaxFeeRate{ 906 Value: allowHighFees, 907 }, 908 } 909 } 910 911 // NewSendRawTransactionCmd returns a new instance which can be used to issue a 912 // sendrawtransaction JSON-RPC command to a bitcoind node. 913 // 914 // A 0 maxFeeRate indicates that a maximum fee rate won't be enforced. 915 func NewBitcoindSendRawTransactionCmd(hexTx string, maxFeeRate int32) *SendRawTransactionCmd { 916 return &SendRawTransactionCmd{ 917 HexTx: hexTx, 918 FeeSetting: &AllowHighFeesOrMaxFeeRate{ 919 Value: &maxFeeRate, 920 }, 921 } 922 } 923 924 // SetBanSubCmd defines the type used in the setban JSON-RPC command for the 925 // sub command field. 926 type SetBanSubCmd string 927 928 const ( 929 // SBAdd indicates the specified host should be added as a persistent 930 // peer. 931 SBAdd SetBanSubCmd = "add" 932 933 // SBRemove indicates the specified peer should be removed. 934 SBRemove SetBanSubCmd = "remove" 935 ) 936 937 // SetBanCmd defines the setban JSON-RPC command. 938 type SetBanCmd struct { 939 Addr string 940 SubCmd SetBanSubCmd `jsonrpcusage:"\"add|remove\""` 941 BanTime *int `jsonrpcdefault:"0"` 942 Absolute *bool `jsonrpcdefault:"false"` 943 } 944 945 // NewSetBanCmd returns a new instance which can be used to issue an setban 946 // JSON-RPC command. 947 func NewSetBanCmd(addr string, subCmd SetBanSubCmd, banTime *int, 948 absolute *bool) *SetBanCmd { 949 return &SetBanCmd{ 950 Addr: addr, 951 SubCmd: subCmd, 952 BanTime: banTime, 953 Absolute: absolute, 954 } 955 } 956 957 // SetGenerateCmd defines the setgenerate JSON-RPC command. 958 type SetGenerateCmd struct { 959 Generate bool 960 GenProcLimit *int `jsonrpcdefault:"-1"` 961 } 962 963 // NewSetGenerateCmd returns a new instance which can be used to issue a 964 // setgenerate JSON-RPC command. 965 // 966 // The parameters which are pointers indicate they are optional. Passing nil 967 // for optional parameters will use the default value. 968 func NewSetGenerateCmd(generate bool, genProcLimit *int) *SetGenerateCmd { 969 return &SetGenerateCmd{ 970 Generate: generate, 971 GenProcLimit: genProcLimit, 972 } 973 } 974 975 // SignMessageWithPrivKeyCmd defines the signmessagewithprivkey JSON-RPC command. 976 type SignMessageWithPrivKeyCmd struct { 977 PrivKey string // base 58 Wallet Import format private key 978 Message string // Message to sign 979 } 980 981 // NewSignMessageWithPrivKey returns a new instance which can be used to issue a 982 // signmessagewithprivkey JSON-RPC command. 983 // 984 // The first parameter is a private key in base 58 Wallet Import format. 985 // The second parameter is the message to sign. 986 func NewSignMessageWithPrivKey(privKey, message string) *SignMessageWithPrivKeyCmd { 987 return &SignMessageWithPrivKeyCmd{ 988 PrivKey: privKey, 989 Message: message, 990 } 991 } 992 993 // StopCmd defines the stop JSON-RPC command. 994 type StopCmd struct{} 995 996 // NewStopCmd returns a new instance which can be used to issue a stop JSON-RPC 997 // command. 998 func NewStopCmd() *StopCmd { 999 return &StopCmd{} 1000 } 1001 1002 // SubmitBlockOptions represents the optional options struct provided with a 1003 // SubmitBlockCmd command. 1004 type SubmitBlockOptions struct { 1005 // must be provided if server provided a workid with template. 1006 WorkID string `json:"workid,omitempty"` 1007 } 1008 1009 // SubmitBlockCmd defines the submitblock JSON-RPC command. 1010 type SubmitBlockCmd struct { 1011 HexBlock string 1012 Options *SubmitBlockOptions 1013 } 1014 1015 // NewSubmitBlockCmd returns a new instance which can be used to issue a 1016 // submitblock JSON-RPC command. 1017 // 1018 // The parameters which are pointers indicate they are optional. Passing nil 1019 // for optional parameters will use the default value. 1020 func NewSubmitBlockCmd(hexBlock string, options *SubmitBlockOptions) *SubmitBlockCmd { 1021 return &SubmitBlockCmd{ 1022 HexBlock: hexBlock, 1023 Options: options, 1024 } 1025 } 1026 1027 // UptimeCmd defines the uptime JSON-RPC command. 1028 type UptimeCmd struct{} 1029 1030 // NewUptimeCmd returns a new instance which can be used to issue an uptime JSON-RPC command. 1031 func NewUptimeCmd() *UptimeCmd { 1032 return &UptimeCmd{} 1033 } 1034 1035 // ValidateAddressCmd defines the validateaddress JSON-RPC command. 1036 type ValidateAddressCmd struct { 1037 Address string 1038 } 1039 1040 // NewValidateAddressCmd returns a new instance which can be used to issue a 1041 // validateaddress JSON-RPC command. 1042 func NewValidateAddressCmd(address string) *ValidateAddressCmd { 1043 return &ValidateAddressCmd{ 1044 Address: address, 1045 } 1046 } 1047 1048 // VerifyChainCmd defines the verifychain JSON-RPC command. 1049 type VerifyChainCmd struct { 1050 CheckLevel *int32 `jsonrpcdefault:"3"` 1051 CheckDepth *int32 `jsonrpcdefault:"288"` // 0 = all 1052 } 1053 1054 // NewVerifyChainCmd returns a new instance which can be used to issue a 1055 // verifychain JSON-RPC command. 1056 // 1057 // The parameters which are pointers indicate they are optional. Passing nil 1058 // for optional parameters will use the default value. 1059 func NewVerifyChainCmd(checkLevel, checkDepth *int32) *VerifyChainCmd { 1060 return &VerifyChainCmd{ 1061 CheckLevel: checkLevel, 1062 CheckDepth: checkDepth, 1063 } 1064 } 1065 1066 // VerifyMessageCmd defines the verifymessage JSON-RPC command. 1067 type VerifyMessageCmd struct { 1068 Address string 1069 Signature string 1070 Message string 1071 } 1072 1073 // NewVerifyMessageCmd returns a new instance which can be used to issue a 1074 // verifymessage JSON-RPC command. 1075 func NewVerifyMessageCmd(address, signature, message string) *VerifyMessageCmd { 1076 return &VerifyMessageCmd{ 1077 Address: address, 1078 Signature: signature, 1079 Message: message, 1080 } 1081 } 1082 1083 // VerifyTxOutProofCmd defines the verifytxoutproof JSON-RPC command. 1084 type VerifyTxOutProofCmd struct { 1085 Proof string 1086 } 1087 1088 // NewVerifyTxOutProofCmd returns a new instance which can be used to issue a 1089 // verifytxoutproof JSON-RPC command. 1090 func NewVerifyTxOutProofCmd(proof string) *VerifyTxOutProofCmd { 1091 return &VerifyTxOutProofCmd{ 1092 Proof: proof, 1093 } 1094 } 1095 1096 func init() { 1097 // No special flags for commands in this file. 1098 flags := UsageFlag(0) 1099 1100 MustRegisterCmd("addnode", (*AddNodeCmd)(nil), flags) 1101 MustRegisterCmd("createrawtransaction", (*CreateRawTransactionCmd)(nil), flags) 1102 MustRegisterCmd("decoderawtransaction", (*DecodeRawTransactionCmd)(nil), flags) 1103 MustRegisterCmd("decodescript", (*DecodeScriptCmd)(nil), flags) 1104 MustRegisterCmd("deriveaddresses", (*DeriveAddressesCmd)(nil), flags) 1105 MustRegisterCmd("fundrawtransaction", (*FundRawTransactionCmd)(nil), flags) 1106 MustRegisterCmd("getaddednodeinfo", (*GetAddedNodeInfoCmd)(nil), flags) 1107 MustRegisterCmd("getbestblockhash", (*GetBestBlockHashCmd)(nil), flags) 1108 MustRegisterCmd("getblock", (*GetBlockCmd)(nil), flags) 1109 MustRegisterCmd("getblockchaininfo", (*GetBlockChainInfoCmd)(nil), flags) 1110 MustRegisterCmd("getblockcount", (*GetBlockCountCmd)(nil), flags) 1111 MustRegisterCmd("getblockfilter", (*GetBlockFilterCmd)(nil), flags) 1112 MustRegisterCmd("getblockhash", (*GetBlockHashCmd)(nil), flags) 1113 MustRegisterCmd("getblockheader", (*GetBlockHeaderCmd)(nil), flags) 1114 MustRegisterCmd("getblockstats", (*GetBlockStatsCmd)(nil), flags) 1115 MustRegisterCmd("getblocktemplate", (*GetBlockTemplateCmd)(nil), flags) 1116 MustRegisterCmd("getcfilter", (*GetCFilterCmd)(nil), flags) 1117 MustRegisterCmd("getcfilterheader", (*GetCFilterHeaderCmd)(nil), flags) 1118 MustRegisterCmd("getchaintips", (*GetChainTipsCmd)(nil), flags) 1119 MustRegisterCmd("getchaintxstats", (*GetChainTxStatsCmd)(nil), flags) 1120 MustRegisterCmd("getconnectioncount", (*GetConnectionCountCmd)(nil), flags) 1121 MustRegisterCmd("getdescriptorinfo", (*GetDescriptorInfoCmd)(nil), flags) 1122 MustRegisterCmd("getdifficulty", (*GetDifficultyCmd)(nil), flags) 1123 MustRegisterCmd("getgenerate", (*GetGenerateCmd)(nil), flags) 1124 MustRegisterCmd("gethashespersec", (*GetHashesPerSecCmd)(nil), flags) 1125 MustRegisterCmd("getinfo", (*GetInfoCmd)(nil), flags) 1126 MustRegisterCmd("getmempoolentry", (*GetMempoolEntryCmd)(nil), flags) 1127 MustRegisterCmd("getmempoolinfo", (*GetMempoolInfoCmd)(nil), flags) 1128 MustRegisterCmd("getmininginfo", (*GetMiningInfoCmd)(nil), flags) 1129 MustRegisterCmd("getnetworkinfo", (*GetNetworkInfoCmd)(nil), flags) 1130 MustRegisterCmd("getnettotals", (*GetNetTotalsCmd)(nil), flags) 1131 MustRegisterCmd("getnetworkhashps", (*GetNetworkHashPSCmd)(nil), flags) 1132 MustRegisterCmd("getnodeaddresses", (*GetNodeAddressesCmd)(nil), flags) 1133 MustRegisterCmd("getpeerinfo", (*GetPeerInfoCmd)(nil), flags) 1134 MustRegisterCmd("listbanned", (*ListBannedCmd)(nil), flags) 1135 MustRegisterCmd("setban", (*SetBanCmd)(nil), flags) 1136 MustRegisterCmd("clearbanned", (*ClearBannedCmd)(nil), flags) 1137 MustRegisterCmd("getrawmempool", (*GetRawMempoolCmd)(nil), flags) 1138 MustRegisterCmd("getrawtransaction", (*GetRawTransactionCmd)(nil), flags) 1139 MustRegisterCmd("gettxout", (*GetTxOutCmd)(nil), flags) 1140 MustRegisterCmd("gettxoutproof", (*GetTxOutProofCmd)(nil), flags) 1141 MustRegisterCmd("gettxoutsetinfo", (*GetTxOutSetInfoCmd)(nil), flags) 1142 MustRegisterCmd("getwork", (*GetWorkCmd)(nil), flags) 1143 MustRegisterCmd("help", (*HelpCmd)(nil), flags) 1144 MustRegisterCmd("invalidateblock", (*InvalidateBlockCmd)(nil), flags) 1145 MustRegisterCmd("ping", (*PingCmd)(nil), flags) 1146 MustRegisterCmd("preciousblock", (*PreciousBlockCmd)(nil), flags) 1147 MustRegisterCmd("reconsiderblock", (*ReconsiderBlockCmd)(nil), flags) 1148 MustRegisterCmd("searchrawtransactions", (*SearchRawTransactionsCmd)(nil), flags) 1149 MustRegisterCmd("sendrawtransaction", (*SendRawTransactionCmd)(nil), flags) 1150 MustRegisterCmd("setgenerate", (*SetGenerateCmd)(nil), flags) 1151 MustRegisterCmd("signmessagewithprivkey", (*SignMessageWithPrivKeyCmd)(nil), flags) 1152 MustRegisterCmd("stop", (*StopCmd)(nil), flags) 1153 MustRegisterCmd("submitblock", (*SubmitBlockCmd)(nil), flags) 1154 MustRegisterCmd("uptime", (*UptimeCmd)(nil), flags) 1155 MustRegisterCmd("validateaddress", (*ValidateAddressCmd)(nil), flags) 1156 MustRegisterCmd("verifychain", (*VerifyChainCmd)(nil), flags) 1157 MustRegisterCmd("verifymessage", (*VerifyMessageCmd)(nil), flags) 1158 MustRegisterCmd("verifytxoutproof", (*VerifyTxOutProofCmd)(nil), flags) 1159 }