Example #1
0
 @Override
 void validateAttachment(Transaction transaction) throws NxtException.ValidationException {
   Attachment.MonetarySystemCurrencyIssuance attachment =
       (Attachment.MonetarySystemCurrencyIssuance) transaction.getAttachment();
   if (attachment.getMaxSupply() > Constants.MAX_CURRENCY_TOTAL_SUPPLY
       || attachment.getMaxSupply() <= 0
       || attachment.getInitialSupply() < 0
       || attachment.getInitialSupply() > attachment.getMaxSupply()
       || attachment.getReserveSupply() < 0
       || attachment.getReserveSupply() > attachment.getMaxSupply()
       || attachment.getIssuanceHeight() < 0
       || attachment.getMinReservePerUnitNQT() < 0
       || attachment.getDecimals() < 0
       || attachment.getDecimals() > 8
       || attachment.getRuleset() != 0) {
     throw new NxtException.NotValidException(
         "Invalid currency issuance: " + attachment.getJSONObject());
   }
   int t = 1;
   for (int i = 0; i < 32; i++) {
     if ((t & attachment.getType()) != 0 && CurrencyType.get(t) == null) {
       throw new NxtException.NotValidException(
           "Invalid currency type: " + attachment.getType());
     }
     t <<= 1;
   }
   CurrencyType.validate(attachment.getType(), transaction);
   CurrencyType.validateCurrencyNaming(transaction.getSenderId(), attachment);
 }
Example #2
0
 @Override
 void undoAttachmentUnconfirmed(Transaction transaction, Account senderAccount) {
   Attachment.MonetarySystemReserveIncrease attachment =
       (Attachment.MonetarySystemReserveIncrease) transaction.getAttachment();
   long reserveSupply;
   Currency currency = Currency.getCurrency(attachment.getCurrencyId());
   if (currency != null) {
     reserveSupply = currency.getReserveSupply();
   } else { // currency must have been deleted, get reserve supply from the original issuance
            // transaction
     Transaction currencyIssuance =
         Nxt.getBlockchain().getTransaction(attachment.getCurrencyId());
     Attachment.MonetarySystemCurrencyIssuance currencyIssuanceAttachment =
         (Attachment.MonetarySystemCurrencyIssuance) currencyIssuance.getAttachment();
     reserveSupply = currencyIssuanceAttachment.getReserveSupply();
   }
   senderAccount.addToUnconfirmedBalanceNQT(
       Math.multiplyExact(reserveSupply, attachment.getAmountPerUnitNQT()));
 }