multi: move extension commands into associated normal command files.

This consolidates all commands and tests into their respective normalfiles. BtcdConnectedNtfn has been renamed DcrdConnectedNtfn.
This commit is contained in:
Donald Adu-Poku 2018-06-03 00:05:36 +00:00 committed by Dave Collins
parent 4f6ed9afdb
commit 4840587397
21 changed files with 2146 additions and 2759 deletions

View File

@ -1,102 +0,0 @@
// Copyright (c) 2014 The btcsuite developers
// Copyright (c) 2015-2016 The Decred 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 chain server with btcd extensions.
package dcrjson
// NodeSubCmd defines the type used in the addnode JSON-RPC command for the
// sub command field.
type NodeSubCmd string
const (
// NConnect indicates the specified host that should be connected to.
NConnect NodeSubCmd = "connect"
// NRemove indicates the specified peer that should be removed as a
// persistent peer.
NRemove NodeSubCmd = "remove"
// NDisconnect indicates the specified peer should be disonnected.
NDisconnect NodeSubCmd = "disconnect"
)
// NodeCmd defines the dropnode JSON-RPC command.
type NodeCmd struct {
SubCmd NodeSubCmd `jsonrpcusage:"\"connect|remove|disconnect\""`
Target string
ConnectSubCmd *string `jsonrpcusage:"\"perm|temp\""`
}
// NewNodeCmd returns a new instance which can be used to issue a `node`
// JSON-RPC command.
//
// The parameters which are pointers indicate they are optional. Passing nil
// for optional parameters will use the default value.
func NewNodeCmd(subCmd NodeSubCmd, target string, connectSubCmd *string) *NodeCmd {
return &NodeCmd{
SubCmd: subCmd,
Target: target,
ConnectSubCmd: connectSubCmd,
}
}
// DebugLevelCmd defines the debuglevel JSON-RPC command. This command is not a
// standard Bitcoin command. It is an extension for btcd.
type DebugLevelCmd struct {
LevelSpec string
}
// NewDebugLevelCmd returns a new DebugLevelCmd which can be used to issue a
// debuglevel JSON-RPC command. This command is not a standard Bitcoin command.
// It is an extension for btcd.
func NewDebugLevelCmd(levelSpec string) *DebugLevelCmd {
return &DebugLevelCmd{
LevelSpec: levelSpec,
}
}
// GenerateCmd defines the generate JSON-RPC command.
type GenerateCmd struct {
NumBlocks uint32
}
// NewGenerateCmd returns a new instance which can be used to issue a generate
// JSON-RPC command.
func NewGenerateCmd(numBlocks uint32) *GenerateCmd {
return &GenerateCmd{
NumBlocks: numBlocks,
}
}
// GetBestBlockCmd defines the getbestblock JSON-RPC command.
type GetBestBlockCmd struct{}
// NewGetBestBlockCmd returns a new instance which can be used to issue a
// getbestblock JSON-RPC command.
func NewGetBestBlockCmd() *GetBestBlockCmd {
return &GetBestBlockCmd{}
}
// GetCurrentNetCmd defines the getcurrentnet JSON-RPC command.
type GetCurrentNetCmd struct{}
// NewGetCurrentNetCmd returns a new instance which can be used to issue a
// getcurrentnet JSON-RPC command.
func NewGetCurrentNetCmd() *GetCurrentNetCmd {
return &GetCurrentNetCmd{}
}
func init() {
// No special flags for commands in this file.
flags := UsageFlag(0)
MustRegisterCmd("debuglevel", (*DebugLevelCmd)(nil), flags)
MustRegisterCmd("node", (*NodeCmd)(nil), flags)
MustRegisterCmd("generate", (*GenerateCmd)(nil), flags)
MustRegisterCmd("getbestblock", (*GetBestBlockCmd)(nil), flags)
MustRegisterCmd("getcurrentnet", (*GetCurrentNetCmd)(nil), flags)
}

View File

@ -1,206 +0,0 @@
// Copyright (c) 2014 The btcsuite developers
// Copyright (c) 2015-2016 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package dcrjson_test
import (
"bytes"
"encoding/json"
"fmt"
"reflect"
"testing"
"github.com/decred/dcrd/dcrjson"
)
// TestBtcdExtCmds tests all of the btcd 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 TestBtcdExtCmds(t *testing.T) {
t.Parallel()
testID := int(1)
tests := []struct {
name string
newCmd func() (interface{}, error)
staticCmd func() interface{}
marshalled string
unmarshalled interface{}
}{
{
name: "debuglevel",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("debuglevel", "trace")
},
staticCmd: func() interface{} {
return dcrjson.NewDebugLevelCmd("trace")
},
marshalled: `{"jsonrpc":"1.0","method":"debuglevel","params":["trace"],"id":1}`,
unmarshalled: &dcrjson.DebugLevelCmd{
LevelSpec: "trace",
},
},
{
name: "node",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("node", dcrjson.NRemove, "1.1.1.1")
},
staticCmd: func() interface{} {
return dcrjson.NewNodeCmd("remove", "1.1.1.1", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"node","params":["remove","1.1.1.1"],"id":1}`,
unmarshalled: &dcrjson.NodeCmd{
SubCmd: dcrjson.NRemove,
Target: "1.1.1.1",
},
},
{
name: "node",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("node", dcrjson.NDisconnect, "1.1.1.1")
},
staticCmd: func() interface{} {
return dcrjson.NewNodeCmd("disconnect", "1.1.1.1", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"node","params":["disconnect","1.1.1.1"],"id":1}`,
unmarshalled: &dcrjson.NodeCmd{
SubCmd: dcrjson.NDisconnect,
Target: "1.1.1.1",
},
},
{
name: "node",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("node", dcrjson.NConnect, "1.1.1.1", "perm")
},
staticCmd: func() interface{} {
return dcrjson.NewNodeCmd("connect", "1.1.1.1", dcrjson.String("perm"))
},
marshalled: `{"jsonrpc":"1.0","method":"node","params":["connect","1.1.1.1","perm"],"id":1}`,
unmarshalled: &dcrjson.NodeCmd{
SubCmd: dcrjson.NConnect,
Target: "1.1.1.1",
ConnectSubCmd: dcrjson.String("perm"),
},
},
{
name: "node",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("node", dcrjson.NConnect, "1.1.1.1", "temp")
},
staticCmd: func() interface{} {
return dcrjson.NewNodeCmd("connect", "1.1.1.1", dcrjson.String("temp"))
},
marshalled: `{"jsonrpc":"1.0","method":"node","params":["connect","1.1.1.1","temp"],"id":1}`,
unmarshalled: &dcrjson.NodeCmd{
SubCmd: dcrjson.NConnect,
Target: "1.1.1.1",
ConnectSubCmd: dcrjson.String("temp"),
},
},
{
name: "generate",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("generate", 1)
},
staticCmd: func() interface{} {
return dcrjson.NewGenerateCmd(1)
},
marshalled: `{"jsonrpc":"1.0","method":"generate","params":[1],"id":1}`,
unmarshalled: &dcrjson.GenerateCmd{
NumBlocks: 1,
},
},
{
name: "getbestblock",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("getbestblock")
},
staticCmd: func() interface{} {
return dcrjson.NewGetBestBlockCmd()
},
marshalled: `{"jsonrpc":"1.0","method":"getbestblock","params":[],"id":1}`,
unmarshalled: &dcrjson.GetBestBlockCmd{},
},
{
name: "getcurrentnet",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("getcurrentnet")
},
staticCmd: func() interface{} {
return dcrjson.NewGetCurrentNetCmd()
},
marshalled: `{"jsonrpc":"1.0","method":"getcurrentnet","params":[],"id":1}`,
unmarshalled: &dcrjson.GetCurrentNetCmd{},
},
}
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 := dcrjson.MarshalCmd("1.0", 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 = dcrjson.MarshalCmd("1.0", 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 dcrjson.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 = dcrjson.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
}
}
}

View File

@ -1,77 +0,0 @@
// Copyright (c) 2015 The btcsuite developers
// Copyright (c) 2015-2016 The Decred 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 dcrjson
// 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,
}
}
// 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,
}
}
// 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("importaddress", (*ImportAddressCmd)(nil), flags)
MustRegisterCmd("importpubkey", (*ImportPubKeyCmd)(nil), flags)
MustRegisterCmd("renameaccount", (*RenameAccountCmd)(nil), flags)
}

View File

@ -1,183 +0,0 @@
// Copyright (c) 2014 The btcsuite developers
// Copyright (c) 2015-2016 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package dcrjson_test
import (
"bytes"
"encoding/json"
"fmt"
"reflect"
"testing"
"github.com/decred/dcrd/dcrjson"
)
// 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 dcrjson.NewCmd("createnewaccount", "acct")
},
staticCmd: func() interface{} {
return dcrjson.NewCreateNewAccountCmd("acct")
},
marshalled: `{"jsonrpc":"1.0","method":"createnewaccount","params":["acct"],"id":1}`,
unmarshalled: &dcrjson.CreateNewAccountCmd{
Account: "acct",
},
},
{
name: "importaddress",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("importaddress", "1Address")
},
staticCmd: func() interface{} {
return dcrjson.NewImportAddressCmd("1Address", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"importaddress","params":["1Address"],"id":1}`,
unmarshalled: &dcrjson.ImportAddressCmd{
Address: "1Address",
Rescan: dcrjson.Bool(true),
},
},
{
name: "importaddress optional",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("importaddress", "1Address", false)
},
staticCmd: func() interface{} {
return dcrjson.NewImportAddressCmd("1Address", dcrjson.Bool(false))
},
marshalled: `{"jsonrpc":"1.0","method":"importaddress","params":["1Address",false],"id":1}`,
unmarshalled: &dcrjson.ImportAddressCmd{
Address: "1Address",
Rescan: dcrjson.Bool(false),
},
},
{
name: "importpubkey",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("importpubkey", "031234")
},
staticCmd: func() interface{} {
return dcrjson.NewImportPubKeyCmd("031234", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"importpubkey","params":["031234"],"id":1}`,
unmarshalled: &dcrjson.ImportPubKeyCmd{
PubKey: "031234",
Rescan: dcrjson.Bool(true),
},
},
{
name: "importpubkey optional",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("importpubkey", "031234", false)
},
staticCmd: func() interface{} {
return dcrjson.NewImportPubKeyCmd("031234", dcrjson.Bool(false))
},
marshalled: `{"jsonrpc":"1.0","method":"importpubkey","params":["031234",false],"id":1}`,
unmarshalled: &dcrjson.ImportPubKeyCmd{
PubKey: "031234",
Rescan: dcrjson.Bool(false),
},
},
{
name: "renameaccount",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("renameaccount", "oldacct", "newacct")
},
staticCmd: func() interface{} {
return dcrjson.NewRenameAccountCmd("oldacct", "newacct")
},
marshalled: `{"jsonrpc":"1.0","method":"renameaccount","params":["oldacct","newacct"],"id":1}`,
unmarshalled: &dcrjson.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 := dcrjson.MarshalCmd("1.0", 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 = dcrjson.MarshalCmd("1.0", 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 dcrjson.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 = dcrjson.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
}
}
}

View File

