forked from decred/dcrd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dcrwalletextwsntfns.go
175 lines (150 loc) · 5.35 KB
/
dcrwalletextwsntfns.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Copyright (c) 2015-2016 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
// NOTE: This file is intended to house the RPC websocket notifications that are
// supported by a chain server.
package dcrjson
const (
// TicketPurchasedNtfnMethod is the method of the dcrwallet
// ticketpurchased notification.
TicketPurchasedNtfnMethod = "ticketpurchased"
// VoteCreatedNtfnMethod is the method of the dcrwallet
// votecreated notification.
VoteCreatedNtfnMethod = "votecreated"
// RevocationCreatedNtfnMethod is the method of the dcrwallet
// revocationcreated notification.
RevocationCreatedNtfnMethod = "revocationcreated"
// WinningTicketsNtfnMethod is the method of the daemon
// winningtickets notification.
WinningTicketsNtfnMethod = "winningtickets"
// SpentAndMissedTicketsNtfnMethod is the method of the daemon
// spentandmissedtickets notification.
SpentAndMissedTicketsNtfnMethod = "spentandmissedtickets"
// NewTicketsNtfnMethod is the method of the daemon
// newtickets notification.
NewTicketsNtfnMethod = "newtickets"
// StakeDifficultyNtfnMethod is the method of the daemon
// stakedifficulty notification.
StakeDifficultyNtfnMethod = "stakedifficulty"
)
// TicketPurchasedNtfn is a type handling custom marshaling and
// unmarshaling of ticketpurchased JSON websocket notifications.
type TicketPurchasedNtfn struct {
TxHash string
Amount int64 // SStx only
}
// NewTicketPurchasedNtfn creates a new TicketPurchasedNtfn.
func NewTicketPurchasedNtfn(txHash string, amount int64) *TicketPurchasedNtfn {
return &TicketPurchasedNtfn{
TxHash: txHash,
Amount: amount,
}
}
// VoteCreatedNtfn is a type handling custom marshaling and
// unmarshaling of ticketpurchased JSON websocket notifications.
type VoteCreatedNtfn struct {
TxHash string
BlockHash string
Height int32
SStxIn string
VoteBits uint16
}
// NewVoteCreatedNtfn creates a new VoteCreatedNtfn.
func NewVoteCreatedNtfn(txHash string, blockHash string, height int32, sstxIn string, voteBits uint16) *VoteCreatedNtfn {
return &VoteCreatedNtfn{
TxHash: txHash,
BlockHash: blockHash,
Height: height,
SStxIn: sstxIn,
VoteBits: voteBits,
}
}
// RevocationCreatedNtfn is a type handling custom marshaling and
// unmarshaling of ticketpurchased JSON websocket notifications.
type RevocationCreatedNtfn struct {
TxHash string
SStxIn string
}
// NewRevocationCreatedNtfn creates a new RevocationCreatedNtfn.
func NewRevocationCreatedNtfn(txHash string, sstxIn string) *RevocationCreatedNtfn {
return &RevocationCreatedNtfn{
TxHash: txHash,
SStxIn: sstxIn,
}
}
// 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,
}
}
// SpentAndMissedTicketsNtfn is a type handling custom marshaling and
// unmarshaling of spentandmissedtickets JSON websocket notifications.
type SpentAndMissedTicketsNtfn struct {
Hash string
Height int32
StakeDiff int64
Tickets map[string]string
}
// NewSpentAndMissedTicketsNtfn creates a new SpentAndMissedTicketsNtfn.
func NewSpentAndMissedTicketsNtfn(hash string, height int32, stakeDiff int64, tickets map[string]string) *SpentAndMissedTicketsNtfn {
return &SpentAndMissedTicketsNtfn{
Hash: hash,
Height: height,
StakeDiff: stakeDiff,
Tickets: tickets,
}
}
// 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,
}
}
// StakeDifficultyNtfn is a type handling custom marshaling and
// unmarshaling of stakedifficulty JSON websocket notifications.
type StakeDifficultyNtfn struct {
BlockHash string
BlockHeight int32
StakeDiff int64
}
// NewStakeDifficultyNtfn creates a new StakeDifficultyNtfn.
func NewStakeDifficultyNtfn(hash string, height int32, stakeDiff int64) *StakeDifficultyNtfn {
return &StakeDifficultyNtfn{
BlockHash: hash,
BlockHeight: height,
StakeDiff: stakeDiff,
}
}
func init() {
// The commands in this file are only usable by websockets and are
// notifications.
flags := UFWalletOnly | UFWebsocketOnly | UFNotification
MustRegisterCmd(TicketPurchasedNtfnMethod, (*TicketPurchasedNtfn)(nil), flags)
MustRegisterCmd(VoteCreatedNtfnMethod, (*VoteCreatedNtfn)(nil), flags)
MustRegisterCmd(RevocationCreatedNtfnMethod, (*RevocationCreatedNtfn)(nil), flags)
MustRegisterCmd(WinningTicketsNtfnMethod, (*WinningTicketsNtfn)(nil), flags)
MustRegisterCmd(SpentAndMissedTicketsNtfnMethod, (*SpentAndMissedTicketsNtfn)(nil), flags)
MustRegisterCmd(NewTicketsNtfnMethod, (*NewTicketsNtfn)(nil), flags)
MustRegisterCmd(StakeDifficultyNtfnMethod, (*StakeDifficultyNtfn)(nil), flags)
}