mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[NOD-240] Get rid of all references for wallet related RPC commands (#361)
* [NOD-240] Removed references to the wallet in rpcserver.go. * [NOD-240] Began removing btcwalletxxx.go. * [NOD-240] Got rid of rpcclient/wallet.go and walletsvrcmds.go. * [NOD-240] Moved GetBestBlockResult to dagsvrresults.go. * [NOD-240] Finished removing walletsvrXXX.go. * [NOD-240] Removed wallet stuff from btcctl. * [NOD-240] Removed a few last things that I've missed.
This commit is contained in:
parent
e5485ac5e6
commit
bb3f23b6dc
@ -22,7 +22,7 @@ import (
|
||||
func TestBtcdExtCmds(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testID := int(1)
|
||||
testID := 1
|
||||
tests := []struct {
|
||||
name string
|
||||
newCmd func() (interface{}, error)
|
||||
|
@ -1,104 +0,0 @@
|
||||
// Copyright (c) 2015 The btcsuite developers
|
||||
// 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 with btcwallet extensions.
|
||||
|
||||
package btcjson
|
||||
|
||||
// CreateNewAccountCmd defines the createNewAccount JSON-RPC command.
|
||||
type CreateNewAccountCmd struct {
|
||||
Account string
|
||||
}
|
||||
|
||||
// NewCreateNewAccountCmd returns a new instance which can be used to issue a
|
||||
// createNewAccount JSON-RPC command.
|
||||
func NewCreateNewAccountCmd(account string) *CreateNewAccountCmd {
|
||||
return &CreateNewAccountCmd{
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// DumpWalletCmd defines the dumpWallet JSON-RPC command.
|
||||
type DumpWalletCmd struct {
|
||||
Filename string
|
||||
}
|
||||
|
||||
// NewDumpWalletCmd returns a new instance which can be used to issue a
|
||||
// dumpWallet JSON-RPC command.
|
||||
func NewDumpWalletCmd(filename string) *DumpWalletCmd {
|
||||
return &DumpWalletCmd{
|
||||
Filename: filename,
|
||||
}
|
||||
}
|
||||
|
||||
// ImportAddressCmd defines the importAddress JSON-RPC command.
|
||||
type ImportAddressCmd struct {
|
||||
Address string
|
||||
Rescan *bool `jsonrpcdefault:"true"`
|
||||
}
|
||||
|
||||
// NewImportAddressCmd returns a new instance which can be used to issue an
|
||||
// importAddress JSON-RPC command.
|
||||
func NewImportAddressCmd(address string, rescan *bool) *ImportAddressCmd {
|
||||
return &ImportAddressCmd{
|
||||
Address: address,
|
||||
Rescan: rescan,
|
||||
}
|
||||
}
|
||||
|
||||
// ImportPubKeyCmd defines the importPubKey JSON-RPC command.
|
||||
type ImportPubKeyCmd struct {
|
||||
PubKey string
|
||||
Rescan *bool `jsonrpcdefault:"true"`
|
||||
}
|
||||
|
||||
// NewImportPubKeyCmd returns a new instance which can be used to issue an
|
||||
// importPubKey JSON-RPC command.
|
||||
func NewImportPubKeyCmd(pubKey string, rescan *bool) *ImportPubKeyCmd {
|
||||
return &ImportPubKeyCmd{
|
||||
PubKey: pubKey,
|
||||
Rescan: rescan,
|
||||
}
|
||||
}
|
||||
|
||||
// ImportWalletCmd defines the importWallet JSON-RPC command.
|
||||
type ImportWalletCmd struct {
|
||||
Filename string
|
||||
}
|
||||
|
||||
// NewImportWalletCmd returns a new instance which can be used to issue a
|
||||
// importWallet JSON-RPC command.
|
||||
func NewImportWalletCmd(filename string) *ImportWalletCmd {
|
||||
return &ImportWalletCmd{
|
||||
Filename: filename,
|
||||
}
|
||||
}
|
||||
|
||||
// RenameAccountCmd defines the renameAccount JSON-RPC command.
|
||||
type RenameAccountCmd struct {
|
||||
OldAccount string
|
||||
NewAccount string
|
||||
}
|
||||
|
||||
// NewRenameAccountCmd returns a new instance which can be used to issue a
|
||||
// renameAccount JSON-RPC command.
|
||||
func NewRenameAccountCmd(oldAccount, newAccount string) *RenameAccountCmd {
|
||||
return &RenameAccountCmd{
|
||||
OldAccount: oldAccount,
|
||||
NewAccount: newAccount,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
// The commands in this file are only usable with a wallet server.
|
||||
flags := UFWalletOnly
|
||||
|
||||
MustRegisterCmd("createNewAccount", (*CreateNewAccountCmd)(nil), flags)
|
||||
MustRegisterCmd("dumpWallet", (*DumpWalletCmd)(nil), flags)
|
||||
MustRegisterCmd("importAddress", (*ImportAddressCmd)(nil), flags)
|
||||
MustRegisterCmd("importPubKey", (*ImportPubKeyCmd)(nil), flags)
|
||||
MustRegisterCmd("importWallet", (*ImportWalletCmd)(nil), flags)
|
||||
MustRegisterCmd("renameAccount", (*RenameAccountCmd)(nil), flags)
|
||||
}
|
@ -1,208 +0,0 @@
|
||||
// Copyright (c) 2014 The btcsuite developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package btcjson_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/daglabs/btcd/btcjson"
|
||||
)
|
||||
|
||||
// TestBtcWalletExtCmds tests all of the btcwallet extended commands marshal and
|
||||
// unmarshal into valid results include handling of optional fields being
|
||||
// omitted in the marshalled command, while optional fields with defaults have
|
||||
// the default assigned on unmarshalled commands.
|
||||
func TestBtcWalletExtCmds(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testID := int(1)
|
||||
tests := []struct {
|
||||
name string
|
||||
newCmd func() (interface{}, error)
|
||||
staticCmd func() interface{}
|
||||
marshalled string
|
||||
unmarshalled interface{}
|
||||
}{
|
||||
{
|
||||
name: "createNewAccount",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("createNewAccount", "acct")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewCreateNewAccountCmd("acct")
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"createNewAccount","params":["acct"],"id":1}`,
|
||||
unmarshalled: &btcjson.CreateNewAccountCmd{
|
||||
Account: "acct",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "dumpWallet",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("dumpWallet", "filename")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewDumpWalletCmd("filename")
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"dumpWallet","params":["filename"],"id":1}`,
|
||||
unmarshalled: &btcjson.DumpWalletCmd{
|
||||
Filename: "filename",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "importAddress",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("importAddress", "1Address")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewImportAddressCmd("1Address", nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"importAddress","params":["1Address"],"id":1}`,
|
||||
unmarshalled: &btcjson.ImportAddressCmd{
|
||||
Address: "1Address",
|
||||
Rescan: btcjson.Bool(true),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "importAddress optional",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("importAddress", "1Address", false)
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewImportAddressCmd("1Address", btcjson.Bool(false))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"importAddress","params":["1Address",false],"id":1}`,
|
||||
unmarshalled: &btcjson.ImportAddressCmd{
|
||||
Address: "1Address",
|
||||
Rescan: btcjson.Bool(false),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "importPubKey",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("importPubKey", "031234")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewImportPubKeyCmd("031234", nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"importPubKey","params":["031234"],"id":1}`,
|
||||
unmarshalled: &btcjson.ImportPubKeyCmd{
|
||||
PubKey: "031234",
|
||||
Rescan: btcjson.Bool(true),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "importPubKey optional",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("importPubKey", "031234", false)
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewImportPubKeyCmd("031234", btcjson.Bool(false))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"importPubKey","params":["031234",false],"id":1}`,
|
||||
unmarshalled: &btcjson.ImportPubKeyCmd{
|
||||
PubKey: "031234",
|
||||
Rescan: btcjson.Bool(false),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "importWallet",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("importWallet", "filename")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewImportWalletCmd("filename")
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"importWallet","params":["filename"],"id":1}`,
|
||||
unmarshalled: &btcjson.ImportWalletCmd{
|
||||
Filename: "filename",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "renameAccount",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("renameAccount", "oldacct", "newacct")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewRenameAccountCmd("oldacct", "newacct")
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"renameAccount","params":["oldacct","newacct"],"id":1}`,
|
||||
unmarshalled: &btcjson.RenameAccountCmd{
|
||||
OldAccount: "oldacct",
|
||||
NewAccount: "newacct",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
for i, test := range tests {
|
||||
// Marshal the command as created by the new static command
|
||||
// creation function.
|
||||
marshalled, err := btcjson.MarshalCmd(testID, test.staticCmd())
|
||||
if err != nil {
|
||||
t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(marshalled, []byte(test.marshalled)) {
|
||||
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
|
||||
"got %s, want %s", i, test.name, marshalled,
|
||||
test.marshalled)
|
||||
continue
|
||||
}
|
||||
|
||||
// Ensure the command is created without error via the generic
|
||||
// new command creation function.
|
||||
cmd, err := test.newCmd()
|
||||
if err != nil {
|
||||
t.Errorf("Test #%d (%s) unexpected NewCmd error: %v ",
|
||||
i, test.name, err)
|
||||
}
|
||||
|
||||
// Marshal the command as created by the generic new command
|
||||
// creation function.
|
||||
marshalled, err = btcjson.MarshalCmd(testID, cmd)
|
||||
if err != nil {
|
||||
t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(marshalled, []byte(test.marshalled)) {
|
||||
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
|
||||
"got %s, want %s", i, test.name, marshalled,
|
||||
test.marshalled)
|
||||
continue
|
||||
}
|
||||
|
||||
var request btcjson.Request
|
||||
if err := json.Unmarshal(marshalled, &request); err != nil {
|
||||
t.Errorf("Test #%d (%s) unexpected error while "+
|
||||
"unmarshalling JSON-RPC request: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
cmd, err = btcjson.UnmarshalCmd(&request)
|
||||
if err != nil {
|
||||
t.Errorf("UnmarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(cmd, test.unmarshalled) {
|
||||
t.Errorf("Test #%d (%s) unexpected unmarshalled command "+
|
||||
"- got %s, want %s", i, test.name,
|
||||
fmt.Sprintf("(%T) %+[1]v", cmd),
|
||||
fmt.Sprintf("(%T) %+[1]v\n", test.unmarshalled))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
@ -90,11 +90,6 @@ func TestMethodUsageFlags(t *testing.T) {
|
||||
method: "getBlock",
|
||||
flags: 0,
|
||||
},
|
||||
{
|
||||
name: "walletPassphrase",
|
||||
method: "walletPassphrase",
|
||||
flags: btcjson.UFWalletOnly,
|
||||
},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
|
@ -502,3 +502,9 @@ type ValidateAddressResult struct {
|
||||
IsValid bool `json:"isValid"`
|
||||
Address string `json:"address,omitempty"`
|
||||
}
|
||||
|
||||
// GetBestBlockResult models the data from the getbestblock command.
|
||||
type GetBestBlockResult struct {
|
||||
Hash string `json:"hash"`
|
||||
Height uint64 `json:"height"`
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ function.
|
||||
Command Inspection
|
||||
|
||||
All registered commands are registered with flags that identify information such
|
||||
as whether the command applies to a dag server, wallet server, or is a
|
||||
as whether the command applies to a dag server or is a
|
||||
notification along with the method name to use. These flags can be obtained
|
||||
with the MethodUsageFlags flags, and the method can be obtained with the
|
||||
CmdMethod function.
|
||||
|
@ -48,19 +48,6 @@ const (
|
||||
ErrRPCClientNodeNotAdded RPCErrorCode = -24
|
||||
)
|
||||
|
||||
// Wallet JSON errors
|
||||
const (
|
||||
ErrRPCWallet RPCErrorCode = -4
|
||||
ErrRPCWalletInsufficientFunds RPCErrorCode = -6
|
||||
ErrRPCWalletInvalidAccountName RPCErrorCode = -11
|
||||
ErrRPCWalletKeypoolRanOut RPCErrorCode = -12
|
||||
ErrRPCWalletUnlockNeeded RPCErrorCode = -13
|
||||
ErrRPCWalletPassphraseIncorrect RPCErrorCode = -14
|
||||
ErrRPCWalletWrongEncState RPCErrorCode = -15
|
||||
ErrRPCWalletEncryptionFailed RPCErrorCode = -16
|
||||
ErrRPCWalletAlreadyUnlocked RPCErrorCode = -17
|
||||
)
|
||||
|
||||
// Specific Errors related to commands. These are the ones a user of the RPC
|
||||
// server are most likely to see. Generally, the codes should match one of the
|
||||
// more general errors above.
|
||||
@ -81,6 +68,5 @@ const (
|
||||
|
||||
// Errors that are specific to btcd.
|
||||
const (
|
||||
ErrRPCNoWallet RPCErrorCode = -1
|
||||
ErrRPCUnimplemented RPCErrorCode = -1
|
||||
)
|
||||
|
@ -19,15 +19,11 @@ import (
|
||||
type UsageFlag uint32
|
||||
|
||||
const (
|
||||
// UFWalletOnly indicates that the command can only be used with an RPC
|
||||
// server that supports wallet commands.
|
||||
UFWalletOnly UsageFlag = 1 << iota
|
||||
|
||||
// UFWebsocketOnly indicates that the command can only be used when
|
||||
// communicating with an RPC server over websockets. This typically
|
||||
// applies to notifications and notification registration functions
|
||||
// since neiher makes since when using a single-shot HTTP-POST request.
|
||||
UFWebsocketOnly
|
||||
UFWebsocketOnly UsageFlag = 1 << iota
|
||||
|
||||
// UFNotification indicates that the command is actually a notification.
|
||||
// This means when it is marshalled, the ID must be nil.
|
||||
@ -41,7 +37,6 @@ const (
|
||||
|
||||
// Map of UsageFlag values back to their constant names for pretty printing.
|
||||
var usageFlagStrings = map[UsageFlag]string{
|
||||
UFWalletOnly: "UFWalletOnly",
|
||||
UFWebsocketOnly: "UFWebsocketOnly",
|
||||
UFNotification: "UFNotification",
|
||||
}
|
||||
@ -55,7 +50,7 @@ func (fl UsageFlag) String() string {
|
||||
|
||||
// Add individual bit flags.
|
||||
s := ""
|
||||
for flag := UFWalletOnly; flag < highestUsageFlagBit; flag <<= 1 {
|
||||
for flag := UFWebsocketOnly; flag < highestUsageFlagBit; flag <<= 1 {
|
||||
if fl&flag == flag {
|
||||
s += usageFlagStrings[flag] + "|"
|
||||
fl -= flag
|
||||
|
@ -21,13 +21,12 @@ func TestUsageFlagStringer(t *testing.T) {
|
||||
want string
|
||||
}{
|
||||
{0, "0x0"},
|
||||
{btcjson.UFWalletOnly, "UFWalletOnly"},
|
||||
{btcjson.UFWebsocketOnly, "UFWebsocketOnly"},
|
||||
{btcjson.UFNotification, "UFNotification"},
|
||||
{btcjson.UFWalletOnly | btcjson.UFWebsocketOnly,
|
||||
"UFWalletOnly|UFWebsocketOnly"},
|
||||
{btcjson.UFWalletOnly | btcjson.UFWebsocketOnly | (1 << 31),
|
||||
"UFWalletOnly|UFWebsocketOnly|0x80000000"},
|
||||
{btcjson.UFWebsocketOnly | btcjson.UFNotification,
|
||||
"UFWebsocketOnly|UFNotification"},
|
||||
{btcjson.UFWebsocketOnly | btcjson.UFNotification | (1 << 31),
|
||||
"UFWebsocketOnly|UFNotification|0x80000000"},
|
||||
}
|
||||
|
||||
// Detect additional usage flags that don't have the stringer added.
|
||||
|
@ -1,671 +0,0 @@
|
||||
// Copyright (c) 2014 The btcsuite developers
|
||||
// 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
|
||||
Account *string
|
||||
}
|
||||
|
||||
// NewAddMultisigAddressCmd returns a new instance which can be used to issue a
|
||||
// addMultisigAddress JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewAddMultisigAddressCmd(nRequired int, keys []string, account *string) *AddMultisigAddressCmd {
|
||||
return &AddMultisigAddressCmd{
|
||||
NRequired: nRequired,
|
||||
Keys: keys,
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
|
||||
// EncryptWalletCmd defines the encryptWallet JSON-RPC command.
|
||||
type EncryptWalletCmd struct {
|
||||
Passphrase string
|
||||
}
|
||||
|
||||
// NewEncryptWalletCmd returns a new instance which can be used to issue a
|
||||
// encryptWallet JSON-RPC command.
|
||||
func NewEncryptWalletCmd(passphrase string) *EncryptWalletCmd {
|
||||
return &EncryptWalletCmd{
|
||||
Passphrase: passphrase,
|
||||
}
|
||||
}
|
||||
|
||||
// EstimatePriorityCmd defines the estimatePriority JSON-RPC command.
|
||||
type EstimatePriorityCmd struct {
|
||||
NumBlocks int64
|
||||
}
|
||||
|
||||
// NewEstimatePriorityCmd returns a new instance which can be used to issue a
|
||||
// estimatePriority JSON-RPC command.
|
||||
func NewEstimatePriorityCmd(numBlocks int64) *EstimatePriorityCmd {
|
||||
return &EstimatePriorityCmd{
|
||||
NumBlocks: numBlocks,
|
||||
}
|
||||
}
|
||||
|
||||
// GetAccountCmd defines the getAccount JSON-RPC command.
|
||||
type GetAccountCmd struct {
|
||||
Address string
|
||||
}
|
||||
|
||||
// NewGetAccountCmd returns a new instance which can be used to issue a
|
||||
// getAccount JSON-RPC command.
|
||||
func NewGetAccountCmd(address string) *GetAccountCmd {
|
||||
return &GetAccountCmd{
|
||||
Address: address,
|
||||
}
|
||||
}
|
||||
|
||||
// GetAccountAddressCmd defines the getAccountAddress JSON-RPC command.
|
||||
type GetAccountAddressCmd struct {
|
||||
Account string
|
||||
}
|
||||
|
||||
// NewGetAccountAddressCmd returns a new instance which can be used to issue a
|
||||
// getAccountAddress JSON-RPC command.
|
||||
func NewGetAccountAddressCmd(account string) *GetAccountAddressCmd {
|
||||
return &GetAccountAddressCmd{
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// GetAddressesByAccountCmd defines the getAddressesByAccount JSON-RPC command.
|
||||
type GetAddressesByAccountCmd struct {
|
||||
Account string
|
||||
}
|
||||
|
||||
// NewGetAddressesByAccountCmd returns a new instance which can be used to issue
|
||||
// a getAddressesByAccount JSON-RPC command.
|
||||
func NewGetAddressesByAccountCmd(account string) *GetAddressesByAccountCmd {
|
||||
return &GetAddressesByAccountCmd{
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// GetBalanceCmd defines the getBalance JSON-RPC command.
|
||||
type GetBalanceCmd struct {
|
||||
Account *string
|
||||
MinConf *int `jsonrpcdefault:"1"`
|
||||
}
|
||||
|
||||
// NewGetBalanceCmd returns a new instance which can be used to issue a
|
||||
// getBalance JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewGetBalanceCmd(account *string, minConf *int) *GetBalanceCmd {
|
||||
return &GetBalanceCmd{
|
||||
Account: account,
|
||||
MinConf: minConf,
|
||||
}
|
||||
}
|
||||
|
||||
// GetNewAddressCmd defines the getNewAddress JSON-RPC command.
|
||||
type GetNewAddressCmd struct {
|
||||
Account *string
|
||||
}
|
||||
|
||||
// NewGetNewAddressCmd returns a new instance which can be used to issue a
|
||||
// getNewAddress JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewGetNewAddressCmd(account *string) *GetNewAddressCmd {
|
||||
return &GetNewAddressCmd{
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// GetRawChangeAddressCmd defines the getRawChangeAddress JSON-RPC command.
|
||||
type GetRawChangeAddressCmd struct {
|
||||
Account *string
|
||||
}
|
||||
|
||||
// NewGetRawChangeAddressCmd returns a new instance which can be used to issue a
|
||||
// getRawChangeAddress JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewGetRawChangeAddressCmd(account *string) *GetRawChangeAddressCmd {
|
||||
return &GetRawChangeAddressCmd{
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// GetReceivedByAccountCmd defines the getReceivedByAccount JSON-RPC command.
|
||||
type GetReceivedByAccountCmd struct {
|
||||
Account string
|
||||
MinConf *int `jsonrpcdefault:"1"`
|
||||
}
|
||||
|
||||
// NewGetReceivedByAccountCmd returns a new instance which can be used to issue
|
||||
// a getReceivedByAccount JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewGetReceivedByAccountCmd(account string, minConf *int) *GetReceivedByAccountCmd {
|
||||
return &GetReceivedByAccountCmd{
|
||||
Account: account,
|
||||
MinConf: minConf,
|
||||
}
|
||||
}
|
||||
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
|
||||
// GetWalletInfoCmd defines the getWalletInfo JSON-RPC command.
|
||||
type GetWalletInfoCmd struct{}
|
||||
|
||||
// NewGetWalletInfoCmd returns a new instance which can be used to issue a
|
||||
// getWalletInfo JSON-RPC command.
|
||||
func NewGetWalletInfoCmd() *GetWalletInfoCmd {
|
||||
return &GetWalletInfoCmd{}
|
||||
}
|
||||
|
||||
// ImportPrivKeyCmd defines the importPrivKey JSON-RPC command.
|
||||
type ImportPrivKeyCmd struct {
|
||||
PrivKey string
|
||||
Label *string
|
||||
Rescan *bool `jsonrpcdefault:"true"`
|
||||
}
|
||||
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
|
||||
// KeyPoolRefillCmd defines the keyPoolRefill JSON-RPC command.
|
||||
type KeyPoolRefillCmd struct {
|
||||
NewSize *uint `jsonrpcdefault:"100"`
|
||||
}
|
||||
|
||||
// NewKeyPoolRefillCmd returns a new instance which can be used to issue a
|
||||
// keyPoolRefill JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewKeyPoolRefillCmd(newSize *uint) *KeyPoolRefillCmd {
|
||||
return &KeyPoolRefillCmd{
|
||||
NewSize: newSize,
|
||||
}
|
||||
}
|
||||
|
||||
// ListAccountsCmd defines the listAccounts JSON-RPC command.
|
||||
type ListAccountsCmd struct {
|
||||
MinConf *int `jsonrpcdefault:"1"`
|
||||
}
|
||||
|
||||
// NewListAccountsCmd returns a new instance which can be used to issue a
|
||||
// listAccounts JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewListAccountsCmd(minConf *int) *ListAccountsCmd {
|
||||
return &ListAccountsCmd{
|
||||
MinConf: minConf,
|
||||
}
|
||||
}
|
||||
|
||||
// ListAddressGroupingsCmd defines the listAddressGroupings JSON-RPC command.
|
||||
type ListAddressGroupingsCmd struct{}
|
||||
|
||||
// NewListAddressGroupingsCmd returns a new instance which can be used to issue
|
||||
// a listaddressgroupoings JSON-RPC command.
|
||||
func NewListAddressGroupingsCmd() *ListAddressGroupingsCmd {
|
||||
return &ListAddressGroupingsCmd{}
|
||||
}
|
||||
|
||||
// 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{}
|
||||
}
|
||||
|
||||
// ListReceivedByAccountCmd defines the listReceivedByAccount JSON-RPC command.
|
||||
type ListReceivedByAccountCmd struct {
|
||||
MinConf *int `jsonrpcdefault:"1"`
|
||||
IncludeEmpty *bool `jsonrpcdefault:"false"`
|
||||
IncludeWatchOnly *bool `jsonrpcdefault:"false"`
|
||||
}
|
||||
|
||||
// NewListReceivedByAccountCmd returns a new instance which can be used to issue
|
||||
// a listReceivedByAccount JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewListReceivedByAccountCmd(minConf *int, includeEmpty, includeWatchOnly *bool) *ListReceivedByAccountCmd {
|
||||
return &ListReceivedByAccountCmd{
|
||||
MinConf: minConf,
|
||||
IncludeEmpty: includeEmpty,
|
||||
IncludeWatchOnly: includeWatchOnly,
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
Account *string
|
||||
Count *int `jsonrpcdefault:"10"`
|
||||
From *int `jsonrpcdefault:"0"`
|
||||
IncludeWatchOnly *bool `jsonrpcdefault:"false"`
|
||||
}
|
||||
|
||||
// NewListTransactionsCmd returns a new instance which can be used to issue a
|
||||
// listTransactions JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewListTransactionsCmd(account *string, count, from *int, includeWatchOnly *bool) *ListTransactionsCmd {
|
||||
return &ListTransactionsCmd{
|
||||
Account: account,
|
||||
Count: count,
|
||||
From: from,
|
||||
IncludeWatchOnly: includeWatchOnly,
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
|
||||
// MoveCmd defines the move JSON-RPC command.
|
||||
type MoveCmd struct {
|
||||
FromAccount string
|
||||
ToAccount string
|
||||
Amount float64 // In BTC
|
||||
MinConf *int `jsonrpcdefault:"1"`
|
||||
Comment *string
|
||||
}
|
||||
|
||||
// NewMoveCmd returns a new instance which can be used to issue a move JSON-RPC
|
||||
// command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewMoveCmd(fromAccount, toAccount string, amount float64, minConf *int, comment *string) *MoveCmd {
|
||||
return &MoveCmd{
|
||||
FromAccount: fromAccount,
|
||||
ToAccount: toAccount,
|
||||
Amount: amount,
|
||||
MinConf: minConf,
|
||||
Comment: comment,
|
||||
}
|
||||
}
|
||||
|
||||
// SendFromCmd defines the sendFrom JSON-RPC command.
|
||||
type SendFromCmd struct {
|
||||
FromAccount string
|
||||
ToAddress string
|
||||
Amount float64 // In BTC
|
||||
MinConf *int `jsonrpcdefault:"1"`
|
||||
Comment *string
|
||||
CommentTo *string
|
||||
}
|
||||
|
||||
// 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(fromAccount, toAddress string, amount float64, minConf *int, comment, commentTo *string) *SendFromCmd {
|
||||
return &SendFromCmd{
|
||||
FromAccount: fromAccount,
|
||||
ToAddress: toAddress,
|
||||
Amount: amount,
|
||||
MinConf: minConf,
|
||||
Comment: comment,
|
||||
CommentTo: commentTo,
|
||||
}
|
||||
}
|
||||
|
||||
// SendManyCmd defines the sendMany JSON-RPC command.
|
||||
type SendManyCmd struct {
|
||||
FromAccount string
|
||||
Amounts map[string]float64 `jsonrpcusage:"{\"address\":amount,...}"` // In BTC
|
||||
MinConf *int `jsonrpcdefault:"1"`
|
||||
Comment *string
|
||||
}
|
||||
|
||||
// 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(fromAccount string, amounts map[string]float64, minConf *int, comment *string) *SendManyCmd {
|
||||
return &SendManyCmd{
|
||||
FromAccount: fromAccount,
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
// SetAccountCmd defines the setAccount JSON-RPC command.
|
||||
type SetAccountCmd struct {
|
||||
Address string
|
||||
Account string
|
||||
}
|
||||
|
||||
// NewSetAccountCmd returns a new instance which can be used to issue a
|
||||
// setAccount JSON-RPC command.
|
||||
func NewSetAccountCmd(address, account string) *SetAccountCmd {
|
||||
return &SetAccountCmd{
|
||||
Address: address,
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
// The commands in this file are only usable with a wallet server.
|
||||
flags := UFWalletOnly
|
||||
|
||||
MustRegisterCmd("addMultisigAddress", (*AddMultisigAddressCmd)(nil), flags)
|
||||
MustRegisterCmd("createMultisig", (*CreateMultisigCmd)(nil), flags)
|
||||
MustRegisterCmd("dumpPrivKey", (*DumpPrivKeyCmd)(nil), flags)
|
||||
MustRegisterCmd("encryptWallet", (*EncryptWalletCmd)(nil), flags)
|
||||
MustRegisterCmd("estimatePriority", (*EstimatePriorityCmd)(nil), flags)
|
||||
MustRegisterCmd("getAccount", (*GetAccountCmd)(nil), flags)
|
||||
MustRegisterCmd("getAccountAddress", (*GetAccountAddressCmd)(nil), flags)
|
||||
MustRegisterCmd("getAddressesByAccount", (*GetAddressesByAccountCmd)(nil), flags)
|
||||
MustRegisterCmd("getBalance", (*GetBalanceCmd)(nil), flags)
|
||||
MustRegisterCmd("getNewAddress", (*GetNewAddressCmd)(nil), flags)
|
||||
MustRegisterCmd("getRawChangeAddress", (*GetRawChangeAddressCmd)(nil), flags)
|
||||
MustRegisterCmd("getReceivedByAccount", (*GetReceivedByAccountCmd)(nil), flags)
|
||||
MustRegisterCmd("getReceivedByAddress", (*GetReceivedByAddressCmd)(nil), flags)
|
||||
MustRegisterCmd("getTransaction", (*GetTransactionCmd)(nil), flags)
|
||||
MustRegisterCmd("getWalletInfo", (*GetWalletInfoCmd)(nil), flags)
|
||||
MustRegisterCmd("importPrivKey", (*ImportPrivKeyCmd)(nil), flags)
|
||||
MustRegisterCmd("keyPoolRefill", (*KeyPoolRefillCmd)(nil), flags)
|
||||
MustRegisterCmd("listAccounts", (*ListAccountsCmd)(nil), flags)
|
||||
MustRegisterCmd("listAddressGroupings", (*ListAddressGroupingsCmd)(nil), flags)
|
||||
MustRegisterCmd("listLockUnspent", (*ListLockUnspentCmd)(nil), flags)
|
||||
MustRegisterCmd("listReceivedByAccount", (*ListReceivedByAccountCmd)(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("move", (*MoveCmd)(nil), flags)
|
||||
MustRegisterCmd("sendFrom", (*SendFromCmd)(nil), flags)
|
||||
MustRegisterCmd("sendMany", (*SendManyCmd)(nil), flags)
|
||||
MustRegisterCmd("sendToAddress", (*SendToAddressCmd)(nil), flags)
|
||||
MustRegisterCmd("setAccount", (*SetAccountCmd)(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)
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,161 +0,0 @@
|
||||
// Copyright (c) 2014 The btcsuite developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package btcjson
|
||||
|
||||
// GetTransactionDetailsResult models the details data from the gettransaction command.
|
||||
//
|
||||
// This models the "short" version of the ListTransactionsResult type, which
|
||||
// excludes fields common to the transaction. These common fields are instead
|
||||
// part of the GetTransactionResult.
|
||||
type GetTransactionDetailsResult struct {
|
||||
Account string `json:"account"`
|
||||
Address string `json:"address,omitempty"`
|
||||
Amount float64 `json:"amount"`
|
||||
Category string `json:"category"`
|
||||
InvolvesWatchOnly bool `json:"involvesWatchOnly,omitempty"`
|
||||
Fee *float64 `json:"fee,omitempty"`
|
||||
Vout uint32 `json:"vout"`
|
||||
}
|
||||
|
||||
// GetTransactionResult models the data from the gettransaction command.
|
||||
type GetTransactionResult struct {
|
||||
Amount float64 `json:"amount"`
|
||||
Fee float64 `json:"fee,omitempty"`
|
||||
Confirmations int64 `json:"confirmations"`
|
||||
BlockHash string `json:"blockHash"`
|
||||
BlockIndex int64 `json:"blockIndex"`
|
||||
BlockTime uint64 `json:"blockTime"`
|
||||
TxID string `json:"txId"`
|
||||
WalletConflicts []string `json:"walletConflicts"`
|
||||
Time int64 `json:"time"`
|
||||
TimeReceived int64 `json:"timeReceived"`
|
||||
Details []GetTransactionDetailsResult `json:"details"`
|
||||
Hex string `json:"hex"`
|
||||
}
|
||||
|
||||
// InfoWalletResult models the data returned by the wallet server getinfo
|
||||
// command.
|
||||
type InfoWalletResult struct {
|
||||
Version int32 `json:"version"`
|
||||
ProtocolVersion int32 `json:"protocolVersion"`
|
||||
WalletVersion int32 `json:"walletVersion"`
|
||||
Balance float64 `json:"balance"`
|
||||
Blocks int32 `json:"blocks"`
|
||||
TimeOffset int64 `json:"timeOffset"`
|
||||
Connections int32 `json:"connections"`
|
||||
Proxy string `json:"proxy"`
|
||||
Difficulty float64 `json:"difficulty"`
|
||||
TestNet bool `json:"testNet"`
|
||||
KeypoolOldest int64 `json:"keypoolOldest"`
|
||||
KeypoolSize int32 `json:"keypoolSize"`
|
||||
UnlockedUntil int64 `json:"unlockedUntil"`
|
||||
PayTxFee float64 `json:"payTxFee"`
|
||||
RelayFee float64 `json:"relayFee"`
|
||||
Errors string `json:"errors"`
|
||||
}
|
||||
|
||||
// ListTransactionsResult models the data from the listtransactions command.
|
||||
type ListTransactionsResult struct {
|
||||
Abandoned bool `json:"abandoned"`
|
||||
Account string `json:"account"`
|
||||
Address string `json:"address,omitempty"`
|
||||
Amount float64 `json:"amount"`
|
||||
BIP125Replaceable string `json:"bip125Replaceable,omitempty"`
|
||||
BlockHash string `json:"blockGash,omitempty"`
|
||||
BlockIndex *int64 `json:"blockIndex,omitempty"`
|
||||
BlockTime uint64 `json:"blockTime,omitempty"`
|
||||
Category string `json:"category"`
|
||||
Confirmations int64 `json:"confirmations"`
|
||||
Fee *float64 `json:"fee,omitempty"`
|
||||
Generated bool `json:"generated,omitempty"`
|
||||
InvolvesWatchOnly bool `json:"involvesWatchOnly,omitempty"`
|
||||
Time int64 `json:"time"`
|
||||
TimeReceived int64 `json:"timeReceived"`
|
||||
Trusted bool `json:"trusted"`
|
||||
TxID string `json:"txId"`
|
||||
Vout uint32 `json:"vout"`
|
||||
WalletConflicts []string `json:"walletConflicts"`
|
||||
Comment string `json:"comment,omitempty"`
|
||||
OtherAccount string `json:"otherAccount,omitempty"`
|
||||
}
|
||||
|
||||
// ListReceivedByAccountResult models the data from the listreceivedbyaccount
|
||||
// command.
|
||||
type ListReceivedByAccountResult struct {
|
||||
Account string `json:"account"`
|
||||
Amount float64 `json:"amount"`
|
||||
Confirmations uint64 `json:"confirmations"`
|
||||
}
|
||||
|
||||
// ListReceivedByAddressResult models the data from the listreceivedbyaddress
|
||||
// command.
|
||||
type ListReceivedByAddressResult struct {
|
||||
Account string `json:"account"`
|
||||
Address string `json:"address"`
|
||||
Amount float64 `json:"amount"`
|
||||
Confirmations uint64 `json:"confirmations"`
|
||||
TxIDs []string `json:"txIds,omitempty"`
|
||||
InvolvesWatchOnly bool `json:"involvesWatchOnly,omitempty"`
|
||||
}
|
||||
|
||||
// ListSinceBlockResult models the data from the listsinceblock command.
|
||||
type ListSinceBlockResult struct {
|
||||
Transactions []ListTransactionsResult `json:"transactions"`
|
||||
LastBlock string `json:"lastBlock"`
|
||||
}
|
||||
|
||||
// ListUnspentResult models a successful response from the listunspent request.
|
||||
type ListUnspentResult struct {
|
||||
TxID string `json:"txId"`
|
||||
Vout uint32 `json:"vout"`
|
||||
Address string `json:"address"`
|
||||
Account string `json:"account"`
|
||||
ScriptPubKey string `json:"scriptPubKey"`
|
||||
RedeemScript string `json:"redeemScript,omitempty"`
|
||||
Amount float64 `json:"amount"`
|
||||
Confirmations int64 `json:"confirmations"`
|
||||
Spendable bool `json:"spendable"`
|
||||
}
|
||||
|
||||
// SignRawTransactionError models the data that contains script verification
|
||||
// errors from the signrawtransaction request.
|
||||
type SignRawTransactionError struct {
|
||||
TxID string `json:"txId"`
|
||||
Vout uint32 `json:"vout"`
|
||||
ScriptSig string `json:"scriptSig"`
|
||||
Sequence uint64 `json:"sequence"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// SignRawTransactionResult models the data from the signrawtransaction
|
||||
// command.
|
||||
type SignRawTransactionResult struct {
|
||||
Hex string `json:"hex"`
|
||||
Complete bool `json:"complete"`
|
||||
Errors []SignRawTransactionError `json:"errors,omitempty"`
|
||||
}
|
||||
|
||||
// ValidateAddressWalletResult models the data returned by the wallet server
|
||||
// validateaddress command.
|
||||
type ValidateAddressWalletResult struct {
|
||||
IsValid bool `json:"isValid"`
|
||||
Address string `json:"address,omitempty"`
|
||||
IsMine bool `json:"isMine,omitempty"`
|
||||
IsWatchOnly bool `json:"isWatchOnly,omitempty"`
|
||||
IsScript bool `json:"isScript,omitempty"`
|
||||
PubKey string `json:"pubKey,omitempty"`
|
||||
IsCompressed bool `json:"isCompressed,omitempty"`
|
||||
Account string `json:"account,omitempty"`
|
||||
Addresses []string `json:"addresses,omitempty"`
|
||||
Hex string `json:"hex,omitempty"`
|
||||
Script string `json:"script,omitempty"`
|
||||
SigsRequired int32 `json:"sigsRequired,omitempty"`
|
||||
}
|
||||
|
||||
// GetBestBlockResult models the data from the getbestblock command.
|
||||
type GetBestBlockResult struct {
|
||||
Hash string `json:"hash"`
|
||||
Height uint64 `json:"height"`
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
// Copyright (c) 2014 The btcsuite developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package btcjson
|
||||
|
||||
// NOTE: This file is intended to house the RPC commands that are supported by
|
||||
// a wallet server, but are only available via websockets.
|
||||
|
||||
// CreateEncryptedWalletCmd defines the createEncryptedWallet JSON-RPC command.
|
||||
type CreateEncryptedWalletCmd struct {
|
||||
Passphrase string
|
||||
}
|
||||
|
||||
// NewCreateEncryptedWalletCmd returns a new instance which can be used to issue
|
||||
// a createEncryptedWallet JSON-RPC command.
|
||||
func NewCreateEncryptedWalletCmd(passphrase string) *CreateEncryptedWalletCmd {
|
||||
return &CreateEncryptedWalletCmd{
|
||||
Passphrase: passphrase,
|
||||
}
|
||||
}
|
||||
|
||||
// ExportWatchingWalletCmd defines the exportWatchingWallet JSON-RPC command.
|
||||
type ExportWatchingWalletCmd struct {
|
||||
Account *string
|
||||
Download *bool `jsonrpcdefault:"false"`
|
||||
}
|
||||
|
||||
// NewExportWatchingWalletCmd returns a new instance which can be used to issue
|
||||
// a exportWatchingWallet JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewExportWatchingWalletCmd(account *string, download *bool) *ExportWatchingWalletCmd {
|
||||
return &ExportWatchingWalletCmd{
|
||||
Account: account,
|
||||
Download: download,
|
||||
}
|
||||
}
|
||||
|
||||
// GetUnconfirmedBalanceCmd defines the getUnconfirmedBalance JSON-RPC command.
|
||||
type GetUnconfirmedBalanceCmd struct {
|
||||
Account *string
|
||||
}
|
||||
|
||||
// NewGetUnconfirmedBalanceCmd returns a new instance which can be used to issue
|
||||
// a getUnconfirmedBalance JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewGetUnconfirmedBalanceCmd(account *string) *GetUnconfirmedBalanceCmd {
|
||||
return &GetUnconfirmedBalanceCmd{
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// ListAddressTransactionsCmd defines the listAddressTransactions JSON-RPC
|
||||
// command.
|
||||
type ListAddressTransactionsCmd struct {
|
||||
Addresses []string
|
||||
Account *string
|
||||
}
|
||||
|
||||
// NewListAddressTransactionsCmd returns a new instance which can be used to
|
||||
// issue a listAddressTransactions JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewListAddressTransactionsCmd(addresses []string, account *string) *ListAddressTransactionsCmd {
|
||||
return &ListAddressTransactionsCmd{
|
||||
Addresses: addresses,
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// ListAllTransactionsCmd defines the listAllTransactions JSON-RPC command.
|
||||
type ListAllTransactionsCmd struct {
|
||||
Account *string
|
||||
}
|
||||
|
||||
// NewListAllTransactionsCmd returns a new instance which can be used to issue a
|
||||
// listAllTransactions JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewListAllTransactionsCmd(account *string) *ListAllTransactionsCmd {
|
||||
return &ListAllTransactionsCmd{
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// RecoverAddressesCmd defines the recoverAddresses JSON-RPC command.
|
||||
type RecoverAddressesCmd struct {
|
||||
Account string
|
||||
N int
|
||||
}
|
||||
|
||||
// NewRecoverAddressesCmd returns a new instance which can be used to issue a
|
||||
// recoverAddresses JSON-RPC command.
|
||||
func NewRecoverAddressesCmd(account string, n int) *RecoverAddressesCmd {
|
||||
return &RecoverAddressesCmd{
|
||||
Account: account,
|
||||
N: n,
|
||||
}
|
||||
}
|
||||
|
||||
// WalletIsLockedCmd defines the walletIsLocked JSON-RPC command.
|
||||
type WalletIsLockedCmd struct{}
|
||||
|
||||
// NewWalletIsLockedCmd returns a new instance which can be used to issue a
|
||||
// walletIsLocked JSON-RPC command.
|
||||
func NewWalletIsLockedCmd() *WalletIsLockedCmd {
|
||||
return &WalletIsLockedCmd{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
// The commands in this file are only usable with a wallet server via
|
||||
// websockets.
|
||||
flags := UFWalletOnly | UFWebsocketOnly
|
||||
|
||||
MustRegisterCmd("createEncryptedWallet", (*CreateEncryptedWalletCmd)(nil), flags)
|
||||
MustRegisterCmd("exportWatchingWallet", (*ExportWatchingWalletCmd)(nil), flags)
|
||||
MustRegisterCmd("getUnconfirmedBalance", (*GetUnconfirmedBalanceCmd)(nil), flags)
|
||||
MustRegisterCmd("listAddressTransactions", (*ListAddressTransactionsCmd)(nil), flags)
|
||||
MustRegisterCmd("listAllTransactions", (*ListAllTransactionsCmd)(nil), flags)
|
||||
MustRegisterCmd("recoverAddresses", (*RecoverAddressesCmd)(nil), flags)
|
||||
MustRegisterCmd("walletIsLocked", (*WalletIsLockedCmd)(nil), flags)
|
||||
}
|
@ -1,259 +0,0 @@
|
||||
// Copyright (c) 2014 The btcsuite developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package btcjson_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/daglabs/btcd/btcjson"
|
||||
)
|
||||
|
||||
// TestWalletSvrWsCmds tests all of the wallet server websocket-specific
|
||||
// commands marshal and unmarshal into valid results include handling of
|
||||
// optional fields being omitted in the marshalled command, while optional
|
||||
// fields with defaults have the default assigned on unmarshalled commands.
|
||||
func TestWalletSvrWsCmds(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testID := int(1)
|
||||
tests := []struct {
|
||||
name string
|
||||
newCmd func() (interface{}, error)
|
||||
staticCmd func() interface{}
|
||||
marshalled string
|
||||
unmarshalled interface{}
|
||||
}{
|
||||
{
|
||||
name: "createEncryptedWallet",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("createEncryptedWallet", "pass")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewCreateEncryptedWalletCmd("pass")
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"createEncryptedWallet","params":["pass"],"id":1}`,
|
||||
unmarshalled: &btcjson.CreateEncryptedWalletCmd{Passphrase: "pass"},
|
||||
},
|
||||
{
|
||||
name: "exportWatchingWallet",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("exportWatchingWallet")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewExportWatchingWalletCmd(nil, nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"exportWatchingWallet","params":[],"id":1}`,
|
||||
unmarshalled: &btcjson.ExportWatchingWalletCmd{
|
||||
Account: nil,
|
||||
Download: btcjson.Bool(false),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "exportWatchingWallet optional1",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("exportWatchingWallet", "acct")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewExportWatchingWalletCmd(btcjson.String("acct"), nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"exportWatchingWallet","params":["acct"],"id":1}`,
|
||||
unmarshalled: &btcjson.ExportWatchingWalletCmd{
|
||||
Account: btcjson.String("acct"),
|
||||
Download: btcjson.Bool(false),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "exportWatchingWallet optional2",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("exportWatchingWallet", "acct", true)
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewExportWatchingWalletCmd(btcjson.String("acct"),
|
||||
btcjson.Bool(true))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"exportWatchingWallet","params":["acct",true],"id":1}`,
|
||||
unmarshalled: &btcjson.ExportWatchingWalletCmd{
|
||||
Account: btcjson.String("acct"),
|
||||
Download: btcjson.Bool(true),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "getUnconfirmedBalance",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("getUnconfirmedBalance")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewGetUnconfirmedBalanceCmd(nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"getUnconfirmedBalance","params":[],"id":1}`,
|
||||
unmarshalled: &btcjson.GetUnconfirmedBalanceCmd{
|
||||
Account: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "getUnconfirmedBalance optional1",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("getUnconfirmedBalance", "acct")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewGetUnconfirmedBalanceCmd(btcjson.String("acct"))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"getUnconfirmedBalance","params":["acct"],"id":1}`,
|
||||
unmarshalled: &btcjson.GetUnconfirmedBalanceCmd{
|
||||
Account: btcjson.String("acct"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "listAddressTransactions",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("listAddressTransactions", `["1Address"]`)
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewListAddressTransactionsCmd([]string{"1Address"}, nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"listAddressTransactions","params":[["1Address"]],"id":1}`,
|
||||
unmarshalled: &btcjson.ListAddressTransactionsCmd{
|
||||
Addresses: []string{"1Address"},
|
||||
Account: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "listAddressTransactions optional1",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("listAddressTransactions", `["1Address"]`, "acct")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewListAddressTransactionsCmd([]string{"1Address"},
|
||||
btcjson.String("acct"))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"listAddressTransactions","params":[["1Address"],"acct"],"id":1}`,
|
||||
unmarshalled: &btcjson.ListAddressTransactionsCmd{
|
||||
Addresses: []string{"1Address"},
|
||||
Account: btcjson.String("acct"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "listAllTransactions",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("listAllTransactions")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewListAllTransactionsCmd(nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"listAllTransactions","params":[],"id":1}`,
|
||||
unmarshalled: &btcjson.ListAllTransactionsCmd{
|
||||
Account: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "listAllTransactions optional",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("listAllTransactions", "acct")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewListAllTransactionsCmd(btcjson.String("acct"))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"listAllTransactions","params":["acct"],"id":1}`,
|
||||
unmarshalled: &btcjson.ListAllTransactionsCmd{
|
||||
Account: btcjson.String("acct"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "recoverAddresses",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("recoverAddresses", "acct", 10)
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewRecoverAddressesCmd("acct", 10)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"recoverAddresses","params":["acct",10],"id":1}`,
|
||||
unmarshalled: &btcjson.RecoverAddressesCmd{
|
||||
Account: "acct",
|
||||
N: 10,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "walletIsLocked",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("walletIsLocked")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewWalletIsLockedCmd()
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"walletIsLocked","params":[],"id":1}`,
|
||||
unmarshalled: &btcjson.WalletIsLockedCmd{},
|
||||
},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
for i, test := range tests {
|
||||
// Marshal the command as created by the new static command
|
||||
// creation function.
|
||||
marshalled, err := btcjson.MarshalCmd(testID, test.staticCmd())
|
||||
if err != nil {
|
||||
t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(marshalled, []byte(test.marshalled)) {
|
||||
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
|
||||
"got %s, want %s", i, test.name, marshalled,
|
||||
test.marshalled)
|
||||
continue
|
||||
}
|
||||
|
||||
// Ensure the command is created without error via the generic
|
||||
// new command creation function.
|
||||
cmd, err := test.newCmd()
|
||||
if err != nil {
|
||||
t.Errorf("Test #%d (%s) unexpected NewCmd error: %v ",
|
||||
i, test.name, err)
|
||||
}
|
||||
|
||||
// Marshal the command as created by the generic new command
|
||||
// creation function.
|
||||
marshalled, err = btcjson.MarshalCmd(testID, cmd)
|
||||
if err != nil {
|
||||
t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(marshalled, []byte(test.marshalled)) {
|
||||
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
|
||||
"got %s, want %s", i, test.name, marshalled,
|
||||
test.marshalled)
|
||||
continue
|
||||
}
|
||||
|
||||
var request btcjson.Request
|
||||
if err := json.Unmarshal(marshalled, &request); err != nil {
|
||||
t.Errorf("Test #%d (%s) unexpected error while "+
|
||||
"unmarshalling JSON-RPC request: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
cmd, err = btcjson.UnmarshalCmd(&request)
|
||||
if err != nil {
|
||||
t.Errorf("UnmarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(cmd, test.unmarshalled) {
|
||||
t.Errorf("Test #%d (%s) unexpected unmarshalled command "+
|
||||
"- got %s, want %s", i, test.name,
|
||||
fmt.Sprintf("(%T) %+[1]v", cmd),
|
||||
fmt.Sprintf("(%T) %+[1]v\n", test.unmarshalled))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
// Copyright (c) 2014 The btcsuite developers
|
||||
// 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 websocket notifications that are
|
||||
// supported by a wallet server.
|
||||
|
||||
package btcjson
|
||||
|
||||
const (
|
||||
// AccountBalanceNtfnMethod is the method used for account balance
|
||||
// notifications.
|
||||
AccountBalanceNtfnMethod = "accountBalance"
|
||||
|
||||
// BtcdConnectedNtfnMethod is the method used for notifications when
|
||||
// a wallet server is connected to a dag server.
|
||||
BtcdConnectedNtfnMethod = "btcdConnected"
|
||||
|
||||
// WalletLockStateNtfnMethod is the method used to notify the lock state
|
||||
// of a wallet has changed.
|
||||
WalletLockStateNtfnMethod = "walletLockState"
|
||||
|
||||
// NewTxNtfnMethod is the method used to notify that a wallet server has
|
||||
// added a new transaction to the transaction store.
|
||||
NewTxNtfnMethod = "newTx"
|
||||
)
|
||||
|
||||
// AccountBalanceNtfn defines the accountBalance JSON-RPC notification.
|
||||
type AccountBalanceNtfn struct {
|
||||
Account string
|
||||
Balance float64 // In BTC
|
||||
Confirmed bool // Whether Balance is confirmed or unconfirmed.
|
||||
}
|
||||
|
||||
// NewAccountBalanceNtfn returns a new instance which can be used to issue an
|
||||
// accountBalance JSON-RPC notification.
|
||||
func NewAccountBalanceNtfn(account string, balance float64, confirmed bool) *AccountBalanceNtfn {
|
||||
return &AccountBalanceNtfn{
|
||||
Account: account,
|
||||
Balance: balance,
|
||||
Confirmed: confirmed,
|
||||
}
|
||||
}
|
||||
|
||||
// BtcdConnectedNtfn defines the btcdConnected JSON-RPC notification.
|
||||
type BtcdConnectedNtfn struct {
|
||||
Connected bool
|
||||
}
|
||||
|
||||
// NewBtcdConnectedNtfn returns a new instance which can be used to issue a
|
||||
// btcdConnected JSON-RPC notification.
|
||||
func NewBtcdConnectedNtfn(connected bool) *BtcdConnectedNtfn {
|
||||
return &BtcdConnectedNtfn{
|
||||
Connected: connected,
|
||||
}
|
||||
}
|
||||
|
||||
// WalletLockStateNtfn defines the walletLockState JSON-RPC notification.
|
||||
type WalletLockStateNtfn struct {
|
||||
Locked bool
|
||||
}
|
||||
|
||||
// NewWalletLockStateNtfn returns a new instance which can be used to issue a
|
||||
// walletLockState JSON-RPC notification.
|
||||
func NewWalletLockStateNtfn(locked bool) *WalletLockStateNtfn {
|
||||
return &WalletLockStateNtfn{
|
||||
Locked: locked,
|
||||
}
|
||||
}
|
||||
|
||||
// NewTxNtfn defines the newTx JSON-RPC notification.
|
||||
type NewTxNtfn struct {
|
||||
Account string
|
||||
Details ListTransactionsResult
|
||||
}
|
||||
|
||||
// NewNewTxNtfn returns a new instance which can be used to issue a newTx
|
||||
// JSON-RPC notification.
|
||||
func NewNewTxNtfn(account string, details ListTransactionsResult) *NewTxNtfn {
|
||||
return &NewTxNtfn{
|
||||
Account: account,
|
||||
Details: details,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
// The commands in this file are only usable with a wallet server via
|
||||
// websockets and are notifications.
|
||||
flags := UFWalletOnly | UFWebsocketOnly | UFNotification
|
||||
|
||||
MustRegisterCmd(AccountBalanceNtfnMethod, (*AccountBalanceNtfn)(nil), flags)
|
||||
MustRegisterCmd(BtcdConnectedNtfnMethod, (*BtcdConnectedNtfn)(nil), flags)
|
||||
MustRegisterCmd(WalletLockStateNtfnMethod, (*WalletLockStateNtfn)(nil), flags)
|
||||
MustRegisterCmd(NewTxNtfnMethod, (*NewTxNtfn)(nil), flags)
|
||||
}
|
@ -1,187 +0,0 @@
|
||||
// Copyright (c) 2014 The btcsuite developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package btcjson_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/daglabs/btcd/btcjson"
|
||||
)
|
||||
|
||||
// TestWalletSvrWsNtfns tests all of the dag server websocket-specific
|
||||
// notifications marshal and unmarshal into valid results include handling of
|
||||
// optional fields being omitted in the marshalled command, while optional
|
||||
// fields with defaults have the default assigned on unmarshalled commands.
|
||||
func TestWalletSvrWsNtfns(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
newNtfn func() (interface{}, error)
|
||||
staticNtfn func() interface{}
|
||||
marshalled string
|
||||
unmarshalled interface{}
|
||||
}{
|
||||
{
|
||||
name: "accountBalance",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("accountBalance", "acct", 1.25, true)
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
return btcjson.NewAccountBalanceNtfn("acct", 1.25, true)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"accountBalance","params":["acct",1.25,true],"id":null}`,
|
||||
unmarshalled: &btcjson.AccountBalanceNtfn{
|
||||
Account: "acct",
|
||||
Balance: 1.25,
|
||||
Confirmed: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "btcdConnected",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("btcdConnected", true)
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
return btcjson.NewBtcdConnectedNtfn(true)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"btcdConnected","params":[true],"id":null}`,
|
||||
unmarshalled: &btcjson.BtcdConnectedNtfn{
|
||||
Connected: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "walletLockState",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("walletLockState", true)
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
return btcjson.NewWalletLockStateNtfn(true)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"walletLockState","params":[true],"id":null}`,
|
||||
unmarshalled: &btcjson.WalletLockStateNtfn{
|
||||
Locked: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "newTx",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("newTx", "acct", `{"account":"acct","address":"1Address","category":"send","amount":1.5,"bip125Replaceable":"unknown","fee":0.0001,"confirmations":1,"trusted":true,"txId":"456","walletConflicts":[],"time":12345678,"timeReceived":12345876,"vout":789,"otherAccount":"otheracct"}`)
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
result := btcjson.ListTransactionsResult{
|
||||
Abandoned: false,
|
||||
Account: "acct",
|
||||
Address: "1Address",
|
||||
BIP125Replaceable: "unknown",
|
||||
Category: "send",
|
||||
Amount: 1.5,
|
||||
Fee: btcjson.Float64(0.0001),
|
||||
Confirmations: 1,
|
||||
TxID: "456",
|
||||
WalletConflicts: []string{},
|
||||
Time: 12345678,
|
||||
TimeReceived: 12345876,
|
||||
Trusted: true,
|
||||
Vout: 789,
|
||||
OtherAccount: "otheracct",
|
||||
}
|
||||
return btcjson.NewNewTxNtfn("acct", result)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"newTx","params":["acct",{"abandoned":false,"account":"acct","address":"1Address","amount":1.5,"bip125Replaceable":"unknown","category":"send","confirmations":1,"fee":0.0001,"time":12345678,"timeReceived":12345876,"trusted":true,"txId":"456","vout":789,"walletConflicts":[],"otherAccount":"otheracct"}],"id":null}`,
|
||||
unmarshalled: &btcjson.NewTxNtfn{
|
||||
Account: "acct",
|
||||
Details: btcjson.ListTransactionsResult{
|
||||
Abandoned: false,
|
||||
Account: "acct",
|
||||
Address: "1Address",
|
||||
BIP125Replaceable: "unknown",
|
||||
Category: "send",
|
||||
Amount: 1.5,
|
||||
Fee: btcjson.Float64(0.0001),
|
||||
Confirmations: 1,
|
||||
TxID: "456",
|
||||
WalletConflicts: []string{},
|
||||
Time: 12345678,
|
||||
TimeReceived: 12345876,
|
||||
Trusted: true,
|
||||
Vout: 789,
|
||||
OtherAccount: "otheracct",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
for i, test := range tests {
|
||||
// Marshal the notification as created by the new static
|
||||
// creation function. The ID is nil for notifications.
|
||||
marshalled, err := btcjson.MarshalCmd(nil, test.staticNtfn())
|
||||
if err != nil {
|
||||
t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(marshalled, []byte(test.marshalled)) {
|
||||
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
|
||||
"got %s, want %s", i, test.name, marshalled,
|
||||
test.marshalled)
|
||||
continue
|
||||
}
|
||||
|
||||
// Ensure the notification is created without error via the
|
||||
// generic new notification creation function.
|
||||
cmd, err := test.newNtfn()
|
||||
if err != nil {
|
||||
t.Errorf("Test #%d (%s) unexpected NewCmd error: %v ",
|
||||
i, test.name, err)
|
||||
}
|
||||
|
||||
// Marshal the notification as created by the generic new
|
||||
// notification creation function. The ID is nil for
|
||||
// notifications.
|
||||
marshalled, err = btcjson.MarshalCmd(nil, cmd)
|
||||
if err != nil {
|
||||
t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(marshalled, []byte(test.marshalled)) {
|
||||
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
|
||||
"got %s, want %s", i, test.name, marshalled,
|
||||
test.marshalled)
|
||||
continue
|
||||
}
|
||||
|
||||
var request btcjson.Request
|
||||
if err := json.Unmarshal(marshalled, &request); err != nil {
|
||||
t.Errorf("Test #%d (%s) unexpected error while "+
|
||||
"unmarshalling JSON-RPC request: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
cmd, err = btcjson.UnmarshalCmd(&request)
|
||||
if err != nil {
|
||||
t.Errorf("UnmarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(cmd, test.unmarshalled) {
|
||||
t.Errorf("Test #%d (%s) unexpected unmarshalled command "+
|
||||
"- got %s, want %s", i, test.name,
|
||||
fmt.Sprintf("(%T) %+[1]v", cmd),
|
||||
fmt.Sprintf("(%T) %+[1]v\n", test.unmarshalled))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ import (
|
||||
|
||||
"github.com/daglabs/btcd/btcjson"
|
||||
"github.com/daglabs/btcd/util"
|
||||
flags "github.com/jessevdk/go-flags"
|
||||
"github.com/jessevdk/go-flags"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -26,13 +26,11 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
btcdHomeDir = util.AppDataDir("btcd", false)
|
||||
btcctlHomeDir = util.AppDataDir("btcctl", false)
|
||||
btcwalletHomeDir = util.AppDataDir("btcwallet", false)
|
||||
defaultConfigFile = filepath.Join(btcctlHomeDir, "btcctl.conf")
|
||||
defaultRPCServer = "localhost"
|
||||
defaultRPCCertFile = filepath.Join(btcdHomeDir, "rpc.cert")
|
||||
defaultWalletCertFile = filepath.Join(btcwalletHomeDir, "rpc.cert")
|
||||
btcdHomeDir = util.AppDataDir("btcd", false)
|
||||
btcctlHomeDir = util.AppDataDir("btcctl", false)
|
||||
defaultConfigFile = filepath.Join(btcctlHomeDir, "btcctl.conf")
|
||||
defaultRPCServer = "localhost"
|
||||
defaultRPCCertFile = filepath.Join(btcdHomeDir, "rpc.cert")
|
||||
)
|
||||
|
||||
// listCommands categorizes and lists all of the usable commands along with
|
||||
@ -40,7 +38,6 @@ var (
|
||||
func listCommands() {
|
||||
const (
|
||||
categoryChain uint8 = iota
|
||||
categoryWallet
|
||||
numCategories
|
||||
)
|
||||
|
||||
@ -69,16 +66,12 @@ func listCommands() {
|
||||
|
||||
// Categorize the command based on the usage flags.
|
||||
category := categoryChain
|
||||
if flags&btcjson.UFWalletOnly != 0 {
|
||||
category = categoryWallet
|
||||
}
|
||||
categorized[category] = append(categorized[category], usage)
|
||||
}
|
||||
|
||||
// Display the command according to their categories.
|
||||
categoryTitles := make([]string, numCategories)
|
||||
categoryTitles[categoryChain] = "Chain Server Commands:"
|
||||
categoryTitles[categoryWallet] = "Wallet Server Commands (--wallet):"
|
||||
for category := uint8(0); category < numCategories; category++ {
|
||||
fmt.Println(categoryTitles[category])
|
||||
for _, usage := range categorized[category] {
|
||||
@ -107,12 +100,11 @@ type config struct {
|
||||
SimNet bool `long:"simnet" description:"Connect to the simulation test network"`
|
||||
DevNet bool `long:"devnet" description:"Connect to the development test network"`
|
||||
TLSSkipVerify bool `long:"skipverify" description:"Do not verify tls certificates (not recommended!)"`
|
||||
Wallet bool `long:"wallet" description:"Connect to wallet"`
|
||||
}
|
||||
|
||||
// normalizeAddress returns addr with the passed default port appended if
|
||||
// there is not already a port specified.
|
||||
func normalizeAddress(addr string, useTestNet3, useSimNet, useDevNet, useWallet bool) string {
|
||||
func normalizeAddress(addr string, useTestNet3, useSimNet, useDevNet bool) string {
|
||||
_, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
var defaultPort string
|
||||
@ -120,23 +112,11 @@ func normalizeAddress(addr string, useTestNet3, useSimNet, useDevNet, useWallet
|
||||
case useDevNet:
|
||||
fallthrough
|
||||
case useTestNet3:
|
||||
if useWallet {
|
||||
defaultPort = "18332"
|
||||
} else {
|
||||
defaultPort = "18334"
|
||||
}
|
||||
defaultPort = "18334"
|
||||
case useSimNet:
|
||||
if useWallet {
|
||||
defaultPort = "18554"
|
||||
} else {
|
||||
defaultPort = "18556"
|
||||
}
|
||||
defaultPort = "18556"
|
||||
default:
|
||||
if useWallet {
|
||||
defaultPort = "8332"
|
||||
} else {
|
||||
defaultPort = "8334"
|
||||
}
|
||||
defaultPort = "8334"
|
||||
}
|
||||
|
||||
return net.JoinHostPort(addr, defaultPort)
|
||||
@ -215,12 +195,7 @@ func loadConfig() (*config, []string, error) {
|
||||
|
||||
if _, err := os.Stat(preCfg.ConfigFile); os.IsNotExist(err) {
|
||||
// Use config file for RPC server to create default btcctl config
|
||||
var serverConfigPath string
|
||||
if preCfg.Wallet {
|
||||
serverConfigPath = filepath.Join(btcwalletHomeDir, "btcwallet.conf")
|
||||
} else {
|
||||
serverConfigPath = filepath.Join(btcdHomeDir, "btcd.conf")
|
||||
}
|
||||
serverConfigPath := filepath.Join(btcdHomeDir, "btcd.conf")
|
||||
|
||||
err := createDefaultConfigFile(preCfg.ConfigFile, serverConfigPath)
|
||||
if err != nil {
|
||||
@ -268,26 +243,20 @@ func loadConfig() (*config, []string, error) {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Override the RPC certificate if the --wallet flag was specified and
|
||||
// the user did not specify one.
|
||||
if cfg.Wallet && cfg.RPCCert == defaultRPCCertFile {
|
||||
cfg.RPCCert = defaultWalletCertFile
|
||||
}
|
||||
|
||||
// Handle environment variable expansion in the RPC certificate path.
|
||||
cfg.RPCCert = cleanAndExpandPath(cfg.RPCCert)
|
||||
|
||||
// Add default port to RPC server based on --testnet and --wallet flags
|
||||
// Add default port to RPC server based on --testnet and --simnet flags
|
||||
// if needed.
|
||||
cfg.RPCServer = normalizeAddress(cfg.RPCServer, cfg.TestNet3,
|
||||
cfg.SimNet, cfg.DevNet, cfg.Wallet)
|
||||
cfg.SimNet, cfg.DevNet)
|
||||
|
||||
return &cfg, remainingArgs, nil
|
||||
}
|
||||
|
||||
// createDefaultConfig creates a basic config file at the given destination path.
|
||||
// For this it tries to read the config file for the RPC server (either btcd or
|
||||
// btcwallet), and extract the RPC user and password from it.
|
||||
// For this it tries to read the config file for the RPC server and extract the
|
||||
// RPC user and password from it.
|
||||
func createDefaultConfigFile(destinationPath, serverConfigPath string) error {
|
||||
// Read the RPC server config
|
||||
serverConfigFile, err := os.Open(serverConfigPath)
|
||||
|
@ -1,37 +0,0 @@
|
||||
btcwallet Websockets Example
|
||||
============================
|
||||
|
||||
This example shows how to use the rpcclient package to connect to a btcwallet
|
||||
RPC server using TLS-secured websockets, register for notifications about
|
||||
changes to account balances, and get a list of unspent transaction outputs
|
||||
(utxos) the wallet can sign.
|
||||
|
||||
This example also sets a timer to shutdown the client after 10 seconds to
|
||||
demonstrate clean shutdown.
|
||||
|
||||
## Running the Example
|
||||
|
||||
The first step is to use `go get` to download and install the rpcclient package:
|
||||
|
||||
```bash
|
||||
$ go get github.com/daglabs/btcd/rpcclient
|
||||
```
|
||||
|
||||
Next, modify the `main.go` source to specify the correct RPC username and
|
||||
password for the RPC server:
|
||||
|
||||
```Go
|
||||
User: "yourrpcuser",
|
||||
Pass: "yourrpcpass",
|
||||
```
|
||||
|
||||
Finally, navigate to the example's directory and run it with:
|
||||
|
||||
```bash
|
||||
$ cd $GOPATH/src/github.com/daglabs/btcd/rpcclient/examples/btcwalletwebsockets
|
||||
$ go run *.go
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This example is licensed under the [copyfree](http://copyfree.org) ISC License.
|
@ -1,72 +0,0 @@
|
||||
// Copyright (c) 2014-2017 The btcsuite developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/daglabs/btcd/rpcclient"
|
||||
"github.com/daglabs/btcd/util"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Only override the handlers for notifications you care about.
|
||||
// Also note most of the handlers will only be called if you register
|
||||
// for notifications. See the documentation of the rpcclient
|
||||
// NotificationHandlers type for more details about each handler.
|
||||
ntfnHandlers := rpcclient.NotificationHandlers{
|
||||
OnAccountBalance: func(account string, balance util.Amount, confirmed bool) {
|
||||
log.Printf("New balance for account %s: %s", account,
|
||||
balance)
|
||||
},
|
||||
}
|
||||
|
||||
// Connect to local btcwallet RPC server using websockets.
|
||||
certHomeDir := util.AppDataDir("btcwallet", false)
|
||||
certs, err := ioutil.ReadFile(filepath.Join(certHomeDir, "rpc.cert"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
connCfg := &rpcclient.ConnConfig{
|
||||
Host: "localhost:18332",
|
||||
Endpoint: "ws",
|
||||
User: "yourrpcuser",
|
||||
Pass: "yourrpcpass",
|
||||
Certificates: certs,
|
||||
}
|
||||
client, err := rpcclient.New(connCfg, &ntfnHandlers)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Get the list of unspent transaction outputs (utxos) that the
|
||||
// connected wallet has at least one private key for.
|
||||
unspent, err := client.ListUnspent()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("Num unspent outputs (utxos): %d", len(unspent))
|
||||
if len(unspent) > 0 {
|
||||
log.Printf("First utxo:\n%s", spew.Sdump(unspent[0]))
|
||||
}
|
||||
|
||||
// For this example gracefully shutdown the client after 10 seconds.
|
||||
// Ordinarily when to shutdown the client is highly application
|
||||
// specific.
|
||||
log.Println("Client shutdown in 10 seconds...")
|
||||
time.AfterFunc(time.Second*10, func() {
|
||||
log.Println("Client shutting down...")
|
||||
client.Shutdown()
|
||||
log.Println("Client shutdown complete.")
|
||||
})
|
||||
|
||||
// Wait until the client either shuts down gracefully (or the user
|
||||
// terminates the process with Ctrl+C).
|
||||
client.WaitForShutdown()
|
||||
}
|
@ -7,13 +7,9 @@ package rpcclient
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/daglabs/btcd/btcjson"
|
||||
"github.com/daglabs/btcd/util"
|
||||
"github.com/daglabs/btcd/util/daghash"
|
||||
"github.com/daglabs/btcd/wire"
|
||||
)
|
||||
@ -66,86 +62,6 @@ func (c *Client) DebugLevel(levelSpec string) (string, error) {
|
||||
return c.DebugLevelAsync(levelSpec).Receive()
|
||||
}
|
||||
|
||||
// FutureCreateEncryptedWalletResult is a future promise to deliver the error
|
||||
// result of a CreateEncryptedWalletAsync RPC invocation.
|
||||
type FutureCreateEncryptedWalletResult chan *response
|
||||
|
||||
// Receive waits for and returns the error response promised by the future.
|
||||
func (r FutureCreateEncryptedWalletResult) Receive() error {
|
||||
_, err := receiveFuture(r)
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateEncryptedWalletAsync returns an instance of a type that can be used to
|
||||
// get the result of the RPC at some future time by invoking the Receive
|
||||
// function on the returned instance.
|
||||
//
|
||||
// See CreateEncryptedWallet for the blocking version and more details.
|
||||
//
|
||||
// NOTE: This is a btcwallet extension.
|
||||
func (c *Client) CreateEncryptedWalletAsync(passphrase string) FutureCreateEncryptedWalletResult {
|
||||
cmd := btcjson.NewCreateEncryptedWalletCmd(passphrase)
|
||||
return c.sendCmd(cmd)
|
||||
}
|
||||
|
||||
// CreateEncryptedWallet requests the creation of an encrypted wallet. Wallets
|
||||
// managed by btcwallet are only written to disk with encrypted private keys,
|
||||
// and generating wallets on the fly is impossible as it requires user input for
|
||||
// the encryption passphrase. This RPC specifies the passphrase and instructs
|
||||
// the wallet creation. This may error if a wallet is already opened, or the
|
||||
// new wallet cannot be written to disk.
|
||||
//
|
||||
// NOTE: This is a btcwallet extension.
|
||||
func (c *Client) CreateEncryptedWallet(passphrase string) error {
|
||||
return c.CreateEncryptedWalletAsync(passphrase).Receive()
|
||||
}
|
||||
|
||||
// FutureListAddressTransactionsResult is a future promise to deliver the result
|
||||
// of a ListAddressTransactionsAsync RPC invocation (or an applicable error).
|
||||
type FutureListAddressTransactionsResult chan *response
|
||||
|
||||
// Receive waits for the response promised by the future and returns information
|
||||
// about all transactions associated with the provided addresses.
|
||||
func (r FutureListAddressTransactionsResult) Receive() ([]btcjson.ListTransactionsResult, error) {
|
||||
res, err := receiveFuture(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Unmarshal the result as an array of listtransactions objects.
|
||||
var transactions []btcjson.ListTransactionsResult
|
||||
err = json.Unmarshal(res, &transactions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return transactions, nil
|
||||
}
|
||||
|
||||
// ListAddressTransactionsAsync returns an instance of a type that can be used
|
||||
// to get the result of the RPC at some future time by invoking the Receive
|
||||
// function on the returned instance.
|
||||
//
|
||||
// See ListAddressTransactions for the blocking version and more details.
|
||||
//
|
||||
// NOTE: This is a btcd extension.
|
||||
func (c *Client) ListAddressTransactionsAsync(addresses []util.Address, account string) FutureListAddressTransactionsResult {
|
||||
// Convert addresses to strings.
|
||||
addrs := make([]string, 0, len(addresses))
|
||||
for _, addr := range addresses {
|
||||
addrs = append(addrs, addr.EncodeAddress())
|
||||
}
|
||||
cmd := btcjson.NewListAddressTransactionsCmd(addrs, &account)
|
||||
return c.sendCmd(cmd)
|
||||
}
|
||||
|
||||
// ListAddressTransactions returns information about all transactions associated
|
||||
// with the provided addresses.
|
||||
//
|
||||
// NOTE: This is a btcwallet extension.
|
||||
func (c *Client) ListAddressTransactions(addresses []util.Address, account string) ([]btcjson.ListTransactionsResult, error) {
|
||||
return c.ListAddressTransactionsAsync(addresses, account).Receive()
|
||||
}
|
||||
|
||||
// FutureGetBestBlockResult is a future promise to deliver the result of a
|
||||
// GetBestBlockAsync RPC invocation (or an applicable error).
|
||||
type FutureGetBestBlockResult chan *response
|
||||
@ -323,75 +239,6 @@ func (c *Client) GetHeaders(blockLocators []*daghash.Hash, stopHash *daghash.Has
|
||||
return c.GetHeadersAsync(blockLocators, stopHash).Receive()
|
||||
}
|
||||
|
||||
// FutureExportWatchingWalletResult is a future promise to deliver the result of
|
||||
// an ExportWatchingWalletAsync RPC invocation (or an applicable error).
|
||||
type FutureExportWatchingWalletResult chan *response
|
||||
|
||||
// Receive waits for the response promised by the future and returns the
|
||||
// exported wallet.
|
||||
func (r FutureExportWatchingWalletResult) Receive() ([]byte, []byte, error) {
|
||||
res, err := receiveFuture(r)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Unmarshal result as a JSON object.
|
||||
var obj map[string]interface{}
|
||||
err = json.Unmarshal(res, &obj)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Check for the wallet and tx string fields in the object.
|
||||
base64Wallet, ok := obj["wallet"].(string)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("unexpected response type for "+
|
||||
"exportwatchingwallet 'wallet' field: %T\n",
|
||||
obj["wallet"])
|
||||
}
|
||||
base64TxStore, ok := obj["tx"].(string)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("unexpected response type for "+
|
||||
"exportwatchingwallet 'tx' field: %T\n",
|
||||
obj["tx"])
|
||||
}
|
||||
|
||||
walletBytes, err := base64.StdEncoding.DecodeString(base64Wallet)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
txStoreBytes, err := base64.StdEncoding.DecodeString(base64TxStore)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return walletBytes, txStoreBytes, nil
|
||||
|
||||
}
|
||||
|
||||
// ExportWatchingWalletAsync returns an instance of a type that can be used to
|
||||
// get the result of the RPC at some future time by invoking the Receive
|
||||
// function on the returned instance.
|
||||
//
|
||||
// See ExportWatchingWallet for the blocking version and more details.
|
||||
//
|
||||
// NOTE: This is a btcwallet extension.
|
||||
func (c *Client) ExportWatchingWalletAsync(account string) FutureExportWatchingWalletResult {
|
||||
cmd := btcjson.NewExportWatchingWalletCmd(&account, btcjson.Bool(true))
|
||||
return c.sendCmd(cmd)
|
||||
}
|
||||
|
||||
// ExportWatchingWallet returns the raw bytes for a watching-only version of
|
||||
// wallet.bin and tx.bin, respectively, for the specified account that can be
|
||||
// used by btcwallet to enable a wallet which does not have the private keys
|
||||
// necessary to spend funds.
|
||||
//
|
||||
// NOTE: This is a btcwallet extension.
|
||||
func (c *Client) ExportWatchingWallet(account string) ([]byte, []byte, error) {
|
||||
return c.ExportWatchingWalletAsync(account).Receive()
|
||||
}
|
||||
|
||||
// FutureSessionResult is a future promise to deliver the result of a
|
||||
// SessionAsync RPC invocation (or an applicable error).
|
||||
type FutureSessionResult chan *response
|
||||
|
@ -108,25 +108,6 @@ type NotificationHandlers struct {
|
||||
// made to register for the notification and the function is non-nil.
|
||||
OnTxAcceptedVerbose func(txDetails *btcjson.TxRawResult)
|
||||
|
||||
// OnBtcdConnected is invoked when a wallet connects or disconnects from
|
||||
// btcd.
|
||||
//
|
||||
// This will only be available when client is connected to a wallet
|
||||
// server such as btcwallet.
|
||||
OnBtcdConnected func(connected bool)
|
||||
|
||||
// OnAccountBalance is invoked with account balance updates.
|
||||
//
|
||||
// This will only be available when speaking to a wallet server
|
||||
// such as btcwallet.
|
||||
OnAccountBalance func(account string, balance util.Amount, confirmed bool)
|
||||
|
||||
// OnWalletLockState is invoked when a wallet is locked or unlocked.
|
||||
//
|
||||
// This will only be available when client is connected to a wallet
|
||||
// server such as btcwallet.
|
||||
OnWalletLockState func(locked bool)
|
||||
|
||||
// OnUnknownNotification is invoked when an unrecognized notification
|
||||
// is received. This typically means the notification handling code
|
||||
// for this package needs to be updated for a new notification type or
|
||||
@ -218,59 +199,6 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
|
||||
|
||||
c.ntfnHandlers.OnTxAcceptedVerbose(rawTx)
|
||||
|
||||
// OnBtcdConnected
|
||||
case btcjson.BtcdConnectedNtfnMethod:
|
||||
// Ignore the notification if the client is not interested in
|
||||
// it.
|
||||
if c.ntfnHandlers.OnBtcdConnected == nil {
|
||||
return
|
||||
}
|
||||
|
||||
connected, err := parseBtcdConnectedNtfnParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid btcd connected "+
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.ntfnHandlers.OnBtcdConnected(connected)
|
||||
|
||||
// OnAccountBalance
|
||||
case btcjson.AccountBalanceNtfnMethod:
|
||||
// Ignore the notification if the client is not interested in
|
||||
// it.
|
||||
if c.ntfnHandlers.OnAccountBalance == nil {
|
||||
return
|
||||
}
|
||||
|
||||
account, bal, conf, err := parseAccountBalanceNtfnParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid account balance "+
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.ntfnHandlers.OnAccountBalance(account, bal, conf)
|
||||
|
||||
// OnWalletLockState
|
||||
case btcjson.WalletLockStateNtfnMethod:
|
||||
// Ignore the notification if the client is not interested in
|
||||
// it.
|
||||
if c.ntfnHandlers.OnWalletLockState == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// The account name is not notified, so the return value is
|
||||
// discarded.
|
||||
_, locked, err := parseWalletLockStateNtfnParams(ntfn.Params)
|
||||
if err != nil {
|
||||
log.Warnf("Received invalid wallet lock state "+
|
||||
"notification: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.ntfnHandlers.OnWalletLockState(locked)
|
||||
|
||||
// OnUnknownNotification
|
||||
default:
|
||||
if c.ntfnHandlers.OnUnknownNotification == nil {
|
||||
@ -513,85 +441,6 @@ func parseTxAcceptedVerboseNtfnParams(params []json.RawMessage) (*btcjson.TxRawR
|
||||
return &rawTx, nil
|
||||
}
|
||||
|
||||
// parseBtcdConnectedNtfnParams parses out the connection status of btcd
|
||||
// and btcwallet from the parameters of a btcdconnected notification.
|
||||
func parseBtcdConnectedNtfnParams(params []json.RawMessage) (bool, error) {
|
||||
if len(params) != 1 {
|
||||
return false, wrongNumParams(len(params))
|
||||
}
|
||||
|
||||
// Unmarshal first parameter as a boolean.
|
||||
var connected bool
|
||||
err := json.Unmarshal(params[0], &connected)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return connected, nil
|
||||
}
|
||||
|
||||
// parseAccountBalanceNtfnParams parses out the account name, total balance,
|
||||
// and whether or not the balance is confirmed or unconfirmed from the
|
||||
// parameters of an accountbalance notification.
|
||||
func parseAccountBalanceNtfnParams(params []json.RawMessage) (account string,
|
||||
balance util.Amount, confirmed bool, err error) {
|
||||
|
||||
if len(params) != 3 {
|
||||
return "", 0, false, wrongNumParams(len(params))
|
||||
}
|
||||
|
||||
// Unmarshal first parameter as a string.
|
||||
err = json.Unmarshal(params[0], &account)
|
||||
if err != nil {
|
||||
return "", 0, false, err
|
||||
}
|
||||
|
||||
// Unmarshal second parameter as a floating point number.
|
||||
var fbal float64
|
||||
err = json.Unmarshal(params[1], &fbal)
|
||||
if err != nil {
|
||||
return "", 0, false, err
|
||||
}
|
||||
|
||||
// Unmarshal third parameter as a boolean.
|
||||
err = json.Unmarshal(params[2], &confirmed)
|
||||
if err != nil {
|
||||
return "", 0, false, err
|
||||
}
|
||||
|
||||
// Bounds check amount.
|
||||
bal, err := util.NewAmount(fbal)
|
||||
if err != nil {
|
||||
return "", 0, false, err
|
||||
}
|
||||
|
||||
return account, bal, confirmed, nil
|
||||
}
|
||||
|
||||
// parseWalletLockStateNtfnParams parses out the account name and locked
|
||||
// state of an account from the parameters of a walletlockstate notification.
|
||||
func parseWalletLockStateNtfnParams(params []json.RawMessage) (account string,
|
||||
locked bool, err error) {
|
||||
|
||||
if len(params) != 2 {
|
||||
return "", false, wrongNumParams(len(params))
|
||||
}
|
||||
|
||||
// Unmarshal first parameter as a string.
|
||||
err = json.Unmarshal(params[0], &account)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
|
||||
// Unmarshal second parameter as a boolean.
|
||||
err = json.Unmarshal(params[1], &locked)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
|
||||
return account, locked, nil
|
||||
}
|
||||
|
||||
// FutureNotifyBlocksResult is a future promise to deliver the result of a
|
||||
// NotifyBlocksAsync RPC invocation (or an applicable error).
|
||||
type FutureNotifyBlocksResult chan *response
|
||||
|
@ -15,49 +15,6 @@ import (
|
||||
"github.com/daglabs/btcd/wire"
|
||||
)
|
||||
|
||||
// SigHashType enumerates the available signature hashing types that the
|
||||
// SignRawTransaction function accepts.
|
||||
type SigHashType string
|
||||
|
||||
// Constants used to indicate the signature hash type for SignRawTransaction.
|
||||
const (
|
||||
// SigHashAll indicates ALL of the outputs should be signed.
|
||||
SigHashAll SigHashType = "ALL"
|
||||
|
||||
// SigHashNone indicates NONE of the outputs should be signed. This
|
||||
// can be thought of as specifying the signer does not care where the
|
||||
// bitcoins go.
|
||||
SigHashNone SigHashType = "NONE"
|
||||
|
||||
// SigHashSingle indicates that a SINGLE output should be signed. This
|
||||
// can be thought of specifying the signer only cares about where ONE of
|
||||
// the outputs goes, but not any of the others.
|
||||
SigHashSingle SigHashType = "SINGLE"
|
||||
|
||||
// SigHashAllAnyoneCanPay indicates that signer does not care where the
|
||||
// other inputs to the transaction come from, so it allows other people
|
||||
// to add inputs. In addition, it uses the SigHashAll signing method
|
||||
// for outputs.
|
||||
SigHashAllAnyoneCanPay SigHashType = "ALL|ANYONECANPAY"
|
||||
|
||||
// SigHashNoneAnyoneCanPay indicates that signer does not care where the
|
||||
// other inputs to the transaction come from, so it allows other people
|
||||
// to add inputs. In addition, it uses the SigHashNone signing method
|
||||
// for outputs.
|
||||
SigHashNoneAnyoneCanPay SigHashType = "NONE|ANYONECANPAY"
|
||||
|
||||
// SigHashSingleAnyoneCanPay indicates that signer does not care where
|
||||
// the other inputs to the transaction come from, so it allows other
|
||||
// people to add inputs. In addition, it uses the SigHashSingle signing
|
||||
// method for outputs.
|
||||
SigHashSingleAnyoneCanPay SigHashType = "SINGLE|ANYONECANPAY"
|
||||
)
|
||||
|
||||
// String returns the SighHashType in human-readable form.
|
||||
func (s SigHashType) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// FutureGetRawTransactionResult is a future promise to deliver the result of a
|
||||
// GetRawTransactionAsync RPC invocation (or an applicable error).
|
||||
type FutureGetRawTransactionResult chan *response
|
||||
@ -306,205 +263,6 @@ func (c *Client) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (*daghas
|
||||
return c.SendRawTransactionAsync(tx, allowHighFees).Receive()
|
||||
}
|
||||
|
||||
// FutureSignRawTransactionResult is a future promise to deliver the result
|
||||
// of one of the SignRawTransactionAsync family of RPC invocations (or an
|
||||
// applicable error).
|
||||
type FutureSignRawTransactionResult chan *response
|
||||
|
||||
// Receive waits for the response promised by the future and returns the
|
||||
// signed transaction as well as whether or not all inputs are now signed.
|
||||
func (r FutureSignRawTransactionResult) Receive() (*wire.MsgTx, bool, error) {
|
||||
res, err := receiveFuture(r)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
// Unmarshal as a signrawtransaction result.
|
||||
var signRawTxResult btcjson.SignRawTransactionResult
|
||||
err = json.Unmarshal(res, &signRawTxResult)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
// Decode the serialized transaction hex to raw bytes.
|
||||
serializedTx, err := hex.DecodeString(signRawTxResult.Hex)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
// Deserialize the transaction and return it.
|
||||
var msgTx wire.MsgTx
|
||||
if err := msgTx.Deserialize(bytes.NewReader(serializedTx)); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
return &msgTx, signRawTxResult.Complete, nil
|
||||
}
|
||||
|
||||
// SignRawTransactionAsync returns an instance of a type that can be used to get
|
||||
// the result of the RPC at some future time by invoking the Receive function on
|
||||
// the returned instance.
|
||||
//
|
||||
// See SignRawTransaction for the blocking version and more details.
|
||||
func (c *Client) SignRawTransactionAsync(tx *wire.MsgTx) FutureSignRawTransactionResult {
|
||||
txHex := ""
|
||||
if tx != nil {
|
||||
// Serialize the transaction and convert to hex string.
|
||||
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
||||
if err := tx.Serialize(buf); err != nil {
|
||||
return newFutureError(err)
|
||||
}
|
||||
txHex = hex.EncodeToString(buf.Bytes())
|
||||
}
|
||||
|
||||
cmd := btcjson.NewSignRawTransactionCmd(txHex, nil, nil, nil)
|
||||
return c.sendCmd(cmd)
|
||||
}
|
||||
|
||||
// SignRawTransaction signs inputs for the passed transaction and returns the
|
||||
// signed transaction as well as whether or not all inputs are now signed.
|
||||
//
|
||||
// This function assumes the RPC server already knows the input transactions and
|
||||
// private keys for the passed transaction which needs to be signed and uses the
|
||||
// default signature hash type. Use one of the SignRawTransaction# variants to
|
||||
// specify that information if needed.
|
||||
func (c *Client) SignRawTransaction(tx *wire.MsgTx) (*wire.MsgTx, bool, error) {
|
||||
return c.SignRawTransactionAsync(tx).Receive()
|
||||
}
|
||||
|
||||
// SignRawTransaction2Async returns an instance of a type that can be used to
|
||||
// get the result of the RPC at some future time by invoking the Receive
|
||||
// function on the returned instance.
|
||||
//
|
||||
// See SignRawTransaction2 for the blocking version and more details.
|
||||
func (c *Client) SignRawTransaction2Async(tx *wire.MsgTx, inputs []btcjson.RawTxInput) FutureSignRawTransactionResult {
|
||||
txHex := ""
|
||||
if tx != nil {
|
||||
// Serialize the transaction and convert to hex string.
|
||||
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
||||
if err := tx.Serialize(buf); err != nil {
|
||||
return newFutureError(err)
|
||||
}
|
||||
txHex = hex.EncodeToString(buf.Bytes())
|
||||
}
|
||||
|
||||
cmd := btcjson.NewSignRawTransactionCmd(txHex, &inputs, nil, nil)
|
||||
return c.sendCmd(cmd)
|
||||
}
|
||||
|
||||
// SignRawTransaction2 signs inputs for the passed transaction given the list
|
||||
// of information about the input transactions needed to perform the signing
|
||||
// process.
|
||||
//
|
||||
// This only input transactions that need to be specified are ones the
|
||||
// RPC server does not already know. Already known input transactions will be
|
||||
// merged with the specified transactions.
|
||||
//
|
||||
// See SignRawTransaction if the RPC server already knows the input
|
||||
// transactions.
|
||||
func (c *Client) SignRawTransaction2(tx *wire.MsgTx, inputs []btcjson.RawTxInput) (*wire.MsgTx, bool, error) {
|
||||
return c.SignRawTransaction2Async(tx, inputs).Receive()
|
||||
}
|
||||
|
||||
// SignRawTransaction3Async returns an instance of a type that can be used to
|
||||
// get the result of the RPC at some future time by invoking the Receive
|
||||
// function on the returned instance.
|
||||
//
|
||||
// See SignRawTransaction3 for the blocking version and more details.
|
||||
func (c *Client) SignRawTransaction3Async(tx *wire.MsgTx,
|
||||
inputs []btcjson.RawTxInput,
|
||||
privKeysWIF []string) FutureSignRawTransactionResult {
|
||||
|
||||
txHex := ""
|
||||
if tx != nil {
|
||||
// Serialize the transaction and convert to hex string.
|
||||
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
||||
if err := tx.Serialize(buf); err != nil {
|
||||
return newFutureError(err)
|
||||
}
|
||||
txHex = hex.EncodeToString(buf.Bytes())
|
||||
}
|
||||
|
||||
cmd := btcjson.NewSignRawTransactionCmd(txHex, &inputs, &privKeysWIF,
|
||||
nil)
|
||||
return c.sendCmd(cmd)
|
||||
}
|
||||
|
||||
// SignRawTransaction3 signs inputs for the passed transaction given the list
|
||||
// of information about extra input transactions and a list of private keys
|
||||
// needed to perform the signing process. The private keys must be in wallet
|
||||
// import format (WIF).
|
||||
//
|
||||
// This only input transactions that need to be specified are ones the
|
||||
// RPC server does not already know. Already known input transactions will be
|
||||
// merged with the specified transactions. This means the list of transaction
|
||||
// inputs can be nil if the RPC server already knows them all.
|
||||
//
|
||||
// NOTE: Unlike the merging functionality of the input transactions, ONLY the
|
||||
// specified private keys will be used, so even if the server already knows some
|
||||
// of the private keys, they will NOT be used.
|
||||
//
|
||||
// See SignRawTransaction if the RPC server already knows the input
|
||||
// transactions and private keys or SignRawTransaction2 if it already knows the
|
||||
// private keys.
|
||||
func (c *Client) SignRawTransaction3(tx *wire.MsgTx,
|
||||
inputs []btcjson.RawTxInput,
|
||||
privKeysWIF []string) (*wire.MsgTx, bool, error) {
|
||||
|
||||
return c.SignRawTransaction3Async(tx, inputs, privKeysWIF).Receive()
|
||||
}
|
||||
|
||||
// SignRawTransaction4Async returns an instance of a type that can be used to
|
||||
// get the result of the RPC at some future time by invoking the Receive
|
||||
// function on the returned instance.
|
||||
//
|
||||
// See SignRawTransaction4 for the blocking version and more details.
|
||||
func (c *Client) SignRawTransaction4Async(tx *wire.MsgTx,
|
||||
inputs []btcjson.RawTxInput, privKeysWIF []string,
|
||||
hashType SigHashType) FutureSignRawTransactionResult {
|
||||
|
||||
txHex := ""
|
||||
if tx != nil {
|
||||
// Serialize the transaction and convert to hex string.
|
||||
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
||||
if err := tx.Serialize(buf); err != nil {
|
||||
return newFutureError(err)
|
||||
}
|
||||
txHex = hex.EncodeToString(buf.Bytes())
|
||||
}
|
||||
|
||||
cmd := btcjson.NewSignRawTransactionCmd(txHex, &inputs, &privKeysWIF,
|
||||
btcjson.String(string(hashType)))
|
||||
return c.sendCmd(cmd)
|
||||
}
|
||||
|
||||
// SignRawTransaction4 signs inputs for the passed transaction using the
|
||||
// the specified signature hash type given the list of information about extra
|
||||
// input transactions and a potential list of private keys needed to perform
|
||||
// the signing process. The private keys, if specified, must be in wallet
|
||||
// import format (WIF).
|
||||
//
|
||||
// The only input transactions that need to be specified are ones the RPC server
|
||||
// does not already know. This means the list of transaction inputs can be nil
|
||||
// if the RPC server already knows them all.
|
||||
//
|
||||
// NOTE: Unlike the merging functionality of the input transactions, ONLY the
|
||||
// specified private keys will be used, so even if the server already knows some
|
||||
// of the private keys, they will NOT be used. The list of private keys can be
|
||||
// nil in which case any private keys the RPC server knows will be used.
|
||||
//
|
||||
// This function should only used if a non-default signature hash type is
|
||||
// desired. Otherwise, see SignRawTransaction if the RPC server already knows
|
||||
// the input transactions and private keys, SignRawTransaction2 if it already
|
||||
// knows the private keys, or SignRawTransaction3 if it does not know both.
|
||||
func (c *Client) SignRawTransaction4(tx *wire.MsgTx,
|
||||
inputs []btcjson.RawTxInput, privKeysWIF []string,
|
||||
hashType SigHashType) (*wire.MsgTx, bool, error) {
|
||||
|
||||
return c.SignRawTransaction4Async(tx, inputs, privKeysWIF,
|
||||
hashType).Receive()
|
||||
}
|
||||
|
||||
// FutureSearchRawTransactionsResult is a future promise to deliver the result
|
||||
// of the SearchRawTransactionsAsync RPC invocation (or an applicable error).
|
||||
type FutureSearchRawTransactionsResult chan *response
|
||||
|
2240
rpcclient/wallet.go
2240
rpcclient/wallet.go
File diff suppressed because it is too large
Load Diff
@ -121,13 +121,6 @@ var (
|
||||
Code: btcjson.ErrRPCUnimplemented,
|
||||
Message: "Command unimplemented",
|
||||
}
|
||||
|
||||
// ErrRPCNoWallet is an error returned to RPC clients when the provided
|
||||
// command is recognized as a wallet command.
|
||||
ErrRPCNoWallet = &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCNoWallet,
|
||||
Message: "This implementation does not implement wallet commands",
|
||||
}
|
||||
)
|
||||
|
||||
type commandHandler func(*Server, interface{}, <-chan struct{}) (interface{}, error)
|
||||
@ -188,54 +181,6 @@ var rpcHandlersBeforeInit = map[string]commandHandler{
|
||||
"flushDbCache": handleFlushDBCache,
|
||||
}
|
||||
|
||||
// list of commands that we recognize, but for which btcd has no support because
|
||||
// it lacks support for wallet functionality. For these commands the user
|
||||
// should ask a connected instance of btcwallet.
|
||||
var rpcAskWallet = map[string]struct{}{
|
||||
"addMultisigAddress": {},
|
||||
"backupWallet": {},
|
||||
"createEncryptedWallet": {},
|
||||
"createMultisig": {},
|
||||
"dumpPrivKey": {},
|
||||
"dumpWallet": {},
|
||||
"encryptWallet": {},
|
||||
"getAccount": {},
|
||||
"getAccountAddress": {},
|
||||
"getAddressesByAccount": {},
|
||||
"getBalance": {},
|
||||
"getNewAddress": {},
|
||||
"getRawChangeAddress": {},
|
||||
"getReceivedByAccount": {},
|
||||
"getReceivedByAddress": {},
|
||||
"getTransaction": {},
|
||||
"getTxOutSetInfo": {},
|
||||
"getUnconfirmedBalance": {},
|
||||
"getWalletInfo": {},
|
||||
"importPrivKey": {},
|
||||
"importWallet": {},
|
||||
"keyPoolRefill": {},
|
||||
"listAccounts": {},
|
||||
"listAddressGroupings": {},
|
||||
"listLockUnspent": {},
|
||||
"listReceivedByAccount": {},
|
||||
"listReceivedByAddress": {},
|
||||
"listSinceBlock": {},
|
||||
"listTransactions": {},
|
||||
"listUnspent": {},
|
||||
"lockUnspent": {},
|
||||
"move": {},
|
||||
"sendFrom": {},
|
||||
"sendMany": {},
|
||||
"sendToAddress": {},
|
||||
"setAccount": {},
|
||||
"setTxFee": {},
|
||||
"signMessage": {},
|
||||
"signRawTransaction": {},
|
||||
"walletLock": {},
|
||||
"walletPassphrase": {},
|
||||
"walletPassphraseChange": {},
|
||||
}
|
||||
|
||||
// Commands that are currently unimplemented, but should ultimately be.
|
||||
var rpcUnimplemented = map[string]struct{}{
|
||||
"estimatePriority": {},
|
||||
@ -363,13 +308,6 @@ func handleUnimplemented(s *Server, cmd interface{}, closeChan <-chan struct{})
|
||||
return nil, ErrRPCUnimplemented
|
||||
}
|
||||
|
||||
// handleAskWallet is the handler for commands that are recognized as valid, but
|
||||
// are unable to answer correctly since it involves wallet state.
|
||||
// These commands will be implemented in btcwallet.
|
||||
func handleAskWallet(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
||||
return nil, ErrRPCNoWallet
|
||||
}
|
||||
|
||||
// handleAddManualNode handles addManualNode commands.
|
||||
func handleAddManualNode(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
||||
c := cmd.(*btcjson.AddManualNodeCmd)
|
||||
@ -3802,11 +3740,6 @@ func (s *Server) standardCmdResult(cmd *parsedRPCCmd, closeChan <-chan struct{})
|
||||
if ok {
|
||||
goto handled
|
||||
}
|
||||
_, ok = rpcAskWallet[cmd.method]
|
||||
if ok {
|
||||
handler = handleAskWallet
|
||||
goto handled
|
||||
}
|
||||
_, ok = rpcUnimplemented[cmd.method]
|
||||
if ok {
|
||||
handler = handleUnimplemented
|
||||
|
@ -46,8 +46,7 @@ var helpDescsEnUS = map[string]string{
|
||||
|
||||
// CreateRawTransactionCmd help.
|
||||
"createRawTransaction--synopsis": "Returns a new transaction spending the provided inputs and sending to the provided addresses.\n" +
|
||||
"The transaction inputs are not signed in the created transaction.\n" +
|
||||
"The signrawtransaction RPC command provided by wallet must be used to sign the resulting transaction.",
|
||||
"The transaction inputs are not signed in the created transaction, and as such must be signed separately.",
|
||||
"createRawTransaction-inputs": "The inputs to the transaction",
|
||||
"createRawTransaction-amounts": "JSON object with the destination addresses as keys and amounts as values",
|
||||
"createRawTransaction-amounts--key": "address",
|
||||
@ -382,25 +381,6 @@ var helpDescsEnUS = map[string]string{
|
||||
"infoDagResult-relayFee": "The minimum relay fee for non-free transactions in BTC/KB",
|
||||
"infoDagResult-errors": "Any current errors",
|
||||
|
||||
// InfoWalletResult help.
|
||||
"infoWalletResult-version": "The version of the server",
|
||||
"infoWalletResult-protocolVersion": "The latest supported protocol version",
|
||||
"infoWalletResult-walletVersion": "The version of the wallet server",
|
||||
"infoWalletResult-balance": "The total bitcoin balance of the wallet",
|
||||
"infoWalletResult-blocks": "The number of blocks processed",
|
||||
"infoWalletResult-timeOffset": "The time offset",
|
||||
"infoWalletResult-connections": "The number of connected peers",
|
||||
"infoWalletResult-proxy": "The proxy used by the server",
|
||||
"infoWalletResult-difficulty": "The current target difficulty",
|
||||
"infoWalletResult-testNet": "Whether or not server is using testnet",
|
||||
"infoWalletResult-devNet": "Whether or not server is using devnet",
|
||||
"infoWalletResult-keypoolOldest": "Seconds since 1 Jan 1970 GMT of the oldest pre-generated key in the key pool",
|
||||
"infoWalletResult-keypoolSize": "The number of new keys that are pre-generated",
|
||||
"infoWalletResult-unlockedUntil": "The timestamp in seconds since 1 Jan 1970 GMT that the wallet is unlocked for transfers, or 0 if the wallet is locked",
|
||||
"infoWalletResult-payTxFee": "The transaction fee set in BTC/KB",
|
||||
"infoWalletResult-relayFee": "The minimum relay fee for non-free transactions in BTC/KB",
|
||||
"infoWalletResult-errors": "Any current errors",
|
||||
|
||||
// GetTopHeadersCmd help.
|
||||
"getTopHeaders--synopsis": "Returns the top block headers starting with the provided start hash (not inclusive)",
|
||||
"getTopHeaders-startHash": "Block hash to stop including block headers for; if not found, all headers to the latest known block are returned.",
|
||||
|
Loading…
x
Reference in New Issue
Block a user