@@ -6,11 +6,9 @@ package wallet
6
6
7
7
import (
8
8
"context"
9
- "time"
10
9
11
10
"decred.org/dcrwallet/v2/errors"
12
11
"decred.org/dcrwallet/v2/rpc/client/dcrd"
13
- "decred.org/dcrwallet/v2/wallet/udb"
14
12
"decred.org/dcrwallet/v2/wallet/walletdb"
15
13
"github.com/decred/dcrd/blockchain/stake/v4"
16
14
"github.com/decred/dcrd/chaincfg/chainhash"
@@ -226,105 +224,11 @@ func (w *Wallet) TicketHashesForVotingAddress(ctx context.Context, votingAddr st
226
224
return ticketHashes , nil
227
225
}
228
226
229
- // RevokeTickets creates and sends revocation transactions for any unrevoked
230
- // missed and expired tickets. The wallet must be unlocked to generate any
231
- // revocations.
227
+ // RevokeTickets no longer revokes any tickets since revocations are now
228
+ // automatically created per DCP0009.
229
+ //
230
+ // Deprecated: this method will be removed in the next major version.
232
231
func (w * Wallet ) RevokeTickets (ctx context.Context , rpcCaller Caller ) error {
233
- const op errors.Op = "wallet.RevokeTickets"
234
-
235
- var ticketHashes []chainhash.Hash
236
- err := walletdb .View (ctx , w .db , func (dbtx walletdb.ReadTx ) error {
237
- var err error
238
- _ , tipHeight := w .txStore .MainChainTip (dbtx )
239
- ticketHashes , err = w .txStore .UnspentTickets (dbtx , tipHeight , false )
240
- return err
241
- })
242
- if err != nil {
243
- return errors .E (op , err )
244
- }
245
-
246
- ticketHashPtrs := make ([]* chainhash.Hash , len (ticketHashes ))
247
- for i := range ticketHashes {
248
- ticketHashPtrs [i ] = & ticketHashes [i ]
249
- }
250
- rpc := dcrd .New (rpcCaller )
251
- expired , missed , err := rpc .ExistsExpiredMissedTickets (ctx , ticketHashPtrs )
252
- if err != nil {
253
- return errors .E (op , err )
254
- }
255
- revokableTickets := make ([]* chainhash.Hash , 0 , len (ticketHashes ))
256
- for i , p := range ticketHashPtrs {
257
- if ! (expired .Get (i ) || missed .Get (i )) {
258
- continue
259
- }
260
- revokableTickets = append (revokableTickets , p )
261
- }
262
- feePerKb := w .RelayFee ()
263
- revocations := make ([]* wire.MsgTx , 0 , len (revokableTickets ))
264
- err = walletdb .View (ctx , w .db , func (dbtx walletdb.ReadTx ) error {
265
- for _ , ticketHash := range revokableTickets {
266
- addrmgrNs := dbtx .ReadBucket (waddrmgrNamespaceKey )
267
- txmgrNs := dbtx .ReadBucket (wtxmgrNamespaceKey )
268
- ticketPurchase , err := w .txStore .Tx (txmgrNs , ticketHash )
269
- if err != nil {
270
- return err
271
- }
272
-
273
- // Don't create revocations when this wallet doesn't have voting
274
- // authority or the private key to revoke.
275
- owned , haveKey , err := w .hasVotingAuthority (addrmgrNs , ticketPurchase )
276
- if err != nil {
277
- return err
278
- }
279
- if ! (owned && haveKey ) {
280
- continue
281
- }
282
-
283
- revocation , err := createUnsignedRevocation (ticketHash ,
284
- ticketPurchase , feePerKb , w .chainParams )
285
- if err != nil {
286
- return err
287
- }
288
- err = w .signRevocation (addrmgrNs , ticketPurchase , revocation )
289
- if err != nil {
290
- return err
291
- }
292
- revocations = append (revocations , revocation )
293
- }
294
- return nil
295
- })
296
- if err != nil {
297
- return errors .E (op , err )
298
- }
299
-
300
- for i , revocation := range revocations {
301
- rec , err := udb .NewTxRecordFromMsgTx (revocation , time .Now ())
302
- if err != nil {
303
- return errors .E (op , err )
304
- }
305
- var watch []wire.OutPoint
306
- //w.lockedOutpointMu intentionally not locked.
307
- err = walletdb .Update (ctx , w .db , func (dbtx walletdb.ReadWriteTx ) error {
308
- // Could be more efficient by avoiding processTransaction, as we
309
- // know it is a revocation.
310
- watch , err = w .processTransactionRecord (ctx , dbtx , rec , nil , nil )
311
- if err != nil {
312
- return errors .E (op , err )
313
- }
314
- return rpc .PublishTransaction (ctx , revocation )
315
- })
316
- if err != nil {
317
- return errors .E (op , err )
318
- }
319
-
320
- log .Infof ("Revoked ticket %v with revocation %v" , revokableTickets [i ],
321
- & rec .Hash )
322
- err = rpc .LoadTxFilter (ctx , false , nil , watch )
323
- if err != nil {
324
- log .Errorf ("Failed to watch outpoints: %v" , err )
325
- }
326
- }
327
-
328
232
return nil
329
233
}
330
234
0 commit comments