3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-30 23:02:15 +00:00

Move block inflation calculator to be a static method of Block. In future this will move again to NetworkParameters.

This commit is contained in:
Mike Hearn 2012-10-08 18:03:50 +02:00
parent 90f5ab7e47
commit 7c636d7ecc
2 changed files with 12 additions and 6 deletions

View File

@ -124,6 +124,16 @@ public class Block extends Message {
super(params, payloadBytes, 0, parseLazy, parseRetain, length);
}
/**
* A utility method that calculates how much new Bitcoin would be created by the block at the given height.
* The inflation of Bitcoin is predictable and drops roughly every 4 years (210,000 blocks). At the dawn of
* the system it was 50 coins per block, in late 2012 it went to 25 coins per block, and so on. The size of
* a coinbase transaction is inflation plus fees.
*/
public static BigInteger getBlockInflation(int height) {
return Utils.toNanoCoins(50, 0).shiftRight(height / 210000);
}
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
// This code is not actually necessary, as transient fields are initialized to the default value which is in

View File

@ -179,7 +179,7 @@ public class FullPrunedBlockChain extends AbstractBlockChain {
totalFees = totalFees.add(valueIn.subtract(valueOut));
}
}
if (totalFees.compareTo(params.MAX_MONEY) > 0 || getBlockInflation(height).add(totalFees).compareTo(coinbaseValue) < 0)
if (totalFees.compareTo(params.MAX_MONEY) > 0 || Block.getBlockInflation(height).add(totalFees).compareTo(coinbaseValue) < 0)
throw new VerificationException("Transaction fees out of range");
} catch (VerificationException e) {
blockStore.abortDatabaseBatchWrite();
@ -190,10 +190,6 @@ public class FullPrunedBlockChain extends AbstractBlockChain {
}
return new TransactionOutputChanges(txOutsCreated, txOutsSpent);
}
private BigInteger getBlockInflation(int height) {
return Utils.toNanoCoins(50, 0).shiftRight(height / 210000);
}
@Override
/**
@ -278,7 +274,7 @@ public class FullPrunedBlockChain extends AbstractBlockChain {
}
}
if (totalFees.compareTo(params.MAX_MONEY) > 0 ||
getBlockInflation(newBlock.getHeight()).add(totalFees).compareTo(coinbaseValue) < 0)
Block.getBlockInflation(newBlock.getHeight()).add(totalFees).compareTo(coinbaseValue) < 0)
throw new VerificationException("Transaction fees out of range");
txOutChanges = new TransactionOutputChanges(txOutsCreated, txOutsSpent);
} else {