[experimental] identify transaction we sent according to commitment value
This commit is contained in:
parent
1f689d33c3
commit
de133cc0a3
@ -508,9 +508,33 @@ fn handle_recover_transaction(
|
||||
} else {
|
||||
// We are sender of a transaction
|
||||
// We only need to return the message
|
||||
// eiter this is notification, a challenge, or response to a challenge
|
||||
// if notification, commitment is the same than in the message
|
||||
// if challenge or response, commitment is H(commitment | b_scan), b_scan being different depending on who we are
|
||||
if let Some(message) = messages
|
||||
.iter()
|
||||
.find(|m| m.commitment.as_ref() == Some(&commitment_str))
|
||||
.find(|m| {
|
||||
if commitment.is_empty() || m.commitment.is_none() { return false }
|
||||
match m.status {
|
||||
CachedMessageStatus::SentWaitingConfirmation => {
|
||||
// commitment we're looking for is simply what's in the message
|
||||
m.commitment.as_ref().map(|c| Vec::from_hex(&c).unwrap()).unwrap() == commitment
|
||||
},
|
||||
CachedMessageStatus::MustSpendConfirmation | CachedMessageStatus::ReceivedMustConfirm => {
|
||||
// we compute the potential commitment
|
||||
let m_commitment = m.commitment.as_ref().map(|c| Vec::from_hex(&c).unwrap()).unwrap();
|
||||
let mut buf = [0u8;64];
|
||||
buf[..32].copy_from_slice(&m_commitment);
|
||||
buf[32..].copy_from_slice(&sp_wallet.get_client().get_scan_key().secret_bytes());
|
||||
|
||||
let mut engine = sha256::HashEngine::default();
|
||||
engine.write_all(&buf).unwrap();
|
||||
let hash = sha256::Hash::from_engine(engine);
|
||||
hash.to_byte_array().to_vec() == commitment
|
||||
},
|
||||
_ => return false
|
||||
}
|
||||
})
|
||||
{
|
||||
return Ok(message.clone());
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user