Skip to content

Migrate Psbt to pro-macros#736

Merged
thunderbiscuit merged 3 commits intobitcoindevkit:masterfrom
ItoroD:macros-psbt
Apr 23, 2025
Merged

Migrate Psbt to pro-macros#736
thunderbiscuit merged 3 commits intobitcoindevkit:masterfrom
ItoroD:macros-psbt

Conversation

@ItoroD
Copy link
Copy Markdown
Collaborator

@ItoroD ItoroD commented Apr 23, 2025

Notes to the reviewers

  • json_serialize and finalize do not have direct mapping doc in rust api docs. I wrote my own doc comments there.
  • I noticed that when bringing in docs from rust side, we might want to change rust specific terminology to more understandable ones for the bindings.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added docs for the new feature

@ItoroD
Copy link
Copy Markdown
Collaborator Author

ItoroD commented Apr 23, 2025

Here is an example of what I mean by rust specific terminology in our jvm doc

image

Comment thread bdk-ffi/src/bitcoin.rs
use bdk_wallet::bitcoin::consensus::encode::serialize;
use bdk_wallet::bitcoin::consensus::Decodable;
use bdk_wallet::bitcoin::io::Cursor;
use bdk_wallet::bitcoin::psbt::ExtractTxError;
Copy link
Copy Markdown
Collaborator Author

@ItoroD ItoroD Apr 23, 2025

Choose a reason for hiding this comment

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

This caused issues when I was testing after migrating to pro-marcos in this pr. Was there a reason why we were not using ExtractTxError from the error crate like the rest of the errors?

I updated this to how we use the other errors like PsbtError, PsbtParseError and the issue was resolved.

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.

No this was totally an oversight! Thanks for the fix.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ok. Great!

Copy link
Copy Markdown
Member

@thunderbiscuit thunderbiscuit left a comment

Choose a reason for hiding this comment

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

A few small tweaks but this is looking good!

Comment thread bdk-ffi/src/bitcoin.rs
use bdk_wallet::bitcoin::consensus::encode::serialize;
use bdk_wallet::bitcoin::consensus::Decodable;
use bdk_wallet::bitcoin::io::Cursor;
use bdk_wallet::bitcoin::psbt::ExtractTxError;
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.

No this was totally an oversight! Thanks for the fix.

Comment thread bdk-ffi/src/bitcoin.rs Outdated
Ok(Psbt(Mutex::new(psbt)))
}

/// Serialize the PSBT into a writer.
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.

How do you feel about this line instead? It feels like it would match your doc from the constructor above.

Serialize the PSBT into a base64-encoded string.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Much better

Comment thread bdk-ffi/src/bitcoin.rs Outdated
Ok(Arc::new(Psbt(Mutex::new(original_psbt))))
}

/// Finalizes the current PSBT (Partially Signed Bitcoin Transaction) and produces a result indicating
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 would remove the "(Partially Signed Bitcoin Transaction)" here and on the json_serialize() method docs, since we're in the type itself and so there is little chance of confusion.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes. I will update

@thunderbiscuit
Copy link
Copy Markdown
Member

Agreed that the docs are not always clear and appropriate. It's a bit up in the air what our policy with those are at the moment; in some cases you'd want the docs to be a little different between languages, which is not possible. In other cases the Rust docs clearly refer to things that don't exist in the ffi layer (in which case I have taken the liberty of removing those lines).

We should talk about this over the next dev call. For now we've been trying to just copy/paste the Rust docs, but some cleanup might be required.

Copy link
Copy Markdown
Member

@thunderbiscuit thunderbiscuit left a comment

Choose a reason for hiding this comment

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

ACK cdd63d1.

@thunderbiscuit thunderbiscuit merged commit cdd63d1 into bitcoindevkit:master Apr 23, 2025
@thunderbiscuit
Copy link
Copy Markdown
Member

My bad! After looking into an odd cargo warning, I realize that the FinalizedPsbtResult should use #[derive(uniffi::Record)]

https://mozilla.github.io/uniffi-rs/latest/proc_macro/records.html

@ItoroD
Copy link
Copy Markdown
Collaborator Author

ItoroD commented Apr 23, 2025

My bad! After looking into an odd cargo warning, I realize that the FinalizedPsbtResult should use #[derive(uniffi::Record)]

https://mozilla.github.io/uniffi-rs/latest/proc_macro/records.html

Wow! Nice catch. So structs with named fields should use record ?

@thunderbiscuit
Copy link
Copy Markdown
Member

Yes exactly. You either get fields or methods (one of the quirks of uniffi). This is why we have methods on Transaction that are actually just fields in Rust, because we cannot have both, and in cases where Rust uses both we expose the fields through getters.

@ItoroD
Copy link
Copy Markdown
Collaborator Author

ItoroD commented Apr 23, 2025

Ok I will create pr for the fix now

@ItoroD
Copy link
Copy Markdown
Collaborator Author

ItoroD commented Apr 23, 2025

or would you rather do this in your pr? @thunderbiscuit

@thunderbiscuit
Copy link
Copy Markdown
Member

No feel free to open a PR for it!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants