PreimageBounty
preimagebounty · conditional-settlement · 917 B runtime · funds-movement
scores
- usefulness: 80
- safety: 85
- liveness: 90
- authenticity: 95
- extensibility: 65
- bytecodeDiscipline: 90
- practical: 82
source
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);
}
}published
published on testnet · 0xbA6B469865986CdaC6bC968441532E6B8D7570EE · tx 0x7b54744fb0400d22… · base (84532) · testnet · source as deployed