smplx_sdk/transaction/
partial_output.rs1use elements_miniscript::bitcoin::PublicKey;
2
3use simplicityhl::elements::pset::Output;
4use simplicityhl::elements::{AssetId, Script};
5
6#[derive(Debug, Clone)]
8pub struct PartialOutput {
9 pub script_pubkey: Script,
11 pub amount: u64,
13 pub asset: AssetId,
15 pub blinding_key: Option<PublicKey>,
17}
18
19impl PartialOutput {
20 #[must_use]
22 pub fn new(script: Script, amount: u64, asset: AssetId) -> Self {
23 Self {
24 script_pubkey: script,
25 amount,
26 asset,
27 blinding_key: None,
28 }
29 }
30
31 #[must_use]
33 pub fn new_metadata(data: &[u8]) -> Self {
34 Self {
35 script_pubkey: Script::new_op_return(data),
36 amount: 0,
37 asset: AssetId::default(),
38 blinding_key: None,
39 }
40 }
41
42 #[must_use]
44 pub fn with_blinding_key(mut self, blinding_key: PublicKey) -> Self {
45 self.blinding_key = Some(blinding_key);
46
47 self
48 }
49
50 #[must_use]
52 pub fn to_output(&self) -> Output {
53 let mut output = Output::new_explicit(self.script_pubkey.clone(), self.amount, self.asset, self.blinding_key);
54
55 if self.blinding_key.is_some() {
57 output.blinder_index = Some(0);
58 }
59
60 output
61 }
62}