OSDN Git Service

Merge pull request #41 from Bytom/dev
[bytom/vapor.git] / vendor / github.com / btcsuite / btcd / btcjson / chainsvrcmds.go
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/json"
12         "fmt"
13 )
14
15 // AddNodeSubCmd defines the type used in the addnode JSON-RPC command for the
16 // sub command field.
17 type AddNodeSubCmd string
18
19 const (
20         // ANAdd indicates the specified host should be added as a persistent
21         // peer.
22         ANAdd AddNodeSubCmd = "add"
23
24         // ANRemove indicates the specified peer should be removed.
25         ANRemove AddNodeSubCmd = "remove"
26
27         // ANOneTry indicates the specified host should try to connect once,
28         // but it should not be made persistent.
29         ANOneTry AddNodeSubCmd = "onetry"
30 )
31
32 // AddNodeCmd defines the addnode JSON-RPC command.
33 type AddNodeCmd struct {
34         Addr   string
35         SubCmd AddNodeSubCmd `jsonrpcusage:"\"add|remove|onetry\""`
36 }
37
38 // NewAddNodeCmd returns a new instance which can be used to issue an addnode
39 // JSON-RPC command.
40 func NewAddNodeCmd(addr string, subCmd AddNodeSubCmd) *AddNodeCmd {
41         return &AddNodeCmd{
42                 Addr:   addr,
43                 SubCmd: subCmd,
44         }
45 }
46
47 // TransactionInput represents the inputs to a transaction.  Specifically a
48 // transaction hash and output number pair.
49 type TransactionInput struct {
50         Txid string `json:"txid"`
51         Vout uint32 `json:"vout"`
52 }
53
54 // CreateRawTransactionCmd defines the createrawtransaction JSON-RPC command.
55 type CreateRawTransactionCmd struct {
56         Inputs   []TransactionInput
57         Amounts  map[string]float64 `jsonrpcusage:"{\"address\":amount,...}"` // In BTC
58         LockTime *int64
59 }
60
61 // NewCreateRawTransactionCmd returns a new instance which can be used to issue
62 // a createrawtransaction JSON-RPC command.
63 //
64 // Amounts are in BTC.
65 func NewCreateRawTransactionCmd(inputs []TransactionInput, amounts map[string]float64,
66         lockTime *int64) *CreateRawTransactionCmd {
67
68         return &CreateRawTransactionCmd{
69                 Inputs:   inputs,
70                 Amounts:  amounts,
71                 LockTime: lockTime,
72         }
73 }
74
75 // DecodeRawTransactionCmd defines the decoderawtransaction JSON-RPC command.
76 type DecodeRawTransactionCmd struct {
77         HexTx string
78 }
79
80 // NewDecodeRawTransactionCmd returns a new instance which can be used to issue
81 // a decoderawtransaction JSON-RPC command.
82 func NewDecodeRawTransactionCmd(hexTx string) *DecodeRawTransactionCmd {
83         return &DecodeRawTransactionCmd{
84                 HexTx: hexTx,
85         }
86 }
87
88 // DecodeScriptCmd defines the decodescript JSON-RPC command.
89 type DecodeScriptCmd struct {
90         HexScript string
91 }
92
93 // NewDecodeScriptCmd returns a new instance which can be used to issue a
94 // decodescript JSON-RPC command.
95 func NewDecodeScriptCmd(hexScript string) *DecodeScriptCmd {
96         return &DecodeScriptCmd{
97                 HexScript: hexScript,
98         }
99 }
100
101 // GetAddedNodeInfoCmd defines the getaddednodeinfo JSON-RPC command.
102 type GetAddedNodeInfoCmd struct {
103         DNS  bool
104         Node *string
105 }
106
107 // NewGetAddedNodeInfoCmd returns a new instance which can be used to issue a
108 // getaddednodeinfo JSON-RPC command.
109 //
110 // The parameters which are pointers indicate they are optional.  Passing nil
111 // for optional parameters will use the default value.
112 func NewGetAddedNodeInfoCmd(dns bool, node *string) *GetAddedNodeInfoCmd {
113         return &GetAddedNodeInfoCmd{
114                 DNS:  dns,
115                 Node: node,
116         }
117 }
118
119 // GetBestBlockHashCmd defines the getbestblockhash JSON-RPC command.
120 type GetBestBlockHashCmd struct{}
121
122 // NewGetBestBlockHashCmd returns a new instance which can be used to issue a
123 // getbestblockhash JSON-RPC command.
124 func NewGetBestBlockHashCmd() *GetBestBlockHashCmd {
125         return &GetBestBlockHashCmd{}
126 }
127
128 // GetBlockCmd defines the getblock JSON-RPC command.
129 type GetBlockCmd struct {
130         Hash      string
131         Verbose   *bool `jsonrpcdefault:"true"`
132         VerboseTx *bool `jsonrpcdefault:"false"`
133 }
134
135 // NewGetBlockCmd returns a new instance which can be used to issue a getblock
136 // JSON-RPC command.
137 //
138 // The parameters which are pointers indicate they are optional.  Passing nil
139 // for optional parameters will use the default value.
140 func NewGetBlockCmd(hash string, verbose, verboseTx *bool) *GetBlockCmd {
141         return &GetBlockCmd{
142                 Hash:      hash,
143                 Verbose:   verbose,
144                 VerboseTx: verboseTx,
145         }
146 }
147
148 // GetBlockChainInfoCmd defines the getblockchaininfo JSON-RPC command.
149 type GetBlockChainInfoCmd struct{}
150
151 // NewGetBlockChainInfoCmd returns a new instance which can be used to issue a
152 // getblockchaininfo JSON-RPC command.
153 func NewGetBlockChainInfoCmd() *GetBlockChainInfoCmd {
154         return &GetBlockChainInfoCmd{}
155 }
156
157 // GetBlockCountCmd defines the getblockcount JSON-RPC command.
158 type GetBlockCountCmd struct{}
159
160 // NewGetBlockCountCmd returns a new instance which can be used to issue a
161 // getblockcount JSON-RPC command.
162 func NewGetBlockCountCmd() *GetBlockCountCmd {
163         return &GetBlockCountCmd{}
164 }
165
166 // GetBlockHashCmd defines the getblockhash JSON-RPC command.
167 type GetBlockHashCmd struct {
168         Index int64
169 }
170
171 // NewGetBlockHashCmd returns a new instance which can be used to issue a
172 // getblockhash JSON-RPC command.
173 func NewGetBlockHashCmd(index int64) *GetBlockHashCmd {
174         return &GetBlockHashCmd{
175                 Index: index,
176         }
177 }
178
179 // GetBlockHeaderCmd defines the getblockheader JSON-RPC command.
180 type GetBlockHeaderCmd struct {
181         Hash    string
182         Verbose *bool `jsonrpcdefault:"true"`
183 }
184
185 // NewGetBlockHeaderCmd returns a new instance which can be used to issue a
186 // getblockheader JSON-RPC command.
187 func NewGetBlockHeaderCmd(hash string, verbose *bool) *GetBlockHeaderCmd {
188         return &GetBlockHeaderCmd{
189                 Hash:    hash,
190                 Verbose: verbose,
191         }
192 }
193
194 // TemplateRequest is a request object as defined in BIP22
195 // (https://en.bitcoin.it/wiki/BIP_0022), it is optionally provided as an
196 // pointer argument to GetBlockTemplateCmd.
197 type TemplateRequest struct {
198         Mode         string   `json:"mode,omitempty"`
199         Capabilities []string `json:"capabilities,omitempty"`
200
201         // Optional long polling.
202         LongPollID string `json:"longpollid,omitempty"`
203
204         // Optional template tweaking.  SigOpLimit and SizeLimit can be int64
205         // or bool.
206         SigOpLimit interface{} `json:"sigoplimit,omitempty"`
207         SizeLimit  interface{} `json:"sizelimit,omitempty"`
208         MaxVersion uint32      `json:"maxversion,omitempty"`
209
210         // Basic pool extension from BIP 0023.
211         Target string `json:"target,omitempty"`
212
213         // Block proposal from BIP 0023.  Data is only provided when Mode is
214         // "proposal".
215         Data   string `json:"data,omitempty"`
216         WorkID string `json:"workid,omitempty"`
217 }
218
219 // convertTemplateRequestField potentially converts the provided value as
220 // needed.
221 func convertTemplateRequestField(fieldName string, iface interface{}) (interface{}, error) {
222         switch val := iface.(type) {
223         case nil:
224                 return nil, nil
225         case bool:
226                 return val, nil
227         case float64:
228                 if val == float64(int64(val)) {
229                         return int64(val), nil
230                 }
231         }
232
233         str := fmt.Sprintf("the %s field must be unspecified, a boolean, or "+
234                 "a 64-bit integer", fieldName)
235         return nil, makeError(ErrInvalidType, str)
236 }
237
238 // UnmarshalJSON provides a custom Unmarshal method for TemplateRequest.  This
239 // is necessary because the SigOpLimit and SizeLimit fields can only be specific
240 // types.
241 func (t *TemplateRequest) UnmarshalJSON(data []byte) error {
242         type templateRequest TemplateRequest
243
244         request := (*templateRequest)(t)
245         if err := json.Unmarshal(data, &request); err != nil {
246                 return err
247         }
248
249         // The SigOpLimit field can only be nil, bool, or int64.
250         val, err := convertTemplateRequestField("sigoplimit", request.SigOpLimit)
251         if err != nil {
252                 return err
253         }
254         request.SigOpLimit = val
255
256         // The SizeLimit field can only be nil, bool, or int64.
257         val, err = convertTemplateRequestField("sizelimit", request.SizeLimit)
258         if err != nil {
259                 return err
260         }
261         request.SizeLimit = val
262
263         return nil
264 }
265
266 // GetBlockTemplateCmd defines the getblocktemplate JSON-RPC command.
267 type GetBlockTemplateCmd struct {
268         Request *TemplateRequest
269 }
270
271 // NewGetBlockTemplateCmd returns a new instance which can be used to issue a
272 // getblocktemplate JSON-RPC command.
273 //
274 // The parameters which are pointers indicate they are optional.  Passing nil
275 // for optional parameters will use the default value.
276 func NewGetBlockTemplateCmd(request *TemplateRequest) *GetBlockTemplateCmd {
277         return &GetBlockTemplateCmd{
278                 Request: request,
279         }
280 }
281
282 // GetChainTipsCmd defines the getchaintips JSON-RPC command.
283 type GetChainTipsCmd struct{}
284
285 // NewGetChainTipsCmd returns a new instance which can be used to issue a
286 // getchaintips JSON-RPC command.
287 func NewGetChainTipsCmd() *GetChainTipsCmd {
288         return &GetChainTipsCmd{}
289 }
290
291 // GetConnectionCountCmd defines the getconnectioncount JSON-RPC command.
292 type GetConnectionCountCmd struct{}
293
294 // NewGetConnectionCountCmd returns a new instance which can be used to issue a
295 // getconnectioncount JSON-RPC command.
296 func NewGetConnectionCountCmd() *GetConnectionCountCmd {
297         return &GetConnectionCountCmd{}
298 }
299
300 // GetDifficultyCmd defines the getdifficulty JSON-RPC command.
301 type GetDifficultyCmd struct{}
302
303 // NewGetDifficultyCmd returns a new instance which can be used to issue a
304 // getdifficulty JSON-RPC command.
305 func NewGetDifficultyCmd() *GetDifficultyCmd {
306         return &GetDifficultyCmd{}
307 }
308
309 // GetGenerateCmd defines the getgenerate JSON-RPC command.
310 type GetGenerateCmd struct{}
311
312 // NewGetGenerateCmd returns a new instance which can be used to issue a
313 // getgenerate JSON-RPC command.
314 func NewGetGenerateCmd() *GetGenerateCmd {
315         return &GetGenerateCmd{}
316 }
317
318 // GetHashesPerSecCmd defines the gethashespersec JSON-RPC command.
319 type GetHashesPerSecCmd struct{}
320
321 // NewGetHashesPerSecCmd returns a new instance which can be used to issue a
322 // gethashespersec JSON-RPC command.
323 func NewGetHashesPerSecCmd() *GetHashesPerSecCmd {
324         return &GetHashesPerSecCmd{}
325 }
326
327 // GetInfoCmd defines the getinfo JSON-RPC command.
328 type GetInfoCmd struct{}
329
330 // NewGetInfoCmd returns a new instance which can be used to issue a
331 // getinfo JSON-RPC command.
332 func NewGetInfoCmd() *GetInfoCmd {
333         return &GetInfoCmd{}
334 }
335
336 // GetMempoolEntryCmd defines the getmempoolentry JSON-RPC command.
337 type GetMempoolEntryCmd struct {
338         TxID string
339 }
340
341 // NewGetMempoolEntryCmd returns a new instance which can be used to issue a
342 // getmempoolentry JSON-RPC command.
343 func NewGetMempoolEntryCmd(txHash string) *GetMempoolEntryCmd {
344         return &GetMempoolEntryCmd{
345                 TxID: txHash,
346         }
347 }
348
349 // GetMempoolInfoCmd defines the getmempoolinfo JSON-RPC command.
350 type GetMempoolInfoCmd struct{}
351
352 // NewGetMempoolInfoCmd returns a new instance which can be used to issue a
353 // getmempool JSON-RPC command.
354 func NewGetMempoolInfoCmd() *GetMempoolInfoCmd {
355         return &GetMempoolInfoCmd{}
356 }
357
358 // GetMiningInfoCmd defines the getmininginfo JSON-RPC command.
359 type GetMiningInfoCmd struct{}
360
361 // NewGetMiningInfoCmd returns a new instance which can be used to issue a
362 // getmininginfo JSON-RPC command.
363 func NewGetMiningInfoCmd() *GetMiningInfoCmd {
364         return &GetMiningInfoCmd{}
365 }
366
367 // GetNetworkInfoCmd defines the getnetworkinfo JSON-RPC command.
368 type GetNetworkInfoCmd struct{}
369
370 // NewGetNetworkInfoCmd returns a new instance which can be used to issue a
371 // getnetworkinfo JSON-RPC command.
372 func NewGetNetworkInfoCmd() *GetNetworkInfoCmd {
373         return &GetNetworkInfoCmd{}
374 }
375
376 // GetNetTotalsCmd defines the getnettotals JSON-RPC command.
377 type GetNetTotalsCmd struct{}
378
379 // NewGetNetTotalsCmd returns a new instance which can be used to issue a
380 // getnettotals JSON-RPC command.
381 func NewGetNetTotalsCmd() *GetNetTotalsCmd {
382         return &GetNetTotalsCmd{}
383 }
384
385 // GetNetworkHashPSCmd defines the getnetworkhashps JSON-RPC command.
386 type GetNetworkHashPSCmd struct {
387         Blocks *int `jsonrpcdefault:"120"`
388         Height *int `jsonrpcdefault:"-1"`
389 }
390
391 // NewGetNetworkHashPSCmd returns a new instance which can be used to issue a
392 // getnetworkhashps JSON-RPC command.
393 //
394 // The parameters which are pointers indicate they are optional.  Passing nil
395 // for optional parameters will use the default value.
396 func NewGetNetworkHashPSCmd(numBlocks, height *int) *GetNetworkHashPSCmd {
397         return &GetNetworkHashPSCmd{
398                 Blocks: numBlocks,
399                 Height: height,
400         }
401 }
402
403 // GetPeerInfoCmd defines the getpeerinfo JSON-RPC command.
404 type GetPeerInfoCmd struct{}
405
406 // NewGetPeerInfoCmd returns a new instance which can be used to issue a getpeer
407 // JSON-RPC command.
408 func NewGetPeerInfoCmd() *GetPeerInfoCmd {
409         return &GetPeerInfoCmd{}
410 }
411
412 // GetRawMempoolCmd defines the getmempool JSON-RPC command.
413 type GetRawMempoolCmd struct {
414         Verbose *bool `jsonrpcdefault:"false"`
415 }
416
417 // NewGetRawMempoolCmd returns a new instance which can be used to issue a
418 // getrawmempool JSON-RPC command.
419 //
420 // The parameters which are pointers indicate they are optional.  Passing nil
421 // for optional parameters will use the default value.
422 func NewGetRawMempoolCmd(verbose *bool) *GetRawMempoolCmd {
423         return &GetRawMempoolCmd{
424                 Verbose: verbose,
425         }
426 }
427
428 // GetRawTransactionCmd defines the getrawtransaction JSON-RPC command.
429 //
430 // NOTE: This field is an int versus a bool to remain compatible with Bitcoin
431 // Core even though it really should be a bool.
432 type GetRawTransactionCmd struct {
433         Txid    string
434         Verbose *int `jsonrpcdefault:"0"`
435 }
436
437 // NewGetRawTransactionCmd returns a new instance which can be used to issue a
438 // getrawtransaction JSON-RPC command.
439 //
440 // The parameters which are pointers indicate they are optional.  Passing nil
441 // for optional parameters will use the default value.
442 func NewGetRawTransactionCmd(txHash string, verbose *int) *GetRawTransactionCmd {
443         return &GetRawTransactionCmd{
444                 Txid:    txHash,
445                 Verbose: verbose,
446         }
447 }
448
449 // GetTxOutCmd defines the gettxout JSON-RPC command.
450 type GetTxOutCmd struct {
451         Txid           string
452         Vout           uint32
453         IncludeMempool *bool `jsonrpcdefault:"true"`
454 }
455
456 // NewGetTxOutCmd returns a new instance which can be used to issue a gettxout
457 // JSON-RPC command.
458 //
459 // The parameters which are pointers indicate they are optional.  Passing nil
460 // for optional parameters will use the default value.
461 func NewGetTxOutCmd(txHash string, vout uint32, includeMempool *bool) *GetTxOutCmd {
462         return &GetTxOutCmd{
463                 Txid:           txHash,
464                 Vout:           vout,
465                 IncludeMempool: includeMempool,
466         }
467 }
468
469 // GetTxOutProofCmd defines the gettxoutproof JSON-RPC command.
470 type GetTxOutProofCmd struct {
471         TxIDs     []string
472         BlockHash *string
473 }
474
475 // NewGetTxOutProofCmd returns a new instance which can be used to issue a
476 // gettxoutproof JSON-RPC command.
477 //
478 // The parameters which are pointers indicate they are optional.  Passing nil
479 // for optional parameters will use the default value.
480 func NewGetTxOutProofCmd(txIDs []string, blockHash *string) *GetTxOutProofCmd {
481         return &GetTxOutProofCmd{
482                 TxIDs:     txIDs,
483                 BlockHash: blockHash,
484         }
485 }
486
487 // GetTxOutSetInfoCmd defines the gettxoutsetinfo JSON-RPC command.
488 type GetTxOutSetInfoCmd struct{}
489
490 // NewGetTxOutSetInfoCmd returns a new instance which can be used to issue a
491 // gettxoutsetinfo JSON-RPC command.
492 func NewGetTxOutSetInfoCmd() *GetTxOutSetInfoCmd {
493         return &GetTxOutSetInfoCmd{}
494 }
495
496 // GetWorkCmd defines the getwork JSON-RPC command.
497 type GetWorkCmd struct {
498         Data *string
499 }
500
501 // NewGetWorkCmd returns a new instance which can be used to issue a getwork
502 // JSON-RPC command.
503 //
504 // The parameters which are pointers indicate they are optional.  Passing nil
505 // for optional parameters will use the default value.
506 func NewGetWorkCmd(data *string) *GetWorkCmd {
507         return &GetWorkCmd{
508                 Data: data,
509         }
510 }
511
512 // HelpCmd defines the help JSON-RPC command.
513 type HelpCmd struct {
514         Command *string
515 }
516
517 // NewHelpCmd returns a new instance which can be used to issue a help JSON-RPC
518 // command.
519 //
520 // The parameters which are pointers indicate they are optional.  Passing nil
521 // for optional parameters will use the default value.
522 func NewHelpCmd(command *string) *HelpCmd {
523         return &HelpCmd{
524                 Command: command,
525         }
526 }
527
528 // InvalidateBlockCmd defines the invalidateblock JSON-RPC command.
529 type InvalidateBlockCmd struct {
530         BlockHash string
531 }
532
533 // NewInvalidateBlockCmd returns a new instance which can be used to issue a
534 // invalidateblock JSON-RPC command.
535 func NewInvalidateBlockCmd(blockHash string) *InvalidateBlockCmd {
536         return &InvalidateBlockCmd{
537                 BlockHash: blockHash,
538         }
539 }
540
541 // PingCmd defines the ping JSON-RPC command.
542 type PingCmd struct{}
543
544 // NewPingCmd returns a new instance which can be used to issue a ping JSON-RPC
545 // command.
546 func NewPingCmd() *PingCmd {
547         return &PingCmd{}
548 }
549
550 // PreciousBlockCmd defines the preciousblock JSON-RPC command.
551 type PreciousBlockCmd struct {
552         BlockHash string
553 }
554
555 // NewPreciousBlockCmd returns a new instance which can be used to issue a
556 // preciousblock JSON-RPC command.
557 func NewPreciousBlockCmd(blockHash string) *PreciousBlockCmd {
558         return &PreciousBlockCmd{
559                 BlockHash: blockHash,
560         }
561 }
562
563 // ReconsiderBlockCmd defines the reconsiderblock JSON-RPC command.
564 type ReconsiderBlockCmd struct {
565         BlockHash string
566 }
567
568 // NewReconsiderBlockCmd returns a new instance which can be used to issue a
569 // reconsiderblock JSON-RPC command.
570 func NewReconsiderBlockCmd(blockHash string) *ReconsiderBlockCmd {
571         return &ReconsiderBlockCmd{
572                 BlockHash: blockHash,
573         }
574 }
575
576 // SearchRawTransactionsCmd defines the searchrawtransactions JSON-RPC command.
577 type SearchRawTransactionsCmd struct {
578         Address     string
579         Verbose     *int  `jsonrpcdefault:"1"`
580         Skip        *int  `jsonrpcdefault:"0"`
581         Count       *int  `jsonrpcdefault:"100"`
582         VinExtra    *int  `jsonrpcdefault:"0"`
583         Reverse     *bool `jsonrpcdefault:"false"`
584         FilterAddrs *[]string
585 }
586
587 // NewSearchRawTransactionsCmd returns a new instance which can be used to issue a
588 // sendrawtransaction JSON-RPC command.
589 //
590 // The parameters which are pointers indicate they are optional.  Passing nil
591 // for optional parameters will use the default value.
592 func NewSearchRawTransactionsCmd(address string, verbose, skip, count *int, vinExtra *int, reverse *bool, filterAddrs *[]string) *SearchRawTransactionsCmd {
593         return &SearchRawTransactionsCmd{
594                 Address:     address,
595                 Verbose:     verbose,
596                 Skip:        skip,
597                 Count:       count,
598                 VinExtra:    vinExtra,
599                 Reverse:     reverse,
600                 FilterAddrs: filterAddrs,
601         }
602 }
603
604 // SendRawTransactionCmd defines the sendrawtransaction JSON-RPC command.
605 type SendRawTransactionCmd struct {
606         HexTx         string
607         AllowHighFees *bool `jsonrpcdefault:"false"`
608 }
609
610 // NewSendRawTransactionCmd returns a new instance which can be used to issue a
611 // sendrawtransaction JSON-RPC command.
612 //
613 // The parameters which are pointers indicate they are optional.  Passing nil
614 // for optional parameters will use the default value.
615 func NewSendRawTransactionCmd(hexTx string, allowHighFees *bool) *SendRawTransactionCmd {
616         return &SendRawTransactionCmd{
617                 HexTx:         hexTx,
618                 AllowHighFees: allowHighFees,
619         }
620 }
621
622 // SetGenerateCmd defines the setgenerate JSON-RPC command.
623 type SetGenerateCmd struct {
624         Generate     bool
625         GenProcLimit *int `jsonrpcdefault:"-1"`
626 }
627
628 // NewSetGenerateCmd returns a new instance which can be used to issue a
629 // setgenerate JSON-RPC command.
630 //
631 // The parameters which are pointers indicate they are optional.  Passing nil
632 // for optional parameters will use the default value.
633 func NewSetGenerateCmd(generate bool, genProcLimit *int) *SetGenerateCmd {
634         return &SetGenerateCmd{
635                 Generate:     generate,
636                 GenProcLimit: genProcLimit,
637         }
638 }
639
640 // StopCmd defines the stop JSON-RPC command.
641 type StopCmd struct{}
642
643 // NewStopCmd returns a new instance which can be used to issue a stop JSON-RPC
644 // command.
645 func NewStopCmd() *StopCmd {
646         return &StopCmd{}
647 }
648
649 // SubmitBlockOptions represents the optional options struct provided with a
650 // SubmitBlockCmd command.
651 type SubmitBlockOptions struct {
652         // must be provided if server provided a workid with template.
653         WorkID string `json:"workid,omitempty"`
654 }
655
656 // SubmitBlockCmd defines the submitblock JSON-RPC command.
657 type SubmitBlockCmd struct {
658         HexBlock string
659         Options  *SubmitBlockOptions
660 }
661
662 // NewSubmitBlockCmd returns a new instance which can be used to issue a
663 // submitblock JSON-RPC command.
664 //
665 // The parameters which are pointers indicate they are optional.  Passing nil
666 // for optional parameters will use the default value.
667 func NewSubmitBlockCmd(hexBlock string, options *SubmitBlockOptions) *SubmitBlockCmd {
668         return &SubmitBlockCmd{
669                 HexBlock: hexBlock,
670                 Options:  options,
671         }
672 }
673
674 // UptimeCmd defines the uptime JSON-RPC command.
675 type UptimeCmd struct{}
676
677 // NewUptimeCmd returns a new instance which can be used to issue an uptime JSON-RPC command.
678 func NewUptimeCmd() *UptimeCmd {
679         return &UptimeCmd{}
680 }
681
682 // ValidateAddressCmd defines the validateaddress JSON-RPC command.
683 type ValidateAddressCmd struct {
684         Address string
685 }
686
687 // NewValidateAddressCmd returns a new instance which can be used to issue a
688 // validateaddress JSON-RPC command.
689 func NewValidateAddressCmd(address string) *ValidateAddressCmd {
690         return &ValidateAddressCmd{
691                 Address: address,
692         }
693 }
694
695 // VerifyChainCmd defines the verifychain JSON-RPC command.
696 type VerifyChainCmd struct {
697         CheckLevel *int32 `jsonrpcdefault:"3"`
698         CheckDepth *int32 `jsonrpcdefault:"288"` // 0 = all
699 }
700
701 // NewVerifyChainCmd returns a new instance which can be used to issue a
702 // verifychain JSON-RPC command.
703 //
704 // The parameters which are pointers indicate they are optional.  Passing nil
705 // for optional parameters will use the default value.
706 func NewVerifyChainCmd(checkLevel, checkDepth *int32) *VerifyChainCmd {
707         return &VerifyChainCmd{
708                 CheckLevel: checkLevel,
709                 CheckDepth: checkDepth,
710         }
711 }
712
713 // VerifyMessageCmd defines the verifymessage JSON-RPC command.
714 type VerifyMessageCmd struct {
715         Address   string
716         Signature string
717         Message   string
718 }
719
720 // NewVerifyMessageCmd returns a new instance which can be used to issue a
721 // verifymessage JSON-RPC command.
722 func NewVerifyMessageCmd(address, signature, message string) *VerifyMessageCmd {
723         return &VerifyMessageCmd{
724                 Address:   address,
725                 Signature: signature,
726                 Message:   message,
727         }
728 }
729
730 // VerifyTxOutProofCmd defines the verifytxoutproof JSON-RPC command.
731 type VerifyTxOutProofCmd struct {
732         Proof string
733 }
734
735 // NewVerifyTxOutProofCmd returns a new instance which can be used to issue a
736 // verifytxoutproof JSON-RPC command.
737 func NewVerifyTxOutProofCmd(proof string) *VerifyTxOutProofCmd {
738         return &VerifyTxOutProofCmd{
739                 Proof: proof,
740         }
741 }
742
743 func init() {
744         // No special flags for commands in this file.
745         flags := UsageFlag(0)
746
747         MustRegisterCmd("addnode", (*AddNodeCmd)(nil), flags)
748         MustRegisterCmd("createrawtransaction", (*CreateRawTransactionCmd)(nil), flags)
749         MustRegisterCmd("decoderawtransaction", (*DecodeRawTransactionCmd)(nil), flags)
750         MustRegisterCmd("decodescript", (*DecodeScriptCmd)(nil), flags)
751         MustRegisterCmd("getaddednodeinfo", (*GetAddedNodeInfoCmd)(nil), flags)
752         MustRegisterCmd("getbestblockhash", (*GetBestBlockHashCmd)(nil), flags)
753         MustRegisterCmd("getblock", (*GetBlockCmd)(nil), flags)
754         MustRegisterCmd("getblockchaininfo", (*GetBlockChainInfoCmd)(nil), flags)
755         MustRegisterCmd("getblockcount", (*GetBlockCountCmd)(nil), flags)
756         MustRegisterCmd("getblockhash", (*GetBlockHashCmd)(nil), flags)
757         MustRegisterCmd("getblockheader", (*GetBlockHeaderCmd)(nil), flags)
758         MustRegisterCmd("getblocktemplate", (*GetBlockTemplateCmd)(nil), flags)
759         MustRegisterCmd("getchaintips", (*GetChainTipsCmd)(nil), flags)
760         MustRegisterCmd("getconnectioncount", (*GetConnectionCountCmd)(nil), flags)
761         MustRegisterCmd("getdifficulty", (*GetDifficultyCmd)(nil), flags)
762         MustRegisterCmd("getgenerate", (*GetGenerateCmd)(nil), flags)
763         MustRegisterCmd("gethashespersec", (*GetHashesPerSecCmd)(nil), flags)
764         MustRegisterCmd("getinfo", (*GetInfoCmd)(nil), flags)
765         MustRegisterCmd("getmempoolentry", (*GetMempoolEntryCmd)(nil), flags)
766         MustRegisterCmd("getmempoolinfo", (*GetMempoolInfoCmd)(nil), flags)
767         MustRegisterCmd("getmininginfo", (*GetMiningInfoCmd)(nil), flags)
768         MustRegisterCmd("getnetworkinfo", (*GetNetworkInfoCmd)(nil), flags)
769         MustRegisterCmd("getnettotals", (*GetNetTotalsCmd)(nil), flags)
770         MustRegisterCmd("getnetworkhashps", (*GetNetworkHashPSCmd)(nil), flags)
771         MustRegisterCmd("getpeerinfo", (*GetPeerInfoCmd)(nil), flags)
772         MustRegisterCmd("getrawmempool", (*GetRawMempoolCmd)(nil), flags)
773         MustRegisterCmd("getrawtransaction", (*GetRawTransactionCmd)(nil), flags)
774         MustRegisterCmd("gettxout", (*GetTxOutCmd)(nil), flags)
775         MustRegisterCmd("gettxoutproof", (*GetTxOutProofCmd)(nil), flags)
776         MustRegisterCmd("gettxoutsetinfo", (*GetTxOutSetInfoCmd)(nil), flags)
777         MustRegisterCmd("getwork", (*GetWorkCmd)(nil), flags)
778         MustRegisterCmd("help", (*HelpCmd)(nil), flags)
779         MustRegisterCmd("invalidateblock", (*InvalidateBlockCmd)(nil), flags)
780         MustRegisterCmd("ping", (*PingCmd)(nil), flags)
781         MustRegisterCmd("preciousblock", (*PreciousBlockCmd)(nil), flags)
782         MustRegisterCmd("reconsiderblock", (*ReconsiderBlockCmd)(nil), flags)
783         MustRegisterCmd("searchrawtransactions", (*SearchRawTransactionsCmd)(nil), flags)
784         MustRegisterCmd("sendrawtransaction", (*SendRawTransactionCmd)(nil), flags)
785         MustRegisterCmd("setgenerate", (*SetGenerateCmd)(nil), flags)
786         MustRegisterCmd("stop", (*StopCmd)(nil), flags)
787         MustRegisterCmd("submitblock", (*SubmitBlockCmd)(nil), flags)
788         MustRegisterCmd("uptime", (*UptimeCmd)(nil), flags)
789         MustRegisterCmd("validateaddress", (*ValidateAddressCmd)(nil), flags)
790         MustRegisterCmd("verifychain", (*VerifyChainCmd)(nil), flags)
791         MustRegisterCmd("verifymessage", (*VerifyMessageCmd)(nil), flags)
792         MustRegisterCmd("verifytxoutproof", (*VerifyTxOutProofCmd)(nil), flags)
793 }