forked from Qortal/qortal
Move getRewardByHeight from Block to BlockChain
This commit is contained in:
parent
f45cedb6ff
commit
9435e9576a
@ -19,7 +19,7 @@ import org.qora.account.PrivateKeyAccount;
|
|||||||
import org.qora.account.PublicKeyAccount;
|
import org.qora.account.PublicKeyAccount;
|
||||||
import org.qora.asset.Asset;
|
import org.qora.asset.Asset;
|
||||||
import org.qora.at.AT;
|
import org.qora.at.AT;
|
||||||
import org.qora.block.BlockChain.RewardByHeight;
|
import org.qora.block.BlockChain;
|
||||||
import org.qora.crypto.Crypto;
|
import org.qora.crypto.Crypto;
|
||||||
import org.qora.data.account.ProxyForgerData;
|
import org.qora.data.account.ProxyForgerData;
|
||||||
import org.qora.data.at.ATData;
|
import org.qora.data.at.ATData;
|
||||||
@ -1104,7 +1104,7 @@ public class Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void processBlockRewards() throws DataException {
|
protected void processBlockRewards() throws DataException {
|
||||||
BigDecimal reward = Block.getRewardAtHeight(this.blockData.getHeight());
|
BigDecimal reward = BlockChain.getInstance().getRewardAtHeight(this.blockData.getHeight());
|
||||||
|
|
||||||
// No reward for our height?
|
// No reward for our height?
|
||||||
if (reward == null)
|
if (reward == null)
|
||||||
@ -1353,7 +1353,7 @@ public class Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void orphanBlockRewards() throws DataException {
|
protected void orphanBlockRewards() throws DataException {
|
||||||
BigDecimal reward = Block.getRewardAtHeight(this.blockData.getHeight());
|
BigDecimal reward = BlockChain.getInstance().getRewardAtHeight(this.blockData.getHeight());
|
||||||
|
|
||||||
// No reward for our height?
|
// No reward for our height?
|
||||||
if (reward == null)
|
if (reward == null)
|
||||||
@ -1415,21 +1415,6 @@ public class Block {
|
|||||||
atRepository.deleteATStates(this.blockData.getHeight());
|
atRepository.deleteATStates(this.blockData.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BigDecimal getRewardAtHeight(int ourHeight) {
|
|
||||||
List<RewardByHeight> rewardsByHeight = BlockChain.getInstance().getBlockRewardsByHeight();
|
|
||||||
|
|
||||||
// No rewards configured?
|
|
||||||
if (rewardsByHeight == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
// Scan through for reward at our height
|
|
||||||
for (int i = rewardsByHeight.size() - 1; i >= 0; --i)
|
|
||||||
if (rewardsByHeight.get(i).height <= ourHeight)
|
|
||||||
return rewardsByHeight.get(i).reward;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Qora balance adjusted to within min/max limits.
|
* Return Qora balance adjusted to within min/max limits.
|
||||||
*/
|
*/
|
||||||
|
@ -299,6 +299,17 @@ public class BlockChain {
|
|||||||
return featureTriggers.get("newAssetPricingTimestamp");
|
return featureTriggers.get("newAssetPricingTimestamp");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// More complex getters for aspects that change by height or timestamp
|
||||||
|
|
||||||
|
public BigDecimal getRewardAtHeight(int ourHeight) {
|
||||||
|
// Scan through for reward at our height
|
||||||
|
for (int i = rewardsByHeight.size() - 1; i >= 0; --i)
|
||||||
|
if (rewardsByHeight.get(i).height <= ourHeight)
|
||||||
|
return rewardsByHeight.get(i).reward;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Validate blockchain config read from JSON */
|
/** Validate blockchain config read from JSON */
|
||||||
private void validateConfig() {
|
private void validateConfig() {
|
||||||
if (this.genesisInfo == null) {
|
if (this.genesisInfo == null) {
|
||||||
|
@ -3,6 +3,7 @@ package org.qora.test.common;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.qora.block.Block;
|
import org.qora.block.Block;
|
||||||
|
import org.qora.block.BlockChain;
|
||||||
import org.qora.data.block.BlockData;
|
import org.qora.data.block.BlockData;
|
||||||
import org.qora.repository.DataException;
|
import org.qora.repository.DataException;
|
||||||
import org.qora.repository.Repository;
|
import org.qora.repository.Repository;
|
||||||
@ -12,7 +13,7 @@ public class BlockUtils {
|
|||||||
public static BigDecimal getNextBlockReward(Repository repository) throws DataException {
|
public static BigDecimal getNextBlockReward(Repository repository) throws DataException {
|
||||||
int currentHeight = repository.getBlockRepository().getBlockchainHeight();
|
int currentHeight = repository.getBlockRepository().getBlockchainHeight();
|
||||||
|
|
||||||
return Block.getRewardAtHeight(currentHeight + 1);
|
return BlockChain.getInstance().getRewardAtHeight(currentHeight + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void orphanLastBlock(Repository repository) throws DataException {
|
public static void orphanLastBlock(Repository repository) throws DataException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user