-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTLC.sol
More file actions
28 lines (22 loc) · 740 Bytes
/
HTLC.sol
File metadata and controls
28 lines (22 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
pragma solidity ^0.8.0;
contract HTLC {
address payable public owner;
address payable public recipient;
uint256 public amount;
bytes32 public secret;
constructor(address payable _owner, address payable _recipient, uint256 _amount, bytes32 _secret) {
owner = _owner;
recipient = _recipient;
amount = _amount;
secret = _secret;
}
function redeem(bytes32 _secret) public {
require(msg.sender == recipient, "Only recipient can redeem");
require(_secret == secret, "Incorrect secret");
msg.sender.transfer(amount);
}
function refund() public {
require(msg.sender == owner, "Only owner can refund");
owner.transfer(amount);
}
}