-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
network/blockchain/contracts/multi_party_escrow/multi_party_escrow.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |