Skip to content

Instantly share code, notes, and snippets.

@MCarlomagno
Created February 8, 2022 18:52
Show Gist options
  • Save MCarlomagno/3a6f4653baf53fe36261b8f7f2a69b70 to your computer and use it in GitHub Desktop.
Save MCarlomagno/3a6f4653baf53fe36261b8f7f2a69b70 to your computer and use it in GitHub Desktop.
pragma solidity >=0.7.0 <0.9.0;
import "github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.3/contracts/cryptography/ECDSA.sol";
import "github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.3/contracts/utils/ReentrancyGuard.sol";
contract UniDirectionalPaymentChannel is ReentrancyGuard {
// ...
function send(uint _amount, bytes memory _sig) external nonReentrant {
// verifing signature and sender != receiver
require(msg.sender == receiver, "sender must be different than receiver");
require(_verify(_amount, _sig), "invalid signature");
(bool sent, ) = receiver.call{value: _amount}("");
require(sent, "Failed to send Ether");
selfdestruct(sender);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment