123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- // Copyright (c) 2014 The btcsuite developers
- // Copyright (c) 2019 Caleb James DeLisle
- // Use of this source code is governed by an ISC
- // license that can be found in the LICENSE file.
- // NOTE: This file is intended to house the RPC commands that are supported by
- // a wallet server.
- package btcjson
- // AddMultisigAddressCmd defines the addmutisigaddress JSON-RPC command.
- type AddMultisigAddressCmd struct {
- NRequired int
- Keys []string
- }
- type AddP2shScriptCmd struct {
- Script string
- Segwit bool
- }
- // AddWitnessAddressCmd defines the addwitnessaddress JSON-RPC command.
- type AddWitnessAddressCmd struct {
- Address string
- }
- // NewAddWitnessAddressCmd returns a new instance which can be used to issue a
- // addwitnessaddress JSON-RPC command.
- func NewAddWitnessAddressCmd(address string) *AddWitnessAddressCmd {
- return &AddWitnessAddressCmd{
- Address: address,
- }
- }
- // CreateMultisigCmd defines the createmultisig JSON-RPC command.
- type CreateMultisigCmd struct {
- NRequired int
- Keys []string
- }
- // NewCreateMultisigCmd returns a new instance which can be used to issue a
- // createmultisig JSON-RPC command.
- func NewCreateMultisigCmd(nRequired int, keys []string) *CreateMultisigCmd {
- return &CreateMultisigCmd{
- NRequired: nRequired,
- Keys: keys,
- }
- }
- // DumpPrivKeyCmd defines the dumpprivkey JSON-RPC command.
- type DumpPrivKeyCmd struct {
- Address string
- }
- // NewDumpPrivKeyCmd returns a new instance which can be used to issue a
- // dumpprivkey JSON-RPC command.
- func NewDumpPrivKeyCmd(address string) *DumpPrivKeyCmd {
- return &DumpPrivKeyCmd{
- Address: address,
- }
- }
- // GetAddressBalances defines the getaddressbalances JSON-RPC command.
- type GetAddressBalancesCmd struct {
- MinConf *int `jsonrpcdefault:"1"`
- ShowZeroBalance *bool
- }
- type GetWalletSeedCmd struct{}
- type GetSecretCmd struct {
- Name string
- }
- type ResyncCmd struct {
- FromHeight *int32
- ToHeight *int32
- Addresses *[]string
- DropDb *bool
- }
- type StopResyncCmd struct{}
- // GetBalanceCmd defines the getbalance JSON-RPC command.
- type GetBalanceCmd struct {
- MinConf *int `jsonrpcdefault:"1"`
- }
- type GetNetworkStewardVoteCmd struct{}
- // GetNewAddressCmd defines the getnewaddress JSON-RPC command.
- type GetNewAddressCmd struct {
- Legacy *bool
- }
- // GetReceivedByAddressCmd defines the getreceivedbyaddress JSON-RPC command.
- type GetReceivedByAddressCmd struct {
- Address string
- MinConf *int `jsonrpcdefault:"1"`
- }
- // NewGetReceivedByAddressCmd returns a new instance which can be used to issue
- // a getreceivedbyaddress JSON-RPC command.
- //
- // The parameters which are pointers indicate they are optional. Passing nil
- // for optional parameters will use the default value.
- func NewGetReceivedByAddressCmd(address string, minConf *int) *GetReceivedByAddressCmd {
- return &GetReceivedByAddressCmd{
- Address: address,
- MinConf: minConf,
- }
- }
- // GetTransactionCmd defines the gettransaction JSON-RPC command.
- type GetTransactionCmd struct {
- Txid string
- IncludeWatchOnly *bool `jsonrpcdefault:"false"`
- }
- // NewGetTransactionCmd returns a new instance which can be used to issue a
- // gettransaction JSON-RPC command.
- //
- // The parameters which are pointers indicate they are optional. Passing nil
- // for optional parameters will use the default value.
- func NewGetTransactionCmd(txHash string, includeWatchOnly *bool) *GetTransactionCmd {
- return &GetTransactionCmd{
- Txid: txHash,
- IncludeWatchOnly: includeWatchOnly,
- }
- }
- // ImportPrivKeyCmd defines the importprivkey JSON-RPC command.
- type ImportPrivKeyCmd struct {
- PrivKey string
- Label *string
- Rescan *bool `jsonrpcdefault:"true"`
- Legacy *bool `jsonrpcdefault:"false"`
- }
- // NewImportPrivKeyCmd returns a new instance which can be used to issue a
- // importprivkey JSON-RPC command.
- //
- // The parameters which are pointers indicate they are optional. Passing nil
- // for optional parameters will use the default value.
- func NewImportPrivKeyCmd(privKey string, label *string, rescan *bool) *ImportPrivKeyCmd {
- return &ImportPrivKeyCmd{
- PrivKey: privKey,
- Label: label,
- Rescan: rescan,
- }
- }
- // ListLockUnspentCmd defines the listlockunspent JSON-RPC command.
- type ListLockUnspentCmd struct{}
- // NewListLockUnspentCmd returns a new instance which can be used to issue a
- // listlockunspent JSON-RPC command.
- func NewListLockUnspentCmd() *ListLockUnspentCmd {
- return &ListLockUnspentCmd{}
- }
- // ListReceivedByAddressCmd defines the listreceivedbyaddress JSON-RPC command.
- type ListReceivedByAddressCmd struct {
- MinConf *int `jsonrpcdefault:"1"`
- IncludeEmpty *bool `jsonrpcdefault:"false"`
- IncludeWatchOnly *bool `jsonrpcdefault:"false"`
- }
- // NewListReceivedByAddressCmd returns a new instance which can be used to issue
- // a listreceivedbyaddress JSON-RPC command.
- //
- // The parameters which are pointers indicate they are optional. Passing nil
- // for optional parameters will use the default value.
- func NewListReceivedByAddressCmd(minConf *int, includeEmpty, includeWatchOnly *bool) *ListReceivedByAddressCmd {
- return &ListReceivedByAddressCmd{
- MinConf: minConf,
- IncludeEmpty: includeEmpty,
- IncludeWatchOnly: includeWatchOnly,
- }
- }
- // ListSinceBlockCmd defines the listsinceblock JSON-RPC command.
- type ListSinceBlockCmd struct {
- BlockHash *string
- TargetConfirmations *int `jsonrpcdefault:"1"`
- IncludeWatchOnly *bool `jsonrpcdefault:"false"`
- }
- // NewListSinceBlockCmd returns a new instance which can be used to issue a
- // listsinceblock JSON-RPC command.
- //
- // The parameters which are pointers indicate they are optional. Passing nil
- // for optional parameters will use the default value.
- func NewListSinceBlockCmd(blockHash *string, targetConfirms *int, includeWatchOnly *bool) *ListSinceBlockCmd {
- return &ListSinceBlockCmd{
- BlockHash: blockHash,
- TargetConfirmations: targetConfirms,
- IncludeWatchOnly: includeWatchOnly,
- }
- }
- // ListTransactionsCmd defines the listtransactions JSON-RPC command.
- type ListTransactionsCmd struct {
- Count *int `jsonrpcdefault:"10"`
- From *int `jsonrpcdefault:"0"`
- }
- // ListUnspentCmd defines the listunspent JSON-RPC command.
- type ListUnspentCmd struct {
- MinConf *int `jsonrpcdefault:"1"`
- MaxConf *int `jsonrpcdefault:"9999999"`
- Addresses *[]string
- }
- // NewListUnspentCmd returns a new instance which can be used to issue a
- // listunspent JSON-RPC command.
- //
- // The parameters which are pointers indicate they are optional. Passing nil
- // for optional parameters will use the default value.
- func NewListUnspentCmd(minConf, maxConf *int, addresses *[]string) *ListUnspentCmd {
- return &ListUnspentCmd{
- MinConf: minConf,
- MaxConf: maxConf,
- Addresses: addresses,
- }
- }
- // LockUnspentCmd defines the lockunspent JSON-RPC command.
- type LockUnspentCmd struct {
- Unlock bool
- Transactions []TransactionInput
- LockName *string
- }
- // NewLockUnspentCmd returns a new instance which can be used to issue a
- // lockunspent JSON-RPC command.
- func NewLockUnspentCmd(unlock bool, transactions []TransactionInput) *LockUnspentCmd {
- return &LockUnspentCmd{
- Unlock: unlock,
- Transactions: transactions,
- }
- }
- // SendFromCmd defines the sendfrom JSON-RPC command.
- type SendFromCmd struct {
- ToAddress string
- Amount float64 // In BTC
- FromAddresses *[]string
- MinConf *int `jsonrpcdefault:"1"`
- Comment *string
- CommentTo *string
- MaxInputs *int
- MinHeight *int
- }
- // NewSendFromCmd returns a new instance which can be used to issue a sendfrom
- // JSON-RPC command.
- //
- // The parameters which are pointers indicate they are optional. Passing nil
- // for optional parameters will use the default value.
- func NewSendFromCmd(fromAddresses *[]string, toAddress string, amount float64, minConf *int, comment, commentTo *string) *SendFromCmd {
- return &SendFromCmd{
- FromAddresses: fromAddresses,
- ToAddress: toAddress,
- Amount: amount,
- MinConf: minConf,
- Comment: comment,
- CommentTo: commentTo,
- MinHeight: nil,
- }
- }
- type CreateTransactionCmd struct {
- ToAddress string
- Amount float64
- FromAddresses *[]string
- ElectrumFormat *bool
- ChangeAddress *string
- InputMinHeight *int
- MinConf *int `jsonrpcdefault:"1"`
- Vote *bool
- MaxInputs *int
- AutoLock *string
- }
- // SendManyCmd defines the sendmany JSON-RPC command.
- type SendManyCmd struct {
- Amounts map[string]float64 `jsonrpcusage:"{\"address\":amount,...}"` // In BTC
- FromAddresses *[]string
- MinConf *int `jsonrpcdefault:"1"`
- Comment *string
- MaxInputs *int
- }
- // NewSendManyCmd returns a new instance which can be used to issue a sendmany
- // JSON-RPC command.
- //
- // The parameters which are pointers indicate they are optional. Passing nil
- // for optional parameters will use the default value.
- func NewSendManyCmd(fromAddresses *[]string, amounts map[string]float64, minConf *int, comment *string) *SendManyCmd {
- return &SendManyCmd{
- FromAddresses: fromAddresses,
- Amounts: amounts,
- MinConf: minConf,
- Comment: comment,
- }
- }
- // SendToAddressCmd defines the sendtoaddress JSON-RPC command.
- type SendToAddressCmd struct {
- Address string
- Amount float64
- Comment *string
- CommentTo *string
- }
- // NewSendToAddressCmd returns a new instance which can be used to issue a
- // sendtoaddress JSON-RPC command.
- //
- // The parameters which are pointers indicate they are optional. Passing nil
- // for optional parameters will use the default value.
- func NewSendToAddressCmd(address string, amount float64, comment, commentTo *string) *SendToAddressCmd {
- return &SendToAddressCmd{
- Address: address,
- Amount: amount,
- Comment: comment,
- CommentTo: commentTo,
- }
- }
- // SetTxFeeCmd defines the settxfee JSON-RPC command.
- type SetTxFeeCmd struct {
- Amount float64 // In BTC
- }
- // NewSetTxFeeCmd returns a new instance which can be used to issue a settxfee
- // JSON-RPC command.
- func NewSetTxFeeCmd(amount float64) *SetTxFeeCmd {
- return &SetTxFeeCmd{
- Amount: amount,
- }
- }
- // SignMessageCmd defines the signmessage JSON-RPC command.
- type SignMessageCmd struct {
- Address string
- Message string
- }
- // NewSignMessageCmd returns a new instance which can be used to issue a
- // signmessage JSON-RPC command.
- func NewSignMessageCmd(address, message string) *SignMessageCmd {
- return &SignMessageCmd{
- Address: address,
- Message: message,
- }
- }
- // RawTxInput models the data needed for raw transaction input that is used in
- // the SignRawTransactionCmd struct.
- type RawTxInput struct {
- Txid string `json:"txid"`
- Vout uint32 `json:"vout"`
- ScriptPubKey string `json:"scriptPubKey"`
- RedeemScript string `json:"redeemScript"`
- }
- // SignRawTransactionCmd defines the signrawtransaction JSON-RPC command.
- type SignRawTransactionCmd struct {
- RawTx string
- Inputs *[]RawTxInput
- PrivKeys *[]string
- Flags *string `jsonrpcdefault:"\"ALL\""`
- }
- // NewSignRawTransactionCmd returns a new instance which can be used to issue a
- // signrawtransaction JSON-RPC command.
- //
- // The parameters which are pointers indicate they are optional. Passing nil
- // for optional parameters will use the default value.
- func NewSignRawTransactionCmd(hexEncodedTx string, inputs *[]RawTxInput, privKeys *[]string, flags *string) *SignRawTransactionCmd {
- return &SignRawTransactionCmd{
- RawTx: hexEncodedTx,
- Inputs: inputs,
- PrivKeys: privKeys,
- Flags: flags,
- }
- }
- // WalletLockCmd defines the walletlock JSON-RPC command.
- type WalletLockCmd struct{}
- // NewWalletLockCmd returns a new instance which can be used to issue a
- // walletlock JSON-RPC command.
- func NewWalletLockCmd() *WalletLockCmd {
- return &WalletLockCmd{}
- }
- // WalletPassphraseCmd defines the walletpassphrase JSON-RPC command.
- type WalletPassphraseCmd struct {
- Passphrase string
- Timeout int64
- }
- // NewWalletPassphraseCmd returns a new instance which can be used to issue a
- // walletpassphrase JSON-RPC command.
- func NewWalletPassphraseCmd(passphrase string, timeout int64) *WalletPassphraseCmd {
- return &WalletPassphraseCmd{
- Passphrase: passphrase,
- Timeout: timeout,
- }
- }
- // WalletPassphraseChangeCmd defines the walletpassphrase JSON-RPC command.
- type WalletPassphraseChangeCmd struct {
- OldPassphrase string
- NewPassphrase string
- }
- // NewWalletPassphraseChangeCmd returns a new instance which can be used to
- // issue a walletpassphrasechange JSON-RPC command.
- func NewWalletPassphraseChangeCmd(oldPassphrase, newPassphrase string) *WalletPassphraseChangeCmd {
- return &WalletPassphraseChangeCmd{
- OldPassphrase: oldPassphrase,
- NewPassphrase: newPassphrase,
- }
- }
- type WalletMempoolCmd struct{}
- // SetNetworkStewardVoteCmd is the argument to the wallet command setnetworkstewardvote
- type SetNetworkStewardVoteCmd struct {
- VoteFor *string `json:"votefor"`
- VoteAgainst *string `json:"voteagainst"`
- }
- func init() {
- // The commands in this file are only usable with a wallet server.
- flags := UFWalletOnly
- MustRegisterCmd("addmultisigaddress", (*AddMultisigAddressCmd)(nil), flags)
- MustRegisterCmd("addp2shscript", (*AddP2shScriptCmd)(nil), flags)
- MustRegisterCmd("addwitnessaddress", (*AddWitnessAddressCmd)(nil), flags)
- MustRegisterCmd("createmultisig", (*CreateMultisigCmd)(nil), flags)
- MustRegisterCmd("createtransaction", (*CreateTransactionCmd)(nil), flags)
- MustRegisterCmd("getaddressbalances", (*GetAddressBalancesCmd)(nil), flags)
- MustRegisterCmd("resync", (*ResyncCmd)(nil), flags)
- MustRegisterCmd("stopresync", (*StopResyncCmd)(nil), flags)
- MustRegisterCmd("dumpprivkey", (*DumpPrivKeyCmd)(nil), flags)
- MustRegisterCmd("getbalance", (*GetBalanceCmd)(nil), flags)
- MustRegisterCmd("getnetworkstewardvote", (*GetNetworkStewardVoteCmd)(nil), flags)
- MustRegisterCmd("getnewaddress", (*GetNewAddressCmd)(nil), flags)
- MustRegisterCmd("getreceivedbyaddress", (*GetReceivedByAddressCmd)(nil), flags)
- MustRegisterCmd("gettransaction", (*GetTransactionCmd)(nil), flags)
- MustRegisterCmd("getwalletseed", (*GetWalletSeedCmd)(nil), flags)
- MustRegisterCmd("getsecret", (*GetSecretCmd)(nil), flags)
- MustRegisterCmd("importprivkey", (*ImportPrivKeyCmd)(nil), flags)
- MustRegisterCmd("listlockunspent", (*ListLockUnspentCmd)(nil), flags)
- MustRegisterCmd("listreceivedbyaddress", (*ListReceivedByAddressCmd)(nil), flags)
- MustRegisterCmd("listsinceblock", (*ListSinceBlockCmd)(nil), flags)
- MustRegisterCmd("listtransactions", (*ListTransactionsCmd)(nil), flags)
- MustRegisterCmd("listunspent", (*ListUnspentCmd)(nil), flags)
- MustRegisterCmd("lockunspent", (*LockUnspentCmd)(nil), flags)
- MustRegisterCmd("sendfrom", (*SendFromCmd)(nil), flags)
- MustRegisterCmd("sendmany", (*SendManyCmd)(nil), flags)
- MustRegisterCmd("sendtoaddress", (*SendToAddressCmd)(nil), flags)
- MustRegisterCmd("setnetworkstewardvote", (*SetNetworkStewardVoteCmd)(nil), flags)
- MustRegisterCmd("settxfee", (*SetTxFeeCmd)(nil), flags)
- MustRegisterCmd("signmessage", (*SignMessageCmd)(nil), flags)
- MustRegisterCmd("signrawtransaction", (*SignRawTransactionCmd)(nil), flags)
- MustRegisterCmd("walletlock", (*WalletLockCmd)(nil), flags)
- MustRegisterCmd("walletpassphrase", (*WalletPassphraseCmd)(nil), flags)
- MustRegisterCmd("walletpassphrasechange", (*WalletPassphraseChangeCmd)(nil), flags)
- MustRegisterCmd("walletmempool", (*WalletMempoolCmd)(nil), flags)
- }
|