Skip to content

Instantly share code, notes, and snippets.

@Siimone
Created December 20, 2018 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Siimone/b26b635d644fd27622b64e08eef4bdb8 to your computer and use it in GitHub Desktop.
Save Siimone/b26b635d644fd27622b64e08eef4bdb8 to your computer and use it in GitHub Desktop.
can_be_unlocked_with - Bitcoin HTLC - COMIT
pub fn can_be_unlocked_with(
&self,
got_secret: Secret,
got_keypair: KeyPair,
) -> Result<(), UnlockingError> {
let got_pubkey_hash: PubkeyHash = got_keypair.public_key().into();
let got_secret_hash = got_secret.hash();
let expected_pubkey_hash = self.recipient_redeem_pubkey_hash;
let expected_secret_hash = &self.secret_hash;
if *expected_secret_hash != got_secret_hash {
return Err(UnlockingError::WrongSecret {
got: got_secret_hash,
expected: expected_secret_hash.clone(),
});
}
if expected_pubkey_hash != got_pubkey_hash {
return Err(UnlockingError::WrongKeyPair {
keypair: got_keypair,
got: got_pubkey_hash,
expected: expected_pubkey_hash,
});
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment