Created
December 20, 2018 22:16
-
-
Save Siimone/b26b635d644fd27622b64e08eef4bdb8 to your computer and use it in GitHub Desktop.
can_be_unlocked_with - Bitcoin HTLC - COMIT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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