hal_simplicity/actions/simplicity/pset/
extract.rs

1// Copyright 2025 Andrew Poelstra
2// SPDX-License-Identifier: CC0-1.0
3
4use elements::encode::serialize_hex;
5
6use super::PsetError;
7
8#[derive(Debug, thiserror::Error)]
9pub enum PsetExtractError {
10	#[error(transparent)]
11	SharedError(#[from] PsetError),
12
13	#[error("invalid PSET: {0}")]
14	PsetDecode(elements::pset::ParseError),
15
16	#[error("failed to extract transaction: {0}")]
17	TransactionExtract(elements::pset::Error),
18}
19
20/// Extract a raw transaction from a completed PSET
21pub fn pset_extract(pset_b64: &str) -> Result<String, PsetExtractError> {
22	let pset: elements::pset::PartiallySignedTransaction =
23		pset_b64.parse().map_err(PsetExtractError::PsetDecode)?;
24
25	let tx = pset.extract_tx().map_err(PsetExtractError::TransactionExtract)?;
26	Ok(serialize_hex(&tx))
27}