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

core: add getter for network fee rate #2620

Merged
merged 1 commit into from
Feb 19, 2024
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
9 changes: 9 additions & 0 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -11132,3 +11132,12 @@ func (c *Core) DisableFundsMixer(assetID uint32) error {
}
return mw.DisableFundsMixer()
}

// NetworkFeeRate generates a network tx fee rate for the specified asset.
// If the wallet implements FeeRater, the wallet will be queried for the
// fee rate. If the wallet is not a FeeRater, local book feed caches are
// checked. If no relevant books are synced, connected DCRDEX servers will be
// queried.
func (c *Core) NetworkFeeRate(assetID uint32) uint64 {
return c.feeSuggestionAny(assetID)
}
39 changes: 39 additions & 0 deletions client/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10907,3 +10907,42 @@ func TestFindBond(t *testing.T) {
})
}
}

func TestNetworkFeeRate(t *testing.T) {
rig := newTestRig()
defer rig.shutdown()

assetID := tUTXOAssetA.ID
wallet, tWallet := newTWallet(assetID)
rig.core.wallets[assetID] = wallet

const feeRaterRate = 50
dumbWallet := wallet.Wallet
wallet.Wallet = &TFeeRater{
TXCWallet: tWallet,
feeRate: feeRaterRate,
}
if r := rig.core.NetworkFeeRate(assetID); r != feeRaterRate {
t.Fatalf("FeeRater not working. %d != %d", r, feeRaterRate)
}
wallet.Wallet = dumbWallet

const bookFeedFeeRate = 60
book := newBookie(rig.dc, assetID, tUTXOAssetB.ID, nil, tLogger)
rig.dc.books[tDcrBtcMktName] = book
book.logEpochReport(&msgjson.EpochReportNote{BaseFeeRate: bookFeedFeeRate})
if r := rig.core.NetworkFeeRate(assetID); r != bookFeedFeeRate {
t.Fatalf("Book feed fee rate not working. %d != %d", r, bookFeedFeeRate)
}
delete(rig.dc.books, tDcrBtcMktName)

const serverFeeRate = 70
rig.ws.queueResponse(msgjson.FeeRateRoute, func(msg *msgjson.Message, f msgFunc) error {
resp, _ := msgjson.NewResponse(msg.ID, serverFeeRate, nil)
f(resp)
return nil
})
if r := rig.core.NetworkFeeRate(assetID); r != serverFeeRate {
t.Fatalf("Server fee rate not working. %d != %d", r, serverFeeRate)
}
}
Loading