Skip to main content

smplx_sdk/transaction/
partial_output.rs

1use elements_miniscript::bitcoin::PublicKey;
2
3use simplicityhl::elements::pset::Output;
4use simplicityhl::elements::{AssetId, Script};
5
6#[derive(Debug, Clone)]
7pub struct PartialOutput {
8    pub script_pubkey: Script,
9    pub amount: u64,
10    pub asset: AssetId,
11    pub blinding_key: Option<PublicKey>,
12}
13
14impl PartialOutput {
15    pub fn new(script: Script, amount: u64, asset: AssetId) -> Self {
16        Self {
17            script_pubkey: script,
18            amount,
19            asset,
20            blinding_key: None,
21        }
22    }
23
24    pub fn new_metadata(data: &[u8]) -> Self {
25        Self {
26            script_pubkey: Script::new_op_return(data),
27            amount: 0,
28            asset: AssetId::default(),
29            blinding_key: None,
30        }
31    }
32
33    pub fn with_blinding_key(mut self, blinding_key: PublicKey) -> Self {
34        self.blinding_key = Some(blinding_key);
35
36        self
37    }
38
39    pub fn to_output(&self) -> Output {
40        let mut output = Output::new_explicit(self.script_pubkey.clone(), self.amount, self.asset, self.blinding_key);
41
42        // the index doesn't really matter as we are the only signer
43        if self.blinding_key.is_some() {
44            output.blinder_index = Some(0);
45        }
46
47        output
48    }
49}