@ -30,6 +30,22 @@ const (
ANOneTry AddNodeSubCmd = "onetry"
)
// NodeSubCmd defines the type used in the addnode JSON-RPC command for the
// sub command field.
type NodeSubCmd string
const (
// NConnect indicates the specified host that should be connected to.
NConnect NodeSubCmd = "connect"
// NRemove indicates the specified peer that should be removed as a
// persistent peer.
NRemove NodeSubCmd = "remove"
// NDisconnect indicates the specified peer should be disonnected.
NDisconnect NodeSubCmd = "disconnect"
)
// AddNodeCmd defines the addnode JSON-RPC command.
type AddNodeCmd struct {
Addr string
@ -76,6 +92,21 @@ func NewCreateRawTransactionCmd(inputs []TransactionInput, amounts map[string]fl
}
}
// DebugLevelCmd defines the debuglevel JSON-RPC command. This command is not a
// standard Bitcoin command. It is an extension for btcd.
type DebugLevelCmd struct {
LevelSpec string
}
// NewDebugLevelCmd returns a new DebugLevelCmd which can be used to issue a
// debuglevel JSON-RPC command. This command is not a standard Bitcoin command.
// It is an extension for btcd.
func NewDebugLevelCmd(levelSpec string) *DebugLevelCmd {
return &DebugLevelCmd{
LevelSpec: levelSpec,
}
}
// DecodeRawTransactionCmd defines the decoderawtransaction JSON-RPC command.
type DecodeRawTransactionCmd struct {
HexTx string
@ -144,6 +175,122 @@ func NewEstimateSmartFeeCmd(confirmations int64, mode EstimateSmartFeeMode) *Est
}
}
// EstimateStakeDiffCmd defines the eststakedifficulty JSON-RPC command.
type EstimateStakeDiffCmd struct {
Tickets *uint32
}
// NewEstimateStakeDiffCmd defines the eststakedifficulty JSON-RPC command.
func NewEstimateStakeDiffCmd(tickets *uint32) *EstimateStakeDiffCmd {
return &EstimateStakeDiffCmd{
Tickets: tickets,
}
}
// ExistsAddressCmd defines the existsaddress JSON-RPC command.
type ExistsAddressCmd struct {
Address string
}
// NewExistsAddressCmd returns a new instance which can be used to issue a
// existsaddress JSON-RPC command.
func NewExistsAddressCmd(address string) *ExistsAddressCmd {
return &ExistsAddressCmd{
Address: address,
}
}
// ExistsAddressesCmd defines the existsaddresses JSON-RPC command.
type ExistsAddressesCmd struct {
Addresses []string
}
// NewExistsAddressesCmd returns a new instance which can be used to issue an
// existsaddresses JSON-RPC command.
func NewExistsAddressesCmd(addresses []string) *ExistsAddressesCmd {
return &ExistsAddressesCmd{
Addresses: addresses,
}
}
// ExistsMissedTicketsCmd defines the existsmissedtickets JSON-RPC command.
type ExistsMissedTicketsCmd struct {
TxHashBlob string
}
// NewExistsMissedTicketsCmd returns a new instance which can be used to issue an
// existsmissedtickets JSON-RPC command.
func NewExistsMissedTicketsCmd(txHashBlob string) *ExistsMissedTicketsCmd {
return &ExistsMissedTicketsCmd{
TxHashBlob: txHashBlob,
}
}
// ExistsExpiredTicketsCmd defines the existsexpiredtickets JSON-RPC command.
type ExistsExpiredTicketsCmd struct {
TxHashBlob string
}
// NewExistsExpiredTicketsCmd returns a new instance which can be used to issue an
// existsexpiredtickets JSON-RPC command.
func NewExistsExpiredTicketsCmd(txHashBlob string) *ExistsExpiredTicketsCmd {
return &ExistsExpiredTicketsCmd{
TxHashBlob: txHashBlob,
}
}
// ExistsLiveTicketCmd defines the existsliveticket JSON-RPC command.
type ExistsLiveTicketCmd struct {
TxHash string
}
// NewExistsLiveTicketCmd returns a new instance which can be used to issue an
// existsliveticket JSON-RPC command.
func NewExistsLiveTicketCmd(txHash string) *ExistsLiveTicketCmd {
return &ExistsLiveTicketCmd{
TxHash: txHash,
}
}
// ExistsLiveTicketsCmd defines the existslivetickets JSON-RPC command.
type ExistsLiveTicketsCmd struct {
TxHashBlob string
}
// NewExistsLiveTicketsCmd returns a new instance which can be used to issue an
// existslivetickets JSON-RPC command.
func NewExistsLiveTicketsCmd(txHashBlob string) *ExistsLiveTicketsCmd {
return &ExistsLiveTicketsCmd{
TxHashBlob: txHashBlob,
}
}
// ExistsMempoolTxsCmd defines the existsmempooltxs JSON-RPC command.
type ExistsMempoolTxsCmd struct {
TxHashBlob string
}
// NewExistsMempoolTxsCmd returns a new instance which can be used to issue an
// existslivetickets JSON-RPC command.
func NewExistsMempoolTxsCmd(txHashBlob string) *ExistsMempoolTxsCmd {
return &ExistsMempoolTxsCmd{
TxHashBlob: txHashBlob,
}
}
// GenerateCmd defines the generate JSON-RPC command.
type GenerateCmd struct {
NumBlocks uint32
}
// NewGenerateCmd returns a new instance which can be used to issue a generate
// JSON-RPC command.
func NewGenerateCmd(numBlocks uint32) *GenerateCmd {
return &GenerateCmd{
NumBlocks: numBlocks,
}
}
// GetAddedNodeInfoCmd defines the getaddednodeinfo JSON-RPC command.
type GetAddedNodeInfoCmd struct {
DNS bool
@ -162,6 +309,15 @@ func NewGetAddedNodeInfoCmd(dns bool, node *string) *GetAddedNodeInfoCmd {
}
}
// GetBestBlockCmd defines the getbestblock JSON-RPC command.
type GetBestBlockCmd struct{}
// NewGetBestBlockCmd returns a new instance which can be used to issue a
// getbestblock JSON-RPC command.
func NewGetBestBlockCmd() *GetBestBlockCmd {
return &GetBestBlockCmd{}
}
// GetBestBlockHashCmd defines the getbestblockhash JSON-RPC command.
type GetBestBlockHashCmd struct{}
@ -379,6 +535,15 @@ func NewGetChainTipsCmd() *GetChainTipsCmd {
return &GetChainTipsCmd{}
}
// GetCoinSupplyCmd defines the getcoinsupply JSON-RPC command.
type GetCoinSupplyCmd struct{}
// NewGetCoinSupplyCmd returns a new instance which can be used to issue a
// getcoinsupply JSON-RPC command.
func NewGetCoinSupplyCmd() *GetCoinSupplyCmd {
return &GetCoinSupplyCmd{}
}
// GetConnectionCountCmd defines the getconnectioncount JSON-RPC command.
type GetConnectionCountCmd struct{}
@ -388,6 +553,15 @@ func NewGetConnectionCountCmd() *GetConnectionCountCmd {
return &GetConnectionCountCmd{}
}
// GetCurrentNetCmd defines the getcurrentnet JSON-RPC command.
type GetCurrentNetCmd struct{}
// NewGetCurrentNetCmd returns a new instance which can be used to issue a
// getcurrentnet JSON-RPC command.
func NewGetCurrentNetCmd() *GetCurrentNetCmd {
return &GetCurrentNetCmd{}
}
// GetDifficultyCmd defines the getdifficulty JSON-RPC command.
type GetDifficultyCmd struct{}
@ -562,6 +736,55 @@ func NewGetRawTransactionCmd(txHash string, verbose *int) *GetRawTransactionCmd
}
}
// GetStakeDifficultyCmd is a type handling custom marshaling and
// unmarshaling of getstakedifficulty JSON RPC commands.
type GetStakeDifficultyCmd struct{}
// NewGetStakeDifficultyCmd returns a new instance which can be used to
// issue a JSON-RPC getstakedifficulty command.
func NewGetStakeDifficultyCmd() *GetStakeDifficultyCmd {
return &GetStakeDifficultyCmd{}
}
// GetStakeVersionInfoCmd returns stake version info for the current interval.
// Optionally, Count indicates how many additional intervals to return.
type GetStakeVersionInfoCmd struct {
Count *int32
}
// NewGetStakeVersionInfoCmd returns a new instance which can be used to
// issue a JSON-RPC getstakeversioninfo command.
func NewGetStakeVersionInfoCmd(count int32) *GetStakeVersionInfoCmd {
return &GetStakeVersionInfoCmd{
Count: &count,
}
}
// GetStakeVersionsCmd returns stake version for a range of blocks.
// Count indicates how many blocks are walked backwards.
type GetStakeVersionsCmd struct {
Hash string
Count int32
}
// NewGetStakeVersionsCmd returns a new instance which can be used to
// issue a JSON-RPC getstakeversions command.
func NewGetStakeVersionsCmd(hash string, count int32) *GetStakeVersionsCmd {
return &GetStakeVersionsCmd{
Hash: hash,
Count: count,
}
}
// GetTicketPoolValueCmd defines the getticketpoolvalue JSON-RPC command.
type GetTicketPoolValueCmd struct{}
// NewGetTicketPoolValueCmd returns a new instance which can be used to issue a
// getticketpoolvalue JSON-RPC command.
func NewGetTicketPoolValueCmd() *GetTicketPoolValueCmd {
return &GetTicketPoolValueCmd{}
}
// GetTxOutCmd defines the gettxout JSON-RPC command.
type GetTxOutCmd struct {
Txid string
@ -591,6 +814,20 @@ func NewGetTxOutSetInfoCmd() *GetTxOutSetInfoCmd {
return &GetTxOutSetInfoCmd{}
}
// GetVoteInfoCmd returns voting results over a range of blocks. Count
// indicates how many blocks are walked backwards.
type GetVoteInfoCmd struct {
Version uint32
}
// NewGetVoteInfoCmd returns a new instance which can be used to
// issue a JSON-RPC getvoteinfo command.
func NewGetVoteInfoCmd(version uint32) *GetVoteInfoCmd {
return &GetVoteInfoCmd{
Version: version,
}
}
// GetWorkCmd defines the getwork JSON-RPC command.
type GetWorkCmd struct {
Data *string
@ -623,6 +860,46 @@ func NewHelpCmd(command *string) *HelpCmd {
}
}
// LiveTicketsCmd is a type handling custom marshaling and
// unmarshaling of livetickets JSON RPC commands.
type LiveTicketsCmd struct{}
// NewLiveTicketsCmd returns a new instance which can be used to issue a JSON-RPC
// livetickets command.
func NewLiveTicketsCmd() *LiveTicketsCmd {
return &LiveTicketsCmd{}
}
// MissedTicketsCmd is a type handling custom marshaling and
// unmarshaling of missedtickets JSON RPC commands.
type MissedTicketsCmd struct{}
// NewMissedTicketsCmd returns a new instance which can be used to issue a JSON-RPC
// missedtickets command.
func NewMissedTicketsCmd() *MissedTicketsCmd {
return &MissedTicketsCmd{}
}
// NodeCmd defines the dropnode JSON-RPC command.
type NodeCmd struct {
SubCmd NodeSubCmd `jsonrpcusage:"\"connect|remove|disconnect\""`
Target string
ConnectSubCmd *string `jsonrpcusage:"\"perm|temp\""`
}
// NewNodeCmd returns a new instance which can be used to issue a `node`
// JSON-RPC command.
//
// The parameters which are pointers indicate they are optional. Passing nil
// for optional parameters will use the default value.
func NewNodeCmd(subCmd NodeSubCmd, target string, connectSubCmd *string) *NodeCmd {
return &NodeCmd{
SubCmd: subCmd,
Target: target,
ConnectSubCmd: connectSubCmd,
}
}
// PingCmd defines the ping JSON-RPC command.
type PingCmd struct{}
@ -632,6 +909,26 @@ func NewPingCmd() *PingCmd {
return &PingCmd{}
}
// RebroadcastMissedCmd is a type handling custom marshaling and
// unmarshaling of rebroadcastwinners JSON RPC commands.
type RebroadcastMissedCmd struct{}
// NewRebroadcastMissedCmd returns a new instance which can be used to
// issue a JSON-RPC rebroadcastmissed command.
func NewRebroadcastMissedCmd() *RebroadcastMissedCmd {
return &RebroadcastMissedCmd{}
}
// RebroadcastWinnersCmd is a type handling custom marshaling and
// unmarshaling of rebroadcastwinners JSON RPC commands.
type RebroadcastWinnersCmd struct{}
// NewRebroadcastWinnersCmd returns a new instance which can be used to
// issue a JSON-RPC rebroadcastwinners command.
func NewRebroadcastWinnersCmd() *RebroadcastWinnersCmd {
return &RebroadcastWinnersCmd{}
}
// SearchRawTransactionsCmd defines the searchrawtransactions JSON-RPC command.
type SearchRawTransactionsCmd struct {
Address string
@ -730,6 +1027,64 @@ func NewSubmitBlockCmd(hexBlock string, options *SubmitBlockOptions) *SubmitBloc
}
}
// TicketFeeInfoCmd defines the ticketsfeeinfo JSON-RPC command.
type TicketFeeInfoCmd struct {
Blocks *uint32
Windows *uint32
}
// NewTicketFeeInfoCmd returns a new instance which can be used to issue a
// JSON-RPC ticket fee info command.
func NewTicketFeeInfoCmd(blocks *uint32, windows *uint32) *TicketFeeInfoCmd {
return &TicketFeeInfoCmd{
Blocks: blocks,
Windows: windows,
}
}
// TicketsForAddressCmd defines the ticketsforbucket JSON-RPC command.
type TicketsForAddressCmd struct {
Address string
}
// NewTicketsForAddressCmd returns a new instance which can be used to issue a
// JSON-RPC tickets for bucket command.
func NewTicketsForAddressCmd(addr string) *TicketsForAddressCmd {
return &TicketsForAddressCmd{addr}
}
// TicketVWAPCmd defines the ticketvwap JSON-RPC command.
type TicketVWAPCmd struct {
Start *uint32
End *uint32
}
// NewTicketVWAPCmd returns a new instance which can be used to issue a
// JSON-RPC ticket volume weight average price command.
func NewTicketVWAPCmd(start *uint32, end *uint32) *TicketVWAPCmd {
return &TicketVWAPCmd{
Start: start,
End: end,
}
}
// TxFeeInfoCmd defines the ticketsfeeinfo JSON-RPC command.
type TxFeeInfoCmd struct {
Blocks *uint32
RangeStart *uint32
RangeEnd *uint32
}
// NewTxFeeInfoCmd returns a new instance which can be used to issue a
// JSON-RPC ticket fee info command.
func NewTxFeeInfoCmd(blocks *uint32, start *uint32, end *uint32) *TxFeeInfoCmd {
return &TxFeeInfoCmd{
Blocks: blocks,
RangeStart: start,
RangeEnd: end,
}
}
// ValidateAddressCmd defines the validateaddress JSON-RPC command.
type ValidateAddressCmd struct {
Address string
@ -778,17 +1133,35 @@ func NewVerifyMessageCmd(address, signature, message string) *VerifyMessageCmd {
}
}
// VersionCmd defines the version JSON-RPC command.
type VersionCmd struct{}
// NewVersionCmd returns a new instance which can be used to issue a JSON-RPC
// version command.
func NewVersionCmd() *VersionCmd { return new(VersionCmd) }
func init() {
// No special flags for commands in this file.
flags := UsageFlag(0)
MustRegisterCmd("addnode", (*AddNodeCmd)(nil), flags)
MustRegisterCmd("createrawtransaction", (*CreateRawTransactionCmd)(nil), flags)
MustRegisterCmd("debuglevel", (*DebugLevelCmd)(nil), flags)
MustRegisterCmd("decoderawtransaction", (*DecodeRawTransactionCmd)(nil), flags)
MustRegisterCmd("decodescript", (*DecodeScriptCmd)(nil), flags)
MustRegisterCmd("estimatefee", (*EstimateFeeCmd)(nil), flags)
MustRegisterCmd("estimatesmartfee", (*EstimateSmartFeeCmd)(nil), flags)
MustRegisterCmd("estimatestakediff", (*EstimateStakeDiffCmd)(nil), flags)
MustRegisterCmd("existsaddress", (*ExistsAddressCmd)(nil), flags)
MustRegisterCmd("existsaddresses", (*ExistsAddressesCmd)(nil), flags)
MustRegisterCmd("existsmissedtickets", (*ExistsMissedTicketsCmd)(nil), flags)
MustRegisterCmd("existsexpiredtickets", (*ExistsExpiredTicketsCmd)(nil), flags)
MustRegisterCmd("existsliveticket", (*ExistsLiveTicketCmd)(nil), flags)
MustRegisterCmd("existslivetickets", (*ExistsLiveTicketsCmd)(nil), flags)
MustRegisterCmd("existsmempooltxs", (*ExistsMempoolTxsCmd)(nil), flags)
MustRegisterCmd("generate", (*GenerateCmd)(nil), flags)
MustRegisterCmd("getaddednodeinfo", (*GetAddedNodeInfoCmd)(nil), flags)
MustRegisterCmd("getbestblock", (*GetBestBlockCmd)(nil), flags)
MustRegisterCmd("getbestblockhash", (*GetBestBlockHashCmd)(nil), flags)
MustRegisterCmd("getblock", (*GetBlockCmd)(nil), flags)
MustRegisterCmd("getblockchaininfo", (*GetBlockChainInfoCmd)(nil), flags)
@ -800,7 +1173,9 @@ func init() {
MustRegisterCmd("getcfilter", (*GetCFilterCmd)(nil), flags)
MustRegisterCmd("getcfilterheader", (*GetCFilterHeaderCmd)(nil), flags)
MustRegisterCmd("getchaintips", (*GetChainTipsCmd)(nil), flags)
MustRegisterCmd("getcoinsupply", (*GetCoinSupplyCmd)(nil), flags)
MustRegisterCmd("getconnectioncount", (*GetConnectionCountCmd)(nil), flags)
MustRegisterCmd("getcurrentnet", (*GetCurrentNetCmd)(nil), flags)
MustRegisterCmd("getdifficulty", (*GetDifficultyCmd)(nil), flags)
MustRegisterCmd("getgenerate", (*GetGenerateCmd)(nil), flags)
MustRegisterCmd("gethashespersec", (*GetHashesPerSecCmd)(nil), flags)
@ -814,17 +1189,32 @@ func init() {
MustRegisterCmd("getpeerinfo", (*GetPeerInfoCmd)(nil), flags)
MustRegisterCmd("getrawmempool", (*GetRawMempoolCmd)(nil), flags)
MustRegisterCmd("getrawtransaction", (*GetRawTransactionCmd)(nil), flags)
MustRegisterCmd("getstakedifficulty", (*GetStakeDifficultyCmd)(nil), flags)
MustRegisterCmd("getstakeversioninfo", (*GetStakeVersionInfoCmd)(nil), flags)
MustRegisterCmd("getstakeversions", (*GetStakeVersionsCmd)(nil), flags)
MustRegisterCmd("getticketpoolvalue", (*GetTicketPoolValueCmd)(nil), flags)
MustRegisterCmd("gettxout", (*GetTxOutCmd)(nil), flags)
MustRegisterCmd("gettxoutsetinfo", (*GetTxOutSetInfoCmd)(nil), flags)
MustRegisterCmd("getvoteinfo", (*GetVoteInfoCmd)(nil), flags)
MustRegisterCmd("getwork", (*GetWorkCmd)(nil), flags)
MustRegisterCmd("help", (*HelpCmd)(nil), flags)
MustRegisterCmd("livetickets", (*LiveTicketsCmd)(nil), flags)
MustRegisterCmd("missedtickets", (*MissedTicketsCmd)(nil), flags)
MustRegisterCmd("node", (*NodeCmd)(nil), flags)
MustRegisterCmd("ping", (*PingCmd)(nil), flags)
MustRegisterCmd("rebroadcastmissed", (*RebroadcastMissedCmd)(nil), flags)
MustRegisterCmd("rebroadcastwinners", (*RebroadcastWinnersCmd)(nil), flags)
MustRegisterCmd("searchrawtransactions", (*SearchRawTransactionsCmd)(nil), flags)
MustRegisterCmd("sendrawtransaction", (*SendRawTransactionCmd)(nil), flags)
MustRegisterCmd("setgenerate", (*SetGenerateCmd)(nil), flags)
MustRegisterCmd("stop", (*StopCmd)(nil), flags)
MustRegisterCmd("submitblock", (*SubmitBlockCmd)(nil), flags)
MustRegisterCmd("ticketfeeinfo", (*TicketFeeInfoCmd)(nil), flags)
MustRegisterCmd("ticketsforaddress", (*TicketsForAddressCmd)(nil), flags)
MustRegisterCmd("ticketvwap", (*TicketVWAPCmd)(nil), flags)
MustRegisterCmd("txfeeinfo", (*TxFeeInfoCmd)(nil), flags)
MustRegisterCmd("validateaddress", (*ValidateAddressCmd)(nil), flags)
MustRegisterCmd("verifychain", (*VerifyChainCmd)(nil), flags)
MustRegisterCmd("verifymessage", (*VerifyMessageCmd)(nil), flags)
MustRegisterCmd("version", (*VersionCmd)(nil), flags)
}

View File

@ -81,6 +81,19 @@ func TestChainSvrCmds(t *testing.T) {
Expiry: dcrjson.Int64(12312333333),
},
},
{
name: "debuglevel",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("debuglevel", "trace")
},
staticCmd: func() interface{} {
return dcrjson.NewDebugLevelCmd("trace")
},
marshalled: `{"jsonrpc":"1.0","method":"debuglevel","params":["trace"],"id":1}`,
unmarshalled: &dcrjson.DebugLevelCmd{
LevelSpec: "trace",
},
},
{
name: "decoderawtransaction",
newCmd: func() (interface{}, error) {
@ -114,6 +127,19 @@ func TestChainSvrCmds(t *testing.T) {
marshalled: `{"jsonrpc":"1.0","method":"estimatesmartfee","params":[6,"conservative"],"id":1}`,
unmarshalled: &dcrjson.EstimateSmartFeeCmd{Confirmations: 6, Mode: dcrjson.EstimateSmartFeeConservative},
},
{
name: "generate",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("generate", 1)
},
staticCmd: func() interface{} {
return dcrjson.NewGenerateCmd(1)
},
marshalled: `{"jsonrpc":"1.0","method":"generate","params":[1],"id":1}`,
unmarshalled: &dcrjson.GenerateCmd{
NumBlocks: 1,
},
},
{
name: "getaddednodeinfo",
newCmd: func() (interface{}, error) {
@ -139,6 +165,17 @@ func TestChainSvrCmds(t *testing.T) {
Node: dcrjson.String("127.0.0.1"),
},
},
{
name: "getbestblock",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("getbestblock")
},
staticCmd: func() interface{} {
return dcrjson.NewGetBestBlockCmd()
},
marshalled: `{"jsonrpc":"1.0","method":"getbestblock","params":[],"id":1}`,
unmarshalled: &dcrjson.GetBestBlockCmd{},
},
{
name: "getbestblockhash",
newCmd: func() (interface{}, error) {
@ -393,6 +430,17 @@ func TestChainSvrCmds(t *testing.T) {
marshalled: `{"jsonrpc":"1.0","method":"getconnectioncount","params":[],"id":1}`,
unmarshalled: &dcrjson.GetConnectionCountCmd{},
},
{
name: "getcurrentnet",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("getcurrentnet")
},
staticCmd: func() interface{} {
return dcrjson.NewGetCurrentNetCmd()
},
marshalled: `{"jsonrpc":"1.0","method":"getcurrentnet","params":[],"id":1}`,
unmarshalled: &dcrjson.GetCurrentNetCmd{},
},
{
name: "getdifficulty",
newCmd: func() (interface{}, error) {
@ -602,6 +650,20 @@ func TestChainSvrCmds(t *testing.T) {
Verbose: dcrjson.Int(1),
},
},
{
name: "getstakeversions",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("getstakeversions", "deadbeef", 1)
},
staticCmd: func() interface{} {
return dcrjson.NewGetStakeVersionsCmd("deadbeef", 1)
},
marshalled: `{"jsonrpc":"1.0","method":"getstakeversions","params":["deadbeef",1],"id":1}`,
unmarshalled: &dcrjson.GetStakeVersionsCmd{
Hash: "deadbeef",
Count: 1,
},
},
{
name: "gettxout",
newCmd: func() (interface{}, error) {
@ -643,6 +705,19 @@ func TestChainSvrCmds(t *testing.T) {
marshalled: `{"jsonrpc":"1.0","method":"gettxoutsetinfo","params":[],"id":1}`,
unmarshalled: &dcrjson.GetTxOutSetInfoCmd{},
},
{
name: "getvoteinfo",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("getvoteinfo", 1)
},
staticCmd: func() interface{} {
return dcrjson.NewGetVoteInfoCmd(1)
},
marshalled: `{"jsonrpc":"1.0","method":"getvoteinfo","params":[1],"id":1}`,
unmarshalled: &dcrjson.GetVoteInfoCmd{
Version: 1,
},
},
{
name: "getwork",
newCmd: func() (interface{}, error) {
@ -695,6 +770,49 @@ func TestChainSvrCmds(t *testing.T) {
Command: dcrjson.String("getblock"),
},
},
{
name: "node option remove",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("node", dcrjson.NRemove, "1.1.1.1")
},
staticCmd: func() interface{} {
return dcrjson.NewNodeCmd("remove", "1.1.1.1", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"node","params":["remove","1.1.1.1"],"id":1}`,
unmarshalled: &dcrjson.NodeCmd{
SubCmd: dcrjson.NRemove,
Target: "1.1.1.1",
},
},
{
name: "node option disconnect",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("node", dcrjson.NDisconnect, "1.1.1.1")
},
staticCmd: func() interface{} {
return dcrjson.NewNodeCmd("disconnect", "1.1.1.1", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"node","params":["disconnect","1.1.1.1"],"id":1}`,
unmarshalled: &dcrjson.NodeCmd{
SubCmd: dcrjson.NDisconnect,
Target: "1.1.1.1",
},
},
{
name: "node option connect",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("node", dcrjson.NConnect, "1.1.1.1", "perm")
},
staticCmd: func() interface{} {
return dcrjson.NewNodeCmd("connect", "1.1.1.1", dcrjson.String("perm"))
},
marshalled: `{"jsonrpc":"1.0","method":"node","params":["connect","1.1.1.1","perm"],"id":1}`,
unmarshalled: &dcrjson.NodeCmd{
SubCmd: dcrjson.NConnect,
Target: "1.1.1.1",
ConnectSubCmd: dcrjson.String("perm"),
},
},
{
name: "ping",
newCmd: func() (interface{}, error) {

View File

@ -7,31 +7,54 @@ package dcrjson
import "encoding/json"
// GetBlockHeaderVerboseResult models the data from the getblockheader command when
// the verbose flag is set. When the verbose flag is not set, getblockheader
// returns a hex-encoded string.
type GetBlockHeaderVerboseResult struct {
Hash string `json:"hash"`
Confirmations int64 `json:"confirmations"`
Version int32 `json:"version"`
PreviousHash string `json:"previousblockhash,omitempty"`
MerkleRoot string `json:"merkleroot"`
StakeRoot string `json:"stakeroot"`
VoteBits uint16 `json:"votebits"`
FinalState string `json:"finalstate"`
Voters uint16 `json:"voters"`
FreshStake uint8 `json:"freshstake"`
Revocations uint8 `json:"revocations"`
PoolSize uint32 `json:"poolsize"`
Bits string `json:"bits"`
SBits float64 `json:"sbits"`
Height uint32 `json:"height"`
Size uint32 `json:"size"`
Time int64 `json:"time"`
Nonce uint32 `json:"nonce"`
StakeVersion uint32 `json:"stakeversion"`
Difficulty float64 `json:"difficulty"`
NextHash string `json:"nextblockhash,omitempty"`
// TxRawDecodeResult models the data from the decoderawtransaction command.
type TxRawDecodeResult struct {
Txid string `json:"txid"`
Version int32 `json:"version"`
Locktime uint32 `json:"locktime"`
Expiry uint32 `json:"expiry"`
Vin []Vin `json:"vin"`
Vout []Vout `json:"vout"`
}
// DecodeScriptResult models the data returned from the decodescript command.
type DecodeScriptResult struct {
Asm string `json:"asm"`
ReqSigs int32 `json:"reqSigs,omitempty"`
Type string `json:"type"`
Addresses []string `json:"addresses,omitempty"`
P2sh string `json:"p2sh,omitempty"`
}
// EstimateSmartFeeResult models the data returned from the estimatesmartfee
// command.
type EstimateSmartFeeResult struct {
FeeRate float64 `json:"feerate"`
Errors []string `json:"errors"`
Blocks int64 `json:"blocks"`
}
// EstimateStakeDiffResult models the data returned from the estimatestakediff
// command.
type EstimateStakeDiffResult struct {
Min float64 `json:"min"`
Max float64 `json:"max"`
Expected float64 `json:"expected"`
User *float64 `json:"user,omitempty"`
}
// GetAddedNodeInfoResultAddr models the data of the addresses portion of the
// getaddednodeinfo command.
type GetAddedNodeInfoResultAddr struct {
Address string `json:"address"`
Connected string `json:"connected"`
}
// GetAddedNodeInfoResult models the data from the getaddednodeinfo command.
type GetAddedNodeInfoResult struct {
AddedNode string `json:"addednode"`
Connected *bool `json:"connected,omitempty"`
Addresses *[]GetAddedNodeInfoResultAddr `json:"addresses,omitempty"`
}
// GetBlockVerboseResult models the data from the getblock command when the
@ -66,44 +89,6 @@ type GetBlockVerboseResult struct {
NextHash string `json:"nextblockhash,omitempty"`
}
// CreateMultiSigResult models the data returned from the createmultisig
// command.
type CreateMultiSigResult struct {
Address string `json:"address"`
RedeemScript string `json:"redeemScript"`
}
// DecodeScriptResult models the data returned from the decodescript command.
type DecodeScriptResult struct {
Asm string `json:"asm"`
ReqSigs int32 `json:"reqSigs,omitempty"`
Type string `json:"type"`
Addresses []string `json:"addresses,omitempty"`
P2sh string `json:"p2sh,omitempty"`
}
// EstimateSmartFeeResult models the data returned from the estimatesmartfee
// command.
type EstimateSmartFeeResult struct {
FeeRate float64 `json:"feerate"`
Errors []string `json:"errors"`
Blocks int64 `json:"blocks"`
}
// GetAddedNodeInfoResultAddr models the data of the addresses portion of the
// getaddednodeinfo command.
type GetAddedNodeInfoResultAddr struct {
Address string `json:"address"`
Connected string `json:"connected"`
}
// GetAddedNodeInfoResult models the data from the getaddednodeinfo command.
type GetAddedNodeInfoResult struct {
AddedNode string `json:"addednode"`
Connected *bool `json:"connected,omitempty"`
Addresses *[]GetAddedNodeInfoResultAddr `json:"addresses,omitempty"`
}
// GetBlockChainInfoResult models the data returned from the getblockchaininfo
// command.
type GetBlockChainInfoResult struct {
@ -116,6 +101,33 @@ type GetBlockChainInfoResult struct {
ChainWork string `json:"chainwork"`
}
// GetBlockHeaderVerboseResult models the data from the getblockheader command when
// the verbose flag is set. When the verbose flag is not set, getblockheader
// returns a hex-encoded string.
type GetBlockHeaderVerboseResult struct {
Hash string `json:"hash"`
Confirmations int64 `json:"confirmations"`
Version int32 `json:"version"`
PreviousHash string `json:"previousblockhash,omitempty"`
MerkleRoot string `json:"merkleroot"`
StakeRoot string `json:"stakeroot"`
VoteBits uint16 `json:"votebits"`
FinalState string `json:"finalstate"`
Voters uint16 `json:"voters"`
FreshStake uint8 `json:"freshstake"`
Revocations uint8 `json:"revocations"`
PoolSize uint32 `json:"poolsize"`
Bits string `json:"bits"`
SBits float64 `json:"sbits"`
Height uint32 `json:"height"`
Size uint32 `json:"size"`
Time int64 `json:"time"`
Nonce uint32 `json:"nonce"`
StakeVersion uint32 `json:"stakeversion"`
Difficulty float64 `json:"difficulty"`
NextHash string `json:"nextblockhash,omitempty"`
}
// GetBlockSubsidyResult models the data returned from the getblocksubsidy
// command.
type GetBlockSubsidyResult struct {
@ -188,6 +200,26 @@ type GetChainTipsResult struct {
Status string `json:"status"`
}
// GetHeadersResult models the data returned by the chain server getheaders
// command.
type GetHeadersResult struct {
Headers []string `json:"headers"`
}
// InfoChainResult models the data returned by the chain server getinfo command.
type InfoChainResult struct {
Version int32 `json:"version"`
ProtocolVersion int32 `json:"protocolversion"`
Blocks int64 `json:"blocks"`
TimeOffset int64 `json:"timeoffset"`
Connections int32 `json:"connections"`
Proxy string `json:"proxy"`
Difficulty float64 `json:"difficulty"`
TestNet bool `json:"testnet"`
RelayFee float64 `json:"relayfee"`
Errors string `json:"errors"`
}
// GetMempoolInfoResult models the data returned from the getmempoolinfo
// command.
type GetMempoolInfoResult struct {
@ -195,6 +227,39 @@ type GetMempoolInfoResult struct {
Bytes int64 `json:"bytes"`
}
// GetMiningInfoResult models the data from the getmininginfo command.
// Contains Decred additions.
type GetMiningInfoResult struct {
Blocks int64 `json:"blocks"`
CurrentBlockSize uint64 `json:"currentblocksize"`
CurrentBlockTx uint64 `json:"currentblocktx"`
Difficulty float64 `json:"difficulty"`
StakeDifficulty int64 `json:"stakedifficulty"`
Errors string `json:"errors"`
Generate bool `json:"generate"`
GenProcLimit int32 `json:"genproclimit"`
HashesPerSec int64 `json:"hashespersec"`
NetworkHashPS int64 `json:"networkhashps"`
PooledTx uint64 `json:"pooledtx"`
TestNet bool `json:"testnet"`
}
// LocalAddressesResult models the localaddresses data from the getnetworkinfo
// command.
type LocalAddressesResult struct {
Address string `json:"address"`
Port uint16 `json:"port"`
Score int32 `json:"score"`
}
// NetworksResult models the networks data from the getnetworkinfo command.
type NetworksResult struct {
Name string `json:"name"`
Limited bool `json:"limited"`
Reachable bool `json:"reachable"`
Proxy string `json:"proxy"`
}
// GetNetworkInfoResult models the data returned from the getnetworkinfo
// command.
type GetNetworkInfoResult struct {
@ -207,6 +272,13 @@ type GetNetworkInfoResult struct {
LocalAddresses []LocalAddressesResult `json:"localaddresses"`
}
// GetNetTotalsResult models the data returned from the getnettotals command.
type GetNetTotalsResult struct {
TotalBytesRecv uint64 `json:"totalbytesrecv"`
TotalBytesSent uint64 `json:"totalbytessent"`
TimeMillis int64 `json:"timemillis"`
}
// GetPeerInfoResult models the data returned from the getpeerinfo command.
type GetPeerInfoResult struct {
ID int32 `json:"id"`
@ -244,15 +316,71 @@ type GetRawMempoolVerboseResult struct {
Depends []string `json:"depends"`
}
// ScriptPubKeyResult models the scriptPubKey data of a tx script. It is
// defined separately since it is used by multiple commands.
type ScriptPubKeyResult struct {
Asm string `json:"asm"`
Hex string `json:"hex,omitempty"`
ReqSigs int32 `json:"reqSigs,omitempty"`
Type string `json:"type"`
Addresses []string `json:"addresses,omitempty"`
CommitAmt *float64 `json:"commitamt,omitempty"`
// TxRawResult models the data from the getrawtransaction command.
type TxRawResult struct {
Hex string `json:"hex"`
Txid string `json:"txid"`
Version int32 `json:"version"`
LockTime uint32 `json:"locktime"`
Expiry uint32 `json:"expiry"`
Vin []Vin `json:"vin"`
Vout []Vout `json:"vout"`
BlockHash string `json:"blockhash,omitempty"`
BlockHeight int64 `json:"blockheight"`
BlockIndex uint32 `json:"blockindex,omitempty"`
Confirmations int64 `json:"confirmations,omitempty"`
Time int64 `json:"time,omitempty"`
Blocktime int64 `json:"blocktime,omitempty"`
}
// GetStakeDifficultyResult models the data returned from the
// getstakedifficulty command.
type GetStakeDifficultyResult struct {
CurrentStakeDifficulty float64 `json:"current"`
NextStakeDifficulty float64 `json:"next"`
}
// VersionCount models a generic version:count tuple.
type VersionCount struct {
Version uint32 `json:"version"`
Count uint32 `json:"count"`
}
// VersionInterval models a cooked version count for an interval.
type VersionInterval struct {
StartHeight int64 `json:"startheight"`
EndHeight int64 `json:"endheight"`
PoSVersions []VersionCount `json:"posversions"`
VoteVersions []VersionCount `json:"voteversions"`
}
// GetStakeVersionInfoResult models the resulting data for getstakeversioninfo
// command.
type GetStakeVersionInfoResult struct {
CurrentHeight int64 `json:"currentheight"`
Hash string `json:"hash"`
Intervals []VersionInterval `json:"intervals"`
}
// VersionBits models a generic version:bits tuple.
type VersionBits struct {
Version uint32 `json:"version"`
Bits uint16 `json:"bits"`
}
// StakeVersions models the data for GetStakeVersionsResult.
type StakeVersions struct {
Hash string `json:"hash"`
Height int64 `json:"height"`
BlockVersion int32 `json:"blockversion"`
StakeVersion uint32 `json:"stakeversion"`
Votes []VersionBits `json:"votes"`
}
// GetStakeVersionsResult models the data returned from the getstakeversions
// command.
type GetStakeVersionsResult struct {
StakeVersions []StakeVersions `json:"stakeversions"`
}
// GetTxOutResult models the data from the gettxout command.
@ -265,11 +393,172 @@ type GetTxOutResult struct {
Coinbase bool `json:"coinbase"`
}
// GetNetTotalsResult models the data returned from the getnettotals command.
type GetNetTotalsResult struct {
TotalBytesRecv uint64 `json:"totalbytesrecv"`
TotalBytesSent uint64 `json:"totalbytessent"`
TimeMillis int64 `json:"timemillis"`
// Choice models an individual choice inside an Agenda.
type Choice struct {
Id string `json:"id"`
Description string `json:"description"`
Bits uint16 `json:"bits"`
IsAbstain bool `json:"isabstain"`
IsNo bool `json:"isno"`
Count uint32 `json:"count"`
Progress float64 `json:"progress"`
}
// Agenda models an individual agenda including its choices.
type Agenda struct {
Id string `json:"id"`
Description string `json:"description"`
Mask uint16 `json:"mask"`
StartTime uint64 `json:"starttime"`
ExpireTime uint64 `json:"expiretime"`
Status string `json:"status"`
QuorumProgress float64 `json:"quorumprogress"`
Choices []Choice `json:"choices"`
}
// GetVoteInfoResult models the data returned from the getvoteinfo command.
type GetVoteInfoResult struct {
CurrentHeight int64 `json:"currentheight"`
StartHeight int64 `json:"startheight"`
EndHeight int64 `json:"endheight"`
Hash string `json:"hash"`
VoteVersion uint32 `json:"voteversion"`
Quorum uint32 `json:"quorum"`
TotalVotes uint32 `json:"totalvotes"`
Agendas []Agenda `json:"agendas,omitempty"`
}
// GetWorkResult models the data from the getwork command.
type GetWorkResult struct {
Data string `json:"data"`
Target string `json:"target"`
}
// Ticket is the structure representing a ticket.
type Ticket struct {
Hash string `json:"hash"`
Owner string `json:"owner"`
}
// LiveTicketsResult models the data returned from the livetickets
// command.
type LiveTicketsResult struct {
Tickets []string `json:"tickets"`
}
// MissedTicketsResult models the data returned from the missedtickets
// command.
type MissedTicketsResult struct {
Tickets []string `json:"tickets"`
}
// FeeInfoBlock is ticket fee information about a block.
type FeeInfoBlock struct {
Height uint32 `json:"height"`
Number uint32 `json:"number"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Mean float64 `json:"mean"`
Median float64 `json:"median"`
StdDev float64 `json:"stddev"`
}
// FeeInfoMempool is ticket fee information about the mempool.
type FeeInfoMempool struct {
Number uint32 `json:"number"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Mean float64 `json:"mean"`
Median float64 `json:"median"`
StdDev float64 `json:"stddev"`
}
// FeeInfoRange is ticket fee information about a range.
type FeeInfoRange struct {
Number uint32 `json:"number"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Mean float64 `json:"mean"`
Median float64 `json:"median"`
StdDev float64 `json:"stddev"`
}
// FeeInfoWindow is ticket fee information about an adjustment window.
type FeeInfoWindow struct {
StartHeight uint32 `json:"startheight"`
EndHeight uint32 `json:"endheight"`
Number uint32 `json:"number"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Mean float64 `json:"mean"`
Median float64 `json:"median"`
StdDev float64 `json:"stddev"`
}
// TicketFeeInfoResult models the data returned from the ticketfeeinfo command.
// command.
type TicketFeeInfoResult struct {
FeeInfoMempool FeeInfoMempool `json:"feeinfomempool"`
FeeInfoBlocks []FeeInfoBlock `json:"feeinfoblocks"`
FeeInfoWindows []FeeInfoWindow `json:"feeinfowindows"`
}
// SearchRawTransactionsResult models the data from the searchrawtransaction
// command.
type SearchRawTransactionsResult struct {
Hex string `json:"hex,omitempty"`
Txid string `json:"txid"`
Version int32 `json:"version"`
LockTime uint32 `json:"locktime"`
Vin []VinPrevOut `json:"vin"`
Vout []Vout `json:"vout"`
BlockHash string `json:"blockhash,omitempty"`
Confirmations uint64 `json:"confirmations,omitempty"`
Time int64 `json:"time,omitempty"`
Blocktime int64 `json:"blocktime,omitempty"`
}
// TxFeeInfoResult models the data returned from the ticketfeeinfo command.
// command.
type TxFeeInfoResult struct {
FeeInfoMempool FeeInfoMempool `json:"feeinfomempool"`
FeeInfoBlocks []FeeInfoBlock `json:"feeinfoblocks"`
FeeInfoRange FeeInfoRange `json:"feeinforange"`
}
// TicketsForAddressResult models the data returned from the ticketforaddress
// command.
type TicketsForAddressResult struct {
Tickets []string `json:"tickets"`
}
// ValidateAddressChainResult models the data returned by the chain server
// validateaddress command.
type ValidateAddressChainResult struct {
IsValid bool `json:"isvalid"`
Address string `json:"address,omitempty"`
}
// VersionResult models objects included in the version response. In the actual
// result, these objects are keyed by the program or API name.
type VersionResult struct {
VersionString string `json:"versionstring"`
Major uint32 `json:"major"`
Minor uint32 `json:"minor"`
Patch uint32 `json:"patch"`
Prerelease string `json:"prerelease"`
BuildMetadata string `json:"buildmetadata"`
}
// ScriptPubKeyResult models the scriptPubKey data of a tx script. It is
// defined separately since it is used by multiple commands.
type ScriptPubKeyResult struct {
Asm string `json:"asm"`
Hex string `json:"hex,omitempty"`
ReqSigs int32 `json:"reqSigs,omitempty"`
Type string `json:"type"`
Addresses []string `json:"addresses,omitempty"`
CommitAmt *float64 `json:"commitamt,omitempty"`
}
// ScriptSig models a signature script. It is defined separately since it only
@ -455,111 +744,3 @@ type Vout struct {
Version uint16 `json:"version"`
ScriptPubKey ScriptPubKeyResult `json:"scriptPubKey"`
}
// GetMiningInfoResult models the data from the getmininginfo command.
// Contains Decred additions.
type GetMiningInfoResult struct {
Blocks int64 `json:"blocks"`
CurrentBlockSize uint64 `json:"currentblocksize"`
CurrentBlockTx uint64 `json:"currentblocktx"`
Difficulty float64 `json:"difficulty"`
StakeDifficulty int64 `json:"stakedifficulty"`
Errors string `json:"errors"`
Generate bool `json:"generate"`
GenProcLimit int32 `json:"genproclimit"`
HashesPerSec int64 `json:"hashespersec"`
NetworkHashPS int64 `json:"networkhashps"`
PooledTx uint64 `json:"pooledtx"`
TestNet bool `json:"testnet"`
}
// GetWorkResult models the data from the getwork command.
type GetWorkResult struct {
Data string `json:"data"`
Target string `json:"target"`
}
// InfoChainResult models the data returned by the chain server getinfo command.
type InfoChainResult struct {
Version int32 `json:"version"`
ProtocolVersion int32 `json:"protocolversion"`
Blocks int64 `json:"blocks"`
TimeOffset int64 `json:"timeoffset"`
Connections int32 `json:"connections"`
Proxy string `json:"proxy"`
Difficulty float64 `json:"difficulty"`
TestNet bool `json:"testnet"`
RelayFee float64 `json:"relayfee"`
Errors string `json:"errors"`
}
// LocalAddressesResult models the localaddresses data from the getnetworkinfo
// command.
type LocalAddressesResult struct {
Address string `json:"address"`
Port uint16 `json:"port"`
Score int32 `json:"score"`
}
// NetworksResult models the networks data from the getnetworkinfo command.
type NetworksResult struct {
Name string `json:"name"`
Limited bool `json:"limited"`
Reachable bool `json:"reachable"`
Proxy string `json:"proxy"`
}
// TxRawResult models the data from the getrawtransaction command.
type TxRawResult struct {
Hex string `json:"hex"`
Txid string `json:"txid"`
Version int32 `json:"version"`
LockTime uint32 `json:"locktime"`
Expiry uint32 `json:"expiry"`
Vin []Vin `json:"vin"`
Vout []Vout `json:"vout"`
BlockHash string `json:"blockhash,omitempty"`
BlockHeight int64 `json:"blockheight"`
BlockIndex uint32 `json:"blockindex,omitempty"`
Confirmations int64 `json:"confirmations,omitempty"`
Time int64 `json:"time,omitempty"`
Blocktime int64 `json:"blocktime,omitempty"`
}
// SearchRawTransactionsResult models the data from the searchrawtransaction
// command.
type SearchRawTransactionsResult struct {
Hex string `json:"hex,omitempty"`
Txid string `json:"txid"`
Version int32 `json:"version"`
LockTime uint32 `json:"locktime"`
Vin []VinPrevOut `json:"vin"`
Vout []Vout `json:"vout"`
BlockHash string `json:"blockhash,omitempty"`
Confirmations uint64 `json:"confirmations,omitempty"`
Time int64 `json:"time,omitempty"`
Blocktime int64 `json:"blocktime,omitempty"`
}
// TxRawDecodeResult models the data from the decoderawtransaction command.
type TxRawDecodeResult struct {
Txid string `json:"txid"`
Version int32 `json:"version"`
Locktime uint32 `json:"locktime"`
Expiry uint32 `json:"expiry"`
Vin []Vin `json:"vin"`
Vout []Vout `json:"vout"`
}
// ValidateAddressChainResult models the data returned by the chain server
// validateaddress command.
type ValidateAddressChainResult struct {
IsValid bool `json:"isvalid"`
Address string `json:"address,omitempty"`
}
// GetHeadersResult models the data returned by the chain server getheaders
// command.
type GetHeadersResult struct {
Headers []string `json:"headers"`
}

View File

@ -1,317 +0,0 @@
// Copyright (c) 2015-2016 The Decred 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 chain server with btcd extensions.
package dcrjson
// EstimateStakeDiffCmd defines the eststakedifficulty JSON-RPC command.
type EstimateStakeDiffCmd struct {
Tickets *uint32
}
// NewEstimateStakeDiffCmd defines the eststakedifficulty JSON-RPC command.
func NewEstimateStakeDiffCmd(tickets *uint32) *EstimateStakeDiffCmd {
return &EstimateStakeDiffCmd{
Tickets: tickets,
}
}
// ExistsAddressCmd defines the existsaddress JSON-RPC command.
type ExistsAddressCmd struct {
Address string
}
// NewExistsAddressCmd returns a new instance which can be used to issue a
// existsaddress JSON-RPC command.
func NewExistsAddressCmd(address string) *ExistsAddressCmd {
return &ExistsAddressCmd{
Address: address,
}
}
// ExistsAddressesCmd defines the existsaddresses JSON-RPC command.
type ExistsAddressesCmd struct {
Addresses []string
}
// NewExistsAddressesCmd returns a new instance which can be used to issue an
// existsaddresses JSON-RPC command.
func NewExistsAddressesCmd(addresses []string) *ExistsAddressesCmd {
return &ExistsAddressesCmd{
Addresses: addresses,
}
}
// ExistsMissedTicketsCmd defines the existsmissedtickets JSON-RPC command.
type ExistsMissedTicketsCmd struct {
TxHashBlob string
}
// NewExistsMissedTicketsCmd returns a new instance which can be used to issue an
// existsmissedtickets JSON-RPC command.
func NewExistsMissedTicketsCmd(txHashBlob string) *ExistsMissedTicketsCmd {
return &ExistsMissedTicketsCmd{
TxHashBlob: txHashBlob,
}
}
// ExistsExpiredTicketsCmd defines the existsexpiredtickets JSON-RPC command.
type ExistsExpiredTicketsCmd struct {
TxHashBlob string
}
// NewExistsExpiredTicketsCmd returns a new instance which can be used to issue an
// existsexpiredtickets JSON-RPC command.
func NewExistsExpiredTicketsCmd(txHashBlob string) *ExistsExpiredTicketsCmd {
return &ExistsExpiredTicketsCmd{
TxHashBlob: txHashBlob,
}
}
// ExistsLiveTicketCmd defines the existsliveticket JSON-RPC command.
type ExistsLiveTicketCmd struct {
TxHash string
}
// NewExistsLiveTicketCmd returns a new instance which can be used to issue an
// existsliveticket JSON-RPC command.
func NewExistsLiveTicketCmd(txHash string) *ExistsLiveTicketCmd {
return &ExistsLiveTicketCmd{
TxHash: txHash,
}
}
// ExistsLiveTicketsCmd defines the existslivetickets JSON-RPC command.
type ExistsLiveTicketsCmd struct {
TxHashBlob string
}
// NewExistsLiveTicketsCmd returns a new instance which can be used to issue an
// existslivetickets JSON-RPC command.
func NewExistsLiveTicketsCmd(txHashBlob string) *ExistsLiveTicketsCmd {
return &ExistsLiveTicketsCmd{
TxHashBlob: txHashBlob,
}
}
// ExistsMempoolTxsCmd defines the existsmempooltxs JSON-RPC command.
type ExistsMempoolTxsCmd struct {
TxHashBlob string
}
// NewExistsMempoolTxsCmd returns a new instance which can be used to issue an
// existslivetickets JSON-RPC command.
func NewExistsMempoolTxsCmd(txHashBlob string) *ExistsMempoolTxsCmd {
return &ExistsMempoolTxsCmd{
TxHashBlob: txHashBlob,
}
}
// GetCoinSupplyCmd defines the getcoinsupply JSON-RPC command.
type GetCoinSupplyCmd struct{}
// NewGetCoinSupplyCmd returns a new instance which can be used to issue a
// getcoinsupply JSON-RPC command.
func NewGetCoinSupplyCmd() *GetCoinSupplyCmd {
return &GetCoinSupplyCmd{}
}
// GetStakeDifficultyCmd is a type handling custom marshaling and
// unmarshaling of getstakedifficulty JSON RPC commands.
type GetStakeDifficultyCmd struct{}
// NewGetStakeDifficultyCmd returns a new instance which can be used to
// issue a JSON-RPC getstakedifficulty command.
func NewGetStakeDifficultyCmd() *GetStakeDifficultyCmd {
return &GetStakeDifficultyCmd{}
}
// GetStakeVersionInfoCmd returns stake version info for the current interval.
// Optionally, Count indicates how many additional intervals to return.
type GetStakeVersionInfoCmd struct {
Count *int32
}
// NewGetStakeVersionInfoCmd returns a new instance which can be used to
// issue a JSON-RPC getstakeversioninfo command.
func NewGetStakeVersionInfoCmd(count int32) *GetStakeVersionInfoCmd {
return &GetStakeVersionInfoCmd{
Count: &count,
}
}
// GetStakeVersionsCmd returns stake version for a range of blocks.
// Count indicates how many blocks are walked backwards.
type GetStakeVersionsCmd struct {
Hash string
Count int32
}
// NewGetStakeVersionsCmd returns a new instance which can be used to
// issue a JSON-RPC getstakeversions command.
func NewGetStakeVersionsCmd(hash string, count int32) *GetStakeVersionsCmd {
return &GetStakeVersionsCmd{
Hash: hash,
Count: count,
}
}
// GetTicketPoolValueCmd defines the getticketpoolvalue JSON-RPC command.
type GetTicketPoolValueCmd struct{}
// NewGetTicketPoolValueCmd returns a new instance which can be used to issue a
// getticketpoolvalue JSON-RPC command.
func NewGetTicketPoolValueCmd() *GetTicketPoolValueCmd {
return &GetTicketPoolValueCmd{}
}
// GetVoteInfoCmd returns voting results over a range of blocks. Count
// indicates how many blocks are walked backwards.
type GetVoteInfoCmd struct {
Version uint32
}
// NewGetVoteInfoCmd returns a new instance which can be used to
// issue a JSON-RPC getvoteinfo command.
func NewGetVoteInfoCmd(version uint32) *GetVoteInfoCmd {
return &GetVoteInfoCmd{
Version: version,
}
}
// LiveTicketsCmd is a type handling custom marshaling and
// unmarshaling of livetickets JSON RPC commands.
type LiveTicketsCmd struct{}
// NewLiveTicketsCmd returns a new instance which can be used to issue a JSON-RPC
// livetickets command.
func NewLiveTicketsCmd() *LiveTicketsCmd {
return &LiveTicketsCmd{}
}
// MissedTicketsCmd is a type handling custom marshaling and
// unmarshaling of missedtickets JSON RPC commands.
type MissedTicketsCmd struct{}
// NewMissedTicketsCmd returns a new instance which can be used to issue a JSON-RPC
// missedtickets command.
func NewMissedTicketsCmd() *MissedTicketsCmd {
return &MissedTicketsCmd{}
}
// RebroadcastMissedCmd is a type handling custom marshaling and
// unmarshaling of rebroadcastwinners JSON RPC commands.
type RebroadcastMissedCmd struct{}
// NewRebroadcastMissedCmd returns a new instance which can be used to
// issue a JSON-RPC rebroadcastmissed command.
func NewRebroadcastMissedCmd() *RebroadcastMissedCmd {
return &RebroadcastMissedCmd{}
}
// RebroadcastWinnersCmd is a type handling custom marshaling and
// unmarshaling of rebroadcastwinners JSON RPC commands.
type RebroadcastWinnersCmd struct{}
// NewRebroadcastWinnersCmd returns a new instance which can be used to
// issue a JSON-RPC rebroadcastwinners command.
func NewRebroadcastWinnersCmd() *RebroadcastWinnersCmd {
return &RebroadcastWinnersCmd{}
}
// TicketFeeInfoCmd defines the ticketsfeeinfo JSON-RPC command.
type TicketFeeInfoCmd struct {
Blocks *uint32
Windows *uint32
}
// NewTicketFeeInfoCmd returns a new instance which can be used to issue a
// JSON-RPC ticket fee info command.
func NewTicketFeeInfoCmd(blocks *uint32, windows *uint32) *TicketFeeInfoCmd {
return &TicketFeeInfoCmd{
Blocks: blocks,
Windows: windows,
}
}
// TicketsForAddressCmd defines the ticketsforbucket JSON-RPC command.
type TicketsForAddressCmd struct {
Address string
}
// NewTicketsForAddressCmd returns a new instance which can be used to issue a
// JSON-RPC tickets for bucket command.
func NewTicketsForAddressCmd(addr string) *TicketsForAddressCmd {
return &TicketsForAddressCmd{addr}
}
// TicketVWAPCmd defines the ticketvwap JSON-RPC command.
type TicketVWAPCmd struct {
Start *uint32
End *uint32
}
// NewTicketVWAPCmd returns a new instance which can be used to issue a
// JSON-RPC ticket volume weight average price command.
func NewTicketVWAPCmd(start *uint32, end *uint32) *TicketVWAPCmd {
return &TicketVWAPCmd{
Start: start,
End: end,
}
}
// TxFeeInfoCmd defines the ticketsfeeinfo JSON-RPC command.
type TxFeeInfoCmd struct {
Blocks *uint32
RangeStart *uint32
RangeEnd *uint32
}
// NewTxFeeInfoCmd returns a new instance which can be used to issue a
// JSON-RPC ticket fee info command.
func NewTxFeeInfoCmd(blocks *uint32, start *uint32, end *uint32) *TxFeeInfoCmd {
return &TxFeeInfoCmd{
Blocks: blocks,
RangeStart: start,
RangeEnd: end,
}
}
// VersionCmd defines the version JSON-RPC command.
type VersionCmd struct{}
// NewVersionCmd returns a new instance which can be used to issue a JSON-RPC
// version command.
func NewVersionCmd() *VersionCmd { return new(VersionCmd) }
func init() {
// No special flags for commands in this file.
flags := UsageFlag(0)
MustRegisterCmd("estimatestakediff", (*EstimateStakeDiffCmd)(nil), flags)
MustRegisterCmd("existsaddress", (*ExistsAddressCmd)(nil), flags)
MustRegisterCmd("existsaddresses", (*ExistsAddressesCmd)(nil), flags)
MustRegisterCmd("existsmissedtickets", (*ExistsMissedTicketsCmd)(nil), flags)
MustRegisterCmd("existsexpiredtickets", (*ExistsExpiredTicketsCmd)(nil), flags)
MustRegisterCmd("existsliveticket", (*ExistsLiveTicketCmd)(nil), flags)
MustRegisterCmd("existslivetickets", (*ExistsLiveTicketsCmd)(nil), flags)
MustRegisterCmd("existsmempooltxs", (*ExistsMempoolTxsCmd)(nil), flags)
MustRegisterCmd("getcoinsupply", (*GetCoinSupplyCmd)(nil), flags)
MustRegisterCmd("getstakedifficulty", (*GetStakeDifficultyCmd)(nil), flags)
MustRegisterCmd("getstakeversioninfo", (*GetStakeVersionInfoCmd)(nil), flags)
MustRegisterCmd("getstakeversions", (*GetStakeVersionsCmd)(nil), flags)
MustRegisterCmd("getticketpoolvalue", (*GetTicketPoolValueCmd)(nil), flags)
MustRegisterCmd("getvoteinfo", (*GetVoteInfoCmd)(nil), flags)
MustRegisterCmd("livetickets", (*LiveTicketsCmd)(nil), flags)
MustRegisterCmd("missedtickets", (*MissedTicketsCmd)(nil), flags)
MustRegisterCmd("rebroadcastmissed", (*RebroadcastMissedCmd)(nil), flags)
MustRegisterCmd("rebroadcastwinners", (*RebroadcastWinnersCmd)(nil), flags)
MustRegisterCmd("ticketfeeinfo", (*TicketFeeInfoCmd)(nil), flags)
MustRegisterCmd("ticketsforaddress", (*TicketsForAddressCmd)(nil), flags)
MustRegisterCmd("ticketvwap", (*TicketVWAPCmd)(nil), flags)
MustRegisterCmd("txfeeinfo", (*TxFeeInfoCmd)(nil), flags)
MustRegisterCmd("version", (*VersionCmd)(nil), flags)
}

View File

@ -1,139 +0,0 @@
// Copyright (c) 2015-2016 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package dcrjson_test
import (
"bytes"
"encoding/json"
"fmt"
"reflect"
"testing"
"github.com/decred/dcrd/dcrjson"
)
// TestBtcdCmds tests all of the btcd 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 TestDcrdCmds(t *testing.T) {
t.Parallel()
testID := int(1)
tests := []struct {
name string
newCmd func() (interface{}, error)
staticCmd func() interface{}
marshalled string
unmarshalled interface{}
}{
{
name: "debuglevel",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("debuglevel", "trace")
},
staticCmd: func() interface{} {
return dcrjson.NewDebugLevelCmd("trace")
},
marshalled: `{"jsonrpc":"1.0","method":"debuglevel","params":["trace"],"id":1}`,
unmarshalled: &dcrjson.DebugLevelCmd{
LevelSpec: "trace",
},
},
{
name: "getstakeversions",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("getstakeversions", "deadbeef", 1)
},
staticCmd: func() interface{} {
return dcrjson.NewGetStakeVersionsCmd("deadbeef", 1)
},
marshalled: `{"jsonrpc":"1.0","method":"getstakeversions","params":["deadbeef",1],"id":1}`,
unmarshalled: &dcrjson.GetStakeVersionsCmd{
Hash: "deadbeef",
Count: 1,
},
},
{
name: "getvoteinfo",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("getvoteinfo", 1)
},
staticCmd: func() interface{} {
return dcrjson.NewGetVoteInfoCmd(1)
},
marshalled: `{"jsonrpc":"1.0","method":"getvoteinfo","params":[1],"id":1}`,
unmarshalled: &dcrjson.GetVoteInfoCmd{
Version: 1,
},
},
}
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 := dcrjson.MarshalCmd("1.0", 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 = dcrjson.MarshalCmd("1.0", 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 dcrjson.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 = dcrjson.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
}
}
}

View File

@ -1,194 +0,0 @@
// Copyright (c) 2014 The btcsuite developers
// Copyright (c) 2015-2016 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package dcrjson
// GetStakeDifficultyResult models the data returned from the
// getstakedifficulty command.
type GetStakeDifficultyResult struct {
CurrentStakeDifficulty float64 `json:"current"`
NextStakeDifficulty float64 `json:"next"`
}
// VersionCount models a generic version:count tuple.
type VersionCount struct {
Version uint32 `json:"version"`
Count uint32 `json:"count"`
}
// VersionInterval models a cooked version count for an interval.
type VersionInterval struct {
StartHeight int64 `json:"startheight"`
EndHeight int64 `json:"endheight"`
PoSVersions []VersionCount `json:"posversions"`
VoteVersions []VersionCount `json:"voteversions"`
}
// GetStakeVersionInfoResult models the resulting data for getstakeversioninfo
// command.
type GetStakeVersionInfoResult struct {
CurrentHeight int64 `json:"currentheight"`
Hash string `json:"hash"`
Intervals []VersionInterval `json:"intervals"`
}
// VersionBits models a generic version:bits tuple.
type VersionBits struct {
Version uint32 `json:"version"`
Bits uint16 `json:"bits"`
}
// StakeVersions models the data for GetStakeVersionsResult.
type StakeVersions struct {
Hash string `json:"hash"`
Height int64 `json:"height"`
BlockVersion int32 `json:"blockversion"`
StakeVersion uint32 `json:"stakeversion"`
Votes []VersionBits `json:"votes"`
}
// GetStakeVersionsResult models the data returned from the getstakeversions
// command.
type GetStakeVersionsResult struct {
StakeVersions []StakeVersions `json:"stakeversions"`
}
// Choice models an individual choice inside an Agenda.
type Choice struct {
Id string `json:"id"`
Description string `json:"description"`
Bits uint16 `json:"bits"`
IsAbstain bool `json:"isabstain"`
IsNo bool `json:"isno"`
Count uint32 `json:"count"`
Progress float64 `json:"progress"`
}
// Agenda models an individual agenda including its choices.
type Agenda struct {
Id string `json:"id"`
Description string `json:"description"`
Mask uint16 `json:"mask"`
StartTime uint64 `json:"starttime"`
ExpireTime uint64 `json:"expiretime"`
Status string `json:"status"`
QuorumProgress float64 `json:"quorumprogress"`
Choices []Choice `json:"choices"`
}
// GetVoteInfoResult models the data returned from the getvoteinfo command.
type GetVoteInfoResult struct {
CurrentHeight int64 `json:"currentheight"`
StartHeight int64 `json:"startheight"`
EndHeight int64 `json:"endheight"`
Hash string `json:"hash"`
VoteVersion uint32 `json:"voteversion"`
Quorum uint32 `json:"quorum"`
TotalVotes uint32 `json:"totalvotes"`
Agendas []Agenda `json:"agendas,omitempty"`
}
// EstimateStakeDiffResult models the data returned from the estimatestakediff
// command.
type EstimateStakeDiffResult struct {
Min float64 `json:"min"`
Max float64 `json:"max"`
Expected float64 `json:"expected"`
User *float64 `json:"user,omitempty"`
}
// LiveTicketsResult models the data returned from the livetickets
// command.
type LiveTicketsResult struct {
Tickets []string `json:"tickets"`
}
// MissedTicketsResult models the data returned from the missedtickets
// command.
type MissedTicketsResult struct {
Tickets []string `json:"tickets"`
}
// Ticket is the structure representing a ticket.
type Ticket struct {
Hash string `json:"hash"`
Owner string `json:"owner"`
}
// FeeInfoBlock is ticket fee information about a block.
type FeeInfoBlock struct {
Height uint32 `json:"height"`
Number uint32 `json:"number"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Mean float64 `json:"mean"`
Median float64 `json:"median"`
StdDev float64 `json:"stddev"`
}
// FeeInfoMempool is ticket fee information about the mempool.
type FeeInfoMempool struct {
Number uint32 `json:"number"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Mean float64 `json:"mean"`
Median float64 `json:"median"`
StdDev float64 `json:"stddev"`
}
// FeeInfoRange is ticket fee information about a range.
type FeeInfoRange struct {
Number uint32 `json:"number"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Mean float64 `json:"mean"`
Median float64 `json:"median"`
StdDev float64 `json:"stddev"`
}
// FeeInfoWindow is ticket fee information about an adjustment window.
type FeeInfoWindow struct {
StartHeight uint32 `json:"startheight"`
EndHeight uint32 `json:"endheight"`
Number uint32 `json:"number"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Mean float64 `json:"mean"`
Median float64 `json:"median"`
StdDev float64 `json:"stddev"`
}
// TicketFeeInfoResult models the data returned from the ticketfeeinfo command.
// command.
type TicketFeeInfoResult struct {
FeeInfoMempool FeeInfoMempool `json:"feeinfomempool"`
FeeInfoBlocks []FeeInfoBlock `json:"feeinfoblocks"`
FeeInfoWindows []FeeInfoWindow `json:"feeinfowindows"`
}
// TicketsForAddressResult models the data returned from the ticketforaddress
// command.
type TicketsForAddressResult struct {
Tickets []string `json:"tickets"`
}
// TxFeeInfoResult models the data returned from the ticketfeeinfo command.
// command.
type TxFeeInfoResult struct {
FeeInfoMempool FeeInfoMempool `json:"feeinfomempool"`
FeeInfoBlocks []FeeInfoBlock `json:"feeinfoblocks"`
FeeInfoRange FeeInfoRange `json:"feeinforange"`
}
// VersionResult models objects included in the version response. In the actual
// result, these objects are keyed by the program or API name.
type VersionResult struct {
VersionString string `json:"versionstring"`
Major uint32 `json:"major"`
Minor uint32 `json:"minor"`
Patch uint32 `json:"patch"`
Prerelease string `json:"prerelease"`
BuildMetadata string `json:"buildmetadata"`
}

View File

@ -1,660 +0,0 @@
// Copyright (c) 2015-2016 The Decred 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 dcrjson
// AccountAddressIndexCmd is a type handling custom marshaling and
// unmarshaling of accountaddressindex JSON wallet extension
// commands.
type AccountAddressIndexCmd struct {
Account string `json:"account"`
Branch int `json:"branch"`
}
// NewAccountAddressIndexCmd creates a new AccountAddressIndexCmd.
func NewAccountAddressIndexCmd(acct string, branch int) *AccountAddressIndexCmd {
return &AccountAddressIndexCmd{
Account: acct,
Branch: branch,
}
}
// AccountSyncAddressIndexCmd is a type handling custom marshaling and
// unmarshaling of accountsyncaddressindex JSON wallet extension
// commands.
type AccountSyncAddressIndexCmd struct {
Account string `json:"account"`
Branch int `json:"branch"`
Index int `json:"index"`
}
// NewAccountSyncAddressIndexCmd creates a new AccountSyncAddressIndexCmd.
func NewAccountSyncAddressIndexCmd(acct string, branch int,
idx int) *AccountSyncAddressIndexCmd {
return &AccountSyncAddressIndexCmd{
Account: acct,
Branch: branch,
Index: idx,
}
}
// AddTicketCmd forces a ticket into the wallet stake manager, for example if
// someone made an invalid ticket for a stake pool and the pool manager wanted
// to manually add it.
type AddTicketCmd struct {
TicketHex string `json:"tickethex"`
}
// NewAddTicketCmd creates a new AddTicketCmd.
func NewAddTicketCmd(ticketHex string) *AddTicketCmd {
return &AddTicketCmd{TicketHex: ticketHex}
}
// ConsolidateCmd is a type handling custom marshaling and
// unmarshaling of consolidate JSON wallet extension
// commands.
type ConsolidateCmd struct {
Inputs int `json:"inputs"`
Account *string
Address *string
}
// NewConsolidateCmd creates a new ConsolidateCmd.
func NewConsolidateCmd(inputs int, acct *string, addr *string) *ConsolidateCmd {
return &ConsolidateCmd{Inputs: inputs, Account: acct, Address: addr}
}
// SStxInput represents the inputs to an SStx transaction. Specifically a
// transactionsha and output number pair, along with the output amounts.
type SStxInput struct {
Txid string `json:"txid"`
Vout uint32 `json:"vout"`
Tree int8 `json:"tree"`
Amt int64 `json:"amt"`
}
// SStxCommitOut represents the output to an SStx transaction. Specifically a
// a commitment address and amount, and a change address and amount.
type SStxCommitOut struct {
Addr string `json:"addr"`
CommitAmt int64 `json:"commitamt"`
ChangeAddr string `json:"changeaddr"`
ChangeAmt int64 `json:"changeamt"`
}
// CreateRawSStxCmd is a type handling custom marshaling and
// unmarshaling of createrawsstx JSON RPC commands.
type CreateRawSStxCmd struct {
Inputs []SStxInput
Amount map[string]int64
COuts []SStxCommitOut
}
// NewCreateRawSStxCmd creates a new CreateRawSStxCmd.
func NewCreateRawSStxCmd(inputs []SStxInput, amount map[string]int64,
couts []SStxCommitOut) *CreateRawSStxCmd {
return &CreateRawSStxCmd{
Inputs: inputs,
Amount: amount,
COuts: couts,
}
}
// CreateRawSSGenTxCmd is a type handling custom marshaling and
// unmarshaling of createrawssgentxcmd JSON RPC commands.
type CreateRawSSGenTxCmd struct {
Inputs []TransactionInput
VoteBits uint16
}
// NewCreateRawSSGenTxCmd creates a new CreateRawSSGenTxCmd.
func NewCreateRawSSGenTxCmd(inputs []TransactionInput,
vb uint16) *CreateRawSSGenTxCmd {
return &CreateRawSSGenTxCmd{
Inputs: inputs,
VoteBits: vb,
}
}
// CreateRawSSRtxCmd is a type handling custom marshaling and
// unmarshaling of createrawssrtx JSON RPC commands.
type CreateRawSSRtxCmd struct {
Inputs []TransactionInput
Fee *float64
}
// NewCreateRawSSRtxCmd creates a new CreateRawSSRtxCmd.
func NewCreateRawSSRtxCmd(inputs []TransactionInput, fee *float64) *CreateRawSSRtxCmd {
return &CreateRawSSRtxCmd{
Inputs: inputs,
Fee: fee,
}
}
// GenerateVoteCmd is a type handling custom marshaling and
// unmarshaling of generatevote JSON wallet extension commands.
type GenerateVoteCmd struct {
BlockHash string
Height int64
TicketHash string
VoteBits uint16
VoteBitsExt string
}
// NewGenerateVoteCmd creates a new GenerateVoteCmd.
func NewGenerateVoteCmd(blockhash string, height int64, tickethash string, votebits uint16, voteBitsExt string) *GenerateVoteCmd {
return &GenerateVoteCmd{
BlockHash: blockhash,
Height: height,
TicketHash: tickethash,
VoteBits: votebits,
VoteBitsExt: voteBitsExt,
}
}
// GetMultisigOutInfoCmd is a type handling custom marshaling and
// unmarshaling of getmultisigoutinfo JSON websocket extension
// commands.
type GetMultisigOutInfoCmd struct {
Hash string
Index uint32
}
// NewGetMultisigOutInfoCmd creates a new GetMultisigOutInfoCmd.
func NewGetMultisigOutInfoCmd(hash string, index uint32) *GetMultisigOutInfoCmd {
return &GetMultisigOutInfoCmd{hash, index}
}
// GetMasterPubkeyCmd is a type handling custom marshaling and unmarshaling of
// getmasterpubkey JSON wallet extension commands.
type GetMasterPubkeyCmd struct {
Account *string
}
// NewGetMasterPubkeyCmd creates a new GetMasterPubkeyCmd.
func NewGetMasterPubkeyCmd(acct *string) *GetMasterPubkeyCmd {
return &GetMasterPubkeyCmd{Account: acct}
}
// GetStakeInfoCmd is a type handling custom marshaling and
// unmarshaling of getstakeinfo JSON wallet extension commands.
type GetStakeInfoCmd struct {
}
// NewGetStakeInfoCmd creates a new GetStakeInfoCmd.
func NewGetStakeInfoCmd() *GetStakeInfoCmd {
return &GetStakeInfoCmd{}
}
// GetTicketFeeCmd is a type handling custom marshaling and
// unmarshaling of getticketfee JSON wallet extension
// commands.
type GetTicketFeeCmd struct {
}
// NewGetTicketFeeCmd creates a new GetTicketFeeCmd.
func NewGetTicketFeeCmd() *GetTicketFeeCmd {
return &GetTicketFeeCmd{}
}
// GetTicketsCmd is a type handling custom marshaling and
// unmarshaling of gettickets JSON wallet extension
// commands.
type GetTicketsCmd struct {
IncludeImmature bool
}
// NewGetTicketsCmd returns a new instance which can be used to issue a
// gettickets JSON-RPC command.
func NewGetTicketsCmd(includeImmature bool) *GetTicketsCmd {
return &GetTicketsCmd{includeImmature}
}
// GetVoteChoicesCmd returns a new instance which can be used to issue a
// getvotechoices JSON-RPC command.
type GetVoteChoicesCmd struct {
}
// NewGetVoteChoicesCmd returns a new instance which can be used to
// issue a JSON-RPC getvotechoices command.
func NewGetVoteChoicesCmd() *GetVoteChoicesCmd {
return &GetVoteChoicesCmd{}
}
// GetWalletFeeCmd defines the getwalletfee JSON-RPC command.
type GetWalletFeeCmd struct{}
// NewGetWalletFeeCmd returns a new instance which can be used to issue a
// getwalletfee JSON-RPC command.
//
func NewGetWalletFeeCmd() *GetWalletFeeCmd {
return &GetWalletFeeCmd{}
}
// ImportScriptCmd is a type for handling custom marshaling and
// unmarshaling of importscript JSON wallet extension commands.
type ImportScriptCmd struct {
Hex string
Rescan *bool `jsonrpcdefault:"true"`
ScanFrom *int
}
// NewImportScriptCmd creates a new GetImportScriptCmd.
func NewImportScriptCmd(hex string, rescan *bool, scanFrom *int) *ImportScriptCmd {
return &ImportScriptCmd{hex, rescan, scanFrom}
}
// CreateVotingAccountCmd is a type for handling custom marshaling and
// unmarshalling of createvotingaccount JSON-RPC command.
type CreateVotingAccountCmd struct {
Name string
PubKey string
ChildIndex *uint32 `jsonrpcdefault:"0"`
}
// NewCreateVotingAccountCmd creates a new CreateVotingAccountCmd.
func NewCreateVotingAccountCmd(name, pubKey string, childIndex *uint32) *CreateVotingAccountCmd {
return &CreateVotingAccountCmd{name, pubKey, childIndex}
}
// DropVotingAccountCmd is a type for handling custom marshaling and
// unmarshalling of dropvotingaccount JSON-RPC command
type DropVotingAccountCmd struct {
}
// NewDropVotingAccountCmd creates a new DropVotingAccountCmd.
func NewDropVotingAccountCmd() *DropVotingAccountCmd {
return &DropVotingAccountCmd{}
}
// ListScriptsCmd is a type for handling custom marshaling and
// unmarshaling of listscripts JSON wallet extension commands.
type ListScriptsCmd struct {
}
// NewListScriptsCmd returns a new instance which can be used to issue a
// listscripts JSON-RPC command.
func NewListScriptsCmd() *ListScriptsCmd {
return &ListScriptsCmd{}
}
// PurchaseTicketCmd is a type handling custom marshaling and
// unmarshaling of purchaseticket JSON RPC commands.
type PurchaseTicketCmd struct {
FromAccount string
SpendLimit float64 // In Coins
MinConf *int `jsonrpcdefault:"1"`
TicketAddress *string
NumTickets *int
PoolAddress *string
PoolFees *float64
Expiry *int
Comment *string
TicketChange *bool
TicketFee *float64
}
// NewPurchaseTicketCmd creates a new PurchaseTicketCmd.
func NewPurchaseTicketCmd(fromAccount string, spendLimit float64, minConf *int,
ticketAddress *string, numTickets *int, poolAddress *string, poolFees *float64,
expiry *int, comment *string, ticketChange *bool, ticketFee *float64) *PurchaseTicketCmd {
return &PurchaseTicketCmd{
FromAccount: fromAccount,
SpendLimit: spendLimit,
MinConf: minConf,
TicketAddress: ticketAddress,
NumTickets: numTickets,
PoolAddress: poolAddress,
PoolFees: poolFees,
Expiry: expiry,
Comment: comment,
TicketChange: ticketChange,
TicketFee: ticketFee,
}
}
// StartAutoBuyerCmd is a type handling custom marshaling and
// unmarshaling of startautobuyer JSON RPC commands.
type StartAutoBuyerCmd struct {
Account string
Passphrase string
BalanceToMaintain *int64
MaxFeePerKb *int64
MaxPriceRelative *float64
MaxPriceAbsolute *int64
VotingAddress *string
PoolAddress *string
PoolFees *float64
MaxPerBlock *int64
}
// NewStartAutoBuyerCmd creates a new StartAutoBuyerCmd.
func NewStartAutoBuyerCmd(account string, passphrase string, balanceToMaintain *int64, maxFeePerKb *int64, maxPriceRelative *float64, maxPriceAbsolute *int64, votingAddress *string, poolAddress *string, poolFees *float64,
maxPerBlock *int64) *StartAutoBuyerCmd {
return &StartAutoBuyerCmd{
Account: account,
Passphrase: passphrase,
BalanceToMaintain: balanceToMaintain,
MaxFeePerKb: maxFeePerKb,
MaxPriceRelative: maxPriceRelative,
MaxPriceAbsolute: maxPriceAbsolute,
VotingAddress: votingAddress,
PoolAddress: poolAddress,
PoolFees: poolFees,
MaxPerBlock: maxPerBlock,
}
}
// StopAutoBuyerCmd is a type handling custom marshaling and
// unmarshaling of stopautobuyer JSON RPC commands.
type StopAutoBuyerCmd struct {
}
// NewStopAutoBuyerCmd creates a new StopAutoBuyerCmd.
func NewStopAutoBuyerCmd() *StopAutoBuyerCmd {
return &StopAutoBuyerCmd{}
}
// RedeemMultiSigOutCmd is a type handling custom marshaling and
// unmarshaling of redeemmultisigout JSON RPC commands.
type RedeemMultiSigOutCmd struct {
Hash string
Index uint32
Tree int8
Address *string
}
// NewRedeemMultiSigOutCmd creates a new RedeemMultiSigOutCmd.
func NewRedeemMultiSigOutCmd(hash string, index uint32, tree int8,
address *string) *RedeemMultiSigOutCmd {
return &RedeemMultiSigOutCmd{
Hash: hash,
Index: index,
Tree: tree,
Address: address,
}
}
// RedeemMultiSigOutsCmd is a type handling custom marshaling and
// unmarshaling of redeemmultisigout JSON RPC commands.
type RedeemMultiSigOutsCmd struct {
FromScrAddress string
ToAddress *string
Number *int
}
// NewRedeemMultiSigOutsCmd creates a new RedeemMultiSigOutsCmd.
func NewRedeemMultiSigOutsCmd(from string, to *string,
number *int) *RedeemMultiSigOutsCmd {
return &RedeemMultiSigOutsCmd{
FromScrAddress: from,
ToAddress: to,
Number: number,
}
}
// RescanWalletCmd describes the rescanwallet JSON-RPC request and parameters.
type RescanWalletCmd struct {
BeginHeight *int `jsonrpcdefault:"0"`
}
// RevokeTicketsCmd describes the revoketickets JSON-RPC request and parameters.
type RevokeTicketsCmd struct {
}
// NewRevokeTicketsCmd creates a new RevokeTicketsCmd.
func NewRevokeTicketsCmd() *RevokeTicketsCmd {
return &RevokeTicketsCmd{}
}
// SendToMultiSigCmd is a type handling custom marshaling and
// unmarshaling of sendtomultisig JSON RPC commands.
type SendToMultiSigCmd struct {
FromAccount string
Amount float64
Pubkeys []string
NRequired *int `jsonrpcdefault:"1"`
MinConf *int `jsonrpcdefault:"1"`
Comment *string
}
// NewSendToMultiSigCmd creates a new SendToMultiSigCmd.
func NewSendToMultiSigCmd(fromaccount string, amount float64, pubkeys []string,
nrequired *int, minConf *int, comment *string) *SendToMultiSigCmd {
return &SendToMultiSigCmd{
FromAccount: fromaccount,
Amount: amount,
Pubkeys: pubkeys,
NRequired: nrequired,
MinConf: minConf,
Comment: comment,
}
}
// SendToSStxCmd is a type handling custom marshaling and
// unmarshaling of sendtosstx JSON RPC commands.
type SendToSStxCmd struct {
FromAccount string
Amounts map[string]int64
Inputs []SStxInput
COuts []SStxCommitOut
MinConf *int `jsonrpcdefault:"1"`
Comment *string
}
// NewSendToSStxCmd creates a new SendToSStxCmd. Optionally a
// pointer to a TemplateRequest may be provided.
func NewSendToSStxCmd(fromaccount string, amounts map[string]int64,
inputs []SStxInput, couts []SStxCommitOut, minConf *int,
comment *string) *SendToSStxCmd {
return &SendToSStxCmd{
FromAccount: fromaccount,
Amounts: amounts,
Inputs: inputs,
COuts: couts,
MinConf: minConf,
Comment: comment,
}
}
// SendToSSGenCmd models the data needed for sendtossgen.
type SendToSSGenCmd struct {
FromAccount string
TicketHash string
BlockHash string
Height int64
VoteBits uint16
Comment *string
}
// NewSendToSSGenCmd creates a new SendToSSGenCmd. Optionally a
// pointer to a TemplateRequest may be provided.
func NewSendToSSGenCmd(fromaccount string, tickethash string, blockhash string,
height int64, votebits uint16, comment *string) *SendToSSGenCmd {
return &SendToSSGenCmd{
FromAccount: fromaccount,
TicketHash: tickethash,
BlockHash: blockhash,
Height: height,
VoteBits: votebits,
Comment: comment,
}
}
// SendToSSRtxCmd is a type handling custom marshaling and
// unmarshaling of sendtossrtx JSON RPC commands.
type SendToSSRtxCmd struct {
FromAccount string
TicketHash string
Comment *string
}
// NewSendToSSRtxCmd creates a new SendToSSRtxCmd. Optionally a
// pointer to a TemplateRequest may be provided.
func NewSendToSSRtxCmd(fromaccount string, tickethash string,
comment *string) *SendToSSRtxCmd {
return &SendToSSRtxCmd{
FromAccount: fromaccount,
TicketHash: tickethash,
Comment: comment,
}
}
// SetBalanceToMaintainCmd is a type handling custom marshaling and
// unmarshaling of setbalancetomaintain JSON RPC commands.
type SetBalanceToMaintainCmd struct {
Balance float64
}
// NewSetBalanceToMaintainCmd creates a new instance of the setticketfee
// command.
func NewSetBalanceToMaintainCmd(balance float64) *SetBalanceToMaintainCmd {
return &SetBalanceToMaintainCmd{
Balance: balance,
}
}
// SetTicketFeeCmd is a type handling custom marshaling and
// unmarshaling of setticketfee JSON RPC commands.
type SetTicketFeeCmd struct {
Fee float64
}
// NewSetTicketFeeCmd creates a new instance of the setticketfee
// command.
func NewSetTicketFeeCmd(fee float64) *SetTicketFeeCmd {
return &SetTicketFeeCmd{
Fee: fee,
}
}
// SetTicketMaxPriceCmd is a type handling custom marshaling and
// unmarshaling of setticketmaxprice JSON RPC commands.
type SetTicketMaxPriceCmd struct {
Max float64
}
// NewSetTicketMaxPriceCmd creates a new instance of the setticketmaxprice
// command.
func NewSetTicketMaxPriceCmd(max float64) *SetTicketMaxPriceCmd {
return &SetTicketMaxPriceCmd{
Max: max,
}
}
// SetVoteChoiceCmd defines the parameters to the setvotechoice method.
type SetVoteChoiceCmd struct {
AgendaID string
ChoiceID string
}
// NewSetVoteChoiceCmd returns a new instance which can be used to issue a
// setvotechoice JSON-RPC command.
func NewSetVoteChoiceCmd(agendaID, choiceID string) *SetVoteChoiceCmd {
return &SetVoteChoiceCmd{AgendaID: agendaID, ChoiceID: choiceID}
}
// SignRawTransactionsCmd defines the signrawtransactions JSON-RPC command.
type SignRawTransactionsCmd struct {
RawTxs []string
Send *bool `jsonrpcdefault:"true"`
}
// NewSignRawTransactionsCmd returns a new instance which can be used to issue a
// signrawtransactions JSON-RPC command.
func NewSignRawTransactionsCmd(hexEncodedTxs []string,
send *bool) *SignRawTransactionsCmd {
return &SignRawTransactionsCmd{
RawTxs: hexEncodedTxs,
Send: send,
}
}
// StakePoolUserInfoCmd defines the stakepooluserinfo JSON-RPC command.
type StakePoolUserInfoCmd struct {
User string
}
// NewStakePoolUserInfoCmd returns a new instance which can be used to issue a
// signrawtransactions JSON-RPC command.
func NewStakePoolUserInfoCmd(user string) *StakePoolUserInfoCmd {
return &StakePoolUserInfoCmd{
User: user,
}
}
// WalletInfoCmd defines the walletinfo JSON-RPC command.
type WalletInfoCmd struct {
}
// NewWalletInfoCmd returns a new instance which can be used to issue a
// walletinfo JSON-RPC command.
func NewWalletInfoCmd() *WalletInfoCmd {
return &WalletInfoCmd{}
}
// SweepAccountCmd defines the sweep account JSON-RPC command.
type SweepAccountCmd struct {
SourceAccount string
DestinationAddress string
RequiredConfirmations *uint32
FeePerKb *float64
}
// NewSweepAccountCmd returns a new instance which can be used to issue a JSON-RPC SweepAccountCmd command.
func NewSweepAccountCmd(sourceAccount string, destinationAddress string, requiredConfs *uint32, feePerKb *float64) *SweepAccountCmd {
return &SweepAccountCmd{
SourceAccount: sourceAccount,
DestinationAddress: destinationAddress,
RequiredConfirmations: requiredConfs,
FeePerKb: feePerKb,
}
}
func init() {
// The commands in this file are only usable with a wallet
// server.
flags := UFWalletOnly
MustRegisterCmd("accountaddressindex", (*AccountAddressIndexCmd)(nil), flags)
MustRegisterCmd("accountsyncaddressindex", (*AccountSyncAddressIndexCmd)(nil), flags)
MustRegisterCmd("addticket", (*AddTicketCmd)(nil), flags)
MustRegisterCmd("consolidate", (*ConsolidateCmd)(nil), flags)
MustRegisterCmd("createrawsstx", (*CreateRawSStxCmd)(nil), flags)
MustRegisterCmd("createrawssgentx", (*CreateRawSSGenTxCmd)(nil), flags)
MustRegisterCmd("createrawssrtx", (*CreateRawSSRtxCmd)(nil), flags)
MustRegisterCmd("generatevote", (*GenerateVoteCmd)(nil), flags)
MustRegisterCmd("getmultisigoutinfo", (*GetMultisigOutInfoCmd)(nil), flags)
MustRegisterCmd("getmasterpubkey", (*GetMasterPubkeyCmd)(nil), flags)
MustRegisterCmd("getstakeinfo", (*GetStakeInfoCmd)(nil), flags)
MustRegisterCmd("getticketfee", (*GetTicketFeeCmd)(nil), flags)
MustRegisterCmd("gettickets", (*GetTicketsCmd)(nil), flags)
MustRegisterCmd("getvotechoices", (*GetVoteChoicesCmd)(nil), flags)
MustRegisterCmd("importscript", (*ImportScriptCmd)(nil), flags)
MustRegisterCmd("createvotingaccount", (*CreateVotingAccountCmd)(nil), flags)
MustRegisterCmd("dropvotingaccount", (*DropVotingAccountCmd)(nil), flags)
MustRegisterCmd("listscripts", (*ListScriptsCmd)(nil), flags)
MustRegisterCmd("purchaseticket", (*PurchaseTicketCmd)(nil), flags)
MustRegisterCmd("redeemmultisigout", (*RedeemMultiSigOutCmd)(nil), flags)
MustRegisterCmd("redeemmultisigouts", (*RedeemMultiSigOutsCmd)(nil), flags)
MustRegisterCmd("rescanwallet", (*RescanWalletCmd)(nil), flags)
MustRegisterCmd("revoketickets", (*RevokeTicketsCmd)(nil), flags)
MustRegisterCmd("sendtomultisig", (*SendToMultiSigCmd)(nil), flags)
MustRegisterCmd("sendtosstx", (*SendToSStxCmd)(nil), flags)
MustRegisterCmd("sendtossgen", (*SendToSSGenCmd)(nil), flags)
MustRegisterCmd("sendtossrtx", (*SendToSSRtxCmd)(nil), flags)
MustRegisterCmd("setbalancetomaintain", (*SetBalanceToMaintainCmd)(nil), flags)
MustRegisterCmd("setticketfee", (*SetTicketFeeCmd)(nil), flags)
MustRegisterCmd("setticketmaxprice", (*SetTicketMaxPriceCmd)(nil), flags)
MustRegisterCmd("setvotechoice", (*SetVoteChoiceCmd)(nil), flags)
MustRegisterCmd("signrawtransactions", (*SignRawTransactionsCmd)(nil), flags)
MustRegisterCmd("stakepooluserinfo", (*StakePoolUserInfoCmd)(nil), flags)
MustRegisterCmd("startautobuyer", (*StartAutoBuyerCmd)(nil), flags)
MustRegisterCmd("stopautobuyer", (*StopAutoBuyerCmd)(nil), flags)
MustRegisterCmd("sweepaccount", (*SweepAccountCmd)(nil), flags)
MustRegisterCmd("walletinfo", (*WalletInfoCmd)(nil), flags)
}

View File

@ -1,131 +0,0 @@
// Copyright (c) 2015-2016 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package dcrjson_test
import (
"bytes"
"encoding/json"
"fmt"
"reflect"
"testing"
"github.com/decred/dcrd/dcrjson"
)
// TestDcrWalletExtCmds 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 TestDcrWalletExtCmds(t *testing.T) {
t.Parallel()
testID := int(1)
tests := []struct {
name string
newCmd func() (interface{}, error)
staticCmd func() interface{}
marshalled string
unmarshalled interface{}
}{
{
name: "sweepaccount - optionals provided",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("sweepaccount", "default", "DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu", 6, 0.05)
},
staticCmd: func() interface{} {
return dcrjson.NewSweepAccountCmd("default", "DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu",
func(i uint32) *uint32 { return &i }(6),
func(i float64) *float64 { return &i }(0.05))
},
marshalled: `{"jsonrpc":"1.0","method":"sweepaccount","params":["default","DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu",6,0.05],"id":1}`,
unmarshalled: &dcrjson.SweepAccountCmd{
SourceAccount: "default",
DestinationAddress: "DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu",
RequiredConfirmations: func(i uint32) *uint32 { return &i }(6),
FeePerKb: func(i float64) *float64 { return &i }(0.05),
},
},
{
name: "sweepaccount - optionals omitted",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("sweepaccount", "default", "DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu")
},
staticCmd: func() interface{} {
return dcrjson.NewSweepAccountCmd("default", "DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu", nil, nil)
},
marshalled: `{"jsonrpc":"1.0","method":"sweepaccount","params":["default","DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu"],"id":1}`,
unmarshalled: &dcrjson.SweepAccountCmd{
SourceAccount: "default",
DestinationAddress: "DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu",
},
},
}
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 := dcrjson.MarshalCmd("1.0", 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 = dcrjson.MarshalCmd("1.0", 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 dcrjson.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 = dcrjson.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
}
}
}

View File

@ -1,152 +0,0 @@
// Copyright (c) 2015 The btcsuite developers
// Copyright (c) 2015-2016 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package dcrjson
// GetMultisigOutInfoResult models the data returned from the getmultisigoutinfo
// command.
type GetMultisigOutInfoResult struct {
Address string `json:"address"`
RedeemScript string `json:"redeemscript"`
M uint8 `json:"m"`
N uint8 `json:"n"`
Pubkeys []string `json:"pubkeys"`
TxHash string `json:"txhash"`
BlockHeight uint32 `json:"blockheight"`
BlockHash string `json:"blockhash"`
Spent bool `json:"spent"`
SpentBy string `json:"spentby"`
SpentByIndex uint32 `json:"spentbyindex"`
Amount float64 `json:"amount"`
}
// GetStakeInfoResult models the data returned from the getstakeinfo
// command.
type GetStakeInfoResult struct {
BlockHeight int64 `json:"blockheight"`
PoolSize uint32 `json:"poolsize"`
Difficulty float64 `json:"difficulty"`
AllMempoolTix uint32 `json:"allmempooltix"`
OwnMempoolTix uint32 `json:"ownmempooltix"`
Immature uint32 `json:"immature"`
Live uint32 `json:"live"`
ProportionLive float64 `json:"proportionlive"`
Voted uint32 `json:"voted"`
TotalSubsidy float64 `json:"totalsubsidy"`
Missed uint32 `json:"missed"`
ProportionMissed float64 `json:"proportionmissed"`
Revoked uint32 `json:"revoked"`
Expired uint32 `json:"expired"`
}
// GetTicketsResult models the data returned from the gettickets
// command.
type GetTicketsResult struct {
Hashes []string `json:"hashes"`
}
// VoteChoice models the data for a vote choice in the getvotechoices result.
type VoteChoice struct {
AgendaID string `json:"agendaid"`
AgendaDescription string `json:"agendadescription"`
ChoiceID string `json:"choiceid"`
ChoiceDescription string `json:"choicedescription"`
}
// GetVoteChoicesResult models the data returned by the getvotechoices command.
type GetVoteChoicesResult struct {
Version uint32 `json:"version"`
Choices []VoteChoice `json:"choices"`
}
// ScriptInfo is the structure representing a redeem script, its hash,
// and its address.
type ScriptInfo struct {
Hash160 string `json:"hash160"`
Address string `json:"address"`
RedeemScript string `json:"redeemscript"`
}
// ListScriptsResult models the data returned from the listscripts
// command.
type ListScriptsResult struct {
Scripts []ScriptInfo `json:"scripts"`
}
// RedeemMultiSigOutResult models the data returned from the redeemmultisigout
// command.
type RedeemMultiSigOutResult struct {
Hex string `json:"hex"`
Complete bool `json:"complete"`
Errors []SignRawTransactionError `json:"errors,omitempty"`
}
// RedeemMultiSigOutsResult models the data returned from the redeemmultisigouts
// command.
type RedeemMultiSigOutsResult struct {
Results []RedeemMultiSigOutResult `json:"results"`
}
// SendToMultiSigResult models the data returned from the sendtomultisig
// command.
type SendToMultiSigResult struct {
TxHash string `json:"txhash"`
Address string `json:"address"`
RedeemScript string `json:"redeemscript"`
}
// SignedTransaction is a signed transaction resulting from a signrawtransactions
// command.
type SignedTransaction struct {
SigningResult SignRawTransactionResult `json:"signingresult"`
Sent bool `json:"sent"`
TxHash *string `json:"txhash,omitempty"`
}
// SignRawTransactionsResult models the data returned from the signrawtransactions
// command.
type SignRawTransactionsResult struct {
Results []SignedTransaction `json:"results"`
}
// PoolUserTicket is the JSON struct corresponding to a stake pool user ticket
// object.
type PoolUserTicket struct {
Status string `json:"status"`
Ticket string `json:"ticket"`
TicketHeight uint32 `json:"ticketheight"`
SpentBy string `json:"spentby"`
SpentByHeight uint32 `json:"spentbyheight"`
}
// StakePoolUserInfoResult models the data returned from the stakepooluserinfo
// command.
type StakePoolUserInfoResult struct {
Tickets []PoolUserTicket `json:"tickets"`
InvalidTickets []string `json:"invalid"`
}
// WalletInfoResult models the data returned from the walletinfo
// command.
type WalletInfoResult struct {
DaemonConnected bool `json:"daemonconnected"`
Unlocked bool `json:"unlocked"`
TxFee float64 `json:"txfee"`
TicketFee float64 `json:"ticketfee"`
TicketPurchasing bool `json:"ticketpurchasing"`
VoteBits uint16 `json:"votebits"`
VoteBitsExtended string `json:"votebitsextended"`
VoteVersion uint32 `json:"voteversion"`
Voting bool `json:"voting"`
}
// SweepAccountResult models the data returned from the sweepaccount
// command.
type SweepAccountResult struct {
UnsignedTransaction string `json:"unsignedtransaction"`
TotalPreviousOutputAmount float64 `json:"totalpreviousoutputamount"`
TotalOutputAmount float64 `json:"totaloutputamount"`
EstimatedSignedSize uint32 `json:"estimatedsignedsize"`
}

View File

@ -1,175 +0,0 @@
// Copyright (c) 2015-2016 The Decred 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 chain server.
package dcrjson
const (
// TicketPurchasedNtfnMethod is the method of the dcrwallet
// ticketpurchased notification.
TicketPurchasedNtfnMethod = "ticketpurchased"
// VoteCreatedNtfnMethod is the method of the dcrwallet
// votecreated notification.
VoteCreatedNtfnMethod = "votecreated"
// RevocationCreatedNtfnMethod is the method of the dcrwallet
// revocationcreated notification.
RevocationCreatedNtfnMethod = "revocationcreated"
// WinningTicketsNtfnMethod is the method of the daemon
// winningtickets notification.
WinningTicketsNtfnMethod = "winningtickets"
// SpentAndMissedTicketsNtfnMethod is the method of the daemon
// spentandmissedtickets notification.
SpentAndMissedTicketsNtfnMethod = "spentandmissedtickets"
// NewTicketsNtfnMethod is the method of the daemon
// newtickets notification.
NewTicketsNtfnMethod = "newtickets"
// StakeDifficultyNtfnMethod is the method of the daemon
// stakedifficulty notification.
StakeDifficultyNtfnMethod = "stakedifficulty"
)
// TicketPurchasedNtfn is a type handling custom marshaling and
// unmarshaling of ticketpurchased JSON websocket notifications.
type TicketPurchasedNtfn struct {
TxHash string
Amount int64 // SStx only
}
// NewTicketPurchasedNtfn creates a new TicketPurchasedNtfn.
func NewTicketPurchasedNtfn(txHash string, amount int64) *TicketPurchasedNtfn {
return &TicketPurchasedNtfn{
TxHash: txHash,
Amount: amount,
}
}
// VoteCreatedNtfn is a type handling custom marshaling and
// unmarshaling of ticketpurchased JSON websocket notifications.
type VoteCreatedNtfn struct {
TxHash string
BlockHash string
Height int32
SStxIn string
VoteBits uint16
}
// NewVoteCreatedNtfn creates a new VoteCreatedNtfn.
func NewVoteCreatedNtfn(txHash string, blockHash string, height int32, sstxIn string, voteBits uint16) *VoteCreatedNtfn {
return &VoteCreatedNtfn{
TxHash: txHash,
BlockHash: blockHash,
Height: height,
SStxIn: sstxIn,
VoteBits: voteBits,
}
}
// RevocationCreatedNtfn is a type handling custom marshaling and
// unmarshaling of ticketpurchased JSON websocket notifications.
type RevocationCreatedNtfn struct {
TxHash string
SStxIn string
}
// NewRevocationCreatedNtfn creates a new RevocationCreatedNtfn.
func NewRevocationCreatedNtfn(txHash string, sstxIn string) *RevocationCreatedNtfn {
return &RevocationCreatedNtfn{
TxHash: txHash,
SStxIn: sstxIn,
}
}
// WinningTicketsNtfn is a type handling custom marshaling and
// unmarshaling of blockconnected JSON websocket notifications.
type WinningTicketsNtfn struct {
BlockHash string
BlockHeight int32
Tickets map[string]string
}
// NewWinningTicketsNtfn creates a new WinningTicketsNtfn.
func NewWinningTicketsNtfn(hash string, height int32, tickets map[string]string) *WinningTicketsNtfn {
return &WinningTicketsNtfn{
BlockHash: hash,
BlockHeight: height,
Tickets: tickets,
}
}
// SpentAndMissedTicketsNtfn is a type handling custom marshaling and
// unmarshaling of spentandmissedtickets JSON websocket notifications.
type SpentAndMissedTicketsNtfn struct {
Hash string
Height int32
StakeDiff int64
Tickets map[string]string
}
// NewSpentAndMissedTicketsNtfn creates a new SpentAndMissedTicketsNtfn.
func NewSpentAndMissedTicketsNtfn(hash string, height int32, stakeDiff int64, tickets map[string]string) *SpentAndMissedTicketsNtfn {
return &SpentAndMissedTicketsNtfn{
Hash: hash,
Height: height,
StakeDiff: stakeDiff,
Tickets: tickets,
}
}
// NewTicketsNtfn is a type handling custom marshaling and
// unmarshaling of newtickets JSON websocket notifications.
type NewTicketsNtfn struct {
Hash string
Height int32
StakeDiff int64
Tickets []string
}
// NewNewTicketsNtfn creates a new NewTicketsNtfn.
func NewNewTicketsNtfn(hash string, height int32, stakeDiff int64, tickets []string) *NewTicketsNtfn {
return &NewTicketsNtfn{
Hash: hash,
Height: height,
StakeDiff: stakeDiff,
Tickets: tickets,
}
}
// StakeDifficultyNtfn is a type handling custom marshaling and
// unmarshaling of stakedifficulty JSON websocket notifications.
type StakeDifficultyNtfn struct {
BlockHash string
BlockHeight int32
StakeDiff int64
}
// NewStakeDifficultyNtfn creates a new StakeDifficultyNtfn.
func NewStakeDifficultyNtfn(hash string, height int32, stakeDiff int64) *StakeDifficultyNtfn {
return &StakeDifficultyNtfn{
BlockHash: hash,
BlockHeight: height,
StakeDiff: stakeDiff,
}
}
func init() {
// The commands in this file are only usable by websockets and are
// notifications.
flags := UFWalletOnly | UFWebsocketOnly | UFNotification
MustRegisterCmd(TicketPurchasedNtfnMethod, (*TicketPurchasedNtfn)(nil), flags)
MustRegisterCmd(VoteCreatedNtfnMethod, (*VoteCreatedNtfn)(nil), flags)
MustRegisterCmd(RevocationCreatedNtfnMethod, (*RevocationCreatedNtfn)(nil), flags)
MustRegisterCmd(WinningTicketsNtfnMethod, (*WinningTicketsNtfn)(nil), flags)
MustRegisterCmd(SpentAndMissedTicketsNtfnMethod, (*SpentAndMissedTicketsNtfn)(nil), flags)
MustRegisterCmd(NewTicketsNtfnMethod, (*NewTicketsNtfn)(nil), flags)
MustRegisterCmd(StakeDifficultyNtfnMethod, (*StakeDifficultyNtfn)(nil), flags)
}

View File

@ -1,191 +0,0 @@
// Copyright (c) 2015-2016 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package dcrjson_test
import (
"bytes"
"encoding/json"
"fmt"
"reflect"
"testing"
"github.com/decred/dcrd/dcrjson"
)
// TestChainSvrWsNtfns tests all of the chain 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 TestDcrwalletChainSvrWsNtfns(t *testing.T) {
t.Parallel()
tests := []struct {
name string
newNtfn func() (interface{}, error)
staticNtfn func() interface{}
marshalled string
unmarshalled interface{}
}{
{
name: "ticketpurchase",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("ticketpurchased", "123", 5)
},
staticNtfn: func() interface{} {
return dcrjson.NewTicketPurchasedNtfn("123", 5)
},
marshalled: `{"jsonrpc":"1.0","method":"ticketpurchased","params":["123",5],"id":null}`,
unmarshalled: &dcrjson.TicketPurchasedNtfn{
TxHash: "123",
Amount: 5,
},
},
{
name: "votecreated",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("votecreated", "123", "1234", 100, "12345", 1)
},
staticNtfn: func() interface{} {
return dcrjson.NewVoteCreatedNtfn("123", "1234", 100, "12345", 1)
},
marshalled: `{"jsonrpc":"1.0","method":"votecreated","params":["123","1234",100,"12345",1],"id":null}`,
unmarshalled: &dcrjson.VoteCreatedNtfn{
TxHash: "123",
BlockHash: "1234",
Height: 100,
SStxIn: "12345",
VoteBits: 1,
},
},
{
name: "revocationcreated",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("revocationcreated", "123", "1234")
},
staticNtfn: func() interface{} {
return dcrjson.NewRevocationCreatedNtfn("123", "1234")
},
marshalled: `{"jsonrpc":"1.0","method":"revocationcreated","params":["123","1234"],"id":null}`,
unmarshalled: &dcrjson.RevocationCreatedNtfn{
TxHash: "123",
SStxIn: "1234",
},
},
{
name: "winningtickets",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("winningtickets", "123", 100, map[string]string{"a": "b"})
},
staticNtfn: func() interface{} {
return dcrjson.NewWinningTicketsNtfn("123", 100, map[string]string{"a": "b"})
},
marshalled: `{"jsonrpc":"1.0","method":"winningtickets","params":["123",100,{"a":"b"}],"id":null}`,
unmarshalled: &dcrjson.WinningTicketsNtfn{
BlockHash: "123",
BlockHeight: 100,
Tickets: map[string]string{"a": "b"},
},
},
{
name: "spentandmissedtickets",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("spentandmissedtickets", "123", 100, 3, map[string]string{"a": "b"})
},
staticNtfn: func() interface{} {
return dcrjson.NewSpentAndMissedTicketsNtfn("123", 100, 3, map[string]string{"a": "b"})
},
marshalled: `{"jsonrpc":"1.0","method":"spentandmissedtickets","params":["123",100,3,{"a":"b"}],"id":null}`,
unmarshalled: &dcrjson.SpentAndMissedTicketsNtfn{
Hash: "123",
Height: 100,
StakeDiff: 3,
Tickets: map[string]string{"a": "b"},
},
},
{
name: "newtickets",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("newtickets", "123", 100, 3, []string{"a", "b"})
},
staticNtfn: func() interface{} {
return dcrjson.NewNewTicketsNtfn("123", 100, 3, []string{"a", "b"})
},
marshalled: `{"jsonrpc":"1.0","method":"newtickets","params":["123",100,3,["a","b"]],"id":null}`,
unmarshalled: &dcrjson.NewTicketsNtfn{
Hash: "123",
Height: 100,
StakeDiff: 3,
Tickets: []string{"a", "b"},
},
},
}
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 := dcrjson.MarshalCmd("1.0", 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 = dcrjson.MarshalCmd("1.0", 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 dcrjson.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 = dcrjson.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
}
}
}

