OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / btcsuite / btcd / btcjson / btcdextcmds.go
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 // GenerateCmd defines the generate JSON-RPC command.
63 type GenerateCmd struct {
64         NumBlocks uint32
65 }
66
67 // NewGenerateCmd returns a new instance which can be used to issue a generate
68 // JSON-RPC command.
69 func NewGenerateCmd(numBlocks uint32) *GenerateCmd {
70         return &GenerateCmd{
71                 NumBlocks: numBlocks,
72         }
73 }
74
75 // GetBestBlockCmd defines the getbestblock JSON-RPC command.
76 type GetBestBlockCmd struct{}
77
78 // NewGetBestBlockCmd returns a new instance which can be used to issue a
79 // getbestblock JSON-RPC command.
80 func NewGetBestBlockCmd() *GetBestBlockCmd {
81         return &GetBestBlockCmd{}
82 }
83
84 // GetCurrentNetCmd defines the getcurrentnet JSON-RPC command.
85 type GetCurrentNetCmd struct{}
86
87 // NewGetCurrentNetCmd returns a new instance which can be used to issue a
88 // getcurrentnet JSON-RPC command.
89 func NewGetCurrentNetCmd() *GetCurrentNetCmd {
90         return &GetCurrentNetCmd{}
91 }
92
93 // GetHeadersCmd defines the getheaders JSON-RPC command.
94 //
95 // NOTE: This is a btcsuite extension ported from
96 // github.com/decred/dcrd/dcrjson.
97 type GetHeadersCmd struct {
98         BlockLocators []string `json:"blocklocators"`
99         HashStop      string   `json:"hashstop"`
100 }
101
102 // NewGetHeadersCmd returns a new instance which can be used to issue a
103 // getheaders JSON-RPC command.
104 //
105 // NOTE: This is a btcsuite extension ported from
106 // github.com/decred/dcrd/dcrjson.
107 func NewGetHeadersCmd(blockLocators []string, hashStop string) *GetHeadersCmd {
108         return &GetHeadersCmd{
109                 BlockLocators: blockLocators,
110                 HashStop:      hashStop,
111         }
112 }
113
114 // VersionCmd defines the version JSON-RPC command.
115 //
116 // NOTE: This is a btcsuite extension ported from
117 // github.com/decred/dcrd/dcrjson.
118 type VersionCmd struct{}
119
120 // NewVersionCmd returns a new instance which can be used to issue a JSON-RPC
121 // version command.
122 //
123 // NOTE: This is a btcsuite extension ported from
124 // github.com/decred/dcrd/dcrjson.
125 func NewVersionCmd() *VersionCmd { return new(VersionCmd) }
126
127 func init() {
128         // No special flags for commands in this file.
129         flags := UsageFlag(0)
130
131         MustRegisterCmd("debuglevel", (*DebugLevelCmd)(nil), flags)
132         MustRegisterCmd("node", (*NodeCmd)(nil), flags)
133         MustRegisterCmd("generate", (*GenerateCmd)(nil), flags)
134         MustRegisterCmd("getbestblock", (*GetBestBlockCmd)(nil), flags)
135         MustRegisterCmd("getcurrentnet", (*GetCurrentNetCmd)(nil), flags)
136         MustRegisterCmd("getheaders", (*GetHeadersCmd)(nil), flags)
137         MustRegisterCmd("version", (*VersionCmd)(nil), flags)
138 }