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