// Contract configuration options
options {
server = server;
exit = 144;
}
contract NonInteractiveSwap(
pubkey maker,
pubkey server,
bytes32 assetIdHash,
int amount,
int expiryTime
) {
// Maker can cancel the swap after expiry
function cancel(signature makerSig) {
require(tx.time >= expiryTime, "Swap has not expired yet");
require(checkSig(makerSig, maker), "Invalid maker signature");
}
// Anyone can complete the swap by providing the correct asset
function swap(bytes32 assetId, signature takerSig, pubkey taker) {
// Verify the asset being provided matches what the maker requested
require(sha256(assetId) == assetIdHash, "Asset ID doesn't match requested asset");
// Verify the output contains the correct amount going to the maker
require(tx.outputs[0].value >= amount, "Output amount too small");
require(tx.outputs[0].asset == assetId, "Output asset incorrect");
// Verify the output is spendable by the maker
bytes makerScript = new P2PKH(maker);
require(tx.outputs[0].scriptPubKey == makerScript, "Output not spendable by maker");
// Verify the taker signature
require(checkSig(takerSig, taker), "Invalid taker signature");
}
}