-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c0c81f
commit a82659f
Showing
10 changed files
with
1,072 additions
and
1,475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,68 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.12; | ||
|
||
contract TestSwap { | ||
import "@rsksmart/rif-relay-contracts/contracts/interfaces/BoltzVerifier.sol"; | ||
|
||
contract TestSwap is NativeSwap { | ||
|
||
uint8 constant public version = 3; | ||
|
||
bytes32 public DOMAIN_SEPARATOR; | ||
bytes32 public TYPEHASH_REFUND; | ||
|
||
mapping (bytes32 => bool) public override swaps; | ||
|
||
function addSwap(bytes32 hash) public { | ||
swaps[hash] = true; | ||
} | ||
|
||
function claim( | ||
bytes32 preimage, | ||
uint amount, | ||
address claimAddress, | ||
address refundAddress, | ||
uint timelock | ||
) external { | ||
(bool success, ) = payable(msg.sender).call{value: amount}(""); | ||
require(success, "Could not transfer Ether"); | ||
|
||
bytes32 preimageHash = sha256(abi.encodePacked(preimage)); | ||
|
||
bytes32 hash = hashValues( | ||
preimageHash, | ||
amount, | ||
claimAddress, | ||
refundAddress, | ||
timelock | ||
); | ||
|
||
checkSwapIsLocked(hash); | ||
|
||
delete swaps[hash]; | ||
|
||
(bool success, ) = payable(claimAddress).call{value: amount}(""); | ||
require(success, "Could not transfer RBTC"); | ||
} | ||
|
||
function hashValues( | ||
bytes32 preimageHash, | ||
uint amount, | ||
address claimAddress, | ||
address refundAddress, | ||
uint timelock | ||
) public override pure returns (bytes32) { | ||
return keccak256(abi.encodePacked( | ||
preimageHash, | ||
amount, | ||
claimAddress, | ||
refundAddress, | ||
timelock | ||
)); | ||
} | ||
|
||
function checkSwapIsLocked(bytes32 hash) private view { | ||
require(swaps[hash] == true, "NativeSwap: swap has no RBTC locked in the contract"); | ||
} | ||
|
||
// solhint-disable-next-line no-empty-blocks | ||
receive() external payable {} | ||
receive() external payable {} | ||
|
||
} |
Oops, something went wrong.