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 with_blinding_key(mut self, blinding_key: PublicKey) -> Self {
25        self.blinding_key = Some(blinding_key);
26
27        self
28    }
29
30    pub fn to_output(&self) -> Output {
31        let mut output = Output::new_explicit(self.script_pubkey.clone(), self.amount, self.asset, self.blinding_key);
32
33        // the index doesn't really matter as we are the only signer
34        if self.blinding_key.is_some() {
35            output.blinder_index = Some(0);
36        }
37
38        output
39    }
40}