diff --git a/network/blockchain/contracts/multi_party_escrow/multi_party_escrow.sol b/network/blockchain/contracts/multi_party_escrow/multi_party_escrow.sol new file mode 100644 index 0000000..0098a05 --- /dev/null +++ b/network/blockchain/contracts/multi_party_escrow/multi_party_escrow.sol @@ -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; + } +}