Skip to content

Commit

Permalink
Merge pull request #67 from uniworld-io/fixClaimFuture
Browse files Browse the repository at this point in the history
- review safely math cal
  • Loading branch information
realelonmusk102 committed Feb 14, 2022
2 parents 4ae23b4 + b563c91 commit 8be7fac
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 59 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

group 'org.unichain'
version '2.0.5-SNAPSHOT'
version '2.0.5'

apply plugin: 'java'
apply plugin: 'com.google.protobuf'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
- don't charge token fee
*/
if(isCreateNewAcc)
{
dbManager.adjustBalanceNoPut(ownerAccountCap, -dbManager.getDynamicPropertiesStore().getCreateNewAccountFeeInSystemContract());
}

ownerAccountCap.burnToken(tokenKey, ctx.getAmount());
dbManager.getAccountStore().put(ownerAddr, ownerAccountCap);
Expand Down
68 changes: 16 additions & 52 deletions src/main/java/org/unichain/core/db/StorageMarket.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,35 @@ public StorageMarket(Manager manager) {
}

private long exchange_to_supply(boolean isUNW, long quant) {
logger.info("isUNW: " + isUNW);
long balance = isUNW ? dbManager.getDynamicPropertiesStore().getTotalStoragePool() :
dbManager.getDynamicPropertiesStore().getTotalStorageReserved();
logger.info("balance: " + balance);
long newBalance = balance + quant;
logger.info("balance + quant: " + (balance + quant));

// if (isUNW) {
// dbManager.getDynamicPropertiesStore().saveTotalStoragePool(newBalance);
// } else {
// dbManager.getDynamicPropertiesStore().saveTotalStorageReserved(newBalance);
// }

long newBalance = Math.addExact(balance, quant);
double issuedSupply = -supply * (1.0 - Math.pow(1.0 + (double) quant / newBalance, 0.0005));
logger.info("issuedSupply: " + issuedSupply);
long out = (long) issuedSupply;
supply += out;

supply = Math.addExact(supply, out);
return out;
}

private long exchange_to_supply2(boolean isUNW, long quant) {
logger.info("isUNW: " + isUNW);
long balance = isUNW ? dbManager.getDynamicPropertiesStore().getTotalStoragePool() :
dbManager.getDynamicPropertiesStore().getTotalStorageReserved();
logger.info("balance: " + balance);
long newBalance = balance - quant;
logger.info("balance - quant: " + (balance - quant));

// if (isUNW) {
// dbManager.getDynamicPropertiesStore().saveTotalStoragePool(newBalance);
// } else {
// dbManager.getDynamicPropertiesStore().saveTotalStorageReserved(newBalance);
// }

long newBalance = Math.subtractExact(balance, quant);
double issuedSupply = -supply * (1.0 - Math.pow(1.0 + (double) quant / newBalance, 0.0005));
logger.info("issuedSupply: " + issuedSupply);
long out = (long) issuedSupply;
supply += out;

supply = Math.addExact(supply, out);
return out;
}

private long exchange_from_supply(boolean isUNW, long supplyQuant) {
long balance = isUNW ? dbManager.getDynamicPropertiesStore().getTotalStoragePool() :
dbManager.getDynamicPropertiesStore().getTotalStorageReserved();
supply -= supplyQuant;
supply =Math.subtractExact(supply, supplyQuant);

double exchangeBalance =
balance * (Math.pow(1.0 + (double) supplyQuant / supply, 2000.0) - 1.0);
logger.info("exchangeBalance: " + exchangeBalance);
double exchangeBalance = balance * (Math.pow(1.0 + (double) supplyQuant / supply, 2000.0) - 1.0);
long out = (long) exchangeBalance;

if (isUNW) {
out = Math.round(exchangeBalance / 100000) * 100000;
logger.info("---out: " + out);
}

return out;
}

