pragma solidity ^0.8.13; contract PreimageBounty { struct Bounty { address payable payer; uint256 amount; uint256 deadline; } mapping(bytes32 => Bounty) private bounties; function lock(bytes32 hash, uint256 deadline) external payable { Bounty storage b = bounties[hash]; require(b.payer == address(0)); require(msg.value != 0); require(deadline > block.timestamp); b.payer = payable(msg.sender); b.amount = msg.value; b.deadline = deadline; } function claim(bytes32 hash, bytes calldata preimage) external { Bounty storage b = bounties[hash]; require(b.payer != address(0)); require(block.timestamp <= b.deadline); require(keccak256(preimage) == hash); uint256 amount = b.amount; delete bounties[hash]; (bool ok, ) = msg.sender.call{value: amount}(""); require(ok); } function abort(bytes32 hash) external { Bounty storage b = bounties[hash]; require(b.payer == msg.sender); require(block.timestamp > b.deadline); address payable payer = b.payer; uint256 amount = b.amount; delete bounties[hash]; (bool ok, ) = payer.call{value: amount}(""); require(ok); } }