Skip to content

Commit 531ccf9

Browse files
committed
simplicity: add 'simplicity pset extract' command
Now rather than extracting using elements-cli, by running elements-cli finalizepsbt <psbt> true you can do it with hal-simplicity, with hal-simplicity simplicity pset extract <psbt>
1 parent 211e7f8 commit 531ccf9

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2025 Andrew Poelstra
2+
// SPDX-License-Identifier: CC0-1.0
3+
4+
use elements::encode::serialize_hex;
5+
6+
use super::super::{Error, ErrorExt as _};
7+
use crate::cmd;
8+
9+
pub fn cmd<'a>() -> clap::App<'a, 'a> {
10+
cmd::subcommand("extract", "extract a raw transaction from a completed PSET")
11+
.args(&cmd::opts_networks())
12+
.args(&[cmd::arg("pset", "PSET to update (base64)").takes_value(true).required(true)])
13+
}
14+
15+
pub fn exec<'a>(matches: &clap::ArgMatches<'a>) {
16+
let pset_b64 = matches.value_of("pset").expect("tx mandatory");
17+
match exec_inner(pset_b64) {
18+
Ok(info) => cmd::print_output(matches, &info),
19+
Err(e) => cmd::print_output(matches, &e),
20+
}
21+
}
22+
23+
fn exec_inner(pset_b64: &str) -> Result<String, Error> {
24+
let pset: elements::pset::PartiallySignedTransaction =
25+
pset_b64.parse().result_context("decoding PSET")?;
26+
27+
let tx = pset.extract_tx().result_context("extracting transaction")?;
28+
Ok(serialize_hex(&tx))
29+
}

src/bin/hal-simplicity/cmd/simplicity/pset/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2025 Andrew Poelstra
22
// SPDX-License-Identifier: CC0-1.0
33

4+
mod extract;
45
mod finalize;
56
mod update_input;
67

@@ -15,12 +16,14 @@ struct UpdatedPset {
1516

1617
pub fn cmd<'a>() -> clap::App<'a, 'a> {
1718
cmd::subcommand_group("pset", "manipulate PSETs for spending from Simplicity programs")
19+
.subcommand(self::extract::cmd())
1820
.subcommand(self::finalize::cmd())
1921
.subcommand(self::update_input::cmd())
2022
}
2123

2224
pub fn exec<'a>(matches: &clap::ArgMatches<'a>) {
2325
match matches.subcommand() {
26+
("extract", Some(m)) => self::extract::exec(m),
2427
("finalize", Some(m)) => self::finalize::exec(m),
2528
("update-input", Some(m)) => self::update_input::exec(m),
2629
(_, _) => unreachable!("clap prints help"),

0 commit comments

Comments
 (0)