github.com/lbryio/lbcd@v0.22.119/btcjson/btcdextcmds.go (about) 1 // Copyright (c) 2014-2016 The btcsuite developers 2 // Copyright (c) 2015-2016 The Decred developers 3 // Use of this source code is governed by an ISC 4 // license that can be found in the LICENSE file. 5 6 // NOTE: This file is intended to house the RPC commands that are supported by 7 // a chain server with btcd extensions. 8 9 package btcjson 10 11 // NodeSubCmd defines the type used in the addnode JSON-RPC command for the 12 // sub command field. 13 type NodeSubCmd string 14 15 const ( 16 // NConnect indicates the specified host that should be connected to. 17 NConnect NodeSubCmd = "connect" 18 19 // NRemove indicates the specified peer that should be removed as a 20 // persistent peer. 21 NRemove NodeSubCmd = "remove" 22 23 // NDisconnect indicates the specified peer should be disonnected. 24 NDisconnect NodeSubCmd = "disconnect" 25 ) 26 27 // NodeCmd defines the dropnode JSON-RPC command. 28 type NodeCmd struct { 29 SubCmd NodeSubCmd `jsonrpcusage:"\"connect|remove|disconnect\""` 30 Target string 31 ConnectSubCmd *string `jsonrpcusage:"\"perm|temp\""` 32 } 33 34 // NewNodeCmd returns a new instance which can be used to issue a `node` 35 // JSON-RPC command. 36 // 37 // The parameters which are pointers indicate they are optional. Passing nil 38 // for optional parameters will use the default value. 39 func NewNodeCmd(subCmd NodeSubCmd, target string, connectSubCmd *string) *NodeCmd { 40 return &NodeCmd{ 41 SubCmd: subCmd, 42 Target: target, 43 ConnectSubCmd: connectSubCmd, 44 } 45 } 46 47 // DebugLevelCmd defines the debuglevel JSON-RPC command. This command is not a 48 // standard Bitcoin command. It is an extension for btcd. 49 type DebugLevelCmd struct { 50 LevelSpec string 51 } 52 53 // NewDebugLevelCmd returns a new DebugLevelCmd which can be used to issue a 54 // debuglevel JSON-RPC command. This command is not a standard Bitcoin command. 55 // It is an extension for btcd. 56 func NewDebugLevelCmd(levelSpec string) *DebugLevelCmd { 57 return &DebugLevelCmd{ 58 LevelSpec: levelSpec, 59 } 60 } 61 62 // GenerateToAddressCmd defines the generatetoaddress JSON-RPC command. 63 type GenerateToAddressCmd struct { 64 NumBlocks int64 65 Address string 66 MaxTries *int64 `jsonrpcdefault:"1000000"` 67 } 68 69 // NewGenerateToAddressCmd returns a new instance which can be used to issue a 70 // generatetoaddress JSON-RPC command. 71 func NewGenerateToAddressCmd(numBlocks int64, address string, maxTries *int64) *GenerateToAddressCmd { 72 return &GenerateToAddressCmd{ 73 NumBlocks: numBlocks, 74 Address: address, 75 MaxTries: maxTries, 76 } 77 } 78 79 // GenerateCmd defines the generate JSON-RPC command. 80 type GenerateCmd struct { 81 NumBlocks uint32 82 } 83 84 // NewGenerateCmd returns a new instance which can be used to issue a generate 85 // JSON-RPC command. 86 func NewGenerateCmd(numBlocks uint32) *GenerateCmd { 87 return &GenerateCmd{ 88 NumBlocks: numBlocks, 89 } 90 } 91 92 // GetBestBlockCmd defines the getbestblock JSON-RPC command. 93 type GetBestBlockCmd struct{} 94 95 // NewGetBestBlockCmd returns a new instance which can be used to issue a 96 // getbestblock JSON-RPC command. 97 func NewGetBestBlockCmd() *GetBestBlockCmd { 98 return &GetBestBlockCmd{} 99 } 100 101 // GetCurrentNetCmd defines the getcurrentnet JSON-RPC command. 102 type GetCurrentNetCmd struct{} 103 104 // NewGetCurrentNetCmd returns a new instance which can be used to issue a 105 // getcurrentnet JSON-RPC command. 106 func NewGetCurrentNetCmd() *GetCurrentNetCmd { 107 return &GetCurrentNetCmd{} 108 } 109 110 // GetHeadersCmd defines the getheaders JSON-RPC command. 111 // 112 // NOTE: This is a btcsuite extension ported from 113 // github.com/decred/dcrd/dcrjson. 114 type GetHeadersCmd struct { 115 BlockLocators []string `json:"blocklocators"` 116 HashStop string `json:"hashstop"` 117 } 118 119 // NewGetHeadersCmd returns a new instance which can be used to issue a 120 // getheaders JSON-RPC command. 121 // 122 // NOTE: This is a btcsuite extension ported from 123 // github.com/decred/dcrd/dcrjson. 124 func NewGetHeadersCmd(blockLocators []string, hashStop string) *GetHeadersCmd { 125 return &GetHeadersCmd{ 126 BlockLocators: blockLocators, 127 HashStop: hashStop, 128 } 129 } 130 131 // VersionCmd defines the version JSON-RPC command. 132 // 133 // NOTE: This is a btcsuite extension ported from 134 // github.com/decred/dcrd/dcrjson. 135 type VersionCmd struct{} 136 137 // NewVersionCmd returns a new instance which can be used to issue a JSON-RPC 138 // version command. 139 // 140 // NOTE: This is a btcsuite extension ported from 141 // github.com/decred/dcrd/dcrjson. 142 func NewVersionCmd() *VersionCmd { return new(VersionCmd) } 143 144 func init() { 145 // No special flags for commands in this file. 146 flags := UsageFlag(0) 147 148 MustRegisterCmd("debuglevel", (*DebugLevelCmd)(nil), flags) 149 MustRegisterCmd("node", (*NodeCmd)(nil), flags) 150 MustRegisterCmd("generate", (*GenerateCmd)(nil), flags) 151 MustRegisterCmd("generatetoaddress", (*GenerateToAddressCmd)(nil), flags) 152 MustRegisterCmd("getbestblock", (*GetBestBlockCmd)(nil), flags) 153 MustRegisterCmd("getcurrentnet", (*GetCurrentNetCmd)(nil), flags) 154 MustRegisterCmd("getheaders", (*GetHeadersCmd)(nil), flags) 155 MustRegisterCmd("version", (*VersionCmd)(nil), flags) 156 }