Expand All @@ -97,17 +68,13 @@ public long tryPayTax(long duration, long limit) {
long tax = exchange(storageTax, false);
logger.info("tax: " + tax);

long newTotalTax = dbManager.getDynamicPropertiesStore().getTotalStorageTax() + tax;
long newTotalPool = dbManager.getDynamicPropertiesStore().getTotalStoragePool() - tax;
long newTotalReserved = dbManager.getDynamicPropertiesStore().getTotalStorageReserved()
+ storageTax;
long newTotalTax = Math.addExact(dbManager.getDynamicPropertiesStore().getTotalStorageTax(), tax);
long newTotalPool = Math.subtractExact(dbManager.getDynamicPropertiesStore().getTotalStoragePool(), tax);
long newTotalReserved = Math.addExact(dbManager.getDynamicPropertiesStore().getTotalStorageReserved(), storageTax);
logger.info("reserved: " + dbManager.getDynamicPropertiesStore().getTotalStorageReserved());
boolean eq = dbManager.getDynamicPropertiesStore().getTotalStorageReserved()
== 128L * 1024 * 1024 * 1024;
boolean eq = dbManager.getDynamicPropertiesStore().getTotalStorageReserved() == 128L * 1024 * 1024 * 1024;
logger.info("reserved == 128GB: " + eq);
logger.info("newTotalTax: " + newTotalTax + " newTotalPool: " + newTotalPool
+ " newTotalReserved: " + newTotalReserved);

logger.info("newTotalTax: " + newTotalTax + " newTotalPool: " + newTotalPool + " newTotalReserved: " + newTotalReserved);
return storageTax;
}

Expand All @@ -116,16 +83,13 @@ public long payTax(long duration, long limit) {
long tax = exchange(storageTax, false);
logger.info("tax: " + tax);

long newTotalTax = dbManager.getDynamicPropertiesStore().getTotalStorageTax() + tax;
long newTotalPool = dbManager.getDynamicPropertiesStore().getTotalStoragePool() - tax;
long newTotalReserved = dbManager.getDynamicPropertiesStore().getTotalStorageReserved()
+ storageTax;
long newTotalTax = Math.addExact(dbManager.getDynamicPropertiesStore().getTotalStorageTax(), tax);
long newTotalPool = Math.subtractExact(dbManager.getDynamicPropertiesStore().getTotalStoragePool(), tax);
long newTotalReserved = Math.addExact(dbManager.getDynamicPropertiesStore().getTotalStorageReserved(), storageTax);
logger.info("reserved: " + dbManager.getDynamicPropertiesStore().getTotalStorageReserved());
boolean eq = dbManager.getDynamicPropertiesStore().getTotalStorageReserved()
== 128L * 1024 * 1024 * 1024;
boolean eq = dbManager.getDynamicPropertiesStore().getTotalStorageReserved() == 128L * 1024 * 1024 * 1024;
logger.info("reserved == 128GB: " + eq);
logger.info("newTotalTax: " + newTotalTax + " newTotalPool: " + newTotalPool
+ " newTotalReserved: " + newTotalReserved);
logger.info("newTotalTax: " + newTotalTax + " newTotalPool: " + newTotalPool + " newTotalReserved: " + newTotalReserved);
dbManager.getDynamicPropertiesStore().saveTotalStorageTax(newTotalTax);
dbManager.getDynamicPropertiesStore().saveTotalStoragePool(newTotalPool);
dbManager.getDynamicPropertiesStore().saveTotalStorageReserved(newTotalReserved);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class GetAccountByIdServlet extends HttpServlet {
private Wallet wallet;

private String convertOutput(Account account) {
// convert asset id
if (account.getAssetIssuedID().isEmpty()) {
return JsonFormat.printToString(account, false);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private String convertOutput(FuturePack futurePack) {
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) {

doPost(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private String convertOutput(Protocol.FutureTokenPack tokenPool) {
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) {

doPost(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private String convertOutput(Contract.TokenPage page) {
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) {

doPost(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) {
Expand Down
4 changes: 2 additions & 2 deletions ver.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -x
versionName='2.0.4'
versionCode='204'
versionName='2.0.5'
versionCode='205'

versionPath="src/main/java/org/unichain/program/Version.java"
sed -i -e "s/versionName.*$/versionName = \"$versionName\";/g;s/versionCode.*$/versionCode = \"$versionCode\";/g" $versionPath
Expand Down

0 comments on commit 8be7fac

Please sign in to comment.