function approve_bymediator(bool _destinOrOrigin) public payable{
require(msg.sender == __mediator); // Restricts the execution to mediator role
require(__conflictFlag); // R4.3, check for a conflict request
require(address(this).balance > 0); // R3.1, check for non-null balance
require(__balanceIsLocked, 'There is no locked balance to approve to be unlocked.'); // R3.2, check for balance lock
if (_destinOrOrigin)
payable(__receiver).transfer(address(this).balance); // R3.3, R7.2.2, recipient is the receiver
else
payable(__payer).transfer(address(this).balance); // R3.3, R7.2.1, recipient is the payer
__balanceIsLocked = false; // R2.2, release balance unlock flag
__conflictFlag = false; // R4.4, release conflict flag
}
Last active
March 23, 2022 18:49
-
-
Save pvrego/9ed3753a532d5575e73de96a4a6a1a06 to your computer and use it in GitHub Desktop.
ABC Wallet
function approve_bypayer() public payable{
require(msg.sender == __payer); // Restricts the execution to payer role
require(address(this).balance > 0); // R3.1, check for non-null balance
require(__balanceIsLocked, 'There is no locked balance to approve to be unlocked.'); // R3.2, check for balance lock
require(!__conflictFlag, 'A conflict has been requested, approval authority has been transfer to the mediator.'); // R5.1, check for not conflict request
payable(__receiver).transfer(address(this).balance); // R3.3, recipient is the receiver
__balanceIsLocked = false; // R2.2, release balance unlock flag
}
function approve_byreceiver() public payable{
require(msg.sender == __receiver); // Restricts the execution to receiver role
require(address(this).balance > 0); // R3.1, check for non-null balance
require(__balanceIsLocked, 'There is no locked balance to approve to be unlocked.'); // R3.2, check for balance lock
require(!__conflictFlag, 'A conflict has been requested, approval authority has been transfer to the mediator.'); // R6.1, check for not conflict request
payable(__payer).transfer(address(this).balance); // R3.3, recipient is the payer
__balanceIsLocked = false; // R2.2, release balance unlock flag
}
constructor(address _newPayer, address _newReceiver, uint _depositMin){
require(_depositMin > 0); // R2.3, non-nullity
__depositMinAllowed = _depositMin; // R2.3, definition of min deposit value
__payer = _newPayer; // R4.1, assignment of the payer role
__receiver = _newReceiver; // R4.1, assignment of the receiver role
__mediator = __owner; // Mediator role is the contract, by design
}
function deposit() public payable{
// R2.1. In order to avoid infinite locks from deposits, once a deposit is made, the balance is locked, and a new deposit
// will only be allowed when an approval occur
require(!__balanceIsLocked, 'Current balance is locked. Unlocking is required before allowing new deposits.');
// R2.3, min amount for deposit
require(msg.value > __depositMinAllowed);
// R2.1, Locks the deposited balance until next withdrawal approval
__balanceIsLocked = true;
}
function raise_conflict() public{
require(msg.sender == __receiver || msg.sender == __payer); // R7.3, restricts to payer or receiver roles
require(address(this).balance > 0); // R7.5, check for non-null balance
require(__balanceIsLocked, 'There is no locked balance to approve to be unlocked.'); // R7.6, check for balance lock
require(!__conflictFlag, 'A conflict request has already been made.'); // R7.4, unicity of conflict request
__conflictFlag = true; // Raises the conflict flag
}
constructor(address _newPayer, address _newReceiver, uint _depositMin)
receive() external payable{}
fallback() external{}
function deposit() public payable
function approve_bypayer() public payable
function approve_bymediator(bool _destinOrOrigin) public payable
function approve_byreceiver() public payable
function raise_conflict() public
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment