Skip to content
Open
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
74 changes: 38 additions & 36 deletions contract/contracts/Commitment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,69 @@ import './interface/ICommitment.sol';

contract Commitment is ICommitment {

mapping(address => Commitment[]) userCommitments;
/************************************************
* Variable and Constraint
***********************************************/

mapping(address => mapping(uint256 =>Commitment)) userCommitments;
uint256 constant MAX_COMMITMENT_LENGTH = 9;

/************************************************
* Getters
***********************************************/

// commitment is so long
// commitments => coms

/// get user's commitment length
function getComsLength(address _address) public view returns (uint256 length) {
length = userCommitments[_address].length;
}

/// get user's all commitments
function getAllComs(address _address) public view returns (Commitment[] memory commitments) {
uint256 length = getComsLength(_address);
for (uint256 i = 0; i < length; i++) {
commitments[i] = userCommitments[_address][i];
}
}

/// get target commitment
function getTargetCom(address _address, uint256 _id) private view returns (Commitment memory commitment) {
uint256 length = getComsLength(_address);
Commitment[] memory commtiments = getAllComs(_address);
uint256 targetIndex;
for (uint256 i = 0; i < length; i++) {
if (commtiments[i].id == _id) targetIndex = i;
}
commitment = userCommitments[_address][targetIndex];
/**
* @notice Gets the last day of the month
* @param _address is user address
* @param _id is commitment identfier
* @return commitment from the userCommitment mapping
*/
function getTargetCommitment(address _address, uint256 _id) external view returns (Commitment memory commitment) {
commitment = userCommitments[_address][_id];
}

/************************************************
* Add
***********************************************/

/// add commitment
function addCom(
/**
* @notice Add commitment
* @param _address is user address
* @param _id is commitment identfier
* @param _hash is commitment hash
* @param _groupId is identifier of group from group.json
* @param _userId is user identifier
* @param _createdAt is the time when creating this commitment
*/
function addCommitment(
address _address,
uint256 _id,
bytes32 _data,
uint256 _groupId,
string calldata _userId,
bytes32 _hash,
bytes32 _userId,
bytes16 _groupId,
uint256 _createdAt
) external {
userCommitments[_address].push(Commitment(_id, _userId, _groupId, _data, '', address(0), _createdAt));
userCommitments[_address][_id] = Commitment(_id, _userId, _hash,address(0), _createdAt,_groupId,"");
}

/************************************************
* Update
***********************************************/

/// update commitment
function updateCom(
/**
* @notice Update commitment
* @param _metadta is metadata of NFT
* @param _address is user address to send NFT
* @param _address is user address
* @param _id is commitment identfier
*/
function updateCommitment(
string calldata _metadta,
address _mintAddress,
address _address,
uint256 _id
) external view {
Commitment memory commitment = getTargetCom(_address, _id);
) external {
Commitment storage commitment = userCommitments[_address][_id];
commitment.metadata = _metadta;
commitment.mintAddress = _mintAddress;
}
Expand Down
29 changes: 22 additions & 7 deletions contract/contracts/Group.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ pragma solidity ^0.8.4;
import './interface/IGroup.sol';

contract Group is IGroup {


/************************************************
* Variable and Constraint
***********************************************/

// @dev
// 49 is come from the amounts of object. /frontend/scripts/groups.json
uint256 public constant size = 49;
Group[size] public groups;
uint256[size] public groupIds;
Expand All @@ -16,28 +20,39 @@ contract Group is IGroup {
* Initialization
***********************************************/

/**
* @notice Initializing groups
* @param _groups is the objects of groups.json
*/
function initialGroups(Group[size] calldata _groups) external {
for (uint256 i = 0; i < size; i++) {
groups[i] = _groups[i];
groupIds[i] = _groups[i].id;
groupNullfiers[i] = _groups[i].nullfier;
groupNullfiers[i] = _groups[i].nullifier;
}
}

/************************************************
* Getters
***********************************************/

function getGroups() external view returns (Group[49] memory _groups) {
_groups = groups;

/**
* @notice Initializing groups
* @return _allGroups is retrn all gropus(49 groups)
*/
function getGroups() external view returns (Group[size] memory _allGroups) {
_allGroups = groups;
}

/// get "group" from _id
function getGroup(uint256 _id) external view returns (Group memory group) {
/**
* @notice get a group from id
* @return _group is retrn target gropus(1 group)
*/
function getGroup(uint256 _id) external view returns (Group memory _group) {
uint256 idsIndex;
for (uint256 i = 0; i < size; i++) {
if (_id == groupIds[i]) idsIndex = i;
}
group = groups[idsIndex];
_group = groups[idsIndex];
}
}
Loading