Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doge regtest #23

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions core/src/main/java/org/libdohj/params/AbstractDogecoinParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,21 @@

package org.libdohj.params;

import java.io.ByteArrayOutputStream;
import java.math.BigInteger;

import org.bitcoinj.core.AltcoinBlock;
import org.bitcoinj.core.Block;
import org.bitcoinj.core.Coin;
import static org.bitcoinj.core.Coin.COIN;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.VerificationException;
import org.bitcoinj.core.*;
import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptOpCodes;
import org.bitcoinj.store.BlockStore;
import org.bitcoinj.store.BlockStoreException;
import org.bitcoinj.utils.MonetaryFormat;

import org.libdohj.core.AltcoinSerializer;
import org.libdohj.core.AuxPoWNetworkParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionInput;
import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.core.Utils;
import org.libdohj.core.AltcoinSerializer;
import org.libdohj.core.AuxPoWNetworkParameters;
import java.io.ByteArrayOutputStream;
import java.math.BigInteger;

import static org.bitcoinj.core.Coin.COIN;

/**
* Common parameters for Dogecoin networks.
Expand Down Expand Up @@ -85,6 +74,7 @@ public abstract class AbstractDogecoinParams extends NetworkParameters implement
public static final String ID_DOGE_MAINNET = "org.dogecoin.production";
/** The string returned by getId() for the testnet. */
public static final String ID_DOGE_TESTNET = "org.dogecoin.test";
public static final String ID_DOGE_REGTEST = "org.dogecoin.regtest";

protected final int newInterval;
protected final int newTargetTimespan;
Expand Down Expand Up @@ -323,7 +313,7 @@ protected long calculateNewDifficultyTargetInner(int previousHeight, final Block
/**
* Calculate the difficulty target expected for the next block after a normal
* recalculation interval.
*
*
* @param previousHeight Height of the block immediately previous to the one we're calculating difficulty of.
* @param previousBlockTime Time of the block immediately previous to the one we're calculating difficulty of.
* @param lastDifficultyTarget Compact difficulty target of the last retarget block.
Expand Down
101 changes: 101 additions & 0 deletions core/src/main/java/org/libdohj/params/DogecoinRegTestParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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 bitcoind 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;
}

@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;
}
}