Esempio n. 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);
     }
   }
 }
Esempio n. 2
0
 static Account addOrGetAccount(long id) {
   Account account = accountTable.get(accountDbKeyFactory.newKey(id));
   if (account == null) {
     account = new Account(id);
     accountTable.insert(account);
   }
   return account;
 }
Esempio n. 3
0
 public static DbIterator<RewardRecipientAssignment> getAccountsWithRewardRecipient(
     Long recipientId) {
   return rewardRecipientAssignmentTable.getManyBy(
       getAccountsWithRewardRecipientClause(recipientId, Nxt.getBlockchain().getHeight() + 1),
       0,
       -1);
 }
Esempio n. 4
0
 public static DbIterator<AccountAsset> getAssetAccounts(long assetId, int from, int to) {
   return accountAssetTable.getManyBy(
       new DbClause.LongClause("asset_id", assetId),
       from,
       to,
       " ORDER BY quantity DESC, account_id ");
 }
Esempio n. 5
0
 void addToForgedBalanceNQT(long amountNQT) {
   if (amountNQT == 0) {
     return;
   }
   this.forgedBalanceNQT = Convert.safeAdd(this.forgedBalanceNQT, amountNQT);
   accountTable.insert(this);
 }
Esempio n. 6
0
 // returns true iff:
 // this.publicKey is set to null (in which case this.publicKey also gets set to key)
 // or
 // this.publicKey is already set to an array equal to key
 boolean setOrVerify(byte[] key, int height) {
   if (this.publicKey == null) {
     if (Db.isInTransaction()) {
       this.publicKey = key;
       this.keyHeight = -1;
       accountTable.insert(this);
     }
     return true;
   } else if (Arrays.equals(this.publicKey, key)) {
     return true;
   } else if (this.keyHeight == -1) {
     Logger.logMessage("DUPLICATE KEY!!!");
     Logger.logMessage(
         "Account key for "
             + Convert.toUnsignedLong(id)
             + " was already set to a different one at the same height "
             + ", current height is "
             + height
             + ", rejecting new key");
     return false;
   } else if (this.keyHeight >= height) {
     Logger.logMessage("DUPLICATE KEY!!!");
     if (Db.isInTransaction()) {
       Logger.logMessage(
           "Changing key for account "
               + Convert.toUnsignedLong(id)
               + " at height "
               + height
               + ", was previously set to a different one at height "
               + keyHeight);
       this.publicKey = key;
       this.keyHeight = height;
       accountTable.insert(this);
     }
     return true;
   }
   Logger.logMessage("DUPLICATE KEY!!!");
   Logger.logMessage(
       "Invalid key for account "
           + Convert.toUnsignedLong(id)
           + " at height "
           + height
           + ", was already set to a different one at height "
           + keyHeight);
   return false;
 }
Esempio n. 7
0
 void addToUnconfirmedBalanceNQT(long amountNQT) {
   if (amountNQT == 0) {
     return;
   }
   this.unconfirmedBalanceNQT = Convert.safeAdd(this.unconfirmedBalanceNQT, amountNQT);
   checkBalance(this.id, this.balanceNQT, this.unconfirmedBalanceNQT);
   accountTable.insert(this);
   listeners.notify(this, Event.UNCONFIRMED_BALANCE);
 }
Esempio n. 8
0
 public static void setRewardRecipientAssignment(Long id, Long recipient) {
   int currentHeight = Nxt.getBlockchain().getLastBlock().getHeight();
   RewardRecipientAssignment assignment = getRewardRecipientAssignment(id);
   if (assignment == null) {
     assignment =
         new RewardRecipientAssignment(
             id,
             id,
             recipient,
             (int) (currentHeight + Constants.BURST_REWARD_RECIPIENT_ASSIGNMENT_WAIT_TIME));
   } else {
     assignment.setRecipient(
         recipient, (int) (currentHeight + Constants.BURST_REWARD_RECIPIENT_ASSIGNMENT_WAIT_TIME));
   }
   rewardRecipientAssignmentTable.insert(assignment);
 }
Esempio n. 9
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));
 }
