dcrjson: Move new tickets ntfn to correct file.

This moves the definition and associated code for the newtickets
notification to the chainsvrwsntfns.go file since it is served by the
chain RPC websocket server.  It also moves the associated test to the
chainsvrwsntfns_test.go file
This commit is contained in:
Dave Collins 2019-02-13 16:58:56 -06:00
parent 0103753174
commit 3ce1ee9652
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2
4 changed files with 39 additions and 40 deletions

View File

@ -17,6 +17,9 @@ const (
// the chain server that a block has been disconnected.
BlockDisconnectedNtfnMethod = "blockdisconnected"
// NewTicketsNtfnMethod is the method of the daemon newtickets notification.
NewTicketsNtfnMethod = "newtickets"
// ReorganizationNtfnMethod is the method used for notifications that the
// block chain is in the process of a reorganization.
ReorganizationNtfnMethod = "reorganization"
@ -77,6 +80,25 @@ func NewBlockDisconnectedNtfn(header string) *BlockDisconnectedNtfn {
}
}
// NewTicketsNtfn is a type handling custom marshaling and
// unmarshaling of newtickets JSON websocket notifications.
type NewTicketsNtfn struct {
Hash string
Height int32
StakeDiff int64
Tickets []string
}
// NewNewTicketsNtfn creates a new NewTicketsNtfn.
func NewNewTicketsNtfn(hash string, height int32, stakeDiff int64, tickets []string) *NewTicketsNtfn {
return &NewTicketsNtfn{
Hash: hash,
Height: height,
StakeDiff: stakeDiff,
Tickets: tickets,
}
}
// ReorganizationNtfn defines the reorganization JSON-RPC notification.
type ReorganizationNtfn struct {
OldHash string `json:"oldhash"`
@ -197,6 +219,7 @@ func init() {
MustRegisterCmd(BlockConnectedNtfnMethod, (*BlockConnectedNtfn)(nil), flags)
MustRegisterCmd(BlockDisconnectedNtfnMethod, (*BlockDisconnectedNtfn)(nil), flags)
MustRegisterCmd(NewTicketsNtfnMethod, (*NewTicketsNtfn)(nil), flags)
MustRegisterCmd(ReorganizationNtfnMethod, (*ReorganizationNtfn)(nil), flags)
MustRegisterCmd(TxAcceptedNtfnMethod, (*TxAcceptedNtfn)(nil), flags)
MustRegisterCmd(TxAcceptedVerboseNtfnMethod, (*TxAcceptedVerboseNtfn)(nil), flags)

View File

@ -54,6 +54,22 @@ func TestChainSvrWsNtfns(t *testing.T) {
Header: "header",
},
},
{
name: "newtickets",
newNtfn: func() (interface{}, error) {
return NewCmd("newtickets", "123", 100, 3, []string{"a", "b"})
},
staticNtfn: func() interface{} {
return NewNewTicketsNtfn("123", 100, 3, []string{"a", "b"})
},
marshalled: `{"jsonrpc":"1.0","method":"newtickets","params":["123",100,3,["a","b"]],"id":null}`,
unmarshalled: &NewTicketsNtfn{
Hash: "123",
Height: 100,
StakeDiff: 3,
Tickets: []string{"a", "b"},
},
},
{
name: "relevanttxaccepted",
newNtfn: func() (interface{}, error) {

View File

@ -17,10 +17,6 @@ const (
// a wallet server is connected to a chain server.
DcrdConnectedNtfnMethod = "dcrdconnected"
// NewTicketsNtfnMethod is the method of the daemon
// newtickets notification.
NewTicketsNtfnMethod = "newtickets"
// NewTxNtfnMethod is the method used to notify that a wallet server has
// added a new transaction to the transaction store.
NewTxNtfnMethod = "newtx"
@ -72,25 +68,6 @@ func NewDcrdConnectedNtfn(connected bool) *DcrdConnectedNtfn {
}
}
// NewTicketsNtfn is a type handling custom marshaling and
// unmarshaling of newtickets JSON websocket notifications.
type NewTicketsNtfn struct {
Hash string
Height int32
StakeDiff int64
Tickets []string
}
// NewNewTicketsNtfn creates a new NewTicketsNtfn.
func NewNewTicketsNtfn(hash string, height int32, stakeDiff int64, tickets []string) *NewTicketsNtfn {
return &NewTicketsNtfn{
Hash: hash,
Height: height,
StakeDiff: stakeDiff,
Tickets: tickets,
}
}
// NewTxNtfn defines the newtx JSON-RPC notification.
type NewTxNtfn struct {
Account string
@ -177,7 +154,6 @@ func init() {
MustRegisterCmd(AccountBalanceNtfnMethod, (*AccountBalanceNtfn)(nil), flags)
MustRegisterCmd(DcrdConnectedNtfnMethod, (*DcrdConnectedNtfn)(nil), flags)
MustRegisterCmd(NewTicketsNtfnMethod, (*NewTicketsNtfn)(nil), flags)
MustRegisterCmd(NewTxNtfnMethod, (*NewTxNtfn)(nil), flags)
MustRegisterCmd(TicketPurchasedNtfnMethod, (*TicketPurchasedNtfn)(nil), flags)
MustRegisterCmd(RevocationCreatedNtfnMethod, (*RevocationCreatedNtfn)(nil), flags)

View File

@ -55,22 +55,6 @@ func TestWalletSvrWsNtfns(t *testing.T) {
Connected: true,
},
},
{
name: "newtickets",
newNtfn: func() (interface{}, error) {
return NewCmd("newtickets", "123", 100, 3, []string{"a", "b"})
},
staticNtfn: func() interface{} {
return NewNewTicketsNtfn("123", 100, 3, []string{"a", "b"})
},
marshalled: `{"jsonrpc":"1.0","method":"newtickets","params":["123",100,3,["a","b"]],"id":null}`,
unmarshalled: &NewTicketsNtfn{
Hash: "123",
Height: 100,
StakeDiff: 3,
Tickets: []string{"a", "b"},
},
},
{
name: "newtx",
newNtfn: func() (interface{}, error) {