View File

@ -8,6 +8,41 @@
package dcrjson
// AccountAddressIndexCmd is a type handling custom marshaling and
// unmarshaling of accountaddressindex JSON wallet extension
// commands.
type AccountAddressIndexCmd struct {
Account string `json:"account"`
Branch int `json:"branch"`
}
// NewAccountAddressIndexCmd creates a new AccountAddressIndexCmd.
func NewAccountAddressIndexCmd(acct string, branch int) *AccountAddressIndexCmd {
return &AccountAddressIndexCmd{
Account: acct,
Branch: branch,
}
}
// AccountSyncAddressIndexCmd is a type handling custom marshaling and
// unmarshaling of accountsyncaddressindex JSON wallet extension
// commands.
type AccountSyncAddressIndexCmd struct {
Account string `json:"account"`
Branch int `json:"branch"`
Index int `json:"index"`
}
// NewAccountSyncAddressIndexCmd creates a new AccountSyncAddressIndexCmd.
func NewAccountSyncAddressIndexCmd(acct string, branch int,
idx int) *AccountSyncAddressIndexCmd {
return &AccountSyncAddressIndexCmd{
Account: acct,
Branch: branch,
Index: idx,
}
}
// AddMultisigAddressCmd defines the addmutisigaddress JSON-RPC command.
type AddMultisigAddressCmd struct {
NRequired int
@ -28,6 +63,39 @@ func NewAddMultisigAddressCmd(nRequired int, keys []string, account *string) *Ad
}
}
// AddTicketCmd forces a ticket into the wallet stake manager, for example if
// someone made an invalid ticket for a stake pool and the pool manager wanted
// to manually add it.
type AddTicketCmd struct {
TicketHex string `json:"tickethex"`
}
// NewAddTicketCmd creates a new AddTicketCmd.
func NewAddTicketCmd(ticketHex string) *AddTicketCmd {
return &AddTicketCmd{TicketHex: ticketHex}
}
// ConsolidateCmd is a type handling custom marshaling and
// unmarshaling of consolidate JSON wallet extension
// commands.
type ConsolidateCmd struct {
Inputs int `json:"inputs"`
Account *string
Address *string
}
// CreateMultiSigResult models the data returned from the createmultisig
// command.
type CreateMultiSigResult struct {
Address string `json:"address"`
RedeemScript string `json:"redeemScript"`
}
// NewConsolidateCmd creates a new ConsolidateCmd.
func NewConsolidateCmd(inputs int, acct *string, addr *string) *ConsolidateCmd {
return &ConsolidateCmd{Inputs: inputs, Account: acct, Address: addr}
}
// CreateMultisigCmd defines the createmultisig JSON-RPC command.
type CreateMultisigCmd struct {
NRequired int
@ -43,6 +111,109 @@ func NewCreateMultisigCmd(nRequired int, keys []string) *CreateMultisigCmd {
}
}
// 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,
}
}
// SStxInput represents the inputs to an SStx transaction. Specifically a
// transactionsha and output number pair, along with the output amounts.
type SStxInput struct {
Txid string `json:"txid"`
Vout uint32 `json:"vout"`
Tree int8 `json:"tree"`
Amt int64 `json:"amt"`
}
// SStxCommitOut represents the output to an SStx transaction. Specifically a
// a commitment address and amount, and a change address and amount.
type SStxCommitOut struct {
Addr string `json:"addr"`
CommitAmt int64 `json:"commitamt"`
ChangeAddr string `json:"changeaddr"`
ChangeAmt int64 `json:"changeamt"`
}
// CreateRawSStxCmd is a type handling custom marshaling and
// unmarshaling of createrawsstx JSON RPC commands.
type CreateRawSStxCmd struct {
Inputs []SStxInput
Amount map[string]int64
COuts []SStxCommitOut
}
// NewCreateRawSStxCmd creates a new CreateRawSStxCmd.
func NewCreateRawSStxCmd(inputs []SStxInput, amount map[string]int64,
couts []SStxCommitOut) *CreateRawSStxCmd {
return &CreateRawSStxCmd{
Inputs: inputs,
Amount: amount,
COuts: couts,
}
}
// CreateRawSSGenTxCmd is a type handling custom marshaling and
// unmarshaling of createrawssgentxcmd JSON RPC commands.
type CreateRawSSGenTxCmd struct {
Inputs []TransactionInput
VoteBits uint16
}
// NewCreateRawSSGenTxCmd creates a new CreateRawSSGenTxCmd.
func NewCreateRawSSGenTxCmd(inputs []TransactionInput,
vb uint16) *CreateRawSSGenTxCmd {
return &CreateRawSSGenTxCmd{
Inputs: inputs,
VoteBits: vb,
}
}
// CreateRawSSRtxCmd is a type handling custom marshaling and
// unmarshaling of createrawssrtx JSON RPC commands.
type CreateRawSSRtxCmd struct {
Inputs []TransactionInput
Fee *float64
}
// NewCreateRawSSRtxCmd creates a new CreateRawSSRtxCmd.
func NewCreateRawSSRtxCmd(inputs []TransactionInput, fee *float64) *CreateRawSSRtxCmd {
return &CreateRawSSRtxCmd{
Inputs: inputs,
Fee: fee,
}
}
// CreateVotingAccountCmd is a type for handling custom marshaling and
// unmarshalling of createvotingaccount JSON-RPC command.
type CreateVotingAccountCmd struct {
Name string
PubKey string
ChildIndex *uint32 `jsonrpcdefault:"0"`
}
// NewCreateVotingAccountCmd creates a new CreateVotingAccountCmd.
func NewCreateVotingAccountCmd(name, pubKey string, childIndex *uint32) *CreateVotingAccountCmd {
return &CreateVotingAccountCmd{name, pubKey, childIndex}
}
// DropVotingAccountCmd is a type for handling custom marshaling and
// unmarshalling of dropvotingaccount JSON-RPC command
type DropVotingAccountCmd struct {
}
// NewDropVotingAccountCmd creates a new DropVotingAccountCmd.
func NewDropVotingAccountCmd() *DropVotingAccountCmd {
return &DropVotingAccountCmd{}
}
// DumpPrivKeyCmd defines the dumpprivkey JSON-RPC command.
type DumpPrivKeyCmd struct {
Address string
@ -69,6 +240,27 @@ func NewEstimatePriorityCmd(numBlocks int64) *EstimatePriorityCmd {
}
}
// GenerateVoteCmd is a type handling custom marshaling and
// unmarshaling of generatevote JSON wallet extension commands.
type GenerateVoteCmd struct {
BlockHash string
Height int64
TicketHash string
VoteBits uint16
VoteBitsExt string
}
// NewGenerateVoteCmd creates a new GenerateVoteCmd.
func NewGenerateVoteCmd(blockhash string, height int64, tickethash string, votebits uint16, voteBitsExt string) *GenerateVoteCmd {
return &GenerateVoteCmd{
BlockHash: blockhash,
Height: height,
TicketHash: tickethash,
VoteBits: votebits,
VoteBitsExt: voteBitsExt,
}
}
// GetAccountCmd defines the getaccount JSON-RPC command.
type GetAccountCmd struct {
Address string
@ -126,6 +318,30 @@ func NewGetBalanceCmd(account *string, minConf *int) *GetBalanceCmd {
}
}
// GetMasterPubkeyCmd is a type handling custom marshaling and unmarshaling of
// getmasterpubkey JSON wallet extension commands.
type GetMasterPubkeyCmd struct {
Account *string
}
// NewGetMasterPubkeyCmd creates a new GetMasterPubkeyCmd.
func NewGetMasterPubkeyCmd(acct *string) *GetMasterPubkeyCmd {
return &GetMasterPubkeyCmd{Account: acct}
}
// GetMultisigOutInfoCmd is a type handling custom marshaling and
// unmarshaling of getmultisigoutinfo JSON websocket extension
// commands.
type GetMultisigOutInfoCmd struct {
Hash string
Index uint32
}
// NewGetMultisigOutInfoCmd creates a new GetMultisigOutInfoCmd.
func NewGetMultisigOutInfoCmd(hash string, index uint32) *GetMultisigOutInfoCmd {
return &GetMultisigOutInfoCmd{hash, index}
}
// GetNewAddressCmd defines the getnewaddress JSON-RPC command.
type GetNewAddressCmd struct {
Account *string
@ -196,6 +412,40 @@ func NewGetReceivedByAddressCmd(address string, minConf *int) *GetReceivedByAddr
}
}
// GetStakeInfoCmd is a type handling custom marshaling and
// unmarshaling of getstakeinfo JSON wallet extension commands.
type GetStakeInfoCmd struct {
}
// NewGetStakeInfoCmd creates a new GetStakeInfoCmd.
func NewGetStakeInfoCmd() *GetStakeInfoCmd {
return &GetStakeInfoCmd{}
}
// GetTicketFeeCmd is a type handling custom marshaling and
// unmarshaling of getticketfee JSON wallet extension
// commands.
type GetTicketFeeCmd struct {
}
// NewGetTicketFeeCmd creates a new GetTicketFeeCmd.
func NewGetTicketFeeCmd() *GetTicketFeeCmd {
return &GetTicketFeeCmd{}
}
// GetTicketsCmd is a type handling custom marshaling and
// unmarshaling of gettickets JSON wallet extension
// commands.
type GetTicketsCmd struct {
IncludeImmature bool
}
// NewGetTicketsCmd returns a new instance which can be used to issue a
// gettickets JSON-RPC command.
func NewGetTicketsCmd(includeImmature bool) *GetTicketsCmd {
return &GetTicketsCmd{includeImmature}
}
// GetTransactionCmd defines the gettransaction JSON-RPC command.
type GetTransactionCmd struct {
Txid string
@ -214,6 +464,42 @@ func NewGetTransactionCmd(txHash string, includeWatchOnly *bool) *GetTransaction
}
}
// GetVoteChoicesCmd returns a new instance which can be used to issue a
// getvotechoices JSON-RPC command.
type GetVoteChoicesCmd struct {
}
// NewGetVoteChoicesCmd returns a new instance which can be used to
// issue a JSON-RPC getvotechoices command.
func NewGetVoteChoicesCmd() *GetVoteChoicesCmd {
return &GetVoteChoicesCmd{}
}
// GetWalletFeeCmd defines the getwalletfee JSON-RPC command.
type GetWalletFeeCmd struct{}
// NewGetWalletFeeCmd returns a new instance which can be used to issue a
// getwalletfee JSON-RPC command.
//
func NewGetWalletFeeCmd() *GetWalletFeeCmd {
return &GetWalletFeeCmd{}
}
// 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,
}
}
// ImportPrivKeyCmd defines the importprivkey JSON-RPC command.
type ImportPrivKeyCmd struct {
PrivKey string
@ -236,6 +522,34 @@ func NewImportPrivKeyCmd(privKey string, label *string, rescan *bool, scanFrom *
}
}
// 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,
}
}
// ImportScriptCmd is a type for handling custom marshaling and
// unmarshaling of importscript JSON wallet extension commands.
type ImportScriptCmd struct {
Hex string
Rescan *bool `jsonrpcdefault:"true"`
ScanFrom *int
}
// NewImportScriptCmd creates a new GetImportScriptCmd.
func NewImportScriptCmd(hex string, rescan *bool, scanFrom *int) *ImportScriptCmd {
return &ImportScriptCmd{hex, rescan, scanFrom}
}
// KeyPoolRefillCmd defines the keypoolrefill JSON-RPC command.
type KeyPoolRefillCmd struct {
NewSize *uint `jsonrpcdefault:"100"`
@ -317,6 +631,17 @@ func NewListReceivedByAddressCmd(minConf *int, includeEmpty, includeWatchOnly *b
}
}
// ListScriptsCmd is a type for handling custom marshaling and
// unmarshaling of listscripts JSON wallet extension commands.
type ListScriptsCmd struct {
}
// NewListScriptsCmd returns a new instance which can be used to issue a
// listscripts JSON-RPC command.
func NewListScriptsCmd() *ListScriptsCmd {
return &ListScriptsCmd{}
}
// ListSinceBlockCmd defines the listsinceblock JSON-RPC command.
type ListSinceBlockCmd struct {
BlockHash *string
@ -394,6 +719,108 @@ func NewLockUnspentCmd(unlock bool, transactions []TransactionInput) *LockUnspen
}
}
// PurchaseTicketCmd is a type handling custom marshaling and
// unmarshaling of purchaseticket JSON RPC commands.
type PurchaseTicketCmd struct {
FromAccount string
SpendLimit float64 // In Coins
MinConf *int `jsonrpcdefault:"1"`
TicketAddress *string
NumTickets *int
PoolAddress *string
PoolFees *float64
Expiry *int
Comment *string
TicketChange *bool
TicketFee *float64
}
// NewPurchaseTicketCmd creates a new PurchaseTicketCmd.
func NewPurchaseTicketCmd(fromAccount string, spendLimit float64, minConf *int,
ticketAddress *string, numTickets *int, poolAddress *string, poolFees *float64,
expiry *int, comment *string, ticketChange *bool, ticketFee *float64) *PurchaseTicketCmd {
return &PurchaseTicketCmd{
FromAccount: fromAccount,
SpendLimit: spendLimit,
MinConf: minConf,
TicketAddress: ticketAddress,
NumTickets: numTickets,
PoolAddress: poolAddress,
PoolFees: poolFees,
Expiry: expiry,
Comment: comment,
TicketChange: ticketChange,
TicketFee: ticketFee,
}
}
// RedeemMultiSigOutCmd is a type handling custom marshaling and
// unmarshaling of redeemmultisigout JSON RPC commands.
type RedeemMultiSigOutCmd struct {
Hash string
Index uint32
Tree int8
Address *string
}
// NewRedeemMultiSigOutCmd creates a new RedeemMultiSigOutCmd.
func NewRedeemMultiSigOutCmd(hash string, index uint32, tree int8,
address *string) *RedeemMultiSigOutCmd {
return &RedeemMultiSigOutCmd{
Hash: hash,
Index: index,
Tree: tree,
Address: address,
}
}
// RedeemMultiSigOutsCmd is a type handling custom marshaling and
// unmarshaling of redeemmultisigout JSON RPC commands.
type RedeemMultiSigOutsCmd struct {
FromScrAddress string
ToAddress *string
Number *int
}
// NewRedeemMultiSigOutsCmd creates a new RedeemMultiSigOutsCmd.
func NewRedeemMultiSigOutsCmd(from string, to *string,
number *int) *RedeemMultiSigOutsCmd {
return &RedeemMultiSigOutsCmd{
FromScrAddress: from,
ToAddress: to,
Number: number,
}
}
// 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,
}
}
// RescanWalletCmd describes the rescanwallet JSON-RPC request and parameters.
type RescanWalletCmd struct {
BeginHeight *int `jsonrpcdefault:"0"`
}
// RevokeTicketsCmd describes the revoketickets JSON-RPC request and parameters.
type RevokeTicketsCmd struct {
}
// NewRevokeTicketsCmd creates a new RevokeTicketsCmd.
func NewRevokeTicketsCmd() *RevokeTicketsCmd {
return &RevokeTicketsCmd{}
}
// SendFromCmd defines the sendfrom JSON-RPC command.
type SendFromCmd struct {
FromAccount string
@ -464,6 +891,113 @@ func NewSendToAddressCmd(address string, amount float64, comment, commentTo *str
}
}
// SendToMultiSigCmd is a type handling custom marshaling and
// unmarshaling of sendtomultisig JSON RPC commands.
type SendToMultiSigCmd struct {
FromAccount string
Amount float64
Pubkeys []string
NRequired *int `jsonrpcdefault:"1"`
MinConf *int `jsonrpcdefault:"1"`
Comment *string
}
// NewSendToMultiSigCmd creates a new SendToMultiSigCmd.
func NewSendToMultiSigCmd(fromaccount string, amount float64, pubkeys []string,
nrequired *int, minConf *int, comment *string) *SendToMultiSigCmd {
return &SendToMultiSigCmd{
FromAccount: fromaccount,
Amount: amount,
Pubkeys: pubkeys,
NRequired: nrequired,
MinConf: minConf,
Comment: comment,
}
}
// SendToSStxCmd is a type handling custom marshaling and
// unmarshaling of sendtosstx JSON RPC commands.
type SendToSStxCmd struct {
FromAccount string
Amounts map[string]int64
Inputs []SStxInput
COuts []SStxCommitOut
MinConf *int `jsonrpcdefault:"1"`
Comment *string
}
// NewSendToSStxCmd creates a new SendToSStxCmd. Optionally a
// pointer to a TemplateRequest may be provided.
func NewSendToSStxCmd(fromaccount string, amounts map[string]int64,
inputs []SStxInput, couts []SStxCommitOut, minConf *int,
comment *string) *SendToSStxCmd {
return &SendToSStxCmd{
FromAccount: fromaccount,
Amounts: amounts,
Inputs: inputs,
COuts: couts,
MinConf: minConf,
Comment: comment,
}
}
// SendToSSGenCmd models the data needed for sendtossgen.
type SendToSSGenCmd struct {
FromAccount string
TicketHash string
BlockHash string
Height int64
VoteBits uint16
Comment *string
}
// NewSendToSSGenCmd creates a new SendToSSGenCmd. Optionally a
// pointer to a TemplateRequest may be provided.
func NewSendToSSGenCmd(fromaccount string, tickethash string, blockhash string,
height int64, votebits uint16, comment *string) *SendToSSGenCmd {
return &SendToSSGenCmd{
FromAccount: fromaccount,
TicketHash: tickethash,
BlockHash: blockhash,
Height: height,
VoteBits: votebits,
Comment: comment,
}
}
// SendToSSRtxCmd is a type handling custom marshaling and
// unmarshaling of sendtossrtx JSON RPC commands.
type SendToSSRtxCmd struct {
FromAccount string
TicketHash string
Comment *string
}
// NewSendToSSRtxCmd creates a new SendToSSRtxCmd. Optionally a
// pointer to a TemplateRequest may be provided.
func NewSendToSSRtxCmd(fromaccount string, tickethash string,
comment *string) *SendToSSRtxCmd {
return &SendToSSRtxCmd{
FromAccount: fromaccount,
TicketHash: tickethash,
Comment: comment,
}
}
// SetBalanceToMaintainCmd is a type handling custom marshaling and
// unmarshaling of setbalancetomaintain JSON RPC commands.
type SetBalanceToMaintainCmd struct {
Balance float64
}
// NewSetBalanceToMaintainCmd creates a new instance of the setticketfee
// command.
func NewSetBalanceToMaintainCmd(balance float64) *SetBalanceToMaintainCmd {
return &SetBalanceToMaintainCmd{
Balance: balance,
}
}
// SetTxFeeCmd defines the settxfee JSON-RPC command.
type SetTxFeeCmd struct {
Amount float64 // In DCR
@ -477,6 +1011,46 @@ func NewSetTxFeeCmd(amount float64) *SetTxFeeCmd {
}
}
// SetTicketFeeCmd is a type handling custom marshaling and
// unmarshaling of setticketfee JSON RPC commands.
type SetTicketFeeCmd struct {
Fee float64
}
// NewSetTicketFeeCmd creates a new instance of the setticketfee
// command.
func NewSetTicketFeeCmd(fee float64) *SetTicketFeeCmd {
return &SetTicketFeeCmd{
Fee: fee,
}
}
// SetTicketMaxPriceCmd is a type handling custom marshaling and
// unmarshaling of setticketmaxprice JSON RPC commands.
type SetTicketMaxPriceCmd struct {
Max float64
}
// NewSetTicketMaxPriceCmd creates a new instance of the setticketmaxprice
// command.
func NewSetTicketMaxPriceCmd(max float64) *SetTicketMaxPriceCmd {
return &SetTicketMaxPriceCmd{
Max: max,
}
}
// SetVoteChoiceCmd defines the parameters to the setvotechoice method.
type SetVoteChoiceCmd struct {
AgendaID string
ChoiceID string
}
// NewSetVoteChoiceCmd returns a new instance which can be used to issue a
// setvotechoice JSON-RPC command.
func NewSetVoteChoiceCmd(agendaID, choiceID string) *SetVoteChoiceCmd {
return &SetVoteChoiceCmd{AgendaID: agendaID, ChoiceID: choiceID}
}
// SignMessageCmd defines the signmessage JSON-RPC command.
type SignMessageCmd struct {
Address string
@ -524,6 +1098,95 @@ func NewSignRawTransactionCmd(hexEncodedTx string, inputs *[]RawTxInput, privKey
}
}
// SignRawTransactionsCmd defines the signrawtransactions JSON-RPC command.
type SignRawTransactionsCmd struct {
RawTxs []string
Send *bool `jsonrpcdefault:"true"`
}
// NewSignRawTransactionsCmd returns a new instance which can be used to issue a
// signrawtransactions JSON-RPC command.
func NewSignRawTransactionsCmd(hexEncodedTxs []string,
send *bool) *SignRawTransactionsCmd {
return &SignRawTransactionsCmd{
RawTxs: hexEncodedTxs,
Send: send,
}
}
// StakePoolUserInfoCmd defines the stakepooluserinfo JSON-RPC command.
type StakePoolUserInfoCmd struct {
User string
}
// NewStakePoolUserInfoCmd returns a new instance which can be used to issue a
// signrawtransactions JSON-RPC command.
func NewStakePoolUserInfoCmd(user string) *StakePoolUserInfoCmd {
return &StakePoolUserInfoCmd{
User: user,
}
}
// StartAutoBuyerCmd is a type handling custom marshaling and
// unmarshaling of startautobuyer JSON RPC commands.
type StartAutoBuyerCmd struct {
Account string
Passphrase string
BalanceToMaintain *int64
MaxFeePerKb *int64
MaxPriceRelative *float64
MaxPriceAbsolute *int64
VotingAddress *string
PoolAddress *string
PoolFees *float64
MaxPerBlock *int64
}
// NewStartAutoBuyerCmd creates a new StartAutoBuyerCmd.
func NewStartAutoBuyerCmd(account string, passphrase string, balanceToMaintain *int64, maxFeePerKb *int64, maxPriceRelative *float64, maxPriceAbsolute *int64, votingAddress *string, poolAddress *string, poolFees *float64,
maxPerBlock *int64) *StartAutoBuyerCmd {
return &StartAutoBuyerCmd{
Account: account,
Passphrase: passphrase,
BalanceToMaintain: balanceToMaintain,
MaxFeePerKb: maxFeePerKb,
MaxPriceRelative: maxPriceRelative,
MaxPriceAbsolute: maxPriceAbsolute,
VotingAddress: votingAddress,
PoolAddress: poolAddress,
PoolFees: poolFees,
MaxPerBlock: maxPerBlock,
}
}
// StopAutoBuyerCmd is a type handling custom marshaling and
// unmarshaling of stopautobuyer JSON RPC commands.
type StopAutoBuyerCmd struct {
}
// NewStopAutoBuyerCmd creates a new StopAutoBuyerCmd.
func NewStopAutoBuyerCmd() *StopAutoBuyerCmd {
return &StopAutoBuyerCmd{}
}
// SweepAccountCmd defines the sweep account JSON-RPC command.
type SweepAccountCmd struct {
SourceAccount string
DestinationAddress string
RequiredConfirmations *uint32
FeePerKb *float64
}
// NewSweepAccountCmd returns a new instance which can be used to issue a JSON-RPC SweepAccountCmd command.
func NewSweepAccountCmd(sourceAccount string, destinationAddress string, requiredConfs *uint32, feePerKb *float64) *SweepAccountCmd {
return &SweepAccountCmd{
SourceAccount: sourceAccount,
DestinationAddress: destinationAddress,
RequiredConfirmations: requiredConfs,
FeePerKb: feePerKb,
}
}
// VerifySeedCmd defines the verifyseed JSON-RPC command.
type VerifySeedCmd struct {
Seed string
@ -542,6 +1205,16 @@ func NewVerifySeedCmd(seed string, account *uint32) *VerifySeedCmd {
}
}
// WalletInfoCmd defines the walletinfo JSON-RPC command.
type WalletInfoCmd struct {
}
// NewWalletInfoCmd returns a new instance which can be used to issue a
// walletinfo JSON-RPC command.
func NewWalletInfoCmd() *WalletInfoCmd {
return &WalletInfoCmd{}
}
// WalletLockCmd defines the walletlock JSON-RPC command.
type WalletLockCmd struct{}
@ -585,37 +1258,78 @@ func init() {
// The commands in this file are only usable with a wallet server.
flags := UFWalletOnly
MustRegisterCmd("accountaddressindex", (*AccountAddressIndexCmd)(nil), flags)
MustRegisterCmd("accountsyncaddressindex", (*AccountSyncAddressIndexCmd)(nil), flags)
MustRegisterCmd("addmultisigaddress", (*AddMultisigAddressCmd)(nil), flags)
MustRegisterCmd("addticket", (*AddTicketCmd)(nil), flags)
MustRegisterCmd("consolidate", (*ConsolidateCmd)(nil), flags)
MustRegisterCmd("createmultisig", (*CreateMultisigCmd)(nil), flags)
MustRegisterCmd("createnewaccount", (*CreateNewAccountCmd)(nil), flags)
MustRegisterCmd("createrawsstx", (*CreateRawSStxCmd)(nil), flags)
MustRegisterCmd("createrawssgentx", (*CreateRawSSGenTxCmd)(nil), flags)
MustRegisterCmd("createrawssrtx", (*CreateRawSSRtxCmd)(nil), flags)
MustRegisterCmd("createvotingaccount", (*CreateVotingAccountCmd)(nil), flags)
MustRegisterCmd("dropvotingaccount", (*DropVotingAccountCmd)(nil), flags)
MustRegisterCmd("dumpprivkey", (*DumpPrivKeyCmd)(nil), flags)
MustRegisterCmd("estimatepriority", (*EstimatePriorityCmd)(nil), flags)
MustRegisterCmd("generatevote", (*GenerateVoteCmd)(nil), flags)
MustRegisterCmd("getaccount", (*GetAccountCmd)(nil), flags)
MustRegisterCmd("getaccountaddress", (*GetAccountAddressCmd)(nil), flags)
MustRegisterCmd("getaddressesbyaccount", (*GetAddressesByAccountCmd)(nil), flags)
MustRegisterCmd("getbalance", (*GetBalanceCmd)(nil), flags)
MustRegisterCmd("getmasterpubkey", (*GetMasterPubkeyCmd)(nil), flags)
MustRegisterCmd("getmultisigoutinfo", (*GetMultisigOutInfoCmd)(nil), flags)
MustRegisterCmd("getnewaddress", (*GetNewAddressCmd)(nil), flags)
MustRegisterCmd("getrawchangeaddress", (*GetRawChangeAddressCmd)(nil), flags)
MustRegisterCmd("getreceivedbyaccount", (*GetReceivedByAccountCmd)(nil), flags)
MustRegisterCmd("getreceivedbyaddress", (*GetReceivedByAddressCmd)(nil), flags)
MustRegisterCmd("getstakeinfo", (*GetStakeInfoCmd)(nil), flags)
MustRegisterCmd("getticketfee", (*GetTicketFeeCmd)(nil), flags)
MustRegisterCmd("gettickets", (*GetTicketsCmd)(nil), flags)
MustRegisterCmd("gettransaction", (*GetTransactionCmd)(nil), flags)
MustRegisterCmd("getvotechoices", (*GetVoteChoicesCmd)(nil), flags)
MustRegisterCmd("getwalletfee", (*GetWalletFeeCmd)(nil), flags)
MustRegisterCmd("importaddress", (*ImportAddressCmd)(nil), flags)
MustRegisterCmd("importprivkey", (*ImportPrivKeyCmd)(nil), flags)
MustRegisterCmd("importpubkey", (*ImportPubKeyCmd)(nil), flags)
MustRegisterCmd("importscript", (*ImportScriptCmd)(nil), flags)
MustRegisterCmd("keypoolrefill", (*KeyPoolRefillCmd)(nil), flags)
MustRegisterCmd("listaccounts", (*ListAccountsCmd)(nil), flags)
MustRegisterCmd("listlockunspent", (*ListLockUnspentCmd)(nil), flags)
MustRegisterCmd("listreceivedbyaccount", (*ListReceivedByAccountCmd)(nil), flags)
MustRegisterCmd("listreceivedbyaddress", (*ListReceivedByAddressCmd)(nil), flags)
MustRegisterCmd("listscripts", (*ListScriptsCmd)(nil), flags)
MustRegisterCmd("listsinceblock", (*ListSinceBlockCmd)(nil), flags)
MustRegisterCmd("listtransactions", (*ListTransactionsCmd)(nil), flags)
MustRegisterCmd("listunspent", (*ListUnspentCmd)(nil), flags)
MustRegisterCmd("lockunspent", (*LockUnspentCmd)(nil), flags)
MustRegisterCmd("purchaseticket", (*PurchaseTicketCmd)(nil), flags)
MustRegisterCmd("redeemmultisigout", (*RedeemMultiSigOutCmd)(nil), flags)
MustRegisterCmd("redeemmultisigouts", (*RedeemMultiSigOutsCmd)(nil), flags)
MustRegisterCmd("renameaccount", (*RenameAccountCmd)(nil), flags)
MustRegisterCmd("rescanwallet", (*RescanWalletCmd)(nil), flags)
MustRegisterCmd("revoketickets", (*RevokeTicketsCmd)(nil), flags)
MustRegisterCmd("sendfrom", (*SendFromCmd)(nil), flags)
MustRegisterCmd("sendmany", (*SendManyCmd)(nil), flags)
MustRegisterCmd("sendtoaddress", (*SendToAddressCmd)(nil), flags)
MustRegisterCmd("sendtomultisig", (*SendToMultiSigCmd)(nil), flags)
MustRegisterCmd("sendtosstx", (*SendToSStxCmd)(nil), flags)
MustRegisterCmd("sendtossgen", (*SendToSSGenCmd)(nil), flags)
MustRegisterCmd("sendtossrtx", (*SendToSSRtxCmd)(nil), flags)
MustRegisterCmd("setbalancetomaintain", (*SetBalanceToMaintainCmd)(nil), flags)
MustRegisterCmd("settxfee", (*SetTxFeeCmd)(nil), flags)
MustRegisterCmd("setticketfee", (*SetTicketFeeCmd)(nil), flags)
MustRegisterCmd("setticketmaxprice", (*SetTicketMaxPriceCmd)(nil), flags)
MustRegisterCmd("setvotechoice", (*SetVoteChoiceCmd)(nil), flags)
MustRegisterCmd("signmessage", (*SignMessageCmd)(nil), flags)
MustRegisterCmd("signrawtransaction", (*SignRawTransactionCmd)(nil), flags)
MustRegisterCmd("signrawtransactions", (*SignRawTransactionsCmd)(nil), flags)
MustRegisterCmd("stakepooluserinfo", (*StakePoolUserInfoCmd)(nil), flags)
MustRegisterCmd("startautobuyer", (*StartAutoBuyerCmd)(nil), flags)
MustRegisterCmd("stopautobuyer", (*StopAutoBuyerCmd)(nil), flags)
MustRegisterCmd("sweepaccount", (*SweepAccountCmd)(nil), flags)
MustRegisterCmd("verifyseed", (*VerifySeedCmd)(nil), flags)
MustRegisterCmd("walletinfo", (*WalletInfoCmd)(nil), flags)
MustRegisterCmd("walletlock", (*WalletLockCmd)(nil), flags)
MustRegisterCmd("walletpassphrase", (*WalletPassphraseCmd)(nil), flags)
MustRegisterCmd("walletpassphrasechange", (*WalletPassphraseChangeCmd)(nil), flags)

View File

@ -77,6 +77,19 @@ func TestWalletSvrCmds(t *testing.T) {
Keys: []string{"031234", "035678"},
},
},
{
name: "createnewaccount",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("createnewaccount", "acct")
},
staticCmd: func() interface{} {
return dcrjson.NewCreateNewAccountCmd("acct")
},
marshalled: `{"jsonrpc":"1.0","method":"createnewaccount","params":["acct"],"id":1}`,
unmarshalled: &dcrjson.CreateNewAccountCmd{
Account: "acct",
},
},
{
name: "dumpprivkey",
newCmd: func() (interface{}, error) {
@ -335,6 +348,34 @@ func TestWalletSvrCmds(t *testing.T) {
IncludeWatchOnly: dcrjson.Bool(true),
},
},
{
name: "importaddress",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("importaddress", "1Address")
},
staticCmd: func() interface{} {
return dcrjson.NewImportAddressCmd("1Address", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"importaddress","params":["1Address"],"id":1}`,
unmarshalled: &dcrjson.ImportAddressCmd{
Address: "1Address",
Rescan: dcrjson.Bool(true),
},
},
{
name: "importaddress optional",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("importaddress", "1Address", false)
},
staticCmd: func() interface{} {
return dcrjson.NewImportAddressCmd("1Address", dcrjson.Bool(false))
},
marshalled: `{"jsonrpc":"1.0","method":"importaddress","params":["1Address",false],"id":1}`,
unmarshalled: &dcrjson.ImportAddressCmd{
Address: "1Address",
Rescan: dcrjson.Bool(false),
},
},
{
name: "importprivkey",
newCmd: func() (interface{}, error) {
@ -396,6 +437,34 @@ func TestWalletSvrCmds(t *testing.T) {
ScanFrom: dcrjson.Int(12345),
},
},
{
name: "importpubkey",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("importpubkey", "031234")
},
staticCmd: func() interface{} {
return dcrjson.NewImportPubKeyCmd("031234", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"importpubkey","params":["031234"],"id":1}`,
unmarshalled: &dcrjson.ImportPubKeyCmd{
PubKey: "031234",
Rescan: dcrjson.Bool(true),
},
},
{
name: "importpubkey optional",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("importpubkey", "031234", false)
},
staticCmd: func() interface{} {
return dcrjson.NewImportPubKeyCmd("031234", dcrjson.Bool(false))
},
marshalled: `{"jsonrpc":"1.0","method":"importpubkey","params":["031234",false],"id":1}`,
unmarshalled: &dcrjson.ImportPubKeyCmd{
PubKey: "031234",
Rescan: dcrjson.Bool(false),
},
},
{
name: "keypoolrefill",
newCmd: func() (interface{}, error) {
@ -801,6 +870,20 @@ func TestWalletSvrCmds(t *testing.T) {
},
},
},
{
name: "renameaccount",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("renameaccount", "oldacct", "newacct")
},
staticCmd: func() interface{} {
return dcrjson.NewRenameAccountCmd("oldacct", "newacct")
},
marshalled: `{"jsonrpc":"1.0","method":"renameaccount","params":["oldacct","newacct"],"id":1}`,
unmarshalled: &dcrjson.RenameAccountCmd{
OldAccount: "oldacct",
NewAccount: "newacct",
},
},
{
name: "sendfrom",
newCmd: func() (interface{}, error) {
@ -1071,6 +1154,38 @@ func TestWalletSvrCmds(t *testing.T) {
Flags: dcrjson.String("ALL"),
},
},
{
name: "sweepaccount - optionals provided",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("sweepaccount", "default", "DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu", 6, 0.05)
},
staticCmd: func() interface{} {
return dcrjson.NewSweepAccountCmd("default", "DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu",
func(i uint32) *uint32 { return &i }(6),
func(i float64) *float64 { return &i }(0.05))
},
marshalled: `{"jsonrpc":"1.0","method":"sweepaccount","params":["default","DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu",6,0.05],"id":1}`,
unmarshalled: &dcrjson.SweepAccountCmd{
SourceAccount: "default",
DestinationAddress: "DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu",
RequiredConfirmations: func(i uint32) *uint32 { return &i }(6),
FeePerKb: func(i float64) *float64 { return &i }(0.05),
},
},
{
name: "sweepaccount - optionals omitted",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("sweepaccount", "default", "DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu")
},
staticCmd: func() interface{} {
return dcrjson.NewSweepAccountCmd("default", "DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu", nil, nil)
},
marshalled: `{"jsonrpc":"1.0","method":"sweepaccount","params":["default","DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu"],"id":1}`,
unmarshalled: &dcrjson.SweepAccountCmd{
SourceAccount: "default",
DestinationAddress: "DsUZxxoHJSty8DCfwfartwTYbuhmVct7tJu",
},
},
{
name: "verifyseed",
newCmd: func() (interface{}, error) {

View File

@ -35,6 +35,54 @@ type GetBalanceResult struct {
TotalVotingAuthority float64 `json:"totalvotingauthority,omitempty"`
}
// GetBestBlockResult models the data from the getbestblock command.
type GetBestBlockResult struct {
Hash string `json:"hash"`
Height int64 `json:"height"`
}
// GetMultisigOutInfoResult models the data returned from the getmultisigoutinfo
// command.
type GetMultisigOutInfoResult struct {
Address string `json:"address"`
RedeemScript string `json:"redeemscript"`
M uint8 `json:"m"`
N uint8 `json:"n"`
Pubkeys []string `json:"pubkeys"`
TxHash string `json:"txhash"`
BlockHeight uint32 `json:"blockheight"`
BlockHash string `json:"blockhash"`
Spent bool `json:"spent"`
SpentBy string `json:"spentby"`
SpentByIndex uint32 `json:"spentbyindex"`
Amount float64 `json:"amount"`
}
// GetStakeInfoResult models the data returned from the getstakeinfo
// command.
type GetStakeInfoResult struct {
BlockHeight int64 `json:"blockheight"`
PoolSize uint32 `json:"poolsize"`
Difficulty float64 `json:"difficulty"`
AllMempoolTix uint32 `json:"allmempooltix"`
OwnMempoolTix uint32 `json:"ownmempooltix"`
Immature uint32 `json:"immature"`
Live uint32 `json:"live"`
ProportionLive float64 `json:"proportionlive"`
Voted uint32 `json:"voted"`
TotalSubsidy float64 `json:"totalsubsidy"`
Missed uint32 `json:"missed"`
ProportionMissed float64 `json:"proportionmissed"`
Revoked uint32 `json:"revoked"`
Expired uint32 `json:"expired"`
}
// GetTicketsResult models the data returned from the gettickets
// command.
type GetTicketsResult struct {
Hashes []string `json:"hashes"`
}
// GetTransactionDetailsResult models the details data from the gettransaction command.
//
// This models the "short" version of the ListTransactionsResult type, which
@ -66,6 +114,20 @@ type GetTransactionResult struct {
Hex string `json:"hex"`
}
// VoteChoice models the data for a vote choice in the getvotechoices result.
type VoteChoice struct {
AgendaID string `json:"agendaid"`
AgendaDescription string `json:"agendadescription"`
ChoiceID string `json:"choiceid"`
ChoiceDescription string `json:"choicedescription"`
}
// GetVoteChoicesResult models the data returned by the getvotechoices command.
type GetVoteChoicesResult struct {
Version uint32 `json:"version"`
Choices []VoteChoice `json:"choices"`
}
// InfoWalletResult models the data returned by the wallet server getinfo
// command.
type InfoWalletResult struct {
@ -87,6 +149,20 @@ type InfoWalletResult struct {
Errors string `json:"errors"`
}
// ScriptInfo is the structure representing a redeem script, its hash,
// and its address.
type ScriptInfo struct {
Hash160 string `json:"hash160"`
Address string `json:"address"`
RedeemScript string `json:"redeemscript"`
}
// ListScriptsResult models the data returned from the listscripts
// command.
type ListScriptsResult struct {
Scripts []ScriptInfo `json:"scripts"`
}
// ListTransactionsTxType defines the type used in the listtransactions JSON-RPC
// result for the TxType command field.
type ListTransactionsTxType string
@ -169,6 +245,28 @@ type ListUnspentResult struct {
Spendable bool `json:"spendable"`
}
// RedeemMultiSigOutResult models the data returned from the redeemmultisigout
// command.
type RedeemMultiSigOutResult struct {
Hex string `json:"hex"`
Complete bool `json:"complete"`
Errors []SignRawTransactionError `json:"errors,omitempty"`
}
// RedeemMultiSigOutsResult models the data returned from the redeemmultisigouts
// command.
type RedeemMultiSigOutsResult struct {
Results []RedeemMultiSigOutResult `json:"results"`
}
// SendToMultiSigResult models the data returned from the sendtomultisig
// command.
type SendToMultiSigResult struct {
TxHash string `json:"txhash"`
Address string `json:"address"`
RedeemScript string `json:"redeemscript"`
}
// SignRawTransactionError models the data that contains script verification
// errors from the signrawtransaction request.
type SignRawTransactionError struct {
@ -187,11 +285,44 @@ type SignRawTransactionResult struct {
Errors []SignRawTransactionError `json:"errors,omitempty"`
}
// VerifySeedResult models the data returned by the wallet server verify
// seed command.
type VerifySeedResult struct {
Result bool `json:"keyresult"`
CoinType uint32 `json:"cointype"`
// SignedTransaction is a signed transaction resulting from a signrawtransactions
// command.
type SignedTransaction struct {
SigningResult SignRawTransactionResult `json:"signingresult"`
Sent bool `json:"sent"`
TxHash *string `json:"txhash,omitempty"`
}
// SignRawTransactionsResult models the data returned from the signrawtransactions
// command.
type SignRawTransactionsResult struct {
Results []SignedTransaction `json:"results"`
}
// PoolUserTicket is the JSON struct corresponding to a stake pool user ticket
// object.
type PoolUserTicket struct {
Status string `json:"status"`
Ticket string `json:"ticket"`
TicketHeight uint32 `json:"ticketheight"`
SpentBy string `json:"spentby"`
SpentByHeight uint32 `json:"spentbyheight"`
}
// StakePoolUserInfoResult models the data returned from the stakepooluserinfo
// command.
type StakePoolUserInfoResult struct {
Tickets []PoolUserTicket `json:"tickets"`
InvalidTickets []string `json:"invalid"`
}
// SweepAccountResult models the data returned from the sweepaccount
// command.
type SweepAccountResult struct {
UnsignedTransaction string `json:"unsignedtransaction"`
TotalPreviousOutputAmount float64 `json:"totalpreviousoutputamount"`
TotalOutputAmount float64 `json:"totaloutputamount"`
EstimatedSignedSize uint32 `json:"estimatedsignedsize"`
}
// ValidateAddressWalletResult models the data returned by the wallet server
@ -212,8 +343,23 @@ type ValidateAddressWalletResult struct {
SigsRequired int32 `json:"sigsrequired,omitempty"`
}
// GetBestBlockResult models the data from the getbestblock command.
type GetBestBlockResult struct {
Hash string `json:"hash"`
Height int64 `json:"height"`
// VerifySeedResult models the data returned by the wallet server verify
// seed command.
type VerifySeedResult struct {
Result bool `json:"keyresult"`
CoinType uint32 `json:"cointype"`
}
// WalletInfoResult models the data returned from the walletinfo
// command.
type WalletInfoResult struct {
DaemonConnected bool `json:"daemonconnected"`
Unlocked bool `json:"unlocked"`
TxFee float64 `json:"txfee"`
TicketFee float64 `json:"ticketfee"`
TicketPurchasing bool `json:"ticketpurchasing"`
VoteBits uint16 `json:"votebits"`
VoteBitsExtended string `json:"votebitsextended"`
VoteVersion uint32 `json:"voteversion"`
Voting bool `json:"voting"`
}

View File

@ -13,17 +13,45 @@ const (
// notifications.
AccountBalanceNtfnMethod = "accountbalance"
// BtcdConnectedNtfnMethod is the method used for notifications when
// DcrdConnectedNtfnMethod is the method used for notifications when
// a wallet server is connected to a chain server.
BtcdConnectedNtfnMethod = "dcrdconnected"
DcrdConnectedNtfnMethod = "dcrdconnected"
// WalletLockStateNtfnMethod is the method used to notify the lock state
// of a wallet has changed.
WalletLockStateNtfnMethod = "walletlockstate"
// NewTicketsNtfnMethod is the method of the daemon
// newtickets notification.
NewTicketsNtfnMethod = "newtickets"
// NewTxNtfnMethod is the method used to notify that a wallet server has
// added a new transaction to the transaction store.
NewTxNtfnMethod = "newtx"
// RevocationCreatedNtfnMethod is the method of the dcrwallet
// revocationcreated notification.
RevocationCreatedNtfnMethod = "revocationcreated"
// SpentAndMissedTicketsNtfnMethod is the method of the daemon
// spentandmissedtickets notification.
SpentAndMissedTicketsNtfnMethod = "spentandmissedtickets"
// StakeDifficultyNtfnMethod is the method of the daemon
// stakedifficulty notification.
StakeDifficultyNtfnMethod = "stakedifficulty"
// TicketPurchasedNtfnMethod is the method of the dcrwallet
// ticketpurchased notification.
TicketPurchasedNtfnMethod = "ticketpurchased"
// VoteCreatedNtfnMethod is the method of the dcrwallet
// votecreated notification.
VoteCreatedNtfnMethod = "votecreated"
// WinningTicketsNtfnMethod is the method of the daemon
// winningtickets notification.
WinningTicketsNtfnMethod = "winningtickets"
// WalletLockStateNtfnMethod is the method used to notify the lock state
// of a wallet has changed.
WalletLockStateNtfnMethod = "walletlockstate"
)
// AccountBalanceNtfn defines the accountbalance JSON-RPC notification.
@ -43,29 +71,35 @@ func NewAccountBalanceNtfn(account string, balance float64, confirmed bool) *Acc
}
}
// BtcdConnectedNtfn defines the dcrddconnected JSON-RPC notification.
type BtcdConnectedNtfn struct {
// DcrdConnectedNtfn defines the dcrddconnected JSON-RPC notification.
type DcrdConnectedNtfn struct {
Connected bool
}
// NewBtcdConnectedNtfn returns a new instance which can be used to issue a
// NewDcrdConnectedNtfn returns a new instance which can be used to issue a
// dcrddconnected JSON-RPC notification.
func NewBtcdConnectedNtfn(connected bool) *BtcdConnectedNtfn {
return &BtcdConnectedNtfn{
func NewDcrdConnectedNtfn(connected bool) *DcrdConnectedNtfn {
return &DcrdConnectedNtfn{
Connected: connected,
}
}
// WalletLockStateNtfn defines the walletlockstate JSON-RPC notification.
type WalletLockStateNtfn struct {
Locked bool
// NewTicketsNtfn is a type handling custom marshaling and
// unmarshaling of newtickets JSON websocket notifications.
type NewTicketsNtfn struct {
Hash string
Height int32
StakeDiff int64
Tickets []string
}
// 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,
// NewNewTicketsNtfn creates a new NewTicketsNtfn.
func NewNewTicketsNtfn(hash string, height int32, stakeDiff int64, tickets []string) *NewTicketsNtfn {
return &NewTicketsNtfn{
Hash: hash,
Height: height,
StakeDiff: stakeDiff,
Tickets: tickets,
}
}
@ -84,13 +118,137 @@ func NewNewTxNtfn(account string, details ListTransactionsResult) *NewTxNtfn {
}
}
// TicketPurchasedNtfn is a type handling custom marshaling and
// unmarshaling of ticketpurchased JSON websocket notifications.
type TicketPurchasedNtfn struct {
TxHash string
Amount int64 // SStx only
}
// NewTicketPurchasedNtfn creates a new TicketPurchasedNtfn.
func NewTicketPurchasedNtfn(txHash string, amount int64) *TicketPurchasedNtfn {
return &TicketPurchasedNtfn{
TxHash: txHash,
Amount: amount,
}
}
// RevocationCreatedNtfn is a type handling custom marshaling and
// unmarshaling of ticketpurchased JSON websocket notifications.
type RevocationCreatedNtfn struct {
TxHash string
SStxIn string
}
// NewRevocationCreatedNtfn creates a new RevocationCreatedNtfn.
func NewRevocationCreatedNtfn(txHash string, sstxIn string) *RevocationCreatedNtfn {
return &RevocationCreatedNtfn{
TxHash: txHash,
SStxIn: sstxIn,
}
}
// SpentAndMissedTicketsNtfn is a type handling custom marshaling and
// unmarshaling of spentandmissedtickets JSON websocket notifications.
type SpentAndMissedTicketsNtfn struct {
Hash string
Height int32
StakeDiff int64
Tickets map[string]string
}
// NewSpentAndMissedTicketsNtfn creates a new SpentAndMissedTicketsNtfn.
func NewSpentAndMissedTicketsNtfn(hash string, height int32, stakeDiff int64, tickets map[string]string) *SpentAndMissedTicketsNtfn {
return &SpentAndMissedTicketsNtfn{
Hash: hash,
Height: height,
StakeDiff: stakeDiff,
Tickets: tickets,
}
}
// StakeDifficultyNtfn is a type handling custom marshaling and
// unmarshaling of stakedifficulty JSON websocket notifications.
type StakeDifficultyNtfn struct {
BlockHash string
BlockHeight int32
StakeDiff int64
}
// NewStakeDifficultyNtfn creates a new StakeDifficultyNtfn.
func NewStakeDifficultyNtfn(hash string, height int32, stakeDiff int64) *StakeDifficultyNtfn {
return &StakeDifficultyNtfn{
BlockHash: hash,
BlockHeight: height,
StakeDiff: stakeDiff,
}
}
// VoteCreatedNtfn is a type handling custom marshaling and
// unmarshaling of ticketpurchased JSON websocket notifications.
type VoteCreatedNtfn struct {
TxHash string
BlockHash string
Height int32
SStxIn string
VoteBits uint16
}
// NewVoteCreatedNtfn creates a new VoteCreatedNtfn.
func NewVoteCreatedNtfn(txHash string, blockHash string, height int32, sstxIn string, voteBits uint16) *VoteCreatedNtfn {
return &VoteCreatedNtfn{
TxHash: txHash,
BlockHash: blockHash,
Height: height,
SStxIn: sstxIn,
VoteBits: voteBits,
}
}
// 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,
}
}
// WinningTicketsNtfn is a type handling custom marshaling and
// unmarshaling of blockconnected JSON websocket notifications.
type WinningTicketsNtfn struct {
BlockHash string
BlockHeight int32
Tickets map[string]string
}
// NewWinningTicketsNtfn creates a new WinningTicketsNtfn.
func NewWinningTicketsNtfn(hash string, height int32, tickets map[string]string) *WinningTicketsNtfn {
return &WinningTicketsNtfn{
BlockHash: hash,
BlockHeight: height,
Tickets: tickets,
}
}
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(DcrdConnectedNtfnMethod, (*DcrdConnectedNtfn)(nil), flags)
MustRegisterCmd(NewTicketsNtfnMethod, (*NewTicketsNtfn)(nil), flags)
MustRegisterCmd(NewTxNtfnMethod, (*NewTxNtfn)(nil), flags)
MustRegisterCmd(TicketPurchasedNtfnMethod, (*TicketPurchasedNtfn)(nil), flags)
MustRegisterCmd(RevocationCreatedNtfnMethod, (*RevocationCreatedNtfn)(nil), flags)
MustRegisterCmd(SpentAndMissedTicketsNtfnMethod, (*SpentAndMissedTicketsNtfn)(nil), flags)
MustRegisterCmd(StakeDifficultyNtfnMethod, (*StakeDifficultyNtfn)(nil), flags)
MustRegisterCmd(VoteCreatedNtfnMethod, (*VoteCreatedNtfn)(nil), flags)
MustRegisterCmd(WalletLockStateNtfnMethod, (*WalletLockStateNtfn)(nil), flags)
MustRegisterCmd(WinningTicketsNtfnMethod, (*WinningTicketsNtfn)(nil), flags)
}

View File

@ -50,24 +50,27 @@ func TestWalletSvrWsNtfns(t *testing.T) {
return dcrjson.NewCmd("dcrdconnected", true)
},
staticNtfn: func() interface{} {
return dcrjson.NewBtcdConnectedNtfn(true)
return dcrjson.NewDcrdConnectedNtfn(true)
},
marshalled: `{"jsonrpc":"1.0","method":"dcrdconnected","params":[true],"id":null}`,
unmarshalled: &dcrjson.BtcdConnectedNtfn{
unmarshalled: &dcrjson.DcrdConnectedNtfn{
Connected: true,
},
},
{
name: "walletlockstate",
name: "newtickets",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("walletlockstate", true)
return dcrjson.NewCmd("newtickets", "123", 100, 3, []string{"a", "b"})
},
staticNtfn: func() interface{} {
return dcrjson.NewWalletLockStateNtfn(true)
return dcrjson.NewNewTicketsNtfn("123", 100, 3, []string{"a", "b"})
},
marshalled: `{"jsonrpc":"1.0","method":"walletlockstate","params":[true],"id":null}`,
unmarshalled: &dcrjson.WalletLockStateNtfn{
Locked: true,
marshalled: `{"jsonrpc":"1.0","method":"newtickets","params":["123",100,3,["a","b"]],"id":null}`,
unmarshalled: &dcrjson.NewTicketsNtfn{
Hash: "123",
Height: 100,
StakeDiff: 3,
Tickets: []string{"a", "b"},
},
},
{
@ -111,6 +114,95 @@ func TestWalletSvrWsNtfns(t *testing.T) {
},
},
},
{
name: "revocationcreated",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("revocationcreated", "123", "1234")
},
staticNtfn: func() interface{} {
return dcrjson.NewRevocationCreatedNtfn("123", "1234")
},
marshalled: `{"jsonrpc":"1.0","method":"revocationcreated","params":["123","1234"],"id":null}`,
unmarshalled: &dcrjson.RevocationCreatedNtfn{
TxHash: "123",
SStxIn: "1234",
},
},
{
name: "spentandmissedtickets",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("spentandmissedtickets", "123", 100, 3, map[string]string{"a": "b"})
},
staticNtfn: func() interface{} {
return dcrjson.NewSpentAndMissedTicketsNtfn("123", 100, 3, map[string]string{"a": "b"})
},
marshalled: `{"jsonrpc":"1.0","method":"spentandmissedtickets","params":["123",100,3,{"a":"b"}],"id":null}`,
unmarshalled: &dcrjson.SpentAndMissedTicketsNtfn{
Hash: "123",
Height: 100,
StakeDiff: 3,
Tickets: map[string]string{"a": "b"},
},
},
{
name: "ticketpurchase",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("ticketpurchased", "123", 5)
},
staticNtfn: func() interface{} {
return dcrjson.NewTicketPurchasedNtfn("123", 5)
},
marshalled: `{"jsonrpc":"1.0","method":"ticketpurchased","params":["123",5],"id":null}`,
unmarshalled: &dcrjson.TicketPurchasedNtfn{
TxHash: "123",
Amount: 5,
},
},
{
name: "votecreated",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("votecreated", "123", "1234", 100, "12345", 1)
},
staticNtfn: func() interface{} {
return dcrjson.NewVoteCreatedNtfn("123", "1234", 100, "12345", 1)
},
marshalled: `{"jsonrpc":"1.0","method":"votecreated","params":["123","1234",100,"12345",1],"id":null}`,
unmarshalled: &dcrjson.VoteCreatedNtfn{
TxHash: "123",
BlockHash: "1234",
Height: 100,
SStxIn: "12345",
VoteBits: 1,
},
},
{
name: "walletlockstate",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("walletlockstate", true)
},
staticNtfn: func() interface{} {
return dcrjson.NewWalletLockStateNtfn(true)
},
marshalled: `{"jsonrpc":"1.0","method":"walletlockstate","params":[true],"id":null}`,
unmarshalled: &dcrjson.WalletLockStateNtfn{
Locked: true,
},
},
{
name: "winningtickets",
newNtfn: func() (interface{}, error) {
return dcrjson.NewCmd("winningtickets", "123", 100, map[string]string{"a": "b"})
},
staticNtfn: func() interface{} {
return dcrjson.NewWinningTicketsNtfn("123", 100, map[string]string{"a": "b"})
},
marshalled: `{"jsonrpc":"1.0","method":"winningtickets","params":["123",100,{"a":"b"}],"id":null}`,
unmarshalled: &dcrjson.WinningTicketsNtfn{
BlockHash: "123",
BlockHeight: 100,
Tickets: map[string]string{"a": "b"},
},
},
}
t.Logf("Running %d tests", len(tests))

View File

@ -152,12 +152,12 @@ type NotificationHandlers struct {
// made to register for the notification and the function is non-nil.
OnTxAcceptedVerbose func(txDetails *dcrjson.TxRawResult)
// OnBtcdConnected is invoked when a wallet connects or disconnects from
// OnDcrdConnected is invoked when a wallet connects or disconnects from
// dcrd.
//
// This will only be available when client is connected to a wallet
// server such as dcrwallet.
OnBtcdConnected func(connected bool)
OnDcrdConnected func(connected bool)
// OnAccountBalance is invoked with account balance updates.
//
@ -397,22 +397,22 @@ func (c *Client) handleNotification(ntfn *rawNotification) {
c.ntfnHandlers.OnTxAcceptedVerbose(rawTx)
// OnBtcdConnected
case dcrjson.BtcdConnectedNtfnMethod:
// OnDcrdConnected
case dcrjson.DcrdConnectedNtfnMethod:
// Ignore the notification if the client is not interested in
// it.
if c.ntfnHandlers.OnBtcdConnected == nil {
if c.ntfnHandlers.OnDcrdConnected == nil {
return
}
connected, err := parseBtcdConnectedNtfnParams(ntfn.Params)
connected, err := parseDcrdConnectedNtfnParams(ntfn.Params)
if err != nil {
log.Warnf("Received invalid dcrd connected "+
"notification: %v", err)
return
}
c.ntfnHandlers.OnBtcdConnected(connected)
c.ntfnHandlers.OnDcrdConnected(connected)
// OnAccountBalance
case dcrjson.AccountBalanceNtfnMethod:
@ -919,9 +919,9 @@ func parseTxAcceptedVerboseNtfnParams(params []json.RawMessage) (*dcrjson.TxRawR
return &rawTx, nil
}
// parseBtcdConnectedNtfnParams parses out the connection status of dcrd
// and dcrwallet from the parameters of a btcdconnected notification.
func parseBtcdConnectedNtfnParams(params []json.RawMessage) (bool, error) {
// parseDcrdConnectedNtfnParams parses out the connection status of dcrd
// and dcrwallet from the parameters of a dcrdconnected notification.
func parseDcrdConnectedNtfnParams(params []json.RawMessage) (bool, error) {
if len(params) != 1 {
return false, wrongNumParams(len(params))
}