コード例 #1
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 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);
     }
   }
 }
コード例 #2
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 static Account addOrGetAccount(long id) {
   Account account = accountTable.get(accountDbKeyFactory.newKey(id));
   if (account == null) {
     account = new Account(id);
     accountTable.insert(account);
   }
   return account;
 }
コード例 #3
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 public static DbIterator<RewardRecipientAssignment> getAccountsWithRewardRecipient(
     Long recipientId) {
   return rewardRecipientAssignmentTable.getManyBy(
       getAccountsWithRewardRecipientClause(recipientId, Nxt.getBlockchain().getHeight() + 1),
       0,
       -1);
 }
コード例 #4
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 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 ");
 }
コード例 #5
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 void addToForgedBalanceNQT(long amountNQT) {
   if (amountNQT == 0) {
     return;
   }
   this.forgedBalanceNQT = Convert.safeAdd(this.forgedBalanceNQT, amountNQT);
   accountTable.insert(this);
 }
コード例 #6
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 // 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;
 }
コード例 #7
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 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);
 }
コード例 #8
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 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);
 }
コード例 #9
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 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));
 }
コード例 #10
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 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);
 }
コード例 #11
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 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);
 }
コード例 #12
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 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);
   }
 }
コード例 #13
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 public DbIterator<AccountAsset> getAssets(int from, int to) {
   return accountAssetTable.getManyBy(new DbClause.LongClause("account_id", this.id), from, to);
 }
コード例 #14
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 public static DbIterator<Account> getLeasingAccounts() {
   return accountTable.getManyBy(leasingAccountsClause, 0, -1);
 }
コード例 #15
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 public static Account getAccount(long id, int height) {
   return id == 0 ? null : accountTable.get(accountDbKeyFactory.newKey(id), height);
 }
コード例 #16
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 void setAccountInfo(String name, String description) {
   this.name = Convert.emptyToNull(name.trim());
   this.description = Convert.emptyToNull(description.trim());
   accountTable.insert(this);
 }
コード例 #17
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 public DbIterator<Account> getLessors() {
   return accountTable.getManyBy(getLessorsClause(Nxt.getBlockchain().getHeight()), 0, -1);
 }
コード例 #18
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 public static RewardRecipientAssignment getRewardRecipientAssignment(Long id) {
   return rewardRecipientAssignmentTable.get(rewardRecipientAssignmentDbKeyFactory.newKey(id));
 }
コード例 #19
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 public static int getCount() {
   return accountTable.getCount();
 }
コード例 #20
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 public DbIterator<Account> getLessors(int height) {
   if (height < 0) {
     return getLessors();
   }
   return accountTable.getManyBy(getLessorsClause(height), height, 0, -1);
 }
コード例 #21
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 public long getUnconfirmedAssetBalanceQNT(long assetId) {
   AccountAsset accountAsset =
       accountAssetTable.get(accountAssetDbKeyFactory.newKey(this.id, assetId));
   return accountAsset == null ? 0 : accountAsset.unconfirmedQuantityQNT;
 }
コード例 #22
0
ファイル: Account.java プロジェクト: BurstProject/burstcoin
 public static DbIterator<Account> getAllAccounts(int from, int to) {
   return accountTable.getAll(from, to);
 }