Skip to content

Atomic Swap

Hash-lock claim plus timeout refund.

txt
# A two-branch lock: the receiver claims with a secret, or the sender refunds after time passes.
Contract AtomicSwap:

    def main(x: hex, sig: hex, path: number):
        if path == 1:
            # The claim branch proves the secret first, then checks the receiver signature.
            EqualVerify(Sha256(x), self.hashX)
            CheckSigVerify(sig, self.receiver)
        else:
            # The refund branch ignores the secret and only opens after the timeout.
            Delete(x)
            NumEqualVerify(GreaterOrEqual(BVM.locktime, self.timeout),1)
            CheckSigVerify(sig, self.sender)