Skip to content

Commit

Permalink
chore: milestone installment amount show in cps treasury
Browse files Browse the repository at this point in the history
  • Loading branch information
naneey committed Jan 25, 2024
1 parent 9859573 commit 3770752
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
24 changes: 13 additions & 11 deletions CPSCore/src/main/java/community/icon/cps/score/cpscore/CPSCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2564,25 +2564,27 @@ public Map<String, Object> getProposalsHistory(@Optional int startIndex) {

@Override
@External(readonly = true)
public List<Integer> getRemainingMilestones(String ipfsHash){
public List<Map<String,?>> getRemainingMilestones(String ipfsHash){
String ipfsHashPrefix = proposalPrefix(ipfsHash);
ArrayDB<Integer> milestoneIDs = milestoneIds.at(ipfsHashPrefix);

List<Integer> milestoneIdList = new ArrayList<>();
for (int i = 0; i < milestoneIDs.size(); i++) {
int size = milestoneIDs.size();
List<Map<String,?>> milestoneIdList = new ArrayList<>();
for (int i = 0; i < size; i++) {
int milestoneId = milestoneIDs.get(i);
String milestonePrefix = mileStonePrefix(ipfsHash, milestoneId);
int proposalTotalPeriod = proposalPeriod.at(ipfsHashPrefix).getOrDefault(0);
int proposalPeriod = ProposalDataDb.proposalPeriod.at(ipfsHashPrefix).getOrDefault(0);
int completionPeriod = MilestoneDb.completionPeriod.at(milestonePrefix).getOrDefault(0);

int computedCompletionPeriod = proposalTotalPeriod + completionPeriod;
int computedCompletionPeriod = proposalPeriod + completionPeriod;

int currentPeriod = getPeriodCount();
if (computedCompletionPeriod > currentPeriod) {
int status = MilestoneDb.status.at(milestonePrefix).getOrDefault(0);
if (status != MILESTONE_REPORT_APPROVED ){
milestoneIdList.add(milestoneId);
}
int status = MilestoneDb.status.at(milestonePrefix).getOrDefault(0);

if (status != MILESTONE_REPORT_APPROVED ){
milestoneIdList.add(Map.of(MILESTONE_ID,milestoneId,
COMPLETION_PERIOD,computedCompletionPeriod,
BUDGET,MilestoneDb.budget.at(milestonePrefix).getOrDefault(BigInteger.ZERO))
);
}
}
return milestoneIdList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,14 @@ public BigInteger getOnsetPayment() {
BigInteger totalBudget = (BigInteger) proposal_details.get(consts.TOTAL_BUDGET);
BigInteger totalPaidAmount = (BigInteger) proposal_details.get(consts.WITHDRAW_AMOUNT);

BigInteger remainingAmount = totalBudget.subtract(totalPaidAmount);
Map<String, ?> project_details = Map.of(
consts.IPFS_HASH, _ipfs_key,
consts.TOKEN, flag,
consts.TOTAL_BUDGET, totalBudget,
consts.TOTAL_INSTALLMENT_PAID, totalPaidAmount,
consts.TOTAL_INSTALLMENT_COUNT, totalInstallment,
consts.TOTAL_TIMES_INSTALLMENT_PAID, totalPaidCount,
consts.INSTALLMENT_AMOUNT, remainingAmount.divide(BigInteger.valueOf(totalInstallment - totalPaidCount)));
consts.INSTALLMENT_AMOUNT, getInstallmetAmount(_ipfs_key));

projectDetails.add(project_details);

Expand Down Expand Up @@ -600,6 +599,11 @@ public void updateNewProjects(String oldHash, String newHash, int milestoneCount

}

private BigInteger getInstallmetAmount(String ipfsHash){
List<Map<String,?>> remainingMilestones = callScore(List.class,getCpsScore(),"getRemainingMilestones",ipfsHash);
BigInteger installmentAmount = (BigInteger) remainingMilestones.get(0).get(consts.BUDGET);
return installmentAmount;
}

public <T> T callScore(Class<T> t, Address address, String method, Object... params) {
return Context.call(t, address, method, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public consts() {
public static final String INSTALLMENT_AMOUNT = "installment_amount";
public static final String TOTAL_INSTALLMENT_COUNT = "total_installment_count";
public static final String SPONSOR_BOND_AMOUNT = "sponsor_bond_amount";
public static final String BUDGET = "budget";


}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public static class MilestoneVoteAttributes {
Map<String, Object> getProposalsHistory(@Optional int startIndex);

@External(readonly = true)
List<Integer> getRemainingMilestones(String ipfsHash);
List<Map<String,?>> getRemainingMilestones(String ipfsHash);

// EventLogs
@EventLog(indexed = 1)
Expand Down

0 comments on commit 3770752

Please sign in to comment.