Esempio n. 10
0
 void addToUnconfirmedAssetBalanceQNT(long assetId, long quantityQNT) {
   if (quantityQNT == 0) {
     return;
   }
   AccountAsset accountAsset;
   accountAsset = accountAssetTable.get(accountAssetDbKeyFactory.newKey(this.id, assetId));
   long unconfirmedAssetBalance = accountAsset == null ? 0 : accountAsset.unconfirmedQuantityQNT;
   unconfirmedAssetBalance = Convert.safeAdd(unconfirmedAssetBalance, quantityQNT);
   if (accountAsset == null) {
     accountAsset = new AccountAsset(this.id, assetId, 0, unconfirmedAssetBalance);
   } else {
     accountAsset.unconfirmedQuantityQNT = unconfirmedAssetBalance;
   }
   accountAsset.save();
   listeners.notify(this, Event.UNCONFIRMED_ASSET_BALANCE);
   assetListeners.notify(accountAsset, Event.UNCONFIRMED_ASSET_BALANCE);
 }
Esempio n. 11
0
 void addToAssetBalanceQNT(long assetId, long quantityQNT) {
   if (quantityQNT == 0) {
     return;
   }
   AccountAsset accountAsset;
   accountAsset = accountAssetTable.get(accountAssetDbKeyFactory.newKey(this.id, assetId));
   long assetBalance = accountAsset == null ? 0 : accountAsset.quantityQNT;
   assetBalance = Convert.safeAdd(assetBalance, quantityQNT);
   if (accountAsset == null) {
     accountAsset = new AccountAsset(this.id, assetId, assetBalance, 0);
   } else {
     accountAsset.quantityQNT = assetBalance;
   }
   accountAsset.save();
   listeners.notify(this, Event.ASSET_BALANCE);
   assetListeners.notify(accountAsset, Event.ASSET_BALANCE);
 }
Esempio n. 12
0
 void apply(byte[] key, int height) {
   if (!setOrVerify(key, this.creationHeight)) {
     throw new IllegalStateException("Public key mismatch");
   }
   if (this.publicKey == null) {
     throw new IllegalStateException(
         "Public key has not been set for account "
             + Convert.toUnsignedLong(id)
             + " at height "
             + height
             + ", key height is "
             + keyHeight);
   }
   if (this.keyHeight == -1 || this.keyHeight > height) {
     this.keyHeight = height;
     accountTable.insert(this);
   }
 }
Esempio n. 13
0
 public DbIterator<AccountAsset> getAssets(int from, int to) {
   return accountAssetTable.getManyBy(new DbClause.LongClause("account_id", this.id), from, to);
 }
Esempio n. 14
0
 public static DbIterator<Account> getLeasingAccounts() {
   return accountTable.getManyBy(leasingAccountsClause, 0, -1);
 }
Esempio n. 15
0
 public static Account getAccount(long id, int height) {
   return id == 0 ? null : accountTable.get(accountDbKeyFactory.newKey(id), height);
 }
Esempio n. 16
0
 void setAccountInfo(String name, String description) {
   this.name = Convert.emptyToNull(name.trim());
   this.description = Convert.emptyToNull(description.trim());
   accountTable.insert(this);
 }
Esempio n. 17
0
 public DbIterator<Account> getLessors() {
   return accountTable.getManyBy(getLessorsClause(Nxt.getBlockchain().getHeight()), 0, -1);
 }
Esempio n. 18
0
 public static RewardRecipientAssignment getRewardRecipientAssignment(Long id) {
   return rewardRecipientAssignmentTable.get(rewardRecipientAssignmentDbKeyFactory.newKey(id));
 }
Esempio n. 19
0
 public static int getCount() {
   return accountTable.getCount();
 }
Esempio n. 20
0
 public DbIterator<Account> getLessors(int height) {
   if (height < 0) {
     return getLessors();
   }
   return accountTable.getManyBy(getLessorsClause(height), height, 0, -1);
 }
Esempio n. 21
0
 public long getUnconfirmedAssetBalanceQNT(long assetId) {
   AccountAsset accountAsset =
       accountAssetTable.get(accountAssetDbKeyFactory.newKey(this.id, assetId));
   return accountAsset == null ? 0 : accountAsset.unconfirmedQuantityQNT;
 }
Esempio n. 22
0
 public static DbIterator<Account> getAllAccounts(int from, int to) {
   return accountTable.getAll(from, to);
 }