From d0d265cc422243c16e88e47460664367b720e33d Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 13 Feb 2019 16:06:31 -0600 Subject: [PATCH] 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. --- dcrjson/chainsvrwsntfns.go | 24 +++++++++++++++++++++++- dcrjson/chainsvrwsntfns_test.go | 17 ++++++++++++++++- dcrjson/walletsvrwsntfns.go | 22 ---------------------- dcrjson/walletsvrwsntfns_test.go | 15 --------------- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/dcrjson/chainsvrwsntfns.go b/dcrjson/chainsvrwsntfns.go index dcab7817..439baa8d 100644 --- a/dcrjson/chainsvrwsntfns.go +++ b/dcrjson/chainsvrwsntfns.go @@ -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) } diff --git a/dcrjson/chainsvrwsntfns_test.go b/dcrjson/chainsvrwsntfns_test.go index 8b4b260b..8ffa107c 100644 --- a/dcrjson/chainsvrwsntfns_test.go +++ b/dcrjson/chainsvrwsntfns_test.go @@ -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)) diff --git a/dcrjson/walletsvrwsntfns.go b/dcrjson/walletsvrwsntfns.go index afb9bdbe..63d8b882 100644 --- a/dcrjson/walletsvrwsntfns.go +++ b/dcrjson/walletsvrwsntfns.go @@ -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) } diff --git a/dcrjson/walletsvrwsntfns_test.go b/dcrjson/walletsvrwsntfns_test.go index 8eaa2471..23d7e2ad 100644 --- a/dcrjson/walletsvrwsntfns_test.go +++ b/dcrjson/walletsvrwsntfns_test.go @@ -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))