confirm_secret_for_address returns the previous secret
This commit is contained in:
parent
49c125f085
commit
8845942f32
@ -92,15 +92,16 @@ impl SecretsStore {
|
|||||||
self.unconfirmed_secrets.push(new_secret);
|
self.unconfirmed_secrets.push(new_secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn confirm_secret_for_address(&mut self, secret: AnkSharedSecretHash, address: SilentPaymentAddress) {
|
/// Returns the previous secret for this address, if any
|
||||||
|
pub fn confirm_secret_for_address(&mut self, secret: AnkSharedSecretHash, address: SilentPaymentAddress) -> Option<AnkSharedSecretHash> {
|
||||||
if let Some(pos) = self.unconfirmed_secrets.iter()
|
if let Some(pos) = self.unconfirmed_secrets.iter()
|
||||||
.position(|s| *s == secret)
|
.position(|s| *s == secret)
|
||||||
{
|
{
|
||||||
self.shared_secrets.insert(address, self.unconfirmed_secrets.swap_remove(pos));
|
self.shared_secrets.insert(address, self.unconfirmed_secrets.swap_remove(pos))
|
||||||
} else {
|
} else {
|
||||||
// We didn't know about that secret, just add it
|
// We didn't know about that secret, just add it
|
||||||
// TODO if we already had a secret for this address we just replace it for now
|
// TODO if we already had a secret for this address we just replace it for now
|
||||||
self.shared_secrets.insert(address, secret);
|
self.shared_secrets.insert(address, secret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user