Example #1
0
 @Override
 void validateAttachment(Transaction transaction) throws NxtException.ValidationException {
   Attachment.MonetarySystemCurrencyMinting attachment =
       (Attachment.MonetarySystemCurrencyMinting) transaction.getAttachment();
   Currency currency = Currency.getCurrency(attachment.getCurrencyId());
   CurrencyType.validate(currency, transaction);
   if (attachment.getUnits() <= 0) {
     throw new NxtException.NotValidException(
         "Invalid number of units: " + attachment.getUnits());
   }
   if (attachment.getUnits()
       > (currency.getMaxSupply() - currency.getReserveSupply())
           / Constants.MAX_MINTING_RATIO) {
     throw new NxtException.NotValidException(
         String.format(
             "Cannot mint more than 1/%d of the total units supply in a single request",
             Constants.MAX_MINTING_RATIO));
   }
   if (!currency.isActive()) {
     throw new NxtException.NotCurrentlyValidException(
         "Currency not currently active " + attachment.getJSONObject());
   }
   long counter =
       CurrencyMint.getCounter(attachment.getCurrencyId(), transaction.getSenderId());
   if (attachment.getCounter() <= counter) {
     throw new NxtException.NotCurrentlyValidException(
         String.format(
             "Counter %d has to be bigger than %d", attachment.getCounter(), counter));
   }
   if (!CurrencyMinting.meetsTarget(transaction.getSenderId(), currency, attachment)) {
     throw new NxtException.NotCurrentlyValidException(
         String.format("Hash doesn't meet target %s", attachment.getJSONObject()));
   }
 }
Example #2
0
 @Override
 boolean isUnconfirmedDuplicate(
     Transaction transaction, Map<TransactionType, Map<String, Integer>> duplicates) {
   Attachment.MonetarySystemCurrencyMinting attachment =
       (Attachment.MonetarySystemCurrencyMinting) transaction.getAttachment();
   return TransactionType.isDuplicate(
       CURRENCY_MINTING,
       attachment.getCurrencyId() + ":" + transaction.getSenderId(),
       duplicates,
       true);
 }