Skip to content

p2sh and p2tr for pset#15

Draft
topologoanatom wants to merge 7 commits intodevelopmentfrom
script-types
Draft

p2sh and p2tr for pset#15
topologoanatom wants to merge 7 commits intodevelopmentfrom
script-types

Conversation

@topologoanatom
Copy link
Collaborator

Changes

Add P2SH and P2TR transactions to service

@topologoanatom topologoanatom self-assigned this Mar 18, 2026
@ivanlele ivanlele self-requested a review March 19, 2026 09:14

let sigs = extract_ordered_sigs(redeem_script, &input.partial_sigs, i)?;

eprintln!("sig[0]: {}", hex::encode(&sigs[0]));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove these

(secret_key, public_key)
}

/// Generate a 2-of-2 multisig address from a list of public keys
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you delete these comments?

pub fn generate_2of2_multisig_address_elements(
pubkeys: &[PublicKey],
address_params: &'static elements::AddressParams,
use_p2sh: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Flags like use_p2sh: bool are generally confusing for devs, and bad API in general, if it’s true, what exactly is the other caset? It’s clearer to do this with an enum that explicitly defines the possible cases (e.g., 2–3 variants)

pub struct TweakResponse {
pub cmr_hex: String,
pub tweaked_public_key_hex: String,
pub untweaked_public_key_hex: String,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Get rid of this

.extract_tx()
.context("Failed to extract transaction from PSET")?;

// For each input, build the witness from partial signatures
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't go around just deleting comments

if input.partial_sigs.len() < 2 {
return Err(anyhow::anyhow!(
"Input {} requires 2 signatures but only has {}",
let (is_p2sh, is_p2wsh, is_p2tr) = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Confusing, just do:

let script_pubkey = _;

if script_pubkey.is_p2sh() {
 # foo
}

# continue

if script_pubkey.is_v1_p2tr() {
 # bar
}

Using fewer else if and else is generally better, and makes the code easier to read. This is dev CLI we can somethimes drop the error case

elements_env,
state.elements_network,
// precalculate inside new scope to prevent script cloning because pset will be mutually borrowed
let (is_p2sh, is_p2wsh, is_p2tr) = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do the same as in finalize in CLI, you can validate that it's one of the three supported types during request validation.

@topologoanatom topologoanatom requested a review from ivanlele March 23, 2026 13:32
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