/** * Get the Network we are working on.. * * @return the network */ public static NetworkParameters getNetwork () { return TestNet3Params.get(); // return RegTestParams.get(); // return MainNetParams.get(); }
public static synchronized TestNet3Params get() { if (instance == null) { instance = new TestNet3Params(); } return instance; }
@Override public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock, final BlockStore blockStore) throws VerificationException, BlockStoreException { if (!isDifficultyTransitionPoint(storedPrev) && nextBlock.getTime().after(testnetDiffDate)) { Block prev = storedPrev.getHeader(); while (!cursor.getHeader().equals(getGenesisBlock()) && cursor.getHeight() % getInterval() != 0 && cursor.getHeader().getDifficultyTargetAsInteger().equals(getMaxTarget())) cursor = cursor.getPrev(blockStore); BigInteger cursorTarget = cursor.getHeader().getDifficultyTargetAsInteger();
@Test public void getNetwork() throws Exception { NetworkParameters params = Address.getParametersFromAddress("17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL"); assertEquals(MainNetParams.get().getId(), params.getId()); params = Address.getParametersFromAddress("n4eA2nbYqErp7H6jebchxAN59DmNpksexv"); assertEquals(TestNet3Params.get().getId(), params.getId()); }
@Test public void testCoinbaseHeightTestnet() throws Exception { // Testnet block 21066 (hash 0000000004053156021d8e42459d284220a7f6e087bf78f30179c3703ca4eefa) // contains a coinbase transaction whose height is two bytes, which is // shorter than we see in most other cases. Block block = TestNet3Params.get().getDefaultSerializer().makeBlock( ByteStreams.toByteArray(getClass().getResourceAsStream("block_testnet21066.dat"))); // Check block. assertEquals("0000000004053156021d8e42459d284220a7f6e087bf78f30179c3703ca4eefa", block.getHashAsString()); block.verify(21066, EnumSet.of(Block.VerifyFlag.HEIGHT_IN_COINBASE)); // Testnet block 32768 (hash 000000007590ba495b58338a5806c2b6f10af921a70dbd814e0da3c6957c0c03) // contains a coinbase transaction whose height is three bytes, but could // fit in two bytes. This test primarily ensures script encoding checks // are applied correctly. block = TestNet3Params.get().getDefaultSerializer().makeBlock( ByteStreams.toByteArray(getClass().getResourceAsStream("block_testnet32768.dat"))); // Check block. assertEquals("000000007590ba495b58338a5806c2b6f10af921a70dbd814e0da3c6957c0c03", block.getHashAsString()); block.verify(32768, EnumSet.of(Block.VerifyFlag.HEIGHT_IN_COINBASE)); }
assertTrue(Arrays.equals(e.acceptableVersions, TestNet3Params.get().getAcceptableAddressCodes())); } catch (AddressFormatException e) { fail();
@Override public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock, final BlockStore blockStore, AbstractBlockChain blockChain) throws VerificationException, BlockStoreException { if (storedPrev.getHeight() < daaHeight && !isDifficultyTransitionPoint(storedPrev) && nextBlock.getTime().after(testnetDiffDate)) { Block prev = storedPrev.getHeader(); while (!cursor.getHeader().equals(getGenesisBlock()) && cursor.getHeight() % getInterval() != 0 && cursor.getHeader().getDifficultyTargetAsInteger().equals(getMaxTarget())) cursor = cursor.getPrev(blockStore); BigInteger cursorTarget = cursor.getHeader().getDifficultyTargetAsInteger();
@Test public void p2shAddress() throws Exception { // Test that we can construct P2SH addresses Address mainNetP2SHAddress = Address.fromBase58(MainNetParams.get(), "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU"); assertEquals(mainNetP2SHAddress.version, MainNetParams.get().p2shHeader); assertTrue(mainNetP2SHAddress.isP2SHAddress()); Address testNetP2SHAddress = Address.fromBase58(TestNet3Params.get(), "2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe"); assertEquals(testNetP2SHAddress.version, TestNet3Params.get().p2shHeader); assertTrue(testNetP2SHAddress.isP2SHAddress()); // Test that we can determine what network a P2SH address belongs to NetworkParameters mainNetParams = Address.getParametersFromAddress("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU"); assertEquals(MainNetParams.get().getId(), mainNetParams.getId()); NetworkParameters testNetParams = Address.getParametersFromAddress("2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe"); assertEquals(TestNet3Params.get().getId(), testNetParams.getId()); // Test that we can convert them from hashes byte[] hex = HEX.decode("2ac4b0b501117cc8119c5797b519538d4942e90e"); Address a = Address.fromP2SHHash(mainParams, hex); assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", a.toString()); Address b = Address.fromP2SHHash(testParams, HEX.decode("18a0e827269b5211eb51a4af1b2fa69333efa722")); assertEquals("2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe", b.toString()); Address c = Address.fromP2SHScript(mainParams, ScriptBuilder.createP2SHOutputScript(hex)); assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", c.toString()); }
/** Alias for TestNet3Params.get(), use that instead. */ @Deprecated public static NetworkParameters testNet3() { return TestNet3Params.get(); }
@Override public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock, final BlockStore blockStore) throws VerificationException, BlockStoreException { if (!isDifficultyTransitionPoint(storedPrev.getHeight()) && nextBlock.getTime().after(testnetDiffDate)) { Block prev = storedPrev.getHeader(); // After 15th February 2012 the rules on the testnet change to avoid people running up the difficulty // and then leaving, making it too hard to mine a block. On non-difficulty transition points, easy // blocks are allowed if there has been a span of 20 minutes without one. final long timeDelta = nextBlock.getTimeSeconds() - prev.getTimeSeconds(); // There is an integer underflow bug in bitcoin-qt that means mindiff blocks are accepted when time // goes backwards. if (timeDelta >= 0 && timeDelta <= NetworkParameters.TARGET_SPACING * 2) { // Walk backwards until we find a block that doesn't have the easiest proof of work, then check // that difficulty is equal to that one. StoredBlock cursor = storedPrev; while (!cursor.getHeader().equals(getGenesisBlock()) && cursor.getHeight() % getInterval() != 0 && cursor.getHeader().getDifficultyTargetAsInteger().equals(getMaxTarget())) cursor = cursor.getPrev(blockStore); BigInteger cursorTarget = cursor.getHeader().getDifficultyTargetAsInteger(); BigInteger newTarget = nextBlock.getDifficultyTargetAsInteger(); if (!cursorTarget.equals(newTarget)) throw new VerificationException("Testnet block transition that is not allowed: " + Long.toHexString(cursor.getHeader().getDifficultyTarget()) + " vs " + Long.toHexString(nextBlock.getDifficultyTarget())); } } else { super.checkDifficultyTransitions(storedPrev, nextBlock, blockStore); } }
public static synchronized TestNet3Params get() { if (instance == null) { instance = new TestNet3Params(); } return instance; }
/** Alias for TestNet3Params.get(), use that instead. */ @Deprecated public static NetworkParameters testNet() { return TestNet3Params.get(); }
@Override public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock, final BlockStore blockStore) throws VerificationException, BlockStoreException { if (!isDifficultyTransitionPoint(storedPrev.getHeight()) && nextBlock.getTime().after(testnetDiffDate)) { Block prev = storedPrev.getHeader(); // After 15th February 2012 the rules on the testnet change to avoid people running up the difficulty // and then leaving, making it too hard to mine a block. On non-difficulty transition points, easy // blocks are allowed if there has been a span of 20 minutes without one. final long timeDelta = nextBlock.getTimeSeconds() - prev.getTimeSeconds(); // There is an integer underflow bug in bitcoin-qt that means mindiff blocks are accepted when time // goes backwards. if (timeDelta >= 0 && timeDelta <= NetworkParameters.TARGET_SPACING * 2) { // Walk backwards until we find a block that doesn't have the easiest proof of work, then check // that difficulty is equal to that one. StoredBlock cursor = storedPrev; while (!cursor.getHeader().equals(getGenesisBlock()) && cursor.getHeight() % getInterval() != 0 && cursor.getHeader().getDifficultyTargetAsInteger().equals(getMaxTarget())) cursor = cursor.getPrev(blockStore); BigInteger cursorTarget = cursor.getHeader().getDifficultyTargetAsInteger(); BigInteger newTarget = nextBlock.getDifficultyTargetAsInteger(); if (!cursorTarget.equals(newTarget)) throw new VerificationException("Testnet block transition that is not allowed: " + Long.toHexString(cursor.getHeader().getDifficultyTarget()) + " vs " + Long.toHexString(nextBlock.getDifficultyTarget())); } } else { super.checkDifficultyTransitions(storedPrev, nextBlock, blockStore); } }
public static synchronized TestNet3Params get() { if (instance == null) { instance = new TestNet3Params(); } return instance; }
/** Alias for TestNet3Params.get(), use that instead. */ @Deprecated public static NetworkParameters testNet() { return TestNet3Params.get(); }
public static synchronized TestNet3Params get() { if (instance == null) { instance = new TestNet3Params(); } return instance; }
/** Alias for TestNet3Params.get(), use that instead. */ @Deprecated public static NetworkParameters testNet3() { return TestNet3Params.get(); }
/** Alias for TestNet3Params.get(), use that instead. */ @Deprecated public static NetworkParameters testNet() { return TestNet3Params.get(); }
/** Alias for TestNet3Params.get(), use that instead. */ @Deprecated public static NetworkParameters testNet3() { return TestNet3Params.get(); }
/** Alias for TestNet3Params.get(), use that instead. */ @Deprecated public static NetworkParameters testNet() { return TestNet3Params.get(); }