-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multi: Refactor wallet.NetworkBackend.
This unifies the wallet's Peer and NetworkBackend interfaces into a single interface, given the SPV peer syncer now fulfills both roles. In order to complete the refactor, the following changes are made: - The funcs that were in Peer are moved to NetworkBackend. - The missing funcs are added to chain.Syncer, forwading the calls to the dcrd client connection. - chain.Syncer assigns itself as NetworkBackend to the wallet, instead of assigning the client connection. - deployments package is modified to take a more limited interface (Querier) instead of the syncer var directly, to avoid circular pkg dependencies. - The live ticket querier (in tickets.go) is modified to take a more limited interface instead of the syncer var directly, to avoid circular pkg dependencies. - Call sites that type selected on *dcrd.RPC are modified to type select on *chain.Syncer. - A Synced() function is added to the NetworkBackend interface so that the JSON-RPC server can more accurately query for synced status from the underlying syncer. In the future, the dependency on concrete type checking could be further reduced on other call sites by using the same technique that was employed in this commit for the deployments package.
- Loading branch information
Showing
16 changed files
with
342 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2023 The Decred developers | ||
// Use of this source code is governed by an ISC | ||
// license that can be found in the LICENSE file. | ||
|
||
package chain | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/decred/dcrd/chaincfg/chainhash" | ||
"github.com/decred/dcrd/dcrutil/v4" | ||
"github.com/decred/dcrd/gcs/v4" | ||
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types/v4" | ||
"github.com/decred/dcrd/txscript/v4/stdaddr" | ||
"github.com/decred/dcrd/wire" | ||
"github.com/jrick/bitset" | ||
) | ||
|
||
// Blocks is part of the wallet.NetworkBackend interface. | ||
func (s *Syncer) Blocks(ctx context.Context, blockHashes []*chainhash.Hash) ([]*wire.MsgBlock, error) { | ||
return s.rpc.Blocks(ctx, blockHashes) | ||
} | ||
|
||
type filterProof = struct { | ||
Filter *gcs.FilterV2 | ||
ProofIndex uint32 | ||
Proof []chainhash.Hash | ||
} | ||
|
||
// CFiltersV2 is part of the wallet.NetworkBackend interface. | ||
func (s *Syncer) CFiltersV2(ctx context.Context, blockHashes []*chainhash.Hash) ([]filterProof, error) { | ||
return s.rpc.CFiltersV2(ctx, blockHashes) | ||
} | ||
|
||
// PublishTransactions is part of the wallet.NetworkBackend interface. | ||
func (s *Syncer) PublishTransactions(ctx context.Context, txs ...*wire.MsgTx) error { | ||
return s.rpc.PublishTransactions(ctx, txs...) | ||
} | ||
|
||
// LoadTxFilter is part of the wallet.NetworkBackend interface. | ||
func (s *Syncer) LoadTxFilter(ctx context.Context, reload bool, addrs []stdaddr.Address, outpoints []wire.OutPoint) error { | ||
return s.rpc.LoadTxFilter(ctx, reload, addrs, outpoints) | ||
} | ||
|
||
// Rescan is part of the wallet.NetworkBackend interface. | ||
func (s *Syncer) Rescan(ctx context.Context, blocks []chainhash.Hash, save func(block *chainhash.Hash, txs []*wire.MsgTx) error) error { | ||
return s.rpc.Rescan(ctx, blocks, save) | ||
} | ||
|
||
// StakeDifficulty is part of the wallet.NetworkBackend interface. | ||
func (s *Syncer) StakeDifficulty(ctx context.Context) (dcrutil.Amount, error) { | ||
return s.rpc.StakeDifficulty(ctx) | ||
} | ||
|
||
// Deployments fulfills the DeploymentQuerier interface. | ||
func (s *Syncer) Deployments(ctx context.Context) (map[string]dcrdtypes.AgendaInfo, error) { | ||
info, err := s.rpc.GetBlockchainInfo(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return info.Deployments, nil | ||
} | ||
|
||
// GetTxOut fulfills the LiveTicketQuerier interface. | ||
func (s *Syncer) GetTxOut(ctx context.Context, txHash *chainhash.Hash, index uint32, tree int8, includeMempool bool) (*dcrdtypes.GetTxOutResult, error) { | ||
return s.rpc.GetTxOut(ctx, txHash, index, tree, includeMempool) | ||
} | ||
|
||
// GetConfirmationHeight fulfills the LiveTicketQuerier interface. | ||
func (s *Syncer) GetConfirmationHeight(ctx context.Context, txHash *chainhash.Hash) (int32, error) { | ||
return s.rpc.GetConfirmationHeight(ctx, txHash) | ||
} | ||
|
||
// ExistsLiveTickets fulfills the LiveTicketQuerier interface. | ||
func (s *Syncer) ExistsLiveTickets(ctx context.Context, tickets []*chainhash.Hash) (bitset.Bytes, error) { | ||
return s.rpc.ExistsLiveTickets(ctx, tickets) | ||
} | ||
|
||
// UsedAddresses fulfills the usedAddressesQuerier interface. | ||
func (s *Syncer) UsedAddresses(ctx context.Context, addrs []stdaddr.Address) (bitset.Bytes, error) { | ||
return s.rpc.UsedAddresses(ctx, addrs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.