Skip to content

Move fee calculation to cdk-common and add fee methods to Wallet trait#1805

Draft
crodas wants to merge 1 commit intocashubtc:mainfrom
crodas:feature/fees-functions
Draft

Move fee calculation to cdk-common and add fee methods to Wallet trait#1805
crodas wants to merge 1 commit intocashubtc:mainfrom
crodas:feature/fees-functions

Conversation

@crodas
Copy link
Copy Markdown
Collaborator

@crodas crodas commented Apr 1, 2026

Description

Move calculate_fee and ProofsFeeBreakdown from cdk/src/fees.rs to cdk-common/src/wallet/fees.rs so downstream consumers of cdk-common can compute fees without depending on the full cdk crate.

Add get_proofs_fee, get_proofs_fee_by_count, and get_proofs_with to the Wallet trait, and make get_proofs_by_states a default method that delegates to get_proofs_with. Expose corresponding FFI bindings.


Notes to the reviewers


Suggested CHANGELOG Updates

CHANGED

ADDED

REMOVED

FIXED


Checklist

@crodas crodas requested a review from thesimplekid April 1, 2026 00:03
@crodas crodas self-assigned this Apr 1, 2026
@github-project-automation github-project-automation bot moved this to Backlog in CDK Apr 1, 2026
@crodas crodas force-pushed the feature/fees-functions branch from 826d72c to a42fae0 Compare April 1, 2026 00:07
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 0% with 58 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.49%. Comparing base (a46f998) to head (a5e66c0).

Files with missing lines Patch % Lines
crates/cdk-ffi/src/wallet.rs 0.00% 42 Missing ⚠️
crates/cdk-ffi/src/types/amount.rs 0.00% 8 Missing ⚠️
crates/cdk-common/src/wallet/mod.rs 0.00% 4 Missing ⚠️
crates/cdk-ffi/src/wallet_trait.rs 0.00% 2 Missing ⚠️
crates/cdk/src/wallet/wallet_trait.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1805      +/-   ##
==========================================
- Coverage   62.51%   62.49%   -0.03%     
==========================================
  Files         329      329              
  Lines       53644    53704      +60     
==========================================
+ Hits        33535    33561      +26     
- Misses      20109    20143      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Move `calculate_fee` and `ProofsFeeBreakdown` from `cdk/src/fees.rs` to
`cdk-common/src/wallet/fees.rs` so downstream consumers of cdk-common can
compute fees without depending on the full cdk crate.

Add `get_proofs_fee`, `get_proofs_fee_by_count`, and `get_proofs_with` to the
Wallet trait, and make `get_proofs_by_states` a default method that delegates
to `get_proofs_with`. Expose corresponding FFI bindings.
@crodas crodas force-pushed the feature/fees-functions branch from a42fae0 to a5e66c0 Compare April 1, 2026 06:03
Comment on lines +803 to +807
/// Fee required to redeem proof set by count per keyset
async fn get_proofs_fee_by_count(
&self,
proofs_per_keyset: HashMap<Id, u64>,
) -> Result<fees::ProofsFeeBreakdown, Self::Error>;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we think this fn should be in the public api, Is it even used privately? Imagine most will use the get_proofs_fee

/// from the database.
async fn get_proofs_by_states(&self, states: Vec<State>) -> Result<Proofs, Self::Error>;
async fn get_proofs_by_states(&self, states: Vec<State>) -> Result<Proofs, Self::Error> {
self.get_proofs_with(Some(states), None).await
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're inconsistent about if the traits have an implementation here or just a definition. In cdk-coommon I think they should only have a definition.

@thesimplekid thesimplekid modified the milestones: 0.16.1, 0.17.0 Apr 2, 2026
@thesimplekid
Copy link
Copy Markdown
Collaborator

@crodas Think this maybe this just fell of your radar? Do we still need it think so?

@crodas
Copy link
Copy Markdown
Collaborator Author

crodas commented Apr 10, 2026

We certainly needed but we agreed last week to work on the wallet documentation and planning first. I'm working on understanding what's really needed and what is an internal function used only for Rust.

Once that document is done and approved, I'll adjust this PR accordingly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants