AbstractDogecoinParams extends NetworkParameters implements AuxPoWNetworkParameters { protected long calculateNewDifficultyTargetInner(int previousHeight, final Block prev, final Block nextBlock, final Block blockIntervalAgo) { return this.calculateNewDifficultyTargetInner(previousHeight, prev.getTimeSeconds(), prev.getDifficultyTarget(), blockIntervalAgo.getTimeSeconds(), nextBlock.getDifficultyTarget()); } AbstractDogecoinParams(final int setDiffChangeTarget); @Override Coin getBlockSubsidy(final int height); int getNewInterval(); int getNewTargetTimespan(); MonetaryFormat getMonetaryFormat(); @Override Coin getMaxMoney(); @Override Coin getMinNonDustOutput(); @Override String getUriScheme(); @Override boolean hasMaxMoney(); @Override void checkDifficultyTransitions(StoredBlock storedPrev, Block nextBlock, BlockStore blockStore); long calculateNewDifficultyTarget(StoredBlock storedPrev, Block nextBlock, BlockStore blockStore); int getDigishieldBlockHeight(); @Override int getChainID(); abstract boolean allowMinDifficultyBlocks(); @Override Sha256Hash getBlockDifficultyHash(Block block); @Override AltcoinSerializer getSerializer(boolean parseRetain); @Override int getProtocolVersionNum(final ProtocolVersion version); @Override boolean isAuxPoWBlockVersion(long version); static final MonetaryFormat DOGE; static final MonetaryFormat MDOGE; static final MonetaryFormat KOINU; static final int DIGISHIELD_BLOCK_HEIGHT; static final int AUXPOW_CHAIN_ID; static final int DOGE_TARGET_TIMESPAN; static final int DOGE_TARGET_TIMESPAN_NEW; static final int DOGE_TARGET_SPACING; static final int DOGE_INTERVAL; static final int DOGE_INTERVAL_NEW; static final String CODE_DOGE; static final String CODE_MDOGE; static final String CODE_KOINU; static final String ID_DOGE_MAINNET; static final String ID_DOGE_TESTNET; static final int DOGECOIN_PROTOCOL_VERSION_AUXPOW; static final int DOGECOIN_PROTOCOL_VERSION_CURRENT; }
@Test public void shouldCalculateBitcoinLikeDifficulty() { int previousHeight = 239; long previousBlockTime = 1386475638; long lastRetargetDifficulty = 0x1e0ffff0; long lastRetargetTime = 1386474927; long nextDifficulty = 0x1e00ffff; long newDifficulty = params.calculateNewDifficultyTargetInner(previousHeight, previousBlockTime, lastRetargetDifficulty, lastRetargetTime, nextDifficulty); assertEquals(0x1e00ffff, newDifficulty); previousHeight = 9599; previousBlockTime = 1386954113; lastRetargetDifficulty = 0x1c1a1206; lastRetargetTime = 1386942008; nextDifficulty = 0x1c15ea59; newDifficulty = params.calculateNewDifficultyTargetInner(previousHeight, previousBlockTime, lastRetargetDifficulty, lastRetargetTime, nextDifficulty); assertEquals(0x1c15ea59, newDifficulty); }
@Test public void shouldConstrainActualTime() { final int previousHeight = 719; final long previousBlockTime = 1386476362; final long lastRetargetDifficulty = 0x1e00ffff; final long lastRetargetTime = 1386475840; final long nextDifficulty = 0x1d0ffff0; final long newDifficulty = params.calculateNewDifficultyTargetInner(previousHeight, previousBlockTime, lastRetargetDifficulty, lastRetargetTime, nextDifficulty); assertEquals(0x1d0ffff0, newDifficulty); }
@Test public void shouldCalculateDigishieldDifficulty() { final int previousHeight = 145000; final long previousBlockTime = 1395094679; final long lastRetargetDifficulty = 0x1b499dfd; final long lastRetargetTime = 1395094427; final long nextDifficulty = 0x1b671062; final long newDifficulty = params.calculateNewDifficultyTargetInner(previousHeight, previousBlockTime, lastRetargetDifficulty, lastRetargetTime, nextDifficulty); assertEquals(0x1b671062, newDifficulty); }
@Test public void shouldCalculateDigishieldDifficultyRounding() { final int previousHeight = 145001; final long previousBlockTime = 1395094727; final long lastRetargetDifficulty = 0x1b671062; final long lastRetargetTime = 1395094679; final long nextDifficulty = 0x1b6558a4; final long newDifficulty = params.calculateNewDifficultyTargetInner(previousHeight, previousBlockTime, lastRetargetDifficulty, lastRetargetTime, nextDifficulty); assertEquals(0x1b6558a4, newDifficulty); }
@Test public void shouldCalculateRetarget() throws IOException { byte[] payload; AltcoinSerializer serializer = (AltcoinSerializer)params.getDefaultSerializer(); final AltcoinBlock block239; final AltcoinBlock block479; final AltcoinBlock block480; final AltcoinBlock block719; final AltcoinBlock block720; payload = Util.getBytes(getClass().getResourceAsStream("dogecoin_block239.bin")); block239 = (AltcoinBlock)serializer.makeBlock(payload); payload = Util.getBytes(getClass().getResourceAsStream("dogecoin_block479.bin")); block479 = (AltcoinBlock)serializer.makeBlock(payload); payload = Util.getBytes(getClass().getResourceAsStream("dogecoin_block480.bin")); block480 = (AltcoinBlock)serializer.makeBlock(payload); payload = Util.getBytes(getClass().getResourceAsStream("dogecoin_block719.bin")); block719 = (AltcoinBlock)serializer.makeBlock(payload); payload = Util.getBytes(getClass().getResourceAsStream("dogecoin_block720.bin")); block720 = (AltcoinBlock)serializer.makeBlock(payload); assertEquals(Sha256Hash.wrap("f9533416310fc4484cf43405a858b06afc9763ad401d267c1835d77e7d225a4e"), block239.getHash()); assertEquals(Sha256Hash.wrap("ed83c923b532835f6597f70def42910aa9e06880e8a19b68f6b4a787f2b4b69f"), block479.getHash()); assertEquals(Sha256Hash.wrap("a0e6d1cdef02b394d31628c3281f67e8534bec74fda1a4294b58be80c3fdf3f3"), block480.getHash()); assertEquals(Sha256Hash.wrap("82e56e141ccfe019d475382d9a108ef86afeb297d95443dfd7250e57af805696"), block719.getHash()); assertEquals(Sha256Hash.wrap("6b34f1a7de1954beb0ddf100bb2b618ff0183b6ae2b4a9376721ef8e04ab3b39"), block720.getHash()); assertEquals(block480.getDifficultyTarget(), params.calculateNewDifficultyTargetInner(479, block479, block480, block239)); assertEquals(block720.getDifficultyTarget(), params.calculateNewDifficultyTargetInner(719, block719, block720, block479)); }