Exemplo 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);
     }
   }
 }
Exemplo n.º 2
0
 void addToBalanceAndUnconfirmedBalanceNQT(long amountNQT) {
   if (amountNQT == 0) {
     return;
   }
   this.balanceNQT = Convert.safeAdd(this.balanceNQT, amountNQT);
   this.unconfirmedBalanceNQT = Convert.safeAdd(this.unconfirmedBalanceNQT, amountNQT);
   addToGuaranteedBalanceNQT(amountNQT);
   checkBalance(this.id, this.balanceNQT, this.unconfirmedBalanceNQT);
   accountTable.insert(this);
   listeners.notify(this, Event.BALANCE);
   listeners.notify(this, Event.UNCONFIRMED_BALANCE);
 }
Exemplo n.º 3
0
 /** Commit pending ledger entries */
 static void commitEntries() {
   for (LedgerEntry ledgerEntry : pendingEntries) {
     accountLedgerTable.insert(ledgerEntry);
     listeners.notify(ledgerEntry, Event.ADD_ENTRY);
   }
   pendingEntries.clear();
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
 static void addTrade(
     Long assetId,
     int timeStamp,
     Long blockId,
     Long askOrderId,
     Long bidOrderId,
     int quantity,
     long price) {
   List<Trade> assetTrades = trades.get(assetId);
   if (assetTrades == null) {
     assetTrades = new CopyOnWriteArrayList<>();
     // cfb: CopyOnWriteArrayList requires a lot of resources to grow but this happens only when a
     // new block is pushed/applied, I can't decide if we should replace it with another class
     trades.put(assetId, assetTrades);
   }
   Trade trade = new Trade(blockId, timeStamp, assetId, askOrderId, bidOrderId, quantity, price);
   assetTrades.add(trade);
   listeners.notify(trade, Event.TRADE);
 }
Exemplo n.º 7
0
 public static boolean removeListener(Listener<Trade> listener, Event eventType) {
   return listeners.removeListener(listener, eventType);
 }
Exemplo n.º 8
0
 public static boolean addListener(Listener<Trade> listener, Event eventType) {
   return listeners.addListener(listener, eventType);
 }
Exemplo n.º 9
0
 public static boolean removeLeaseListener(Listener<AccountLease> listener, Event eventType) {
   return leaseListeners.removeListener(listener, eventType);
 }
Exemplo n.º 10
0
 public static boolean removeAssetListener(Listener<AccountAsset> listener, Event eventType) {
   return assetListeners.removeListener(listener, eventType);
 }
Exemplo n.º 11
0
 public static boolean addAssetListener(Listener<AccountAsset> listener, Event eventType) {
   return assetListeners.addListener(listener, eventType);
 }
Exemplo n.º 12
0
 /**
  * Remove a listener
  *
  * @param listener Listener
  * @param eventType Event to listen for
  * @return True if the listener was removed
  */
 public static boolean removeListener(Listener<LedgerEntry> listener, Event eventType) {
   return listeners.removeListener(listener, eventType);
 }