Skip to content

Commit

Permalink
refactor try_substitute_receiver_output for code reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
spacebear21 committed Jul 18, 2024
1 parent 8467c62 commit de88036
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 5 additions & 7 deletions payjoin/src/receive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,10 @@ impl ProvisionalProposal {
&mut self,
generate_script: impl Fn() -> Result<bitcoin::ScriptBuf, Error>,
) -> Result<(), Error> {
if self.params.disable_output_substitution {
return Err(Error::Server("Output substitution is disabled.".into()));
}
let substitute_script = generate_script()?;
self.payjoin_psbt.unsigned_tx.output[self.owned_vouts[0]].script_pubkey = substitute_script;
Ok(())
let output_value = self.payjoin_psbt.unsigned_tx.output[self.owned_vouts[0]].value;
let generate_outputs =
|| Ok(vec![TxOut { value: output_value, script_pubkey: generate_script()? }]);
self.try_substitute_receiver_outputs(Some(generate_outputs))
}

pub fn try_substitute_receiver_outputs(
Expand Down Expand Up @@ -542,7 +540,7 @@ impl ProvisionalProposal {
}
None => return Ok(()),
}
todo!();
Ok(())
}

/// Apply additional fee contribution now that the receiver has contributed input
Expand Down
7 changes: 7 additions & 0 deletions payjoin/src/receive/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ impl ProvisionalProposal {
self.inner.try_substitute_receiver_output(generate_script)
}

pub fn try_substitute_receiver_outputs(
&mut self,
generate_outputs: Option<impl Fn() -> Result<Vec<TxOut>, Error>>,
) -> Result<(), Error> {
self.inner.try_substitute_receiver_outputs(generate_outputs)
}

pub fn finalize_proposal(
self,
wallet_process_psbt: impl Fn(&Psbt) -> Result<Psbt, Error>,
Expand Down

0 comments on commit de88036

Please sign in to comment.