-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e68d7e
commit 444199b
Showing
2 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
core/src/main/java/org/libdohj/params/DogecoinRegTestParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright 2013 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.libdohj.params; | ||
|
||
import org.bitcoinj.core.Block; | ||
import org.bitcoinj.core.StoredBlock; | ||
import org.bitcoinj.core.VerificationException; | ||
import org.bitcoinj.store.BlockStore; | ||
import org.bitcoinj.store.BlockStoreException; | ||
|
||
import java.math.BigInteger; | ||
|
||
import static com.google.common.base.Preconditions.checkState; | ||
|
||
/** | ||
* Network parameters for the regression test mode of dogecoin in which all blocks are trivially solvable. | ||
*/ | ||
public class DogecoinRegTestParams extends DogecoinTestNet3Params { | ||
private static final BigInteger MAX_TARGET = new BigInteger("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16); | ||
|
||
public DogecoinRegTestParams() { | ||
super(); | ||
// Difficulty adjustments are disabled for regtest. | ||
// By setting the block interval for difficulty adjustments to Integer.MAX_VALUE we make sure difficulty never changes. | ||
interval = Integer.MAX_VALUE; | ||
maxTarget = MAX_TARGET; | ||
subsidyDecreaseBlockCount = 150; | ||
port = 18444; | ||
id = ID_DOGE_REGTEST; | ||
packetMagic = 0xfabfb5da; | ||
addressHeader = 111; | ||
dumpedPrivateKeyHeader = 239; | ||
} | ||
|
||
@Override | ||
public boolean allowEmptyPeerChain() { | ||
return true; | ||
} | ||
|
||
private static Block genesis; | ||
|
||
@Override | ||
public Block getGenesisBlock() { | ||
synchronized (DogecoinRegTestParams.class) { | ||
if (genesis == null) { | ||
genesis = super.getGenesisBlock(); | ||
genesis.setNonce(2); | ||
genesis.setDifficultyTarget(0x207fffffL); | ||
genesis.setTime(1296688602L); | ||
checkState(genesis.getVersion() == 1); | ||
checkState(genesis.getHashAsString().toLowerCase().equals("3d2160a3b5dc4a9d62e7e66a295f70313ac808440ef7400d6c0772171ce973a5")); | ||
genesis.verifyHeader(); | ||
} | ||
return genesis; | ||
} | ||
} | ||
|
||
private static DogecoinRegTestParams instance; | ||
|
||
public static synchronized DogecoinRegTestParams get() { | ||
if (instance == null) { | ||
instance = new DogecoinRegTestParams(); | ||
} | ||
return instance; | ||
} | ||
|
||
@Override | ||
public String getPaymentProtocolId() { | ||
return ID_DOGE_REGTEST; | ||
} | ||
|
||
@Override | ||
/** the testnet rules don't work for regtest, where difficulty stays the same */ | ||
public long calculateNewDifficultyTarget(StoredBlock storedPrev, Block nextBlock, BlockStore blockStore) | ||
throws VerificationException, BlockStoreException { | ||
final Block prev = storedPrev.getHeader(); | ||
return prev.getDifficultyTarget(); | ||
} | ||
|
||
@Override | ||
public boolean allowMinDifficultyBlocks() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isTestNet() { | ||
return false; | ||
} | ||
} |