Skip to content

Commit

Permalink
Create multi_party_escrow.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jun 19, 2024
1 parent e777f28 commit 8e476d1
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
pragma solidity ^0.8.0;

contract MultiPartyEscrow {
address[] public parties;
mapping (address => uint) public deposits;
mapping (address => bool) public hasFulfilled;
uint public totalDeposits;
uint public requiredDeposits;
uint public deadline;

constructor(address[] memory _parties, uint _requiredDeposits, uint _deadline) public {
parties = _parties;
requiredDeposits = _requiredDeposits;
deadline = _deadline;
}

function deposit() public payable {
require(msg.sender!= address(0), "Invalid sender");
require(deposits[msg.sender] == 0, "Already deposited");
deposits[msg.sender] = msg.value;
totalDeposits += msg.value;
if (totalDeposits >= requiredDeposits) {
executeAgreement();
}
}

function fulfillObligation() public {
require(hasFulfilled[msg.sender] == false, "Already fulfilled");
hasFulfilled[msg.sender] = true;
if (allPartiesHaveFulfilled()) {
executeAgreement();
}
}

function executeAgreement() internal {
// execute the agreement logic here
// e.g. transfer funds, update state, etc.
}

function allPartiesHaveFulfilled() internal view returns (bool) {
for (uint i = 0; i < parties.length; i++) {
if (!hasFulfilled[parties[i]]) {
return false;
}
}
return true;
}
}

0 comments on commit 8e476d1

Please sign in to comment.