From b57628ea9f3b4f8f15198f77578b921b0b142b31 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 6 Nov 2013 11:10:22 -0500 Subject: [PATCH 01/76] Initial commit. --- LICENSE | 13 ++ cmds.go | 470 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 483 insertions(+) create mode 100644 LICENSE create mode 100644 cmds.go diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..62a53cea --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2013 Conformal Systems LLC. + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/cmds.go b/cmds.go new file mode 100644 index 00000000..8e8eb234 --- /dev/null +++ b/cmds.go @@ -0,0 +1,470 @@ +// Copyright (c) 2013 Conformal Systems LLC. +// Use of this source code is governed by an ISC +// license that can be found in the LICENSE file. + +package btcws + +import ( + "encoding/json" + "errors" + "github.com/conformal/btcdb" + "github.com/conformal/btcjson" + "github.com/conformal/btcwire" +) + +func init() { + btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd) + btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd) + btcjson.RegisterCustomCmd("rescan", parseRescanCmd) + btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd) + btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd) +} + +// GetCurrentNetCmd is a type handling custom marshaling and +// unmarshaling of getcurrentnet JSON websocket extension +// commands. +type GetCurrentNetCmd struct { + id interface{} +} + +// Enforce that GetCurrentNetCmd satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &GetCurrentNetCmd{} + +// NewGetCurrentNetCmd creates a new GetCurrentNetCmd. +func NewGetCurrentNetCmd(id interface{}) *GetCurrentNetCmd { + return &GetCurrentNetCmd{id: id} +} + +// parseGetCurrentNetCmd parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the custom +// command with the btcjson parser. +func parseGetCurrentNetCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) != 0 { + return nil, btcjson.ErrWrongNumberOfParams + } + + return NewGetCurrentNetCmd(r.Id), nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *GetCurrentNetCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *GetCurrentNetCmd) Method() string { + return "getcurrentnet" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *GetCurrentNetCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "getcurrentnet", + Id: cmd.id, + } + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *GetCurrentNetCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseGetCurrentNetCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*GetCurrentNetCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + +// GetBestBlockCmd is a type handling custom marshaling and +// unmarshaling of getbestblock JSON websocket extension +// commands. +type GetBestBlockCmd struct { + id interface{} +} + +// Enforce that GetBestBlockCmd satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &GetBestBlockCmd{} + +// NewGetBestBlockCmd creates a new GetBestBlock. +func NewGetBestBlockCmd(id interface{}) *GetBestBlockCmd { + return &GetBestBlockCmd{id: id} +} + +// parseGetBestBlockCmd parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the custom +// command with the btcjson parser. +func parseGetBestBlockCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) != 0 { + return nil, btcjson.ErrWrongNumberOfParams + } + + return NewGetBestBlockCmd(r.Id), nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *GetBestBlockCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *GetBestBlockCmd) Method() string { + return "getbestblock" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *GetBestBlockCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "getbestblock", + Id: cmd.id, + } + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *GetBestBlockCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseGetBestBlockCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*GetBestBlockCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + +// RescanCmd is a type handling custom marshaling and +// unmarshaling of rescan JSON websocket extension +// commands. +type RescanCmd struct { + id interface{} + BeginBlock int32 + Addresses map[string]struct{} + EndBlock int64 // TODO: switch this and btcdb.AllShas to int32 +} + +// Enforce that RescanCmd satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &RescanCmd{} + +// NewRescanCmd creates a new RescanCmd, parsing the optional +// arguments optArgs which may either be empty or a single upper +// block height. +func NewRescanCmd(id interface{}, begin int32, addresses map[string]struct{}, + optArgs ...int64) (*RescanCmd, error) { + + // Optional parameters set to their defaults. + end := btcdb.AllShas + + if len(optArgs) > 0 { + if len(optArgs) > 1 { + return nil, btcjson.ErrTooManyOptArgs + } + end = optArgs[0] + } + + return &RescanCmd{ + id: id, + BeginBlock: begin, + Addresses: addresses, + EndBlock: end, + }, nil +} + +// parseRescanCmd parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the custom +// command with the btcjson parser. +func parseRescanCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) < 2 { + return nil, btcjson.ErrWrongNumberOfParams + } + + begin, ok := r.Params[0].(float64) + if !ok { + return nil, errors.New("first parameter must be a number") + } + iaddrs, ok := r.Params[1].(map[string]interface{}) + if !ok { + return nil, errors.New("second parameter must be a JSON object") + } + addresses := make(map[string]struct{}, len(iaddrs)) + for addr := range iaddrs { + addresses[addr] = struct{}{} + } + params := make([]int64, len(r.Params[2:])) + for i, val := range r.Params[2:] { + fval, ok := val.(float64) + if !ok { + return nil, errors.New("optional parameters must " + + "be be numbers") + } + params[i] = int64(fval) + } + + return NewRescanCmd(r.Id, int32(begin), addresses, params...) +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *RescanCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *RescanCmd) Method() string { + return "rescan" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *RescanCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "rescan", + Id: cmd.id, + Params: []interface{}{ + cmd.BeginBlock, + cmd.Addresses, + }, + } + + if cmd.EndBlock != btcdb.AllShas { + raw.Params = append(raw.Params, cmd.EndBlock) + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *RescanCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseRescanCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*RescanCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + +// NotifyNewTXsCmd is a type handling custom marshaling and +// unmarshaling of notifynewtxs JSON websocket extension +// commands. +type NotifyNewTXsCmd struct { + id interface{} + Addresses []string +} + +// Enforce that NotifyNewTXsCmd satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &NotifyNewTXsCmd{} + +// NewNotifyNewTXsCmd creates a new RescanCmd, parsing the optional +// arguments optArgs which may either be empty or a +func NewNotifyNewTXsCmd(id interface{}, addresses []string) *NotifyNewTXsCmd { + return &NotifyNewTXsCmd{ + id: id, + Addresses: addresses, + } +} + +// parseNotifyNewTXsCmd parses a NotifyNewTXsCmd into a concrete type +// satisifying the btcjson.Cmd interface. This is used when registering +// the custom command with the btcjson parser. +func parseNotifyNewTXsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) != 1 { + return nil, btcjson.ErrWrongNumberOfParams + } + + iaddrs, ok := r.Params[0].([]interface{}) + if !ok { + return nil, errors.New("first parameter must be a JSON array") + } + addresses := make([]string, len(iaddrs)) + for i := range iaddrs { + addr, ok := iaddrs[i].(string) + if !ok { + return nil, errors.New("first parameter must be an " + + "array of strings") + } + addresses[i] = addr + } + + return NewNotifyNewTXsCmd(r.Id, addresses), nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *NotifyNewTXsCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *NotifyNewTXsCmd) Method() string { + return "notifynewtxs" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *NotifyNewTXsCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "notifynewtxs", + Id: cmd.id, + Params: []interface{}{ + cmd.Addresses, + }, + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *NotifyNewTXsCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseNotifyNewTXsCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*NotifyNewTXsCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + +// NotifySpentCmd is a type handling custom marshaling and +// unmarshaling of notifyspent JSON websocket extension +// commands. +type NotifySpentCmd struct { + id interface{} + *btcwire.OutPoint +} + +// Enforce that NotifySpentCmd satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &NotifySpentCmd{} + +// NewNotifySpentCmd creates a new RescanCmd, parsing the optional +// arguments optArgs which may either be empty or a +func NewNotifySpentCmd(id interface{}, op *btcwire.OutPoint) *NotifySpentCmd { + return &NotifySpentCmd{ + id: id, + OutPoint: op, + } +} + +// parseNotifySpentCmd parses a NotifySpentCmd into a concrete type +// satisifying the btcjson.Cmd interface. This is used when registering +// the custom command with the btcjson parser. +func parseNotifySpentCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) != 2 { + return nil, btcjson.ErrWrongNumberOfParams + } + + hashStr, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter must be a string") + } + hash, err := btcwire.NewShaHashFromStr(hashStr) + if err != nil { + return nil, errors.New("first parameter is not a valid " + + "hash string") + } + idx, ok := r.Params[1].(float64) + if !ok { + return nil, errors.New("second parameter is not a number") + } + if idx < 0 { + return nil, errors.New("second parameter cannot be negative") + } + + cmd := NewNotifySpentCmd(r.Id, btcwire.NewOutPoint(hash, uint32(idx))) + return cmd, nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *NotifySpentCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *NotifySpentCmd) Method() string { + return "notifyspent" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *NotifySpentCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "notifyspent", + Id: cmd.id, + Params: []interface{}{ + cmd.OutPoint.Hash.String(), + cmd.OutPoint.Index, + }, + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *NotifySpentCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseNotifySpentCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*NotifySpentCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} From f32b5692d5e1eada8b80bd5094d635e76b0abd05 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 8 Nov 2013 12:41:04 -0500 Subject: [PATCH 02/76] Add btcd notification types and parser. --- notifications.go | 245 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 notifications.go diff --git a/notifications.go b/notifications.go new file mode 100644 index 00000000..0b096117 --- /dev/null +++ b/notifications.go @@ -0,0 +1,245 @@ +// Copyright (c) 2013 Conformal Systems LLC. +// Use of this source code is governed by an ISC +// license that can be found in the LICENSE file. + +package btcws + +import ( + "encoding/json" + "errors" + "github.com/conformal/btcjson" +) + +var ( + // ErrNtfnUnexpected describes an error where an unexpected + // notification is received when unmarshaling into a concrete + // Notification variable. + ErrNtfnUnexpected = errors.New("notification unexpected") + + // ErrNtfnNotFound describes an error where a parser does not + // handle unmarshaling a notification. + ErrNtfnNotFound = errors.New("notification not found") +) + +const ( + // BlockConnectedNtfnId is the id of the btcd blockconnected + // notification. + BlockConnectedNtfnId = "btcd:blockconnected" + + // BlockDisconnectedNtfnId is the id of the btcd blockdisconnected + // notification. + BlockDisconnectedNtfnId = "btcd:blockdisconnected" + + //TxMinedNtfnId is the id of the btcd txmined notification. + TxMinedNtfnId = "btcd:txmined" +) + +type newNtfnFn func() Notification + +func newBlockConnectedNtfn() Notification { + return &BlockConnectedNtfn{} +} + +func newBlockDisconnectedNtfn() Notification { + return &BlockDisconnectedNtfn{} +} + +func newTxMinedNtfn() Notification { + return &TxMinedNtfn{} +} + +var newNtfnFns = map[string]newNtfnFn{ + BlockConnectedNtfnId: newBlockConnectedNtfn, + BlockDisconnectedNtfnId: newBlockDisconnectedNtfn, + TxMinedNtfnId: newTxMinedNtfn, +} + +// ParseMarshaledNtfn attempts to unmarshal a marshaled notification +// into the notification described by id. +func ParseMarshaledNtfn(id string, b []byte) (Notification, error) { + if newFn, ok := newNtfnFns[id]; ok { + n := newFn() + if err := n.UnmarshalJSON(b); err != nil { + return nil, err + } + return n, nil + } + return nil, ErrNtfnNotFound +} + +// Notification is an interface implemented by all notification types. +type Notification interface { + json.Marshaler + json.Unmarshaler + Id() interface{} +} + +// BlockConnectedNtfn is a type handling custom marshaling and +// unmarshaling of blockconnected JSON websocket notifications. +type BlockConnectedNtfn struct { + Hash string `json:"hash"` + Height int32 `json:"height"` +} + +type blockConnectedResult BlockConnectedNtfn + +// Enforce that BlockConnectedNtfn satisfies the Notification interface. +var _ Notification = &BlockConnectedNtfn{} + +// NewBlockConnectedNtfn creates a new BlockConnectedNtfn. +func NewBlockConnectedNtfn(hash string, height int32) *BlockConnectedNtfn { + return &BlockConnectedNtfn{ + Hash: hash, + Height: height, + } +} + +// satisifies the Notification interface by returning the id of the +// notification. +func (n *BlockConnectedNtfn) Id() interface{} { + return BlockConnectedNtfnId +} + +// MarshalJSON returns the JSON encoding of n. Part of the Notification +// interface. +func (n *BlockConnectedNtfn) MarshalJSON() ([]byte, error) { + id := n.Id() + reply := btcjson.Reply{ + Result: *n, + Id: &id, + } + return json.Marshal(reply) +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the Notification interface. +func (n *BlockConnectedNtfn) UnmarshalJSON(b []byte) error { + var ntfn struct { + Result blockConnectedResult `json:"result"` + Error *btcjson.Error `json:"error"` + Id interface{} `json:"id"` + } + if err := json.Unmarshal(b, &ntfn); err != nil { + return err + } + + // Notification IDs must match expected. + if n.Id() != ntfn.Id { + return ErrNtfnUnexpected + } + + *n = BlockConnectedNtfn(ntfn.Result) + return nil +} + +// BlockDisconnectedNtfn is a type handling custom marshaling and +// unmarshaling of blockdisconnected JSON websocket notifications. +type BlockDisconnectedNtfn struct { + Hash string `json:"hash"` + Height int32 `json:"height"` +} + +type blockDisconnectedResult BlockDisconnectedNtfn + +// Enforce that BlockDisconnectedNtfn satisfies the Notification interface. +var _ Notification = &BlockDisconnectedNtfn{} + +// NewBlockDisconnectedNtfn creates a new BlockConnectedNtfn. +func NewBlockDisconnectedNtfn(hash string, height int32) *BlockDisconnectedNtfn { + return &BlockDisconnectedNtfn{ + Hash: hash, + Height: height, + } +} + +// Id satisifies the Notification interface by returning the id of the +// notification. +func (n *BlockDisconnectedNtfn) Id() interface{} { + return BlockDisconnectedNtfnId +} + +// MarshalJSON returns the JSON encoding of n. Part of the Notification +// interface. +func (n *BlockDisconnectedNtfn) MarshalJSON() ([]byte, error) { + id := n.Id() + reply := btcjson.Reply{ + Result: *n, + Id: &id, + } + return json.Marshal(reply) +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the Notification interface. +func (n *BlockDisconnectedNtfn) UnmarshalJSON(b []byte) error { + var ntfn struct { + Result blockDisconnectedResult `json:"result"` + Error *btcjson.Error `json:"error"` + Id interface{} `json:"id"` + } + if err := json.Unmarshal(b, &ntfn); err != nil { + return err + } + + // Notification IDs must match expected. + if n.Id() != ntfn.Id { + return ErrNtfnUnexpected + } + + *n = BlockDisconnectedNtfn(ntfn.Result) + return nil +} + +// TxMinedNtfn is a type handling custom marshaling and +// unmarshaling of txmined JSON websocket notifications. +type TxMinedNtfn struct { + Hash string `json:"hash"` +} + +type txMinedResult TxMinedNtfn + +// Enforce that TxMinedNtfn satisfies the Notification interface. +var _ Notification = &TxMinedNtfn{} + +// NewTxMinedNtfn creates a new TxMinedNtfn. +func NewTxMinedNtfn(hash string) *TxMinedNtfn { + return &TxMinedNtfn{Hash: hash} +} + +// Id satisifies the Notification interface by returning the id of the +// notification. +func (n *TxMinedNtfn) Id() interface{} { + return TxMinedNtfnId +} + +// MarshalJSON returns the JSON encoding of n. Part of the Notification +// interface. +func (n *TxMinedNtfn) MarshalJSON() ([]byte, error) { + id := n.Id() + reply := btcjson.Reply{ + Result: n.Hash, + Id: &id, + } + return json.Marshal(reply) +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the Notification interface. +func (n *TxMinedNtfn) UnmarshalJSON(b []byte) error { + var ntfn struct { + Result txMinedResult `json:"result"` + Error *btcjson.Error `json:"error"` + Id interface{} `json:"id"` + } + if err := json.Unmarshal(b, &ntfn); err != nil { + return err + } + + // Notification IDs must match expected. + if n.Id() != ntfn.Id { + return ErrNtfnUnexpected + } + + *n = TxMinedNtfn(ntfn.Result) + return nil +} From 3270be61fc865f312428fc1676e3ac8b07aacde4 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 8 Nov 2013 12:42:32 -0500 Subject: [PATCH 03/76] go fmt --- notifications.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notifications.go b/notifications.go index 0b096117..c7df61c7 100644 --- a/notifications.go +++ b/notifications.go @@ -24,14 +24,14 @@ var ( const ( // BlockConnectedNtfnId is the id of the btcd blockconnected // notification. - BlockConnectedNtfnId = "btcd:blockconnected" + BlockConnectedNtfnId = "btcd:blockconnected" // BlockDisconnectedNtfnId is the id of the btcd blockdisconnected // notification. BlockDisconnectedNtfnId = "btcd:blockdisconnected" //TxMinedNtfnId is the id of the btcd txmined notification. - TxMinedNtfnId = "btcd:txmined" + TxMinedNtfnId = "btcd:txmined" ) type newNtfnFn func() Notification From 0c37bf3b50580377506584a085f3635cf903769f Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 8 Nov 2013 13:03:34 -0500 Subject: [PATCH 04/76] Marshal txmined notification results correctly. --- notifications.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifications.go b/notifications.go index c7df61c7..609d28b0 100644 --- a/notifications.go +++ b/notifications.go @@ -217,7 +217,7 @@ func (n *TxMinedNtfn) Id() interface{} { func (n *TxMinedNtfn) MarshalJSON() ([]byte, error) { id := n.Id() reply := btcjson.Reply{ - Result: n.Hash, + Result: *n, Id: &id, } return json.Marshal(reply) From 91b030cb762c8be7386e46c1721e2f72a6e4d4a6 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 8 Nov 2013 14:07:57 -0500 Subject: [PATCH 05/76] Fix comments. --- cmds.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmds.go b/cmds.go index 8e8eb234..86e7f8bb 100644 --- a/cmds.go +++ b/cmds.go @@ -291,8 +291,7 @@ type NotifyNewTXsCmd struct { // Enforce that NotifyNewTXsCmd satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &NotifyNewTXsCmd{} -// NewNotifyNewTXsCmd creates a new RescanCmd, parsing the optional -// arguments optArgs which may either be empty or a +// NewNotifyNewTXsCmd creates a new RescanCmd. func NewNotifyNewTXsCmd(id interface{}, addresses []string) *NotifyNewTXsCmd { return &NotifyNewTXsCmd{ id: id, @@ -383,8 +382,7 @@ type NotifySpentCmd struct { // Enforce that NotifySpentCmd satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &NotifySpentCmd{} -// NewNotifySpentCmd creates a new RescanCmd, parsing the optional -// arguments optArgs which may either be empty or a +// NewNotifySpentCmd creates a new RescanCmd. func NewNotifySpentCmd(id interface{}, op *btcwire.OutPoint) *NotifySpentCmd { return &NotifySpentCmd{ id: id, From 38bebf2036657c407ba9b1f319c1dd4bb6c380ed Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 8 Nov 2013 14:13:47 -0500 Subject: [PATCH 06/76] Fix another issue with a godoc comment. --- notifications.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifications.go b/notifications.go index 609d28b0..3f134963 100644 --- a/notifications.go +++ b/notifications.go @@ -94,7 +94,7 @@ func NewBlockConnectedNtfn(hash string, height int32) *BlockConnectedNtfn { } } -// satisifies the Notification interface by returning the id of the +// Id satisifies the Notification interface by returning the id of the // notification. func (n *BlockConnectedNtfn) Id() interface{} { return BlockConnectedNtfnId From 497f1770445677372557d70621782d921a5318e3 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 12 Nov 2013 11:57:06 -0500 Subject: [PATCH 07/76] Add frontend <-> wallet extension commands. This change adds support for the following extension commands: - createencryptedwallet - getbalances - walletislocked --- cmds.go | 276 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 276 insertions(+) diff --git a/cmds.go b/cmds.go index 86e7f8bb..7f78c136 100644 --- a/cmds.go +++ b/cmds.go @@ -18,6 +18,9 @@ func init() { btcjson.RegisterCustomCmd("rescan", parseRescanCmd) btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd) btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd) + btcjson.RegisterCustomCmd("createencryptedwallet", parseCreateEncryptedWalletCmd) + btcjson.RegisterCustomCmd("getbalances", parseGetBalancesCmd) + btcjson.RegisterCustomCmd("walletislocked", parseWalletIsLockedCmd) } // GetCurrentNetCmd is a type handling custom marshaling and @@ -466,3 +469,276 @@ func (cmd *NotifySpentCmd) UnmarshalJSON(b []byte) error { *cmd = *concreteCmd return nil } + +// CreateEncryptedWalletCmd is a type handling custom +// marshaling and unmarshaling of createencryptedwallet +// JSON websocket extension commands. +type CreateEncryptedWalletCmd struct { + id interface{} + Account string + Description string + Passphrase string +} + +// Enforce that CreateEncryptedWalletCmd satisifies the btcjson.Cmd +// interface. +var _ btcjson.Cmd = &CreateEncryptedWalletCmd{} + +// NewCreateEncryptedWalletCmd creates a new CreateEncryptedWalletCmd. +func NewCreateEncryptedWalletCmd(id interface{}, + account, description, passphrase string) *CreateEncryptedWalletCmd { + + return &CreateEncryptedWalletCmd{ + id: id, + Account: account, + Description: description, + Passphrase: passphrase, + } +} + +// parseCreateEncryptedWalletCmd parses a CreateEncryptedWalletCmd +// into a concrete type satisifying the btcjson.Cmd interface. +// This is used when registering the custom command with the btcjson +// parser. +func parseCreateEncryptedWalletCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) != 3 { + return nil, btcjson.ErrWrongNumberOfParams + } + + account, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter must be a string") + } + description, ok := r.Params[1].(string) + if !ok { + return nil, errors.New("second parameter is not a string") + } + passphrase, ok := r.Params[2].(string) + if !ok { + return nil, errors.New("third parameter is not a string") + } + + cmd := NewCreateEncryptedWalletCmd(r.Id, account, description, + passphrase) + return cmd, nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *CreateEncryptedWalletCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *CreateEncryptedWalletCmd) Method() string { + return "createencryptedwallet" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *CreateEncryptedWalletCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "createencryptedwallet", + Id: cmd.id, + Params: []interface{}{ + cmd.Account, + cmd.Description, + cmd.Passphrase, + }, + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *CreateEncryptedWalletCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseCreateEncryptedWalletCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*CreateEncryptedWalletCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + +// GetBalancesCmd is a type handling custom marshaling and +// unmarshaling of getbalances JSON websocket extension commands. +type GetBalancesCmd struct { + id interface{} +} + +// Enforce that GetBalancesCmd satisifies the btcjson.Cmd +// interface. +var _ btcjson.Cmd = &GetBalancesCmd{} + +// NewGetBalancesCmd creates a new GetBalancesCmd. +func NewGetBalancesCmd(id interface{}) *GetBalancesCmd { + return &GetBalancesCmd{id: id} +} + +// parseGetBalancesCmd parses a GetBalancesCmd into a concrete +// type satisifying the btcjson.Cmd interface. This is used when +// registering the custom command with the btcjson parser. +func parseGetBalancesCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) != 0 { + return nil, btcjson.ErrWrongNumberOfParams + } + + return NewGetBalancesCmd(r.Id), nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *GetBalancesCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *GetBalancesCmd) Method() string { + return "getbalances" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *GetBalancesCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "getbalances", + Id: cmd.id, + Params: []interface{}{}, + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *GetBalancesCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseGetBalancesCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*GetBalancesCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + +// WalletIsLockedCmd is a type handling custom marshaling and +// unmarshaling of walletislocked JSON websocket extension commands. +type WalletIsLockedCmd struct { + id interface{} + Account string +} + +// Enforce that WalletIsLockedCmd satisifies the btcjson.Cmd +// interface. +var _ btcjson.Cmd = &WalletIsLockedCmd{} + +// NewWalletIsLockedCmd creates a new WalletIsLockedCmd. +func NewWalletIsLockedCmd(id interface{}, + optArgs ...string) (*WalletIsLockedCmd, error) { + + // Optional arguments set to their default values. + account := "" + + if len(optArgs) > 1 { + return nil, btcjson.ErrInvalidParams + } + + if len(optArgs) == 1 { + account = optArgs[0] + } + + return &WalletIsLockedCmd{ + id: id, + Account: account, + }, nil +} + +// parseWalletIsLockedCmd parses a WalletIsLockedCmd into a concrete +// type satisifying the btcjson.Cmd interface. This is used when +// registering the custom command with the btcjson parser. +func parseWalletIsLockedCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) > 1 { + return nil, btcjson.ErrInvalidParams + } + + if len(r.Params) == 0 { + return NewWalletIsLockedCmd(r.Id) + } + + account, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("account must be a string") + } + return NewWalletIsLockedCmd(r.Id, account) +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *WalletIsLockedCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *WalletIsLockedCmd) Method() string { + return "walletislocked" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *WalletIsLockedCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "walletislocked", + Id: cmd.id, + Params: []interface{}{}, + } + + if cmd.Account != "" { + raw.Params = append(raw.Params, cmd.Account) + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *WalletIsLockedCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseWalletIsLockedCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*WalletIsLockedCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} From dd3c9b2b5fba8e58aa6d84c7136271fc28574db9 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 25 Nov 2013 12:54:01 -0500 Subject: [PATCH 08/76] Send additional block information with a TxMinedNtfn. --- notifications.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/notifications.go b/notifications.go index 3f134963..13eb461b 100644 --- a/notifications.go +++ b/notifications.go @@ -193,7 +193,11 @@ func (n *BlockDisconnectedNtfn) UnmarshalJSON(b []byte) error { // TxMinedNtfn is a type handling custom marshaling and // unmarshaling of txmined JSON websocket notifications. type TxMinedNtfn struct { - Hash string `json:"hash"` + TxID string `json:"txid"` + BlockHash string `json:"blockhash"` + BlockHeight int32 `json:"blockheight"` + BlockTime int64 `json:"blocktime"` + Index int `json:"index"` } type txMinedResult TxMinedNtfn @@ -202,8 +206,16 @@ type txMinedResult TxMinedNtfn var _ Notification = &TxMinedNtfn{} // NewTxMinedNtfn creates a new TxMinedNtfn. -func NewTxMinedNtfn(hash string) *TxMinedNtfn { - return &TxMinedNtfn{Hash: hash} +func NewTxMinedNtfn(txid, blockhash string, blockheight int32, + blocktime int64, index int) *TxMinedNtfn { + + return &TxMinedNtfn{ + TxID: txid, + BlockHash: blockhash, + BlockHeight: blockheight, + BlockTime: blocktime, + Index: index, + } } // Id satisifies the Notification interface by returning the id of the From d9d7db7c20a465144a63d7a9b95c2b46fe2ce6de Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 2 Dec 2013 14:59:09 -0500 Subject: [PATCH 09/76] Add listalltransactions command. --- cmds.go | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 106 insertions(+), 5 deletions(-) diff --git a/cmds.go b/cmds.go index 7f78c136..20b1580c 100644 --- a/cmds.go +++ b/cmds.go @@ -13,13 +13,14 @@ import ( ) func init() { - btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd) - btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd) - btcjson.RegisterCustomCmd("rescan", parseRescanCmd) - btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd) - btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd) btcjson.RegisterCustomCmd("createencryptedwallet", parseCreateEncryptedWalletCmd) btcjson.RegisterCustomCmd("getbalances", parseGetBalancesCmd) + btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd) + btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd) + btcjson.RegisterCustomCmd("listalltransactions", parseListAllTransactionsCmd) + btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd) + btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd) + btcjson.RegisterCustomCmd("rescan", parseRescanCmd) btcjson.RegisterCustomCmd("walletislocked", parseWalletIsLockedCmd) } @@ -742,3 +743,103 @@ func (cmd *WalletIsLockedCmd) UnmarshalJSON(b []byte) error { *cmd = *concreteCmd return nil } + +// ListAllTransactionsCmd is a type handling custom marshaling and +// unmarshaling of walletislocked JSON websocket extension commands. +type ListAllTransactionsCmd struct { + id interface{} + Account string +} + +// Enforce that ListAllTransactionsCmd satisifies the btcjson.Cmd +// interface. +var _ btcjson.Cmd = &ListAllTransactionsCmd{} + +// NewListAllTransactionsCmd creates a new ListAllTransactionsCmd. +func NewListAllTransactionsCmd(id interface{}, + optArgs ...string) (*ListAllTransactionsCmd, error) { + + // Optional arguments set to their default values. + account := "" + + if len(optArgs) > 1 { + return nil, btcjson.ErrInvalidParams + } + + if len(optArgs) == 1 { + account = optArgs[0] + } + + return &ListAllTransactionsCmd{ + id: id, + Account: account, + }, nil +} + +// parseListAllTransactionsCmd parses a ListAllTransactionsCmd into a concrete +// type satisifying the btcjson.Cmd interface. This is used when +// registering the custom command with the btcjson parser. +func parseListAllTransactionsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) > 1 { + return nil, btcjson.ErrInvalidParams + } + + if len(r.Params) == 0 { + return NewListAllTransactionsCmd(r.Id) + } + + account, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("account must be a string") + } + return NewListAllTransactionsCmd(r.Id, account) +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *ListAllTransactionsCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *ListAllTransactionsCmd) Method() string { + return "listalltransactions" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *ListAllTransactionsCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "listalltransactions", + Id: cmd.id, + Params: []interface{}{}, + } + + if cmd.Account != "" { + raw.Params = append(raw.Params, cmd.Account) + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *ListAllTransactionsCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseListAllTransactionsCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*ListAllTransactionsCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} From 3379f2a0097ae8f59f1791d0e713a0446ac24989 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 2 Dec 2013 15:05:16 -0500 Subject: [PATCH 10/76] Fix copy-paste typo. --- cmds.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds.go b/cmds.go index 20b1580c..00134f9b 100644 --- a/cmds.go +++ b/cmds.go @@ -745,7 +745,7 @@ func (cmd *WalletIsLockedCmd) UnmarshalJSON(b []byte) error { } // ListAllTransactionsCmd is a type handling custom marshaling and -// unmarshaling of walletislocked JSON websocket extension commands. +// unmarshaling of listalltransactions JSON websocket extension commands. type ListAllTransactionsCmd struct { id interface{} Account string From 50c0dd15821bd6075dcf370a71df7ec0162b5cb2 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 2 Dec 2013 17:32:17 -0500 Subject: [PATCH 11/76] Add btcwallet:newtx notification support. --- notifications.go | 68 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/notifications.go b/notifications.go index 13eb461b..e2a9c0c4 100644 --- a/notifications.go +++ b/notifications.go @@ -30,8 +30,11 @@ const ( // notification. BlockDisconnectedNtfnId = "btcd:blockdisconnected" - //TxMinedNtfnId is the id of the btcd txmined notification. + // TxMinedNtfnId is the id of the btcd txmined notification. TxMinedNtfnId = "btcd:txmined" + + // TxNtfnId is the id of the btcwallet newtx notification. + TxNtfnId = "btcwallet:newtx" ) type newNtfnFn func() Notification @@ -48,10 +51,15 @@ func newTxMinedNtfn() Notification { return &TxMinedNtfn{} } +func newTxNtfn() Notification { + return &TxNtfn{} +} + var newNtfnFns = map[string]newNtfnFn{ BlockConnectedNtfnId: newBlockConnectedNtfn, BlockDisconnectedNtfnId: newBlockDisconnectedNtfn, TxMinedNtfnId: newTxMinedNtfn, + TxNtfnId: newTxNtfn, } // ParseMarshaledNtfn attempts to unmarshal a marshaled notification @@ -255,3 +263,61 @@ func (n *TxMinedNtfn) UnmarshalJSON(b []byte) error { *n = TxMinedNtfn(ntfn.Result) return nil } + +// TxNtfn is a type handling custom marshaling and +// unmarshaling of newtx JSON websocket notifications. +type TxNtfn struct { + Account string `json:"account"` + Details map[string]interface{} `json:"details"` +} + +type txNtfnResult TxNtfn + +// Enforce that TxNtfn satisfies the Notification interface. +var _ Notification = &TxNtfn{} + +// NewTxNtfn creates a new TxNtfn. +func NewTxNtfn(account string, details map[string]interface{}) *TxNtfn { + return &TxNtfn{ + Account: account, + Details: details, + } +} + +// Id satisifies the Notification interface by returning the id of the +// notification. +func (n *TxNtfn) Id() interface{} { + return TxNtfnId +} + +// MarshalJSON returns the JSON encoding of n. Part of the Notification +// interface. +func (n *TxNtfn) MarshalJSON() ([]byte, error) { + id := n.Id() + reply := btcjson.Reply{ + Result: *n, + Id: &id, + } + return json.Marshal(reply) +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the Notification interface. +func (n *TxNtfn) UnmarshalJSON(b []byte) error { + var ntfn struct { + Result txNtfnResult `json:"result"` + Error *btcjson.Error `json:"error"` + Id interface{} `json:"id"` + } + if err := json.Unmarshal(b, &ntfn); err != nil { + return err + } + + // Notification IDs must match expected. + if n.Id() != ntfn.Id { + return ErrNtfnUnexpected + } + + *n = TxNtfn(ntfn.Result) + return nil +} From b29f112f05eaf541de73ae8707d2ea7f895c0637 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 2 Dec 2013 17:32:36 -0500 Subject: [PATCH 12/76] go fmt --- notifications.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifications.go b/notifications.go index e2a9c0c4..55ecd3be 100644 --- a/notifications.go +++ b/notifications.go @@ -267,7 +267,7 @@ func (n *TxMinedNtfn) UnmarshalJSON(b []byte) error { // TxNtfn is a type handling custom marshaling and // unmarshaling of newtx JSON websocket notifications. type TxNtfn struct { - Account string `json:"account"` + Account string `json:"account"` Details map[string]interface{} `json:"details"` } From dda0cce06f94c8186d6c1301d8804947ee2fd82f Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 10 Dec 2013 16:14:35 -0500 Subject: [PATCH 13/76] Add getaddressbalance extension. --- cmds.go | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/cmds.go b/cmds.go index 00134f9b..7cfe0b66 100644 --- a/cmds.go +++ b/cmds.go @@ -14,6 +14,7 @@ import ( func init() { btcjson.RegisterCustomCmd("createencryptedwallet", parseCreateEncryptedWalletCmd) + btcjson.RegisterCustomCmd("getaddressbalance", parseGetAddressBalanceCmd) btcjson.RegisterCustomCmd("getbalances", parseGetBalancesCmd) btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd) btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd) @@ -843,3 +844,117 @@ func (cmd *ListAllTransactionsCmd) UnmarshalJSON(b []byte) error { *cmd = *concreteCmd return nil } + +// GetAddressBalanceCmd is a type handling custom marshaling +// and unmarshaling of getaddressbalance JSON websocket extension +// commands. +type GetAddressBalanceCmd struct { + id interface{} + Address string + Minconf int +} + +// Enforce that GetAddressBalanceCmd satisifies the btcjson.Cmd +// interface. +var _ btcjson.Cmd = &GetAddressBalanceCmd{} + +// parseGetAddressBalanceCmd parses a GetAddressBalanceCmd into a concrete +// type satisifying the btcjson.Cmd interface. This is used when +// registering the custom command with the btcjson parser. +func parseGetAddressBalanceCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + // Length of param slice must be minimum 1 (one required parameter) + // and maximum 2 (1 optional parameter). + if len(r.Params) < 1 || len(r.Params) > 2 { + return nil, btcjson.ErrInvalidParams + } + + address, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("address must be a string") + } + + if len(r.Params) == 1 { + // No optional params. + return NewGetAddressBalanceCmd(r.Id, address) + } + + // 1 optional param for minconf. + fminConf, ok := r.Params[1].(float64) + if !ok { + return nil, errors.New("first optional parameter minconf must be a number") + } + return NewGetAddressBalanceCmd(r.Id, address, int(fminConf)) +} + +// NewGetAddressBalanceCmd creates a new GetAddressBalanceCmd. +func NewGetAddressBalanceCmd(id interface{}, address string, + optArgs ...int) (*GetAddressBalanceCmd, error) { + + // Optional arguments set to their default values. + minconf := 1 + + if len(optArgs) > 1 { + return nil, btcjson.ErrInvalidParams + } + + if len(optArgs) == 1 { + minconf = optArgs[0] + } + + return &GetAddressBalanceCmd{ + id: id, + Address: address, + Minconf: minconf, + }, nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *GetAddressBalanceCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *GetAddressBalanceCmd) Method() string { + return "getaddressbalance" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *GetAddressBalanceCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "getaddressbalance", + Id: cmd.id, + Params: []interface{}{ + cmd.Address, + }, + } + + if cmd.Minconf != 1 { + raw.Params = append(raw.Params, cmd.Minconf) + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *GetAddressBalanceCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseListAllTransactionsCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*GetAddressBalanceCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} From b23acb632acb927a32cddfcb81621641a18f4481 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 10 Dec 2013 19:10:01 -0600 Subject: [PATCH 14/76] Add support for TravisCI. --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..ae71c02f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: go +go: release +install: go get -d -t -v ./... From 630d38b1b91215e711868593790ddcd1e50161ec Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 11 Dec 2013 12:15:32 -0500 Subject: [PATCH 15/76] Add README. --- README.md | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..77d7ee2f --- /dev/null +++ b/README.md @@ -0,0 +1,88 @@ +btcws +===== + +[![Build Status](https://travis-ci.org/conformal/btcws.png?branch=master)] +(https://travis-ci.org/conformal/btcws) + +Package btcws implements extensions to the standard bitcoind JSON-RPC +API for the btcd suite of programs (btcd, btcwallet, and btcgui). +Importing this package registers all implemented custom requests with +btcjson (using btcjson.RegisterCustomCmd). + +## Sample Use +```Go +// Client Side +import ( + "code.google.com/p/go.net/websocket" + "github.com/conformal/btcws" +) + +// Create rescan command. +id := 0 +addrs := map[string]struct{}{ + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": struct{}, +} +cmd, err := btcws.NewRescanCmd(id, 270000, addrs) + +// Set up a handler for a reply with id 0. +AddReplyHandler(id, func(reply map[string]interface{}) { + // Deal with reply. +}) + +// JSON marshal and send rescan request to websocket connection. +websocket.JSON.Send(btcdWSConn, cmd) + + +// Server Side +import ( + "code.google.com/p/go.net/websocket" + "github.com/conformal/btcjson" + "github.com/conformal/btcws" +) + +// Get marshaled request. +var b []byte +err := websocket.Message.Receive(clientWSConn, &b) + +// Parse marshaled command. +cmd, err := btcjson.ParseMarshaledCmd(b) + +// If this is a rescan command, handle and reply. +rcmd, ok := cmd.(*btcws.RescanCmd) +if ok { + // Do stuff + var reply []byte + err := websocket.Message.Send(clientWSConn, reply) +} + +``` + +## Installation + +```bash +$ go get github.com/conformal/btcws +``` + +## GPG Verification Key + +All official release tags are signed by Conformal so users can ensure the code +has not been tampered with and is coming from Conformal. To verify the +signature perform the following: + +- Download the public key from the Conformal website at + https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt + +- Import the public key into your GPG keyring: + ```bash + gpg --import GIT-GPG-KEY-conformal.txt + ``` + +- Verify the release tag with the following command where `TAG_NAME` is a + placeholder for the specific tag: + ```bash + git tag -v TAG_NAME + ``` + +## License + +Package btcws is licensed under the liberal ISC License. From 2731634dda1557cb22a7ae3b335ca4b31b8e03a1 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 13 Dec 2013 10:58:30 -0500 Subject: [PATCH 16/76] Implement notifications that actually follow the JSON-RPC spec. This changes notifications to JSON-RPC Requests, rather than Responses, that also satisify the btcjson.Cmd interface and are registered with btcjson's parser. This prevents issues where JSON-RPC Response IDs clash due to a client using the same ID as what an old notification used. As this changes the API, and thus, requires notification handlers to be modified, the remaining missing notifications used by btcwallet have been implemented. Applications parsing these notifications, such as btcgui, can now use a common handler function signature for all notifications. Test coverage for all notifications has been added (excluding testing for badly-marshaled notifications with wrong numbers of parameters, or wrong types). Fixes #2. --- notifications.go | 720 ++++++++++++++++++++++++++++++++---------- notifications_test.go | 161 ++++++++++ test_coverage.txt | 107 +++++++ 3 files changed, 825 insertions(+), 163 deletions(-) create mode 100644 notifications_test.go create mode 100644 test_coverage.txt diff --git a/notifications.go b/notifications.go index 55ecd3be..c8c7cc68 100644 --- a/notifications.go +++ b/notifications.go @@ -11,88 +11,161 @@ import ( ) var ( - // ErrNtfnUnexpected describes an error where an unexpected - // notification is received when unmarshaling into a concrete - // Notification variable. - ErrNtfnUnexpected = errors.New("notification unexpected") - - // ErrNtfnNotFound describes an error where a parser does not - // handle unmarshaling a notification. - ErrNtfnNotFound = errors.New("notification not found") + // ErrNotANtfn describes an error where a JSON-RPC Request + // object cannot be successfully parsed as a notification + // due to having an ID. + ErrNotANtfn = errors.New("notifications may not have IDs") ) const ( - // BlockConnectedNtfnId is the id of the btcd blockconnected + // AccountBalanceNtfnMethod is the method of the btcwallet + // accountbalance notification. + AccountBalanceNtfnMethod = "accountbalance" + + // BlockConnectedNtfnMethod is the method of the btcd + // blockconnected notification. + BlockConnectedNtfnMethod = "blockconnected" + + // BlockDisconnectedNtfnMethod is the method of the btcd + // blockdisconnected notification. + BlockDisconnectedNtfnMethod = "blockdisconnected" + + // BtcdConnectedNtfnMethod is the method of the btcwallet + // btcdconnected notification. + BtcdConnectedNtfnMethod = "btcdconnected" + + // TxMinedNtfnMethod is the method of the btcd txmined // notification. - BlockConnectedNtfnId = "btcd:blockconnected" + TxMinedNtfnMethod = "txmined" - // BlockDisconnectedNtfnId is the id of the btcd blockdisconnected + // TxNtfnMethod is the method of the btcwallet newtx // notification. - BlockDisconnectedNtfnId = "btcd:blockdisconnected" + TxNtfnMethod = "newtx" - // TxMinedNtfnId is the id of the btcd txmined notification. - TxMinedNtfnId = "btcd:txmined" - - // TxNtfnId is the id of the btcwallet newtx notification. - TxNtfnId = "btcwallet:newtx" + // WalletLockStateNtfnMethod is the method of the btcwallet + // walletlockstate notification. + WalletLockStateNtfnMethod = "walletlockstate" ) -type newNtfnFn func() Notification - -func newBlockConnectedNtfn() Notification { - return &BlockConnectedNtfn{} +// Register notifications with btcjson. +func init() { + btcjson.RegisterCustomCmd(AccountBalanceNtfnMethod, parseAccountBalanceNtfn) + btcjson.RegisterCustomCmd(BlockConnectedNtfnMethod, parseBlockConnectedNtfn) + btcjson.RegisterCustomCmd(BlockDisconnectedNtfnMethod, parseBlockDisconnectedNtfn) + btcjson.RegisterCustomCmd(BtcdConnectedNtfnMethod, parseBtcdConnectedNtfn) + btcjson.RegisterCustomCmd(TxMinedNtfnMethod, parseTxMinedNtfn) + btcjson.RegisterCustomCmd(TxNtfnMethod, parseTxNtfn) + btcjson.RegisterCustomCmd(WalletLockStateNtfnMethod, parseWalletLockStateNtfn) } -func newBlockDisconnectedNtfn() Notification { - return &BlockDisconnectedNtfn{} +// AccountBalanceNtfn is a type handling custom marshaling and +// unmarshaling of accountbalance JSON websocket notifications. +type AccountBalanceNtfn struct { + Account string + Balance float64 + Confirmed bool // Whether Balance is confirmed or unconfirmed. } -func newTxMinedNtfn() Notification { - return &TxMinedNtfn{} -} +// Enforce that AccountBalanceNtfn satisifes the btcjson.Cmd interface. +var _ btcjson.Cmd = &AccountBalanceNtfn{} -func newTxNtfn() Notification { - return &TxNtfn{} -} +// NewAccountBalanceNtfn creates a new AccountBalanceNtfn. +func NewAccountBalanceNtfn(account string, balance float64, + confirmed bool) *AccountBalanceNtfn { -var newNtfnFns = map[string]newNtfnFn{ - BlockConnectedNtfnId: newBlockConnectedNtfn, - BlockDisconnectedNtfnId: newBlockDisconnectedNtfn, - TxMinedNtfnId: newTxMinedNtfn, - TxNtfnId: newTxNtfn, -} - -// ParseMarshaledNtfn attempts to unmarshal a marshaled notification -// into the notification described by id. -func ParseMarshaledNtfn(id string, b []byte) (Notification, error) { - if newFn, ok := newNtfnFns[id]; ok { - n := newFn() - if err := n.UnmarshalJSON(b); err != nil { - return nil, err - } - return n, nil + return &AccountBalanceNtfn{ + Account: account, + Balance: balance, + Confirmed: confirmed, } - return nil, ErrNtfnNotFound } -// Notification is an interface implemented by all notification types. -type Notification interface { - json.Marshaler - json.Unmarshaler - Id() interface{} +// parseAccountBalanceNtfn parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the notification +// with the btcjson parser. +func parseAccountBalanceNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 3 { + return nil, btcjson.ErrWrongNumberOfParams + } + + account, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter account must be a string") + } + balance, ok := r.Params[1].(float64) + if !ok { + return nil, errors.New("second parameter balance must be a number") + } + confirmed, ok := r.Params[2].(bool) + if !ok { + return nil, errors.New("third parameter confirmed must be a boolean") + } + + return NewAccountBalanceNtfn(account, balance, confirmed), nil +} + +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *AccountBalanceNtfn) Id() interface{} { + return nil +} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *AccountBalanceNtfn) Method() string { + return AccountBalanceNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd +// interface. +func (n *AccountBalanceNtfn) MarshalJSON() ([]byte, error) { + ntfn := btcjson.Message{ + Jsonrpc: "1.0", + Method: n.Method(), + Params: []interface{}{ + n.Account, + n.Balance, + n.Confirmed, + }, + } + return json.Marshal(ntfn) +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the btcjson.Cmd interface. +func (n *AccountBalanceNtfn) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newNtfn, err := parseAccountBalanceNtfn(&r) + if err != nil { + return err + } + + concreteNtfn, ok := newNtfn.(*AccountBalanceNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn + return nil } // BlockConnectedNtfn is a type handling custom marshaling and // unmarshaling of blockconnected JSON websocket notifications. type BlockConnectedNtfn struct { - Hash string `json:"hash"` - Height int32 `json:"height"` + Hash string + Height int32 } -type blockConnectedResult BlockConnectedNtfn - -// Enforce that BlockConnectedNtfn satisfies the Notification interface. -var _ Notification = &BlockConnectedNtfn{} +// Enforce that BlockConnectedNtfn satisfies the btcjson.Cmd interface. +var _ btcjson.Cmd = &BlockConnectedNtfn{} // NewBlockConnectedNtfn creates a new BlockConnectedNtfn. func NewBlockConnectedNtfn(hash string, height int32) *BlockConnectedNtfn { @@ -102,57 +175,89 @@ func NewBlockConnectedNtfn(hash string, height int32) *BlockConnectedNtfn { } } -// Id satisifies the Notification interface by returning the id of the -// notification. -func (n *BlockConnectedNtfn) Id() interface{} { - return BlockConnectedNtfnId +// parseBlockConnectedNtfn parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the notification +// with the btcjson parser. +func parseBlockConnectedNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 2 { + return nil, btcjson.ErrWrongNumberOfParams + } + + hash, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter hash must be a string") + } + fheight, ok := r.Params[1].(float64) + if !ok { + return nil, errors.New("second parameter height must be a number") + } + + return NewBlockConnectedNtfn(hash, int32(fheight)), nil } -// MarshalJSON returns the JSON encoding of n. Part of the Notification +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *BlockConnectedNtfn) Id() interface{} { + return nil +} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *BlockConnectedNtfn) Method() string { + return BlockConnectedNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *BlockConnectedNtfn) MarshalJSON() ([]byte, error) { - id := n.Id() - reply := btcjson.Reply{ - Result: *n, - Id: &id, + ntfn := btcjson.Message{ + Jsonrpc: "1.0", + Method: n.Method(), + Params: []interface{}{ + n.Hash, + n.Height, + }, } - return json.Marshal(reply) + return json.Marshal(ntfn) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of -// the Notification interface. +// the btcjson.Cmd interface. func (n *BlockConnectedNtfn) UnmarshalJSON(b []byte) error { - var ntfn struct { - Result blockConnectedResult `json:"result"` - Error *btcjson.Error `json:"error"` - Id interface{} `json:"id"` - } - if err := json.Unmarshal(b, &ntfn); err != nil { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { return err } - // Notification IDs must match expected. - if n.Id() != ntfn.Id { - return ErrNtfnUnexpected + newNtfn, err := parseBlockConnectedNtfn(&r) + if err != nil { + return err } - *n = BlockConnectedNtfn(ntfn.Result) + concreteNtfn, ok := newNtfn.(*BlockConnectedNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn return nil } // BlockDisconnectedNtfn is a type handling custom marshaling and // unmarshaling of blockdisconnected JSON websocket notifications. type BlockDisconnectedNtfn struct { - Hash string `json:"hash"` - Height int32 `json:"height"` + Hash string + Height int32 } -type blockDisconnectedResult BlockDisconnectedNtfn +// Enforce that BlockDisconnectedNtfn satisfies the btcjson.Cmd interface. +var _ btcjson.Cmd = &BlockDisconnectedNtfn{} -// Enforce that BlockDisconnectedNtfn satisfies the Notification interface. -var _ Notification = &BlockDisconnectedNtfn{} - -// NewBlockDisconnectedNtfn creates a new BlockConnectedNtfn. +// NewBlockDisconnectedNtfn creates a new BlockDisconnectedNtfn. func NewBlockDisconnectedNtfn(hash string, height int32) *BlockDisconnectedNtfn { return &BlockDisconnectedNtfn{ Hash: hash, @@ -160,58 +265,172 @@ func NewBlockDisconnectedNtfn(hash string, height int32) *BlockDisconnectedNtfn } } -// Id satisifies the Notification interface by returning the id of the -// notification. -func (n *BlockDisconnectedNtfn) Id() interface{} { - return BlockDisconnectedNtfnId +// parseBlockDisconnectedNtfn parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the notification +// with the btcjson parser. +func parseBlockDisconnectedNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 2 { + return nil, btcjson.ErrWrongNumberOfParams + } + + hash, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter hash must be a string") + } + fheight, ok := r.Params[1].(float64) + if !ok { + return nil, errors.New("second parameter height must be a number") + } + + return NewBlockDisconnectedNtfn(hash, int32(fheight)), nil } -// MarshalJSON returns the JSON encoding of n. Part of the Notification +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *BlockDisconnectedNtfn) Id() interface{} { + return nil +} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *BlockDisconnectedNtfn) Method() string { + return BlockDisconnectedNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *BlockDisconnectedNtfn) MarshalJSON() ([]byte, error) { - id := n.Id() - reply := btcjson.Reply{ - Result: *n, - Id: &id, + ntfn := btcjson.Message{ + Jsonrpc: "1.0", + Method: n.Method(), + Params: []interface{}{ + n.Hash, + n.Height, + }, } - return json.Marshal(reply) + return json.Marshal(ntfn) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of -// the Notification interface. +// the btcjson.Cmd interface. func (n *BlockDisconnectedNtfn) UnmarshalJSON(b []byte) error { - var ntfn struct { - Result blockDisconnectedResult `json:"result"` - Error *btcjson.Error `json:"error"` - Id interface{} `json:"id"` - } - if err := json.Unmarshal(b, &ntfn); err != nil { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { return err } - // Notification IDs must match expected. - if n.Id() != ntfn.Id { - return ErrNtfnUnexpected + newNtfn, err := parseBlockDisconnectedNtfn(&r) + if err != nil { + return err } - *n = BlockDisconnectedNtfn(ntfn.Result) + concreteNtfn, ok := newNtfn.(*BlockDisconnectedNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn + return nil +} + +// BtcdConnectedNtfn is a type handling custom marshaling and +// unmarshaling of btcdconnected JSON websocket notifications. +type BtcdConnectedNtfn struct { + Connected bool +} + +// Enforce that BtcdConnectedNtfn satisifies the btcjson.Cmd +// interface. +var _ btcjson.Cmd = &BtcdConnectedNtfn{} + +// NewBtcdConnectedNtfn creates a new BtcdConnectedNtfn. +func NewBtcdConnectedNtfn(connected bool) *BtcdConnectedNtfn { + return &BtcdConnectedNtfn{connected} +} + +// parseBtcdConnectedNtfn parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the notification +// with the btcjson parser. +func parseBtcdConnectedNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 1 { + return nil, btcjson.ErrWrongNumberOfParams + } + + connected, ok := r.Params[0].(bool) + if !ok { + return nil, errors.New("first parameter connected is not a boolean") + } + + return NewBtcdConnectedNtfn(connected), nil +} + +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *BtcdConnectedNtfn) Id() interface{} { + return nil +} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *BtcdConnectedNtfn) Method() string { + return BtcdConnectedNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd +// interface. +func (n *BtcdConnectedNtfn) MarshalJSON() ([]byte, error) { + ntfn := btcjson.Message{ + Jsonrpc: "1.0", + Method: n.Method(), + Params: []interface{}{ + n.Connected, + }, + } + return json.Marshal(ntfn) +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the btcjson.Cmd interface. +func (n *BtcdConnectedNtfn) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newNtfn, err := parseTxMinedNtfn(&r) + if err != nil { + return err + } + + concreteNtfn, ok := newNtfn.(*BtcdConnectedNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn return nil } // TxMinedNtfn is a type handling custom marshaling and // unmarshaling of txmined JSON websocket notifications. type TxMinedNtfn struct { - TxID string `json:"txid"` - BlockHash string `json:"blockhash"` - BlockHeight int32 `json:"blockheight"` - BlockTime int64 `json:"blocktime"` - Index int `json:"index"` + TxID string + BlockHash string + BlockHeight int32 + BlockTime int64 + Index int } -type txMinedResult TxMinedNtfn - -// Enforce that TxMinedNtfn satisfies the Notification interface. -var _ Notification = &TxMinedNtfn{} +// Enforce that TxMinedNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &TxMinedNtfn{} // NewTxMinedNtfn creates a new TxMinedNtfn. func NewTxMinedNtfn(txid, blockhash string, blockheight int32, @@ -226,55 +445,103 @@ func NewTxMinedNtfn(txid, blockhash string, blockheight int32, } } -// Id satisifies the Notification interface by returning the id of the -// notification. -func (n *TxMinedNtfn) Id() interface{} { - return TxMinedNtfnId +// parseTxMinedNtfn parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the notification +// with the btcjson parser. +func parseTxMinedNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 5 { + return nil, btcjson.ErrWrongNumberOfParams + } + + txid, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter txid must be a string") + } + blockhash, ok := r.Params[1].(string) + if !ok { + return nil, errors.New("second parameter blockhash must be a string") + } + fblockheight, ok := r.Params[2].(float64) + if !ok { + return nil, errors.New("third parameter blockheight must be a number") + } + fblocktime, ok := r.Params[3].(float64) + if !ok { + return nil, errors.New("fourth parameter blocktime must be a number") + } + findex, ok := r.Params[4].(float64) + if !ok { + return nil, errors.New("fifth parameter index must be a number") + } + + return NewTxMinedNtfn(txid, blockhash, int32(fblockheight), + int64(fblocktime), int(findex)), nil } -// MarshalJSON returns the JSON encoding of n. Part of the Notification +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *TxMinedNtfn) Id() interface{} { + return nil +} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *TxMinedNtfn) Method() string { + return TxMinedNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *TxMinedNtfn) MarshalJSON() ([]byte, error) { - id := n.Id() - reply := btcjson.Reply{ - Result: *n, - Id: &id, + ntfn := btcjson.Message{ + Jsonrpc: "1.0", + Method: n.Method(), + Params: []interface{}{ + n.TxID, + n.BlockHash, + n.BlockHeight, + n.BlockTime, + n.Index, + }, } - return json.Marshal(reply) + return json.Marshal(ntfn) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of -// the Notification interface. +// the btcjson.Cmd interface. func (n *TxMinedNtfn) UnmarshalJSON(b []byte) error { - var ntfn struct { - Result txMinedResult `json:"result"` - Error *btcjson.Error `json:"error"` - Id interface{} `json:"id"` - } - if err := json.Unmarshal(b, &ntfn); err != nil { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { return err } - // Notification IDs must match expected. - if n.Id() != ntfn.Id { - return ErrNtfnUnexpected + newNtfn, err := parseTxMinedNtfn(&r) + if err != nil { + return err } - *n = TxMinedNtfn(ntfn.Result) + concreteNtfn, ok := newNtfn.(*TxMinedNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn return nil } // TxNtfn is a type handling custom marshaling and // unmarshaling of newtx JSON websocket notifications. type TxNtfn struct { - Account string `json:"account"` - Details map[string]interface{} `json:"details"` + Account string + Details map[string]interface{} } -type txNtfnResult TxNtfn - -// Enforce that TxNtfn satisfies the Notification interface. -var _ Notification = &TxNtfn{} +// Enforce that TxNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &TxNtfn{} // NewTxNtfn creates a new TxNtfn. func NewTxNtfn(account string, details map[string]interface{}) *TxNtfn { @@ -284,40 +551,167 @@ func NewTxNtfn(account string, details map[string]interface{}) *TxNtfn { } } -// Id satisifies the Notification interface by returning the id of the -// notification. -func (n *TxNtfn) Id() interface{} { - return TxNtfnId +// parseTxNtfn parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the notification +// with the btcjson parser. +func parseTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 2 { + return nil, btcjson.ErrWrongNumberOfParams + } + + account, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter account must be a string") + } + details, ok := r.Params[1].(map[string]interface{}) + if !ok { + return nil, errors.New("second parameter details must be a JSON object") + } + + return NewTxNtfn(account, details), nil } -// MarshalJSON returns the JSON encoding of n. Part of the Notification +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *TxNtfn) Id() interface{} { + return nil +} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *TxNtfn) Method() string { + return TxNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *TxNtfn) MarshalJSON() ([]byte, error) { - id := n.Id() - reply := btcjson.Reply{ - Result: *n, - Id: &id, + ntfn := btcjson.Message{ + Jsonrpc: "1.0", + Method: n.Method(), + Params: []interface{}{ + n.Account, + n.Details, + }, } - return json.Marshal(reply) + return json.Marshal(ntfn) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of -// the Notification interface. +// the btcjson.Cmd interface. func (n *TxNtfn) UnmarshalJSON(b []byte) error { - var ntfn struct { - Result txNtfnResult `json:"result"` - Error *btcjson.Error `json:"error"` - Id interface{} `json:"id"` - } - if err := json.Unmarshal(b, &ntfn); err != nil { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { return err } - // Notification IDs must match expected. - if n.Id() != ntfn.Id { - return ErrNtfnUnexpected + newNtfn, err := parseTxNtfn(&r) + if err != nil { + return err } - *n = TxNtfn(ntfn.Result) + concreteNtfn, ok := newNtfn.(*TxNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn + return nil +} + +// WalletLockStateNtfn is a type handling custom marshaling and +// unmarshaling of walletlockstate JSON websocket notifications. +type WalletLockStateNtfn struct { + Account string + Locked bool +} + +// Enforce that WalletLockStateNtfnMethod satisifies the btcjson.Cmd +// interface. +var _ btcjson.Cmd = &WalletLockStateNtfn{} + +// NewWalletLockStateNtfn creates a new WalletLockStateNtfn. +func NewWalletLockStateNtfn(account string, + locked bool) *WalletLockStateNtfn { + + return &WalletLockStateNtfn{ + Account: account, + Locked: locked, + } +} + +// parseWalletLockStateNtfn parses a RawCmd into a concrete type +// satisifying the btcjson.Cmd interface. This is used when registering +// the notification with the btcjson parser. +func parseWalletLockStateNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 2 { + return nil, btcjson.ErrWrongNumberOfParams + } + + account, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter account must be a string") + } + locked, ok := r.Params[1].(bool) + if !ok { + return nil, errors.New("second parameter locked must be a boolean") + } + + return NewWalletLockStateNtfn(account, locked), nil +} + +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *WalletLockStateNtfn) Id() interface{} { + return nil +} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *WalletLockStateNtfn) Method() string { + return WalletLockStateNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd +// interface. +func (n *WalletLockStateNtfn) MarshalJSON() ([]byte, error) { + ntfn := btcjson.Message{ + Jsonrpc: "1.0", + Method: n.Method(), + Params: []interface{}{ + n.Account, + n.Locked, + }, + } + return json.Marshal(ntfn) +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the btcjson.Cmd interface. +func (n *WalletLockStateNtfn) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newNtfn, err := parseWalletLockStateNtfn(&r) + if err != nil { + return err + } + + concreteNtfn, ok := newNtfn.(*WalletLockStateNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn return nil } diff --git a/notifications_test.go b/notifications_test.go new file mode 100644 index 00000000..a3de913a --- /dev/null +++ b/notifications_test.go @@ -0,0 +1,161 @@ +// Copyright (c) 2013 Conformal Systems LLC. +// Use of this source code is governed by an ISC +// license that can be found in the LICENSE file. + +package btcws_test + +import ( + "github.com/conformal/btcjson" + "github.com/conformal/btcws" + "github.com/davecgh/go-spew/spew" + "reflect" + "testing" +) + +var ntfntests = []struct { + name string + f func() btcjson.Cmd + result btcjson.Cmd // after marshal and unmarshal +}{ + { + name: "accountbalance", + f: func() btcjson.Cmd { + return btcws.NewAccountBalanceNtfn("abcde", 1.2345, true) + }, + result: &btcws.AccountBalanceNtfn{ + Account: "abcde", + Balance: 1.2345, + Confirmed: true, + }, + }, + { + name: "blockconnected", + f: func() btcjson.Cmd { + return btcws.NewBlockConnectedNtfn( + "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", + 153469) + }, + result: &btcws.BlockConnectedNtfn{ + Hash: "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", + Height: 153469, + }, + }, + { + name: "blockdisconnected", + f: func() btcjson.Cmd { + return btcws.NewBlockDisconnectedNtfn( + "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", + 153469) + }, + result: &btcws.BlockDisconnectedNtfn{ + Hash: "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", + Height: 153469, + }, + }, + { + name: "btcdconnected", + f: func() btcjson.Cmd { + return btcws.NewBtcdConnectedNtfn(true) + }, + result: &btcws.BtcdConnectedNtfn{ + Connected: true, + }, + }, + { + name: "txmined", + f: func() btcjson.Cmd { + return btcws.NewTxMinedNtfn( + "062f2b5f7d28c787e0f3aee382132241cd590efb7b83bd2c7f506de5aa4ef275", + "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", + 153469, + 1386944019, + 0) + }, + result: &btcws.TxMinedNtfn{ + TxID: "062f2b5f7d28c787e0f3aee382132241cd590efb7b83bd2c7f506de5aa4ef275", + BlockHash: "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", + BlockHeight: 153469, + BlockTime: 1386944019, + Index: 0, + }, + }, + { + name: "newtx", + f: func() btcjson.Cmd { + details := map[string]interface{}{ + "key1": float64(12345), + "key2": true, + "key3": "lalala", + "key4": []interface{}{"abcde", float64(12345)}, + } + return btcws.NewTxNtfn("abcde", details) + }, + result: &btcws.TxNtfn{ + Account: "abcde", + Details: map[string]interface{}{ + "key1": float64(12345), + "key2": true, + "key3": "lalala", + "key4": []interface{}{"abcde", float64(12345)}, + }, + }, + }, + { + name: "walletlockstate", + f: func() btcjson.Cmd { + return btcws.NewWalletLockStateNtfn("abcde", true) + }, + result: &btcws.WalletLockStateNtfn{ + Account: "abcde", + Locked: true, + }, + }, +} + +func TestNtfns(t *testing.T) { + for _, test := range ntfntests { + // create notification. + n := test.f() + + // verify that id is nil. + if n.Id() != nil { + t.Error("%s: notification should not have non-nil id %v", + test.name, n.Id()) + continue + } + + mn, err := n.MarshalJSON() + if err != nil { + t.Errorf("%s: failed to marshal notification: %v", + test.name, err) + continue + } + + n2, err := btcjson.ParseMarshaledCmd(mn) + if err != nil { + t.Errorf("%s: failed to ummarshal cmd: %v", + test.name, err) + continue + } + + if !reflect.DeepEqual(test.result, n2) { + t.Errorf("%s: unmarshal not as expected. "+ + "got %v wanted %v", test.name, spew.Sdump(n2), + spew.Sdump(test.result)) + } + if !reflect.DeepEqual(n, n2) { + t.Errorf("%s: unmarshal not as we started with. "+ + "got %v wanted %v", test.name, spew.Sdump(n2), + spew.Sdump(n)) + } + + // Read marshaled notification back into n. Should still + // match result. + n.UnmarshalJSON(mn) + if !reflect.DeepEqual(test.result, n) { + t.Errorf("%s: unmarshal not as expected. "+ + "got %v wanted %v", test.name, spew.Sdump(n), + spew.Sdump(test.result)) + } + } +} diff --git a/test_coverage.txt b/test_coverage.txt new file mode 100644 index 00000000..4f123d4b --- /dev/null +++ b/test_coverage.txt @@ -0,0 +1,107 @@ + +github.com/conformal/btcws/cmds.go init 100.00% (10/10) +github.com/conformal/btcws/notifications.go init 100.00% (7/7) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxMinedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go parseTxMinedNtfn 70.00% (14/20) +github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) +github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 45.45% (5/11) +github.com/conformal/btcws/cmds.go parseRescanCmd 0.00% (0/18) +github.com/conformal/btcws/cmds.go parseNotifySpentCmd 0.00% (0/15) +github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 0.00% (0/13) +github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 0.00% (0/12) +github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go GetBalancesCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 0.00% (0/11) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 0.00% (0/8) +github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 0.00% (0/8) +github.com/conformal/btcws/cmds.go NewRescanCmd 0.00% (0/6) +github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 0.00% (0/6) +github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 0.00% (0/6) +github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 0.00% (0/6) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 0.00% (0/4) +github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 0.00% (0/4) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 0.00% (0/4) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 0.00% (0/4) +github.com/conformal/btcws/cmds.go parseGetBalancesCmd 0.00% (0/3) +github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 0.00% (0/3) +github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 0.00% (0/3) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 0.00% (0/2) +github.com/conformal/btcws/cmds.go GetBalancesCmd.MarshalJSON 0.00% (0/2) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 0.00% (0/2) +github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 0.00% (0/2) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 0.00% (0/2) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 0.00% (0/2) +github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewNotifySpentCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewGetBalancesCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetBalancesCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go RescanCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go RescanCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetBalancesCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 0.00% (0/1) +github.com/conformal/btcws -------------------------------------- 32.39% (161/497) + From 2be94151a37ebf88562d93f5f7932d5f4cb1e3c2 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 13 Dec 2013 12:30:23 -0500 Subject: [PATCH 17/76] Add positive tests for commands. Fixes #3. --- cmds_test.go | 276 ++++++++++++++++++++++++++++++++++++++++++++++ test_coverage.txt | 176 ++++++++++++++--------------- 2 files changed, 364 insertions(+), 88 deletions(-) create mode 100644 cmds_test.go diff --git a/cmds_test.go b/cmds_test.go new file mode 100644 index 00000000..46b21e04 --- /dev/null +++ b/cmds_test.go @@ -0,0 +1,276 @@ +// Copyright (c) 2013 Conformal Systems LLC. +// Use of this source code is governed by an ISC +// license that can be found in the LICENSE file. + +// this has to be in the real package so we can mock up structs +package btcws + +import ( + "github.com/conformal/btcdb" + "github.com/conformal/btcjson" + "github.com/conformal/btcwire" + "github.com/davecgh/go-spew/spew" + "reflect" + "testing" +) + +var cmdtests = []struct { + name string + f func() (btcjson.Cmd, error) + result btcjson.Cmd // after marshal and unmarshal +}{ + { + name: "createencryptedwallet", + f: func() (btcjson.Cmd, error) { + return NewCreateEncryptedWalletCmd( + float64(1), + "abcde", + "description", + "banana"), nil + }, + result: &CreateEncryptedWalletCmd{ + id: float64(1), + Account: "abcde", + Description: "description", + Passphrase: "banana", + }, + }, + { + name: "getaddressbalance no optargs", + f: func() (btcjson.Cmd, error) { + return NewGetAddressBalanceCmd( + float64(1), + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH") + }, + result: &GetAddressBalanceCmd{ + id: float64(1), + Address: "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", + Minconf: 1, + }, + }, + { + name: "getaddressbalance one optarg", + f: func() (btcjson.Cmd, error) { + return NewGetAddressBalanceCmd( + float64(1), + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", + 0) + }, + result: &GetAddressBalanceCmd{ + id: float64(1), + Address: "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", + Minconf: 0, + }, + }, + { + name: "getbalances", + f: func() (btcjson.Cmd, error) { + return NewGetBalancesCmd(float64(1)), nil + }, + result: &GetBalancesCmd{ + id: float64(1), + }, + }, + { + name: "getbestblock", + f: func() (btcjson.Cmd, error) { + return NewGetBestBlockCmd(float64(1)), nil + }, + result: &GetBestBlockCmd{ + id: float64(1), + }, + }, + { + name: "getcurrentnet", + f: func() (btcjson.Cmd, error) { + return NewGetCurrentNetCmd(float64(1)), nil + }, + result: &GetCurrentNetCmd{ + id: float64(1), + }, + }, + { + name: "listalltransactions no optargs", + f: func() (btcjson.Cmd, error) { + return NewListAllTransactionsCmd(float64(1)) + }, + result: &ListAllTransactionsCmd{ + id: float64(1), + Account: "", + }, + }, + { + name: "listalltransactions one optarg", + f: func() (btcjson.Cmd, error) { + return NewListAllTransactionsCmd( + float64(1), + "abcde") + }, + result: &ListAllTransactionsCmd{ + id: float64(1), + Account: "abcde", + }, + }, + { + name: "notifynewtxs", + f: func() (btcjson.Cmd, error) { + addrs := []string{ + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", + } + return NewNotifyNewTXsCmd( + float64(1), + addrs), nil + }, + result: &NotifyNewTXsCmd{ + id: float64(1), + Addresses: []string{ + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", + }, + }, + }, + { + name: "notifyspent", + f: func() (btcjson.Cmd, error) { + op := &btcwire.OutPoint{ + Hash: btcwire.ShaHash{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31}, + Index: 1, + } + return NewNotifySpentCmd(float64(1), op), nil + }, + result: &NotifySpentCmd{ + id: float64(1), + OutPoint: &btcwire.OutPoint{ + Hash: btcwire.ShaHash{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31}, + Index: 1, + }, + }, + }, + { + name: "rescan no optargs", + f: func() (btcjson.Cmd, error) { + addrs := map[string]struct{}{ + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": struct{}{}, + } + return NewRescanCmd( + float64(1), + 270000, + addrs) + }, + result: &RescanCmd{ + id: float64(1), + BeginBlock: 270000, + Addresses: map[string]struct{}{ + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": struct{}{}, + }, + EndBlock: btcdb.AllShas, + }, + }, + { + name: "rescan one optarg", + f: func() (btcjson.Cmd, error) { + addrs := map[string]struct{}{ + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": struct{}{}, + } + return NewRescanCmd( + float64(1), + 270000, + addrs, + 280000) + }, + result: &RescanCmd{ + id: float64(1), + BeginBlock: 270000, + Addresses: map[string]struct{}{ + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": struct{}{}, + }, + EndBlock: 280000, + }, + }, + { + name: "walletislocked no optargs", + f: func() (btcjson.Cmd, error) { + return NewWalletIsLockedCmd(float64(1)) + }, + result: &WalletIsLockedCmd{ + id: float64(1), + Account: "", + }, + }, + { + name: "walletislocked one optarg", + f: func() (btcjson.Cmd, error) { + return NewWalletIsLockedCmd( + float64(1), + "abcde") + }, + result: &WalletIsLockedCmd{ + id: float64(1), + Account: "abcde", + }, + }, +} + +func TestCmds(t *testing.T) { + for _, test := range cmdtests { + c, err := test.f() + if err != nil { + t.Errorf("%s: failed to run func: %v", + test.name, err) + continue + } + + mc, err := c.MarshalJSON() + if err != nil { + t.Errorf("%s: failed to marshal cmd: %v", + test.name, err) + continue + } + + c2, err := btcjson.ParseMarshaledCmd(mc) + if err != nil { + t.Errorf("%s: failed to ummarshal cmd: %v", + test.name, err) + continue + } + + if !reflect.DeepEqual(test.result, c2) { + t.Errorf("%s: unmarshal not as expected. "+ + "got %v wanted %v", test.name, spew.Sdump(c2), + spew.Sdump(test.result)) + } + if !reflect.DeepEqual(c, c2) { + t.Errorf("%s: unmarshal not as we started with. "+ + "got %v wanted %v", test.name, spew.Sdump(c2), + spew.Sdump(c)) + } + + // id from Id func must match result. + if c.Id() != test.result.Id() { + t.Errorf("%s: Id returned incorrect id. "+ + "got %v wanted %v", test.name, c.Id(), + test.result.Id()) + } + + // method from Method func must match result. + if c.Method() != test.result.Method() { + t.Errorf("%s: Method returned incorrect method. "+ + "got %v wanted %v", test.name, c.Method(), + test.result.Method()) + } + + // Read marshaled command back into c. Should still + // match result. + c.UnmarshalJSON(mc) + if !reflect.DeepEqual(test.result, c) { + t.Errorf("%s: unmarshal not as expected. "+ + "got %v wanted %v", test.name, spew.Sdump(c), + spew.Sdump(test.result)) + } + } +} diff --git a/test_coverage.txt b/test_coverage.txt index 4f123d4b..852136f0 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,107 +1,107 @@ github.com/conformal/btcws/cmds.go init 100.00% (10/10) github.com/conformal/btcws/notifications.go init 100.00% (7/7) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetBalancesCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBalancesCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBalancesCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBalancesCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 87.50% (7/8) +github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go parseRescanCmd 77.78% (14/18) +github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 75.00% (9/12) +github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go TxMinedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBalancesCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) github.com/conformal/btcws/notifications.go parseTxMinedNtfn 70.00% (14/20) +github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 69.23% (9/13) +github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (10/15) +github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) +github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) +github.com/conformal/btcws/cmds.go parseGetBalancesCmd 66.67% (2/3) github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) +github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 45.45% (5/11) -github.com/conformal/btcws/cmds.go parseRescanCmd 0.00% (0/18) -github.com/conformal/btcws/cmds.go parseNotifySpentCmd 0.00% (0/15) -github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 0.00% (0/13) -github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 0.00% (0/12) -github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go GetBalancesCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 0.00% (0/11) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 0.00% (0/8) -github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 0.00% (0/8) -github.com/conformal/btcws/cmds.go NewRescanCmd 0.00% (0/6) -github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 0.00% (0/6) -github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 0.00% (0/6) -github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 0.00% (0/6) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 0.00% (0/4) -github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 0.00% (0/4) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 0.00% (0/4) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 0.00% (0/4) -github.com/conformal/btcws/cmds.go parseGetBalancesCmd 0.00% (0/3) -github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 0.00% (0/3) -github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 0.00% (0/3) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 0.00% (0/2) -github.com/conformal/btcws/cmds.go GetBalancesCmd.MarshalJSON 0.00% (0/2) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 0.00% (0/2) -github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 0.00% (0/2) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 0.00% (0/2) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 0.00% (0/2) -github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewNotifySpentCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewGetBalancesCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetBalancesCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go RescanCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go RescanCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetBalancesCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 0.00% (0/1) -github.com/conformal/btcws -------------------------------------- 32.39% (161/497) +github.com/conformal/btcws -------------------------------------- 77.26% (384/497) From 86575afa9183734181a07fbfef8bf082ad355ad0 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 20 Dec 2013 15:00:31 -0500 Subject: [PATCH 18/76] Add listaddresstransactions extension. --- cmds.go | 118 +++++++++++++++++++++++++ cmds_test.go | 37 ++++++++ test_coverage.txt | 216 ++++++++++++++++++++++++---------------------- 3 files changed, 266 insertions(+), 105 deletions(-) diff --git a/cmds.go b/cmds.go index 7cfe0b66..59efa075 100644 --- a/cmds.go +++ b/cmds.go @@ -18,6 +18,7 @@ func init() { btcjson.RegisterCustomCmd("getbalances", parseGetBalancesCmd) btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd) btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd) + btcjson.RegisterCustomCmd("listaddresstransactions", parseListAddressTransactionsCmd) btcjson.RegisterCustomCmd("listalltransactions", parseListAllTransactionsCmd) btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd) btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd) @@ -745,6 +746,123 @@ func (cmd *WalletIsLockedCmd) UnmarshalJSON(b []byte) error { return nil } +type ListAddressTransactionsCmd struct { + id interface{} + Account string + Addresses []string +} + +// Enforce that ListAddressTransactionsCmd satisifies the btcjson.Cmd +// interface. +var _ btcjson.Cmd = &ListAddressTransactionsCmd{} + +// NewListAddressTransactionsCmd creates a new ListAddressTransactionsCmd. +func NewListAddressTransactionsCmd(id interface{}, addresses []string, + optArgs ...string) (*ListAddressTransactionsCmd, error) { + + if len(optArgs) > 1 { + return nil, btcjson.ErrTooManyOptArgs + } + + // Optional arguments set to their default values. + account := "" + + if len(optArgs) == 1 { + account = optArgs[0] + } + + return &ListAddressTransactionsCmd{ + id: id, + Account: account, + Addresses: addresses, + }, nil +} + +// parseListAddressTransactionsCmd parses a ListAddressTransactionsCmd into +// a concrete type satisifying the btcjson.Cmd interface. This is used +// when registering the custom command with the btcjson parser. +func parseListAddressTransactionsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) == 0 || len(r.Params) > 2 { + return nil, btcjson.ErrInvalidParams + } + + iaddrs, ok := r.Params[0].([]interface{}) + if !ok { + return nil, errors.New("first parameter must be a JSON array") + } + addresses := make([]string, len(iaddrs)) + for i := range iaddrs { + addr, ok := iaddrs[i].(string) + if !ok { + return nil, errors.New("first parameter must be an " + + "array of strings") + } + addresses[i] = addr + } + + if len(r.Params) == 1 { + // No optional parameters. + return NewListAddressTransactionsCmd(r.Id, addresses) + } + + account, ok := r.Params[1].(string) + if !ok { + return nil, errors.New("second parameter must be a string") + } + return NewListAddressTransactionsCmd(r.Id, addresses, account) +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *ListAddressTransactionsCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *ListAddressTransactionsCmd) Method() string { + return "listaddresstransactions" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *ListAddressTransactionsCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: cmd.Method(), + Id: cmd.id, + Params: []interface{}{ + cmd.Addresses, + }, + } + + if cmd.Account != "" { + raw.Params = append(raw.Params, cmd.Account) + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *ListAddressTransactionsCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseListAddressTransactionsCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*ListAddressTransactionsCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + // ListAllTransactionsCmd is a type handling custom marshaling and // unmarshaling of listalltransactions JSON websocket extension commands. type ListAllTransactionsCmd struct { diff --git a/cmds_test.go b/cmds_test.go index 46b21e04..6c50c4d3 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -89,6 +89,43 @@ var cmdtests = []struct { id: float64(1), }, }, + { + name: "listaddresstransactions no optargs", + f: func() (btcjson.Cmd, error) { + addrs := []string{ + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", + } + return NewListAddressTransactionsCmd( + float64(1), + addrs) + }, + result: &ListAddressTransactionsCmd{ + id: float64(1), + Account: "", + Addresses: []string{ + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", + }, + }, + }, + { + name: "listaddresstransactions one optarg", + f: func() (btcjson.Cmd, error) { + addrs := []string{ + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", + } + return NewListAddressTransactionsCmd( + float64(1), + addrs, + "abcde") + }, + result: &ListAddressTransactionsCmd{ + id: float64(1), + Account: "abcde", + Addresses: []string{ + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", + }, + }, + }, { name: "listalltransactions no optargs", f: func() (btcjson.Cmd, error) { diff --git a/test_coverage.txt b/test_coverage.txt index 852136f0..0548b2d9 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,107 +1,113 @@ -github.com/conformal/btcws/cmds.go init 100.00% (10/10) -github.com/conformal/btcws/notifications.go init 100.00% (7/7) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetBalancesCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBalancesCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBalancesCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBalancesCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 87.50% (7/8) -github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go parseRescanCmd 77.78% (14/18) -github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 75.00% (9/12) -github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxMinedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBalancesCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) -github.com/conformal/btcws/notifications.go parseTxMinedNtfn 70.00% (14/20) -github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 69.23% (9/13) -github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (10/15) -github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) -github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) -github.com/conformal/btcws/cmds.go parseGetBalancesCmd 66.67% (2/3) -github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) -github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 45.45% (5/11) -github.com/conformal/btcws -------------------------------------- 77.26% (384/497) +github.com/conformal/btcws/cmds.go init 100.00% (11/11) +github.com/conformal/btcws/notifications.go init 100.00% (7/7) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetBalancesCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBalancesCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBalancesCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBalancesCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 87.50% (7/8) +github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go parseRescanCmd 77.78% (14/18) +github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 76.47% (13/17) +github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 75.00% (9/12) +github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) +github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBalancesCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxMinedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go parseTxMinedNtfn 70.00% (14/20) +github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 69.23% (9/13) +github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (10/15) +github.com/conformal/btcws/cmds.go parseGetBalancesCmd 66.67% (2/3) +github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) +github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) +github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) +github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 45.45% (5/11) +github.com/conformal/btcws ---------------------------------------- 77.51% (417/538) From 87b7352008f8abbb8a4f79a69a49b2dd841637ac Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 30 Dec 2013 13:53:43 -0500 Subject: [PATCH 19/76] Add getunconfirmedbalance extension. --- cmds.go | 103 ++++++++++++++++++++++++++++++++++ cmds_test.go | 21 +++++++ test_coverage.txt | 138 ++++++++++++++++++++++++---------------------- 3 files changed, 196 insertions(+), 66 deletions(-) diff --git a/cmds.go b/cmds.go index 59efa075..550bdac4 100644 --- a/cmds.go +++ b/cmds.go @@ -18,6 +18,7 @@ func init() { btcjson.RegisterCustomCmd("getbalances", parseGetBalancesCmd) btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd) btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd) + btcjson.RegisterCustomCmd("getunconfirmedbalance", parseGetUnconfirmedBalanceCmd) btcjson.RegisterCustomCmd("listaddresstransactions", parseListAddressTransactionsCmd) btcjson.RegisterCustomCmd("listalltransactions", parseListAllTransactionsCmd) btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd) @@ -95,6 +96,108 @@ func (cmd *GetCurrentNetCmd) UnmarshalJSON(b []byte) error { return nil } +// GetUnconfirmedBalanceCmd is a type handling custom marshaling and +// unmarshaling of getunconfirmedbalance JSON websocket extension +// commands. +type GetUnconfirmedBalanceCmd struct { + id interface{} + Account string +} + +// Enforce that GetUnconfirmedBalanceCmd satisifies the btcjson.Cmd +// interface. +var _ btcjson.Cmd = &GetUnconfirmedBalanceCmd{} + +// NewGetUnconfirmedBalanceCmd creates a new GetUnconfirmedBalanceCmd. +func NewGetUnconfirmedBalanceCmd(id interface{}, + optArgs ...string) (*GetUnconfirmedBalanceCmd, error) { + + if len(optArgs) > 1 { + return nil, btcjson.ErrTooManyOptArgs + } + + // Optional parameters set to their defaults. + account := "" + + if len(optArgs) == 1 { + account = optArgs[0] + } + + return &GetUnconfirmedBalanceCmd{ + id: id, + Account: account, + }, nil +} + +// parseGetUnconfirmedBalanceCmd parses a RawCmd into a concrete type +// satisifying the btcjson.Cmd interface. This is used when registering +// the custom command with the btcjson parser. +func parseGetUnconfirmedBalanceCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) > 1 { + return nil, btcjson.ErrWrongNumberOfParams + } + + if len(r.Params) == 0 { + // No optional args. + return NewGetUnconfirmedBalanceCmd(r.Id) + } + + // One optional parameter for account. + account, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter account must be a string") + } + return NewGetUnconfirmedBalanceCmd(r.Id, account) +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *GetUnconfirmedBalanceCmd) Id() interface{} { + return cmd.id +} + +// Method satisifies the Cmd interface by returning the RPC method. +func (cmd *GetUnconfirmedBalanceCmd) Method() string { + return "getunconfirmedbalance" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *GetUnconfirmedBalanceCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "getunconfirmedbalance", + Id: cmd.id, + } + + if cmd.Account != "" { + raw.Params = append(raw.Params, cmd.Account) + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *GetUnconfirmedBalanceCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseGetUnconfirmedBalanceCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*GetUnconfirmedBalanceCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + // GetBestBlockCmd is a type handling custom marshaling and // unmarshaling of getbestblock JSON websocket extension // commands. diff --git a/cmds_test.go b/cmds_test.go index 6c50c4d3..a41a81b9 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -89,6 +89,27 @@ var cmdtests = []struct { id: float64(1), }, }, + { + name: "getunconfirmedbalance no optargs", + f: func() (btcjson.Cmd, error) { + return NewGetUnconfirmedBalanceCmd(float64(1)) + }, + result: &GetUnconfirmedBalanceCmd{ + id: float64(1), + Account: "", + }, + }, + { + name: "getunconfirmedbalance one optarg", + f: func() (btcjson.Cmd, error) { + return NewGetUnconfirmedBalanceCmd(float64(1), + "abcde") + }, + result: &GetUnconfirmedBalanceCmd{ + id: float64(1), + Account: "abcde", + }, + }, { name: "listaddresstransactions no optargs", f: func() (btcjson.Cmd, error) { diff --git a/test_coverage.txt b/test_coverage.txt index 0548b2d9..e7992e4b 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,113 +1,119 @@ -github.com/conformal/btcws/cmds.go init 100.00% (11/11) +github.com/conformal/btcws/cmds.go init 100.00% (12/12) github.com/conformal/btcws/notifications.go init 100.00% (7/7) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go GetBalancesCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewGetBalancesCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go GetBalancesCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetBalancesCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 87.50% (7/8) +github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go parseRescanCmd 77.78% (14/18) github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 76.47% (13/17) github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 75.00% (9/12) +github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 75.00% (6/8) github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) -github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBalancesCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxMinedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBalancesCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxMinedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go parseTxMinedNtfn 70.00% (14/20) github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 69.23% (9/13) github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (10/15) -github.com/conformal/btcws/cmds.go parseGetBalancesCmd 66.67% (2/3) github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) +github.com/conformal/btcws/cmds.go parseGetBalancesCmd 66.67% (2/3) github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) -github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 45.45% (5/11) -github.com/conformal/btcws ---------------------------------------- 77.51% (417/538) +github.com/conformal/btcws ---------------------------------------- 77.72% (443/570) From c06d4007feab97e1c29ec68a74312d5d51ad59fb Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 8 Jan 2014 09:44:11 -0500 Subject: [PATCH 20/76] Fix build for new btcjson.Cmd interface. --- cmds.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ notifications.go | 28 ++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/cmds.go b/cmds.go index 550bdac4..e5f89e07 100644 --- a/cmds.go +++ b/cmds.go @@ -58,6 +58,11 @@ func (cmd *GetCurrentNetCmd) Id() interface{} { return cmd.id } +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *GetCurrentNetCmd) SetId(id interface{}) { + cmd.id = id +} + // Method satisfies the Cmd interface by returning the RPC method. func (cmd *GetCurrentNetCmd) Method() string { return "getcurrentnet" @@ -155,6 +160,11 @@ func (cmd *GetUnconfirmedBalanceCmd) Id() interface{} { return cmd.id } +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *GetUnconfirmedBalanceCmd) SetId(id interface{}) { + cmd.id = id +} + // Method satisifies the Cmd interface by returning the RPC method. func (cmd *GetUnconfirmedBalanceCmd) Method() string { return "getunconfirmedbalance" @@ -229,6 +239,11 @@ func (cmd *GetBestBlockCmd) Id() interface{} { return cmd.id } +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *GetBestBlockCmd) SetId(id interface{}) { + cmd.id = id +} + // Method satisfies the Cmd interface by returning the RPC method. func (cmd *GetBestBlockCmd) Method() string { return "getbestblock" @@ -342,6 +357,11 @@ func (cmd *RescanCmd) Id() interface{} { return cmd.id } +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *RescanCmd) SetId(id interface{}) { + cmd.id = id +} + // Method satisfies the Cmd interface by returning the RPC method. func (cmd *RescanCmd) Method() string { return "rescan" @@ -438,6 +458,11 @@ func (cmd *NotifyNewTXsCmd) Id() interface{} { return cmd.id } +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *NotifyNewTXsCmd) SetId(id interface{}) { + cmd.id = id +} + // Method satisfies the Cmd interface by returning the RPC method. func (cmd *NotifyNewTXsCmd) Method() string { return "notifynewtxs" @@ -533,6 +558,11 @@ func (cmd *NotifySpentCmd) Id() interface{} { return cmd.id } +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *NotifySpentCmd) SetId(id interface{}) { + cmd.id = id +} + // Method satisfies the Cmd interface by returning the RPC method. func (cmd *NotifySpentCmd) Method() string { return "notifyspent" @@ -634,6 +664,11 @@ func (cmd *CreateEncryptedWalletCmd) Id() interface{} { return cmd.id } +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *CreateEncryptedWalletCmd) SetId(id interface{}) { + cmd.id = id +} + // Method satisfies the Cmd interface by returning the RPC method. func (cmd *CreateEncryptedWalletCmd) Method() string { return "createencryptedwallet" @@ -709,6 +744,11 @@ func (cmd *GetBalancesCmd) Id() interface{} { return cmd.id } +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *GetBalancesCmd) SetId(id interface{}) { + cmd.id = id +} + // Method satisfies the Cmd interface by returning the RPC method. func (cmd *GetBalancesCmd) Method() string { return "getbalances" @@ -805,6 +845,11 @@ func (cmd *WalletIsLockedCmd) Id() interface{} { return cmd.id } +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *WalletIsLockedCmd) SetId(id interface{}) { + cmd.id = id +} + // Method satisfies the Cmd interface by returning the RPC method. func (cmd *WalletIsLockedCmd) Method() string { return "walletislocked" @@ -920,6 +965,11 @@ func (cmd *ListAddressTransactionsCmd) Id() interface{} { return cmd.id } +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *ListAddressTransactionsCmd) SetId(id interface{}) { + cmd.id = id +} + // Method satisfies the Cmd interface by returning the RPC method. func (cmd *ListAddressTransactionsCmd) Method() string { return "listaddresstransactions" @@ -1022,6 +1072,11 @@ func (cmd *ListAllTransactionsCmd) Id() interface{} { return cmd.id } +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *ListAllTransactionsCmd) SetId(id interface{}) { + cmd.id = id +} + // Method satisfies the Cmd interface by returning the RPC method. func (cmd *ListAllTransactionsCmd) Method() string { return "listalltransactions" @@ -1134,6 +1189,11 @@ func (cmd *GetAddressBalanceCmd) Id() interface{} { return cmd.id } +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *GetAddressBalanceCmd) SetId(id interface{}) { + cmd.id = id +} + // Method satisfies the Cmd interface by returning the RPC method. func (cmd *GetAddressBalanceCmd) Method() string { return "getaddressbalance" diff --git a/notifications.go b/notifications.go index c8c7cc68..c914ecbd 100644 --- a/notifications.go +++ b/notifications.go @@ -114,6 +114,10 @@ func (n *AccountBalanceNtfn) Id() interface{} { return nil } +// SetId is implemented to satisify the btcjson.Cmd interface. The +// notification id is not modified. +func (n *AccountBalanceNtfn) SetId(id interface{}) {} + // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *AccountBalanceNtfn) Method() string { @@ -205,6 +209,10 @@ func (n *BlockConnectedNtfn) Id() interface{} { return nil } +// SetId is implemented to satisify the btcjson.Cmd interface. The +// notification id is not modified. +func (n *BlockConnectedNtfn) SetId(id interface{}) {} + // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *BlockConnectedNtfn) Method() string { @@ -295,6 +303,10 @@ func (n *BlockDisconnectedNtfn) Id() interface{} { return nil } +// SetId is implemented to satisify the btcjson.Cmd interface. The +// notification id is not modified. +func (n *BlockDisconnectedNtfn) SetId(id interface{}) {} + // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *BlockDisconnectedNtfn) Method() string { @@ -378,6 +390,10 @@ func (n *BtcdConnectedNtfn) Id() interface{} { return nil } +// SetId is implemented to satisify the btcjson.Cmd interface. The +// notification id is not modified. +func (n *BtcdConnectedNtfn) SetId(id interface{}) {} + // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *BtcdConnectedNtfn) Method() string { @@ -488,6 +504,10 @@ func (n *TxMinedNtfn) Id() interface{} { return nil } +// SetId is implemented to satisify the btcjson.Cmd interface. The +// notification id is not modified. +func (n *TxMinedNtfn) SetId(id interface{}) {} + // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *TxMinedNtfn) Method() string { @@ -581,6 +601,10 @@ func (n *TxNtfn) Id() interface{} { return nil } +// SetId is implemented to satisify the btcjson.Cmd interface. The +// notification id is not modified. +func (n *TxNtfn) SetId(id interface{}) {} + // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *TxNtfn) Method() string { @@ -674,6 +698,10 @@ func (n *WalletLockStateNtfn) Id() interface{} { return nil } +// SetId is implemented to satisify the btcjson.Cmd interface. The +// notification id is not modified. +func (n *WalletLockStateNtfn) SetId(id interface{}) {} + // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *WalletLockStateNtfn) Method() string { From 9ea77c00f20fb3e61240560398a4b85c37339870 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 8 Jan 2014 11:28:38 -0500 Subject: [PATCH 21/76] Add RescanResultNtfn to notify rescan results. --- notifications.go | 156 ++++++++++++++++++++++++++++++++++++++++++ notifications_test.go | 30 ++++++++ test_coverage.txt | 129 ++++++++++++++++++++-------------- 3 files changed, 263 insertions(+), 52 deletions(-) diff --git a/notifications.go b/notifications.go index c914ecbd..df2d4678 100644 --- a/notifications.go +++ b/notifications.go @@ -34,6 +34,10 @@ const ( // btcdconnected notification. BtcdConnectedNtfnMethod = "btcdconnected" + // RescanResultNtfnMethod is the method of the btcd + // rescanresult notification. + RescanResultNtfnMethod = "rescanresult" + // TxMinedNtfnMethod is the method of the btcd txmined // notification. TxMinedNtfnMethod = "txmined" @@ -53,6 +57,7 @@ func init() { btcjson.RegisterCustomCmd(BlockConnectedNtfnMethod, parseBlockConnectedNtfn) btcjson.RegisterCustomCmd(BlockDisconnectedNtfnMethod, parseBlockDisconnectedNtfn) btcjson.RegisterCustomCmd(BtcdConnectedNtfnMethod, parseBtcdConnectedNtfn) + btcjson.RegisterCustomCmd(RescanResultNtfnMethod, parseRescanResultNtfn) btcjson.RegisterCustomCmd(TxMinedNtfnMethod, parseTxMinedNtfn) btcjson.RegisterCustomCmd(TxNtfnMethod, parseTxNtfn) btcjson.RegisterCustomCmd(WalletLockStateNtfnMethod, parseWalletLockStateNtfn) @@ -435,6 +440,157 @@ func (n *BtcdConnectedNtfn) UnmarshalJSON(b []byte) error { return nil } +// RescanResultNtfn is a type handling custom marshaling and unmarshaling +// of rescanresult JSON websocket notifications. +type RescanResultNtfn struct { + Receiver string + Amount int64 + TxID string + TxOutIndex uint32 + PkScript string + BlockHash string + BlockHeight int32 + BlockIndex int + BlockTime int64 + Spent bool +} + +// Enforce that RescanResultNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &RescanResultNtfn{} + +// parseRescanResultNtfn parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the notification +// with the btcjson parser. +func parseRescanResultNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 10 { + return nil, btcjson.ErrWrongNumberOfParams + } + + receiver, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter receiver must be a string") + } + famount, ok := r.Params[1].(float64) + if !ok { + return nil, errors.New("second parameter amount must be a number") + } + amount := int64(famount) + txid, ok := r.Params[2].(string) + if !ok { + return nil, errors.New("third parameter txid must be a string") + } + fTxOutIdx, ok := r.Params[3].(float64) + if !ok { + return nil, errors.New("fourth parameter txoutidx must be a number") + } + txOutIdx := uint32(fTxOutIdx) + pkScript, ok := r.Params[4].(string) + if !ok { + return nil, errors.New("fifth parameter pkScript must be a string") + } + blockHash := r.Params[5].(string) + if !ok { + return nil, errors.New("sixth parameter blockHash must be a string") + } + fBlockHeight, ok := r.Params[6].(float64) + if !ok { + return nil, errors.New("seventh parameter blockHeight must be a number") + } + blockHeight := int32(fBlockHeight) + fBlockIndex, ok := r.Params[7].(float64) + if !ok { + return nil, errors.New("eighth parameter blockIndex must be a number") + } + blockIndex := int(fBlockIndex) + fBlockTime, ok := r.Params[8].(float64) + if !ok { + return nil, errors.New("ninth parameter blockTime must be a number") + } + blockTime := int64(fBlockTime) + spent, ok := r.Params[9].(bool) + if !ok { + return nil, errors.New("tenth parameter spent must be a bool") + } + + cmd := &RescanResultNtfn{ + Receiver: receiver, + Amount: amount, + TxID: txid, + TxOutIndex: txOutIdx, + PkScript: pkScript, + BlockHash: blockHash, + BlockHeight: blockHeight, + BlockIndex: blockIndex, + BlockTime: blockTime, + Spent: spent, + } + return cmd, nil +} + +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *RescanResultNtfn) Id() interface{} { + return nil +} + +// SetId is implemented to satisify the btcjson.Cmd interface. The +// notification id is not modified. +func (n *RescanResultNtfn) SetId(id interface{}) {} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *RescanResultNtfn) Method() string { + return RescanResultNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd +// interface. +func (n *RescanResultNtfn) MarshalJSON() ([]byte, error) { + ntfn := btcjson.Message{ + Jsonrpc: "1.0", + Method: n.Method(), + Params: []interface{}{ + n.Receiver, + n.Amount, + n.TxID, + n.TxOutIndex, + n.PkScript, + n.BlockHash, + n.BlockHeight, + n.BlockIndex, + n.BlockTime, + n.Spent, + }, + } + return json.Marshal(ntfn) +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the btcjson.Cmd interface. +func (n *RescanResultNtfn) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newNtfn, err := parseRescanResultNtfn(&r) + if err != nil { + return err + } + + concreteNtfn, ok := newNtfn.(*RescanResultNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn + return nil +} + // TxMinedNtfn is a type handling custom marshaling and // unmarshaling of txmined JSON websocket notifications. type TxMinedNtfn struct { diff --git a/notifications_test.go b/notifications_test.go index a3de913a..45c4bcc9 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -61,6 +61,36 @@ var ntfntests = []struct { Connected: true, }, }, + { + name: "rescanresult", + f: func() btcjson.Cmd { + cmd := &btcws.RescanResultNtfn{ + Receiver: "miFxiuApPo3KBqtMnPUjasZmHoVnoH3Eoc", + Amount: 200000000, + TxID: "851f5c0652e785c5ed80aafaf2d918e5cbe5c307dbba3680808ada1d01f36886", + TxOutIndex: 1, + PkScript: "76a9141e127eda7cd71b9724085f588840a3e9d697ae9888ac", + BlockHash: "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", + BlockHeight: 153469, + BlockIndex: 1, + BlockTime: 1386944019, + Spent: true, + } + return cmd + }, + result: &btcws.RescanResultNtfn{ + Receiver: "miFxiuApPo3KBqtMnPUjasZmHoVnoH3Eoc", + Amount: 200000000, + TxID: "851f5c0652e785c5ed80aafaf2d918e5cbe5c307dbba3680808ada1d01f36886", + TxOutIndex: 1, + PkScript: "76a9141e127eda7cd71b9724085f588840a3e9d697ae9888ac", + BlockHash: "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", + BlockHeight: 153469, + BlockIndex: 1, + BlockTime: 1386944019, + Spent: true, + }, + }, { name: "txmined", f: func() btcjson.Cmd { diff --git a/test_coverage.txt b/test_coverage.txt index e7992e4b..ed17fabb 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,89 +1,92 @@ github.com/conformal/btcws/cmds.go init 100.00% (12/12) -github.com/conformal/btcws/notifications.go init 100.00% (7/7) +github.com/conformal/btcws/notifications.go init 100.00% (8/8) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go GetBalancesCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go RescanResultNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go NewGetBalancesCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go GetBalancesCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetBalancesCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanResultNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanResultNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 87.50% (7/8) -github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go parseRescanCmd 77.78% (14/18) github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 76.47% (13/17) github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 75.00% (9/12) github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 75.00% (6/8) github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) @@ -91,29 +94,51 @@ github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go GetBalancesCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RescanResultNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go TxMinedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go parseRescanResultNtfn 70.73% (29/41) github.com/conformal/btcws/notifications.go parseTxMinedNtfn 70.00% (14/20) github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 69.23% (9/13) github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (10/15) +github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) github.com/conformal/btcws/cmds.go parseGetBalancesCmd 66.67% (2/3) -github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 45.45% (5/11) -github.com/conformal/btcws ---------------------------------------- 77.72% (443/570) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetBalancesCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go TxMinedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go RescanResultNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws ---------------------------------------- 75.90% (485/639) From 6e3f9e451bc735fff824f5a704d47e6ff0166c83 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 8 Jan 2014 15:23:59 -0500 Subject: [PATCH 22/76] Rename RescanResultNtfn to ProcessedTxNtfn. This notification should be generic enough to be used by both rescan and normal block processing code, so give it a generic name too. --- notifications.go | 40 ++++++++++++++++++++-------------------- notifications_test.go | 6 +++--- test_coverage.txt | 12 ++++++------ 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/notifications.go b/notifications.go index df2d4678..1e17cf64 100644 --- a/notifications.go +++ b/notifications.go @@ -34,9 +34,9 @@ const ( // btcdconnected notification. BtcdConnectedNtfnMethod = "btcdconnected" - // RescanResultNtfnMethod is the method of the btcd - // rescanresult notification. - RescanResultNtfnMethod = "rescanresult" + // ProcessedTxNtfnMethod is the method of the btcd + // processedtx notification. + ProcessedTxNtfnMethod = "processedx" // TxMinedNtfnMethod is the method of the btcd txmined // notification. @@ -57,7 +57,7 @@ func init() { btcjson.RegisterCustomCmd(BlockConnectedNtfnMethod, parseBlockConnectedNtfn) btcjson.RegisterCustomCmd(BlockDisconnectedNtfnMethod, parseBlockDisconnectedNtfn) btcjson.RegisterCustomCmd(BtcdConnectedNtfnMethod, parseBtcdConnectedNtfn) - btcjson.RegisterCustomCmd(RescanResultNtfnMethod, parseRescanResultNtfn) + btcjson.RegisterCustomCmd(ProcessedTxNtfnMethod, parseProcessedTxNtfn) btcjson.RegisterCustomCmd(TxMinedNtfnMethod, parseTxMinedNtfn) btcjson.RegisterCustomCmd(TxNtfnMethod, parseTxNtfn) btcjson.RegisterCustomCmd(WalletLockStateNtfnMethod, parseWalletLockStateNtfn) @@ -440,9 +440,9 @@ func (n *BtcdConnectedNtfn) UnmarshalJSON(b []byte) error { return nil } -// RescanResultNtfn is a type handling custom marshaling and unmarshaling -// of rescanresult JSON websocket notifications. -type RescanResultNtfn struct { +// ProcessedTxNtfn is a type handling custom marshaling and unmarshaling +// of processedtx JSON websocket notifications. +type ProcessedTxNtfn struct { Receiver string Amount int64 TxID string @@ -455,13 +455,13 @@ type RescanResultNtfn struct { Spent bool } -// Enforce that RescanResultNtfn satisifies the btcjson.Cmd interface. -var _ btcjson.Cmd = &RescanResultNtfn{} +// Enforce that ProcessedTxNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &ProcessedTxNtfn{} -// parseRescanResultNtfn parses a RawCmd into a concrete type satisifying +// parseProcessedTxNtfn parses a RawCmd into a concrete type satisifying // the btcjson.Cmd interface. This is used when registering the notification // with the btcjson parser. -func parseRescanResultNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { +func parseProcessedTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { if r.Id != nil { return nil, ErrNotANtfn } @@ -516,7 +516,7 @@ func parseRescanResultNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, errors.New("tenth parameter spent must be a bool") } - cmd := &RescanResultNtfn{ + cmd := &ProcessedTxNtfn{ Receiver: receiver, Amount: amount, TxID: txid, @@ -533,23 +533,23 @@ func parseRescanResultNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { // Id satisifies the btcjson.Cmd interface by returning nil for a // notification ID. -func (n *RescanResultNtfn) Id() interface{} { +func (n *ProcessedTxNtfn) Id() interface{} { return nil } // SetId is implemented to satisify the btcjson.Cmd interface. The // notification id is not modified. -func (n *RescanResultNtfn) SetId(id interface{}) {} +func (n *ProcessedTxNtfn) SetId(id interface{}) {} // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. -func (n *RescanResultNtfn) Method() string { - return RescanResultNtfnMethod +func (n *ProcessedTxNtfn) Method() string { + return ProcessedTxNtfnMethod } // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. -func (n *RescanResultNtfn) MarshalJSON() ([]byte, error) { +func (n *ProcessedTxNtfn) MarshalJSON() ([]byte, error) { ntfn := btcjson.Message{ Jsonrpc: "1.0", Method: n.Method(), @@ -571,19 +571,19 @@ func (n *RescanResultNtfn) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of // the btcjson.Cmd interface. -func (n *RescanResultNtfn) UnmarshalJSON(b []byte) error { +func (n *ProcessedTxNtfn) UnmarshalJSON(b []byte) error { // Unmarshal into a RawCmd. var r btcjson.RawCmd if err := json.Unmarshal(b, &r); err != nil { return err } - newNtfn, err := parseRescanResultNtfn(&r) + newNtfn, err := parseProcessedTxNtfn(&r) if err != nil { return err } - concreteNtfn, ok := newNtfn.(*RescanResultNtfn) + concreteNtfn, ok := newNtfn.(*ProcessedTxNtfn) if !ok { return btcjson.ErrInternal } diff --git a/notifications_test.go b/notifications_test.go index 45c4bcc9..16f846d7 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -62,9 +62,9 @@ var ntfntests = []struct { }, }, { - name: "rescanresult", + name: "processedtx", f: func() btcjson.Cmd { - cmd := &btcws.RescanResultNtfn{ + cmd := &btcws.ProcessedTxNtfn{ Receiver: "miFxiuApPo3KBqtMnPUjasZmHoVnoH3Eoc", Amount: 200000000, TxID: "851f5c0652e785c5ed80aafaf2d918e5cbe5c307dbba3680808ada1d01f36886", @@ -78,7 +78,7 @@ var ntfntests = []struct { } return cmd }, - result: &btcws.RescanResultNtfn{ + result: &btcws.ProcessedTxNtfn{ Receiver: "miFxiuApPo3KBqtMnPUjasZmHoVnoH3Eoc", Amount: 200000000, TxID: "851f5c0652e785c5ed80aafaf2d918e5cbe5c307dbba3680808ada1d01f36886", diff --git a/test_coverage.txt b/test_coverage.txt index ed17fabb..37843fe4 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -10,7 +10,7 @@ github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% github.com/conformal/btcws/cmds.go GetBalancesCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go RescanResultNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go ProcessedTxNtfn.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) @@ -64,10 +64,10 @@ github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanResultNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go ProcessedTxNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanResultNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go ProcessedTxNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) @@ -102,11 +102,11 @@ github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RescanResultNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go ProcessedTxNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go TxMinedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go parseRescanResultNtfn 70.73% (29/41) +github.com/conformal/btcws/notifications.go parseProcessedTxNtfn 70.73% (29/41) github.com/conformal/btcws/notifications.go parseTxMinedNtfn 70.00% (14/20) github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 69.23% (9/13) github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (10/15) @@ -138,7 +138,7 @@ github.com/conformal/btcws/notifications.go TxMinedNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go RescanResultNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go ProcessedTxNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.SetId 0.00% (0/0) github.com/conformal/btcws ---------------------------------------- 75.90% (485/639) From d493181886a00801b49d857d7cc669eac6a0448d Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 8 Jan 2014 21:29:19 -0500 Subject: [PATCH 23/76] Add TxSpentNtfn to notify wallets spent outpoints. --- notifications.go | 107 ++++++++++++++++++++++++++ notifications_test.go | 14 ++++ test_coverage.txt | 173 ++++++++++++++++++++++-------------------- 3 files changed, 211 insertions(+), 83 deletions(-) diff --git a/notifications.go b/notifications.go index 1e17cf64..b366a49a 100644 --- a/notifications.go +++ b/notifications.go @@ -46,6 +46,10 @@ const ( // notification. TxNtfnMethod = "newtx" + // TxSpentNtfnMethod is the method of the btcd txspent + // notification. + TxSpentNtfnMethod = "txspent" + // WalletLockStateNtfnMethod is the method of the btcwallet // walletlockstate notification. WalletLockStateNtfnMethod = "walletlockstate" @@ -59,6 +63,7 @@ func init() { btcjson.RegisterCustomCmd(BtcdConnectedNtfnMethod, parseBtcdConnectedNtfn) btcjson.RegisterCustomCmd(ProcessedTxNtfnMethod, parseProcessedTxNtfn) btcjson.RegisterCustomCmd(TxMinedNtfnMethod, parseTxMinedNtfn) + btcjson.RegisterCustomCmd(TxSpentNtfnMethod, parseTxSpentNtfn) btcjson.RegisterCustomCmd(TxNtfnMethod, parseTxNtfn) btcjson.RegisterCustomCmd(WalletLockStateNtfnMethod, parseWalletLockStateNtfn) } @@ -716,6 +721,108 @@ type TxNtfn struct { Details map[string]interface{} } +// TxSpentNtfn is a type handling custom marshaling and +// unmarshaling of txspent JSON websocket notifications. +type TxSpentNtfn struct { + SpentTxId string + SpentTxOutIndex int + SpendingTx string +} + +// Enforce that TxSpentNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &TxSpentNtfn{} + +// NewTxSpentNtfn creates a new TxSpentNtfn. +func NewTxSpentNtfn(txid string, txOutIndex int, spendingTx string) *TxSpentNtfn { + return &TxSpentNtfn{ + SpentTxId: txid, + SpentTxOutIndex: txOutIndex, + SpendingTx: spendingTx, + } +} + +// parseTxSpentNtfn parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the notification +// with the btcjson parser. +func parseTxSpentNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 3 { + return nil, btcjson.ErrWrongNumberOfParams + } + + txid, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter txid must be a string") + } + findex, ok := r.Params[1].(float64) + if !ok { + return nil, errors.New("second parameter index must be a number") + } + index := int(findex) + spendingTx, ok := r.Params[2].(string) + if !ok { + return nil, errors.New("third parameter spendingTx must be a string") + } + + return NewTxSpentNtfn(txid, index, spendingTx), nil +} + +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *TxSpentNtfn) Id() interface{} { + return nil +} + +// SetId is implemented to satisify the btcjson.Cmd interface. The +// notification id is not modified. +func (n *TxSpentNtfn) SetId(id interface{}) {} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *TxSpentNtfn) Method() string { + return TxSpentNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd +// interface. +func (n *TxSpentNtfn) MarshalJSON() ([]byte, error) { + ntfn := btcjson.Message{ + Jsonrpc: "1.0", + Method: n.Method(), + Params: []interface{}{ + n.SpentTxId, + n.SpentTxOutIndex, + n.SpendingTx, + }, + } + return json.Marshal(ntfn) +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the btcjson.Cmd interface. +func (n *TxSpentNtfn) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newNtfn, err := parseTxSpentNtfn(&r) + if err != nil { + return err + } + + concreteNtfn, ok := newNtfn.(*TxSpentNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn + return nil +} + // Enforce that TxNtfn satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &TxNtfn{} diff --git a/notifications_test.go b/notifications_test.go index 16f846d7..a7e8c057 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -109,6 +109,20 @@ var ntfntests = []struct { Index: 0, }, }, + { + name: "txspent", + f: func() btcjson.Cmd { + return btcws.NewTxSpentNtfn( + "b22eb08001da1d57aec3131ccb46ea61820c46c71695a802585fbd56e93625a9", + 1, + "0100000001a92536e956bd5f5802a89516c7460c8261ea46cb1c13c3ae571dda0180b02eb2010000006a4730440220240e3ad18a0393e9894120eb87ded8545222df4890cf98a55b5d36042c966898022031bbd795453fcd01b2a9eb30a8cbbe0ea043b7e4e85ff17ba2b44c243d14aafc0121028031f92546ff86436802fdfe07dc9e1876b70c8b8fa29ca9e9c90664d7022717ffffffff0200ab9041000000001976a91401f65945e042b5e09ecf0a9d9115adecb4caee8588ac703fbc0d040000001976a914c31a4d3e819598e55ff80601e4b2c662454385ca88ac00000000") + }, + result: &btcws.TxSpentNtfn{ + SpentTxId: "b22eb08001da1d57aec3131ccb46ea61820c46c71695a802585fbd56e93625a9", + SpentTxOutIndex: 1, + SpendingTx: "0100000001a92536e956bd5f5802a89516c7460c8261ea46cb1c13c3ae571dda0180b02eb2010000006a4730440220240e3ad18a0393e9894120eb87ded8545222df4890cf98a55b5d36042c966898022031bbd795453fcd01b2a9eb30a8cbbe0ea043b7e4e85ff17ba2b44c243d14aafc0121028031f92546ff86436802fdfe07dc9e1876b70c8b8fa29ca9e9c90664d7022717ffffffff0200ab9041000000001976a91401f65945e042b5e09ecf0a9d9115adecb4caee8588ac703fbc0d040000001976a914c31a4d3e819598e55ff80601e4b2c662454385ca88ac00000000", + }, + }, { name: "newtx", f: func() btcjson.Cmd { diff --git a/test_coverage.txt b/test_coverage.txt index 37843fe4..9a3d57da 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,144 +1,151 @@ github.com/conformal/btcws/cmds.go init 100.00% (12/12) -github.com/conformal/btcws/notifications.go init 100.00% (8/8) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/notifications.go init 100.00% (9/9) github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/cmds.go GetBalancesCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go ProcessedTxNtfn.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxSpentNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go ProcessedTxNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go NewGetBalancesCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go GetBalancesCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetBalancesCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go ProcessedTxNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go ProcessedTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go ProcessedTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go ProcessedTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxSpentNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxSpentNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxSpentNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 87.50% (7/8) -github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go parseRescanCmd 77.78% (14/18) github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 76.47% (13/17) github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 75.00% (9/12) -github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 75.00% (6/8) github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBalancesCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 75.00% (6/8) +github.com/conformal/btcws/notifications.go TxSpentNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go ProcessedTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go TxMinedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBalancesCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go parseProcessedTxNtfn 70.73% (29/41) github.com/conformal/btcws/notifications.go parseTxMinedNtfn 70.00% (14/20) github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 69.23% (9/13) +github.com/conformal/btcws/notifications.go parseTxSpentNtfn 66.67% (10/15) github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (10/15) +github.com/conformal/btcws/cmds.go parseGetBalancesCmd 66.67% (2/3) github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) -github.com/conformal/btcws/cmds.go parseGetBalancesCmd 66.67% (2/3) github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) -github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 45.45% (5/11) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go GetBalancesCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go GetBestBlockCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.SetId 0.00% (0/1) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go TxMinedNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go ProcessedTxNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws ---------------------------------------- 75.90% (485/639) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go TxMinedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go ProcessedTxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go TxSpentNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws ---------------------------------------- 75.86% (509/671) From 33890d49e92b051894bcd53552bde1cee55dbc70 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Thu, 9 Jan 2014 11:51:51 -0500 Subject: [PATCH 24/76] Fix a typo. --- notifications.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifications.go b/notifications.go index b366a49a..3fd4c7cb 100644 --- a/notifications.go +++ b/notifications.go @@ -36,7 +36,7 @@ const ( // ProcessedTxNtfnMethod is the method of the btcd // processedtx notification. - ProcessedTxNtfnMethod = "processedx" + ProcessedTxNtfnMethod = "processedtx" // TxMinedNtfnMethod is the method of the btcd txmined // notification. From 05a0ba18b48a12b8d0d615a1371befdaa6bdc5dc Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Thu, 9 Jan 2014 13:14:53 -0500 Subject: [PATCH 25/76] Kill GetBalancesCmd. --- cmds.go | 77 ------------------- cmds_test.go | 9 --- test_coverage.txt | 187 ++++++++++++++++++++++------------------------ 3 files changed, 90 insertions(+), 183 deletions(-) diff --git a/cmds.go b/cmds.go index e5f89e07..64b0e9fb 100644 --- a/cmds.go +++ b/cmds.go @@ -15,7 +15,6 @@ import ( func init() { btcjson.RegisterCustomCmd("createencryptedwallet", parseCreateEncryptedWalletCmd) btcjson.RegisterCustomCmd("getaddressbalance", parseGetAddressBalanceCmd) - btcjson.RegisterCustomCmd("getbalances", parseGetBalancesCmd) btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd) btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd) btcjson.RegisterCustomCmd("getunconfirmedbalance", parseGetUnconfirmedBalanceCmd) @@ -713,82 +712,6 @@ func (cmd *CreateEncryptedWalletCmd) UnmarshalJSON(b []byte) error { return nil } -// GetBalancesCmd is a type handling custom marshaling and -// unmarshaling of getbalances JSON websocket extension commands. -type GetBalancesCmd struct { - id interface{} -} - -// Enforce that GetBalancesCmd satisifies the btcjson.Cmd -// interface. -var _ btcjson.Cmd = &GetBalancesCmd{} - -// NewGetBalancesCmd creates a new GetBalancesCmd. -func NewGetBalancesCmd(id interface{}) *GetBalancesCmd { - return &GetBalancesCmd{id: id} -} - -// parseGetBalancesCmd parses a GetBalancesCmd into a concrete -// type satisifying the btcjson.Cmd interface. This is used when -// registering the custom command with the btcjson parser. -func parseGetBalancesCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { - if len(r.Params) != 0 { - return nil, btcjson.ErrWrongNumberOfParams - } - - return NewGetBalancesCmd(r.Id), nil -} - -// Id satisifies the Cmd interface by returning the ID of the command. -func (cmd *GetBalancesCmd) Id() interface{} { - return cmd.id -} - -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *GetBalancesCmd) SetId(id interface{}) { - cmd.id = id -} - -// Method satisfies the Cmd interface by returning the RPC method. -func (cmd *GetBalancesCmd) Method() string { - return "getbalances" -} - -// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. -func (cmd *GetBalancesCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "getbalances", - Id: cmd.id, - Params: []interface{}{}, - } - - return json.Marshal(raw) -} - -// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of -// the Cmd interface. -func (cmd *GetBalancesCmd) UnmarshalJSON(b []byte) error { - // Unmarshal into a RawCmd. - var r btcjson.RawCmd - if err := json.Unmarshal(b, &r); err != nil { - return err - } - - newCmd, err := parseGetBalancesCmd(&r) - if err != nil { - return err - } - - concreteCmd, ok := newCmd.(*GetBalancesCmd) - if !ok { - return btcjson.ErrInternal - } - *cmd = *concreteCmd - return nil -} - // WalletIsLockedCmd is a type handling custom marshaling and // unmarshaling of walletislocked JSON websocket extension commands. type WalletIsLockedCmd struct { diff --git a/cmds_test.go b/cmds_test.go index a41a81b9..0e92526f 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -62,15 +62,6 @@ var cmdtests = []struct { Minconf: 0, }, }, - { - name: "getbalances", - f: func() (btcjson.Cmd, error) { - return NewGetBalancesCmd(float64(1)), nil - }, - result: &GetBalancesCmd{ - id: float64(1), - }, - }, { name: "getbestblock", f: func() (btcjson.Cmd, error) { diff --git a/test_coverage.txt b/test_coverage.txt index 9a3d57da..03911e44 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,151 +1,144 @@ -github.com/conformal/btcws/cmds.go init 100.00% (12/12) +github.com/conformal/btcws/cmds.go init 100.00% (11/11) github.com/conformal/btcws/notifications.go init 100.00% (9/9) github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetBalancesCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxSpentNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/notifications.go ProcessedTxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxSpentNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxSpentNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBalancesCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBalancesCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBalancesCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxSpentNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go ProcessedTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go ProcessedTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go ProcessedTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxSpentNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxSpentNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxSpentNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go ProcessedTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxSpentNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 87.50% (7/8) -github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go parseRescanCmd 77.78% (14/18) github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 76.47% (13/17) github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 75.00% (9/12) -github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 75.00% (6/8) -github.com/conformal/btcws/notifications.go TxSpentNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go ProcessedTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxMinedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBalancesCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go ProcessedTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxSpentNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxMinedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go parseProcessedTxNtfn 70.73% (29/41) github.com/conformal/btcws/notifications.go parseTxMinedNtfn 70.00% (14/20) github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 69.23% (9/13) -github.com/conformal/btcws/notifications.go parseTxSpentNtfn 66.67% (10/15) github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (10/15) -github.com/conformal/btcws/cmds.go parseGetBalancesCmd 66.67% (2/3) -github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) +github.com/conformal/btcws/notifications.go parseTxSpentNtfn 66.67% (10/15) github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) +github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) -github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 45.45% (5/11) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetBalancesCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go GetBestBlockCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/notifications.go TxSpentNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go TxMinedNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go ProcessedTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go TxSpentNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws ---------------------------------------- 75.86% (509/671) +github.com/conformal/btcws ---------------------------------------- 75.85% (493/650) From 15f2ce4abdeac8d339d7e442e969ca3650885b19 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 13 Jan 2014 17:16:58 -0500 Subject: [PATCH 26/76] Fix a couple incorrect comments. --- cmds.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds.go b/cmds.go index 64b0e9fb..a47666e2 100644 --- a/cmds.go +++ b/cmds.go @@ -419,7 +419,7 @@ type NotifyNewTXsCmd struct { // Enforce that NotifyNewTXsCmd satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &NotifyNewTXsCmd{} -// NewNotifyNewTXsCmd creates a new RescanCmd. +// NewNotifyNewTXsCmd creates a new NotifyNewTXsCmd. func NewNotifyNewTXsCmd(id interface{}, addresses []string) *NotifyNewTXsCmd { return &NotifyNewTXsCmd{ id: id, @@ -515,7 +515,7 @@ type NotifySpentCmd struct { // Enforce that NotifySpentCmd satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &NotifySpentCmd{} -// NewNotifySpentCmd creates a new RescanCmd. +// NewNotifySpentCmd creates a new NotifySpentCmd. func NewNotifySpentCmd(id interface{}, op *btcwire.OutPoint) *NotifySpentCmd { return &NotifySpentCmd{ id: id, From ed8812f34039f52d26e62afda9bac0002b97ab38 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 17 Jan 2014 16:24:21 -0500 Subject: [PATCH 27/76] Add NotifyBlocksCmd. --- cmds.go | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/cmds.go b/cmds.go index a47666e2..4ba9366a 100644 --- a/cmds.go +++ b/cmds.go @@ -20,6 +20,7 @@ func init() { btcjson.RegisterCustomCmd("getunconfirmedbalance", parseGetUnconfirmedBalanceCmd) btcjson.RegisterCustomCmd("listaddresstransactions", parseListAddressTransactionsCmd) btcjson.RegisterCustomCmd("listalltransactions", parseListAllTransactionsCmd) + btcjson.RegisterCustomCmd("notifyblocks", parseNotifyBlocks) btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd) btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd) btcjson.RegisterCustomCmd("rescan", parseRescanCmd) @@ -408,6 +409,82 @@ func (cmd *RescanCmd) UnmarshalJSON(b []byte) error { return nil } +// NotifyBlocksCmd is a type handling custom marshaling and +// unmarshaling of notifyblocks JSON websocket extension +// commands. +type NotifyBlocksCmd struct { + id interface{} +} + +// Enforce that NotifyBlocksCmd satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &NotifyBlocksCmd{} + +// NewNotifyBlocksCmd creates a new NotifyBlocksCmd. +func NewNotifyBlocksCmd(id interface{}) *NotifyBlocksCmd { + return &NotifyBlocksCmd{ + id: id, + } +} + +// parseNotifyBlocks parses a NotifyBlocksCmd into a concrete type +// satisifying the btcjson.Cmd interface. This is used when registering +// the custom command with the btcjson parser. +func parseNotifyBlocks(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) != 0 { + return nil, btcjson.ErrWrongNumberOfParams + } + return NewNotifyBlocksCmd(r.Id), nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *NotifyBlocksCmd) Id() interface{} { + return cmd.id +} + +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *NotifyBlocksCmd) SetId(id interface{}) { + cmd.id = id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *NotifyBlocksCmd) Method() string { + return "notifyblocks" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *NotifyBlocksCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "notifyblocks", + Id: cmd.id, + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *NotifyBlocksCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseNotifyNewTXsCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*NotifyBlocksCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + // NotifyNewTXsCmd is a type handling custom marshaling and // unmarshaling of notifynewtxs JSON websocket extension // commands. From b90c6c61ba31ca1328aa99ac6f3681177945b800 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 17 Jan 2014 18:38:26 -0500 Subject: [PATCH 28/76] Fix previous. --- cmds.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmds.go b/cmds.go index 4ba9366a..04688e14 100644 --- a/cmds.go +++ b/cmds.go @@ -20,7 +20,7 @@ func init() { btcjson.RegisterCustomCmd("getunconfirmedbalance", parseGetUnconfirmedBalanceCmd) btcjson.RegisterCustomCmd("listaddresstransactions", parseListAddressTransactionsCmd) btcjson.RegisterCustomCmd("listalltransactions", parseListAllTransactionsCmd) - btcjson.RegisterCustomCmd("notifyblocks", parseNotifyBlocks) + btcjson.RegisterCustomCmd("notifyblocks", parseNotifyBlocksCmd) btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd) btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd) btcjson.RegisterCustomCmd("rescan", parseRescanCmd) @@ -426,10 +426,10 @@ func NewNotifyBlocksCmd(id interface{}) *NotifyBlocksCmd { } } -// parseNotifyBlocks parses a NotifyBlocksCmd into a concrete type +// parseNotifyBlocksCmd parses a NotifyBlocksCmd into a concrete type // satisifying the btcjson.Cmd interface. This is used when registering // the custom command with the btcjson parser. -func parseNotifyBlocks(r *btcjson.RawCmd) (btcjson.Cmd, error) { +func parseNotifyBlocksCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { if len(r.Params) != 0 { return nil, btcjson.ErrWrongNumberOfParams } @@ -472,7 +472,7 @@ func (cmd *NotifyBlocksCmd) UnmarshalJSON(b []byte) error { return err } - newCmd, err := parseNotifyNewTXsCmd(&r) + newCmd, err := parseNotifyBlocksCmd(&r) if err != nil { return err } From f471d2b336662859a0902892d97a18cce5f1f131 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 21 Jan 2014 14:23:36 -0500 Subject: [PATCH 29/76] Add ExportWatchingWalletCmd. --- cmds.go | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 116 insertions(+), 7 deletions(-) diff --git a/cmds.go b/cmds.go index 04688e14..c11d02cf 100644 --- a/cmds.go +++ b/cmds.go @@ -14,6 +14,7 @@ import ( func init() { btcjson.RegisterCustomCmd("createencryptedwallet", parseCreateEncryptedWalletCmd) + btcjson.RegisterCustomCmd("exportwatchingwallet", parseExportWatchingWalletCmd) btcjson.RegisterCustomCmd("getaddressbalance", parseGetAddressBalanceCmd) btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd) btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd) @@ -101,6 +102,114 @@ func (cmd *GetCurrentNetCmd) UnmarshalJSON(b []byte) error { return nil } +// ExportWatchingWalletCmd is a type handling custom marshaling and +// unmarshaling of exportwatchingwallet JSON websocket extension +// commands. +type ExportWatchingWalletCmd struct { + id interface{} + Account string + Zip bool +} + +// Enforce that ExportWatchingWalletCmd satisifies the btcjson.Cmd +// interface. +var _ btcjson.Cmd = &ExportWatchingWalletCmd{} + +// NewExportWatchingWalletCmd creates a new ExportWatchingWalletCmd. +func NewExportWatchingWalletCmd(id interface{}, optArgs ...interface{}) (*ExportWatchingWalletCmd, error) { + if len(optArgs) > 2 { + return nil, btcjson.ErrTooManyOptArgs + } + + // Optional parameters set to their defaults. + account := "" + zip := false + + if len(optArgs) > 0 { + a, ok := optArgs[0].(string) + if !ok { + return nil, errors.New("first optarg account must be a string") + } + account = a + } + if len(optArgs) > 1 { + z, ok := optArgs[0].(bool) + if !ok { + return nil, errors.New("second optarg zip must be a boolean") + } + zip = z + } + + return &ExportWatchingWalletCmd{ + id: id, + Account: account, + Zip: zip, + }, nil +} + +// parseExportWatchingWalletCmd parses a RawCmd into a concrete type +// satisifying the btcjson.Cmd interface. This is used when registering +// the custom command with the btcjson parser. +func parseExportWatchingWalletCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + return NewExportWatchingWalletCmd(r.Id, r.Params...) +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *ExportWatchingWalletCmd) Id() interface{} { + return cmd.Id +} + +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *ExportWatchingWalletCmd) SetId(id interface{}) { + cmd.id = id +} + +// Method satisifies the Cmd interface by returning the RPC method. +func (cmd *ExportWatchingWalletCmd) Method() string { + return "exportwatchingwallet" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *ExportWatchingWalletCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "exportwatchingwallet", + Id: cmd.id, + } + + if cmd.Account != "" || cmd.Zip { + raw.Params = append(raw.Params, cmd.Account) + } + if cmd.Zip { + raw.Params = append(raw.Params, cmd.Zip) + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *ExportWatchingWalletCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseExportWatchingWalletCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*ExportWatchingWalletCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + // GetUnconfirmedBalanceCmd is a type handling custom marshaling and // unmarshaling of getunconfirmedbalance JSON websocket extension // commands. @@ -413,7 +522,7 @@ func (cmd *RescanCmd) UnmarshalJSON(b []byte) error { // unmarshaling of notifyblocks JSON websocket extension // commands. type NotifyBlocksCmd struct { - id interface{} + id interface{} } // Enforce that NotifyBlocksCmd satisifies the btcjson.Cmd interface. @@ -422,18 +531,18 @@ var _ btcjson.Cmd = &NotifyBlocksCmd{} // NewNotifyBlocksCmd creates a new NotifyBlocksCmd. func NewNotifyBlocksCmd(id interface{}) *NotifyBlocksCmd { return &NotifyBlocksCmd{ - id: id, + id: id, } } -// parseNotifyBlocksCmd parses a NotifyBlocksCmd into a concrete type +// parseNotifyBlocksCmd parses a NotifyBlocksCmd into a concrete type // satisifying the btcjson.Cmd interface. This is used when registering // the custom command with the btcjson parser. func parseNotifyBlocksCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { - if len(r.Params) != 0 { - return nil, btcjson.ErrWrongNumberOfParams - } - return NewNotifyBlocksCmd(r.Id), nil + if len(r.Params) != 0 { + return nil, btcjson.ErrWrongNumberOfParams + } + return NewNotifyBlocksCmd(r.Id), nil } // Id satisifies the Cmd interface by returning the ID of the command. From 8fb5c9f0e66448001d88ba1946fbf27b2a817b28 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 21 Jan 2014 15:10:12 -0500 Subject: [PATCH 30/76] Return the actual id value, not func. --- cmds.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds.go b/cmds.go index c11d02cf..cbca42ce 100644 --- a/cmds.go +++ b/cmds.go @@ -156,7 +156,7 @@ func parseExportWatchingWalletCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { // Id satisifies the Cmd interface by returning the ID of the command. func (cmd *ExportWatchingWalletCmd) Id() interface{} { - return cmd.Id + return cmd.id } // SetId satisifies the Cmd interface by setting the ID of the command. From e321b6bdc74d2e7c4562e125088961885570156f Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 22 Jan 2014 10:08:09 -0500 Subject: [PATCH 31/76] Rename exportwatchingwallet zip option to download. --- cmds.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cmds.go b/cmds.go index cbca42ce..45cddeb0 100644 --- a/cmds.go +++ b/cmds.go @@ -106,9 +106,9 @@ func (cmd *GetCurrentNetCmd) UnmarshalJSON(b []byte) error { // unmarshaling of exportwatchingwallet JSON websocket extension // commands. type ExportWatchingWalletCmd struct { - id interface{} - Account string - Zip bool + id interface{} + Account string + Download bool } // Enforce that ExportWatchingWalletCmd satisifies the btcjson.Cmd @@ -123,7 +123,7 @@ func NewExportWatchingWalletCmd(id interface{}, optArgs ...interface{}) (*Export // Optional parameters set to their defaults. account := "" - zip := false + dl := false if len(optArgs) > 0 { a, ok := optArgs[0].(string) @@ -133,17 +133,17 @@ func NewExportWatchingWalletCmd(id interface{}, optArgs ...interface{}) (*Export account = a } if len(optArgs) > 1 { - z, ok := optArgs[0].(bool) + b, ok := optArgs[0].(bool) if !ok { return nil, errors.New("second optarg zip must be a boolean") } - zip = z + dl = b } return &ExportWatchingWalletCmd{ - id: id, - Account: account, - Zip: zip, + id: id, + Account: account, + Download: dl, }, nil } @@ -178,11 +178,11 @@ func (cmd *ExportWatchingWalletCmd) MarshalJSON() ([]byte, error) { Id: cmd.id, } - if cmd.Account != "" || cmd.Zip { + if cmd.Account != "" || cmd.Download { raw.Params = append(raw.Params, cmd.Account) } - if cmd.Zip { - raw.Params = append(raw.Params, cmd.Zip) + if cmd.Download { + raw.Params = append(raw.Params, cmd.Download) } return json.Marshal(raw) From e745fffb83d860a73a9fa9271f64c2ed34bf64b5 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 22 Jan 2014 10:13:34 -0500 Subject: [PATCH 32/76] Fix slice index for parameter. --- cmds.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds.go b/cmds.go index 45cddeb0..a535568c 100644 --- a/cmds.go +++ b/cmds.go @@ -133,7 +133,7 @@ func NewExportWatchingWalletCmd(id interface{}, optArgs ...interface{}) (*Export account = a } if len(optArgs) > 1 { - b, ok := optArgs[0].(bool) + b, ok := optArgs[1].(bool) if !ok { return nil, errors.New("second optarg zip must be a boolean") } From 7e1c44369ce96a9a7af2d621f2cb1352adb1f665 Mon Sep 17 00:00:00 2001 From: "Owain G. Ainsworth" Date: Wed, 15 Jan 2014 21:51:21 +0000 Subject: [PATCH 33/76] Adapt to btcjson api changes. Add placeholder help text for all the json types that btcws adds. Jrick will fill them in when he adds documentation. --- cmds.go | 39 ++++++++++++++++++++++++++------------- notifications.go | 27 ++++++++++++++++++--------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/cmds.go b/cmds.go index a535568c..dc304d44 100644 --- a/cmds.go +++ b/cmds.go @@ -13,19 +13,32 @@ import ( ) func init() { - btcjson.RegisterCustomCmd("createencryptedwallet", parseCreateEncryptedWalletCmd) - btcjson.RegisterCustomCmd("exportwatchingwallet", parseExportWatchingWalletCmd) - btcjson.RegisterCustomCmd("getaddressbalance", parseGetAddressBalanceCmd) - btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd) - btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd) - btcjson.RegisterCustomCmd("getunconfirmedbalance", parseGetUnconfirmedBalanceCmd) - btcjson.RegisterCustomCmd("listaddresstransactions", parseListAddressTransactionsCmd) - btcjson.RegisterCustomCmd("listalltransactions", parseListAllTransactionsCmd) - btcjson.RegisterCustomCmd("notifyblocks", parseNotifyBlocksCmd) - btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd) - btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd) - btcjson.RegisterCustomCmd("rescan", parseRescanCmd) - btcjson.RegisterCustomCmd("walletislocked", parseWalletIsLockedCmd) + btcjson.RegisterCustomCmd("createencryptedwallet", + parseCreateEncryptedWalletCmd, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("exportwatchingwallet", + parseExportWatchingWalletCmd, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("getaddressbalance", + parseGetAddressBalanceCmd, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd, + `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd, + `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("getunconfirmedbalance", + parseGetUnconfirmedBalanceCmd, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("listaddresstransactions", + parseListAddressTransactionsCmd, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("listalltransactions", + parseListAllTransactionsCmd, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("notifyblocks", parseNotifyBlocksCmd, + `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd, + `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd, + `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("rescan", parseRescanCmd, + `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("walletislocked", parseWalletIsLockedCmd, + `TODO(jrick) fillmein`) } // GetCurrentNetCmd is a type handling custom marshaling and diff --git a/notifications.go b/notifications.go index 3fd4c7cb..59b0c2bb 100644 --- a/notifications.go +++ b/notifications.go @@ -57,15 +57,24 @@ const ( // Register notifications with btcjson. func init() { - btcjson.RegisterCustomCmd(AccountBalanceNtfnMethod, parseAccountBalanceNtfn) - btcjson.RegisterCustomCmd(BlockConnectedNtfnMethod, parseBlockConnectedNtfn) - btcjson.RegisterCustomCmd(BlockDisconnectedNtfnMethod, parseBlockDisconnectedNtfn) - btcjson.RegisterCustomCmd(BtcdConnectedNtfnMethod, parseBtcdConnectedNtfn) - btcjson.RegisterCustomCmd(ProcessedTxNtfnMethod, parseProcessedTxNtfn) - btcjson.RegisterCustomCmd(TxMinedNtfnMethod, parseTxMinedNtfn) - btcjson.RegisterCustomCmd(TxSpentNtfnMethod, parseTxSpentNtfn) - btcjson.RegisterCustomCmd(TxNtfnMethod, parseTxNtfn) - btcjson.RegisterCustomCmd(WalletLockStateNtfnMethod, parseWalletLockStateNtfn) + btcjson.RegisterCustomCmd(AccountBalanceNtfnMethod, + parseAccountBalanceNtfn, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(BlockConnectedNtfnMethod, + parseBlockConnectedNtfn, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(BlockDisconnectedNtfnMethod, + parseBlockDisconnectedNtfn, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(BtcdConnectedNtfnMethod, + parseBtcdConnectedNtfn, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(ProcessedTxNtfnMethod, + parseProcessedTxNtfn, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(TxMinedNtfnMethod, parseTxMinedNtfn, + `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(TxSpentNtfnMethod, parseTxSpentNtfn, + `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(TxNtfnMethod, parseTxNtfn, + `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(WalletLockStateNtfnMethod, + parseWalletLockStateNtfn, `TODO(jrick) fillmein`) } // AccountBalanceNtfn is a type handling custom marshaling and From 14dc8cee835f2fcbfea5eb02c45634014af17b6f Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 22 Jan 2014 13:11:01 -0600 Subject: [PATCH 34/76] Add new authenticate command. --- cmds.go | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/cmds.go b/cmds.go index dc304d44..4954792c 100644 --- a/cmds.go +++ b/cmds.go @@ -13,6 +13,11 @@ import ( ) func init() { + btcjson.RegisterCustomCmd("authenticate", parseAuthenticateCmd, + `authenticate "username" "passphrase" +Authenticate the websocket with the RPC server. This is only required if the +credentials were not already supplied via HTTP auth headers. It must be the +first command sent or you will be disconnected.`) btcjson.RegisterCustomCmd("createencryptedwallet", parseCreateEncryptedWalletCmd, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("exportwatchingwallet", @@ -41,6 +46,100 @@ func init() { `TODO(jrick) fillmein`) } +// AuthenticateCmd is a type handling custom marshaling and +// unmarshaling of authenticate JSON websocket extension +// commands. +type AuthenticateCmd struct { + id interface{} + Username string + Passphrase string +} + +// Enforce that AuthenticateCmd satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &AuthenticateCmd{} + +// NewAuthenticateCmd creates a new GetCurrentNetCmd. +func NewAuthenticateCmd(id interface{}, username, passphrase string) *AuthenticateCmd { + return &AuthenticateCmd{ + id: id, + Username: username, + Passphrase: passphrase, + } +} + +// parseAuthenticateCmd parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the custom +// command with the btcjson parser. +func parseAuthenticateCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) != 2 { + return nil, btcjson.ErrWrongNumberOfParams + } + + username, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter username must be a string") + } + + passphrase, ok := r.Params[1].(string) + if !ok { + return nil, errors.New("second parameter passphrase must be a string") + } + + return NewAuthenticateCmd(r.Id, username, passphrase), nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *AuthenticateCmd) Id() interface{} { + return cmd.id +} + +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *AuthenticateCmd) SetId(id interface{}) { + cmd.id = id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *AuthenticateCmd) Method() string { + return "authenticate" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *AuthenticateCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: cmd.Method(), + Id: cmd.id, + Params: []interface{}{ + cmd.Username, + cmd.Passphrase, + }, + } + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *AuthenticateCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseAuthenticateCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*AuthenticateCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + // GetCurrentNetCmd is a type handling custom marshaling and // unmarshaling of getcurrentnet JSON websocket extension // commands. From 413e02870214b8600fe7219b43ac417df97587bf Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Thu, 23 Jan 2014 10:56:20 -0500 Subject: [PATCH 35/76] Add RecoverAddressesCmd. --- cmds.go | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/cmds.go b/cmds.go index 4954792c..bf3eb63d 100644 --- a/cmds.go +++ b/cmds.go @@ -40,6 +40,8 @@ first command sent or you will be disconnected.`) `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("recoveraddresses", parseRecoverAddressesCmd, + `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("rescan", parseRescanCmd, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("walletislocked", parseWalletIsLockedCmd, @@ -503,6 +505,99 @@ func (cmd *GetBestBlockCmd) UnmarshalJSON(b []byte) error { return nil } +// RecoverAddressesCmd is a type handling custom marshaling and +// unmarshaling of recoveraddresses JSON websocket extension +// commands. +type RecoverAddressesCmd struct { + id interface{} + Account string + N int +} + +// Enforce that RecoverAddressesCmd satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &RecoverAddressesCmd{} + +// NewRecoverAddressesCmd creates a new RecoverAddressesCmd. +func NewRecoverAddressesCmd(id interface{}, account string, n int) *RecoverAddressesCmd { + return &RecoverAddressesCmd{ + id: id, + Account: account, + N: n, + } +} + +// parseRecoverAddressesCmd parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the custom +// command with the btcjson parser. +func parseRecoverAddressesCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) != 2 { + return nil, btcjson.ErrWrongNumberOfParams + } + + account, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter account must be a string") + } + n, ok := r.Params[1].(float64) + if !ok { + return nil, errors.New("second parameter n must be a number") + } + return NewRecoverAddressesCmd(r.Id, account, int(n)), nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *RecoverAddressesCmd) Id() interface{} { + return cmd.id +} + +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *RecoverAddressesCmd) SetId(id interface{}) { + cmd.id = id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *RecoverAddressesCmd) Method() string { + return "recoveraddresses" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *RecoverAddressesCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "recoveraddresses", + Id: cmd.id, + Params: []interface{}{ + cmd.Account, + cmd.N, + }, + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *RecoverAddressesCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseRecoverAddressesCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*RecoverAddressesCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + // RescanCmd is a type handling custom marshaling and // unmarshaling of rescan JSON websocket extension // commands. From 0f7f080f1946e09126dd528c6ecc7b46f5726cf7 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 24 Jan 2014 10:55:36 -0500 Subject: [PATCH 36/76] Move help texts into their own const group. --- cmds.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cmds.go b/cmds.go index bf3eb63d..b70c697d 100644 --- a/cmds.go +++ b/cmds.go @@ -12,12 +12,17 @@ import ( "github.com/conformal/btcwire" ) -func init() { - btcjson.RegisterCustomCmd("authenticate", parseAuthenticateCmd, - `authenticate "username" "passphrase" +// Help texts +const ( + authenticateHelp = `authenticate "username" "passphrase" Authenticate the websocket with the RPC server. This is only required if the credentials were not already supplied via HTTP auth headers. It must be the -first command sent or you will be disconnected.`) +first command sent or you will be disconnected.` +) + +func init() { + btcjson.RegisterCustomCmd("authenticate", parseAuthenticateCmd, + authenticateHelp) btcjson.RegisterCustomCmd("createencryptedwallet", parseCreateEncryptedWalletCmd, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("exportwatchingwallet", From 50a1c37317a087d6d64eabe0b83998bff398b025 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 24 Jan 2014 11:14:44 -0500 Subject: [PATCH 37/76] Remove parameters for createencryptedwallet. The createencryptedwallet extension RPC request should not be used to create wallets for additional accounts. Instead, all btcwallet accounts should use the same passphrase as the default account's wallet. This change removes the account name and description parameters from createencryptedwallet, as it will only be used to create the default account. --- cmds.go | 40 ++++++++++------------------------------ cmds_test.go | 8 ++------ 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/cmds.go b/cmds.go index b70c697d..cfc63d74 100644 --- a/cmds.go +++ b/cmds.go @@ -1007,10 +1007,8 @@ func (cmd *NotifySpentCmd) UnmarshalJSON(b []byte) error { // marshaling and unmarshaling of createencryptedwallet // JSON websocket extension commands. type CreateEncryptedWalletCmd struct { - id interface{} - Account string - Description string - Passphrase string + id interface{} + Passphrase string } // Enforce that CreateEncryptedWalletCmd satisifies the btcjson.Cmd @@ -1018,14 +1016,10 @@ type CreateEncryptedWalletCmd struct { var _ btcjson.Cmd = &CreateEncryptedWalletCmd{} // NewCreateEncryptedWalletCmd creates a new CreateEncryptedWalletCmd. -func NewCreateEncryptedWalletCmd(id interface{}, - account, description, passphrase string) *CreateEncryptedWalletCmd { - +func NewCreateEncryptedWalletCmd(id interface{}, passphrase string) *CreateEncryptedWalletCmd { return &CreateEncryptedWalletCmd{ - id: id, - Account: account, - Description: description, - Passphrase: passphrase, + id: id, + Passphrase: passphrase, } } @@ -1034,26 +1028,16 @@ func NewCreateEncryptedWalletCmd(id interface{}, // This is used when registering the custom command with the btcjson // parser. func parseCreateEncryptedWalletCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { - if len(r.Params) != 3 { + if len(r.Params) != 1 { return nil, btcjson.ErrWrongNumberOfParams } - account, ok := r.Params[0].(string) + passphrase, ok := r.Params[0].(string) if !ok { - return nil, errors.New("first parameter must be a string") - } - description, ok := r.Params[1].(string) - if !ok { - return nil, errors.New("second parameter is not a string") - } - passphrase, ok := r.Params[2].(string) - if !ok { - return nil, errors.New("third parameter is not a string") + return nil, errors.New("first parameter is not a string") } - cmd := NewCreateEncryptedWalletCmd(r.Id, account, description, - passphrase) - return cmd, nil + return NewCreateEncryptedWalletCmd(r.Id, passphrase), nil } // Id satisifies the Cmd interface by returning the ID of the command. @@ -1078,11 +1062,7 @@ func (cmd *CreateEncryptedWalletCmd) MarshalJSON() ([]byte, error) { Jsonrpc: "1.0", Method: "createencryptedwallet", Id: cmd.id, - Params: []interface{}{ - cmd.Account, - cmd.Description, - cmd.Passphrase, - }, + Params: []interface{}{cmd.Passphrase}, } return json.Marshal(raw) diff --git a/cmds_test.go b/cmds_test.go index 0e92526f..5a4865c1 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -24,15 +24,11 @@ var cmdtests = []struct { f: func() (btcjson.Cmd, error) { return NewCreateEncryptedWalletCmd( float64(1), - "abcde", - "description", "banana"), nil }, result: &CreateEncryptedWalletCmd{ - id: float64(1), - Account: "abcde", - Description: "description", - Passphrase: "banana", + id: float64(1), + Passphrase: "banana", }, }, { From 0e8cbf71e8e54f4ae5652b83679738424db7d1c5 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 4 Feb 2014 13:52:15 -0500 Subject: [PATCH 38/76] Replace Error with Errorf, found by go vet. --- notifications_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifications_test.go b/notifications_test.go index a7e8c057..a06f72dc 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -163,7 +163,7 @@ func TestNtfns(t *testing.T) { // verify that id is nil. if n.Id() != nil { - t.Error("%s: notification should not have non-nil id %v", + t.Errorf("%s: notification should not have non-nil id %v", test.name, n.Id()) continue } From 463029df766a71503cddb8653f5a7ccc9b52d52e Mon Sep 17 00:00:00 2001 From: David Hill Date: Tue, 4 Feb 2014 16:02:45 -0500 Subject: [PATCH 39/76] gofmt --- cmds_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmds_test.go b/cmds_test.go index 5a4865c1..2ac2f885 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -200,7 +200,7 @@ var cmdtests = []struct { name: "rescan no optargs", f: func() (btcjson.Cmd, error) { addrs := map[string]struct{}{ - "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": struct{}{}, + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": {}, } return NewRescanCmd( float64(1), @@ -211,7 +211,7 @@ var cmdtests = []struct { id: float64(1), BeginBlock: 270000, Addresses: map[string]struct{}{ - "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": struct{}{}, + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": {}, }, EndBlock: btcdb.AllShas, }, @@ -220,7 +220,7 @@ var cmdtests = []struct { name: "rescan one optarg", f: func() (btcjson.Cmd, error) { addrs := map[string]struct{}{ - "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": struct{}{}, + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": {}, } return NewRescanCmd( float64(1), @@ -232,7 +232,7 @@ var cmdtests = []struct { id: float64(1), BeginBlock: 270000, Addresses: map[string]struct{}{ - "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": struct{}{}, + "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": {}, }, EndBlock: 280000, }, From f6c7cf92fd07cf9f75388d7b70bbb701f362e067 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 4 Feb 2014 17:00:08 -0500 Subject: [PATCH 40/76] Make go vet happy. --- cmds_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds_test.go b/cmds_test.go index 2ac2f885..49fffebe 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -177,7 +177,7 @@ var cmdtests = []struct { name: "notifyspent", f: func() (btcjson.Cmd, error) { op := &btcwire.OutPoint{ - Hash: btcwire.ShaHash{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + Hash: [...]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, @@ -188,7 +188,7 @@ var cmdtests = []struct { result: &NotifySpentCmd{ id: float64(1), OutPoint: &btcwire.OutPoint{ - Hash: btcwire.ShaHash{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + Hash: [...]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, From 3cba42282e40cbc423ad1302bc44ffd060fc5824 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 4 Feb 2014 17:04:05 -0500 Subject: [PATCH 41/76] Fill in missing comment; found by golint. --- cmds.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmds.go b/cmds.go index cfc63d74..f08fe839 100644 --- a/cmds.go +++ b/cmds.go @@ -1195,6 +1195,8 @@ func (cmd *WalletIsLockedCmd) UnmarshalJSON(b []byte) error { return nil } +// ListAddressTransactionsCmd is a type handling custom marshaling and +// unmarshaling of listaddresstransactions JSON websocket extension commands. type ListAddressTransactionsCmd struct { id interface{} Account string From 07c403efd0a92d76385627656f3919bf2f1f4bcc Mon Sep 17 00:00:00 2001 From: Francis Lam Date: Sat, 8 Feb 2014 17:03:22 -0500 Subject: [PATCH 42/76] Added commands to support notifyallnewtxs Sending NotifyAllNewTXsCmd will register websocket client to receive notifications on all new transactions. Once registered the client will receive either AllTxNtfn or AllVerboseTxNtfn based on the required verbose field in the NotifyAllNewTXsCmd. --- cmds.go | 86 ++++++++++++++++++++ cmds_test.go | 12 +++ notifications.go | 184 ++++++++++++++++++++++++++++++++++++++++++ notifications_test.go | 31 +++++++ 4 files changed, 313 insertions(+) diff --git a/cmds.go b/cmds.go index f08fe839..668ed677 100644 --- a/cmds.go +++ b/cmds.go @@ -43,6 +43,8 @@ func init() { `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("notifyallnewtxs", parseNotifyAllNewTXsCmd, + `TODO(flam) fillmein`) btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("recoveraddresses", parseRecoverAddressesCmd, @@ -902,6 +904,90 @@ func (cmd *NotifyNewTXsCmd) UnmarshalJSON(b []byte) error { return nil } +// NotifyAllNewTXsCmd is a type handling custom marshaling and +// unmarshaling of notifynewtxs JSON websocket extension +// commands. +type NotifyAllNewTXsCmd struct { + id interface{} + Verbose bool +} + +// Enforce that NotifyAllNewTXsCmd satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &NotifyAllNewTXsCmd{} + +// NewNotifyAllNewTXsCmd creates a new NotifyAllNewTXsCmd. +func NewNotifyAllNewTXsCmd(id interface{}, verbose bool) *NotifyAllNewTXsCmd { + return &NotifyAllNewTXsCmd{ + id: id, + Verbose: verbose, + } +} + +// parseNotifyAllNewTXsCmd parses a NotifyAllNewTXsCmd into a concrete type +// satisifying the btcjson.Cmd interface. This is used when registering +// the custom command with the btcjson parser. +func parseNotifyAllNewTXsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) != 1 { + return nil, btcjson.ErrWrongNumberOfParams + } + + verbose := r.Params[0].(bool) + + return NewNotifyAllNewTXsCmd(r.Id, verbose), nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *NotifyAllNewTXsCmd) Id() interface{} { + return cmd.id +} + +// SetId satisifies the Cmd interface by setting the ID of the command. +func (cmd *NotifyAllNewTXsCmd) SetId(id interface{}) { + cmd.id = id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *NotifyAllNewTXsCmd) Method() string { + return "notifyallnewtxs" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *NotifyAllNewTXsCmd) MarshalJSON() ([]byte, error) { + // Fill a RawCmd and marshal. + raw := btcjson.RawCmd{ + Jsonrpc: "1.0", + Method: "notifyallnewtxs", + Id: cmd.id, + Params: []interface{}{ + cmd.Verbose, + }, + } + + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *NotifyAllNewTXsCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseNotifyAllNewTXsCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*NotifyAllNewTXsCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + // NotifySpentCmd is a type handling custom marshaling and // unmarshaling of notifyspent JSON websocket extension // commands. diff --git a/cmds_test.go b/cmds_test.go index 49fffebe..0a2375c6 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -173,6 +173,18 @@ var cmdtests = []struct { }, }, }, + { + name: "notifyallnewtxs", + f: func() (btcjson.Cmd, error) { + return NewNotifyAllNewTXsCmd( + float64(1), + true), nil + }, + result: &NotifyAllNewTXsCmd{ + id: float64(1), + Verbose: true, + }, + }, { name: "notifyspent", f: func() (btcjson.Cmd, error) { diff --git a/notifications.go b/notifications.go index 59b0c2bb..2d5fa72c 100644 --- a/notifications.go +++ b/notifications.go @@ -38,6 +38,14 @@ const ( // processedtx notification. ProcessedTxNtfnMethod = "processedtx" + // AllTxNtfnMethod is the method of the btcd alltx + // notification + AllTxNtfnMethod = "alltx" + + // AllVerboseTxNtfnMethod is the method of the btcd + // allverbosetx notifications. + AllVerboseTxNtfnMethod = "allverbosetx" + // TxMinedNtfnMethod is the method of the btcd txmined // notification. TxMinedNtfnMethod = "txmined" @@ -75,6 +83,10 @@ func init() { `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(WalletLockStateNtfnMethod, parseWalletLockStateNtfn, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(AllTxNtfnMethod, + parseAllTxNtfn, `TODO(flam) fillmein`) + btcjson.RegisterCustomCmdGenerator(AllVerboseTxNtfnMethod, + generateAllVerboseTxNtfn) } // AccountBalanceNtfn is a type handling custom marshaling and @@ -1015,3 +1027,175 @@ func (n *WalletLockStateNtfn) UnmarshalJSON(b []byte) error { *n = *concreteNtfn return nil } + +// AllTxNtfn is a type handling custom marshaling and +// unmarshaling of txmined JSON websocket notifications. +type AllTxNtfn struct { + TxID string + Amount int64 +} + +// Enforce that AllTxNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &AllTxNtfn{} + +// NewAllTxNtfn creates a new AllTxNtfn. +func NewAllTxNtfn(txid string, amount int64) *AllTxNtfn { + return &AllTxNtfn{ + TxID: txid, + Amount: amount, + } +} + +// parseAllTxNtfn parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the notification +// with the btcjson parser. +func parseAllTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 2 { + return nil, btcjson.ErrWrongNumberOfParams + } + + txid, ok := r.Params[0].(string) + if !ok { + return nil, errors.New("first parameter txid must be a string") + } + famount, ok := r.Params[1].(float64) + if !ok { + return nil, errors.New("second parameter amount must be a number") + } + + return NewAllTxNtfn(txid, int64(famount)), nil +} + +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *AllTxNtfn) Id() interface{} { + return nil +} + +// SetId is implemented to satisify the btcjson.Cmd interface. The +// notification id is not modified. +func (n *AllTxNtfn) SetId(id interface{}) {} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *AllTxNtfn) Method() string { + return AllTxNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd +// interface. +func (n *AllTxNtfn) MarshalJSON() ([]byte, error) { + ntfn := btcjson.Message{ + Jsonrpc: "1.0", + Method: n.Method(), + Params: []interface{}{ + n.TxID, + n.Amount, + }, + } + return json.Marshal(ntfn) +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the btcjson.Cmd interface. +func (n *AllTxNtfn) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newNtfn, err := parseAllTxNtfn(&r) + if err != nil { + return err + } + + concreteNtfn, ok := newNtfn.(*AllTxNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn + return nil +} + +// AllVerboseTxNtfn is a type handling custom marshaling and +// unmarshaling of txmined JSON websocket notifications. +type AllVerboseTxNtfn struct { + RawTx *btcjson.TxRawResult +} + +// Enforce that AllTxNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &AllVerboseTxNtfn{} + +// NewAllVerboseTxNtfn creates a new AllVerboseTxNtfn. +func NewAllVerboseTxNtfn(rawTx *btcjson.TxRawResult) *AllVerboseTxNtfn { + return &AllVerboseTxNtfn{ + RawTx: rawTx, + } +} + +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *AllVerboseTxNtfn) Id() interface{} { + return nil +} + +// SetId is implemented to satisify the btcjson.Cmd interface. The +// notification id is not modified. +func (n *AllVerboseTxNtfn) SetId(id interface{}) {} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *AllVerboseTxNtfn) Method() string { + return AllVerboseTxNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd +// interface. +func (n *AllVerboseTxNtfn) MarshalJSON() ([]byte, error) { + ntfn := btcjson.Message{ + Jsonrpc: "1.0", + Method: n.Method(), + Params: []interface{}{ + n.RawTx, + }, + } + return json.Marshal(ntfn) +} + +func generateAllVerboseTxNtfn() btcjson.Cmd { + return new(AllVerboseTxNtfn) +} + +type rawParamsCmd struct { + Jsonrpc string `json:"jsonrpc"` + Id interface{} `json:"id"` + Method string `json:"method"` + Params []*json.RawMessage `json:"params"` +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the btcjson.Cmd interface. +func (n *AllVerboseTxNtfn) UnmarshalJSON(b []byte) error { + // Unmarshal into a custom rawParamsCmd + var r rawParamsCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + if len(r.Params) != 1 { + return btcjson.ErrWrongNumberOfParams + } + + var rawTx *btcjson.TxRawResult + if err := json.Unmarshal(*r.Params[0], &rawTx); err != nil { + return err + } + + *n = *NewAllVerboseTxNtfn(rawTx) + return nil +} diff --git a/notifications_test.go b/notifications_test.go index a06f72dc..d70abee3 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -154,6 +154,37 @@ var ntfntests = []struct { Locked: true, }, }, + { + name: "alltx", + f: func() btcjson.Cmd { + return btcws.NewAllTxNtfn( + "062f2b5f7d28c787e0f3aee382132241cd590efb7b83bd2c7f506de5aa4ef275", + 34567765) + }, + result: &btcws.AllTxNtfn{ + TxID: "062f2b5f7d28c787e0f3aee382132241cd590efb7b83bd2c7f506de5aa4ef275", + Amount: 34567765, + }, + }, + { + name: "allverbosetx", + f: func() btcjson.Cmd { + return btcws.NewAllVerboseTxNtfn(&btcjson.TxRawResult{ + Hex: "01000000010cdf900074a3622499a2f28f44a94476f27a8900a2bdd60e042754b6cab09741000000008a473044022012e11012fad1eb21ba1c82deb8da98778b08e714b72f281293064528343fae0502204294d7520f469f9673087a55395de0ce0e9074dce236db9fe7f30013b5fd00b90141047b6ff7832b4a763666e5481a0bd9eedb656d9f882d215c16fe9563d7b191cd67b2a41601a853a9f9d92773ae6f912ef451a089148e510623759cf55c408efdefffffffff02f4063f00000000001976a914b269e0ceec5d5b5e192cf580ae42341e0f79b0b588aca8c84b02000000001976a91439233c0d43a1411e547c60bad8985bae3530b6af88ac00000000", + Txid: "0cfeb968fb5d0f6b9a2a1de37c0607a1964dd3e335f203377cec90e03b20869e", + Version: 0x1, + LockTime: 0x0, + }) + }, + result: &btcws.AllVerboseTxNtfn{ + RawTx: &btcjson.TxRawResult{ + Hex: "01000000010cdf900074a3622499a2f28f44a94476f27a8900a2bdd60e042754b6cab09741000000008a473044022012e11012fad1eb21ba1c82deb8da98778b08e714b72f281293064528343fae0502204294d7520f469f9673087a55395de0ce0e9074dce236db9fe7f30013b5fd00b90141047b6ff7832b4a763666e5481a0bd9eedb656d9f882d215c16fe9563d7b191cd67b2a41601a853a9f9d92773ae6f912ef451a089148e510623759cf55c408efdefffffffff02f4063f00000000001976a914b269e0ceec5d5b5e192cf580ae42341e0f79b0b588aca8c84b02000000001976a91439233c0d43a1411e547c60bad8985bae3530b6af88ac00000000", + Txid: "0cfeb968fb5d0f6b9a2a1de37c0607a1964dd3e335f203377cec90e03b20869e", + Version: 0x1, + LockTime: 0x0, + }, + }, + }, } func TestNtfns(t *testing.T) { From bb9d3696b40f50fd3f24ecd1efd5b8a9af12ed4f Mon Sep 17 00:00:00 2001 From: Francis Lam Date: Sat, 8 Feb 2014 18:26:06 -0500 Subject: [PATCH 43/76] Changed NewNotifyAllNewTXsCmd to optionally accept verbose arg --- cmds.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmds.go b/cmds.go index 668ed677..fdc09160 100644 --- a/cmds.go +++ b/cmds.go @@ -915,25 +915,40 @@ type NotifyAllNewTXsCmd struct { // Enforce that NotifyAllNewTXsCmd satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &NotifyAllNewTXsCmd{} -// NewNotifyAllNewTXsCmd creates a new NotifyAllNewTXsCmd. -func NewNotifyAllNewTXsCmd(id interface{}, verbose bool) *NotifyAllNewTXsCmd { +// NewNotifyAllNewTXsCmd creates a new NotifyAllNewTXsCmd that optionally +// takes a single verbose parameter that defaults to false. +func NewNotifyAllNewTXsCmd(id interface{}, optArgs ...bool) (*NotifyAllNewTXsCmd, error) { + verbose := false + + optArgsLen := len(optArgs) + if optArgsLen > 0 { + if optArgsLen > 1 { + return nil, btcjson.ErrTooManyOptArgs + } + verbose = optArgs[0] + } + return &NotifyAllNewTXsCmd{ id: id, Verbose: verbose, - } + }, nil } // parseNotifyAllNewTXsCmd parses a NotifyAllNewTXsCmd into a concrete type // satisifying the btcjson.Cmd interface. This is used when registering // the custom command with the btcjson parser. func parseNotifyAllNewTXsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { - if len(r.Params) != 1 { - return nil, btcjson.ErrWrongNumberOfParams + verbose := false + numParams := len(r.Params) + + if numParams > 0 { + if numParams > 1 { + return nil, btcjson.ErrWrongNumberOfParams + } + verbose = r.Params[0].(bool) } - verbose := r.Params[0].(bool) - - return NewNotifyAllNewTXsCmd(r.Id, verbose), nil + return NewNotifyAllNewTXsCmd(r.Id, verbose) } // Id satisifies the Cmd interface by returning the ID of the command. From 0821c583e583ae4732d1dbc214449febda72e4a7 Mon Sep 17 00:00:00 2001 From: Francis Lam Date: Sun, 9 Feb 2014 13:43:02 -0500 Subject: [PATCH 44/76] Added explicit json key names to new tx notifications Also added check for nil ID on AllVerboseTxNtfn.UnmarshalJSON to make it consistent with other notification handling. --- notifications.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/notifications.go b/notifications.go index 2d5fa72c..f00683a6 100644 --- a/notifications.go +++ b/notifications.go @@ -1031,8 +1031,8 @@ func (n *WalletLockStateNtfn) UnmarshalJSON(b []byte) error { // AllTxNtfn is a type handling custom marshaling and // unmarshaling of txmined JSON websocket notifications. type AllTxNtfn struct { - TxID string - Amount int64 + TxID string `json:"txid"` + Amount int64 `json:"amount"` } // Enforce that AllTxNtfn satisifies the btcjson.Cmd interface. @@ -1125,7 +1125,7 @@ func (n *AllTxNtfn) UnmarshalJSON(b []byte) error { // AllVerboseTxNtfn is a type handling custom marshaling and // unmarshaling of txmined JSON websocket notifications. type AllVerboseTxNtfn struct { - RawTx *btcjson.TxRawResult + RawTx *btcjson.TxRawResult `json:"rawtx"` } // Enforce that AllTxNtfn satisifies the btcjson.Cmd interface. @@ -1187,6 +1187,10 @@ func (n *AllVerboseTxNtfn) UnmarshalJSON(b []byte) error { return err } + if r.Id != nil { + return ErrNotANtfn + } + if len(r.Params) != 1 { return btcjson.ErrWrongNumberOfParams } From 5c666417351a31c54a7569553198d0763a2337e9 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 10 Feb 2014 09:11:25 -0500 Subject: [PATCH 45/76] Make tests build again. --- cmds_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds_test.go b/cmds_test.go index 0a2375c6..0b048dd7 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -178,7 +178,7 @@ var cmdtests = []struct { f: func() (btcjson.Cmd, error) { return NewNotifyAllNewTXsCmd( float64(1), - true), nil + true) }, result: &NotifyAllNewTXsCmd{ id: float64(1), From bb4cba51cdb939016061d69aaf395d7fc965cf38 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 17 Feb 2014 13:45:06 -0500 Subject: [PATCH 46/76] Switch to new transaction notifications. This change removes the processedtx notification, replacing it with recvtx, and the spenttx notification, replacing it with redeemingtx. Both new transactions return the full serialized transaction (encoded in hexadecimal) rather than details about the transaction. The old txmined notification has also been completely removed as it is unreliable due to transaction malleability and no code should be depending on it. --- notifications.go | 464 +++++++++++++++++------------------------- notifications_test.go | 92 ++++----- test_coverage.txt | 243 +++++++++++++--------- 3 files changed, 373 insertions(+), 426 deletions(-) diff --git a/notifications.go b/notifications.go index f00683a6..e399b30b 100644 --- a/notifications.go +++ b/notifications.go @@ -22,6 +22,14 @@ const ( // accountbalance notification. AccountBalanceNtfnMethod = "accountbalance" + // AllTxNtfnMethod is the method of the btcd alltx + // notification + AllTxNtfnMethod = "alltx" + + // AllVerboseTxNtfnMethod is the method of the btcd + // allverbosetx notifications. + AllVerboseTxNtfnMethod = "allverbosetx" + // BlockConnectedNtfnMethod is the method of the btcd // blockconnected notification. BlockConnectedNtfnMethod = "blockconnected" @@ -34,29 +42,16 @@ const ( // btcdconnected notification. BtcdConnectedNtfnMethod = "btcdconnected" - // ProcessedTxNtfnMethod is the method of the btcd - // processedtx notification. - ProcessedTxNtfnMethod = "processedtx" - - // AllTxNtfnMethod is the method of the btcd alltx - // notification - AllTxNtfnMethod = "alltx" - - // AllVerboseTxNtfnMethod is the method of the btcd - // allverbosetx notifications. - AllVerboseTxNtfnMethod = "allverbosetx" - - // TxMinedNtfnMethod is the method of the btcd txmined - // notification. - TxMinedNtfnMethod = "txmined" + // RecvTxNtfnMethod is the method of the btcd recvtx notification. + RecvTxNtfnMethod = "recvtx" // TxNtfnMethod is the method of the btcwallet newtx // notification. TxNtfnMethod = "newtx" - // TxSpentNtfnMethod is the method of the btcd txspent + // RedeemingTxNtfnMethod is the method of the btcd redeemingtx // notification. - TxSpentNtfnMethod = "txspent" + RedeemingTxNtfnMethod = "redeemingtx" // WalletLockStateNtfnMethod is the method of the btcwallet // walletlockstate notification. @@ -73,11 +68,9 @@ func init() { parseBlockDisconnectedNtfn, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(BtcdConnectedNtfnMethod, parseBtcdConnectedNtfn, `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd(ProcessedTxNtfnMethod, - parseProcessedTxNtfn, `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd(TxMinedNtfnMethod, parseTxMinedNtfn, - `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd(TxSpentNtfnMethod, parseTxSpentNtfn, + btcjson.RegisterCustomCmd(RecvTxNtfnMethod, + parseRecvTxNtfn, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(RedeemingTxNtfnMethod, parseRedeemingTxNtfn, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(TxNtfnMethod, parseTxNtfn, `TODO(jrick) fillmein`) @@ -89,6 +82,14 @@ func init() { generateAllVerboseTxNtfn) } +// BlockDetails describes details of a tx in a block. +type BlockDetails struct { + Height int32 + Hash string + Index int + Time int64 +} + // AccountBalanceNtfn is a type handling custom marshaling and // unmarshaling of accountbalance JSON websocket notifications. type AccountBalanceNtfn struct { @@ -453,7 +454,7 @@ func (n *BtcdConnectedNtfn) UnmarshalJSON(b []byte) error { return err } - newNtfn, err := parseTxMinedNtfn(&r) + newNtfn, err := parseBtcdConnectedNtfn(&r) if err != nil { return err } @@ -466,150 +467,136 @@ func (n *BtcdConnectedNtfn) UnmarshalJSON(b []byte) error { return nil } -// ProcessedTxNtfn is a type handling custom marshaling and unmarshaling -// of processedtx JSON websocket notifications. -type ProcessedTxNtfn struct { - Receiver string - Amount int64 - TxID string - TxOutIndex uint32 - PkScript string - BlockHash string - BlockHeight int32 - BlockIndex int - BlockTime int64 - Spent bool +// RecvTxNtfn is a type handling custom marshaling and unmarshaling +// of recvtx JSON websocket notifications. +type RecvTxNtfn struct { + HexTx string + Block *BlockDetails } -// Enforce that ProcessedTxNtfn satisifies the btcjson.Cmd interface. -var _ btcjson.Cmd = &ProcessedTxNtfn{} +// Enforce that RecvTxNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &RecvTxNtfn{} -// parseProcessedTxNtfn parses a RawCmd into a concrete type satisifying -// the btcjson.Cmd interface. This is used when registering the notification -// with the btcjson parser. -func parseProcessedTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { +// NewRecvTxNtfn creates a new RecvTxNtfn. +func NewRecvTxNtfn(hextx string, block *BlockDetails) *RecvTxNtfn { + return &RecvTxNtfn{ + HexTx: hextx, + Block: block, + } +} + +// parsRecvTxNtfn parses a RawCmd into a concrete type satisifying the +// btcjson.Cmd interface. This is used when registering the notification with +// the btcjson parser. +func parseRecvTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { if r.Id != nil { return nil, ErrNotANtfn } - if len(r.Params) != 10 { + // Must have one or two parameters. + if len(r.Params) == 0 || len(r.Params) > 2 { return nil, btcjson.ErrWrongNumberOfParams } - receiver, ok := r.Params[0].(string) + hextx, ok := r.Params[0].(string) if !ok { - return nil, errors.New("first parameter receiver must be a string") - } - famount, ok := r.Params[1].(float64) - if !ok { - return nil, errors.New("second parameter amount must be a number") - } - amount := int64(famount) - txid, ok := r.Params[2].(string) - if !ok { - return nil, errors.New("third parameter txid must be a string") - } - fTxOutIdx, ok := r.Params[3].(float64) - if !ok { - return nil, errors.New("fourth parameter txoutidx must be a number") - } - txOutIdx := uint32(fTxOutIdx) - pkScript, ok := r.Params[4].(string) - if !ok { - return nil, errors.New("fifth parameter pkScript must be a string") - } - blockHash := r.Params[5].(string) - if !ok { - return nil, errors.New("sixth parameter blockHash must be a string") - } - fBlockHeight, ok := r.Params[6].(float64) - if !ok { - return nil, errors.New("seventh parameter blockHeight must be a number") - } - blockHeight := int32(fBlockHeight) - fBlockIndex, ok := r.Params[7].(float64) - if !ok { - return nil, errors.New("eighth parameter blockIndex must be a number") - } - blockIndex := int(fBlockIndex) - fBlockTime, ok := r.Params[8].(float64) - if !ok { - return nil, errors.New("ninth parameter blockTime must be a number") - } - blockTime := int64(fBlockTime) - spent, ok := r.Params[9].(bool) - if !ok { - return nil, errors.New("tenth parameter spent must be a bool") + return nil, errors.New("first parameter hextx must be a string") } - cmd := &ProcessedTxNtfn{ - Receiver: receiver, - Amount: amount, - TxID: txid, - TxOutIndex: txOutIdx, - PkScript: pkScript, - BlockHash: blockHash, - BlockHeight: blockHeight, - BlockIndex: blockIndex, - BlockTime: blockTime, - Spent: spent, + ntfn := &RecvTxNtfn{HexTx: hextx} + + if len(r.Params) > 1 { + details, ok := r.Params[1].(map[string]interface{}) + if !ok { + return nil, errors.New("second parameter must be a JSON object") + } + + height, ok := details["height"].(float64) + if !ok { + return nil, errors.New("unspecified block height") + } + + hash, ok := details["hash"].(string) + if !ok { + return nil, errors.New("unspecified block hash") + } + + index, ok := details["index"].(float64) + if !ok { + return nil, errors.New("unspecified block index") + } + + time, ok := details["time"].(float64) + if !ok { + return nil, errors.New("unspecified block time") + } + + ntfn.Block = &BlockDetails{ + Height: int32(height), + Hash: hash, + Index: int(index), + Time: int64(time), + } } - return cmd, nil + + return ntfn, nil } // Id satisifies the btcjson.Cmd interface by returning nil for a // notification ID. -func (n *ProcessedTxNtfn) Id() interface{} { +func (n *RecvTxNtfn) Id() interface{} { return nil } // SetId is implemented to satisify the btcjson.Cmd interface. The // notification id is not modified. -func (n *ProcessedTxNtfn) SetId(id interface{}) {} +func (n *RecvTxNtfn) SetId(id interface{}) {} // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. -func (n *ProcessedTxNtfn) Method() string { - return ProcessedTxNtfnMethod +func (n *RecvTxNtfn) Method() string { + return RecvTxNtfnMethod } // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. -func (n *ProcessedTxNtfn) MarshalJSON() ([]byte, error) { +func (n *RecvTxNtfn) MarshalJSON() ([]byte, error) { + params := []interface{}{n.HexTx} + + if n.Block != nil { + details := map[string]interface{}{ + "height": float64(n.Block.Height), + "hash": n.Block.Hash, + "index": float64(n.Block.Index), + "time": float64(n.Block.Time), + } + params = append(params, details) + } + ntfn := btcjson.Message{ Jsonrpc: "1.0", Method: n.Method(), - Params: []interface{}{ - n.Receiver, - n.Amount, - n.TxID, - n.TxOutIndex, - n.PkScript, - n.BlockHash, - n.BlockHeight, - n.BlockIndex, - n.BlockTime, - n.Spent, - }, + Params: params, } + return json.Marshal(ntfn) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of // the btcjson.Cmd interface. -func (n *ProcessedTxNtfn) UnmarshalJSON(b []byte) error { +func (n *RecvTxNtfn) UnmarshalJSON(b []byte) error { // Unmarshal into a RawCmd. var r btcjson.RawCmd if err := json.Unmarshal(b, &r); err != nil { return err } - newNtfn, err := parseProcessedTxNtfn(&r) + newNtfn, err := parseRecvTxNtfn(&r) if err != nil { return err } - concreteNtfn, ok := newNtfn.(*ProcessedTxNtfn) + concreteNtfn, ok := newNtfn.(*RecvTxNtfn) if !ok { return btcjson.ErrInternal } @@ -617,117 +604,136 @@ func (n *ProcessedTxNtfn) UnmarshalJSON(b []byte) error { return nil } -// TxMinedNtfn is a type handling custom marshaling and -// unmarshaling of txmined JSON websocket notifications. -type TxMinedNtfn struct { - TxID string - BlockHash string - BlockHeight int32 - BlockTime int64 - Index int +// RedeemingTxNtfn is a type handling custom marshaling and unmarshaling +// of redeemingtx JSON websocket notifications. +type RedeemingTxNtfn struct { + HexTx string + Block *BlockDetails } -// Enforce that TxMinedNtfn satisifies the btcjson.Cmd interface. -var _ btcjson.Cmd = &TxMinedNtfn{} +// Enforce that RedeemingTxNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &RedeemingTxNtfn{} -// NewTxMinedNtfn creates a new TxMinedNtfn. -func NewTxMinedNtfn(txid, blockhash string, blockheight int32, - blocktime int64, index int) *TxMinedNtfn { - - return &TxMinedNtfn{ - TxID: txid, - BlockHash: blockhash, - BlockHeight: blockheight, - BlockTime: blocktime, - Index: index, +// NewRedeemingTxNtfn creates a new RedeemingTxNtfn. +func NewRedeemingTxNtfn(hextx string, block *BlockDetails) *RedeemingTxNtfn { + return &RedeemingTxNtfn{ + HexTx: hextx, + Block: block, } } -// parseTxMinedNtfn parses a RawCmd into a concrete type satisifying -// the btcjson.Cmd interface. This is used when registering the notification -// with the btcjson parser. -func parseTxMinedNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { +// parseRedeemingTxNtfn parses a RawCmd into a concrete type satisifying the +// btcjson.Cmd interface. This is used when registering the notification with +// the btcjson parser. +func parseRedeemingTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { if r.Id != nil { return nil, ErrNotANtfn } - if len(r.Params) != 5 { + // Must have one or two parameters. + if len(r.Params) == 0 || len(r.Params) > 2 { return nil, btcjson.ErrWrongNumberOfParams } - txid, ok := r.Params[0].(string) + hextx, ok := r.Params[0].(string) if !ok { - return nil, errors.New("first parameter txid must be a string") - } - blockhash, ok := r.Params[1].(string) - if !ok { - return nil, errors.New("second parameter blockhash must be a string") - } - fblockheight, ok := r.Params[2].(float64) - if !ok { - return nil, errors.New("third parameter blockheight must be a number") - } - fblocktime, ok := r.Params[3].(float64) - if !ok { - return nil, errors.New("fourth parameter blocktime must be a number") - } - findex, ok := r.Params[4].(float64) - if !ok { - return nil, errors.New("fifth parameter index must be a number") + return nil, errors.New("first parameter hextx must be a string") } - return NewTxMinedNtfn(txid, blockhash, int32(fblockheight), - int64(fblocktime), int(findex)), nil + ntfn := &RedeemingTxNtfn{HexTx: hextx} + + if len(r.Params) > 1 { + details, ok := r.Params[1].(map[string]interface{}) + if !ok { + return nil, errors.New("second parameter must be a JSON object") + } + + height, ok := details["height"].(float64) + if !ok { + return nil, errors.New("unspecified block height") + } + + hash, ok := details["hash"].(string) + if !ok { + return nil, errors.New("unspecified block hash") + } + + index, ok := details["index"].(float64) + if !ok { + return nil, errors.New("unspecified block index") + } + + time, ok := details["time"].(float64) + if !ok { + return nil, errors.New("unspecified block time") + } + + ntfn.Block = &BlockDetails{ + Height: int32(height), + Hash: hash, + Index: int(index), + Time: int64(time), + } + } + + return ntfn, nil } // Id satisifies the btcjson.Cmd interface by returning nil for a // notification ID. -func (n *TxMinedNtfn) Id() interface{} { +func (n *RedeemingTxNtfn) Id() interface{} { return nil } // SetId is implemented to satisify the btcjson.Cmd interface. The // notification id is not modified. -func (n *TxMinedNtfn) SetId(id interface{}) {} +func (n *RedeemingTxNtfn) SetId(id interface{}) {} // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. -func (n *TxMinedNtfn) Method() string { - return TxMinedNtfnMethod +func (n *RedeemingTxNtfn) Method() string { + return RedeemingTxNtfnMethod } // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. -func (n *TxMinedNtfn) MarshalJSON() ([]byte, error) { +func (n *RedeemingTxNtfn) MarshalJSON() ([]byte, error) { + params := []interface{}{n.HexTx} + + if n.Block != nil { + details := map[string]interface{}{ + "height": float64(n.Block.Height), + "hash": n.Block.Hash, + "index": float64(n.Block.Index), + "time": float64(n.Block.Time), + } + params = append(params, details) + } + ntfn := btcjson.Message{ Jsonrpc: "1.0", Method: n.Method(), - Params: []interface{}{ - n.TxID, - n.BlockHash, - n.BlockHeight, - n.BlockTime, - n.Index, - }, + Params: params, } + return json.Marshal(ntfn) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of // the btcjson.Cmd interface. -func (n *TxMinedNtfn) UnmarshalJSON(b []byte) error { +func (n *RedeemingTxNtfn) UnmarshalJSON(b []byte) error { // Unmarshal into a RawCmd. var r btcjson.RawCmd if err := json.Unmarshal(b, &r); err != nil { return err } - newNtfn, err := parseTxMinedNtfn(&r) + newNtfn, err := parseRedeemingTxNtfn(&r) if err != nil { return err } - concreteNtfn, ok := newNtfn.(*TxMinedNtfn) + concreteNtfn, ok := newNtfn.(*RedeemingTxNtfn) if !ok { return btcjson.ErrInternal } @@ -742,108 +748,6 @@ type TxNtfn struct { Details map[string]interface{} } -// TxSpentNtfn is a type handling custom marshaling and -// unmarshaling of txspent JSON websocket notifications. -type TxSpentNtfn struct { - SpentTxId string - SpentTxOutIndex int - SpendingTx string -} - -// Enforce that TxSpentNtfn satisifies the btcjson.Cmd interface. -var _ btcjson.Cmd = &TxSpentNtfn{} - -// NewTxSpentNtfn creates a new TxSpentNtfn. -func NewTxSpentNtfn(txid string, txOutIndex int, spendingTx string) *TxSpentNtfn { - return &TxSpentNtfn{ - SpentTxId: txid, - SpentTxOutIndex: txOutIndex, - SpendingTx: spendingTx, - } -} - -// parseTxSpentNtfn parses a RawCmd into a concrete type satisifying -// the btcjson.Cmd interface. This is used when registering the notification -// with the btcjson parser. -func parseTxSpentNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { - if r.Id != nil { - return nil, ErrNotANtfn - } - - if len(r.Params) != 3 { - return nil, btcjson.ErrWrongNumberOfParams - } - - txid, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter txid must be a string") - } - findex, ok := r.Params[1].(float64) - if !ok { - return nil, errors.New("second parameter index must be a number") - } - index := int(findex) - spendingTx, ok := r.Params[2].(string) - if !ok { - return nil, errors.New("third parameter spendingTx must be a string") - } - - return NewTxSpentNtfn(txid, index, spendingTx), nil -} - -// Id satisifies the btcjson.Cmd interface by returning nil for a -// notification ID. -func (n *TxSpentNtfn) Id() interface{} { - return nil -} - -// SetId is implemented to satisify the btcjson.Cmd interface. The -// notification id is not modified. -func (n *TxSpentNtfn) SetId(id interface{}) {} - -// Method satisifies the btcjson.Cmd interface by returning the method -// of the notification. -func (n *TxSpentNtfn) Method() string { - return TxSpentNtfnMethod -} - -// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd -// interface. -func (n *TxSpentNtfn) MarshalJSON() ([]byte, error) { - ntfn := btcjson.Message{ - Jsonrpc: "1.0", - Method: n.Method(), - Params: []interface{}{ - n.SpentTxId, - n.SpentTxOutIndex, - n.SpendingTx, - }, - } - return json.Marshal(ntfn) -} - -// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of -// the btcjson.Cmd interface. -func (n *TxSpentNtfn) UnmarshalJSON(b []byte) error { - // Unmarshal into a RawCmd. - var r btcjson.RawCmd - if err := json.Unmarshal(b, &r); err != nil { - return err - } - - newNtfn, err := parseTxSpentNtfn(&r) - if err != nil { - return err - } - - concreteNtfn, ok := newNtfn.(*TxSpentNtfn) - if !ok { - return btcjson.ErrInternal - } - *n = *concreteNtfn - return nil -} - // Enforce that TxNtfn satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &TxNtfn{} diff --git a/notifications_test.go b/notifications_test.go index d70abee3..b099bd0a 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -62,65 +62,65 @@ var ntfntests = []struct { }, }, { - name: "processedtx", + name: "recvtx no block", f: func() btcjson.Cmd { - cmd := &btcws.ProcessedTxNtfn{ - Receiver: "miFxiuApPo3KBqtMnPUjasZmHoVnoH3Eoc", - Amount: 200000000, - TxID: "851f5c0652e785c5ed80aafaf2d918e5cbe5c307dbba3680808ada1d01f36886", - TxOutIndex: 1, - PkScript: "76a9141e127eda7cd71b9724085f588840a3e9d697ae9888ac", - BlockHash: "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", - BlockHeight: 153469, - BlockIndex: 1, - BlockTime: 1386944019, - Spent: true, + return btcws.NewRecvTxNtfn("lalala the hex tx", nil) + }, + result: &btcws.RecvTxNtfn{ + HexTx: "lalala the hex tx", + Block: nil, + }, + }, + { + name: "recvtx with block", + f: func() btcjson.Cmd { + block := &btcws.BlockDetails{ + Height: 153469, + Hash: "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", + Index: 1, + Time: 1386944019, } - return cmd + return btcws.NewRecvTxNtfn("lalala the hex tx", block) }, - result: &btcws.ProcessedTxNtfn{ - Receiver: "miFxiuApPo3KBqtMnPUjasZmHoVnoH3Eoc", - Amount: 200000000, - TxID: "851f5c0652e785c5ed80aafaf2d918e5cbe5c307dbba3680808ada1d01f36886", - TxOutIndex: 1, - PkScript: "76a9141e127eda7cd71b9724085f588840a3e9d697ae9888ac", - BlockHash: "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", - BlockHeight: 153469, - BlockIndex: 1, - BlockTime: 1386944019, - Spent: true, + result: &btcws.RecvTxNtfn{ + HexTx: "lalala the hex tx", + Block: &btcws.BlockDetails{ + Height: 153469, + Hash: "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", + Index: 1, + Time: 1386944019, + }, }, }, { - name: "txmined", + name: "redeemingtx", f: func() btcjson.Cmd { - return btcws.NewTxMinedNtfn( - "062f2b5f7d28c787e0f3aee382132241cd590efb7b83bd2c7f506de5aa4ef275", - "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", - 153469, - 1386944019, - 0) + return btcws.NewRedeemingTxNtfn("lalala the hex tx", nil) }, - result: &btcws.TxMinedNtfn{ - TxID: "062f2b5f7d28c787e0f3aee382132241cd590efb7b83bd2c7f506de5aa4ef275", - BlockHash: "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", - BlockHeight: 153469, - BlockTime: 1386944019, - Index: 0, + result: &btcws.RedeemingTxNtfn{ + HexTx: "lalala the hex tx", + Block: nil, }, }, { - name: "txspent", + name: "redeemingtx with block", f: func() btcjson.Cmd { - return btcws.NewTxSpentNtfn( - "b22eb08001da1d57aec3131ccb46ea61820c46c71695a802585fbd56e93625a9", - 1, - "0100000001a92536e956bd5f5802a89516c7460c8261ea46cb1c13c3ae571dda0180b02eb2010000006a4730440220240e3ad18a0393e9894120eb87ded8545222df4890cf98a55b5d36042c966898022031bbd795453fcd01b2a9eb30a8cbbe0ea043b7e4e85ff17ba2b44c243d14aafc0121028031f92546ff86436802fdfe07dc9e1876b70c8b8fa29ca9e9c90664d7022717ffffffff0200ab9041000000001976a91401f65945e042b5e09ecf0a9d9115adecb4caee8588ac703fbc0d040000001976a914c31a4d3e819598e55ff80601e4b2c662454385ca88ac00000000") + block := &btcws.BlockDetails{ + Height: 153469, + Hash: "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", + Index: 1, + Time: 1386944019, + } + return btcws.NewRedeemingTxNtfn("lalala the hex tx", block) }, - result: &btcws.TxSpentNtfn{ - SpentTxId: "b22eb08001da1d57aec3131ccb46ea61820c46c71695a802585fbd56e93625a9", - SpentTxOutIndex: 1, - SpendingTx: "0100000001a92536e956bd5f5802a89516c7460c8261ea46cb1c13c3ae571dda0180b02eb2010000006a4730440220240e3ad18a0393e9894120eb87ded8545222df4890cf98a55b5d36042c966898022031bbd795453fcd01b2a9eb30a8cbbe0ea043b7e4e85ff17ba2b44c243d14aafc0121028031f92546ff86436802fdfe07dc9e1876b70c8b8fa29ca9e9c90664d7022717ffffffff0200ab9041000000001976a91401f65945e042b5e09ecf0a9d9115adecb4caee8588ac703fbc0d040000001976a914c31a4d3e819598e55ff80601e4b2c662454385ca88ac00000000", + result: &btcws.RedeemingTxNtfn{ + HexTx: "lalala the hex tx", + Block: &btcws.BlockDetails{ + Height: 153469, + Hash: "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70", + Index: 1, + Time: 1386944019, + }, }, }, { diff --git a/test_coverage.txt b/test_coverage.txt index 03911e44..e8d23d5b 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,80 +1,91 @@ -github.com/conformal/btcws/cmds.go init 100.00% (11/11) -github.com/conformal/btcws/notifications.go init 100.00% (9/9) -github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go init 100.00% (16/16) +github.com/conformal/btcws/notifications.go init 100.00% (10/10) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.MarshalJSON 100.00% (6/6) +github.com/conformal/btcws/notifications.go RecvTxNtfn.MarshalJSON 100.00% (6/6) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/notifications.go ProcessedTxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxSpentNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxMinedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go AllTxNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxSpentNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxSpentNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go ProcessedTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxMinedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxMinedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go ProcessedTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxMinedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxSpentNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAllVerboseTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go AllTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go AllTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAllTxNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go generateAllVerboseTxNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 87.50% (7/8) +github.com/conformal/btcws/cmds.go NewNotifyAllNewTXsCmd 85.71% (6/7) +github.com/conformal/btcws/cmds.go parseNotifyAllNewTXsCmd 85.71% (6/7) github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) @@ -86,59 +97,91 @@ github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 76.47% (1 github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 75.00% (9/12) github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 75.00% (6/8) github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go ProcessedTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxSpentNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxMinedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go parseProcessedTxNtfn 70.73% (29/41) -github.com/conformal/btcws/notifications.go parseTxMinedNtfn 70.00% (14/20) -github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 69.23% (9/13) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) +github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go AllTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go parseRedeemingTxNtfn 69.23% (18/26) +github.com/conformal/btcws/notifications.go parseRecvTxNtfn 69.23% (18/26) github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (10/15) -github.com/conformal/btcws/notifications.go parseTxSpentNtfn 66.67% (10/15) -github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) +github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.UnmarshalJSON 66.67% (8/12) +github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 66.67% (4/6) github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) +github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) -github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseAllTxNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 45.45% (5/11) -github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewExportWatchingWalletCmd 0.00% (0/15) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go AuthenticateCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go parseAuthenticateCmd 0.00% (0/9) +github.com/conformal/btcws/cmds.go parseRecoverAddressesCmd 0.00% (0/9) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.MarshalJSON 0.00% (0/6) +github.com/conformal/btcws/cmds.go parseNotifyBlocksCmd 0.00% (0/3) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.MarshalJSON 0.00% (0/2) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.MarshalJSON 0.00% (0/2) +github.com/conformal/btcws/cmds.go AuthenticateCmd.MarshalJSON 0.00% (0/2) github.com/conformal/btcws/cmds.go GetBestBlockCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewAuthenticateCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/notifications.go TxSpentNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewNotifyBlocksCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewRecoverAddressesCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go parseExportWatchingWalletCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go AuthenticateCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go AuthenticateCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go AuthenticateCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.SetId 0.00% (0/1) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go RecvTxNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go TxMinedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go ProcessedTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws ---------------------------------------- 75.85% (493/650) +github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go AllTxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws ---------------------------------------- 66.67% (534/801) From dd3813d811d85223ee67f304f874c99f5bd3b03c Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 21 Mar 2014 14:08:54 -0500 Subject: [PATCH 47/76] Bootstrap unspent outpoints for rescan requests. --- cmds.go | 66 ++++++++++++++++++++++++++++++++++++++--------- cmds_test.go | 48 +++++++++++++++++++++++++++------- test_coverage.txt | 6 ++--- 3 files changed, 96 insertions(+), 24 deletions(-) diff --git a/cmds.go b/cmds.go index fdc09160..05b97d16 100644 --- a/cmds.go +++ b/cmds.go @@ -611,7 +611,8 @@ func (cmd *RecoverAddressesCmd) UnmarshalJSON(b []byte) error { type RescanCmd struct { id interface{} BeginBlock int32 - Addresses map[string]struct{} + Addresses []string + OutPoints []*btcwire.OutPoint EndBlock int64 // TODO: switch this and btcdb.AllShas to int32 } @@ -621,8 +622,8 @@ var _ btcjson.Cmd = &RescanCmd{} // NewRescanCmd creates a new RescanCmd, parsing the optional // arguments optArgs which may either be empty or a single upper // block height. -func NewRescanCmd(id interface{}, begin int32, addresses map[string]struct{}, - optArgs ...int64) (*RescanCmd, error) { +func NewRescanCmd(id interface{}, begin int32, addresses []string, + outpoints []*btcwire.OutPoint, optArgs ...int64) (*RescanCmd, error) { // Optional parameters set to their defaults. end := btcdb.AllShas @@ -638,6 +639,7 @@ func NewRescanCmd(id interface{}, begin int32, addresses map[string]struct{}, id: id, BeginBlock: begin, Addresses: addresses, + OutPoints: outpoints, EndBlock: end, }, nil } @@ -646,7 +648,7 @@ func NewRescanCmd(id interface{}, begin int32, addresses map[string]struct{}, // the btcjson.Cmd interface. This is used when registering the custom // command with the btcjson parser. func parseRescanCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { - if len(r.Params) < 2 { + if len(r.Params) < 3 { return nil, btcjson.ErrWrongNumberOfParams } @@ -654,16 +656,47 @@ func parseRescanCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { if !ok { return nil, errors.New("first parameter must be a number") } - iaddrs, ok := r.Params[1].(map[string]interface{}) + + iaddrs, ok := r.Params[1].([]interface{}) if !ok { - return nil, errors.New("second parameter must be a JSON object") + return nil, errors.New("second parameter must be a JSON array") } - addresses := make(map[string]struct{}, len(iaddrs)) - for addr := range iaddrs { - addresses[addr] = struct{}{} + addresses := make([]string, 0, len(iaddrs)) + for _, addr := range iaddrs { + addrStr, ok := addr.(string) + if !ok { + return nil, errors.New("address is not a string") + } + addresses = append(addresses, addrStr) } - params := make([]int64, len(r.Params[2:])) - for i, val := range r.Params[2:] { + + ops, ok := r.Params[2].([]interface{}) + if !ok { + return nil, errors.New("third parameter must be a JSON array") + } + outpoints := make([]*btcwire.OutPoint, 0, len(ops)) + for i := range ops { + op, ok := ops[i].(map[string]interface{}) + if !ok { + return nil, errors.New("outpoint is not a JSON object") + } + txHashHexStr, ok := op["hash"].(string) + if !ok { + return nil, errors.New("outpoint hash is not a string") + } + txHash, err := btcwire.NewShaHashFromStr(txHashHexStr) + if err != nil { + return nil, errors.New("outpoint hash is not a valid hex string") + } + index, ok := op["index"].(float64) + if !ok { + return nil, errors.New("outpoint index is not a number") + } + outpoints = append(outpoints, btcwire.NewOutPoint(txHash, uint32(index))) + } + + params := make([]int64, len(r.Params[3:])) + for i, val := range r.Params[3:] { fval, ok := val.(float64) if !ok { return nil, errors.New("optional parameters must " + @@ -672,7 +705,7 @@ func parseRescanCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { params[i] = int64(fval) } - return NewRescanCmd(r.Id, int32(begin), addresses, params...) + return NewRescanCmd(r.Id, int32(begin), addresses, outpoints, params...) } // Id satisifies the Cmd interface by returning the ID of the command. @@ -692,6 +725,14 @@ func (cmd *RescanCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *RescanCmd) MarshalJSON() ([]byte, error) { + ops := make([]interface{}, 0, len(cmd.OutPoints)) + for _, op := range cmd.OutPoints { + ops = append(ops, map[string]interface{}{ + "hash": op.Hash.String(), + "index": float64(op.Index), + }) + } + // Fill a RawCmd and marshal. raw := btcjson.RawCmd{ Jsonrpc: "1.0", @@ -700,6 +741,7 @@ func (cmd *RescanCmd) MarshalJSON() ([]byte, error) { Params: []interface{}{ cmd.BeginBlock, cmd.Addresses, + ops, }, } diff --git a/cmds_test.go b/cmds_test.go index 0b048dd7..7c249bc0 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -211,19 +211,34 @@ var cmdtests = []struct { { name: "rescan no optargs", f: func() (btcjson.Cmd, error) { - addrs := map[string]struct{}{ - "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": {}, + addrs := []string{"17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH"} + ops := []*btcwire.OutPoint{ + &btcwire.OutPoint{ + Hash: [...]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31}, + Index: 1, + }, } return NewRescanCmd( float64(1), 270000, - addrs) + addrs, + ops) }, result: &RescanCmd{ id: float64(1), BeginBlock: 270000, - Addresses: map[string]struct{}{ - "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": {}, + Addresses: []string{"17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH"}, + OutPoints: []*btcwire.OutPoint{ + &btcwire.OutPoint{ + Hash: [...]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31}, + Index: 1, + }, }, EndBlock: btcdb.AllShas, }, @@ -231,20 +246,35 @@ var cmdtests = []struct { { name: "rescan one optarg", f: func() (btcjson.Cmd, error) { - addrs := map[string]struct{}{ - "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": {}, + addrs := []string{"17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH"} + ops := []*btcwire.OutPoint{ + &btcwire.OutPoint{ + Hash: [...]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31}, + Index: 1, + }, } return NewRescanCmd( float64(1), 270000, addrs, + ops, 280000) }, result: &RescanCmd{ id: float64(1), BeginBlock: 270000, - Addresses: map[string]struct{}{ - "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": {}, + Addresses: []string{"17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH"}, + OutPoints: []*btcwire.OutPoint{ + &btcwire.OutPoint{ + Hash: [...]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31}, + Index: 1, + }, }, EndBlock: 280000, }, diff --git a/test_coverage.txt b/test_coverage.txt index e8d23d5b..a9254930 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,11 +1,11 @@ github.com/conformal/btcws/cmds.go init 100.00% (16/16) github.com/conformal/btcws/notifications.go init 100.00% (10/10) +github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (7/7) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.MarshalJSON 100.00% (6/6) github.com/conformal/btcws/notifications.go RecvTxNtfn.MarshalJSON 100.00% (6/6) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) @@ -92,11 +92,11 @@ github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go parseRescanCmd 77.78% (14/18) github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 76.47% (13/17) github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 75.00% (9/12) github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 75.00% (6/8) github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) +github.com/conformal/btcws/cmds.go parseRescanCmd 74.36% (29/39) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) @@ -183,5 +183,5 @@ github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.SetId 0.00% (0 github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go AllTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws ---------------------------------------- 66.67% (534/801) +github.com/conformal/btcws ---------------------------------------- 66.91% (552/825) From 97439fa822af74dd58fefa25fe41b6469af01e8a Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 24 Mar 2014 13:04:55 -0500 Subject: [PATCH 48/76] Implement rescanprogress notification. --- notifications.go | 90 ++++++++++++++++++++ notifications_test.go | 14 +++- test_coverage.txt | 191 ++++++++++++++++++++++-------------------- 3 files changed, 202 insertions(+), 93 deletions(-) diff --git a/notifications.go b/notifications.go index e399b30b..99ddf508 100644 --- a/notifications.go +++ b/notifications.go @@ -53,6 +53,10 @@ const ( // notification. RedeemingTxNtfnMethod = "redeemingtx" + // RescanProgressNtfnMethod is the method of the btcd rescanprogress + // notification. + RescanProgressNtfnMethod = "rescanprogress" + // WalletLockStateNtfnMethod is the method of the btcwallet // walletlockstate notification. WalletLockStateNtfnMethod = "walletlockstate" @@ -70,6 +74,9 @@ func init() { parseBtcdConnectedNtfn, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(RecvTxNtfnMethod, parseRecvTxNtfn, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(RescanProgressNtfnMethod, + parseRescanProgressNtfn, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(RedeemingTxNtfnMethod, parseRedeemingTxNtfn, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(TxNtfnMethod, parseTxNtfn, @@ -741,6 +748,89 @@ func (n *RedeemingTxNtfn) UnmarshalJSON(b []byte) error { return nil } +// RescanProgressNtfn is type handling custom marshaling and +// unmarshaling of rescanprogress JSON websocket notifications. +type RescanProgressNtfn struct { + LastProcessed int32 +} + +// Enforce that RescanProgressNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &RescanProgressNtfn{} + +// NewRescanProgressNtfn creates a new RescanProgressNtfn. +func NewRescanProgressNtfn(last int32) *RescanProgressNtfn { + return &RescanProgressNtfn{last} +} + +// parseRescanProgressNtfn parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the notification +// with the btcjson parser. +func parseRescanProgressNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 1 { + return nil, btcjson.ErrWrongNumberOfParams + } + + last, ok := r.Params[0].(float64) + if !ok { + return nil, errors.New("first parameter must be a number") + } + + return NewRescanProgressNtfn(int32(last)), nil +} + +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *RescanProgressNtfn) Id() interface{} { + return nil +} + +// SetId is implemented to satisify the btcjson.Cmd interface. The +// notification ID is not modified. +func (n *RescanProgressNtfn) SetId(id interface{}) {} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *RescanProgressNtfn) Method() string { + return RescanProgressNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd +// interface. +func (n *RescanProgressNtfn) MarshalJSON() ([]byte, error) { + ntfn := btcjson.Message{ + Jsonrpc: "1.0", + Method: n.Method(), + Params: []interface{}{n.LastProcessed}, + } + return json.Marshal(ntfn) +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the btcjson.Cmd interface. +func (n *RescanProgressNtfn) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newNtfn, err := parseRescanProgressNtfn(&r) + if err != nil { + return err + } + + concreteNtfn, ok := newNtfn.(*RescanProgressNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn + return nil +} + // TxNtfn is a type handling custom marshaling and // unmarshaling of newtx JSON websocket notifications. type TxNtfn struct { diff --git a/notifications_test.go b/notifications_test.go index b099bd0a..6236091c 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -123,6 +123,15 @@ var ntfntests = []struct { }, }, }, + { + name: "rescanprogress", + f: func() btcjson.Cmd { + return btcws.NewRescanProgressNtfn(12345) + }, + result: &btcws.RescanProgressNtfn{ + LastProcessed: 12345, + }, + }, { name: "newtx", f: func() btcjson.Cmd { @@ -226,7 +235,10 @@ func TestNtfns(t *testing.T) { // Read marshaled notification back into n. Should still // match result. - n.UnmarshalJSON(mn) + if err := n.UnmarshalJSON(mn); err != nil { + t.Errorf("%s: unmarshal failed: %v", test.name, err) + continue + } if !reflect.DeepEqual(test.result, n) { t.Errorf("%s: unmarshal not as expected. "+ "got %v wanted %v", test.name, spew.Sdump(n), diff --git a/test_coverage.txt b/test_coverage.txt index a9254930..060d9df0 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,62 +1,57 @@ github.com/conformal/btcws/cmds.go init 100.00% (16/16) -github.com/conformal/btcws/notifications.go init 100.00% (10/10) +github.com/conformal/btcws/notifications.go init 100.00% (11/11) github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (7/7) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.MarshalJSON 100.00% (6/6) github.com/conformal/btcws/notifications.go RecvTxNtfn.MarshalJSON 100.00% (6/6) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) +github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go AllTxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.MarshalJSON 100.00% (2/2) github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go NewAllVerboseTxNtfn 100.00% (1/1) github.com/conformal/btcws/notifications.go AllTxNtfn.Method 100.00% (1/1) @@ -71,54 +66,64 @@ github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go generateAllVerboseTxNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRescanProgressNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go generateAllVerboseTxNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 87.50% (7/8) github.com/conformal/btcws/cmds.go NewNotifyAllNewTXsCmd 85.71% (6/7) github.com/conformal/btcws/cmds.go parseNotifyAllNewTXsCmd 85.71% (6/7) -github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 76.47% (13/17) github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 75.00% (9/12) github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 75.00% (6/8) github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) github.com/conformal/btcws/cmds.go parseRescanCmd 74.36% (29/39) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) -github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go AllTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go parseRedeemingTxNtfn 69.23% (18/26) github.com/conformal/btcws/notifications.go parseRecvTxNtfn 69.23% (18/26) github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (10/15) @@ -127,61 +132,63 @@ github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 66.67% (4/ github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) +github.com/conformal/btcws/notifications.go parseAllTxNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseAllTxNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) +github.com/conformal/btcws/notifications.go parseRescanProgressNtfn 62.50% (5/8) github.com/conformal/btcws/cmds.go NewExportWatchingWalletCmd 0.00% (0/15) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go NotifyBlocksCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go AuthenticateCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go parseAuthenticateCmd 0.00% (0/9) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go parseRecoverAddressesCmd 0.00% (0/9) +github.com/conformal/btcws/cmds.go parseAuthenticateCmd 0.00% (0/9) github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.MarshalJSON 0.00% (0/6) github.com/conformal/btcws/cmds.go parseNotifyBlocksCmd 0.00% (0/3) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.MarshalJSON 0.00% (0/2) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.MarshalJSON 0.00% (0/2) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.MarshalJSON 0.00% (0/2) github.com/conformal/btcws/cmds.go AuthenticateCmd.MarshalJSON 0.00% (0/2) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewAuthenticateCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewNotifyBlocksCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Method 0.00% (0/1) github.com/conformal/btcws/cmds.go NotifyBlocksCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewNotifyBlocksCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Method 0.00% (0/1) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go NewRecoverAddressesCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Id 0.00% (0/1) github.com/conformal/btcws/cmds.go parseExportWatchingWalletCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go AuthenticateCmd.Method 0.00% (0/1) github.com/conformal/btcws/cmds.go AuthenticateCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go AuthenticateCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewAuthenticateCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go AllTxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go RecvTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go AllTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws ---------------------------------------- 66.91% (552/825) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws ---------------------------------------- 67.18% (571/850) From b77de52d3d029e27659b18befad5d08e303189b6 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Thu, 10 Apr 2014 16:42:28 -0500 Subject: [PATCH 49/76] Move GetBestBlockResult struct from btcwallet. --- cmds.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmds.go b/cmds.go index 05b97d16..9b2d30cf 100644 --- a/cmds.go +++ b/cmds.go @@ -438,6 +438,12 @@ func (cmd *GetUnconfirmedBalanceCmd) UnmarshalJSON(b []byte) error { return nil } +// GetBestBlockResult holds the result of a getbestblock response. +type GetBestBlockResult struct { + Hash string `json:"hash"` + Height int32 `json:"height"` +} + // GetBestBlockCmd is a type handling custom marshaling and // unmarshaling of getbestblock JSON websocket extension // commands. From bfcd7f6790d7b0b2caf926d07cf1c6a760a22dc2 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 10 Apr 2014 14:33:21 -0500 Subject: [PATCH 50/76] Update for latest btcjson.RawCmd changes. This commit modifies all of the commands and notifications to work properly with the latest btcjson.RawCmd Params field changes. This new approach is superior to the old method of using a []interface{} because it means that each parameter is now unmarshalled into the expected concrete type directly instead of whatever it happens to be in the JSON. Since it is now preferred to use full blown structs for individual parameters, the RescanCmd type has been changed to use a new OutPoint that can be used directly for marshalling and unmarshalling instead of a *btcwire.OutPoint. Also, all of the MarshalJSON functions now make use of the new btcjson.NewRawCmd function rather than repeating the same common field over and over and all of the MarshalJSON, UnmarshalJSON, and parseX functions have been made more consistent. ok @jrick --- cmds.go | 555 +++++++++++++++++++++------------------------- cmds_test.go | 63 +++--- notifications.go | 433 ++++++++++++++++-------------------- test_coverage.txt | 250 ++++++++++----------- 4 files changed, 606 insertions(+), 695 deletions(-) diff --git a/cmds.go b/cmds.go index 9b2d30cf..7204231d 100644 --- a/cmds.go +++ b/cmds.go @@ -84,14 +84,16 @@ func parseAuthenticateCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - username, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter username must be a string") + var username string + if err := json.Unmarshal(r.Params[0], &username); err != nil { + return nil, errors.New("first parameter 'username' must be " + + "a string: " + err.Error()) } - passphrase, ok := r.Params[1].(string) - if !ok { - return nil, errors.New("second parameter passphrase must be a string") + var passphrase string + if err := json.Unmarshal(r.Params[1], &passphrase); err != nil { + return nil, errors.New("second parameter 'passphrase' must " + + "be a string: " + err.Error()) } return NewAuthenticateCmd(r.Id, username, passphrase), nil @@ -114,15 +116,14 @@ func (cmd *AuthenticateCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *AuthenticateCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: cmd.Method(), - Id: cmd.id, - Params: []interface{}{ - cmd.Username, - cmd.Passphrase, - }, + params := []interface{}{ + cmd.Username, + cmd.Passphrase, + } + + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err } return json.Marshal(raw) } @@ -192,11 +193,9 @@ func (cmd *GetCurrentNetCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *GetCurrentNetCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "getcurrentnet", - Id: cmd.id, + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), []interface{}{}) + if err != nil { + return nil, err } return json.Marshal(raw) } @@ -272,7 +271,30 @@ func NewExportWatchingWalletCmd(id interface{}, optArgs ...interface{}) (*Export // satisifying the btcjson.Cmd interface. This is used when registering // the custom command with the btcjson parser. func parseExportWatchingWalletCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { - return NewExportWatchingWalletCmd(r.Id, r.Params...) + if len(r.Params) > 2 { + return nil, btcjson.ErrTooManyOptArgs + } + + optArgs := make([]interface{}, 0, 2) + if len(r.Params) > 0 { + var account string + if err := json.Unmarshal(r.Params[0], &account); err != nil { + return nil, errors.New("first optional parameter " + + " 'account' must be a string: " + err.Error()) + } + optArgs = append(optArgs, account) + } + + if len(r.Params) > 1 { + var download bool + if err := json.Unmarshal(r.Params[1], &download); err != nil { + return nil, errors.New("second optional parameter " + + " 'download' must be a bool: " + err.Error()) + } + optArgs = append(optArgs, download) + } + + return NewExportWatchingWalletCmd(r.Id, optArgs...) } // Id satisifies the Cmd interface by returning the ID of the command. @@ -292,20 +314,18 @@ func (cmd *ExportWatchingWalletCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *ExportWatchingWalletCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "exportwatchingwallet", - Id: cmd.id, - } - + params := make([]interface{}, 0, 2) if cmd.Account != "" || cmd.Download { - raw.Params = append(raw.Params, cmd.Account) + params = append(params, cmd.Account) } if cmd.Download { - raw.Params = append(raw.Params, cmd.Download) + params = append(params, cmd.Download) } + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } return json.Marshal(raw) } @@ -372,17 +392,17 @@ func parseGetUnconfirmedBalanceCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - if len(r.Params) == 0 { - // No optional args. - return NewGetUnconfirmedBalanceCmd(r.Id) + optArgs := make([]string, 0, 1) + if len(r.Params) > 0 { + var account string + if err := json.Unmarshal(r.Params[0], &account); err != nil { + return nil, errors.New("first optional parameter " + + " 'account' must be a string: " + err.Error()) + } + optArgs = append(optArgs, account) } - // One optional parameter for account. - account, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter account must be a string") - } - return NewGetUnconfirmedBalanceCmd(r.Id, account) + return NewGetUnconfirmedBalanceCmd(r.Id, optArgs...) } // Id satisifies the Cmd interface by returning the ID of the command. @@ -402,17 +422,15 @@ func (cmd *GetUnconfirmedBalanceCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *GetUnconfirmedBalanceCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "getunconfirmedbalance", - Id: cmd.id, - } - + params := make([]interface{}, 0, 1) if cmd.Account != "" { - raw.Params = append(raw.Params, cmd.Account) + params = append(params, cmd.Account) } + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } return json.Marshal(raw) } @@ -487,11 +505,9 @@ func (cmd *GetBestBlockCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *GetBestBlockCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "getbestblock", - Id: cmd.id, + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), []interface{}{}) + if err != nil { + return nil, err } return json.Marshal(raw) } @@ -547,15 +563,19 @@ func parseRecoverAddressesCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - account, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter account must be a string") + var account string + if err := json.Unmarshal(r.Params[0], &account); err != nil { + return nil, errors.New("first parameter 'account' must be a " + + "string: " + err.Error()) } - n, ok := r.Params[1].(float64) - if !ok { - return nil, errors.New("second parameter n must be a number") + + var n int + if err := json.Unmarshal(r.Params[1], &n); err != nil { + return nil, errors.New("second parameter 'n' must be an " + + "integer: " + err.Error()) } - return NewRecoverAddressesCmd(r.Id, account, int(n)), nil + + return NewRecoverAddressesCmd(r.Id, account, n), nil } // Id satisifies the Cmd interface by returning the ID of the command. @@ -575,17 +595,15 @@ func (cmd *RecoverAddressesCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *RecoverAddressesCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "recoveraddresses", - Id: cmd.id, - Params: []interface{}{ - cmd.Account, - cmd.N, - }, + params := []interface{}{ + cmd.Account, + cmd.N, } + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } return json.Marshal(raw) } @@ -611,6 +629,22 @@ func (cmd *RecoverAddressesCmd) UnmarshalJSON(b []byte) error { return nil } +// OutPoint describes a transaction outpoint that will be marshalled to and +// from JSON. +type OutPoint struct { + Hash string `json:"hash"` + Index uint32 `json:"index"` +} + +// NewOutPointFromWire creates a new OutPoint from the OutPoint structure +// of the btcwire package. +func NewOutPointFromWire(op *btcwire.OutPoint) *OutPoint { + return &OutPoint{ + Hash: op.Hash.String(), + Index: op.Index, + } +} + // RescanCmd is a type handling custom marshaling and // unmarshaling of rescan JSON websocket extension // commands. @@ -618,7 +652,7 @@ type RescanCmd struct { id interface{} BeginBlock int32 Addresses []string - OutPoints []*btcwire.OutPoint + OutPoints []OutPoint EndBlock int64 // TODO: switch this and btcdb.AllShas to int32 } @@ -629,7 +663,7 @@ var _ btcjson.Cmd = &RescanCmd{} // arguments optArgs which may either be empty or a single upper // block height. func NewRescanCmd(id interface{}, begin int32, addresses []string, - outpoints []*btcwire.OutPoint, optArgs ...int64) (*RescanCmd, error) { + outpoints []OutPoint, optArgs ...int64) (*RescanCmd, error) { // Optional parameters set to their defaults. end := btcdb.AllShas @@ -658,60 +692,36 @@ func parseRescanCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - begin, ok := r.Params[0].(float64) - if !ok { - return nil, errors.New("first parameter must be a number") + var begin int32 + if err := json.Unmarshal(r.Params[0], &begin); err != nil { + return nil, errors.New("first parameter 'begin' must be a " + + "32-bit integer: " + err.Error()) } - iaddrs, ok := r.Params[1].([]interface{}) - if !ok { - return nil, errors.New("second parameter must be a JSON array") - } - addresses := make([]string, 0, len(iaddrs)) - for _, addr := range iaddrs { - addrStr, ok := addr.(string) - if !ok { - return nil, errors.New("address is not a string") - } - addresses = append(addresses, addrStr) + var addresses []string + if err := json.Unmarshal(r.Params[1], &addresses); err != nil { + return nil, errors.New("second parameter 'addresses' must be " + + "an array of strings: " + err.Error()) } - ops, ok := r.Params[2].([]interface{}) - if !ok { - return nil, errors.New("third parameter must be a JSON array") - } - outpoints := make([]*btcwire.OutPoint, 0, len(ops)) - for i := range ops { - op, ok := ops[i].(map[string]interface{}) - if !ok { - return nil, errors.New("outpoint is not a JSON object") - } - txHashHexStr, ok := op["hash"].(string) - if !ok { - return nil, errors.New("outpoint hash is not a string") - } - txHash, err := btcwire.NewShaHashFromStr(txHashHexStr) - if err != nil { - return nil, errors.New("outpoint hash is not a valid hex string") - } - index, ok := op["index"].(float64) - if !ok { - return nil, errors.New("outpoint index is not a number") - } - outpoints = append(outpoints, btcwire.NewOutPoint(txHash, uint32(index))) + var outpoints []OutPoint + if err := json.Unmarshal(r.Params[2], &outpoints); err != nil { + return nil, errors.New("third parameter 'outpoints' must be " + + "an array of transaction outpoint JSON objects: " + + err.Error()) } - params := make([]int64, len(r.Params[3:])) - for i, val := range r.Params[3:] { - fval, ok := val.(float64) - if !ok { - return nil, errors.New("optional parameters must " + - "be be numbers") + optArgs := make([]int64, 0, 1) + if len(r.Params) > 3 { + var endblock int64 + if err := json.Unmarshal(r.Params[3], &endblock); err != nil { + return nil, errors.New("fourth optional parameter " + + " 'endblock' must be an integer: " + err.Error()) } - params[i] = int64(fval) + optArgs = append(optArgs, endblock) } - return NewRescanCmd(r.Id, int32(begin), addresses, outpoints, params...) + return NewRescanCmd(r.Id, begin, addresses, outpoints, optArgs...) } // Id satisifies the Cmd interface by returning the ID of the command. @@ -731,30 +741,18 @@ func (cmd *RescanCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *RescanCmd) MarshalJSON() ([]byte, error) { - ops := make([]interface{}, 0, len(cmd.OutPoints)) - for _, op := range cmd.OutPoints { - ops = append(ops, map[string]interface{}{ - "hash": op.Hash.String(), - "index": float64(op.Index), - }) - } - - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "rescan", - Id: cmd.id, - Params: []interface{}{ - cmd.BeginBlock, - cmd.Addresses, - ops, - }, - } - + params := make([]interface{}, 3, 4) + params[0] = cmd.BeginBlock + params[1] = cmd.Addresses + params[2] = cmd.OutPoints if cmd.EndBlock != btcdb.AllShas { - raw.Params = append(raw.Params, cmd.EndBlock) + params = append(params, cmd.EndBlock) } + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } return json.Marshal(raw) } @@ -824,13 +822,10 @@ func (cmd *NotifyBlocksCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *NotifyBlocksCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "notifyblocks", - Id: cmd.id, + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), []interface{}{}) + if err != nil { + return nil, err } - return json.Marshal(raw) } @@ -883,18 +878,10 @@ func parseNotifyNewTXsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - iaddrs, ok := r.Params[0].([]interface{}) - if !ok { - return nil, errors.New("first parameter must be a JSON array") - } - addresses := make([]string, len(iaddrs)) - for i := range iaddrs { - addr, ok := iaddrs[i].(string) - if !ok { - return nil, errors.New("first parameter must be an " + - "array of strings") - } - addresses[i] = addr + var addresses []string + if err := json.Unmarshal(r.Params[0], &addresses); err != nil { + return nil, errors.New("first parameter 'addresses' must be " + + "an array of strings: " + err.Error()) } return NewNotifyNewTXsCmd(r.Id, addresses), nil @@ -917,16 +904,14 @@ func (cmd *NotifyNewTXsCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *NotifyNewTXsCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "notifynewtxs", - Id: cmd.id, - Params: []interface{}{ - cmd.Addresses, - }, + params := []interface{}{ + cmd.Addresses, } + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } return json.Marshal(raw) } @@ -986,17 +971,21 @@ func NewNotifyAllNewTXsCmd(id interface{}, optArgs ...bool) (*NotifyAllNewTXsCmd // satisifying the btcjson.Cmd interface. This is used when registering // the custom command with the btcjson parser. func parseNotifyAllNewTXsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { - verbose := false - numParams := len(r.Params) - - if numParams > 0 { - if numParams > 1 { - return nil, btcjson.ErrWrongNumberOfParams - } - verbose = r.Params[0].(bool) + if len(r.Params) > 1 { + return nil, btcjson.ErrWrongNumberOfParams } - return NewNotifyAllNewTXsCmd(r.Id, verbose) + optArgs := make([]bool, 0, 1) + if len(r.Params) > 0 { + var verbose bool + if err := json.Unmarshal(r.Params[0], &verbose); err != nil { + return nil, errors.New("first optional parameter " + + "'verbose' must be a bool: " + err.Error()) + } + optArgs = append(optArgs, verbose) + } + + return NewNotifyAllNewTXsCmd(r.Id, optArgs...) } // Id satisifies the Cmd interface by returning the ID of the command. @@ -1016,16 +1005,14 @@ func (cmd *NotifyAllNewTXsCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *NotifyAllNewTXsCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "notifyallnewtxs", - Id: cmd.id, - Params: []interface{}{ - cmd.Verbose, - }, + params := []interface{}{ + cmd.Verbose, } + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } return json.Marshal(raw) } @@ -1056,14 +1043,14 @@ func (cmd *NotifyAllNewTXsCmd) UnmarshalJSON(b []byte) error { // commands. type NotifySpentCmd struct { id interface{} - *btcwire.OutPoint + *OutPoint } // Enforce that NotifySpentCmd satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &NotifySpentCmd{} // NewNotifySpentCmd creates a new NotifySpentCmd. -func NewNotifySpentCmd(id interface{}, op *btcwire.OutPoint) *NotifySpentCmd { +func NewNotifySpentCmd(id interface{}, op *OutPoint) *NotifySpentCmd { return &NotifySpentCmd{ id: id, OutPoint: op, @@ -1074,29 +1061,17 @@ func NewNotifySpentCmd(id interface{}, op *btcwire.OutPoint) *NotifySpentCmd { // satisifying the btcjson.Cmd interface. This is used when registering // the custom command with the btcjson parser. func parseNotifySpentCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { - if len(r.Params) != 2 { + if len(r.Params) != 1 { return nil, btcjson.ErrWrongNumberOfParams } - hashStr, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter must be a string") - } - hash, err := btcwire.NewShaHashFromStr(hashStr) - if err != nil { - return nil, errors.New("first parameter is not a valid " + - "hash string") - } - idx, ok := r.Params[1].(float64) - if !ok { - return nil, errors.New("second parameter is not a number") - } - if idx < 0 { - return nil, errors.New("second parameter cannot be negative") + var outpoint OutPoint + if err := json.Unmarshal(r.Params[0], &outpoint); err != nil { + return nil, errors.New("first parameter 'outpoint' must be a " + + "an outpoint JSON object: " + err.Error()) } - cmd := NewNotifySpentCmd(r.Id, btcwire.NewOutPoint(hash, uint32(idx))) - return cmd, nil + return NewNotifySpentCmd(r.Id, &outpoint), nil } // Id satisifies the Cmd interface by returning the ID of the command. @@ -1116,17 +1091,14 @@ func (cmd *NotifySpentCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *NotifySpentCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "notifyspent", - Id: cmd.id, - Params: []interface{}{ - cmd.OutPoint.Hash.String(), - cmd.OutPoint.Index, - }, + params := []interface{}{ + cmd.OutPoint, } + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } return json.Marshal(raw) } @@ -1181,9 +1153,10 @@ func parseCreateEncryptedWalletCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - passphrase, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter is not a string") + var passphrase string + if err := json.Unmarshal(r.Params[0], &passphrase); err != nil { + return nil, errors.New("first parameter 'passphrase' must be " + + "a string: " + err.Error()) } return NewCreateEncryptedWalletCmd(r.Id, passphrase), nil @@ -1206,14 +1179,14 @@ func (cmd *CreateEncryptedWalletCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *CreateEncryptedWalletCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "createencryptedwallet", - Id: cmd.id, - Params: []interface{}{cmd.Passphrase}, + params := []interface{}{ + cmd.Passphrase, } + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } return json.Marshal(raw) } @@ -1283,10 +1256,12 @@ func parseWalletIsLockedCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return NewWalletIsLockedCmd(r.Id) } - account, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("account must be a string") + var account string + if err := json.Unmarshal(r.Params[0], &account); err != nil { + return nil, errors.New("first parameter 'account' must be a " + + "string: " + err.Error()) } + return NewWalletIsLockedCmd(r.Id, account) } @@ -1307,18 +1282,15 @@ func (cmd *WalletIsLockedCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *WalletIsLockedCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "walletislocked", - Id: cmd.id, - Params: []interface{}{}, - } - + params := make([]interface{}, 0, 1) if cmd.Account != "" { - raw.Params = append(raw.Params, cmd.Account) + params = append(params, cmd.Account) } + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } return json.Marshal(raw) } @@ -1386,30 +1358,23 @@ func parseListAddressTransactionsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrInvalidParams } - iaddrs, ok := r.Params[0].([]interface{}) - if !ok { - return nil, errors.New("first parameter must be a JSON array") + var addresses []string + if err := json.Unmarshal(r.Params[0], &addresses); err != nil { + return nil, errors.New("first parameter 'addresses' must be " + + "an array of strings: " + err.Error()) } - addresses := make([]string, len(iaddrs)) - for i := range iaddrs { - addr, ok := iaddrs[i].(string) - if !ok { - return nil, errors.New("first parameter must be an " + - "array of strings") + + optArgs := make([]string, 0, 1) + if len(r.Params) > 1 { + var account string + if err := json.Unmarshal(r.Params[1], &account); err != nil { + return nil, errors.New("second optional parameter " + + "'account' must be a string: " + err.Error()) } - addresses[i] = addr + optArgs = append(optArgs, account) } - if len(r.Params) == 1 { - // No optional parameters. - return NewListAddressTransactionsCmd(r.Id, addresses) - } - - account, ok := r.Params[1].(string) - if !ok { - return nil, errors.New("second parameter must be a string") - } - return NewListAddressTransactionsCmd(r.Id, addresses, account) + return NewListAddressTransactionsCmd(r.Id, addresses, optArgs...) } // Id satisifies the Cmd interface by returning the ID of the command. @@ -1429,20 +1394,16 @@ func (cmd *ListAddressTransactionsCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *ListAddressTransactionsCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: cmd.Method(), - Id: cmd.id, - Params: []interface{}{ - cmd.Addresses, - }, - } - + params := make([]interface{}, 1, 2) + params[0] = cmd.Addresses if cmd.Account != "" { - raw.Params = append(raw.Params, cmd.Account) + params = append(params, cmd.Account) } + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } return json.Marshal(raw) } @@ -1508,15 +1469,17 @@ func parseListAllTransactionsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrInvalidParams } - if len(r.Params) == 0 { - return NewListAllTransactionsCmd(r.Id) + optArgs := make([]string, 0, 1) + if len(r.Params) > 0 { + var account string + if err := json.Unmarshal(r.Params[0], &account); err != nil { + return nil, errors.New("first optional parameter " + + "'account' must be a string: " + err.Error()) + } + optArgs = append(optArgs, account) } - account, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("account must be a string") - } - return NewListAllTransactionsCmd(r.Id, account) + return NewListAllTransactionsCmd(r.Id, optArgs...) } // Id satisifies the Cmd interface by returning the ID of the command. @@ -1536,18 +1499,15 @@ func (cmd *ListAllTransactionsCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *ListAllTransactionsCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "listalltransactions", - Id: cmd.id, - Params: []interface{}{}, - } - + params := make([]interface{}, 0, 1) if cmd.Account != "" { - raw.Params = append(raw.Params, cmd.Account) + params = append(params, cmd.Account) } + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } return json.Marshal(raw) } @@ -1596,22 +1556,23 @@ func parseGetAddressBalanceCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrInvalidParams } - address, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("address must be a string") + var address string + if err := json.Unmarshal(r.Params[0], &address); err != nil { + return nil, errors.New("first parameter 'address' must be a " + + " string: " + err.Error()) } - if len(r.Params) == 1 { - // No optional params. - return NewGetAddressBalanceCmd(r.Id, address) + optArgs := make([]int, 0, 1) + if len(r.Params) > 1 { + var minConf int + if err := json.Unmarshal(r.Params[1], &minConf); err != nil { + return nil, errors.New("second optional parameter " + + " 'minconf' must be an integer: " + err.Error()) + } + optArgs = append(optArgs, minConf) } - // 1 optional param for minconf. - fminConf, ok := r.Params[1].(float64) - if !ok { - return nil, errors.New("first optional parameter minconf must be a number") - } - return NewGetAddressBalanceCmd(r.Id, address, int(fminConf)) + return NewGetAddressBalanceCmd(r.Id, address, optArgs...) } // NewGetAddressBalanceCmd creates a new GetAddressBalanceCmd. @@ -1653,20 +1614,16 @@ func (cmd *GetAddressBalanceCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *GetAddressBalanceCmd) MarshalJSON() ([]byte, error) { - // Fill a RawCmd and marshal. - raw := btcjson.RawCmd{ - Jsonrpc: "1.0", - Method: "getaddressbalance", - Id: cmd.id, - Params: []interface{}{ - cmd.Address, - }, - } - + params := make([]interface{}, 1, 2) + params[0] = cmd.Address if cmd.Minconf != 1 { - raw.Params = append(raw.Params, cmd.Minconf) + params = append(params, cmd.Minconf) } + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } return json.Marshal(raw) } diff --git a/cmds_test.go b/cmds_test.go index 7c249bc0..3325d4c1 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -8,7 +8,6 @@ package btcws import ( "github.com/conformal/btcdb" "github.com/conformal/btcjson" - "github.com/conformal/btcwire" "github.com/davecgh/go-spew/spew" "reflect" "testing" @@ -188,22 +187,20 @@ var cmdtests = []struct { { name: "notifyspent", f: func() (btcjson.Cmd, error) { - op := &btcwire.OutPoint{ - Hash: [...]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31}, + op := &OutPoint{ + Hash: "000102030405060708091011121314" + + "1516171819202122232425262728" + + "293031", Index: 1, } return NewNotifySpentCmd(float64(1), op), nil }, result: &NotifySpentCmd{ id: float64(1), - OutPoint: &btcwire.OutPoint{ - Hash: [...]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31}, + OutPoint: &OutPoint{ + Hash: "000102030405060708091011121314" + + "1516171819202122232425262728" + + "293031", Index: 1, }, }, @@ -212,12 +209,11 @@ var cmdtests = []struct { name: "rescan no optargs", f: func() (btcjson.Cmd, error) { addrs := []string{"17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH"} - ops := []*btcwire.OutPoint{ - &btcwire.OutPoint{ - Hash: [...]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31}, + ops := []OutPoint{ + { + Hash: "000102030405060708091011121314" + + "1516171819202122232425262728" + + "293031", Index: 1, }, } @@ -231,12 +227,11 @@ var cmdtests = []struct { id: float64(1), BeginBlock: 270000, Addresses: []string{"17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH"}, - OutPoints: []*btcwire.OutPoint{ - &btcwire.OutPoint{ - Hash: [...]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31}, + OutPoints: []OutPoint{ + { + Hash: "000102030405060708091011121314" + + "1516171819202122232425262728" + + "293031", Index: 1, }, }, @@ -247,12 +242,11 @@ var cmdtests = []struct { name: "rescan one optarg", f: func() (btcjson.Cmd, error) { addrs := []string{"17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH"} - ops := []*btcwire.OutPoint{ - &btcwire.OutPoint{ - Hash: [...]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31}, + ops := []OutPoint{ + { + Hash: "000102030405060708091011121314" + + "1516171819202122232425262728" + + "293031", Index: 1, }, } @@ -267,12 +261,11 @@ var cmdtests = []struct { id: float64(1), BeginBlock: 270000, Addresses: []string{"17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH"}, - OutPoints: []*btcwire.OutPoint{ - &btcwire.OutPoint{ - Hash: [...]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31}, + OutPoints: []OutPoint{ + { + Hash: "000102030405060708091011121314" + + "1516171819202122232425262728" + + "293031", Index: 1, }, }, diff --git a/notifications.go b/notifications.go index 99ddf508..8af72cef 100644 --- a/notifications.go +++ b/notifications.go @@ -91,10 +91,10 @@ func init() { // BlockDetails describes details of a tx in a block. type BlockDetails struct { - Height int32 - Hash string - Index int - Time int64 + Height int32 `json:"height"` + Hash string `json:"hash"` + Index int `json:"index"` + Time int64 `json:"time"` } // AccountBalanceNtfn is a type handling custom marshaling and @@ -131,17 +131,19 @@ func parseAccountBalanceNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - account, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter account must be a string") + var account string + if err := json.Unmarshal(r.Params[0], &account); err != nil { + return nil, errors.New("first parameter 'account' must be a string: " + err.Error()) } - balance, ok := r.Params[1].(float64) - if !ok { - return nil, errors.New("second parameter balance must be a number") + + var balance float64 + if err := json.Unmarshal(r.Params[1], &balance); err != nil { + return nil, errors.New("second parameter 'balance' must be a number: " + err.Error()) } - confirmed, ok := r.Params[2].(bool) - if !ok { - return nil, errors.New("third parameter confirmed must be a boolean") + + var confirmed bool + if err := json.Unmarshal(r.Params[2], &confirmed); err != nil { + return nil, errors.New("third parameter 'confirmed' must be a bool: " + err.Error()) } return NewAccountBalanceNtfn(account, balance, confirmed), nil @@ -166,16 +168,18 @@ func (n *AccountBalanceNtfn) Method() string { // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *AccountBalanceNtfn) MarshalJSON() ([]byte, error) { - ntfn := btcjson.Message{ - Jsonrpc: "1.0", - Method: n.Method(), - Params: []interface{}{ - n.Account, - n.Balance, - n.Confirmed, - }, + params := []interface{}{ + n.Account, + n.Balance, + n.Confirmed, } - return json.Marshal(ntfn) + + // No ID for notifications. + raw, err := btcjson.NewRawCmd(nil, n.Method(), params) + if err != nil { + return nil, err + } + return json.Marshal(raw) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of @@ -230,16 +234,17 @@ func parseBlockConnectedNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - hash, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter hash must be a string") - } - fheight, ok := r.Params[1].(float64) - if !ok { - return nil, errors.New("second parameter height must be a number") + var hash string + if err := json.Unmarshal(r.Params[0], &hash); err != nil { + return nil, errors.New("first parameter 'hash' must be a string: " + err.Error()) } - return NewBlockConnectedNtfn(hash, int32(fheight)), nil + var height int32 + if err := json.Unmarshal(r.Params[1], &height); err != nil { + return nil, errors.New("second parameter 'height' must be a 32-bit integer: " + err.Error()) + } + + return NewBlockConnectedNtfn(hash, height), nil } // Id satisifies the btcjson.Cmd interface by returning nil for a @@ -261,15 +266,17 @@ func (n *BlockConnectedNtfn) Method() string { // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *BlockConnectedNtfn) MarshalJSON() ([]byte, error) { - ntfn := btcjson.Message{ - Jsonrpc: "1.0", - Method: n.Method(), - Params: []interface{}{ - n.Hash, - n.Height, - }, + params := []interface{}{ + n.Hash, + n.Height, } - return json.Marshal(ntfn) + + // No ID for notifications. + raw, err := btcjson.NewRawCmd(nil, n.Method(), params) + if err != nil { + return nil, err + } + return json.Marshal(raw) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of @@ -324,16 +331,17 @@ func parseBlockDisconnectedNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - hash, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter hash must be a string") - } - fheight, ok := r.Params[1].(float64) - if !ok { - return nil, errors.New("second parameter height must be a number") + var hash string + if err := json.Unmarshal(r.Params[0], &hash); err != nil { + return nil, errors.New("first parameter 'hash' must be a string: " + err.Error()) } - return NewBlockDisconnectedNtfn(hash, int32(fheight)), nil + var height int32 + if err := json.Unmarshal(r.Params[1], &height); err != nil { + return nil, errors.New("second parameter 'height' must be a 32-bit integer: " + err.Error()) + } + + return NewBlockDisconnectedNtfn(hash, height), nil } // Id satisifies the btcjson.Cmd interface by returning nil for a @@ -355,15 +363,17 @@ func (n *BlockDisconnectedNtfn) Method() string { // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *BlockDisconnectedNtfn) MarshalJSON() ([]byte, error) { - ntfn := btcjson.Message{ - Jsonrpc: "1.0", - Method: n.Method(), - Params: []interface{}{ - n.Hash, - n.Height, - }, + params := []interface{}{ + n.Hash, + n.Height, } - return json.Marshal(ntfn) + + // No ID for notifications. + raw, err := btcjson.NewRawCmd(nil, n.Method(), params) + if err != nil { + return nil, err + } + return json.Marshal(raw) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of @@ -415,9 +425,9 @@ func parseBtcdConnectedNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - connected, ok := r.Params[0].(bool) - if !ok { - return nil, errors.New("first parameter connected is not a boolean") + var connected bool + if err := json.Unmarshal(r.Params[0], &connected); err != nil { + return nil, errors.New("first parameter 'connected' must be a bool: " + err.Error()) } return NewBtcdConnectedNtfn(connected), nil @@ -442,14 +452,16 @@ func (n *BtcdConnectedNtfn) Method() string { // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *BtcdConnectedNtfn) MarshalJSON() ([]byte, error) { - ntfn := btcjson.Message{ - Jsonrpc: "1.0", - Method: n.Method(), - Params: []interface{}{ - n.Connected, - }, + params := []interface{}{ + n.Connected, } - return json.Marshal(ntfn) + + // No ID for notifications. + raw, err := btcjson.NewRawCmd(nil, n.Method(), params) + if err != nil { + return nil, err + } + return json.Marshal(raw) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of @@ -505,48 +517,22 @@ func parseRecvTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - hextx, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter hextx must be a string") + var hextx string + if err := json.Unmarshal(r.Params[0], &hextx); err != nil { + return nil, errors.New("first parameter 'hextx' must be a " + + "string: " + err.Error()) } - ntfn := &RecvTxNtfn{HexTx: hextx} - + var blockDetails *BlockDetails if len(r.Params) > 1 { - details, ok := r.Params[1].(map[string]interface{}) - if !ok { - return nil, errors.New("second parameter must be a JSON object") - } - - height, ok := details["height"].(float64) - if !ok { - return nil, errors.New("unspecified block height") - } - - hash, ok := details["hash"].(string) - if !ok { - return nil, errors.New("unspecified block hash") - } - - index, ok := details["index"].(float64) - if !ok { - return nil, errors.New("unspecified block index") - } - - time, ok := details["time"].(float64) - if !ok { - return nil, errors.New("unspecified block time") - } - - ntfn.Block = &BlockDetails{ - Height: int32(height), - Hash: hash, - Index: int(index), - Time: int64(time), + if err := json.Unmarshal(r.Params[1], &blockDetails); err != nil { + return nil, errors.New("second optional parameter " + + "'details' must be a JSON oject of block " + + "details: " + err.Error()) } } - return ntfn, nil + return NewRecvTxNtfn(hextx, blockDetails), nil } // Id satisifies the btcjson.Cmd interface by returning nil for a @@ -568,25 +554,18 @@ func (n *RecvTxNtfn) Method() string { // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *RecvTxNtfn) MarshalJSON() ([]byte, error) { - params := []interface{}{n.HexTx} - + params := make([]interface{}, 1, 2) + params[0] = n.HexTx if n.Block != nil { - details := map[string]interface{}{ - "height": float64(n.Block.Height), - "hash": n.Block.Hash, - "index": float64(n.Block.Index), - "time": float64(n.Block.Time), - } - params = append(params, details) + params = append(params, n.Block) } - ntfn := btcjson.Message{ - Jsonrpc: "1.0", - Method: n.Method(), - Params: params, + // No ID for notifications. + raw, err := btcjson.NewRawCmd(nil, n.Method(), params) + if err != nil { + return nil, err } - - return json.Marshal(ntfn) + return json.Marshal(raw) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of @@ -642,48 +621,22 @@ func parseRedeemingTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - hextx, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter hextx must be a string") + var hextx string + if err := json.Unmarshal(r.Params[0], &hextx); err != nil { + return nil, errors.New("first parameter 'hextx' must be a " + + "string: " + err.Error()) } - ntfn := &RedeemingTxNtfn{HexTx: hextx} - + var blockDetails *BlockDetails if len(r.Params) > 1 { - details, ok := r.Params[1].(map[string]interface{}) - if !ok { - return nil, errors.New("second parameter must be a JSON object") - } - - height, ok := details["height"].(float64) - if !ok { - return nil, errors.New("unspecified block height") - } - - hash, ok := details["hash"].(string) - if !ok { - return nil, errors.New("unspecified block hash") - } - - index, ok := details["index"].(float64) - if !ok { - return nil, errors.New("unspecified block index") - } - - time, ok := details["time"].(float64) - if !ok { - return nil, errors.New("unspecified block time") - } - - ntfn.Block = &BlockDetails{ - Height: int32(height), - Hash: hash, - Index: int(index), - Time: int64(time), + if err := json.Unmarshal(r.Params[1], &blockDetails); err != nil { + return nil, errors.New("second optional parameter " + + "'details' must be a JSON oject of block " + + "details: " + err.Error()) } } - return ntfn, nil + return NewRedeemingTxNtfn(hextx, blockDetails), nil } // Id satisifies the btcjson.Cmd interface by returning nil for a @@ -705,25 +658,18 @@ func (n *RedeemingTxNtfn) Method() string { // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *RedeemingTxNtfn) MarshalJSON() ([]byte, error) { - params := []interface{}{n.HexTx} - + params := make([]interface{}, 1, 2) + params[0] = n.HexTx if n.Block != nil { - details := map[string]interface{}{ - "height": float64(n.Block.Height), - "hash": n.Block.Hash, - "index": float64(n.Block.Index), - "time": float64(n.Block.Time), - } - params = append(params, details) + params = append(params, n.Block) } - ntfn := btcjson.Message{ - Jsonrpc: "1.0", - Method: n.Method(), - Params: params, + // No ID for notifications. + raw, err := btcjson.NewRawCmd(nil, n.Method(), params) + if err != nil { + return nil, err } - - return json.Marshal(ntfn) + return json.Marshal(raw) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of @@ -774,12 +720,13 @@ func parseRescanProgressNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - last, ok := r.Params[0].(float64) - if !ok { - return nil, errors.New("first parameter must be a number") + var last int32 + if err := json.Unmarshal(r.Params[0], &last); err != nil { + return nil, errors.New("first parameter 'last' must be a " + + "32-bit integer: " + err.Error()) } - return NewRescanProgressNtfn(int32(last)), nil + return NewRescanProgressNtfn(last), nil } // Id satisifies the btcjson.Cmd interface by returning nil for a @@ -801,12 +748,16 @@ func (n *RescanProgressNtfn) Method() string { // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *RescanProgressNtfn) MarshalJSON() ([]byte, error) { - ntfn := btcjson.Message{ - Jsonrpc: "1.0", - Method: n.Method(), - Params: []interface{}{n.LastProcessed}, + params := []interface{}{ + n.LastProcessed, } - return json.Marshal(ntfn) + + // No ID for notifications. + raw, err := btcjson.NewRawCmd(nil, n.Method(), params) + if err != nil { + return nil, err + } + return json.Marshal(raw) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of @@ -861,13 +812,17 @@ func parseTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - account, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter account must be a string") + var account string + if err := json.Unmarshal(r.Params[0], &account); err != nil { + return nil, errors.New("first parameter 'account' must be a " + + "string: " + err.Error()) } - details, ok := r.Params[1].(map[string]interface{}) - if !ok { - return nil, errors.New("second parameter details must be a JSON object") + + // TODO(davec): Object + var details map[string]interface{} + if err := json.Unmarshal(r.Params[1], &details); err != nil { + return nil, errors.New("second parameter 'details' must be a " + + "JSON object of transaction details: " + err.Error()) } return NewTxNtfn(account, details), nil @@ -892,15 +847,17 @@ func (n *TxNtfn) Method() string { // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *TxNtfn) MarshalJSON() ([]byte, error) { - ntfn := btcjson.Message{ - Jsonrpc: "1.0", - Method: n.Method(), - Params: []interface{}{ - n.Account, - n.Details, - }, + params := []interface{}{ + n.Account, + n.Details, } - return json.Marshal(ntfn) + + // No ID for notifications. + raw, err := btcjson.NewRawCmd(nil, n.Method(), params) + if err != nil { + return nil, err + } + return json.Marshal(raw) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of @@ -958,13 +915,16 @@ func parseWalletLockStateNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - account, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter account must be a string") + var account string + if err := json.Unmarshal(r.Params[0], &account); err != nil { + return nil, errors.New("first parameter 'account' must be a " + + "string: " + err.Error()) } - locked, ok := r.Params[1].(bool) - if !ok { - return nil, errors.New("second parameter locked must be a boolean") + + var locked bool + if err := json.Unmarshal(r.Params[1], &locked); err != nil { + return nil, errors.New("second parameter 'locked' must be a " + + "bool: " + err.Error()) } return NewWalletLockStateNtfn(account, locked), nil @@ -989,15 +949,17 @@ func (n *WalletLockStateNtfn) Method() string { // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *WalletLockStateNtfn) MarshalJSON() ([]byte, error) { - ntfn := btcjson.Message{ - Jsonrpc: "1.0", - Method: n.Method(), - Params: []interface{}{ - n.Account, - n.Locked, - }, + params := []interface{}{ + n.Account, + n.Locked, } - return json.Marshal(ntfn) + + // No ID for notifications. + raw, err := btcjson.NewRawCmd(nil, n.Method(), params) + if err != nil { + return nil, err + } + return json.Marshal(raw) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of @@ -1052,16 +1014,19 @@ func parseAllTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - txid, ok := r.Params[0].(string) - if !ok { - return nil, errors.New("first parameter txid must be a string") - } - famount, ok := r.Params[1].(float64) - if !ok { - return nil, errors.New("second parameter amount must be a number") + var txid string + if err := json.Unmarshal(r.Params[0], &txid); err != nil { + return nil, errors.New("first parameter 'txid' must be a " + + "string: " + err.Error()) } - return NewAllTxNtfn(txid, int64(famount)), nil + var amount int64 + if err := json.Unmarshal(r.Params[1], &amount); err != nil { + return nil, errors.New("second parameter 'amount' must be an " + + "integer: " + err.Error()) + } + + return NewAllTxNtfn(txid, amount), nil } // Id satisifies the btcjson.Cmd interface by returning nil for a @@ -1083,15 +1048,17 @@ func (n *AllTxNtfn) Method() string { // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *AllTxNtfn) MarshalJSON() ([]byte, error) { - ntfn := btcjson.Message{ - Jsonrpc: "1.0", - Method: n.Method(), - Params: []interface{}{ - n.TxID, - n.Amount, - }, + params := []interface{}{ + n.TxID, + n.Amount, } - return json.Marshal(ntfn) + + // No ID for notifications. + raw, err := btcjson.NewRawCmd(nil, n.Method(), params) + if err != nil { + return nil, err + } + return json.Marshal(raw) } // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of @@ -1151,32 +1118,26 @@ func (n *AllVerboseTxNtfn) Method() string { // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. func (n *AllVerboseTxNtfn) MarshalJSON() ([]byte, error) { - ntfn := btcjson.Message{ - Jsonrpc: "1.0", - Method: n.Method(), - Params: []interface{}{ - n.RawTx, - }, + params := []interface{}{ + n.RawTx, } - return json.Marshal(ntfn) + + // No ID for notifications. + raw, err := btcjson.NewRawCmd(nil, n.Method(), params) + if err != nil { + return nil, err + } + return json.Marshal(raw) } func generateAllVerboseTxNtfn() btcjson.Cmd { return new(AllVerboseTxNtfn) } -type rawParamsCmd struct { - Jsonrpc string `json:"jsonrpc"` - Id interface{} `json:"id"` - Method string `json:"method"` - Params []*json.RawMessage `json:"params"` -} - // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of // the btcjson.Cmd interface. func (n *AllVerboseTxNtfn) UnmarshalJSON(b []byte) error { - // Unmarshal into a custom rawParamsCmd - var r rawParamsCmd + var r btcjson.RawCmd if err := json.Unmarshal(b, &r); err != nil { return err } @@ -1190,7 +1151,7 @@ func (n *AllVerboseTxNtfn) UnmarshalJSON(b []byte) error { } var rawTx *btcjson.TxRawResult - if err := json.Unmarshal(*r.Params[0], &rawTx); err != nil { + if err := json.Unmarshal(r.Params[0], &rawTx); err != nil { return err } diff --git a/test_coverage.txt b/test_coverage.txt index 060d9df0..a27ce0d2 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,56 +1,6 @@ github.com/conformal/btcws/cmds.go init 100.00% (16/16) github.com/conformal/btcws/notifications.go init 100.00% (11/11) -github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 100.00% (7/7) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.MarshalJSON 100.00% (6/6) -github.com/conformal/btcws/notifications.go RecvTxNtfn.MarshalJSON 100.00% (6/6) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 100.00% (4/4) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go AllTxNtfn.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.MarshalJSON 100.00% (2/2) -github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go NewAllVerboseTxNtfn 100.00% (1/1) @@ -60,135 +10,185 @@ github.com/conformal/btcws/notifications.go AllTxNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go NewAllTxNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go generateAllVerboseTxNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go RescanProgressNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go RescanProgressNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) github.com/conformal/btcws/notifications.go NewRescanProgressNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go generateAllVerboseTxNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 87.50% (7/8) +github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 90.00% (9/10) +github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 88.89% (8/9) +github.com/conformal/btcws/notifications.go RecvTxNtfn.MarshalJSON 87.50% (7/8) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 87.50% (7/8) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.MarshalJSON 87.50% (7/8) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 87.50% (7/8) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 85.71% (6/7) github.com/conformal/btcws/cmds.go NewNotifyAllNewTXsCmd 85.71% (6/7) -github.com/conformal/btcws/cmds.go parseNotifyAllNewTXsCmd 85.71% (6/7) -github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 85.71% (6/7) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 85.71% (6/7) github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 76.47% (13/17) -github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 75.00% (9/12) -github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 75.00% (6/8) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go AllTxNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 77.78% (7/9) +github.com/conformal/btcws/cmds.go parseNotifyAllNewTXsCmd 77.78% (7/9) +github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 75.00% (9/12) +github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 75.00% (9/12) github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) -github.com/conformal/btcws/cmds.go parseRescanCmd 74.36% (29/39) -github.com/conformal/btcws/notifications.go AllTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 72.73% (8/11) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 75.00% (3/4) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 75.00% (3/4) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go RescanProgressNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go parseRedeemingTxNtfn 69.23% (18/26) -github.com/conformal/btcws/notifications.go parseRecvTxNtfn 69.23% (18/26) -github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (10/15) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go AllTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go parseRescanCmd 72.22% (13/18) +github.com/conformal/btcws/notifications.go parseRecvTxNtfn 66.67% (8/12) github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.UnmarshalJSON 66.67% (8/12) +github.com/conformal/btcws/notifications.go parseRedeemingTxNtfn 66.67% (8/12) +github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 66.67% (4/6) +github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (4/6) github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 66.67% (4/6) github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) -github.com/conformal/btcws/notifications.go parseAllTxNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) +github.com/conformal/btcws/notifications.go parseAllTxNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseRescanProgressNtfn 62.50% (5/8) +github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) github.com/conformal/btcws/cmds.go NewExportWatchingWalletCmd 0.00% (0/15) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go parseExportWatchingWalletCmd 0.00% (0/14) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go AuthenticateCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.MarshalJSON 0.00% (0/9) github.com/conformal/btcws/cmds.go parseRecoverAddressesCmd 0.00% (0/9) github.com/conformal/btcws/cmds.go parseAuthenticateCmd 0.00% (0/9) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.MarshalJSON 0.00% (0/6) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.MarshalJSON 0.00% (0/5) +github.com/conformal/btcws/cmds.go AuthenticateCmd.MarshalJSON 0.00% (0/5) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.MarshalJSON 0.00% (0/4) github.com/conformal/btcws/cmds.go parseNotifyBlocksCmd 0.00% (0/3) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.MarshalJSON 0.00% (0/2) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.MarshalJSON 0.00% (0/2) -github.com/conformal/btcws/cmds.go AuthenticateCmd.MarshalJSON 0.00% (0/2) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go NewNotifyBlocksCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewRecoverAddressesCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewAuthenticateCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewRecoverAddressesCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go parseExportWatchingWalletCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go AuthenticateCmd.Method 0.00% (0/1) github.com/conformal/btcws/cmds.go AuthenticateCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go AuthenticateCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewAuthenticateCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.SetId 0.00% (0/1) github.com/conformal/btcws/notifications.go AllTxNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go RescanProgressNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go RecvTxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws ---------------------------------------- 67.18% (571/850) +github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go RecvTxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws ---------------------------------------- 64.77% (568/877) From 6f08ca8a8a5c105b3ced32be957f99719b8cf415 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 11 Apr 2014 09:04:53 -0500 Subject: [PATCH 51/76] Correct unmarshal for GetAddressBalanceCmd. The unmarshaller for the GetAddressBalanceCmd was calling the wrong parse function. It wasn't caught by the tests because the error on UnmarshalJSON was being ignored, so this commit also updates the tests to check the error. --- cmds.go | 2 +- cmds_test.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmds.go b/cmds.go index 7204231d..8303d1ec 100644 --- a/cmds.go +++ b/cmds.go @@ -1636,7 +1636,7 @@ func (cmd *GetAddressBalanceCmd) UnmarshalJSON(b []byte) error { return err } - newCmd, err := parseListAllTransactionsCmd(&r) + newCmd, err := parseGetAddressBalanceCmd(&r) if err != nil { return err } diff --git a/cmds_test.go b/cmds_test.go index 3325d4c1..5e0d3f0a 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -346,7 +346,10 @@ func TestCmds(t *testing.T) { // Read marshaled command back into c. Should still // match result. - c.UnmarshalJSON(mc) + if err := c.UnmarshalJSON(mc); err != nil { + t.Errorf("%s: error while unmarshalling: %v", test.name, + err) + } if !reflect.DeepEqual(test.result, c) { t.Errorf("%s: unmarshal not as expected. "+ "got %v wanted %v", test.name, spew.Sdump(c), From fc07555ad3a527ab1ee601fe91a90c50f27871f6 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 11 Apr 2014 09:16:58 -0500 Subject: [PATCH 52/76] Update for latest btcjson API changes. This commit modifies the AllVerboseTxNtfn command to use a parser along with the standard btcjson.RegisterCustomCmd instead of the now removed RegisterCustomCmdGenerator function. This is possible due to the recent changes that defers the unmarshalling of the parameters of a RawCmd to the parser. --- notifications.go | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/notifications.go b/notifications.go index 8af72cef..902e48d7 100644 --- a/notifications.go +++ b/notifications.go @@ -85,8 +85,8 @@ func init() { parseWalletLockStateNtfn, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(AllTxNtfnMethod, parseAllTxNtfn, `TODO(flam) fillmein`) - btcjson.RegisterCustomCmdGenerator(AllVerboseTxNtfnMethod, - generateAllVerboseTxNtfn) + btcjson.RegisterCustomCmd(AllVerboseTxNtfnMethod, + parseAllVerboseTxNtfn, `TODO(flam) fillmein`) } // BlockDetails describes details of a tx in a block. @@ -1099,6 +1099,26 @@ func NewAllVerboseTxNtfn(rawTx *btcjson.TxRawResult) *AllVerboseTxNtfn { } } +// parseAllVerboseTxNtfn parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the notification +// with the btcjson parser. +func parseAllVerboseTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 1 { + return nil, btcjson.ErrWrongNumberOfParams + } + + var rawTx *btcjson.TxRawResult + if err := json.Unmarshal(r.Params[0], &rawTx); err != nil { + return nil, err + } + + return NewAllVerboseTxNtfn(rawTx), nil +} + // Id satisifies the btcjson.Cmd interface by returning nil for a // notification ID. func (n *AllVerboseTxNtfn) Id() interface{} { @@ -1130,10 +1150,6 @@ func (n *AllVerboseTxNtfn) MarshalJSON() ([]byte, error) { return json.Marshal(raw) } -func generateAllVerboseTxNtfn() btcjson.Cmd { - return new(AllVerboseTxNtfn) -} - // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of // the btcjson.Cmd interface. func (n *AllVerboseTxNtfn) UnmarshalJSON(b []byte) error { @@ -1142,19 +1158,15 @@ func (n *AllVerboseTxNtfn) UnmarshalJSON(b []byte) error { return err } - if r.Id != nil { - return ErrNotANtfn - } - - if len(r.Params) != 1 { - return btcjson.ErrWrongNumberOfParams - } - - var rawTx *btcjson.TxRawResult - if err := json.Unmarshal(r.Params[0], &rawTx); err != nil { + newNtfn, err := parseAllVerboseTxNtfn(&r) + if err != nil { return err } - *n = *NewAllVerboseTxNtfn(rawTx) + concreteNtfn, ok := newNtfn.(*AllVerboseTxNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn return nil } From fdc49d6a304d36b9bd2ab09232b013e4b8ff694e Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 8 Apr 2014 21:30:55 -0500 Subject: [PATCH 53/76] Convert NewTxNtfn to use new concrete type. The NewTxNtfn notification was previously using a map[string]interface. This commit modifies it to use the new concrete type btcjson.ListTransactionsResult instead which allows nicer marshalling and unmarshalling. ok @jrick --- notifications.go | 9 ++++----- notifications_test.go | 44 +++++++++++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/notifications.go b/notifications.go index 902e48d7..3a2ad102 100644 --- a/notifications.go +++ b/notifications.go @@ -786,14 +786,14 @@ func (n *RescanProgressNtfn) UnmarshalJSON(b []byte) error { // unmarshaling of newtx JSON websocket notifications. type TxNtfn struct { Account string - Details map[string]interface{} + Details *btcjson.ListTransactionsResult } // Enforce that TxNtfn satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &TxNtfn{} // NewTxNtfn creates a new TxNtfn. -func NewTxNtfn(account string, details map[string]interface{}) *TxNtfn { +func NewTxNtfn(account string, details *btcjson.ListTransactionsResult) *TxNtfn { return &TxNtfn{ Account: account, Details: details, @@ -818,14 +818,13 @@ func parseTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { "string: " + err.Error()) } - // TODO(davec): Object - var details map[string]interface{} + var details btcjson.ListTransactionsResult if err := json.Unmarshal(r.Params[1], &details); err != nil { return nil, errors.New("second parameter 'details' must be a " + "JSON object of transaction details: " + err.Error()) } - return NewTxNtfn(account, details), nil + return NewTxNtfn(account, &details), nil } // Id satisifies the btcjson.Cmd interface by returning nil for a diff --git a/notifications_test.go b/notifications_test.go index 6236091c..0b87dbcb 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -135,21 +135,45 @@ var ntfntests = []struct { { name: "newtx", f: func() btcjson.Cmd { - details := map[string]interface{}{ - "key1": float64(12345), - "key2": true, - "key3": "lalala", - "key4": []interface{}{"abcde", float64(12345)}, + details := &btcjson.ListTransactionsResult{ + Account: "original", + Address: "mnSsMBY8j4AhQzbR6XqawND7NPTECVdtLd", + Category: "receive", + Amount: 100, + Fee: 0.0, + Confirmations: 6707, + Generated: false, + BlockHash: "000000000b20bf5fe8e25b19f9ec340744cda321a17ade12af9838530a75098b", + BlockIndex: 2, + BlockTime: 1397079345, + TxID: "cb082a63b29f446551829d03fa8bac02d3825a18994d5feec564f14101fc5fad", + WalletConflicts: []string{}, + Time: 123123123, + TimeReceived: 1397079169, + Comment: "comment", + OtherAccount: "", } return btcws.NewTxNtfn("abcde", details) }, result: &btcws.TxNtfn{ Account: "abcde", - Details: map[string]interface{}{ - "key1": float64(12345), - "key2": true, - "key3": "lalala", - "key4": []interface{}{"abcde", float64(12345)}, + Details: &btcjson.ListTransactionsResult{ + Account: "original", + Address: "mnSsMBY8j4AhQzbR6XqawND7NPTECVdtLd", + Category: "receive", + Amount: 100, + Fee: 0.0, + Confirmations: 6707, + Generated: false, + BlockHash: "000000000b20bf5fe8e25b19f9ec340744cda321a17ade12af9838530a75098b", + BlockIndex: 2, + BlockTime: 1397079345, + TxID: "cb082a63b29f446551829d03fa8bac02d3825a18994d5feec564f14101fc5fad", + WalletConflicts: []string{}, + Time: 123123123, + TimeReceived: 1397079169, + Comment: "comment", + OtherAccount: "", }, }, }, From 3208b7ae75bda7ca4733cbe0bdefba642218a6ce Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 11 Apr 2014 14:00:22 -0500 Subject: [PATCH 54/76] Update for btcjson RegisterCustomCmd API change. --- cmds.go | 32 ++++++++++++++++---------------- notifications.go | 27 +++++++++++++-------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/cmds.go b/cmds.go index 8303d1ec..d959315a 100644 --- a/cmds.go +++ b/cmds.go @@ -21,38 +21,38 @@ first command sent or you will be disconnected.` ) func init() { - btcjson.RegisterCustomCmd("authenticate", parseAuthenticateCmd, + btcjson.RegisterCustomCmd("authenticate", parseAuthenticateCmd, nil, authenticateHelp) btcjson.RegisterCustomCmd("createencryptedwallet", - parseCreateEncryptedWalletCmd, `TODO(jrick) fillmein`) + parseCreateEncryptedWalletCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("exportwatchingwallet", - parseExportWatchingWalletCmd, `TODO(jrick) fillmein`) + parseExportWatchingWalletCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("getaddressbalance", - parseGetAddressBalanceCmd, `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd, + parseGetAddressBalanceCmd, nil, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd, nil, `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd, + btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("getunconfirmedbalance", - parseGetUnconfirmedBalanceCmd, `TODO(jrick) fillmein`) + parseGetUnconfirmedBalanceCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("listaddresstransactions", - parseListAddressTransactionsCmd, `TODO(jrick) fillmein`) + parseListAddressTransactionsCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("listalltransactions", - parseListAllTransactionsCmd, `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd("notifyblocks", parseNotifyBlocksCmd, + parseListAllTransactionsCmd, nil, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("notifyblocks", parseNotifyBlocksCmd, nil, `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd, + btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("notifyallnewtxs", parseNotifyAllNewTXsCmd, - `TODO(flam) fillmein`) + nil, `TODO(flam) fillmein`) btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd, - `TODO(jrick) fillmein`) + nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("recoveraddresses", parseRecoverAddressesCmd, - `TODO(jrick) fillmein`) + nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("rescan", parseRescanCmd, - `TODO(jrick) fillmein`) + nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("walletislocked", parseWalletIsLockedCmd, - `TODO(jrick) fillmein`) + nil, `TODO(jrick) fillmein`) } // AuthenticateCmd is a type handling custom marshaling and diff --git a/notifications.go b/notifications.go index 3a2ad102..b57d1fa0 100644 --- a/notifications.go +++ b/notifications.go @@ -65,28 +65,27 @@ const ( // Register notifications with btcjson. func init() { btcjson.RegisterCustomCmd(AccountBalanceNtfnMethod, - parseAccountBalanceNtfn, `TODO(jrick) fillmein`) + parseAccountBalanceNtfn, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(BlockConnectedNtfnMethod, - parseBlockConnectedNtfn, `TODO(jrick) fillmein`) + parseBlockConnectedNtfn, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(BlockDisconnectedNtfnMethod, - parseBlockDisconnectedNtfn, `TODO(jrick) fillmein`) + parseBlockDisconnectedNtfn, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(BtcdConnectedNtfnMethod, - parseBtcdConnectedNtfn, `TODO(jrick) fillmein`) + parseBtcdConnectedNtfn, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(RecvTxNtfnMethod, - parseRecvTxNtfn, `TODO(jrick) fillmein`) + parseRecvTxNtfn, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(RescanProgressNtfnMethod, - parseRescanProgressNtfn, `TODO(jrick) fillmein`) - + parseRescanProgressNtfn, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(RedeemingTxNtfnMethod, parseRedeemingTxNtfn, - `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd(TxNtfnMethod, parseTxNtfn, + nil, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(TxNtfnMethod, parseTxNtfn, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(WalletLockStateNtfnMethod, - parseWalletLockStateNtfn, `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd(AllTxNtfnMethod, - parseAllTxNtfn, `TODO(flam) fillmein`) - btcjson.RegisterCustomCmd(AllVerboseTxNtfnMethod, - parseAllVerboseTxNtfn, `TODO(flam) fillmein`) + parseWalletLockStateNtfn, nil, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(AllTxNtfnMethod, parseAllTxNtfn, nil, + `TODO(flam) fillmein`) + btcjson.RegisterCustomCmd(AllVerboseTxNtfnMethod, parseAllVerboseTxNtfn, + nil, `TODO(flam) fillmein`) } // BlockDetails describes details of a tx in a block. From db5bc2c77ce40511cc867027fd41a9663a0600e7 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 11 Apr 2014 14:03:36 -0500 Subject: [PATCH 55/76] Add reply parser for ListAddressTransactionCmd. ok @jrick --- cmds.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmds.go b/cmds.go index d959315a..3ddda914 100644 --- a/cmds.go +++ b/cmds.go @@ -36,7 +36,8 @@ func init() { btcjson.RegisterCustomCmd("getunconfirmedbalance", parseGetUnconfirmedBalanceCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("listaddresstransactions", - parseListAddressTransactionsCmd, nil, `TODO(jrick) fillmein`) + parseListAddressTransactionsCmd, + parseListAddressTransactionsCmdReply, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("listalltransactions", parseListAllTransactionsCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("notifyblocks", parseNotifyBlocksCmd, nil, @@ -1377,6 +1378,17 @@ func parseListAddressTransactionsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return NewListAddressTransactionsCmd(r.Id, addresses, optArgs...) } +// parseListAddressTransactionsCmdReply parses a the reply to a +// ListAddressTransactionsCmd into a concrete type and returns it packed into +// an interface. This is used when registering the custom command with btcjson. +func parseListAddressTransactionsCmdReply(message json.RawMessage) (interface{}, error) { + var res []btcjson.ListTransactionsResult + if err := json.Unmarshal(message, &res); err != nil { + return nil, err + } + return res, nil +} + // Id satisifies the Cmd interface by returning the ID of the command. func (cmd *ListAddressTransactionsCmd) Id() interface{} { return cmd.id From 0b4401ddb6c7d057193b23b46571720065da69c8 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 14 Apr 2014 19:09:15 -0500 Subject: [PATCH 56/76] Rename NotifyNewTXsCmd to NotifyReceivedCmd. This commit renamed the notifynewtxs RPC to notifyreceived since it more accurately reflects its intention which is to register addresses to be notified about when they receive funds. This is work towards conformal/btcd#98. ok @jrick. --- cmds.go | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/cmds.go b/cmds.go index 3ddda914..31698c9e 100644 --- a/cmds.go +++ b/cmds.go @@ -42,7 +42,7 @@ func init() { parseListAllTransactionsCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("notifyblocks", parseNotifyBlocksCmd, nil, `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd("notifynewtxs", parseNotifyNewTXsCmd, nil, + btcjson.RegisterCustomCmd("notifyreceived", parseNotifyReceivedCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("notifyallnewtxs", parseNotifyAllNewTXsCmd, nil, `TODO(flam) fillmein`) @@ -852,29 +852,29 @@ func (cmd *NotifyBlocksCmd) UnmarshalJSON(b []byte) error { return nil } -// NotifyNewTXsCmd is a type handling custom marshaling and -// unmarshaling of notifynewtxs JSON websocket extension +// NotifyReceivedCmd is a type handling custom marshaling and +// unmarshaling of notifyreceived JSON websocket extension // commands. -type NotifyNewTXsCmd struct { +type NotifyReceivedCmd struct { id interface{} Addresses []string } -// Enforce that NotifyNewTXsCmd satisifies the btcjson.Cmd interface. -var _ btcjson.Cmd = &NotifyNewTXsCmd{} +// Enforce that NotifyReceivedCmd satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &NotifyReceivedCmd{} // NewNotifyNewTXsCmd creates a new NotifyNewTXsCmd. -func NewNotifyNewTXsCmd(id interface{}, addresses []string) *NotifyNewTXsCmd { - return &NotifyNewTXsCmd{ +func NewNotifyReceivedCmd(id interface{}, addresses []string) *NotifyReceivedCmd { + return &NotifyReceivedCmd{ id: id, Addresses: addresses, } } -// parseNotifyNewTXsCmd parses a NotifyNewTXsCmd into a concrete type +// parseNotifyReceivedCmd parses a NotifyNewTXsCmd into a concrete type // satisifying the btcjson.Cmd interface. This is used when registering // the custom command with the btcjson parser. -func parseNotifyNewTXsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { +func parseNotifyReceivedCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { if len(r.Params) != 1 { return nil, btcjson.ErrWrongNumberOfParams } @@ -885,26 +885,26 @@ func parseNotifyNewTXsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { "an array of strings: " + err.Error()) } - return NewNotifyNewTXsCmd(r.Id, addresses), nil + return NewNotifyReceivedCmd(r.Id, addresses), nil } // Id satisifies the Cmd interface by returning the ID of the command. -func (cmd *NotifyNewTXsCmd) Id() interface{} { +func (cmd *NotifyReceivedCmd) Id() interface{} { return cmd.id } // SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *NotifyNewTXsCmd) SetId(id interface{}) { +func (cmd *NotifyReceivedCmd) SetId(id interface{}) { cmd.id = id } // Method satisfies the Cmd interface by returning the RPC method. -func (cmd *NotifyNewTXsCmd) Method() string { - return "notifynewtxs" +func (cmd *NotifyReceivedCmd) Method() string { + return "notifyreceived" } // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. -func (cmd *NotifyNewTXsCmd) MarshalJSON() ([]byte, error) { +func (cmd *NotifyReceivedCmd) MarshalJSON() ([]byte, error) { params := []interface{}{ cmd.Addresses, } @@ -918,19 +918,19 @@ func (cmd *NotifyNewTXsCmd) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of // the Cmd interface. -func (cmd *NotifyNewTXsCmd) UnmarshalJSON(b []byte) error { +func (cmd *NotifyReceivedCmd) UnmarshalJSON(b []byte) error { // Unmarshal into a RawCmd. var r btcjson.RawCmd if err := json.Unmarshal(b, &r); err != nil { return err } - newCmd, err := parseNotifyNewTXsCmd(&r) + newCmd, err := parseNotifyReceivedCmd(&r) if err != nil { return err } - concreteCmd, ok := newCmd.(*NotifyNewTXsCmd) + concreteCmd, ok := newCmd.(*NotifyReceivedCmd) if !ok { return btcjson.ErrInternal } From f389d39c43d0cf6d43626265411a730cd507aa4d Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 14 Apr 2014 22:45:37 -0500 Subject: [PATCH 57/76] Update tests for notifynewtxs -> notifyreceived. --- cmds_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmds_test.go b/cmds_test.go index 5e0d3f0a..2aef6e62 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -156,16 +156,16 @@ var cmdtests = []struct { }, }, { - name: "notifynewtxs", + name: "notifyreceived", f: func() (btcjson.Cmd, error) { addrs := []string{ "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", } - return NewNotifyNewTXsCmd( + return NewNotifyReceivedCmd( float64(1), addrs), nil }, - result: &NotifyNewTXsCmd{ + result: &NotifyReceivedCmd{ id: float64(1), Addresses: []string{ "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", From ce482901693110fe7213f6d6c1760c9810c84c7d Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 15 Apr 2014 00:02:44 -0500 Subject: [PATCH 58/76] Rename new transaction register/notifications. This commit renames the notifyallnewtxs RPC to notifynewtransactions to be more consistent with the standard RPC names and to more accurately reflect its intention which is to register for new transactions as they are accepted to the memory pool. In addition, the notifications produced have been renamed to txaccepted and txacceptedverbose depending on whether or not the verbose flag was set when the client registered to receive the notifications via notifynewtransactions. This closes conformal/btcd#98. --- cmds.go | 50 ++++++++++++------------ cmds_test.go | 6 +-- notifications.go | 88 +++++++++++++++++++++---------------------- notifications_test.go | 12 +++--- 4 files changed, 78 insertions(+), 78 deletions(-) diff --git a/cmds.go b/cmds.go index 31698c9e..e4798b32 100644 --- a/cmds.go +++ b/cmds.go @@ -44,8 +44,8 @@ func init() { `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("notifyreceived", parseNotifyReceivedCmd, nil, `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd("notifyallnewtxs", parseNotifyAllNewTXsCmd, - nil, `TODO(flam) fillmein`) + btcjson.RegisterCustomCmd("notifynewtransactions", + parseNotifyNewTransactionsCmd, nil, `TODO(flam) fillmein`) btcjson.RegisterCustomCmd("notifyspent", parseNotifySpentCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("recoveraddresses", parseRecoverAddressesCmd, @@ -863,7 +863,7 @@ type NotifyReceivedCmd struct { // Enforce that NotifyReceivedCmd satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &NotifyReceivedCmd{} -// NewNotifyNewTXsCmd creates a new NotifyNewTXsCmd. +// NewNotifyReceivedCmd creates a new NotifyReceivedCmd. func NewNotifyReceivedCmd(id interface{}, addresses []string) *NotifyReceivedCmd { return &NotifyReceivedCmd{ id: id, @@ -938,20 +938,20 @@ func (cmd *NotifyReceivedCmd) UnmarshalJSON(b []byte) error { return nil } -// NotifyAllNewTXsCmd is a type handling custom marshaling and -// unmarshaling of notifynewtxs JSON websocket extension +// NotifyNewTransactionsCmd is a type handling custom marshaling and +// unmarshaling of notifynewtransactions JSON websocket extension // commands. -type NotifyAllNewTXsCmd struct { +type NotifyNewTransactionsCmd struct { id interface{} Verbose bool } -// Enforce that NotifyAllNewTXsCmd satisifies the btcjson.Cmd interface. -var _ btcjson.Cmd = &NotifyAllNewTXsCmd{} +// Enforce that NotifyNewTransactionsCmd satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &NotifyNewTransactionsCmd{} -// NewNotifyAllNewTXsCmd creates a new NotifyAllNewTXsCmd that optionally -// takes a single verbose parameter that defaults to false. -func NewNotifyAllNewTXsCmd(id interface{}, optArgs ...bool) (*NotifyAllNewTXsCmd, error) { +// NewNotifyNewTransactionsCmd creates a new NotifyNewTransactionsCmd that +// optionally takes a single verbose parameter that defaults to false. +func NewNotifyNewTransactionsCmd(id interface{}, optArgs ...bool) (*NotifyNewTransactionsCmd, error) { verbose := false optArgsLen := len(optArgs) @@ -962,16 +962,16 @@ func NewNotifyAllNewTXsCmd(id interface{}, optArgs ...bool) (*NotifyAllNewTXsCmd verbose = optArgs[0] } - return &NotifyAllNewTXsCmd{ + return &NotifyNewTransactionsCmd{ id: id, Verbose: verbose, }, nil } -// parseNotifyAllNewTXsCmd parses a NotifyAllNewTXsCmd into a concrete type -// satisifying the btcjson.Cmd interface. This is used when registering -// the custom command with the btcjson parser. -func parseNotifyAllNewTXsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { +// parseNotifyNewTransactionsCmd parses a NotifyNewTransactionsCmd into a +// concrete type satisifying the btcjson.Cmd interface. This is used when +// registering the custom command with the btcjson parser. +func parseNotifyNewTransactionsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { if len(r.Params) > 1 { return nil, btcjson.ErrWrongNumberOfParams } @@ -986,26 +986,26 @@ func parseNotifyAllNewTXsCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { optArgs = append(optArgs, verbose) } - return NewNotifyAllNewTXsCmd(r.Id, optArgs...) + return NewNotifyNewTransactionsCmd(r.Id, optArgs...) } // Id satisifies the Cmd interface by returning the ID of the command. -func (cmd *NotifyAllNewTXsCmd) Id() interface{} { +func (cmd *NotifyNewTransactionsCmd) Id() interface{} { return cmd.id } // SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *NotifyAllNewTXsCmd) SetId(id interface{}) { +func (cmd *NotifyNewTransactionsCmd) SetId(id interface{}) { cmd.id = id } // Method satisfies the Cmd interface by returning the RPC method. -func (cmd *NotifyAllNewTXsCmd) Method() string { - return "notifyallnewtxs" +func (cmd *NotifyNewTransactionsCmd) Method() string { + return "notifynewtransactions" } // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. -func (cmd *NotifyAllNewTXsCmd) MarshalJSON() ([]byte, error) { +func (cmd *NotifyNewTransactionsCmd) MarshalJSON() ([]byte, error) { params := []interface{}{ cmd.Verbose, } @@ -1019,19 +1019,19 @@ func (cmd *NotifyAllNewTXsCmd) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of // the Cmd interface. -func (cmd *NotifyAllNewTXsCmd) UnmarshalJSON(b []byte) error { +func (cmd *NotifyNewTransactionsCmd) UnmarshalJSON(b []byte) error { // Unmarshal into a RawCmd. var r btcjson.RawCmd if err := json.Unmarshal(b, &r); err != nil { return err } - newCmd, err := parseNotifyAllNewTXsCmd(&r) + newCmd, err := parseNotifyNewTransactionsCmd(&r) if err != nil { return err } - concreteCmd, ok := newCmd.(*NotifyAllNewTXsCmd) + concreteCmd, ok := newCmd.(*NotifyNewTransactionsCmd) if !ok { return btcjson.ErrInternal } diff --git a/cmds_test.go b/cmds_test.go index 2aef6e62..a7dcaa45 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -173,13 +173,13 @@ var cmdtests = []struct { }, }, { - name: "notifyallnewtxs", + name: "notifynewtransactions", f: func() (btcjson.Cmd, error) { - return NewNotifyAllNewTXsCmd( + return NewNotifyNewTransactionsCmd( float64(1), true) }, - result: &NotifyAllNewTXsCmd{ + result: &NotifyNewTransactionsCmd{ id: float64(1), Verbose: true, }, diff --git a/notifications.go b/notifications.go index b57d1fa0..6f5eb208 100644 --- a/notifications.go +++ b/notifications.go @@ -22,13 +22,13 @@ const ( // accountbalance notification. AccountBalanceNtfnMethod = "accountbalance" - // AllTxNtfnMethod is the method of the btcd alltx + // TxAcceptedNtfnMethod is the method of the btcd txaccepted // notification - AllTxNtfnMethod = "alltx" + TxAcceptedNtfnMethod = "txaccepted" - // AllVerboseTxNtfnMethod is the method of the btcd - // allverbosetx notifications. - AllVerboseTxNtfnMethod = "allverbosetx" + // TxAcceptedVerboseNtfnMethod is the method of the btcd + // txacceptedverbose notifications. + TxAcceptedVerboseNtfnMethod = "txacceptedverbose" // BlockConnectedNtfnMethod is the method of the btcd // blockconnected notification. @@ -82,10 +82,10 @@ func init() { `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(WalletLockStateNtfnMethod, parseWalletLockStateNtfn, nil, `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd(AllTxNtfnMethod, parseAllTxNtfn, nil, + btcjson.RegisterCustomCmd(TxAcceptedNtfnMethod, parseTxAcceptedNtfn, nil, `TODO(flam) fillmein`) - btcjson.RegisterCustomCmd(AllVerboseTxNtfnMethod, parseAllVerboseTxNtfn, - nil, `TODO(flam) fillmein`) + btcjson.RegisterCustomCmd(TxAcceptedVerboseNtfnMethod, + parseTxAcceptedVerboseNtfn, nil, `TODO(flam) fillmein`) } // BlockDetails describes details of a tx in a block. @@ -982,28 +982,28 @@ func (n *WalletLockStateNtfn) UnmarshalJSON(b []byte) error { return nil } -// AllTxNtfn is a type handling custom marshaling and +// TxAcceptedNtfn is a type handling custom marshaling and // unmarshaling of txmined JSON websocket notifications. -type AllTxNtfn struct { +type TxAcceptedNtfn struct { TxID string `json:"txid"` Amount int64 `json:"amount"` } -// Enforce that AllTxNtfn satisifies the btcjson.Cmd interface. -var _ btcjson.Cmd = &AllTxNtfn{} +// Enforce that TxAcceptedNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &TxAcceptedNtfn{} -// NewAllTxNtfn creates a new AllTxNtfn. -func NewAllTxNtfn(txid string, amount int64) *AllTxNtfn { - return &AllTxNtfn{ +// NewTxAcceptedNtfn creates a new TxAcceptedNtfn. +func NewTxAcceptedNtfn(txid string, amount int64) *TxAcceptedNtfn { + return &TxAcceptedNtfn{ TxID: txid, Amount: amount, } } -// parseAllTxNtfn parses a RawCmd into a concrete type satisifying +// parseTxAcceptedNtfn parses a RawCmd into a concrete type satisifying // the btcjson.Cmd interface. This is used when registering the notification // with the btcjson parser. -func parseAllTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { +func parseTxAcceptedNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { if r.Id != nil { return nil, ErrNotANtfn } @@ -1024,28 +1024,28 @@ func parseAllTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { "integer: " + err.Error()) } - return NewAllTxNtfn(txid, amount), nil + return NewTxAcceptedNtfn(txid, amount), nil } // Id satisifies the btcjson.Cmd interface by returning nil for a // notification ID. -func (n *AllTxNtfn) Id() interface{} { +func (n *TxAcceptedNtfn) Id() interface{} { return nil } // SetId is implemented to satisify the btcjson.Cmd interface. The // notification id is not modified. -func (n *AllTxNtfn) SetId(id interface{}) {} +func (n *TxAcceptedNtfn) SetId(id interface{}) {} // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. -func (n *AllTxNtfn) Method() string { - return AllTxNtfnMethod +func (n *TxAcceptedNtfn) Method() string { + return TxAcceptedNtfnMethod } // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. -func (n *AllTxNtfn) MarshalJSON() ([]byte, error) { +func (n *TxAcceptedNtfn) MarshalJSON() ([]byte, error) { params := []interface{}{ n.TxID, n.Amount, @@ -1061,19 +1061,19 @@ func (n *AllTxNtfn) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of // the btcjson.Cmd interface. -func (n *AllTxNtfn) UnmarshalJSON(b []byte) error { +func (n *TxAcceptedNtfn) UnmarshalJSON(b []byte) error { // Unmarshal into a RawCmd. var r btcjson.RawCmd if err := json.Unmarshal(b, &r); err != nil { return err } - newNtfn, err := parseAllTxNtfn(&r) + newNtfn, err := parseTxAcceptedNtfn(&r) if err != nil { return err } - concreteNtfn, ok := newNtfn.(*AllTxNtfn) + concreteNtfn, ok := newNtfn.(*TxAcceptedNtfn) if !ok { return btcjson.ErrInternal } @@ -1081,26 +1081,26 @@ func (n *AllTxNtfn) UnmarshalJSON(b []byte) error { return nil } -// AllVerboseTxNtfn is a type handling custom marshaling and +// TxAcceptedVerboseNtfn is a type handling custom marshaling and // unmarshaling of txmined JSON websocket notifications. -type AllVerboseTxNtfn struct { +type TxAcceptedVerboseNtfn struct { RawTx *btcjson.TxRawResult `json:"rawtx"` } -// Enforce that AllTxNtfn satisifies the btcjson.Cmd interface. -var _ btcjson.Cmd = &AllVerboseTxNtfn{} +// Enforce that TxAcceptedNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &TxAcceptedVerboseNtfn{} -// NewAllVerboseTxNtfn creates a new AllVerboseTxNtfn. -func NewAllVerboseTxNtfn(rawTx *btcjson.TxRawResult) *AllVerboseTxNtfn { - return &AllVerboseTxNtfn{ +// NewTxAcceptedVerboseNtfn creates a new TxAcceptedVerboseNtfn. +func NewTxAcceptedVerboseNtfn(rawTx *btcjson.TxRawResult) *TxAcceptedVerboseNtfn { + return &TxAcceptedVerboseNtfn{ RawTx: rawTx, } } -// parseAllVerboseTxNtfn parses a RawCmd into a concrete type satisifying +// parseTxAcceptedVerboseNtfn parses a RawCmd into a concrete type satisifying // the btcjson.Cmd interface. This is used when registering the notification // with the btcjson parser. -func parseAllVerboseTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { +func parseTxAcceptedVerboseNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { if r.Id != nil { return nil, ErrNotANtfn } @@ -1114,28 +1114,28 @@ func parseAllVerboseTxNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, err } - return NewAllVerboseTxNtfn(rawTx), nil + return NewTxAcceptedVerboseNtfn(rawTx), nil } // Id satisifies the btcjson.Cmd interface by returning nil for a // notification ID. -func (n *AllVerboseTxNtfn) Id() interface{} { +func (n *TxAcceptedVerboseNtfn) Id() interface{} { return nil } // SetId is implemented to satisify the btcjson.Cmd interface. The // notification id is not modified. -func (n *AllVerboseTxNtfn) SetId(id interface{}) {} +func (n *TxAcceptedVerboseNtfn) SetId(id interface{}) {} // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. -func (n *AllVerboseTxNtfn) Method() string { - return AllVerboseTxNtfnMethod +func (n *TxAcceptedVerboseNtfn) Method() string { + return TxAcceptedVerboseNtfnMethod } // MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd // interface. -func (n *AllVerboseTxNtfn) MarshalJSON() ([]byte, error) { +func (n *TxAcceptedVerboseNtfn) MarshalJSON() ([]byte, error) { params := []interface{}{ n.RawTx, } @@ -1150,18 +1150,18 @@ func (n *AllVerboseTxNtfn) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals the JSON encoding of n into n. Part of // the btcjson.Cmd interface. -func (n *AllVerboseTxNtfn) UnmarshalJSON(b []byte) error { +func (n *TxAcceptedVerboseNtfn) UnmarshalJSON(b []byte) error { var r btcjson.RawCmd if err := json.Unmarshal(b, &r); err != nil { return err } - newNtfn, err := parseAllVerboseTxNtfn(&r) + newNtfn, err := parseTxAcceptedVerboseNtfn(&r) if err != nil { return err } - concreteNtfn, ok := newNtfn.(*AllVerboseTxNtfn) + concreteNtfn, ok := newNtfn.(*TxAcceptedVerboseNtfn) if !ok { return btcjson.ErrInternal } diff --git a/notifications_test.go b/notifications_test.go index 0b87dbcb..4dc399fb 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -188,28 +188,28 @@ var ntfntests = []struct { }, }, { - name: "alltx", + name: "txaccepted", f: func() btcjson.Cmd { - return btcws.NewAllTxNtfn( + return btcws.NewTxAcceptedNtfn( "062f2b5f7d28c787e0f3aee382132241cd590efb7b83bd2c7f506de5aa4ef275", 34567765) }, - result: &btcws.AllTxNtfn{ + result: &btcws.TxAcceptedNtfn{ TxID: "062f2b5f7d28c787e0f3aee382132241cd590efb7b83bd2c7f506de5aa4ef275", Amount: 34567765, }, }, { - name: "allverbosetx", + name: "txacceptedverbose", f: func() btcjson.Cmd { - return btcws.NewAllVerboseTxNtfn(&btcjson.TxRawResult{ + return btcws.NewTxAcceptedVerboseNtfn(&btcjson.TxRawResult{ Hex: "01000000010cdf900074a3622499a2f28f44a94476f27a8900a2bdd60e042754b6cab09741000000008a473044022012e11012fad1eb21ba1c82deb8da98778b08e714b72f281293064528343fae0502204294d7520f469f9673087a55395de0ce0e9074dce236db9fe7f30013b5fd00b90141047b6ff7832b4a763666e5481a0bd9eedb656d9f882d215c16fe9563d7b191cd67b2a41601a853a9f9d92773ae6f912ef451a089148e510623759cf55c408efdefffffffff02f4063f00000000001976a914b269e0ceec5d5b5e192cf580ae42341e0f79b0b588aca8c84b02000000001976a91439233c0d43a1411e547c60bad8985bae3530b6af88ac00000000", Txid: "0cfeb968fb5d0f6b9a2a1de37c0607a1964dd3e335f203377cec90e03b20869e", Version: 0x1, LockTime: 0x0, }) }, - result: &btcws.AllVerboseTxNtfn{ + result: &btcws.TxAcceptedVerboseNtfn{ RawTx: &btcjson.TxRawResult{ Hex: "01000000010cdf900074a3622499a2f28f44a94476f27a8900a2bdd60e042754b6cab09741000000008a473044022012e11012fad1eb21ba1c82deb8da98778b08e714b72f281293064528343fae0502204294d7520f469f9673087a55395de0ce0e9074dce236db9fe7f30013b5fd00b90141047b6ff7832b4a763666e5481a0bd9eedb656d9f882d215c16fe9563d7b191cd67b2a41601a853a9f9d92773ae6f912ef451a089148e510623759cf55c408efdefffffffff02f4063f00000000001976a914b269e0ceec5d5b5e192cf580ae42341e0f79b0b588aca8c84b02000000001976a91439233c0d43a1411e547c60bad8985bae3530b6af88ac00000000", Txid: "0cfeb968fb5d0f6b9a2a1de37c0607a1964dd3e335f203377cec90e03b20869e", From e12673df11bf8df0095313940e57f51f4e1c7aa3 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 6 May 2014 10:49:46 -0500 Subject: [PATCH 59/76] Switch notifyspent to take an array of outpoints. This allows a wallet process to request spent notifications for many outpoints at once, rather than creating separate requests for each. --- cmds.go | 23 ++-- cmds_test.go | 26 +++-- test_coverage.txt | 266 +++++++++++++++++++++++----------------------- 3 files changed, 161 insertions(+), 154 deletions(-) diff --git a/cmds.go b/cmds.go index e4798b32..fab9bace 100644 --- a/cmds.go +++ b/cmds.go @@ -1043,18 +1043,18 @@ func (cmd *NotifyNewTransactionsCmd) UnmarshalJSON(b []byte) error { // unmarshaling of notifyspent JSON websocket extension // commands. type NotifySpentCmd struct { - id interface{} - *OutPoint + id interface{} + OutPoints []OutPoint } // Enforce that NotifySpentCmd satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &NotifySpentCmd{} // NewNotifySpentCmd creates a new NotifySpentCmd. -func NewNotifySpentCmd(id interface{}, op *OutPoint) *NotifySpentCmd { +func NewNotifySpentCmd(id interface{}, outpoints []OutPoint) *NotifySpentCmd { return &NotifySpentCmd{ - id: id, - OutPoint: op, + id: id, + OutPoints: outpoints, } } @@ -1066,13 +1066,14 @@ func parseNotifySpentCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - var outpoint OutPoint - if err := json.Unmarshal(r.Params[0], &outpoint); err != nil { - return nil, errors.New("first parameter 'outpoint' must be a " + - "an outpoint JSON object: " + err.Error()) + var outpoints []OutPoint + if err := json.Unmarshal(r.Params[0], &outpoints); err != nil { + return nil, errors.New("first parameter 'outpoints' must be a " + + "an array of transaction outpoint JSON objects: " + + err.Error()) } - return NewNotifySpentCmd(r.Id, &outpoint), nil + return NewNotifySpentCmd(r.Id, outpoints), nil } // Id satisifies the Cmd interface by returning the ID of the command. @@ -1093,7 +1094,7 @@ func (cmd *NotifySpentCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *NotifySpentCmd) MarshalJSON() ([]byte, error) { params := []interface{}{ - cmd.OutPoint, + cmd.OutPoints, } raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) diff --git a/cmds_test.go b/cmds_test.go index a7dcaa45..db4201f7 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -187,21 +187,25 @@ var cmdtests = []struct { { name: "notifyspent", f: func() (btcjson.Cmd, error) { - op := &OutPoint{ - Hash: "000102030405060708091011121314" + - "1516171819202122232425262728" + - "293031", - Index: 1, + ops := []OutPoint{ + { + Hash: "000102030405060708091011121314" + + "1516171819202122232425262728" + + "293031", + Index: 1, + }, } - return NewNotifySpentCmd(float64(1), op), nil + return NewNotifySpentCmd(float64(1), ops), nil }, result: &NotifySpentCmd{ id: float64(1), - OutPoint: &OutPoint{ - Hash: "000102030405060708091011121314" + - "1516171819202122232425262728" + - "293031", - Index: 1, + OutPoints: []OutPoint{ + { + Hash: "000102030405060708091011121314" + + "1516171819202122232425262728" + + "293031", + Index: 1, + }, }, }, }, diff --git a/test_coverage.txt b/test_coverage.txt index a27ce0d2..e0c81432 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,194 +1,196 @@ github.com/conformal/btcws/cmds.go init 100.00% (16/16) github.com/conformal/btcws/notifications.go init 100.00% (11/11) -github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAllVerboseTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go AllTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go AllTxNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAllTxNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifyNewTXsCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go generateAllVerboseTxNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewNotifyReceivedCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyReceivedCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyReceivedCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRescanProgressNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRescanProgressNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxAcceptedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxAcceptedVerboseNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 90.00% (9/10) -github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 88.89% (8/9) -github.com/conformal/btcws/notifications.go RecvTxNtfn.MarshalJSON 87.50% (7/8) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 87.50% (7/8) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 87.50% (7/8) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.MarshalJSON 87.50% (7/8) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 87.50% (7/8) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 85.71% (6/7) -github.com/conformal/btcws/cmds.go NewNotifyAllNewTXsCmd 85.71% (6/7) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 85.71% (6/7) +github.com/conformal/btcws/notifications.go RecvTxNtfn.MarshalJSON 87.50% (7/8) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 85.71% (6/7) -github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 85.71% (6/7) +github.com/conformal/btcws/cmds.go NewNotifyNewTransactionsCmd 85.71% (6/7) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 85.71% (6/7) github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go AllTxNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NotifyReceivedCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 77.78% (7/9) -github.com/conformal/btcws/cmds.go parseNotifyAllNewTXsCmd 77.78% (7/9) +github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 77.78% (7/9) +github.com/conformal/btcws/cmds.go parseNotifyNewTransactionsCmd 77.78% (7/9) github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 75.00% (9/12) github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 75.00% (9/12) github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 75.00% (3/4) github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 75.00% (3/4) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go AllTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyReceivedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go parseRescanCmd 72.22% (13/18) -github.com/conformal/btcws/notifications.go parseRecvTxNtfn 66.67% (8/12) -github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.UnmarshalJSON 66.67% (8/12) github.com/conformal/btcws/notifications.go parseRedeemingTxNtfn 66.67% (8/12) -github.com/conformal/btcws/cmds.go parseNotifyNewTXsCmd 66.67% (4/6) +github.com/conformal/btcws/notifications.go parseRecvTxNtfn 66.67% (8/12) +github.com/conformal/btcws/cmds.go parseNotifyReceivedCmd 66.67% (4/6) github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (4/6) github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 66.67% (4/6) -github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) +github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) -github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseAllTxNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseTxAcceptedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseRescanProgressNtfn 62.50% (5/8) +github.com/conformal/btcws/notifications.go parseTxAcceptedVerboseNtfn 62.50% (5/8) github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) github.com/conformal/btcws/cmds.go NewExportWatchingWalletCmd 0.00% (0/15) github.com/conformal/btcws/cmds.go parseExportWatchingWalletCmd 0.00% (0/14) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go AuthenticateCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go NotifyBlocksCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.MarshalJSON 0.00% (0/9) -github.com/conformal/btcws/cmds.go parseRecoverAddressesCmd 0.00% (0/9) +github.com/conformal/btcws/cmds.go AuthenticateCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go parseAuthenticateCmd 0.00% (0/9) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.MarshalJSON 0.00% (0/5) +github.com/conformal/btcws/cmds.go parseRecoverAddressesCmd 0.00% (0/9) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.MarshalJSON 0.00% (0/9) github.com/conformal/btcws/cmds.go AuthenticateCmd.MarshalJSON 0.00% (0/5) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.MarshalJSON 0.00% (0/5) github.com/conformal/btcws/cmds.go NotifyBlocksCmd.MarshalJSON 0.00% (0/4) +github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmdReply 0.00% (0/4) github.com/conformal/btcws/cmds.go parseNotifyBlocksCmd 0.00% (0/3) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewNotifyBlocksCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewAuthenticateCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewOutPointFromWire 0.00% (0/1) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewRecoverAddressesCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyNewTXsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyAllNewTXsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Method 0.00% (0/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) github.com/conformal/btcws/cmds.go AuthenticateCmd.Method 0.00% (0/1) github.com/conformal/btcws/cmds.go AuthenticateCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go AuthenticateCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewAuthenticateCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewRecoverAddressesCmd 0.00% (0/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/notifications.go AllTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyReceivedCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewNotifyBlocksCmd 0.00% (0/1) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go AllVerboseTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.SetId 0.00% (0/0) github.com/conformal/btcws/notifications.go RecvTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws ---------------------------------------- 64.77% (568/877) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.SetId 0.00% (0/0) +github.com/conformal/btcws ---------------------------------------- 64.30% (571/888) From c24be8b7bfbba53b40c10f2d22abdb739c888936 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sun, 11 May 2014 02:32:24 -0500 Subject: [PATCH 60/76] Add reply parser for GetBestBlockCmd. --- cmds.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cmds.go b/cmds.go index fab9bace..f6a3c302 100644 --- a/cmds.go +++ b/cmds.go @@ -29,8 +29,8 @@ func init() { parseExportWatchingWalletCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("getaddressbalance", parseGetAddressBalanceCmd, nil, `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd, nil, - `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd, + parseGetBestBlockCmdReply, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("getunconfirmedbalance", @@ -489,6 +489,17 @@ func parseGetBestBlockCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return NewGetBestBlockCmd(r.Id), nil } +// parseGetBestBlockCmdReply parses a the reply to a GetBestBlockCmd into a +// concrete type and returns it packed into an interface. This is used when +// registering the custom command with btcjson. +func parseGetBestBlockCmdReply(message json.RawMessage) (interface{}, error) { + var res *GetBestBlockResult + if err := json.Unmarshal(message, &res); err != nil { + return nil, err + } + return res, nil +} + // Id satisifies the Cmd interface by returning the ID of the command. func (cmd *GetBestBlockCmd) Id() interface{} { return cmd.id From b873e70c95c3801201751fb951c62d4c0af03dfb Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 11 Jun 2014 12:04:51 -0500 Subject: [PATCH 61/76] Remove SetId. --- cmds.go | 80 ------------------------------------------------ notifications.go | 44 -------------------------- 2 files changed, 124 deletions(-) diff --git a/cmds.go b/cmds.go index f6a3c302..04ce4005 100644 --- a/cmds.go +++ b/cmds.go @@ -105,11 +105,6 @@ func (cmd *AuthenticateCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *AuthenticateCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *AuthenticateCmd) Method() string { return "authenticate" @@ -182,11 +177,6 @@ func (cmd *GetCurrentNetCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *GetCurrentNetCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *GetCurrentNetCmd) Method() string { return "getcurrentnet" @@ -303,11 +293,6 @@ func (cmd *ExportWatchingWalletCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *ExportWatchingWalletCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisifies the Cmd interface by returning the RPC method. func (cmd *ExportWatchingWalletCmd) Method() string { return "exportwatchingwallet" @@ -411,11 +396,6 @@ func (cmd *GetUnconfirmedBalanceCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *GetUnconfirmedBalanceCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisifies the Cmd interface by returning the RPC method. func (cmd *GetUnconfirmedBalanceCmd) Method() string { return "getunconfirmedbalance" @@ -505,11 +485,6 @@ func (cmd *GetBestBlockCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *GetBestBlockCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *GetBestBlockCmd) Method() string { return "getbestblock" @@ -595,11 +570,6 @@ func (cmd *RecoverAddressesCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *RecoverAddressesCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *RecoverAddressesCmd) Method() string { return "recoveraddresses" @@ -741,11 +711,6 @@ func (cmd *RescanCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *RescanCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *RescanCmd) Method() string { return "rescan" @@ -822,11 +787,6 @@ func (cmd *NotifyBlocksCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *NotifyBlocksCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *NotifyBlocksCmd) Method() string { return "notifyblocks" @@ -904,11 +864,6 @@ func (cmd *NotifyReceivedCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *NotifyReceivedCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *NotifyReceivedCmd) Method() string { return "notifyreceived" @@ -1005,11 +960,6 @@ func (cmd *NotifyNewTransactionsCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *NotifyNewTransactionsCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *NotifyNewTransactionsCmd) Method() string { return "notifynewtransactions" @@ -1092,11 +1042,6 @@ func (cmd *NotifySpentCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *NotifySpentCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *NotifySpentCmd) Method() string { return "notifyspent" @@ -1180,11 +1125,6 @@ func (cmd *CreateEncryptedWalletCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *CreateEncryptedWalletCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *CreateEncryptedWalletCmd) Method() string { return "createencryptedwallet" @@ -1283,11 +1223,6 @@ func (cmd *WalletIsLockedCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *WalletIsLockedCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *WalletIsLockedCmd) Method() string { return "walletislocked" @@ -1406,11 +1341,6 @@ func (cmd *ListAddressTransactionsCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *ListAddressTransactionsCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *ListAddressTransactionsCmd) Method() string { return "listaddresstransactions" @@ -1511,11 +1441,6 @@ func (cmd *ListAllTransactionsCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *ListAllTransactionsCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *ListAllTransactionsCmd) Method() string { return "listalltransactions" @@ -1626,11 +1551,6 @@ func (cmd *GetAddressBalanceCmd) Id() interface{} { return cmd.id } -// SetId satisifies the Cmd interface by setting the ID of the command. -func (cmd *GetAddressBalanceCmd) SetId(id interface{}) { - cmd.id = id -} - // Method satisfies the Cmd interface by returning the RPC method. func (cmd *GetAddressBalanceCmd) Method() string { return "getaddressbalance" diff --git a/notifications.go b/notifications.go index 6f5eb208..b074255b 100644 --- a/notifications.go +++ b/notifications.go @@ -154,10 +154,6 @@ func (n *AccountBalanceNtfn) Id() interface{} { return nil } -// SetId is implemented to satisify the btcjson.Cmd interface. The -// notification id is not modified. -func (n *AccountBalanceNtfn) SetId(id interface{}) {} - // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *AccountBalanceNtfn) Method() string { @@ -252,10 +248,6 @@ func (n *BlockConnectedNtfn) Id() interface{} { return nil } -// SetId is implemented to satisify the btcjson.Cmd interface. The -// notification id is not modified. -func (n *BlockConnectedNtfn) SetId(id interface{}) {} - // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *BlockConnectedNtfn) Method() string { @@ -349,10 +341,6 @@ func (n *BlockDisconnectedNtfn) Id() interface{} { return nil } -// SetId is implemented to satisify the btcjson.Cmd interface. The -// notification id is not modified. -func (n *BlockDisconnectedNtfn) SetId(id interface{}) {} - // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *BlockDisconnectedNtfn) Method() string { @@ -438,10 +426,6 @@ func (n *BtcdConnectedNtfn) Id() interface{} { return nil } -// SetId is implemented to satisify the btcjson.Cmd interface. The -// notification id is not modified. -func (n *BtcdConnectedNtfn) SetId(id interface{}) {} - // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *BtcdConnectedNtfn) Method() string { @@ -540,10 +524,6 @@ func (n *RecvTxNtfn) Id() interface{} { return nil } -// SetId is implemented to satisify the btcjson.Cmd interface. The -// notification id is not modified. -func (n *RecvTxNtfn) SetId(id interface{}) {} - // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *RecvTxNtfn) Method() string { @@ -644,10 +624,6 @@ func (n *RedeemingTxNtfn) Id() interface{} { return nil } -// SetId is implemented to satisify the btcjson.Cmd interface. The -// notification id is not modified. -func (n *RedeemingTxNtfn) SetId(id interface{}) {} - // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *RedeemingTxNtfn) Method() string { @@ -734,10 +710,6 @@ func (n *RescanProgressNtfn) Id() interface{} { return nil } -// SetId is implemented to satisify the btcjson.Cmd interface. The -// notification ID is not modified. -func (n *RescanProgressNtfn) SetId(id interface{}) {} - // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *RescanProgressNtfn) Method() string { @@ -832,10 +804,6 @@ func (n *TxNtfn) Id() interface{} { return nil } -// SetId is implemented to satisify the btcjson.Cmd interface. The -// notification id is not modified. -func (n *TxNtfn) SetId(id interface{}) {} - // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *TxNtfn) Method() string { @@ -934,10 +902,6 @@ func (n *WalletLockStateNtfn) Id() interface{} { return nil } -// SetId is implemented to satisify the btcjson.Cmd interface. The -// notification id is not modified. -func (n *WalletLockStateNtfn) SetId(id interface{}) {} - // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *WalletLockStateNtfn) Method() string { @@ -1033,10 +997,6 @@ func (n *TxAcceptedNtfn) Id() interface{} { return nil } -// SetId is implemented to satisify the btcjson.Cmd interface. The -// notification id is not modified. -func (n *TxAcceptedNtfn) SetId(id interface{}) {} - // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *TxAcceptedNtfn) Method() string { @@ -1123,10 +1083,6 @@ func (n *TxAcceptedVerboseNtfn) Id() interface{} { return nil } -// SetId is implemented to satisify the btcjson.Cmd interface. The -// notification id is not modified. -func (n *TxAcceptedVerboseNtfn) SetId(id interface{}) {} - // Method satisifies the btcjson.Cmd interface by returning the method // of the notification. func (n *TxAcceptedVerboseNtfn) Method() string { From 5a01ac2ed8e27dcc8901703a5f9ad6fba6b10d41 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 11 Jun 2014 12:05:15 -0500 Subject: [PATCH 62/76] Update test coverage report. --- test_coverage.txt | 218 ++++++++++++++++++++-------------------------- 1 file changed, 96 insertions(+), 122 deletions(-) diff --git a/test_coverage.txt b/test_coverage.txt index e0c81432..bc91d65c 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,196 +1,170 @@ github.com/conformal/btcws/cmds.go init 100.00% (16/16) github.com/conformal/btcws/notifications.go init 100.00% (11/11) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxAcceptedVerboseNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxAcceptedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifyReceivedCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyReceivedCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyReceivedCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRescanProgressNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxAcceptedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxAcceptedVerboseNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRescanProgressNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 90.00% (9/10) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 87.50% (7/8) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 87.50% (7/8) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 87.50% (7/8) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.MarshalJSON 87.50% (7/8) github.com/conformal/btcws/notifications.go RecvTxNtfn.MarshalJSON 87.50% (7/8) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 85.71% (6/7) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 85.71% (6/7) -github.com/conformal/btcws/cmds.go NewNotifyNewTransactionsCmd 85.71% (6/7) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 85.71% (6/7) -github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 85.71% (6/7) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 85.71% (6/7) +github.com/conformal/btcws/cmds.go NewNotifyNewTransactionsCmd 85.71% (6/7) github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go NotifyReceivedCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NotifyReceivedCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 77.78% (7/9) -github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 77.78% (7/9) github.com/conformal/btcws/cmds.go parseNotifyNewTransactionsCmd 77.78% (7/9) +github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 77.78% (7/9) github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 75.00% (9/12) github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 75.00% (9/12) github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 75.00% (3/4) github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 75.00% (3/4) -github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyReceivedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyReceivedCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go parseRescanCmd 72.22% (13/18) -github.com/conformal/btcws/notifications.go parseRedeemingTxNtfn 66.67% (8/12) github.com/conformal/btcws/notifications.go parseRecvTxNtfn 66.67% (8/12) -github.com/conformal/btcws/cmds.go parseNotifyReceivedCmd 66.67% (4/6) +github.com/conformal/btcws/notifications.go parseRedeemingTxNtfn 66.67% (8/12) github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (4/6) +github.com/conformal/btcws/cmds.go parseNotifyReceivedCmd 66.67% (4/6) github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 66.67% (4/6) github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) -github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseTxAcceptedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) github.com/conformal/btcws/notifications.go parseRescanProgressNtfn 62.50% (5/8) github.com/conformal/btcws/notifications.go parseTxAcceptedVerboseNtfn 62.50% (5/8) -github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) github.com/conformal/btcws/cmds.go NewExportWatchingWalletCmd 0.00% (0/15) github.com/conformal/btcws/cmds.go parseExportWatchingWalletCmd 0.00% (0/14) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go AuthenticateCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go parseAuthenticateCmd 0.00% (0/9) -github.com/conformal/btcws/cmds.go parseRecoverAddressesCmd 0.00% (0/9) github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.MarshalJSON 0.00% (0/9) +github.com/conformal/btcws/cmds.go parseRecoverAddressesCmd 0.00% (0/9) +github.com/conformal/btcws/cmds.go parseAuthenticateCmd 0.00% (0/9) github.com/conformal/btcws/cmds.go AuthenticateCmd.MarshalJSON 0.00% (0/5) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.MarshalJSON 0.00% (0/5) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.MarshalJSON 0.00% (0/4) github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmdReply 0.00% (0/4) +github.com/conformal/btcws/cmds.go parseGetBestBlockCmdReply 0.00% (0/4) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.MarshalJSON 0.00% (0/4) github.com/conformal/btcws/cmds.go parseNotifyBlocksCmd 0.00% (0/3) -github.com/conformal/btcws/cmds.go NewOutPointFromWire 0.00% (0/1) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go AuthenticateCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go AuthenticateCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go AuthenticateCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewOutPointFromWire 0.00% (0/1) github.com/conformal/btcws/cmds.go NewAuthenticateCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go RescanCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.SetId 0.00% (0/1) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Id 0.00% (0/1) github.com/conformal/btcws/cmds.go NewRecoverAddressesCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.SetId 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyReceivedCmd.SetId 0.00% (0/1) github.com/conformal/btcws/cmds.go NewNotifyBlocksCmd 0.00% (0/1) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go TxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go RecvTxNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.SetId 0.00% (0/0) -github.com/conformal/btcws ---------------------------------------- 64.30% (571/888) +github.com/conformal/btcws/cmds.go AuthenticateCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go AuthenticateCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Method 0.00% (0/1) +github.com/conformal/btcws ---------------------------------------- 65.18% (571/876) From 160113d6124d82d6ddc88ef9672a469ab048178b Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 16 Jun 2014 09:37:56 -0500 Subject: [PATCH 63/76] Add rescanfinished notification. --- notifications.go | 90 +++++++++++++++++++++++++++++++++++++++++++ notifications_test.go | 9 +++++ 2 files changed, 99 insertions(+) diff --git a/notifications.go b/notifications.go index b074255b..7565fdbb 100644 --- a/notifications.go +++ b/notifications.go @@ -53,6 +53,10 @@ const ( // notification. RedeemingTxNtfnMethod = "redeemingtx" + // RescanFinishedNtfnMethod is the method of the btcd rescanfinished + // notification. + RescanFinishedNtfnMethod = "rescanfinished" + // RescanProgressNtfnMethod is the method of the btcd rescanprogress // notification. RescanProgressNtfnMethod = "rescanprogress" @@ -74,6 +78,8 @@ func init() { parseBtcdConnectedNtfn, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(RecvTxNtfnMethod, parseRecvTxNtfn, nil, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd(RescanFinishedNtfnMethod, + parseRescanFinishedNtfn, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(RescanProgressNtfnMethod, parseRescanProgressNtfn, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd(RedeemingTxNtfnMethod, parseRedeemingTxNtfn, @@ -669,6 +675,90 @@ func (n *RedeemingTxNtfn) UnmarshalJSON(b []byte) error { return nil } +// RescanFinishedNtfn is type handling custom marshaling and +// unmarshaling of rescanfinished JSON websocket notifications. +type RescanFinishedNtfn struct { + LastProcessed int32 +} + +// Enforce that RescanFinishedNtfn satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &RescanFinishedNtfn{} + +// NewRescanFinishedNtfn creates a new RescanFinshedNtfn. +func NewRescanFinishedNtfn(last int32) *RescanFinishedNtfn { + return &RescanFinishedNtfn{last} +} + +// parseRescanFinishedNtfn parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the notification +// with the btcjson parser. +func parseRescanFinishedNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if r.Id != nil { + return nil, ErrNotANtfn + } + + if len(r.Params) != 1 { + return nil, btcjson.ErrWrongNumberOfParams + } + + var last int32 + if err := json.Unmarshal(r.Params[0], &last); err != nil { + return nil, errors.New("first parameter 'last' must be a " + + "32-bit integer: " + err.Error()) + } + + return NewRescanFinishedNtfn(last), nil +} + +// Id satisifies the btcjson.Cmd interface by returning nil for a +// notification ID. +func (n *RescanFinishedNtfn) Id() interface{} { + return nil +} + +// Method satisifies the btcjson.Cmd interface by returning the method +// of the notification. +func (n *RescanFinishedNtfn) Method() string { + return RescanFinishedNtfnMethod +} + +// MarshalJSON returns the JSON encoding of n. Part of the btcjson.Cmd +// interface. +func (n *RescanFinishedNtfn) MarshalJSON() ([]byte, error) { + params := []interface{}{ + n.LastProcessed, + } + + // No ID for notifications. + raw, err := btcjson.NewRawCmd(nil, n.Method(), params) + if err != nil { + return nil, err + } + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of n into n. Part of +// the btcjson.Cmd interface. +func (n *RescanFinishedNtfn) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newNtfn, err := parseRescanFinishedNtfn(&r) + if err != nil { + return err + } + + concreteNtfn, ok := newNtfn.(*RescanFinishedNtfn) + if !ok { + return btcjson.ErrInternal + } + *n = *concreteNtfn + return nil +} + // RescanProgressNtfn is type handling custom marshaling and // unmarshaling of rescanprogress JSON websocket notifications. type RescanProgressNtfn struct { diff --git a/notifications_test.go b/notifications_test.go index 4dc399fb..05d407b1 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -123,6 +123,15 @@ var ntfntests = []struct { }, }, }, + { + name: "rescanfinished", + f: func() btcjson.Cmd { + return btcws.NewRescanFinishedNtfn(12345) + }, + result: &btcws.RescanFinishedNtfn{ + LastProcessed: 12345, + }, + }, { name: "rescanprogress", f: func() btcjson.Cmd { From 385201f9dad8f9f7721929c16b0dec7a7360d2fe Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 16 Jun 2014 14:47:11 -0500 Subject: [PATCH 64/76] Update test coverage report. --- test_coverage.txt | 186 ++++++++++++++++++++++++---------------------- 1 file changed, 96 insertions(+), 90 deletions(-) diff --git a/test_coverage.txt b/test_coverage.txt index bc91d65c..93d43c01 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,170 +1,176 @@ github.com/conformal/btcws/cmds.go init 100.00% (16/16) -github.com/conformal/btcws/notifications.go init 100.00% (11/11) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxAcceptedVerboseNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go init 100.00% (12/12) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxAcceptedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifyReceivedCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyReceivedCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyReceivedCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRescanProgressNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRescanFinishedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanFinishedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanFinishedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRescanProgressNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxAcceptedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxAcceptedVerboseNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 90.00% (9/10) +github.com/conformal/btcws/notifications.go RecvTxNtfn.MarshalJSON 87.50% (7/8) github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 87.50% (7/8) github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 87.50% (7/8) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.MarshalJSON 87.50% (7/8) -github.com/conformal/btcws/notifications.go RecvTxNtfn.MarshalJSON 87.50% (7/8) +github.com/conformal/btcws/cmds.go NewNotifyNewTransactionsCmd 85.71% (6/7) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 85.71% (6/7) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 85.71% (6/7) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 85.71% (6/7) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 85.71% (6/7) -github.com/conformal/btcws/cmds.go NewNotifyNewTransactionsCmd 85.71% (6/7) -github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) github.com/conformal/btcws/notifications.go TxAcceptedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go RescanFinishedNtfn.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/cmds.go NotifyReceivedCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 77.78% (7/9) github.com/conformal/btcws/cmds.go parseNotifyNewTransactionsCmd 77.78% (7/9) +github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 77.78% (7/9) github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 77.78% (7/9) github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 75.00% (9/12) github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 75.00% (9/12) github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 75.00% (3/4) github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 75.00% (3/4) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 75.00% (3/4) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyReceivedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RescanFinishedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go TxAcceptedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyReceivedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go parseRescanCmd 72.22% (13/18) github.com/conformal/btcws/notifications.go parseRecvTxNtfn 66.67% (8/12) github.com/conformal/btcws/notifications.go parseRedeemingTxNtfn 66.67% (8/12) -github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (4/6) github.com/conformal/btcws/cmds.go parseNotifyReceivedCmd 66.67% (4/6) github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 66.67% (4/6) +github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (4/6) github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) +github.com/conformal/btcws/notifications.go parseTxAcceptedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseTxAcceptedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) github.com/conformal/btcws/notifications.go parseRescanProgressNtfn 62.50% (5/8) github.com/conformal/btcws/notifications.go parseTxAcceptedVerboseNtfn 62.50% (5/8) +github.com/conformal/btcws/notifications.go parseRescanFinishedNtfn 62.50% (5/8) +github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) github.com/conformal/btcws/cmds.go NewExportWatchingWalletCmd 0.00% (0/15) github.com/conformal/btcws/cmds.go parseExportWatchingWalletCmd 0.00% (0/14) -github.com/conformal/btcws/cmds.go AuthenticateCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go AuthenticateCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.MarshalJSON 0.00% (0/9) github.com/conformal/btcws/cmds.go parseRecoverAddressesCmd 0.00% (0/9) github.com/conformal/btcws/cmds.go parseAuthenticateCmd 0.00% (0/9) github.com/conformal/btcws/cmds.go AuthenticateCmd.MarshalJSON 0.00% (0/5) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.MarshalJSON 0.00% (0/5) -github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmdReply 0.00% (0/4) github.com/conformal/btcws/cmds.go parseGetBestBlockCmdReply 0.00% (0/4) github.com/conformal/btcws/cmds.go NotifyBlocksCmd.MarshalJSON 0.00% (0/4) +github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmdReply 0.00% (0/4) github.com/conformal/btcws/cmds.go parseNotifyBlocksCmd 0.00% (0/3) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewOutPointFromWire 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewNotifyBlocksCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) github.com/conformal/btcws/cmds.go NewAuthenticateCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewOutPointFromWire 0.00% (0/1) +github.com/conformal/btcws/cmds.go AuthenticateCmd.Id 0.00% (0/1) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Id 0.00% (0/1) github.com/conformal/btcws/cmds.go NewRecoverAddressesCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewNotifyBlocksCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Method 0.00% (0/1) github.com/conformal/btcws/cmds.go AuthenticateCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go AuthenticateCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Method 0.00% (0/1) -github.com/conformal/btcws ---------------------------------------- 65.18% (571/876) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Id 0.00% (0/1) +github.com/conformal/btcws ---------------------------------------- 65.49% (592/904) From 1acb4b81518f816c7beeff389b35cf26d40efd42 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 2 Jul 2014 19:44:43 -0500 Subject: [PATCH 65/76] goimports -w . --- cmds.go | 1 + cmds_test.go | 5 +++-- notifications.go | 1 + notifications_test.go | 5 +++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmds.go b/cmds.go index 04ce4005..5e01786a 100644 --- a/cmds.go +++ b/cmds.go @@ -7,6 +7,7 @@ package btcws import ( "encoding/json" "errors" + "github.com/conformal/btcdb" "github.com/conformal/btcjson" "github.com/conformal/btcwire" diff --git a/cmds_test.go b/cmds_test.go index db4201f7..ea4d607f 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -6,11 +6,12 @@ package btcws import ( + "reflect" + "testing" + "github.com/conformal/btcdb" "github.com/conformal/btcjson" "github.com/davecgh/go-spew/spew" - "reflect" - "testing" ) var cmdtests = []struct { diff --git a/notifications.go b/notifications.go index 7565fdbb..5b8bc655 100644 --- a/notifications.go +++ b/notifications.go @@ -7,6 +7,7 @@ package btcws import ( "encoding/json" "errors" + "github.com/conformal/btcjson" ) diff --git a/notifications_test.go b/notifications_test.go index 05d407b1..22ca40fd 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -5,11 +5,12 @@ package btcws_test import ( + "reflect" + "testing" + "github.com/conformal/btcjson" "github.com/conformal/btcws" "github.com/davecgh/go-spew/spew" - "reflect" - "testing" ) var ntfntests = []struct { From de236d53950fa01eddc49ffd0b45b6d443d65de5 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 16 Jul 2014 20:35:11 -0500 Subject: [PATCH 66/76] Use hashes for rescan, add hash+time to ntfns. ok @davecgh --- cmds.go | 25 ++++++++-------- cmds_test.go | 15 +++++----- notifications.go | 68 +++++++++++++++++++++++++++++++------------ notifications_test.go | 16 +++++++--- 4 files changed, 81 insertions(+), 43 deletions(-) diff --git a/cmds.go b/cmds.go index 5e01786a..d22c2a10 100644 --- a/cmds.go +++ b/cmds.go @@ -8,7 +8,6 @@ import ( "encoding/json" "errors" - "github.com/conformal/btcdb" "github.com/conformal/btcjson" "github.com/conformal/btcwire" ) @@ -633,10 +632,10 @@ func NewOutPointFromWire(op *btcwire.OutPoint) *OutPoint { // commands. type RescanCmd struct { id interface{} - BeginBlock int32 + BeginBlock string Addresses []string OutPoints []OutPoint - EndBlock int64 // TODO: switch this and btcdb.AllShas to int32 + EndBlock string } // Enforce that RescanCmd satisifies the btcjson.Cmd interface. @@ -644,12 +643,12 @@ var _ btcjson.Cmd = &RescanCmd{} // NewRescanCmd creates a new RescanCmd, parsing the optional // arguments optArgs which may either be empty or a single upper -// block height. -func NewRescanCmd(id interface{}, begin int32, addresses []string, - outpoints []OutPoint, optArgs ...int64) (*RescanCmd, error) { +// block hash. +func NewRescanCmd(id interface{}, begin string, addresses []string, + outpoints []OutPoint, optArgs ...string) (*RescanCmd, error) { // Optional parameters set to their defaults. - end := btcdb.AllShas + var end string if len(optArgs) > 0 { if len(optArgs) > 1 { @@ -675,10 +674,10 @@ func parseRescanCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, btcjson.ErrWrongNumberOfParams } - var begin int32 + var begin string if err := json.Unmarshal(r.Params[0], &begin); err != nil { return nil, errors.New("first parameter 'begin' must be a " + - "32-bit integer: " + err.Error()) + "string: " + err.Error()) } var addresses []string @@ -694,12 +693,12 @@ func parseRescanCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { err.Error()) } - optArgs := make([]int64, 0, 1) + optArgs := make([]string, 0, 1) if len(r.Params) > 3 { - var endblock int64 + var endblock string if err := json.Unmarshal(r.Params[3], &endblock); err != nil { return nil, errors.New("fourth optional parameter " + - " 'endblock' must be an integer: " + err.Error()) + "'endblock' must be a string: " + err.Error()) } optArgs = append(optArgs, endblock) } @@ -723,7 +722,7 @@ func (cmd *RescanCmd) MarshalJSON() ([]byte, error) { params[0] = cmd.BeginBlock params[1] = cmd.Addresses params[2] = cmd.OutPoints - if cmd.EndBlock != btcdb.AllShas { + if cmd.EndBlock != "" { params = append(params, cmd.EndBlock) } diff --git a/cmds_test.go b/cmds_test.go index ea4d607f..5c9f8e2b 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -9,7 +9,6 @@ import ( "reflect" "testing" - "github.com/conformal/btcdb" "github.com/conformal/btcjson" "github.com/davecgh/go-spew/spew" ) @@ -224,13 +223,13 @@ var cmdtests = []struct { } return NewRescanCmd( float64(1), - 270000, + "0000000000000002a775aec59dc6a9e4bb1c025cf1b8c2195dd9dc3998c827c5", addrs, ops) }, result: &RescanCmd{ id: float64(1), - BeginBlock: 270000, + BeginBlock: "0000000000000002a775aec59dc6a9e4bb1c025cf1b8c2195dd9dc3998c827c5", Addresses: []string{"17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH"}, OutPoints: []OutPoint{ { @@ -240,7 +239,7 @@ var cmdtests = []struct { Index: 1, }, }, - EndBlock: btcdb.AllShas, + EndBlock: "", }, }, { @@ -257,14 +256,14 @@ var cmdtests = []struct { } return NewRescanCmd( float64(1), - 270000, + "0000000000000002a775aec59dc6a9e4bb1c025cf1b8c2195dd9dc3998c827c5", addrs, ops, - 280000) + "0000000000000001c091ada69f444dc0282ecaabe4808ddbb2532e5555db0c03") }, result: &RescanCmd{ id: float64(1), - BeginBlock: 270000, + BeginBlock: "0000000000000002a775aec59dc6a9e4bb1c025cf1b8c2195dd9dc3998c827c5", Addresses: []string{"17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH"}, OutPoints: []OutPoint{ { @@ -274,7 +273,7 @@ var cmdtests = []struct { Index: 1, }, }, - EndBlock: 280000, + EndBlock: "0000000000000001c091ada69f444dc0282ecaabe4808ddbb2532e5555db0c03", }, }, { diff --git a/notifications.go b/notifications.go index 5b8bc655..708aeb85 100644 --- a/notifications.go +++ b/notifications.go @@ -679,15 +679,17 @@ func (n *RedeemingTxNtfn) UnmarshalJSON(b []byte) error { // RescanFinishedNtfn is type handling custom marshaling and // unmarshaling of rescanfinished JSON websocket notifications. type RescanFinishedNtfn struct { - LastProcessed int32 + Hash string + Height int32 + Time int64 } // Enforce that RescanFinishedNtfn satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &RescanFinishedNtfn{} // NewRescanFinishedNtfn creates a new RescanFinshedNtfn. -func NewRescanFinishedNtfn(last int32) *RescanFinishedNtfn { - return &RescanFinishedNtfn{last} +func NewRescanFinishedNtfn(hash string, height int32, time int64) *RescanFinishedNtfn { + return &RescanFinishedNtfn{hash, height, time} } // parseRescanFinishedNtfn parses a RawCmd into a concrete type satisifying @@ -698,17 +700,29 @@ func parseRescanFinishedNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, ErrNotANtfn } - if len(r.Params) != 1 { + if len(r.Params) != 3 { return nil, btcjson.ErrWrongNumberOfParams } - var last int32 - if err := json.Unmarshal(r.Params[0], &last); err != nil { - return nil, errors.New("first parameter 'last' must be a " + + var hash string + if err := json.Unmarshal(r.Params[0], &hash); err != nil { + return nil, errors.New("first parameter 'hash' must be a " + + "string: " + err.Error()) + } + + var height int32 + if err := json.Unmarshal(r.Params[1], &height); err != nil { + return nil, errors.New("second parameter 'height' must be a " + "32-bit integer: " + err.Error()) } - return NewRescanFinishedNtfn(last), nil + var time int64 + if err := json.Unmarshal(r.Params[2], &time); err != nil { + return nil, errors.New("third parameter 'time' must be a " + + "64-bit integer: " + err.Error()) + } + + return NewRescanFinishedNtfn(hash, height, time), nil } // Id satisifies the btcjson.Cmd interface by returning nil for a @@ -727,7 +741,9 @@ func (n *RescanFinishedNtfn) Method() string { // interface. func (n *RescanFinishedNtfn) MarshalJSON() ([]byte, error) { params := []interface{}{ - n.LastProcessed, + n.Hash, + n.Height, + n.Time, } // No ID for notifications. @@ -763,15 +779,17 @@ func (n *RescanFinishedNtfn) UnmarshalJSON(b []byte) error { // RescanProgressNtfn is type handling custom marshaling and // unmarshaling of rescanprogress JSON websocket notifications. type RescanProgressNtfn struct { - LastProcessed int32 + Hash string + Height int32 + Time int64 } // Enforce that RescanProgressNtfn satisifies the btcjson.Cmd interface. var _ btcjson.Cmd = &RescanProgressNtfn{} // NewRescanProgressNtfn creates a new RescanProgressNtfn. -func NewRescanProgressNtfn(last int32) *RescanProgressNtfn { - return &RescanProgressNtfn{last} +func NewRescanProgressNtfn(hash string, height int32, time int64) *RescanProgressNtfn { + return &RescanProgressNtfn{hash, height, time} } // parseRescanProgressNtfn parses a RawCmd into a concrete type satisifying @@ -782,17 +800,29 @@ func parseRescanProgressNtfn(r *btcjson.RawCmd) (btcjson.Cmd, error) { return nil, ErrNotANtfn } - if len(r.Params) != 1 { + if len(r.Params) != 3 { return nil, btcjson.ErrWrongNumberOfParams } - var last int32 - if err := json.Unmarshal(r.Params[0], &last); err != nil { - return nil, errors.New("first parameter 'last' must be a " + + var hash string + if err := json.Unmarshal(r.Params[0], &hash); err != nil { + return nil, errors.New("first parameter 'hash' must be a " + + "string: " + err.Error()) + } + + var height int32 + if err := json.Unmarshal(r.Params[1], &height); err != nil { + return nil, errors.New("second parameter 'height' must be a " + "32-bit integer: " + err.Error()) } - return NewRescanProgressNtfn(last), nil + var time int64 + if err := json.Unmarshal(r.Params[2], &time); err != nil { + return nil, errors.New("third parameter 'time' must be a " + + "64-bit integer: " + err.Error()) + } + + return NewRescanProgressNtfn(hash, height, time), nil } // Id satisifies the btcjson.Cmd interface by returning nil for a @@ -811,7 +841,9 @@ func (n *RescanProgressNtfn) Method() string { // interface. func (n *RescanProgressNtfn) MarshalJSON() ([]byte, error) { params := []interface{}{ - n.LastProcessed, + n.Hash, + n.Height, + n.Time, } // No ID for notifications. diff --git a/notifications_test.go b/notifications_test.go index 22ca40fd..f473b4e9 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -127,19 +127,27 @@ var ntfntests = []struct { { name: "rescanfinished", f: func() btcjson.Cmd { - return btcws.NewRescanFinishedNtfn(12345) + return btcws.NewRescanFinishedNtfn( + "00000000b8980ec1fe96bc1b4425788ddc88dd36699521a448ebca2020b38699", + 12345, 1240784732) }, result: &btcws.RescanFinishedNtfn{ - LastProcessed: 12345, + Hash: "00000000b8980ec1fe96bc1b4425788ddc88dd36699521a448ebca2020b38699", + Height: 12345, + Time: 1240784732, }, }, { name: "rescanprogress", f: func() btcjson.Cmd { - return btcws.NewRescanProgressNtfn(12345) + return btcws.NewRescanProgressNtfn( + "00000000b8980ec1fe96bc1b4425788ddc88dd36699521a448ebca2020b38699", + 12345, 1240784732) }, result: &btcws.RescanProgressNtfn{ - LastProcessed: 12345, + Hash: "00000000b8980ec1fe96bc1b4425788ddc88dd36699521a448ebca2020b38699", + Height: 12345, + Time: 1240784732, }, }, { From 85cc323e34e694615c4364ebe97010d7c3197952 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Sat, 26 Jul 2014 17:53:35 -0500 Subject: [PATCH 67/76] Remove GetAddressBalanceCmd. Support for this extension request has been removed from btcwallet and will not be returning. --- cmds.go | 113 ------------------------ cmds_test.go | 27 ------ test_coverage.txt | 218 ++++++++++++++++++++++------------------------ 3 files changed, 106 insertions(+), 252 deletions(-) diff --git a/cmds.go b/cmds.go index d22c2a10..898e5d18 100644 --- a/cmds.go +++ b/cmds.go @@ -27,8 +27,6 @@ func init() { parseCreateEncryptedWalletCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("exportwatchingwallet", parseExportWatchingWalletCmd, nil, `TODO(jrick) fillmein`) - btcjson.RegisterCustomCmd("getaddressbalance", - parseGetAddressBalanceCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd, parseGetBestBlockCmdReply, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("getcurrentnet", parseGetCurrentNetCmd, nil, @@ -1481,114 +1479,3 @@ func (cmd *ListAllTransactionsCmd) UnmarshalJSON(b []byte) error { *cmd = *concreteCmd return nil } - -// GetAddressBalanceCmd is a type handling custom marshaling -// and unmarshaling of getaddressbalance JSON websocket extension -// commands. -type GetAddressBalanceCmd struct { - id interface{} - Address string - Minconf int -} - -// Enforce that GetAddressBalanceCmd satisifies the btcjson.Cmd -// interface. -var _ btcjson.Cmd = &GetAddressBalanceCmd{} - -// parseGetAddressBalanceCmd parses a GetAddressBalanceCmd into a concrete -// type satisifying the btcjson.Cmd interface. This is used when -// registering the custom command with the btcjson parser. -func parseGetAddressBalanceCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { - // Length of param slice must be minimum 1 (one required parameter) - // and maximum 2 (1 optional parameter). - if len(r.Params) < 1 || len(r.Params) > 2 { - return nil, btcjson.ErrInvalidParams - } - - var address string - if err := json.Unmarshal(r.Params[0], &address); err != nil { - return nil, errors.New("first parameter 'address' must be a " + - " string: " + err.Error()) - } - - optArgs := make([]int, 0, 1) - if len(r.Params) > 1 { - var minConf int - if err := json.Unmarshal(r.Params[1], &minConf); err != nil { - return nil, errors.New("second optional parameter " + - " 'minconf' must be an integer: " + err.Error()) - } - optArgs = append(optArgs, minConf) - } - - return NewGetAddressBalanceCmd(r.Id, address, optArgs...) -} - -// NewGetAddressBalanceCmd creates a new GetAddressBalanceCmd. -func NewGetAddressBalanceCmd(id interface{}, address string, - optArgs ...int) (*GetAddressBalanceCmd, error) { - - // Optional arguments set to their default values. - minconf := 1 - - if len(optArgs) > 1 { - return nil, btcjson.ErrInvalidParams - } - - if len(optArgs) == 1 { - minconf = optArgs[0] - } - - return &GetAddressBalanceCmd{ - id: id, - Address: address, - Minconf: minconf, - }, nil -} - -// Id satisifies the Cmd interface by returning the ID of the command. -func (cmd *GetAddressBalanceCmd) Id() interface{} { - return cmd.id -} - -// Method satisfies the Cmd interface by returning the RPC method. -func (cmd *GetAddressBalanceCmd) Method() string { - return "getaddressbalance" -} - -// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. -func (cmd *GetAddressBalanceCmd) MarshalJSON() ([]byte, error) { - params := make([]interface{}, 1, 2) - params[0] = cmd.Address - if cmd.Minconf != 1 { - params = append(params, cmd.Minconf) - } - - raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) - if err != nil { - return nil, err - } - return json.Marshal(raw) -} - -// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of -// the Cmd interface. -func (cmd *GetAddressBalanceCmd) UnmarshalJSON(b []byte) error { - // Unmarshal into a RawCmd. - var r btcjson.RawCmd - if err := json.Unmarshal(b, &r); err != nil { - return err - } - - newCmd, err := parseGetAddressBalanceCmd(&r) - if err != nil { - return err - } - - concreteCmd, ok := newCmd.(*GetAddressBalanceCmd) - if !ok { - return btcjson.ErrInternal - } - *cmd = *concreteCmd - return nil -} diff --git a/cmds_test.go b/cmds_test.go index 5c9f8e2b..f02d6a10 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -30,33 +30,6 @@ var cmdtests = []struct { Passphrase: "banana", }, }, - { - name: "getaddressbalance no optargs", - f: func() (btcjson.Cmd, error) { - return NewGetAddressBalanceCmd( - float64(1), - "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH") - }, - result: &GetAddressBalanceCmd{ - id: float64(1), - Address: "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", - Minconf: 1, - }, - }, - { - name: "getaddressbalance one optarg", - f: func() (btcjson.Cmd, error) { - return NewGetAddressBalanceCmd( - float64(1), - "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", - 0) - }, - result: &GetAddressBalanceCmd{ - id: float64(1), - Address: "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", - Minconf: 0, - }, - }, { name: "getbestblock", f: func() (btcjson.Cmd, error) { diff --git a/test_coverage.txt b/test_coverage.txt index 93d43c01..5748bc33 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,176 +1,170 @@ -github.com/conformal/btcws/cmds.go init 100.00% (16/16) +github.com/conformal/btcws/cmds.go init 100.00% (15/15) github.com/conformal/btcws/notifications.go init 100.00% (12/12) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxAcceptedVerboseNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxAcceptedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifyReceivedCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyReceivedCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyReceivedCmd.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRescanFinishedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanFinishedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanFinishedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRescanProgressNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxAcceptedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxAcceptedVerboseNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRescanProgressNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanFinishedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RescanFinishedNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRescanFinishedNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) +github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) +github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 90.00% (9/10) github.com/conformal/btcws/notifications.go RecvTxNtfn.MarshalJSON 87.50% (7/8) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 87.50% (7/8) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.MarshalJSON 87.50% (7/8) github.com/conformal/btcws/notifications.go RedeemingTxNtfn.MarshalJSON 87.50% (7/8) -github.com/conformal/btcws/cmds.go NewNotifyNewTransactionsCmd 85.71% (6/7) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 85.71% (6/7) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 85.71% (6/7) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 87.50% (7/8) github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 85.71% (6/7) -github.com/conformal/btcws/cmds.go NewGetAddressBalanceCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewNotifyNewTransactionsCmd 85.71% (6/7) +github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 85.71% (6/7) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 85.71% (6/7) github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go RescanFinishedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go NotifyReceivedCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) +github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go parseNotifyNewTransactionsCmd 77.78% (7/9) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/notifications.go RescanFinishedNtfn.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 80.00% (4/5) +github.com/conformal/btcws/cmds.go NotifyReceivedCmd.MarshalJSON 80.00% (4/5) github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 77.78% (7/9) +github.com/conformal/btcws/cmds.go parseNotifyNewTransactionsCmd 77.78% (7/9) github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 77.78% (7/9) github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 75.00% (9/12) -github.com/conformal/btcws/cmds.go parseGetAddressBalanceCmd 75.00% (9/12) github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 75.00% (3/4) github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 75.00% (3/4) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 75.00% (3/4) github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetAddressBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RescanFinishedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyReceivedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go NotifyReceivedCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RescanFinishedNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go RescanProgressNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.UnmarshalJSON 72.73% (8/11) +github.com/conformal/btcws/notifications.go TxAcceptedNtfn.UnmarshalJSON 72.73% (8/11) github.com/conformal/btcws/cmds.go parseRescanCmd 72.22% (13/18) github.com/conformal/btcws/notifications.go parseRecvTxNtfn 66.67% (8/12) github.com/conformal/btcws/notifications.go parseRedeemingTxNtfn 66.67% (8/12) -github.com/conformal/btcws/cmds.go parseNotifyReceivedCmd 66.67% (4/6) -github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 66.67% (4/6) github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (4/6) -github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) +github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 66.67% (4/6) +github.com/conformal/btcws/cmds.go parseNotifyReceivedCmd 66.67% (4/6) github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) +github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) +github.com/conformal/btcws/notifications.go parseRescanProgressNtfn 64.29% (9/14) +github.com/conformal/btcws/notifications.go parseRescanFinishedNtfn 64.29% (9/14) github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) -github.com/conformal/btcws/notifications.go parseTxAcceptedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseRescanProgressNtfn 62.50% (5/8) -github.com/conformal/btcws/notifications.go parseTxAcceptedVerboseNtfn 62.50% (5/8) -github.com/conformal/btcws/notifications.go parseRescanFinishedNtfn 62.50% (5/8) +github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseTxAcceptedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) +github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) +github.com/conformal/btcws/notifications.go parseTxAcceptedVerboseNtfn 62.50% (5/8) github.com/conformal/btcws/cmds.go NewExportWatchingWalletCmd 0.00% (0/15) github.com/conformal/btcws/cmds.go parseExportWatchingWalletCmd 0.00% (0/14) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go AuthenticateCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.MarshalJSON 0.00% (0/9) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.UnmarshalJSON 0.00% (0/11) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.UnmarshalJSON 0.00% (0/11) github.com/conformal/btcws/cmds.go parseRecoverAddressesCmd 0.00% (0/9) github.com/conformal/btcws/cmds.go parseAuthenticateCmd 0.00% (0/9) -github.com/conformal/btcws/cmds.go AuthenticateCmd.MarshalJSON 0.00% (0/5) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.MarshalJSON 0.00% (0/9) github.com/conformal/btcws/cmds.go RecoverAddressesCmd.MarshalJSON 0.00% (0/5) +github.com/conformal/btcws/cmds.go AuthenticateCmd.MarshalJSON 0.00% (0/5) github.com/conformal/btcws/cmds.go parseGetBestBlockCmdReply 0.00% (0/4) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.MarshalJSON 0.00% (0/4) github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmdReply 0.00% (0/4) +github.com/conformal/btcws/cmds.go NotifyBlocksCmd.MarshalJSON 0.00% (0/4) github.com/conformal/btcws/cmds.go parseNotifyBlocksCmd 0.00% (0/3) -github.com/conformal/btcws/cmds.go NewNotifyBlocksCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewAuthenticateCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewOutPointFromWire 0.00% (0/1) -github.com/conformal/btcws/cmds.go AuthenticateCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewRecoverAddressesCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Method 0.00% (0/1) github.com/conformal/btcws/cmds.go AuthenticateCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go AuthenticateCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewNotifyBlocksCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewRecoverAddressesCmd 0.00% (0/1) +github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Id 0.00% (0/1) github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Method 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewOutPointFromWire 0.00% (0/1) github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) +github.com/conformal/btcws/cmds.go NewAuthenticateCmd 0.00% (0/1) github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Id 0.00% (0/1) -github.com/conformal/btcws ---------------------------------------- 65.49% (592/904) +github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) +github.com/conformal/btcws ---------------------------------------- 64.84% (568/876) From 67fc6fa645a3a75b4b127de7976401e34911d99a Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Thu, 11 Dec 2014 10:34:50 -0500 Subject: [PATCH 68/76] Reference new subrepo paths in README. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 77d7ee2f..0ce3e60e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ btcjson (using btcjson.RegisterCustomCmd). ```Go // Client Side import ( - "code.google.com/p/go.net/websocket" + "golang.org/x/net/websocket" "github.com/conformal/btcws" ) @@ -35,7 +35,7 @@ websocket.JSON.Send(btcdWSConn, cmd) // Server Side import ( - "code.google.com/p/go.net/websocket" + "golang.org/x/net/websocket" "github.com/conformal/btcjson" "github.com/conformal/btcws" ) From 47d862e482652f1022cf19fb302839e76ae8cc6d Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Mon, 10 Nov 2014 22:03:58 +0530 Subject: [PATCH 69/76] Added CreateNewAccount, RenameAccount commands --- cmds.go | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++ cmds_test.go | 26 ++++++++ 2 files changed, 209 insertions(+) diff --git a/cmds.go b/cmds.go index 898e5d18..fd10d736 100644 --- a/cmds.go +++ b/cmds.go @@ -18,6 +18,12 @@ const ( Authenticate the websocket with the RPC server. This is only required if the credentials were not already supplied via HTTP auth headers. It must be the first command sent or you will be disconnected.` + + createNewAccountHelp = `createnewaccount "accountname" +Create a new account with the given name.` + + renameAccountHelp = `renameaccount "oldname" "newname" +Rename an account to the given new name.` ) func init() { @@ -25,6 +31,8 @@ func init() { authenticateHelp) btcjson.RegisterCustomCmd("createencryptedwallet", parseCreateEncryptedWalletCmd, nil, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("createnewaccount", + parseCreateNewAccountCmd, nil, createNewAccountHelp) btcjson.RegisterCustomCmd("exportwatchingwallet", parseExportWatchingWalletCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("getbestblock", parseGetBestBlockCmd, @@ -48,6 +56,8 @@ func init() { nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("recoveraddresses", parseRecoverAddressesCmd, nil, `TODO(jrick) fillmein`) + btcjson.RegisterCustomCmd("renameaccount", parseRenameAccountCmd, + nil, renameAccountHelp) btcjson.RegisterCustomCmd("rescan", parseRescanCmd, nil, `TODO(jrick) fillmein`) btcjson.RegisterCustomCmd("walletislocked", parseWalletIsLockedCmd, @@ -609,6 +619,96 @@ func (cmd *RecoverAddressesCmd) UnmarshalJSON(b []byte) error { return nil } +// RenameAccountCmd is a type handling custom marshaling and +// unmarshaling of renameaccount JSON websocket extension +// commands. +type RenameAccountCmd struct { + id interface{} + OldAccount string + NewAccount string +} + +// Enforce that RenameAccountCmd satisifies the btcjson.Cmd interface. +var _ btcjson.Cmd = &RenameAccountCmd{} + +// NewRenameAccountCmd creates a new GetCurrentNetCmd. +func NewRenameAccountCmd(id interface{}, oldaccount, newaccount string) *RenameAccountCmd { + return &RenameAccountCmd{ + id: id, + OldAccount: oldaccount, + NewAccount: newaccount, + } +} + +// parseRenameAccountCmd parses a RawCmd into a concrete type satisifying +// the btcjson.Cmd interface. This is used when registering the custom +// command with the btcjson parser. +func parseRenameAccountCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) != 2 { + return nil, btcjson.ErrWrongNumberOfParams + } + + var oldaccount string + if err := json.Unmarshal(r.Params[0], &oldaccount); err != nil { + return nil, errors.New("first parameter 'oldaccount' must be " + + "a string: " + err.Error()) + } + + var newaccount string + if err := json.Unmarshal(r.Params[1], &newaccount); err != nil { + return nil, errors.New("second parameter 'newaccount' must " + + "be a string: " + err.Error()) + } + + return NewRenameAccountCmd(r.Id, oldaccount, newaccount), nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *RenameAccountCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *RenameAccountCmd) Method() string { + return "renameaccount" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *RenameAccountCmd) MarshalJSON() ([]byte, error) { + params := []interface{}{ + cmd.OldAccount, + cmd.NewAccount, + } + + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *RenameAccountCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseRenameAccountCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*RenameAccountCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + // OutPoint describes a transaction outpoint that will be marshalled to and // from JSON. type OutPoint struct { @@ -1163,6 +1263,89 @@ func (cmd *CreateEncryptedWalletCmd) UnmarshalJSON(b []byte) error { return nil } +// CreateNewAccountCmd is a type handling custom +// marshaling and unmarshaling of createnewaccount +// JSON websocket extension commands. +type CreateNewAccountCmd struct { + id interface{} + Account string +} + +// Enforce that CreateNewAccountCmd satisifies the btcjson.Cmd +// interface. +var _ btcjson.Cmd = &CreateNewAccountCmd{} + +// NewCreateNewAccountCmd creates a new CreateNewAccountCmd. +func NewCreateNewAccountCmd(id interface{}, account string) *CreateNewAccountCmd { + return &CreateNewAccountCmd{ + id: id, + Account: account, + } +} + +// parseCreateNewAccountCmd parses a CreateNewAccountCmd +// into a concrete type satisifying the btcjson.Cmd interface. +// This is used when registering the custom command with the btcjson +// parser. +func parseCreateNewAccountCmd(r *btcjson.RawCmd) (btcjson.Cmd, error) { + if len(r.Params) != 1 { + return nil, btcjson.ErrWrongNumberOfParams + } + + var account string + if err := json.Unmarshal(r.Params[0], &account); err != nil { + return nil, errors.New("first parameter 'account' must be " + + "a string: " + err.Error()) + } + + return NewCreateNewAccountCmd(r.Id, account), nil +} + +// Id satisifies the Cmd interface by returning the ID of the command. +func (cmd *CreateNewAccountCmd) Id() interface{} { + return cmd.id +} + +// Method satisfies the Cmd interface by returning the RPC method. +func (cmd *CreateNewAccountCmd) Method() string { + return "createnewaccount" +} + +// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. +func (cmd *CreateNewAccountCmd) MarshalJSON() ([]byte, error) { + params := []interface{}{ + cmd.Account, + } + + raw, err := btcjson.NewRawCmd(cmd.id, cmd.Method(), params) + if err != nil { + return nil, err + } + return json.Marshal(raw) +} + +// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of +// the Cmd interface. +func (cmd *CreateNewAccountCmd) UnmarshalJSON(b []byte) error { + // Unmarshal into a RawCmd. + var r btcjson.RawCmd + if err := json.Unmarshal(b, &r); err != nil { + return err + } + + newCmd, err := parseCreateNewAccountCmd(&r) + if err != nil { + return err + } + + concreteCmd, ok := newCmd.(*CreateNewAccountCmd) + if !ok { + return btcjson.ErrInternal + } + *cmd = *concreteCmd + return nil +} + // WalletIsLockedCmd is a type handling custom marshaling and // unmarshaling of walletislocked JSON websocket extension commands. type WalletIsLockedCmd struct { diff --git a/cmds_test.go b/cmds_test.go index f02d6a10..29c9b72a 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -30,6 +30,18 @@ var cmdtests = []struct { Passphrase: "banana", }, }, + { + name: "createnewaccount", + f: func() (btcjson.Cmd, error) { + return NewCreateNewAccountCmd( + float64(1), + "account"), nil + }, + result: &CreateNewAccountCmd{ + id: float64(1), + Account: "account", + }, + }, { name: "getbestblock", f: func() (btcjson.Cmd, error) { @@ -182,6 +194,20 @@ var cmdtests = []struct { }, }, }, + { + name: "renameaccount", + f: func() (btcjson.Cmd, error) { + return NewRenameAccountCmd( + float64(1), + "old", + "new"), nil + }, + result: &RenameAccountCmd{ + id: float64(1), + OldAccount: "old", + NewAccount: "new", + }, + }, { name: "rescan no optargs", f: func() (btcjson.Cmd, error) { From 32205c5552d5781a932eceab01eedb0b3ceb233d Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Thu, 20 Nov 2014 11:03:56 +0530 Subject: [PATCH 70/76] ListAllTransactions - allow nil for account name --- cmds.go | 10 ++++++---- cmds_test.go | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/cmds.go b/cmds.go index fd10d736..cc3f33a1 100644 --- a/cmds.go +++ b/cmds.go @@ -1568,7 +1568,7 @@ func (cmd *ListAddressTransactionsCmd) UnmarshalJSON(b []byte) error { // unmarshaling of listalltransactions JSON websocket extension commands. type ListAllTransactionsCmd struct { id interface{} - Account string + Account *string } // Enforce that ListAllTransactionsCmd satisifies the btcjson.Cmd @@ -1580,14 +1580,16 @@ func NewListAllTransactionsCmd(id interface{}, optArgs ...string) (*ListAllTransactionsCmd, error) { // Optional arguments set to their default values. - account := "" + var account *string if len(optArgs) > 1 { return nil, btcjson.ErrInvalidParams + } else { + account = nil } if len(optArgs) == 1 { - account = optArgs[0] + account = &optArgs[0] } return &ListAllTransactionsCmd{ @@ -1630,7 +1632,7 @@ func (cmd *ListAllTransactionsCmd) Method() string { // MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface. func (cmd *ListAllTransactionsCmd) MarshalJSON() ([]byte, error) { params := make([]interface{}, 0, 1) - if cmd.Account != "" { + if cmd.Account != nil { params = append(params, cmd.Account) } diff --git a/cmds_test.go b/cmds_test.go index 29c9b72a..91950f61 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -13,6 +13,8 @@ import ( "github.com/davecgh/go-spew/spew" ) +var testAccount = "account" + var cmdtests = []struct { name string f func() (btcjson.Cmd, error) @@ -74,11 +76,11 @@ var cmdtests = []struct { name: "getunconfirmedbalance one optarg", f: func() (btcjson.Cmd, error) { return NewGetUnconfirmedBalanceCmd(float64(1), - "abcde") + testAccount) }, result: &GetUnconfirmedBalanceCmd{ id: float64(1), - Account: "abcde", + Account: testAccount, }, }, { @@ -108,11 +110,11 @@ var cmdtests = []struct { return NewListAddressTransactionsCmd( float64(1), addrs, - "abcde") + testAccount) }, result: &ListAddressTransactionsCmd{ id: float64(1), - Account: "abcde", + Account: testAccount, Addresses: []string{ "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH", }, @@ -125,7 +127,7 @@ var cmdtests = []struct { }, result: &ListAllTransactionsCmd{ id: float64(1), - Account: "", + Account: nil, }, }, { @@ -133,11 +135,11 @@ var cmdtests = []struct { f: func() (btcjson.Cmd, error) { return NewListAllTransactionsCmd( float64(1), - "abcde") + testAccount) }, result: &ListAllTransactionsCmd{ id: float64(1), - Account: "abcde", + Account: &testAccount, }, }, { @@ -290,11 +292,11 @@ var cmdtests = []struct { f: func() (btcjson.Cmd, error) { return NewWalletIsLockedCmd( float64(1), - "abcde") + testAccount) }, result: &WalletIsLockedCmd{ id: float64(1), - Account: "abcde", + Account: testAccount, }, }, } From 923ca529bd117ac407803ea9b7e1e8ca27fad253 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 16 Jan 2015 15:11:02 -0600 Subject: [PATCH 71/76] Update btcwire import paths to new location. --- cmds.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds.go b/cmds.go index cc3f33a1..bcfd9d1a 100644 --- a/cmds.go +++ b/cmds.go @@ -8,8 +8,8 @@ import ( "encoding/json" "errors" + "github.com/btcsuite/btcwire" "github.com/conformal/btcjson" - "github.com/conformal/btcwire" ) // Help texts From 0ff8ea38484570177b9775e803d567d9f4296ff9 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 16 Jan 2015 23:35:26 -0600 Subject: [PATCH 72/76] Update btcws import paths to new location. --- README.md | 10 +++++----- notifications_test.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0ce3e60e..c2646f82 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ btcws ===== -[![Build Status](https://travis-ci.org/conformal/btcws.png?branch=master)] -(https://travis-ci.org/conformal/btcws) +[![Build Status](https://travis-ci.org/btcsuite/btcws.png?branch=master)] +(https://travis-ci.org/btcsuite/btcws) Package btcws implements extensions to the standard bitcoind JSON-RPC API for the btcd suite of programs (btcd, btcwallet, and btcgui). @@ -14,7 +14,7 @@ btcjson (using btcjson.RegisterCustomCmd). // Client Side import ( "golang.org/x/net/websocket" - "github.com/conformal/btcws" + "github.com/btcsuite/btcws" ) // Create rescan command. @@ -37,7 +37,7 @@ websocket.JSON.Send(btcdWSConn, cmd) import ( "golang.org/x/net/websocket" "github.com/conformal/btcjson" - "github.com/conformal/btcws" + "github.com/btcsuite/btcws" ) // Get marshaled request. @@ -60,7 +60,7 @@ if ok { ## Installation ```bash -$ go get github.com/conformal/btcws +$ go get github.com/btcsuite/btcws ``` ## GPG Verification Key diff --git a/notifications_test.go b/notifications_test.go index f473b4e9..a2d37436 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -8,8 +8,8 @@ import ( "reflect" "testing" + "github.com/btcsuite/btcws" "github.com/conformal/btcjson" - "github.com/conformal/btcws" "github.com/davecgh/go-spew/spew" ) From 80aaecd8a2e0f63388d1dc9b1b6b72bc6e24ac2f Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 16 Jan 2015 23:54:00 -0600 Subject: [PATCH 73/76] Update btcjson import paths to new location. --- README.md | 2 +- cmds.go | 2 +- cmds_test.go | 2 +- notifications.go | 2 +- notifications_test.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c2646f82..c537d113 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ websocket.JSON.Send(btcdWSConn, cmd) // Server Side import ( "golang.org/x/net/websocket" - "github.com/conformal/btcjson" + "github.com/btcsuite/btcjson" "github.com/btcsuite/btcws" ) diff --git a/cmds.go b/cmds.go index bcfd9d1a..581673fb 100644 --- a/cmds.go +++ b/cmds.go @@ -8,8 +8,8 @@ import ( "encoding/json" "errors" + "github.com/btcsuite/btcjson" "github.com/btcsuite/btcwire" - "github.com/conformal/btcjson" ) // Help texts diff --git a/cmds_test.go b/cmds_test.go index 91950f61..ff0ed517 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -9,7 +9,7 @@ import ( "reflect" "testing" - "github.com/conformal/btcjson" + "github.com/btcsuite/btcjson" "github.com/davecgh/go-spew/spew" ) diff --git a/notifications.go b/notifications.go index 708aeb85..093f5c6a 100644 --- a/notifications.go +++ b/notifications.go @@ -8,7 +8,7 @@ import ( "encoding/json" "errors" - "github.com/conformal/btcjson" + "github.com/btcsuite/btcjson" ) var ( diff --git a/notifications_test.go b/notifications_test.go index a2d37436..0e13dda0 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -8,8 +8,8 @@ import ( "reflect" "testing" + "github.com/btcsuite/btcjson" "github.com/btcsuite/btcws" - "github.com/conformal/btcjson" "github.com/davecgh/go-spew/spew" ) From d68ac86944ffb9323d49d4814eac57164c043c97 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 5 Feb 2015 15:02:20 -0600 Subject: [PATCH 74/76] Update btcwire path import paths to new location. --- cmds.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmds.go b/cmds.go index 581673fb..340bd25c 100644 --- a/cmds.go +++ b/cmds.go @@ -8,8 +8,8 @@ import ( "encoding/json" "errors" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcjson" - "github.com/btcsuite/btcwire" ) // Help texts @@ -717,8 +717,8 @@ type OutPoint struct { } // NewOutPointFromWire creates a new OutPoint from the OutPoint structure -// of the btcwire package. -func NewOutPointFromWire(op *btcwire.OutPoint) *OutPoint { +// of the wire package. +func NewOutPointFromWire(op *wire.OutPoint) *OutPoint { return &OutPoint{ Hash: op.Hash.String(), Index: op.Index, From b8f3da692e464dc815904a9dcdb351559e800671 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 19 Feb 2015 11:54:02 -0600 Subject: [PATCH 75/76] Update btcjson path import paths to new location. --- README.md | 2 +- cmds.go | 2 +- cmds_test.go | 2 +- notifications.go | 2 +- notifications_test.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c537d113..230b6dc2 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ websocket.JSON.Send(btcdWSConn, cmd) // Server Side import ( "golang.org/x/net/websocket" - "github.com/btcsuite/btcjson" + "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcws" ) diff --git a/cmds.go b/cmds.go index 340bd25c..faa15c9c 100644 --- a/cmds.go +++ b/cmds.go @@ -8,8 +8,8 @@ import ( "encoding/json" "errors" + "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcjson" ) // Help texts diff --git a/cmds_test.go b/cmds_test.go index ff0ed517..f6c8f173 100644 --- a/cmds_test.go +++ b/cmds_test.go @@ -9,7 +9,7 @@ import ( "reflect" "testing" - "github.com/btcsuite/btcjson" + "github.com/btcsuite/btcd/btcjson" "github.com/davecgh/go-spew/spew" ) diff --git a/notifications.go b/notifications.go index 093f5c6a..d06d5410 100644 --- a/notifications.go +++ b/notifications.go @@ -8,7 +8,7 @@ import ( "encoding/json" "errors" - "github.com/btcsuite/btcjson" + "github.com/btcsuite/btcd/btcjson" ) var ( diff --git a/notifications_test.go b/notifications_test.go index 0e13dda0..a63c458d 100644 --- a/notifications_test.go +++ b/notifications_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - "github.com/btcsuite/btcjson" + "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcws" "github.com/davecgh/go-spew/spew" ) From 3e800e154cf27c0dbaafcde1ef440c50d82160c0 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 19 Feb 2015 12:50:19 -0600 Subject: [PATCH 76/76] Import btcws repo into btcjson/btcws directory. --- .travis.yml | 3 - LICENSE | 13 -- README.md => btcjson/btcws/README.md | 8 +- cmds.go => btcjson/btcws/cmds.go | 2 - cmds_test.go => btcjson/btcws/cmds_test.go | 0 .../btcws/notifications.go | 0 .../btcws/notifications_test.go | 2 +- test_coverage.txt | 170 ------------------ 8 files changed, 5 insertions(+), 193 deletions(-) delete mode 100644 .travis.yml delete mode 100644 LICENSE rename README.md => btcjson/btcws/README.md (90%) rename cmds.go => btcjson/btcws/cmds.go (99%) rename cmds_test.go => btcjson/btcws/cmds_test.go (100%) rename notifications.go => btcjson/btcws/notifications.go (100%) rename notifications_test.go => btcjson/btcws/notifications_test.go (99%) delete mode 100644 test_coverage.txt diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ae71c02f..00000000 --- a/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: release -install: go get -d -t -v ./... diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 62a53cea..00000000 --- a/LICENSE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright (c) 2013 Conformal Systems LLC. - -Permission to use, copy, modify, and distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/btcjson/btcws/README.md similarity index 90% rename from README.md rename to btcjson/btcws/README.md index 230b6dc2..cd1bb925 100644 --- a/README.md +++ b/btcjson/btcws/README.md @@ -1,7 +1,7 @@ btcws ===== -[![Build Status](https://travis-ci.org/btcsuite/btcws.png?branch=master)] +[![Build Status](https://travis-ci.org/btcsuite/btcd.png?branch=master)] (https://travis-ci.org/btcsuite/btcws) Package btcws implements extensions to the standard bitcoind JSON-RPC @@ -14,7 +14,7 @@ btcjson (using btcjson.RegisterCustomCmd). // Client Side import ( "golang.org/x/net/websocket" - "github.com/btcsuite/btcws" + "github.com/btcsuite/btcd/btcjson/btcws" ) // Create rescan command. @@ -37,7 +37,7 @@ websocket.JSON.Send(btcdWSConn, cmd) import ( "golang.org/x/net/websocket" "github.com/btcsuite/btcd/btcjson" - "github.com/btcsuite/btcws" + "github.com/btcsuite/btcd/btcjson/btcws" ) // Get marshaled request. @@ -60,7 +60,7 @@ if ok { ## Installation ```bash -$ go get github.com/btcsuite/btcws +$ go get github.com/btcsuite/btcd/btcjson/btcws ``` ## GPG Verification Key diff --git a/cmds.go b/btcjson/btcws/cmds.go similarity index 99% rename from cmds.go rename to btcjson/btcws/cmds.go index faa15c9c..e79df6f3 100644 --- a/cmds.go +++ b/btcjson/btcws/cmds.go @@ -1584,8 +1584,6 @@ func NewListAllTransactionsCmd(id interface{}, if len(optArgs) > 1 { return nil, btcjson.ErrInvalidParams - } else { - account = nil } if len(optArgs) == 1 { diff --git a/cmds_test.go b/btcjson/btcws/cmds_test.go similarity index 100% rename from cmds_test.go rename to btcjson/btcws/cmds_test.go diff --git a/notifications.go b/btcjson/btcws/notifications.go similarity index 100% rename from notifications.go rename to btcjson/btcws/notifications.go diff --git a/notifications_test.go b/btcjson/btcws/notifications_test.go similarity index 99% rename from notifications_test.go rename to btcjson/btcws/notifications_test.go index a63c458d..1df4e2d6 100644 --- a/notifications_test.go +++ b/btcjson/btcws/notifications_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/btcsuite/btcd/btcjson" - "github.com/btcsuite/btcws" + "github.com/btcsuite/btcd/btcjson/btcws" "github.com/davecgh/go-spew/spew" ) diff --git a/test_coverage.txt b/test_coverage.txt deleted file mode 100644 index 5748bc33..00000000 --- a/test_coverage.txt +++ /dev/null @@ -1,170 +0,0 @@ - -github.com/conformal/btcws/cmds.go init 100.00% (15/15) -github.com/conformal/btcws/notifications.go init 100.00% (12/12) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxAcceptedVerboseNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetCurrentNetCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxAcceptedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewAccountBalanceNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifyReceivedCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBtcdConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyReceivedCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyReceivedCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewNotifySpentCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NotifySpentCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockDisconnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewBlockConnectedNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewCreateEncryptedWalletCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewWalletLockStateNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go TxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewTxNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go NewGetBestBlockCmd 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRescanProgressNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanFinishedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RescanFinishedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRescanFinishedNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRedeemingTxNtfn 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go RecvTxNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/notifications.go NewRecvTxNtfn 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Method 100.00% (1/1) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.Id 100.00% (1/1) -github.com/conformal/btcws/cmds.go RescanCmd.MarshalJSON 90.00% (9/10) -github.com/conformal/btcws/notifications.go RecvTxNtfn.MarshalJSON 87.50% (7/8) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.MarshalJSON 87.50% (7/8) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.MarshalJSON 87.50% (7/8) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.MarshalJSON 85.71% (6/7) -github.com/conformal/btcws/cmds.go NewNotifyNewTransactionsCmd 85.71% (6/7) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.MarshalJSON 85.71% (6/7) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.MarshalJSON 85.71% (6/7) -github.com/conformal/btcws/cmds.go NewGetUnconfirmedBalanceCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAllTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewListAddressTransactionsCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewRescanCmd 83.33% (5/6) -github.com/conformal/btcws/cmds.go NewWalletIsLockedCmd 83.33% (5/6) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go TxNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/notifications.go RescanFinishedNtfn.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go NotifySpentCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go NotifyReceivedCmd.MarshalJSON 80.00% (4/5) -github.com/conformal/btcws/cmds.go parseGetUnconfirmedBalanceCmd 77.78% (7/9) -github.com/conformal/btcws/cmds.go parseNotifyNewTransactionsCmd 77.78% (7/9) -github.com/conformal/btcws/cmds.go parseListAllTransactionsCmd 77.78% (7/9) -github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmd 75.00% (9/12) -github.com/conformal/btcws/cmds.go parseWalletIsLockedCmd 75.00% (6/8) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.MarshalJSON 75.00% (3/4) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.MarshalJSON 75.00% (3/4) -github.com/conformal/btcws/notifications.go TxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAddressTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go WalletIsLockedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go AccountBalanceNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go CreateEncryptedWalletCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifySpentCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyNewTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go NotifyReceivedCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BlockDisconnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go BtcdConnectedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go RescanCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RecvTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RedeemingTxNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go ListAllTransactionsCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RescanFinishedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetBestBlockCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go RescanProgressNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetUnconfirmedBalanceCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go GetCurrentNetCmd.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go WalletLockStateNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxAcceptedVerboseNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/notifications.go TxAcceptedNtfn.UnmarshalJSON 72.73% (8/11) -github.com/conformal/btcws/cmds.go parseRescanCmd 72.22% (13/18) -github.com/conformal/btcws/notifications.go parseRecvTxNtfn 66.67% (8/12) -github.com/conformal/btcws/notifications.go parseRedeemingTxNtfn 66.67% (8/12) -github.com/conformal/btcws/cmds.go parseNotifySpentCmd 66.67% (4/6) -github.com/conformal/btcws/cmds.go parseCreateEncryptedWalletCmd 66.67% (4/6) -github.com/conformal/btcws/cmds.go parseNotifyReceivedCmd 66.67% (4/6) -github.com/conformal/btcws/cmds.go parseGetCurrentNetCmd 66.67% (2/3) -github.com/conformal/btcws/cmds.go parseGetBestBlockCmd 66.67% (2/3) -github.com/conformal/btcws/notifications.go parseRescanProgressNtfn 64.29% (9/14) -github.com/conformal/btcws/notifications.go parseRescanFinishedNtfn 64.29% (9/14) -github.com/conformal/btcws/notifications.go parseAccountBalanceNtfn 64.29% (9/14) -github.com/conformal/btcws/notifications.go parseBlockDisconnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseWalletLockStateNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseTxAcceptedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseBlockConnectedNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseTxNtfn 63.64% (7/11) -github.com/conformal/btcws/notifications.go parseBtcdConnectedNtfn 62.50% (5/8) -github.com/conformal/btcws/notifications.go parseTxAcceptedVerboseNtfn 62.50% (5/8) -github.com/conformal/btcws/cmds.go NewExportWatchingWalletCmd 0.00% (0/15) -github.com/conformal/btcws/cmds.go parseExportWatchingWalletCmd 0.00% (0/14) -github.com/conformal/btcws/cmds.go AuthenticateCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.UnmarshalJSON 0.00% (0/11) -github.com/conformal/btcws/cmds.go parseRecoverAddressesCmd 0.00% (0/9) -github.com/conformal/btcws/cmds.go parseAuthenticateCmd 0.00% (0/9) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.MarshalJSON 0.00% (0/9) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.MarshalJSON 0.00% (0/5) -github.com/conformal/btcws/cmds.go AuthenticateCmd.MarshalJSON 0.00% (0/5) -github.com/conformal/btcws/cmds.go parseGetBestBlockCmdReply 0.00% (0/4) -github.com/conformal/btcws/cmds.go parseListAddressTransactionsCmdReply 0.00% (0/4) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.MarshalJSON 0.00% (0/4) -github.com/conformal/btcws/cmds.go parseNotifyBlocksCmd 0.00% (0/3) -github.com/conformal/btcws/cmds.go AuthenticateCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go AuthenticateCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewNotifyBlocksCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewRecoverAddressesCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go RecoverAddressesCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Method 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewOutPointFromWire 0.00% (0/1) -github.com/conformal/btcws/cmds.go NotifyBlocksCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go NewAuthenticateCmd 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Id 0.00% (0/1) -github.com/conformal/btcws/cmds.go ExportWatchingWalletCmd.Method 0.00% (0/1) -github.com/conformal/btcws ---------------------------------------- 64.84% (568/876) -