@Override void applyAttachment( Transaction transaction, Account senderAccount, Account recipientAccount) { Attachment.MonetarySystemCurrencyIssuance attachment = (Attachment.MonetarySystemCurrencyIssuance) transaction.getAttachment(); Currency.addCurrency(transaction, senderAccount, attachment); senderAccount.addToCurrencyAndUnconfirmedCurrencyUnits( transaction.getId(), attachment.getInitialSupply()); }
@Override boolean isDuplicate( Transaction transaction, Map<TransactionType, Map<String, Integer>> duplicates) { Attachment.MonetarySystemCurrencyIssuance attachment = (Attachment.MonetarySystemCurrencyIssuance) transaction.getAttachment(); String nameLower = attachment.getName().toLowerCase(); String codeLower = attachment.getCode().toLowerCase(); boolean isDuplicate = TransactionType.isDuplicate(CURRENCY_ISSUANCE, nameLower, duplicates, true); if (!nameLower.equals(codeLower)) { isDuplicate = isDuplicate || TransactionType.isDuplicate(CURRENCY_ISSUANCE, codeLower, duplicates, true); } return isDuplicate; }
@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())); }
@Override Fee getBaselineFee(Transaction transaction) { Attachment.MonetarySystemCurrencyIssuance attachment = (Attachment.MonetarySystemCurrencyIssuance) transaction.getAttachment(); if (Currency.getCurrencyByCode(attachment.getCode()) != null || Currency.getCurrencyByCode(attachment.getName()) != null || Currency.getCurrencyByName(attachment.getName()) != null || Currency.getCurrencyByName(attachment.getCode()) != null) { return FIVE_LETTER_CURRENCY_ISSUANCE_FEE; } switch (Math.min(attachment.getCode().length(), attachment.getName().length())) { case 3: return THREE_LETTER_CURRENCY_ISSUANCE_FEE; case 4: return FOUR_LETTER_CURRENCY_ISSUANCE_FEE; case 5: return FIVE_LETTER_CURRENCY_ISSUANCE_FEE; default: // never, invalid code length will be checked and caught later return THREE_LETTER_CURRENCY_ISSUANCE_FEE; } }
@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); }