dcrjson: Move winning tickets ntfn to correct file.

This moves the definition and associated code for the winningtickets
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 accordingly.
This commit is contained in:
Dave Collins 2019-02-13 16:06:31 -06:00
parent bffca0f0cc
commit d0d265cc42
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2
4 changed files with 39 additions and 39 deletions

View File

@ -1,5 +1,5 @@
// Copyright (c) 2014 The btcsuite developers
// Copyright (c) 2015-2016 The Decred developers
// Copyright (c) 2015-2019 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
@ -35,6 +35,10 @@ const (
// from the chain server that inform a client that a relevant
// transaction was accepted by the mempool.
RelevantTxAcceptedNtfnMethod = "relevanttxaccepted"
// WinningTicketsNtfnMethod is the method of the daemon winningtickets
// notification.
WinningTicketsNtfnMethod = "winningtickets"
)
// BlockConnectedNtfn defines the blockconnected JSON-RPC notification.
@ -125,6 +129,23 @@ func NewRelevantTxAcceptedNtfn(txHex string) *RelevantTxAcceptedNtfn {
return &RelevantTxAcceptedNtfn{Transaction: txHex}
}
// WinningTicketsNtfn is a type handling custom marshaling and
// unmarshaling of blockconnected JSON websocket notifications.
type WinningTicketsNtfn struct {
BlockHash string
BlockHeight int32
Tickets map[string]string
}
// NewWinningTicketsNtfn creates a new WinningTicketsNtfn.
func NewWinningTicketsNtfn(hash string, height int32, tickets map[string]string) *WinningTicketsNtfn {
return &WinningTicketsNtfn{
BlockHash: hash,
BlockHeight: height,
Tickets: tickets,
}
}
func init() {
// The commands in this file are only usable by websockets and are
// notifications.
@ -136,4 +157,5 @@ func init() {
MustRegisterCmd(TxAcceptedNtfnMethod, (*TxAcceptedNtfn)(nil), flags)
MustRegisterCmd(TxAcceptedVerboseNtfnMethod, (*TxAcceptedVerboseNtfn)(nil), flags)
MustRegisterCmd(RelevantTxAcceptedNtfnMethod, (*RelevantTxAcceptedNtfn)(nil), flags)
MustRegisterCmd(WinningTicketsNtfnMethod, (*WinningTicketsNtfn)(nil), flags)
}

View File

@ -1,5 +1,5 @@
// Copyright (c) 2014 The btcsuite developers
// Copyright (c) 2015-2016 The Decred developers
// Copyright (c) 2015-2019 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
@ -111,6 +111,21 @@ func TestChainSvrWsNtfns(t *testing.T) {
},
},
},
{
name: "winningtickets",
newNtfn: func() (interface{}, error) {
return NewCmd("winningtickets", "123", 100, map[string]string{"a": "b"})
},
staticNtfn: func() interface{} {
return NewWinningTicketsNtfn("123", 100, map[string]string{"a": "b"})
},
marshalled: `{"jsonrpc":"1.0","method":"winningtickets","params":["123",100,{"a":"b"}],"id":null}`,
unmarshalled: &WinningTicketsNtfn{
BlockHash: "123",
BlockHeight: 100,
Tickets: map[string]string{"a": "b"},
},
},
}
t.Logf("Running %d tests", len(tests))

View File

@ -45,10 +45,6 @@ const (
// votecreated notification.
VoteCreatedNtfnMethod = "votecreated"
// WinningTicketsNtfnMethod is the method of the daemon
// winningtickets notification.
WinningTicketsNtfnMethod = "winningtickets"
// WalletLockStateNtfnMethod is the method used to notify the lock state
// of a wallet has changed.
WalletLockStateNtfnMethod = "walletlockstate"
@ -218,23 +214,6 @@ func NewWalletLockStateNtfn(locked bool) *WalletLockStateNtfn {
}
}
// WinningTicketsNtfn is a type handling custom marshaling and
// unmarshaling of blockconnected JSON websocket notifications.
type WinningTicketsNtfn struct {
BlockHash string
BlockHeight int32
Tickets map[string]string
}
// NewWinningTicketsNtfn creates a new WinningTicketsNtfn.
func NewWinningTicketsNtfn(hash string, height int32, tickets map[string]string) *WinningTicketsNtfn {
return &WinningTicketsNtfn{
BlockHash: hash,
BlockHeight: height,
Tickets: tickets,
}
}
func init() {
// The commands in this file are only usable with a wallet server via
// websockets and are notifications.
@ -250,5 +229,4 @@ func init() {
MustRegisterCmd(StakeDifficultyNtfnMethod, (*StakeDifficultyNtfn)(nil), flags)
MustRegisterCmd(VoteCreatedNtfnMethod, (*VoteCreatedNtfn)(nil), flags)
MustRegisterCmd(WalletLockStateNtfnMethod, (*WalletLockStateNtfn)(nil), flags)
MustRegisterCmd(WinningTicketsNtfnMethod, (*WinningTicketsNtfn)(nil), flags)
}

View File

@ -186,21 +186,6 @@ func TestWalletSvrWsNtfns(t *testing.T) {
Locked: true,
},
},
{
name: "winningtickets",
newNtfn: func() (interface{}, error) {
return NewCmd("winningtickets", "123", 100, map[string]string{"a": "b"})
},
staticNtfn: func() interface{} {
return NewWinningTicketsNtfn("123", 100, map[string]string{"a": "b"})
},
marshalled: `{"jsonrpc":"1.0","method":"winningtickets","params":["123",100,{"a":"b"}],"id":null}`,
unmarshalled: &WinningTicketsNtfn{
BlockHash: "123",
BlockHeight: 100,
Tickets: map[string]string{"a": "b"},
},
},
}
t.Logf("Running %d tests", len(tests))