Skip to content

Instantly share code, notes, and snippets.

@Siimone
Created December 19, 2018 11:33
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/f58237af6260b724fe197a6f2e8c9190 to your computer and use it in GitHub Desktop.
Save Siimone/f58237af6260b724fe197a6f2e8c9190 to your computer and use it in GitHub Desktop.
Bitcoin HTLC constructor - COMIT
fn create_htlc(
recipient_pubkey_hash: &PubkeyHash,
sender_pubkey_hash: &PubkeyHash,
secret_hash: &[u8],
redeem_block_height: u32,
) -> Script {
let script = Builder::new()
.push_opcode(OP_IF)
.push_opcode(OP_SHA256)
.push_slice(secret_hash)
.push_opcode(OP_EQUALVERIFY)
.push_opcode(OP_DUP)
.push_opcode(OP_HASH160)
.push_slice(recipient_pubkey_hash.as_ref())
.push_opcode(OP_ELSE)
.push_int(i64::from(redeem_block_height))
.push_opcode(OP_CHECKSEQUENCEVERIFY)
.push_opcode(OP_DROP)
.push_opcode(OP_DUP)
.push_opcode(OP_HASH160)
.push_slice(sender_pubkey_hash.as_ref())
.push_opcode(OP_ENDIF)
.push_opcode(OP_EQUALVERIFY)
.push_opcode(OP_CHECKSIG)
.into_script();
trace!("BTC HTLC: {}", script);
script
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment