Skip to content

Add fee rate constructors that take Amount as arg - #4614

Merged
apoelstra merged 2 commits into
rust-bitcoin:masterfrom
tcharding:06-12-add-fee-rate-constructors
Jun 12, 2025
Merged

apoelstra merged 2 commits into
rust-bitcoin:masterfrom
tcharding:06-12-add-fee-rate-constructors

Conversation

@tcharding

@tcharding tcharding commented Jun 12, 2025 •

Copy link
Copy Markdown
Member

Some users may find it more ergonomic to pass in an Amount when constructing fee rates. Also the strong type adds some semantic meaning as well as imposes the Amount::MAX limit.

Add an equivalent constructor for each of the existing ones that uses an argument of type Amount instead of u64 sats.

(This was pulled out of #4610.)

Close: #4734

Satoshis per virtual byte is grammatically better than satoshis per
virtual bytes - I think.
Some users may find it more ergonomic to pass in an `Amount` when
constructing fee rates. Also the strong type adds some semantic meaning
as well as imposes the `Amount::MAX` limit.

Add an equivalent constructor for each of the existing ones that uses an
argument of type `Amount` instead of `u64` sats.
@github-actions github-actions Bot added the C-units PRs modifying the units crate label Jun 12, 2025
@yancyribbens

yancyribbens commented Jun 12, 2025 •

Copy link
Copy Markdown
Contributor

I went looking for #4734 to try and understand why this PR is useful but it doesn't exist. Why is Amount to FeeRate useful exactly?

@apoelstra

Copy link
Copy Markdown
Member

Because feerates are defined in terms of amounts.

@yancyribbens

Copy link
Copy Markdown
Contributor

true, it's a ratio of amount/weight (sat/wu). Although I haven't run into a situation where it's useful to go from amount to fee_rate. Why not from Weight to fee_rate then also?

@yancyribbens

Copy link
Copy Markdown
Contributor

To me, fee is defined in terms of amounts.

@apoelstra apoelstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK 6ed3fd6; successfully ran local tests

@apoelstra
apoelstra merged commit aab9c2d into rust-bitcoin:master Jun 12, 2025
@tcharding
tcharding deleted the 06-12-add-fee-rate-constructors branch June 18, 2025 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-units PRs modifying the units crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants