Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary Fetch funcs for txBroadcaster and txCreator #418

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pool/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ func NewHub(hcfg *HubConfig) (*Hub, error) {
WalletAccount: h.cfg.WalletAccount,
WalletPass: h.cfg.WalletPass,
GetBlockConfirmations: h.getBlockConfirmations,
FetchTxCreator: func() TxCreator { return h.nodeConn },
FetchTxBroadcaster: func() TxBroadcaster { return h.walletConn },
TxCreator: h.nodeConn,
TxBroadcaster: h.walletConn,
CoinbaseConfTimeout: h.cfg.CoinbaseConfTimeout,
SignalCache: h.SignalCache,
}
Expand Down
32 changes: 16 additions & 16 deletions pool/paymentmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ const (
paymentBufferSize = uint32(30)
)

// TxCreator defines the functionality needed by a transaction creator for the
// pool.
type TxCreator interface {
// txCreator defines the functionality needed by a transaction creator for the
// pool. Typically a dcrd client but can be stubbed for testing.
type txCreator interface {
// GetTxOut fetches the output referenced by the provided txHash and index.
GetTxOut(context.Context, *chainhash.Hash, uint32, int8, bool) (*chainjson.GetTxOutResult, error)
// CreateRawTransaction generates a transaction from the provided
Expand All @@ -62,9 +62,9 @@ type TxCreator interface {
GetBlock(ctx context.Context, blockHash *chainhash.Hash) (*wire.MsgBlock, error)
}

// TxBroadcaster defines the functionality needed by a transaction broadcaster
// for the pool.
type TxBroadcaster interface {
// txBroadcaster defines the functionality needed by a transaction broadcaster
// for the pool. Typically a dcrwallet client but can be stubbed for testing.
type txBroadcaster interface {
// SignTransaction signs transaction inputs, unlocking them for use.
SignTransaction(context.Context, *walletrpc.SignTransactionRequest, ...grpc.CallOption) (*walletrpc.SignTransactionResponse, error)
// PublishTransaction broadcasts the transaction unto the network.
Expand Down Expand Up @@ -106,12 +106,12 @@ type PaymentMgrConfig struct {
// GetBlockConfirmations returns the number of block confirmations for the
// provided block hash.
GetBlockConfirmations func(context.Context, *chainhash.Hash) (int64, error)
// FetchTxCreator returns a transaction creator that allows coinbase lookups
// and payment transaction creation.
FetchTxCreator func() TxCreator
// FetchTxBroadcaster returns a transaction broadcaster that allows signing
// and publishing of transactions.
FetchTxBroadcaster func() TxBroadcaster
// TxCreator is a transaction creator that allows coinbase lookups and
// payment transaction creation.
TxCreator txCreator
// TxBroadcaster is a transaction broadcaster that allows signing and
// publishing of transactions.
TxBroadcaster txBroadcaster
// CoinbaseConfTimeout is the duration to wait for coinbase confirmations
// when generating a payout transaction.
CoinbaseConfTimeout time.Duration
Expand Down Expand Up @@ -479,7 +479,7 @@ func (pm *PaymentMgr) applyTxFees(inputs []chainjson.TransactionInput, outputs m
//
// The context passed to this function must have a corresponding
// cancellation to allow for a clean shutdown process.
func (pm *PaymentMgr) confirmCoinbases(ctx context.Context, txB TxBroadcaster, txHashes map[chainhash.Hash]uint32) error {
func (pm *PaymentMgr) confirmCoinbases(ctx context.Context, txB txBroadcaster, txHashes map[chainhash.Hash]uint32) error {
const funcName = "confirmCoinbases"
maxSpendableConfs := int32(pm.cfg.ActiveNet.CoinbaseMaturity) + 1

Expand Down Expand Up @@ -591,7 +591,7 @@ func (pm *PaymentMgr) monitorRescan(ctx context.Context, rescanSource walletrpc.

// generatePayoutTxDetails creates the payout transaction inputs and outputs
// from the provided payments
func (pm *PaymentMgr) generatePayoutTxDetails(ctx context.Context, txC TxCreator, feeAddr stdaddr.Address, payments map[string][]*Payment, treasuryActive bool) ([]chainjson.TransactionInput,
func (pm *PaymentMgr) generatePayoutTxDetails(ctx context.Context, txC txCreator, feeAddr stdaddr.Address, payments map[string][]*Payment, treasuryActive bool) ([]chainjson.TransactionInput,
map[chainhash.Hash]uint32, map[string]dcrutil.Amount, dcrutil.Amount, error) {
const funcName = "generatePayoutTxDetails"

Expand Down Expand Up @@ -727,7 +727,7 @@ func (pm *PaymentMgr) payDividends(ctx context.Context, height uint32, treasuryA
pm.mtx.Unlock()
}()

txB := pm.cfg.FetchTxBroadcaster()
txB := pm.cfg.TxBroadcaster
if txB == nil {
desc := fmt.Sprintf("%s: tx broadcaster cannot be nil", funcName)
return errs.PoolError(errs.Disconnected, desc)
Expand Down Expand Up @@ -784,7 +784,7 @@ func (pm *PaymentMgr) payDividends(ctx context.Context, height uint32, treasuryA
}
}

txC := pm.cfg.FetchTxCreator()
txC := pm.cfg.TxCreator
if txC == nil {
desc := fmt.Sprintf("%s: tx creator cannot be nil", funcName)
return errs.PoolError(errs.Disconnected, desc)
Expand Down
Loading
Loading