Skip to content

feat: expose Display trait on Amount and Psbt types#1045

Merged
thunderbiscuit merged 1 commit into
bitcoindevkit:masterfrom
shivv23:feat/display-amount-psbt
Jul 16, 2026
Merged

feat: expose Display trait on Amount and Psbt types#1045
thunderbiscuit merged 1 commit into
bitcoindevkit:masterfrom
shivv23:feat/display-amount-psbt

Conversation

@shivv23

@shivv23 shivv23 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

Add #[uniffi::export(Display)] and implement the Display trait on the Amount and Psbt types, exposing them to the FFI bindings (Kotlin, Swift, Python).

Notes to the reviewers

This follows the same pattern used by other types in the codebase (FeeRate, Script, Address, Transaction, WalletEvent, etc.) that already expose Display to bindings. Part of issue #1020.

Documentation

Changelog

changelog: none

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing
  • I've added exactly one changelog:* label
  • I've linked the relevant upstream docs or specs above

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

@j-kon

j-kon commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Nice small addition, and this seems consistent with the Display exports already used for types like FeeRate, Script, Address, and Transaction.

One small question: should this PR add a focused test for the new binding-facing Display behavior? Since this exposes Display through UniFFI, it would be useful to assert that Amount and Psbt stringify as expected, especially because the PR checklist marks tests as added but the diff only changes bitcoin.rs.

@shivv23

shivv23 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Hey @j-kon , I should have included tests with the initial commit. I've pushed test_amount_display and test_psbt_display to cover the new Display behavior for both types.

Regarding the changelog label — I have changelog: added in the PR body but it seems the label itself needs to be applied by someone with triage access. Could you add it?

Thanks for the review!

@j-kon

j-kon commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Hey @j-kon , I should have included tests with the initial commit. I've pushed test_amount_display and test_psbt_display to cover the new Display behavior for both types.

Regarding the changelog label — I have changelog: added in the PR body but it seems the label itself needs to be applied by someone with triage access. Could you add it?

Thanks for the review!

Thanks for adding the tests, that addresses my review comment.

I don’t think I have triage access to apply labels on this repo, so I can’t add the changelog: added label myself. Maybe a maintainer can help apply it.

@ItoroD ItoroD left a comment

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.

Thanks for adding this. LGTM. Just a few comments commit message for the test should start with

test: add ....

Comment thread bdk-ffi/src/bitcoin.rs Outdated
#[uniffi::export(Display)]
pub struct Amount(pub(crate) BdkAmount);

impl Display for Amount {

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.

Just a nit. Usually we place the display Impl at the bottom of the type implementation. i.e after all implementations of the particular type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment thread bdk-ffi/src/bitcoin.rs Outdated
#[uniffi::export(Display)]
pub struct Psbt(pub(crate) Mutex<BdkPsbt>);

impl Display for Psbt {

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.

same here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

@shivv23
shivv23 force-pushed the feat/display-amount-psbt branch 2 times, most recently from c793a9a to 458ca59 Compare July 14, 2026 16:22
@shivv23

shivv23 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Hi @ItoroD! I have made all changes you mentioned to the PR. Kindly review it again.

@ItoroD ItoroD left a comment

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.

On second thought I am thinking we might not need the tests. As in the past we do not typically write tests explicitly for display. This will mean we will have lots of solely display tests for various types which I do not think its necessary. I will just leave this comment here to see what other reviews think.

I am happy to approve one the import change is made.

Comment thread bdk-ffi/src/tests/bitcoin.rs Outdated

#[test]
fn test_amount_display() {
let amount = crate::bitcoin::Amount::from_sat(100_000_000);

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.

Here, maybe we can use the import at the top of the file like the others. So no need to use the fully qualified import here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ItoroD Done!

@thunderbiscuit thunderbiscuit 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.

If you can:

  1. Remove the test
  2. Rebase on master

I think this one is ready to go.

Comment thread bdk-ffi/src/tests/bitcoin.rs Outdated
);
}

#[test]

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.

I agree with @ItoroD; we do not need to add tests for the Display trait.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@thunderbiscuit Agree with you, have made the required changes.

@shivv23
shivv23 force-pushed the feat/display-amount-psbt branch from 458ca59 to 342c716 Compare July 15, 2026 07:53
@shivv23

shivv23 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@ItoroD and @thunderbiscuit Hi! I have made the required changes requested. Thanks!

@thunderbiscuit

Copy link
Copy Markdown
Member

I apologize @shivv23 but I didn't notice your commits were not PGP signed. This is a requirement of the BDK Org, so you'll have to sign that commit before I can merge. Otherwise this looks good! (also keep an eye out because if I merge anything in between you'll also have to rebase).

@shivv23
shivv23 force-pushed the feat/display-amount-psbt branch 2 times, most recently from 746203e to ea5036d Compare July 15, 2026 20:22
@shivv23

shivv23 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Hi @thunderbiscuit! All feedback addressed (tests removed, Display placement moved to bottom of type impls, rebased on master). Commit is now GPG-signed and verified. Please take another look.

Signed-off-by: shivv23 <shivamkumar0423@gmail.com>
@shivv23
shivv23 force-pushed the feat/display-amount-psbt branch from ea5036d to a62a58b Compare July 15, 2026 20:38

@ItoroD ItoroD left a comment

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.

ACK a62a58b

@thunderbiscuit thunderbiscuit 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 a62a58b.

@thunderbiscuit
thunderbiscuit merged commit a62a58b into bitcoindevkit:master Jul 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants