Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public function to retrieve all contributions #76

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion contracts/ServiceNodeContribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,16 @@ contract ServiceNodeContribution is Shared {
"the contract, withdraw their funds and to re-initiate a new contract.");

// NOTE: Check contract status and collateral
require(amount >= minimumContribution(), "Contribution is below the minimum requirement.");
require(totalContribution() + amount <= stakingRequirement, "Contribution exceeds the funding goal.");
require(!finalized, "Node has already been finalized.");
require(!cancelled, "Node has been cancelled.");

// NOTE: Add the contributor to the contract
if (contributions[msg.sender] == 0) {
require(amount >= minimumContribution(), "Contribution is below the minimum requirement.");
contributorAddresses.push(msg.sender);
}
// else this is an existing contributor topping up an already-valid contribution

// NOTE: Update the amount contributed and transfer the tokens
contributions[msg.sender] += amount;
Expand Down Expand Up @@ -467,6 +468,21 @@ contract ServiceNodeContribution is Shared {
return result;
}

/**
* @notice Access the list of contributor addresses and corresponding contributions. The
* first returned address (if any) is also the operator address.
*/
function getContributions() public view returns (address[] memory addrs, uint256[] memory contribs) {
uint256 size = contributorAddresses.length;
addrs = new address[](size);
contribs = new uint256[](size);
for (uint256 i = 0; i < size; i++) {
addrs[i] = contributorAddresses[i];
contribs[i] = contributions[addrs[i]];
}
return (addrs, contribs);
}

/**
* @notice Sum up all the contributions recorded in the contributors list
*/
Expand Down
3 changes: 3 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ module.exports = {
},
},
},
paths: {
tests: "./test/unit-js"
},
};

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
"@nomicfoundation/hardhat-chai-matchers": "^2.0.2",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.10",
"@nomicfoundation/hardhat-toolbox": "^3.0.0",
"@nomicfoundation/hardhat-verify": "^1.1.1",
"@typechain/ethers-v6": "^0.4.3",
"@typechain/hardhat": "^8.0.3",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.3.11",
"@types/mocha": "^10.0.6",
"chai": "^4.3.10",
"ethers": "^6.4.0",
"hardhat": "^2.22.9",
"hardhat": "^2.22.10",
"hardhat-gas-reporter": "^1.0.9",
"solidity-coverage": "^0.8.5",
"ts-node": "^10.9.1",
"typechain": "^8.3.2",
"typescript": "^5.3.2"
},
"dependencies": {
"@openzeppelin/contracts": "^5.0.0",
"@openzeppelin/contracts": "^5.0.2",
"@openzeppelin/contracts-upgradeable": "^5.0.2",
"@openzeppelin/hardhat-upgrades": "^3.0.5",
"dotenv": "^16.4.5",
Expand Down
Loading