Skip to content

Commit

Permalink
Added the NatsSpec Documentation Standard
Browse files Browse the repository at this point in the history
Commented all functions and public Variables
  • Loading branch information
arcteggzz committed Apr 15, 2022
1 parent a6ad7c9 commit 5e5b739
Showing 1 changed file with 43 additions and 23 deletions.
66 changes: 43 additions & 23 deletions hardhat/contracts/DecentralizedLibrary.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/// @title A decentralized Library for uploading, retrieving and sharing files
/// @author Team Buterin-BlockGames Zuri
/// @notice You can use this contract to upload, retrieve and share files to a decetralized Library
/// @dev All functions currently run without errors or unexpected outputs. The Library is a web3 version of the IPFS system
/// @custom: An experimental and Proof Of Concept contract deployed for testing purposes only.
contract DecentralizedLibrary {
//Variables
address[] public upLoaders; //Variable to track the addressees that has uploaded
mapping(address => string[]) public _uploadedCIDS; //Variable to track the uploaded cids of an address
/// @notice Public Variable to track the addresses that has uploaded
/// @dev Variable is an array of addresses
address[] public upLoaders;
/// @notice Public Variable to track the uploaded hashes of the metadata of files uploaded by an address
/// @dev Variable is an array of strings. Each upload generates a string and that string is stored in an array an passed into this variable
mapping(address => string[]) public _uploadedCIDS;

//FUNCTION 01
//first upload oooof
/// @notice Upload a file as a first-time user of the Library
/// @dev Update the mapping based on the address calling the function with the array of uploaded hashes
/// @param _cidsToUpload The Array list of hashes to upload to IPFS
function _upload(string[] memory _cidsToUpload) public {
_uploadedCIDS[msg.sender] = _cidsToUpload;
upLoaders.push(msg.sender);
}

//FUNCTION 02
//subsequent uploads
/// @notice Upload a file as an existing user of the Library
/// @dev Update the mapping based on the address calling the function with the array of uploaded hashes
/// @dev Call the _addTwoArrays to add the new list of hashes to the existing list
/// @param _newCidsToUpload The Array list of hashes to upload to IPFS
function _subsequentUpload(string[] memory _newCidsToUpload) public {
// string[] memory _existingCIDS;
// _existingCIDS = _getListOfUploadedCIDS(msg.sender);
Expand All @@ -24,8 +34,10 @@ contract DecentralizedLibrary {
_uploadedCIDS[msg.sender] = _updatedCIDS;
}

//FUNCTION 03
//view all uploads of an address
/// @notice Get a list of uploaded hashes from the Library
/// @dev view function to return an array of strings representing the hashes of uploaded files
/// @param _address The address to check it's uploaded files
/// @return An array of strings, representing the uploaded hashes of metadata files to IPFS
function _getListOfUploadedCIDS(address _address)
public
view
Expand All @@ -34,28 +46,34 @@ contract DecentralizedLibrary {
return _uploadedCIDS[_address];
}

//FUNCTION 04
//share an array of cids with an existing address
/// @notice Share files with an existing customer in the Library
/// @dev Update the recipients mapping address with the list of shared files
/// @param _cidsToShare An array of strings to hold the hashes of files to share
/// @param _address The address to share the files with
function _shareWithExisting(string[] memory _cidsToShare, address _address)
public
{
// string[] memory _existingCIDS;
// _existingCIDS = _getListOfUploadedCIDS(_address);
string[] memory _updatedCIDS;
_updatedCIDS = _addTwoArrays(_address, _cidsToShare); //helper function 1
_updatedCIDS = _addTwoArrays(_address, _cidsToShare);
_uploadedCIDS[_address] = _updatedCIDS;
}

//FUNCTION 05
//share an array of cids with a new address
//// @notice Share files with a non existing customer in the Library
/// @dev Update the recipients mapping address with the list of shared files
/// @param _cidsToShare An array of strings to hold the hashes of files to share
/// @param _address The address to share the files with
function _shareWithNew(string[] memory _cidsToShare, address _address)
public
{
upLoaders.push(_address);
_uploadedCIDS[_address] = _cidsToShare;
}

//HELPER FUNCTION 01
/// @notice Adds two arrays of strings together
/// @dev Retrieve the array of existing hashes and add to it, the elements of another similar array
/// @param _address The address to check it's existing hashes
/// @param _newCidsToUpload The new set of hashes to add to the existing
/// @return An array of strings, representing the total hashes of existing and new hashes
function _addTwoArrays(address _address, string[] memory _newCidsToUpload)
public
returns (string[] memory)
Expand All @@ -67,14 +85,16 @@ contract DecentralizedLibrary {
return _updatedCIDS; //final array is updated
}

//HELPER FUNCTION 02
//return ether balance of the wallet calling the function
/// @notice Get balance of address calling function
/// @return ether balance of the wallet calling the function
function viewBalance() public view returns (uint256) {
return msg.sender.balance;
return address(msg.sender).balance;
}

//HELPER FUNCTION 03
//confirm if address is in the mapping
/// @notice Check if an address is an existing user of the Library
/// @dev confirm if address is in the User Array
/// @param _address The address to check it's an existing user
/// @return boolean, whether an address is existing in the Users Array
function isAnUploader(address _address) public view returns (bool) {
for (uint8 s = 0; s < upLoaders.length; s += 1) {
if (_address == upLoaders[s]) return (true);
Expand Down

0 comments on commit 5e5b739

Please sign in to comment.