HTLC implementation manually

239 Views Asked by At

Is there any way to implement HTLC manually for locking funds in the channels in lightning network and releasing the funds after the time lock expired.

1

There are 1 best solutions below

2
Rene Pickhardt On

It is probably better to ask that question on https://bitcoin.stackexchange.com however if you look at the lightning network specification (aka BOLT) at BOLT 03 transactions you will for example find this script for a commitment transaction

# To remote node with revocation key
OP_DUP OP_HASH160 <RIPEMD160(SHA256(revocationpubkey))> OP_EQUAL
OP_IF
    OP_CHECKSIG
OP_ELSE
    <remote_htlcpubkey> OP_SWAP OP_SIZE 32 OP_EQUAL
    OP_NOTIF
        # To local node via HTLC-timeout transaction (timelocked).
        OP_DROP 2 OP_SWAP <local_htlcpubkey> 2 OP_CHECKMULTISIG
    OP_ELSE
        # To remote node with preimage.
        OP_HASH160 <RIPEMD160(payment_hash)> OP_EQUALVERIFY
        OP_CHECKSIG
    OP_ENDIF
OP_ENDIF

Also note that there is a standalone BIP 199 which is still a draft but specifies how to work with htlcs.