public long getEffectiveBalanceNXT() { Block lastBlock = Nxt.getBlockchain().getLastBlock(); if (lastBlock.getHeight() >= Constants.TRANSPARENT_FORGING_BLOCK_6 && (getPublicKey() == null || lastBlock.getHeight() - keyHeight <= 1440)) { return 0; // cfb: Accounts with the public key revealed less than 1440 blocks ago are not // allowed to generate blocks } if (lastBlock.getHeight() < Constants.TRANSPARENT_FORGING_BLOCK_3 && this.creationHeight < Constants.TRANSPARENT_FORGING_BLOCK_2) { if (this.creationHeight == 0) { return getBalanceNQT() / Constants.ONE_NXT; } if (lastBlock.getHeight() - this.creationHeight < 1440) { return 0; } long receivedInlastBlock = 0; for (Transaction transaction : lastBlock.getTransactions()) { if (id == transaction.getRecipientId()) { receivedInlastBlock += transaction.getAmountNQT(); } } return (getBalanceNQT() - receivedInlastBlock) / Constants.ONE_NXT; } if (lastBlock.getHeight() < currentLeasingHeightFrom) { return (getGuaranteedBalanceNQT(1440) + getLessorsGuaranteedBalanceNQT()) / Constants.ONE_NXT; } return getLessorsGuaranteedBalanceNQT() / Constants.ONE_NXT; }
@Override public long getBlockIdAtHeight(int height) { Block block = lastBlock.get(); if (height > block.getHeight()) { throw new IllegalArgumentException( "Invalid height " + height + ", current blockchain is at " + block.getHeight()); } if (height == block.getHeight()) { return block.getId(); } return BlockDb.findBlockIdAtHeight(height); }
@Override public void paint(BufferedImage buf) { Graphics g = buf.getGraphics(); g.setColor(Color.green); for (Block b : blocks) g.fillRoundRect(b.getX(), b.getY(), b.getWidth(), b.getHeight() + 10, 5, 5); }
public void changeOrientation(Point one, Point two) { Block temp = new Block(one, two); if (temp.getHeight() != this.getHeight() || temp.getWidth() != this.getWidth()) { throw new IllegalArgumentException("Block size can not change"); } UpperLeft = one; LowerRight = two; }
public static boolean verifyFork(Transaction transaction) { if (blockchain.getHeight() < Constants.DIGITAL_GOODS_STORE_BLOCK) { return true; } if (transaction.getReferencedTransactionFullHash() != null) { return true; } if (blockchain.getHeight() < Constants.EC_CHANGE_BLOCK_1) { if (blockchain.getHeight() - transaction.getECBlockHeight() > Constants.EC_BLOCK_DISTANCE_LIMIT) { return false; } } Block ecBlock = blockchain.getBlock(transaction.getECBlockId()); return ecBlock != null && ecBlock.getHeight() == transaction.getECBlockHeight(); }
/** * Create a ledger entry * * @param event Event * @param eventId Event identifier * @param accountId Account identifier * @param holding Holding or null * @param holdingId Holding identifier or null * @param change Change in balance * @param balance New balance */ public LedgerEntry( LedgerEvent event, long eventId, long accountId, LedgerHolding holding, Long holdingId, long change, long balance) { this.event = event; this.eventId = eventId; this.accountId = accountId; this.holding = holding; this.holdingId = holdingId; this.change = change; this.balance = balance; Block block = blockchain.getLastBlock(); this.blockId = block.getId(); this.height = block.getHeight(); this.timestamp = block.getTimestamp(); }
@Test public void nemesisBlockCanBeCreated() { // Act: final Block block = this.loadNemesisBlock(); // Assert: Assert.assertThat( block.getSigner().getAddress(), IsEqual.equalTo(NEMESIS_BLOCK_INFO.getAddress())); Assert.assertThat(block.getType(), IsEqual.equalTo(-1)); Assert.assertThat(block.getVersion(), IsEqual.equalTo(EXPECTED_VERSION)); Assert.assertThat(block.getTimeStamp(), IsEqual.equalTo(TimeInstant.ZERO)); // 2 multisig aggregate transactions Assert.assertThat( block.getTotalFee(), IsEqual.equalTo(EXPECTED_MULTISIG_AGGREGATE_FEE.multiply(2))); Assert.assertThat(block.getPreviousBlockHash(), IsEqual.equalTo(Hash.ZERO)); Assert.assertThat(block.getHeight(), IsEqual.equalTo(BlockHeight.ONE)); Assert.assertThat(block.getTransactions().size(), IsEqual.equalTo(NUM_NEMESIS_TRANSACTIONS)); Assert.assertThat(block.getDifficulty(), IsEqual.equalTo(BlockDifficulty.INITIAL_DIFFICULTY)); Assert.assertThat(block.getGenerationHash(), IsNull.notNullValue()); }