示例#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()));
   }
 }
示例#2
0
 @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());
   }
 }
示例#3
0
 @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());
   }
 }
示例#4
0
 @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());
   }
 }