Add optional payload to create_transaction_spend_outpoint
This commit is contained in:
parent
3f96ce339b
commit
066410ec63
@ -77,6 +77,7 @@ pub fn create_transaction_spend_outpoint(
|
||||
sp_wallet: &SpWallet,
|
||||
mut recipient: Recipient,
|
||||
commited_in_txid: &Txid,
|
||||
payload: Option<Vec<u8>>,
|
||||
fee_rate: Amount
|
||||
) -> Result<Psbt> {
|
||||
let available_outpoints = sp_wallet.get_outputs().to_spendable_list();
|
||||
@ -105,19 +106,30 @@ pub fn create_transaction_spend_outpoint(
|
||||
// Take the recipient address
|
||||
let address = recipient.address.clone();
|
||||
|
||||
// create a dummy commitment that is H(b_scan | commited_in txid)
|
||||
let mut buf = [0u8;64];
|
||||
buf[..32].copy_from_slice(commited_in_txid.as_raw_hash().as_byte_array());
|
||||
buf[32..].copy_from_slice(&sp_wallet.get_client().get_scan_key().secret_bytes());
|
||||
|
||||
let mut engine = sha256::HashEngine::default();
|
||||
engine.write_all(&buf)?;
|
||||
let hash = sha256::Hash::from_engine(engine);
|
||||
let mut commitment = [0u8;32];
|
||||
if let Some(p) = payload {
|
||||
let mut engine = sha256::HashEngine::default();
|
||||
engine.write_all(&p)?;
|
||||
let hash = sha256::Hash::from_engine(engine);
|
||||
|
||||
commitment.copy_from_slice(hash.as_byte_array());
|
||||
} else {
|
||||
// create a dummy commitment that is H(b_scan | commited_in txid)
|
||||
let mut buf = [0u8;64];
|
||||
buf[..32].copy_from_slice(commited_in_txid.as_raw_hash().as_byte_array());
|
||||
buf[32..].copy_from_slice(&sp_wallet.get_client().get_scan_key().secret_bytes());
|
||||
|
||||
let mut engine = sha256::HashEngine::default();
|
||||
engine.write_all(&buf)?;
|
||||
let hash = sha256::Hash::from_engine(engine);
|
||||
|
||||
commitment.copy_from_slice(hash.as_byte_array());
|
||||
}
|
||||
|
||||
let mut new_psbt = sp_wallet.get_client().create_new_psbt(
|
||||
inputs,
|
||||
vec![recipient],
|
||||
Some(hash.as_byte_array()),
|
||||
Some(&commitment),
|
||||
)?;
|
||||
|
||||
SpClient::set_fees(&mut new_psbt, fee_rate, address)?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user