Skip to main content

htlc_script

Function htlc_script 

Source
pub fn htlc_script(
    payment_hash: &[u8; 32],
    receiver_pubkey_hash: &[u8; 20],
    sender_pubkey_hash: &[u8; 20],
    timeout: u32,
) -> Vec<u8> 
Expand description

Build an HTLC (Hash Time-Locked Contract) script.

Script:

OP_IF
  OP_SHA256 <hash> OP_EQUALVERIFY
  <receiver_pubkey_hash> OP_CHECKSIG          // hashlock path
OP_ELSE
  <timeout> OP_CLTV OP_DROP
  <sender_pubkey_hash> OP_CHECKSIG            // timelock refund path
OP_ENDIF

§Arguments

  • payment_hash — 32-byte SHA-256 hash of the preimage
  • receiver_pubkey_hash — 20-byte HASH160 of receiver
  • sender_pubkey_hash — 20-byte HASH160 of sender (refund)
  • timeout — CLTV timeout for the refund path