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.
# The current input must be non-final so the transaction locktime is enforced.
Delete(x)
inputSequence = BVM.unlockingInput.Slice(36, 40)
NumEqualVerify(Equal(inputSequence, 0xffffffff), 0)
NumEqualVerify(GreaterOrEqual(BVM.locktime, self.timeout),1)
CheckSigVerify(sig, self.sender)