Skip to content

Instantly share code, notes, and snippets.

@Georgi87
Last active April 17, 2018 09:16
Show Gist options
  • Save Georgi87/bc65ef9857d06430b642b24f4d747089 to your computer and use it in GitHub Desktop.
Save Georgi87/bc65ef9857d06430b642b24f4d747089 to your computer and use it in GitHub Desktop.
contract PaymentHub {
uint256 public constant CHALLENGE_PERIOD = 7 days;
address public paymentHubOwner;
mapping(address => uint256) public balances;
mapping(address => uint256) public withdrawRequests;
function PaymentHub(address _paymentHubOwner)
public
{
require(_paymentHubOwner != 0);
paymentHubOwner = _paymentHubOwner;
}
function changeOwner(address _paymentHubOwner)
public
{
require(msg.sender == paymentHubOwner);
require(_paymentHubOwner != 0);
paymentHubOwner = _paymentHubOwner;
}
function deposit(address safeOwner)
public
payable
{
require(safeOwner != 0);
balances[safeOwner] += msg.value;
}
function withdrawalByPaymentHub(address gnosisSafe, uint256 fee, uint8 v, bytes32 r, bytes32 s)
public
{
require(msg.sender == paymentHubOwner);
address safeOwner = ecrecover(keccak256(this, gnosisSafe, fee), v, r, s);
require(balances[safeOwner] >= fee);
uint256 change = balances[safeOwner] - fee;
balances[safeOwner] = 0;
paymentHubOwner.send(fee);
gnosisSafe.send(change);
}
function withdrawalRequestBySafeOwner()
public
{
withdrawRequests[msg.sender] = now;
}
function withdrawalBySafeOwner()
public
{
require(withdrawRequests[msg.sender] > 0);
require(now - withdrawRequests[msg.sender] > CHALLENGE_PERIOD);
withdrawRequests[msg.sender] = 0;
uint256 balance = balances[msg.sender];
balances[msg.sender] = 0;
msg.sender.send(balance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment