Exemple #1
0
 void leaseEffectiveBalance(long lesseeId, short period) {
   Account lessee = Account.getAccount(lesseeId);
   if (lessee != null && lessee.getPublicKey() != null) {
     int height = Nxt.getBlockchain().getHeight();
     if (currentLeasingHeightFrom == Integer.MAX_VALUE) {
       currentLeasingHeightFrom = height + 1440;
       currentLeasingHeightTo = currentLeasingHeightFrom + period;
       currentLesseeId = lesseeId;
       nextLeasingHeightFrom = Integer.MAX_VALUE;
       accountTable.insert(this);
       leaseListeners.notify(
           new AccountLease(
               this.getId(), lesseeId, currentLeasingHeightFrom, currentLeasingHeightTo),
           Event.LEASE_SCHEDULED);
     } else {
       nextLeasingHeightFrom = height + 1440;
       if (nextLeasingHeightFrom < currentLeasingHeightTo) {
         nextLeasingHeightFrom = currentLeasingHeightTo;
       }
       nextLeasingHeightTo = nextLeasingHeightFrom + period;
       nextLesseeId = lesseeId;
       accountTable.insert(this);
       leaseListeners.notify(
           new AccountLease(this.getId(), lesseeId, nextLeasingHeightFrom, nextLeasingHeightTo),
           Event.LEASE_SCHEDULED);
     }
   }
 }
Exemple #2
0
 public static Account getAccount(byte[] publicKey) {
   Account account = accountTable.get(accountDbKeyFactory.newKey(getId(publicKey)));
   if (account == null) {
     return null;
   }
   if (account.getPublicKey() == null || Arrays.equals(account.getPublicKey(), publicKey)) {
     return account;
   }
   throw new RuntimeException(
       "DUPLICATE KEY for account "
           + Convert.toUnsignedLong(account.getId())
           + " existing key "
           + Convert.toHexString(account.getPublicKey())
           + " new key "
           + Convert.toHexString(publicKey));
 }
  @Override
  JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    long recipientId = ParameterParser.getRecipientId(req);
    Account recipientAccount = Account.getAccount(recipientId);
    if (recipientAccount == null || recipientAccount.getPublicKey() == null) {
      return INCORRECT_RECIPIENT;
    }

    EncryptedData encryptedData = ParameterParser.getEncryptedMessage(req, recipientAccount);
    return JSONData.encryptedData(encryptedData);
  }