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); } } }
void addToForgedBalanceNQT(long amountNQT) { if (amountNQT == 0) { return; } this.forgedBalanceNQT = Convert.safeAdd(this.forgedBalanceNQT, amountNQT); accountTable.insert(this); }
// 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; }
static Account addOrGetAccount(long id) { Account account = accountTable.get(accountDbKeyFactory.newKey(id)); if (account == null) { account = new Account(id); accountTable.insert(account); } return account; }
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); }
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); }
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); } }
void setAccountInfo(String name, String description) { this.name = Convert.emptyToNull(name.trim()); this.description = Convert.emptyToNull(description.trim()); accountTable.insert(this); }