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.
This commit is contained in:
Dave Collins 2014-04-15 00:02:44 -05:00
parent f389d39c43
commit ce48290169
4 changed files with 78 additions and 78 deletions

50
cmds.go
View file

@ -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
}

View file

@ -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,
},

View file

@ -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
}

View file

@ -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",