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