bdk-ffi icon indicating copy to clipboard operation
bdk-ffi copied to clipboard

feat: Expose psbt output

Open ItoroD opened this issue 2 months ago • 1 comments

Description

Expose output for psbt.

Useful API docs:

Notes to the reviewers

  • TapLeaf which is an enum with variant in rust-bitcoin, has been flattened in LeafNode in our bitcoin.rs file. Seems UniFFI enums with complex types like Arc<Script> don't work well for FFI. An error thrown in Kotlin where org.bitcoindevkit.TapLeaf.Script is conflicting with org.bitcoindevkit.Script.

So instead of having

pub enum TapLeaf {
    Script(ScriptBuf, LeafVersion),
    Hidden(TapNodeHash),
}

pub struct LeafNode {
    /// The [`TapLeaf`]
    leaf: TapLeaf,
    /// The merkle proof (hashing partners) to get this node.
    merkle_branch: TaprootMerkleBranch,
}

We use:

#[derive(Clone, Debug, uniffi::Enum)]
pub enum TapLeaf {
    /// A known script
    Script,
    /// Hidden node
    Hidden,
}


#[derive(Clone, Debug, uniffi::Record)]
pub struct LeafNode {
    /// The leaf type (script or hidden)
    pub leaf_type: TapLeaf,
    /// The script if this is a Script leaf (None if Hidden)
    pub script: Option<Arc<Script>>,
    /// The version if this is a Script leaf (None if Hidden)
    pub version: Option<u8>,
    /// The hash if this is a Hidden leaf (None if Script)
    pub hash: Option<String>,
    /// The merkle proof (hashing partners) to get this node.
    pub merkle_branch: Vec<String>,
}
  • Also has_hidden_nodes is not exposed directly in rust-bitcoin. Hence I derived that while I iterated through the leave nodes in tap_tree mapping.

Documentation

Checklists

All Submissions:

  • [x] I've signed all my commits
  • [x] I followed the contribution guidelines
  • [x] I ran cargo fmt and cargo clippy before committing
  • [ ] I've added a changelog in the next release tracking issue (see example)
  • [ ] I've linked the relevant upstream docs or specs above

New Features:

  • [ ] I've added tests for the new feature
  • [x] I've added docs for the new feature

ItoroD avatar Nov 04 '25 19:11 ItoroD

Looking good bc2bdb01f0fed34979de9085aa44b69cc147ab5d

thunderbiscuit avatar Nov 07 '25 20:11 thunderbiscuit