mirror of
https://github.com/Qortal/qortal.git
synced 2025-02-12 02:05:50 +00:00
Fix forging bit mask for account flags
This commit is contained in:
parent
8149e18f49
commit
158631e68a
@ -2,13 +2,14 @@ package org.qora.account;
|
||||
|
||||
import org.qora.block.BlockChain;
|
||||
import org.qora.repository.DataException;
|
||||
import org.qora.utils.BitTwiddling;
|
||||
|
||||
/** Relating to whether accounts can forge. */
|
||||
public class Forging {
|
||||
|
||||
/** Returns mask for account flags for forging bits. */
|
||||
public static int getForgingMask() {
|
||||
return (1 << BlockChain.getInstance().getForgingTiers().size()) - 1;
|
||||
return BitTwiddling.calcMask(BlockChain.getInstance().getForgingTiers().size() - 1);
|
||||
}
|
||||
|
||||
public static boolean canForge(Account account) throws DataException {
|
||||
|
24
src/main/java/org/qora/utils/BitTwiddling.java
Normal file
24
src/main/java/org/qora/utils/BitTwiddling.java
Normal file
@ -0,0 +1,24 @@
|
||||
package org.qora.utils;
|
||||
|
||||
public class BitTwiddling {
|
||||
|
||||
/**
|
||||
* Returns bit-mask for values up to, and including, <tt>maxValue</tt>.
|
||||
* <p>
|
||||
* e.g. for values up to 5 (0101b) this returns a mask of 7 (0111b).
|
||||
* <p>
|
||||
* Based on Integer.highestOneBit.
|
||||
*
|
||||
* @param maxValue
|
||||
* @return mask
|
||||
*/
|
||||
public static int calcMask(int maxValue) {
|
||||
maxValue |= maxValue >> 1;
|
||||
maxValue |= maxValue >> 2;
|
||||
maxValue |= maxValue >> 4;
|
||||
maxValue |= maxValue >> 8;
|
||||
maxValue |= maxValue >> 16;
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user