Skip to content

Conversation

@ItoroD
Copy link
Collaborator

@ItoroD ItoroD commented Nov 4, 2025

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:

  • I've signed all my commits
  • I followed the contribution guidelines
  • 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
  • I've added docs for the new feature

@ItoroD ItoroD force-pushed the expose-psbt-output branch from 8b2e470 to 0c88e5f Compare November 4, 2025 19:55
@ItoroD ItoroD changed the title feat: Expose psbt output (Draft) feat: Expose psbt output Nov 4, 2025
@ItoroD ItoroD force-pushed the expose-psbt-output branch from 0c88e5f to 1167c84 Compare November 5, 2025 11:50
@ItoroD ItoroD force-pushed the expose-psbt-output branch from 1167c84 to bc2bdb0 Compare November 7, 2025 17:16
@ItoroD ItoroD marked this pull request as ready for review November 7, 2025 18:09
@ItoroD ItoroD requested a review from thunderbiscuit November 7, 2025 18:10
@ItoroD ItoroD changed the title (Draft) feat: Expose psbt output feat: Expose psbt output Nov 7, 2025
@thunderbiscuit
Copy link
Member

Looking good bc2bdb0

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants