示例#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()));
   }
 }
示例#2
0
 /**
  * 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");
   }
 }
示例#3
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()));
   }
 }
示例#4
0
 /**
  * Gets the ID of the specified currency.
  *
  * @param currency
  * @return The ID of the specified currency.
  */
 public static String getCurrencyId(String currency) {
   if (Currency.physicalExists(currency)) {
     return Currency.getId(currency);
   } else {
     throw new NoCurrencyException(
         "MCCom: public static String getCurrencyId(String currency)", "currency");
   }
 }
示例#5
0
 @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);
 }
示例#6
0
 public static Currency fromJDKCurrency(java.util.Currency jdkCurrency) {
   for (Currency c1 : Currency.values()) {
     if (jdkCurrency.getCurrencyCode().equals(c1.toString())) {
       return c1;
     }
   }
   return null;
 }
示例#7
0
 /**
  * Returns the specified physical currency's value.
  *
  * @param currency
  * @throws NoCurrencyException
  * @return Currency value
  */
 public static double getPhysicalCurrencyValue(String currency) {
   if (Currency.physicalExists(currency)) {
     return Currency.getPhysicalValue(currency);
   } else {
     throw new NoCurrencyException(
         "MCCom: public static double getPhysicalCurrencyValue(String currency)", "currency");
   }
 }
 public HttpResponse convert(Currency from, Currency to) {
   String url = this.googleCurrencyUrl + "&q=1" + from.toString() + "=?" + to.toString();
   try {
     HttpUriRequest request = new HttpGet(url);
     return httpClient.execute(request);
   } catch (ClientProtocolException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return null;
 }
示例#9
0
  public void insertData(ArrayList<Currency> currencyList) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues ecbValues = new ContentValues();
    db.execSQL("DELETE FROM " + ECB_TABLE);

    for (Currency cur : currencyList) {
      ecbValues.put(CURRENCYCODE, cur.get("name"));
      ecbValues.put(CURRENCYVALUE, cur.get("rate"));
      db.insert(ECB_TABLE, null, ecbValues);
    }

    db.close();
  }
示例#10
0
 @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
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((client == null) ? 0 : client.hashCode());
   result = prime * result + ((fromCurr == null) ? 0 : fromCurr.hashCode());
   result = prime * result + id;
   result = prime * result + ((status == null) ? 0 : status.hashCode());
   result = prime * result + ((toCurr == null) ? 0 : toCurr.hashCode());
   long temp;
   temp = toCurrAmount.longValue();
   result = prime * result + (int) (temp ^ (temp >>> 32));
   return result;
 }
示例#12
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());
   }
 }
示例#13
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());
   }
 }
示例#14
0
 @Override
 void applyAttachment(
     Transaction transaction, Account senderAccount, Account recipientAccount) {
   Attachment.MonetarySystemReserveClaim attachment =
       (Attachment.MonetarySystemReserveClaim) transaction.getAttachment();
   Currency.claimReserve(senderAccount, attachment.getCurrencyId(), attachment.getUnits());
 }
示例#15
0
文件: Money.java 项目: Mbyrnes/MOV
  /**
   * Compare this money for equality with the specified money.
   *
   * @param object the money to compare
   * @return <code>true</code> iff the monies are equal.
   */
  public boolean equals(Object object) {
    Money money = (Money) object;

    assert currency.equals(money.currency);

    return (amount == money.amount);
  }
示例#16
0
 @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;
 }
示例#17
0
 @Override
 void applyAttachment(
     Transaction transaction, Account senderAccount, Account recipientAccount) {
   Attachment.MonetarySystemReserveIncrease attachment =
       (Attachment.MonetarySystemReserveIncrease) transaction.getAttachment();
   Currency.increaseReserve(
       senderAccount, attachment.getCurrencyId(), attachment.getAmountPerUnitNQT());
 }
示例#18
0
 @Override
 public int hashCode() {
   final int PRIME = 37;
   int result = 1;
   result = PRIME * result + ((currency == null) ? 0 : currency.hashCode());
   result = PRIME * result + ((moneyValue == null) ? 0 : moneyValue.hashCode());
   return result;
 }
示例#19
0
 protected void create(String account) {
   accountlist.add(account);
   accountbalance.put(account, Settings.startingBalance);
   accountcurrency.put(account, Currency.getDefault());
   accountstatus.put(account, "NORMAL"); // TODO: Add status support
   hashaccount.put(account.toLowerCase(), account);
   treeaccount.add(account.toLowerCase());
 }
示例#20
0
 public static Currency fromString(String text) {
   if (text != null) {
     for (Currency currency : Currency.values()) {
       if (text.equalsIgnoreCase(currency.stringValue)) return currency;
     }
   }
   return null;
 }
示例#21
0
 @Override
 void applyAttachment(
     Transaction transaction, Account senderAccount, Account recipientAccount) {
   Attachment.MonetarySystemCurrencyTransfer attachment =
       (Attachment.MonetarySystemCurrencyTransfer) transaction.getAttachment();
   Currency.transferCurrency(
       senderAccount, recipientAccount, attachment.getCurrencyId(), attachment.getUnits());
   CurrencyTransfer.addTransfer(transaction, attachment);
 }
示例#22
0
 @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());
 }
示例#23
0
文件: Money.java 项目: Mbyrnes/MOV
  /**
   * Compare this money to the specified money.
   *
   * @param object the money to compare
   * @return the value <code>0</code> if the monies are equal; <code>1</code> if this money is more
   *     than the specified money or <code>-1</code> if this money is less than the specified money.
   */
  public int compareTo(Object object) {
    Money money = (Money) object;

    assert currency.equals(money.currency);

    if (amount < money.amount) return -1;
    if (amount > money.amount) return 1;
    return 0;
  }
示例#24
0
 @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()));
 }
示例#25
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());
   }
 }
示例#26
0
 // -----------------------------------------------------------------------
 public void test_getAvailable() {
   Set<Currency> available = Currency.getAvailableCurrencies();
   assertTrue(available.contains(Currency.USD));
   assertTrue(available.contains(Currency.EUR));
   assertTrue(available.contains(Currency.JPY));
   assertTrue(available.contains(Currency.GBP));
   assertTrue(available.contains(Currency.CHF));
   assertTrue(available.contains(Currency.AUD));
   assertTrue(available.contains(Currency.CAD));
 }
示例#27
0
 @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());
   }
 }
示例#28
0
 @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);
 }
示例#29
0
 // -----------------------------------------------------------------------
 public void test_constants() {
   assertEquals(Currency.of("USD"), Currency.USD);
   assertEquals(Currency.of("EUR"), Currency.EUR);
   assertEquals(Currency.of("JPY"), Currency.JPY);
   assertEquals(Currency.of("GBP"), Currency.GBP);
   assertEquals(Currency.of("CHF"), Currency.CHF);
   assertEquals(Currency.of("AUD"), Currency.AUD);
   assertEquals(Currency.of("CAD"), Currency.CAD);
 }
示例#30
0
 @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);
 }