Esempio n. 1
1
 @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()));
   }
 }
Esempio n. 2
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()));
   }
 }
Esempio n. 3
0
 private Vote(Transaction transaction, Attachment.MessagingVoteCasting attachment) {
   this.id = transaction.getId();
   this.dbKey = voteDbKeyFactory.newKey(this.id);
   this.pollId = attachment.getPollId();
   this.voterId = transaction.getSenderId();
   this.voteBytes = attachment.getPollVote();
 }
Esempio n. 4
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);
 }
Esempio n. 5
0
 private Asset(Transaction transaction, Attachment.ColoredCoinsAssetIssuance attachment) {
   this.assetId = transaction.getId();
   this.dbKey = assetDbKeyFactory.newKey(this.assetId);
   this.accountId = transaction.getSenderId();
   this.name = attachment.getName();
   this.description = attachment.getDescription();
   this.quantityQNT = attachment.getQuantityQNT();
   this.decimals = attachment.getDecimals();
 }
 static void publishOffer(
     Transaction transaction, Attachment.MonetarySystemPublishExchangeOffer attachment) {
   CurrencyBuyOffer previousOffer =
       CurrencyBuyOffer.getOffer(attachment.getCurrencyId(), transaction.getSenderId());
   if (previousOffer != null) {
     removeOffer(previousOffer);
   }
   CurrencyBuyOffer.addOffer(transaction, attachment);
   CurrencySellOffer.addOffer(transaction, attachment);
 }
Esempio n. 7
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);
 }