@Override void validateAttachment(Transaction transaction) throws NxtException.ValidationException { Attachment.MonetarySystemCurrencyDeletion attachment = (Attachment.MonetarySystemCurrencyDeletion) transaction.getAttachment(); Currency currency = Currency.getCurrency(attachment.getCurrencyId()); CurrencyType.validate(currency, transaction); if (!currency.canBeDeletedBy(transaction.getSenderId())) { throw new NxtException.NotCurrentlyValidException( "Currency " + Long.toUnsignedString(currency.getId()) + " cannot be deleted by account " + Long.toUnsignedString(transaction.getSenderId())); } }
@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())); } }
/** * Gets the currency with the specified ID. * * @param id * @return The currency with the specified ID. */ public static String getCurrencyById(String id) { if (Currency.idExists(id)) { return Currency.getCurrency(id); } else { throw new NoCurrencyIdException("MCCom: public static String getCurrency(String id)", "id"); } }
@Override void applyAttachment( Transaction transaction, Account senderAccount, Account recipientAccount) { Attachment.MonetarySystemCurrencyDeletion attachment = (Attachment.MonetarySystemCurrencyDeletion) transaction.getAttachment(); Currency currency = Currency.getCurrency(attachment.getCurrencyId()); currency.delete(getLedgerEvent(), transaction.getId(), senderAccount); }
@Override void validateAttachment(Transaction transaction) throws NxtException.ValidationException { Attachment.MonetarySystemReserveClaim attachment = (Attachment.MonetarySystemReserveClaim) transaction.getAttachment(); if (attachment.getUnits() <= 0) { throw new NxtException.NotValidException( "Reserve claim number of units must be positive: " + attachment.getUnits()); } CurrencyType.validate(Currency.getCurrency(attachment.getCurrencyId()), transaction); }
@Override void undoAttachmentUnconfirmed(Transaction transaction, Account senderAccount) { Attachment.MonetarySystemExchangeSell attachment = (Attachment.MonetarySystemExchangeSell) transaction.getAttachment(); Currency currency = Currency.getCurrency(attachment.getCurrencyId()); if (currency != null) { senderAccount.addToUnconfirmedCurrencyUnits( attachment.getCurrencyId(), attachment.getUnits()); } }
@Override void validateAttachment(Transaction transaction) throws NxtException.ValidationException { Attachment.MonetarySystemReserveIncrease attachment = (Attachment.MonetarySystemReserveIncrease) transaction.getAttachment(); if (attachment.getAmountPerUnitNQT() <= 0) { throw new NxtException.NotValidException( "Reserve increase NXT amount must be positive: " + attachment.getAmountPerUnitNQT()); } CurrencyType.validate(Currency.getCurrency(attachment.getCurrencyId()), transaction); }
@Override void undoAttachmentUnconfirmed(Transaction transaction, Account senderAccount) { Attachment.MonetarySystemPublishExchangeOffer attachment = (Attachment.MonetarySystemPublishExchangeOffer) transaction.getAttachment(); senderAccount.addToUnconfirmedBalanceNQT( Math.multiplyExact(attachment.getInitialBuySupply(), attachment.getBuyRateNQT())); Currency currency = Currency.getCurrency(attachment.getCurrencyId()); if (currency != null) { senderAccount.addToUnconfirmedCurrencyUnits( attachment.getCurrencyId(), attachment.getInitialSellSupply()); } }
@Override void undoAttachmentUnconfirmed(Transaction transaction, Account senderAccount) { Attachment.MonetarySystemCurrencyTransfer attachment = (Attachment.MonetarySystemCurrencyTransfer) transaction.getAttachment(); Currency currency = Currency.getCurrency(attachment.getCurrencyId()); if (currency != null) { senderAccount.addToUnconfirmedCurrencyUnits( getLedgerEvent(), transaction.getId(), attachment.getCurrencyId(), attachment.getUnits()); } }
@Override final void validateAttachment(Transaction transaction) throws NxtException.ValidationException { Attachment.MonetarySystemExchange attachment = (Attachment.MonetarySystemExchange) transaction.getAttachment(); if (attachment.getRateNQT() <= 0 || attachment.getUnits() == 0) { throw new NxtException.NotValidException("Invalid exchange: " + attachment.getJSONObject()); } Currency currency = Currency.getCurrency(attachment.getCurrencyId()); CurrencyType.validate(currency, transaction); if (!currency.isActive()) { throw new NxtException.NotCurrentlyValidException( "Currency not active: " + attachment.getJSONObject()); } }
@Override boolean applyAttachmentUnconfirmed(Transaction transaction, Account senderAccount) { Attachment.MonetarySystemReserveIncrease attachment = (Attachment.MonetarySystemReserveIncrease) transaction.getAttachment(); Currency currency = Currency.getCurrency(attachment.getCurrencyId()); if (senderAccount.getUnconfirmedBalanceNQT() >= Math.multiplyExact( currency.getReserveSupply(), attachment.getAmountPerUnitNQT())) { senderAccount.addToUnconfirmedBalanceNQT( -Math.multiplyExact(currency.getReserveSupply(), attachment.getAmountPerUnitNQT())); return true; } return false; }
@Override void validateAttachment(Transaction transaction) throws NxtException.ValidationException { Attachment.MonetarySystemPublishExchangeOffer attachment = (Attachment.MonetarySystemPublishExchangeOffer) transaction.getAttachment(); if (attachment.getBuyRateNQT() <= 0 || attachment.getSellRateNQT() <= 0 || attachment.getBuyRateNQT() > attachment.getSellRateNQT()) { throw new NxtException.NotValidException( String.format( "Invalid exchange offer, buy rate %d and sell rate %d has to be larger than 0, buy rate cannot be larger than sell rate", attachment.getBuyRateNQT(), attachment.getSellRateNQT())); } if (attachment.getTotalBuyLimit() < 0 || attachment.getTotalSellLimit() < 0 || attachment.getInitialBuySupply() < 0 || attachment.getInitialSellSupply() < 0 || attachment.getExpirationHeight() < 0) { throw new NxtException.NotValidException( "Invalid exchange offer, units and height cannot be negative: " + attachment.getJSONObject()); } if (attachment.getTotalBuyLimit() < attachment.getInitialBuySupply() || attachment.getTotalSellLimit() < attachment.getInitialSellSupply()) { throw new NxtException.NotValidException( "Initial supplies must not exceed total limits"); } if (Nxt.getBlockchain().getHeight() > Constants.SHUFFLING_BLOCK) { if (attachment.getTotalBuyLimit() == 0 && attachment.getTotalSellLimit() == 0) { throw new NxtException.NotCurrentlyValidException( "Total buy and sell limits cannot be both 0"); } if (attachment.getInitialBuySupply() == 0 && attachment.getInitialSellSupply() == 0) { throw new NxtException.NotCurrentlyValidException( "Initial buy and sell supply cannot be both 0"); } } if (attachment.getExpirationHeight() <= attachment.getFinishValidationHeight(transaction)) { throw new NxtException.NotCurrentlyValidException( "Expiration height must be after transaction execution height"); } Currency currency = Currency.getCurrency(attachment.getCurrencyId()); CurrencyType.validate(currency, transaction); if (!currency.isActive()) { throw new NxtException.NotCurrentlyValidException( "Currency not currently active: " + attachment.getJSONObject()); } }
@Override boolean isDuplicate( Transaction transaction, Map<TransactionType, Map<String, Integer>> duplicates) { Attachment.MonetarySystemCurrencyDeletion attachment = (Attachment.MonetarySystemCurrencyDeletion) transaction.getAttachment(); Currency currency = Currency.getCurrency(attachment.getCurrencyId()); String nameLower = currency.getName().toLowerCase(); String codeLower = currency.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 validateAttachment(Transaction transaction) throws NxtException.ValidationException { Attachment.MonetarySystemCurrencyTransfer attachment = (Attachment.MonetarySystemCurrencyTransfer) transaction.getAttachment(); if (attachment.getUnits() <= 0) { throw new NxtException.NotValidException( "Invalid currency transfer: " + attachment.getJSONObject()); } if (transaction.getRecipientId() == Genesis.CREATOR_ID) { throw new NxtException.NotValidException( "Currency transfer to genesis account not allowed"); } Currency currency = Currency.getCurrency(attachment.getCurrencyId()); CurrencyType.validate(currency, transaction); if (!currency.isActive()) { throw new NxtException.NotCurrentlyValidException( "Currency not currently active: " + attachment.getJSONObject()); } }
@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())); }
protected void handleTag(int i, XMLElement curElement) { switch (i) { case 0: // Title setString(infoTags[i], curElement.decodeString(curElement.getContents())); break; case 1: // Seller name if (curElement.getChild("name") == null) { setSellerName(curElement.getContents()); } else { mSeller = Seller.newFromXML(curElement); } break; case 2: // High bidder name case 18: // Location of item setString(infoTags[i], curElement.getContents()); break; case 3: // Bid count setInteger(infoTags[i], Integer.parseInt(curElement.getContents())); break; case 4: // Start date case 5: // End date setDate(infoTags[i], new Date(Long.parseLong(curElement.getContents()))); break; case 6: // Current price case 11: // Shipping cost case 12: // Insurance cost case 13: // Buy Now price case 22: // Buy Now US price case 14: // Current US price case 16: // Minimum price/bid Currency amount = Currency.getCurrency( curElement.getProperty("CURRENCY"), curElement.getProperty("PRICE")); setMonetary(infoTags[i], amount); switch (i) { case 13: setDefaultCurrency(amount); break; case 6: if (amount.getCurrencyType() == Currency.US_DOLLAR) { setMonetary("us_cur", amount); setString("currency", amount.fullCurrencyName()); } setDefaultCurrency(amount); break; case 12: String optional = curElement.getProperty("OPTIONAL"); setBoolean("insurance_optional", optional == null || (optional.equals("true"))); break; } break; case 7: // Is a dutch auction? case 8: // Is a reserve auction? case 9: // Is a private auction? case 15: // Fixed price case 17: // PayPal accepted setBoolean(infoTags[i], true); if (i == 7 || i == 15) { String quant = curElement.getProperty("QUANTITY"); if (quant == null) { setInteger("quantity", 1); } else { setInteger("quantity", Integer.parseInt(quant)); } } else if (i == 8) { setBoolean("reserve_met", "true".equals(curElement.getProperty("MET"))); } break; case 19: // Feedback score String feedback = curElement.getContents(); if (mSeller == null) mSeller = new Seller(); if (feedback != null) mSeller.setFeedback(Integer.parseInt(feedback)); break; case 20: // Positive feedback percentage (w/o the % sign) String percentage = curElement.getContents(); if (mSeller == null) mSeller = new Seller(); mSeller.setPositivePercentage(percentage); break; case 21: // Seller info block mSeller = Seller.newFromXML(curElement); break; default: break; // commented out for FORWARDS compatibility. // throw new RuntimeException("Unexpected value when handling AuctionInfo tags!"); } }