changeset 29724:20ca5028ab4d

Refactor make test
author Troy Benjegerdes <hozer@hozed.org>
date Thu, 01 Feb 2018 22:51:37 -0600
parents 805b94b58299
children
files src/Makefile src/bitcoin/bitcoin.h src/bloom.h src/codecoin.h src/grantcoin/consensus.h src/grantcoin/grantcoin.h src/grantcoin/params.cpp src/init.cpp src/litecoin/litecoin.h src/net.cpp src/netbase.cpp src/primitives/block.cpp src/primitives/block.h src/primitives/transaction.cpp src/primitives/transaction.h src/test/prevector_tests.cpp src/test/txvalidationcache_tests.cpp
diffstat 17 files changed, 468 insertions(+), 269 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/Makefile	Thu Feb 01 22:51:37 2018 -0600
@@ -396,8 +396,6 @@
 	mkdir -p $(DESTDIR)$(prefix)/bin
 	install -D $^ $(DESTDIR)$(prefix)/bin/
 
-test check: obj/test_$(COIN_BRAND) FORCE
-	./obj/test_$(COIN_BRAND)
 
 regression: test FORCE
 	$(MAKE) COIN_BRAND=litecoin test
@@ -489,6 +487,8 @@
   test/data/tx_valid.json \
   test/data/sighash.json
 
+JSON_TEST_H_FILES = $(patsubst test/data/%.json,$(OBJDIR)/test/data/%.json.h,$(wildcard $(JSON_TEST_FILES)))
+
 RAW_TEST_FILES = test/data/alertTests.raw
 
 $(OBJDIR)/%.json.h: %.json
@@ -499,9 +499,13 @@
 	@echo "};};" >> $@
 	@echo "Generated $@"
 
-TESTOBJS := $(patsubst test/%.cpp,$(OBJDIR)/test/%.o,$(wildcard test/*.cpp))
+TESTS := $(patsubst test/%.cpp,%,$(wildcard test/*_tests.cpp))
+TEST_OBJS := $(patsubst %,$(OBJDIR)/test/%.o,$(TESTS))
+TEST_EXTRA_OBJS = $(OBJDIR)/test/test_codecoin.o $(OBJDIR)/test/test_bitcoin_main.o
 
-$(TESTOBJS): $(patsubst test/data/%.json,$(OBJDIR)/test/data/%.json.h,$(wildcard $(JSON_TEST_FILES)))
+$(TEST_OBJS): $(JSON_TEST_H_FILES) $(TESTDIR)
+
+$(TEST_EXTRA_OBJS): $(TESTDIR)
 
 $(OBJDIR)/test/%.o: test/%.cpp
 	$(V_CXX) $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
@@ -513,23 +517,25 @@
 #yes this has extra cruft for scrypt. ugh.
 #filter for init.o is ugly too
 
-fltr_d_ojbs = $(OBJDIR)/init.o $(OBJDIR)/torcontrol.o 
-test_d_objs = $(filter-out $(fltr),$(D_OBJS:$(OBJDIR)/%=$(OBJDIR)/%))
-testobjs = $(filter-out $(OBJDIR)/test/test_bitcoin_fuzzy.o,$(TESTOBJS))
+fltr_d_objs = $(OBJDIR)/init.o $(OBJDIR)/torcontrol.o 
+test_d_objs = $(filter-out $(fltr_d_objs),$(D_OBJS:$(OBJDIR)/%=$(OBJDIR)/%))
 
-obj/test_$(COIN_BRAND): $(test_d_objs) \
-		$(WALLET_OBJS) $(testobjs) \
+$(TESTS): obj/test_$(COIN_BRAND) FORCE
+	./obj/test_$(COIN_BRAND) --run_test=$@
+
+test check: $(TESTS)
+
+obj/test_$(COIN_BRAND): $(test_d_objs) $(TEST_EXTRA_OBJS) \
+		$(WALLET_OBJS) $(TEST_OBJS) \
 		$(OBJDIR)/rpc/client.o $(OBJDIR)/crypto/scrypt.o $(OBJS_SSE2)
 	$(V_LINK) $(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ $(TESTLIBS) $(xLDFLAGS) $(LIBS) $(D_LIBS) $(BOOST_LIBS)
 endif
 
 clean:
-	-rm -f $(OBJDIR)/*.o
-	-rm -f $(OBJDIR)/*/*.o
-	-rm -f $(OBJDIR)/*.P
-	-rm -f $(OBJDIR)/*/*.P
-	-rm -f $(OBJDIR)/build.h
-	-rm -f obj/$(COIN_BRAND)* obj/test_$(COIN_BRAND)
+	-rm -f $(OBJDIR)/*.o $(OBJDIR)/*/*.o
+	-rm -f $(OBJDIR)/*.P $(OBJDIR)/*/*.P
+	-rm -f $(OBJDIR)/build.h $(OBJDIR)/*/*/*.json.h
+	-rm -f $(MAN) $(BINS) obj/test_$(COIN_BRAND)
 
 realclean:
 	rm -rf obj
--- a/src/bitcoin/bitcoin.h	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/bitcoin/bitcoin.h	Thu Feb 01 22:51:37 2018 -0600
@@ -51,8 +51,4 @@
 #define BRAND_file __FILE__
 #define BITCOIN_COMPAT
 
-/* allow for overloads.. */
-#define CTransaction Transaction
-#define CMutableTransaction MutableTransaction
-
 #endif
--- a/src/bloom.h	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/bloom.h	Thu Feb 01 22:51:37 2018 -0600
@@ -15,7 +15,8 @@
 #include <vector>
 
 class COutPoint;
-class Transaction;
+#include <codecoin.h>
+class CTransaction;
 class uint256;
 
 //! 20,000 items with fp rate < 0.1% or 10,000 items and <0.0001%
@@ -103,7 +104,7 @@
     //! Also adds any outputs which match the filter to the filter (to match their spending txes)
     //bool IsRelevantAndUpdate(const CTransaction& tx);
     //! Codecoin TODO: finish migration from CTransaction to Transaction
-    bool IsRelevantAndUpdate(const Transaction& tx);
+    bool IsRelevantAndUpdate(const CTransaction& tx);
 
     //! Checks for empty and full filters to avoid wasting cpu
     void UpdateEmptyFull();
--- a/src/codecoin.h	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/codecoin.h	Thu Feb 01 22:51:37 2018 -0600
@@ -51,6 +51,12 @@
 #ifndef CBlockHeader
 #define CBlockHeader BlockHeader
 #endif
+#ifndef CTransaction
+#define CTransaction SegwitTx
+#endif
+#ifndef CMutableTransaction
+#define CMutableTransaction MutableSegwitTx
+#endif
 
 /* This used to be in configure's bitcoin_config.h */
 #define HAVE_DECL_DAEMON 1	/* linux/osx support for now */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/grantcoin/consensus.h	Thu Feb 01 22:51:37 2018 -0600
@@ -0,0 +1,37 @@
+// Copyright (c) 2009-2010 Satoshi Nakamoto
+// Copyright (c) 2009-2016 The Bitcoin Core developers
+// This file is part of the Catoshi Codecoin financial cryptography software
+// Copyright (c) 2014-2018 7 Elements LLC
+// Distributed under the Affero GNU General public license version 3
+// see the file COPYING or http://www.gnu.org/licenses/agpl-3.0.html
+
+/* Bitcoin consensus defines, following Bitcoin's consensus.h */
+
+#ifndef CODECOIN_GRANTCOIN_CONSENSUS_H
+#define CODECOIN_GRANTCOIN_CONSENSUS_H
+
+#include <stdlib.h>
+#include <stdint.h>
+
+/** The maximum allowed size for a serialized block, in bytes (only for buffer size limits) */
+static const unsigned int MAX_BLOCK_SERIALIZED_SIZE = 1000000;
+/** The maximum allowed weight for a block, see BIP 141 (network rule) */
+static const unsigned int MAX_BLOCK_WEIGHT = 1000000;
+/** The maximum allowed number of signature check operations in a block (network rule) */
+static const int64_t MAX_BLOCK_SIGOPS_COST = 20000;
+/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
+static const int COINBASE_MATURITY = 500;
+
+/* why not.. not using it yet anyway.. */
+static const int WITNESS_SCALE_FACTOR = 3;
+
+static const size_t MIN_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 60; // 60 is the lower bound for the size of a valid serialized CTransaction
+static const size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 10; // 10 is the lower bound for the size of a serialized CTransaction
+
+/** Flags for nSequence and nLockTime locks */
+/** Interpret sequence numbers as relative lock-time constraints. */
+static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE = (1 << 0);
+/** Use GetMedianTimePast() instead of nTime for end point timestamp. */
+static constexpr unsigned int LOCKTIME_MEDIAN_TIME_PAST = (1 << 1);
+
+#endif // CODECOIN_GRANTCOIN_CONSENSUS_H
--- a/src/grantcoin/grantcoin.h	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/grantcoin/grantcoin.h	Thu Feb 01 22:51:37 2018 -0600
@@ -4,29 +4,21 @@
 #ifndef CODECOIN_grantcoin_H
 #define CODECOIN_grantcoin_H
 
-/* ========= Things defined in bitcoin@0.12/consensus/consensus.h  ========= */
+#include "grantcoin/consensus.h"
 
-/** The maximum allowed size for a serialized block, in bytes (network rule) */
-static const unsigned int MAX_BLOCK_SIZE =   1000000; // Segwit will move this around
-static const unsigned int MAX_BLOCK_SIZE_GEN = 1000000/2;
+/* ========= Things migrated from ~bitcoin@.15/policy/policy.h    ========= */
 
-/** The maximum allowed number of signature check operations in a block (network rule) */
-static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
+/** Default for -maxmempool, maximum megabytes of mempool memory usage */
+static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 500;
 
-/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
-static const int COINBASE_MATURITY = 500;
+/** Min feerate for defining dust. Historically this has been based on the
+ * minRelayTxFee, however changing the dust limit changes which transactions are
+ * standard and should be done with care and ideally rarely. It makes sense to
+ * only increase the dust limit after prior releases were already not creating
+ * outputs below the new threshold */
+static const unsigned int DUST_RELAY_TX_FEE = 3000;
 
-/** Flags for nSequence and nLockTime locks */
-#warning "check validity for grantcoin"
-enum {
-    /* Interpret sequence numbers as relative lock-time constraints. */
-    LOCKTIME_VERIFY_SEQUENCE = (1 << 0),
-
-    /* Use GetMedianTimePast() instead of nTime for end point timestamp. */
-    LOCKTIME_MEDIAN_TIME_PAST = (1 << 1),
-};
-
-/* ========= End defines from bitcoin@0.12/consensus/consensus.h  ========= */
+/* ========= End defines from bitcoin@0.14/policy/policy.h        ========= */
 
 static const int RPC_PORT = 9983;
 static const int RPC_PORT_TESTNET = 9985;
@@ -39,14 +31,17 @@
 static const int COIN_DECIMALS = 6; /* decimal places for coin */
 #define COIN_DECIMALS_FMT "06"
 
+/** Default for -minrelaytxfee, minimum relay fee for transactions */
+static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = CENT;
+
 /** No amount larger than this (in satoshi) is valid */
 static const int64_t MAX_MONEY = 50000000000 * COIN;
 inline bool MoneyRange(int64_t nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
 
 
-static const int STAKE_TARGET_SPACING = 1.5 * 60; // 90-second block spacing 
-static const unsigned int nStakeMinAge = 60 * 60 * 24; // minimum age for coin age (24 hours)
-static const unsigned int nStakeMaxAge = 60 * 60 * 24 * 90; // stake age of full weight
+//static const int STAKE_TARGET_SPACING = 1.5 * 60; // 90-second block spacing 
+//static const unsigned int nStakeMinAge = 60 * 60 * 24; // minimum age for coin age (24 hours)
+//static const unsigned int nStakeMaxAge = 60 * 60 * 24 * 90; // stake age of full weight
 //static const int64 START_BLOCK_PROOF_OF_STAKE = 250000; // PoS allowed starting at this block
 
 extern const unsigned int nMaxClockDrift;
@@ -70,6 +65,8 @@
 
 #define FEATURE_MONEYSUPPLY
 #define FEATURE_CFG_MAXFUTURE
+extern int32_t nMaxFutureTime;
+
 #define FEATURE_FUTURE_IS_HARDER
 
 #define BRAND "Grantcoin"
@@ -88,10 +85,14 @@
 /* primitives/<stuff> needs this */
 #define BITCOIN_COMPAT
 
-/* allow for overloads.. */
-#define CTransaction TransactionGRT
-#define CMutableTransaction MutableTransactionGRT
+/* overload the BITCOIN_COMPAT defines*/
+#define CTransaction StakeTx
+#define CMutableTransaction MutableStakeTx
+
 #define CBlockHeader BlockHeader
-#define CBlock BlockGRT
+
+/* TODO make BlockGRT (or StakeBlock??) later */
+//#define CBlock BlockGRT
+#define CBlock Block
 
 #endif
--- a/src/grantcoin/params.cpp	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/grantcoin/params.cpp	Thu Feb 01 22:51:37 2018 -0600
@@ -1,25 +1,24 @@
 // Copyright (c) 2010 Satoshi Nakamoto
 // Copyright (c) 2009-2014 The Bitcoin developers
-// Copyright (c) 2014 Troy Benjegerdes, under AGPLv3
+// Copyright (c) 2014-2018 Troy Benjegerdes, under AGPLv3
 // Distributed under the Affero GNU General public license version 3
 // file COPYING or http://www.gnu.org/licenses/agpl-3.0.html
 
-#include "chainparams.h"
-#include "consensus/merkle.h"
+/* Grantcoin/Manna Params */
 
-#include "tinyformat.h"
-#include "util.h"
-#include "utilstrencodings.h"
+#include <chainparams.h>
+#include <consensus/merkle.h>
+
+#include <tinyformat.h>
+#include <util.h>
+#include <utilstrencodings.h>
 
 #include <cinttypes>
 #include <assert.h>
 
-#include <boost/assign/list_of.hpp>
 
 #include "arith_uint256.h"
 
-//using namespace std;
-
 /**
  * Main network
  */
@@ -29,6 +28,17 @@
 public:
     CMainParams() {
         strNetworkID = "grantcoin";
+        //consensus.powLimit = ~uint256S(0) >> 28; // Reduced initial difficulty from Peercoin's 32
+        //consensus.powLimit = uint256S("0000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
+	consensus.powLimit = ArithToUint256(~arith_uint256(0) >> 28); // TODO: implement operator= for this
+        consensus.nMajorityEnforceBlockUpgrade = 750;
+        consensus.nMajorityRejectBlockOutdated = 950;
+        consensus.nMajorityWindow = 1000;
+        consensus.nPowTargetTimespan = 3.5 * 24 * 60 * 60; // 3.5 days FIXME not used for GRT?
+        consensus.nPowTargetSpacing = 1.5 * 60; // 1.5 minutes
+        consensus.nMinerConfirmationWindow = 3360;
+        consensus.nRuleChangeActivationThreshold = 3024; /* 90% of miners */
+
         /** 
          * The message start string is designed to be unlikely to occur in normal data.
          * The characters are rarely used upper ASCII, not valid as UTF-8, and produce
@@ -39,16 +49,6 @@
         pchMessageStart[2] = 0xe1;
         pchMessageStart[3] = 0xe4;
         nDefaultPort = 9982; /* P2P_PORT */
-        //consensus.powLimit = ~uint256S(0) >> 28; // Reduced initial difficulty from Peercoin's 32
-        //consensus.powLimit = uint256S("0000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
-	consensus.powLimit = ArithToUint256(~arith_uint256(0) >> 28); // TODO: implement operator= for this
-        consensus.nMajorityEnforceBlockUpgrade = 750;
-        consensus.nMajorityRejectBlockOutdated = 950;
-        consensus.nMajorityWindow = 1000;
-        consensus.nPowTargetTimespan = 3.5 * 24 * 60 * 60; // 3.5 days FIXME not used for GRT?
-        consensus.nPowTargetSpacing = 1.5 * 60; // 1.5 minutes
-        consensus.nMinerConfirmationWindow = 3360;
-        consensus.nRuleChangeActivationThreshold = 3024; /* 90% of miners */
 
         nMaxTipAge = 24 * 60 * 60;
 
@@ -93,30 +93,27 @@
         fMineBlocksOnDemand = false;
         fTestnetToBeDeprecatedFieldRPC = false;
 
-#if 0
-        checkpointData = (CCheckpointData) {
-            boost::assign::map_list_of
-	    (     0, uint256S("0000000f0483c7cc4433d89e321373d82d86ef5ba8157d8f7b9ef3449283421a"))
-//	    (33000, uint256S("0x"))
-	    1434870875, 	// * UNIX timestamp of last checkpoint block
-	    106400,		// * total number of transactions between genesis and last checkpoint
-				//	 (the tx=... number in the SetBestChain debug.log lines)
-	    1000.0		// * estimated number of transactions per day after checkpoint
+        checkpointData = {
+	{
+		{  11111, uint256S("00000005e6192125f526f1a8f24b47253282259d6c59adf2039157c523f5ef6c")},
+		{ 100000, uint256S("000000000000266c129bdcc8549e1517a2d3ec2a5c8aedad7f77ae12426be4d4")},
+		{ 200000, uint256S("00000000000019f86a0086b0d5acdf95a8c7a6da2e1cf9c052f8ed6a7a01957f")},
+		//  300000 00000000000019f86a0086b0d5acdf95a8c7a6da2e1cf9c052f8ed6a7a01957f	
+		// 400000 0000000000004937c23ec9c7e8b007370d99b18220624e12d27f9e80723080a0
+		// 500000 000000000000014c803fb1b57d8b05d70d1765ca2d932093b8ff1e00e35b15d3
+		// 600000 0000000000001b44b2e64698557c16224d37331c0d0b69442084dde82dfa9b78
+		// 700000 000000000000751463730a2ede3218249ee7917889a8cf7396ac881cadab5ac7
+		{ 800000, uint256S("00000000004add0b66dab5d4dadae283211f7de0dbd37d2ba6504b603c9b2599")},
+		{ 900000, uint256S("000000000008bef9e174e237d87c067a7f17b289647011465e1a6430fec7a40b")},
+		{ 994000, uint256S("0000000000003599eee46c88fa2d0a52d8b978dd4642f1787e4c465f43b7b2b2")},	
 	};
-#else
-        checkpointData = (CCheckpointData) {
-            boost::assign::map_list_of
-            ( 11111, uint256S("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"))
-	};
-#endif
     }
 };
-static CMainParams mainParams;
 
 /**
  * Testnet (Grantcoin v1)
  */
-class CTestNetParams : public CMainParams {
+class CTestNetParams : public CChainParams {
 public:
     CTestNetParams() {
         strNetworkID = "test";
@@ -158,7 +155,7 @@
 
         vFixedSeeds.clear();
         vSeeds.clear();
-        vSeeds.push_back(CDNSSeedData("testseed.grantcoin.org", "testseed.grt.7el.us"));
+        vSeeds.emplace_back("testseed.grantcoin.org", "testseed.grt.7el.us");
 
         base58Prefixes[PUBKEY_ADDRESS] = { 65 };  // grantcoin test blockchain: addresses begin with 'T'
         base58Prefixes[SCRIPT_ADDRESS] = { 127 }; // grantcoin test blockchain: addresses begin with 't'
@@ -170,11 +167,101 @@
         fDefaultConsistencyChecks = false;
         fRequireStandard = false;
         fMineBlocksOnDemand = false;
-        fTestnetToBeDeprecatedFieldRPC = true;
+
+#if 0
+        checkpointData = {
+            {
+                {546, uint256S("0")},
+            }
+        };
+
+	/* 			   Unix TS, total TX=, estimated transactions/sec */
+        chainTxData = ChainTxData{
+#error
+            1517526271, // Unix 
+            100000,
+            0.01
+        };
+#endif
     }
 };
 
-static CTestNetParams testNetParams;
+/**
+ * Regression test
+ */
+class CRegTestParams : public CChainParams {
+public:
+    CRegTestParams() {
+        strNetworkID = "regtest";
+        consensus.nSubsidyHalvingInterval = 150;
+        consensus.BIP16Height = 0; // always enforce P2SH BIP16 on regtest
+        consensus.BIP34Height = 100000000; // BIP34 has not activated on regtest (far in the future so block v1 are not rejected in tests)
+        consensus.BIP34Hash = uint256();
+        consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests)
+        consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests)
+        consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
+        consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
+        consensus.nPowTargetSpacing = 10 * 60;
+        consensus.fPowAllowMinDifficultyBlocks = true;
+        consensus.fPowNoRetargeting = true;
+        consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
+        consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
+        consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
+        consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
+        consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
+        consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
+        consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 0;
+        consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
+        consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
+        consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = Consensus::BIP9Deployment::ALWAYS_ACTIVE;
+        consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
+
+        // The best chain should have at least this much work.
+        consensus.nMinimumChainWork = uint256S("0x00");
+
+        // By default assume that the signatures in ancestors of this block are valid.
+        consensus.defaultAssumeValid = uint256S("0x00");
+
+        pchMessageStart[0] = 0xfa;
+        pchMessageStart[1] = 0xbf;
+        pchMessageStart[2] = 0xb5;
+        pchMessageStart[3] = 0xda;
+        nDefaultPort = 18444;
+        nPruneAfterHeight = 1000;
+
+        genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN);
+        consensus.hashGenesisBlock = genesis.GetHash();
+        assert(consensus.hashGenesisBlock == uint256S("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
+        assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
+
+        vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
+        vSeeds.clear();      //!< Regtest mode doesn't have any DNS seeds.
+
+        fDefaultConsistencyChecks = true;
+        fRequireStandard = false;
+        fMineBlocksOnDemand = true;
+
+        checkpointData = {
+            {
+                {0, uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")},
+            }
+        };
+
+        chainTxData = ChainTxData{
+            0,
+            0,
+            0
+        };
+
+        base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
+        base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
+        base58Prefixes[SECRET_KEY] =     std::vector<unsigned char>(1,239);
+        base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
+        base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
+
+        bech32_hrp = "bcrt";
+    }
+};
 
 static CChainParams *pCurrentParams = 0;
 
@@ -208,6 +295,9 @@
 using namespace std;
 using namespace boost;
 
+// GRT always has FEATURE_MAXFUTURE
+int32_t nMaxFutureTime = 0;
+
 // TODO: separate max clock drift from tx timestamp limits?
 const unsigned int nMaxClockDrift = 2*60*60;   // this is WAY to big..
 
--- a/src/init.cpp	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/init.cpp	Thu Feb 01 22:51:37 2018 -0600
@@ -1054,9 +1054,9 @@
         nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
 
 #if defined(FEATURE_CFG_MAXFUTURE)
-	if (IsArgSet("-maxfuture"))
+	if (gArgs.IsArgSet("-maxfuture"))
 	{
-		int nNewFuture = GetArg("-maxfuture", 7200);
+		int nNewFuture = gArgs.GetArg("-maxfuture", 7200);
 		if (nNewFuture > 0 && nNewFuture < 20000){
 			nMaxFutureTime = nNewFuture;
 			InitWarning(strprintf(_("maxfuture (nMaxFutureTime) set to %d"), nMaxFutureTime));
--- a/src/litecoin/litecoin.h	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/litecoin/litecoin.h	Thu Feb 01 22:51:37 2018 -0600
@@ -41,8 +41,4 @@
 #define LITECOIN_SCRYPT_POWHASH
 #define BITCOIN_COMPAT
 
-/* allow for overloads.. */
-#define CTransaction Transaction
-#define CMutableTransaction MutableTransaction
-
 #endif
--- a/src/net.cpp	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/net.cpp	Thu Feb 01 22:51:37 2018 -0600
@@ -42,12 +42,12 @@
 // We add a random period time (0 to 1 seconds) to feeler connections to prevent synchronization.
 #define FEELER_SLEEP_WINDOW 1
 
-#if !defined(HAVE_MSG_NOSIGNAL)
+#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
 #define MSG_NOSIGNAL 0
 #endif
 
 // MSG_DONTWAIT is not available on some platforms, if it doesn't exist define it as 0
-#if !defined(HAVE_MSG_DONTWAIT)
+#if !defined(HAVE_MSG_DONTWAIT) && !defined(MSG_DONTWAIT)
 #define MSG_DONTWAIT 0
 #endif
 
--- a/src/netbase.cpp	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/netbase.cpp	Thu Feb 01 22:51:37 2018 -0600
@@ -24,7 +24,7 @@
 #include <boost/algorithm/string/case_conv.hpp> // for to_lower()
 #include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
 
-#if !defined(HAVE_MSG_NOSIGNAL)
+#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
 #define MSG_NOSIGNAL 0
 #endif
 
--- a/src/primitives/block.cpp	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/primitives/block.cpp	Thu Feb 01 22:51:37 2018 -0600
@@ -1,12 +1,12 @@
 // Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2016 The Bitcoin developers
+// Copyright (c) 2009-2017 The Bitcoin Core developers
 // Copyright (c) 2009-2012 The *coin developers
 // where * = (Bit, Lite, PP, Peerunity, Blu, Cat, Solar, URO, ...)
-// Previously distributed under the MIT/X11 software license, see the
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-// Copyright (c) 2014-2017 Troy Benjegerdes, under AGPLv3
+// Previously distributed under the MIT/X11 software license, see 
+// http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2014-2018 Troy Benjegerdes, under AGPLv3
 // Distributed under the Affero GNU General public license version 3
-// file COPYING or http://www.gnu.org/licenses/agpl-3.0.html
+// see the file COPYING or http://www.gnu.org/licenses/agpl-3.0.html
 
 #include <primitives/block.h>
 
@@ -17,6 +17,12 @@
 
 #if defined(LITECOIN_SCRYPT_POWHASH)
 #include "crypto/scrypt.h"
+uint256 ScryptBlockHeader::GetPoWHash() const
+{
+    uint256 thash;
+    scrypt_1024_1_1_256(BEGIN(nVersion), BEGIN(thash));
+    return thash;
+}
 #endif
 
 uint256 BlockHeader::GetHash() const
@@ -24,21 +30,12 @@
     return SerializeHash(*this);
 }
 
-uint256 BlockHeader::GetPoWHash() const
-{
-#if defined(LITECOIN_SCRYPT_POWHASH)
-    uint256 thash;
-    scrypt_1024_1_1_256(BEGIN(nVersion), BEGIN(thash));
-    return thash;
-#else
-	return GetHash();
-#endif
-}
-
-std::string CBlock::ToString() const
+std::string Block::ToString() const
 {
     std::stringstream s;
-    s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
+    s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, "
+                   "hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, "
+                   "vtx=%u)\n",
         GetHash().ToString(),
         nVersion,
         hashPrevBlock.ToString(),
--- a/src/primitives/block.h	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/primitives/block.h	Thu Feb 01 22:51:37 2018 -0600
@@ -11,7 +11,7 @@
 #ifndef CODECOIN_PRIMITIVES_BLOCK_H
 #define CODECOIN_PRIMITIVES_BLOCK_H
 
-#include <codecoin.h>
+//#include <codecoin.h>
 #include <primitives/transaction.h>
 #include <serialize.h>
 #include <uintBIG.h>
@@ -78,7 +78,10 @@
 
     uint256 GetHash() const;
 
-    uint256 GetPoWHash() const;
+    uint256 GetPoWHash() const
+    { 
+        return GetHash();
+    };
 
     int64_t GetBlockTime() const
     {
@@ -86,10 +89,15 @@
     }
 };
 
+class ScryptBlockHeader : BlockHeader
+{
+    uint256 GetPoWHash() const;
+};
+
 
 /* below depends on BITCOIN_COMPAT magic */
 
-class CBlock : public BlockHeader
+class Block : public BlockHeader
 {
 public:
     // network and disk
@@ -102,12 +110,12 @@
     // memory only
     mutable bool fChecked;
 
-    CBlock()
+    Block()
     {
         SetNull();
     }
 
-    CBlock(const BlockHeader &header)
+    Block(const BlockHeader &header)
     {
         SetNull();
         *((BlockHeader*)this) = header;
@@ -117,7 +125,7 @@
 
     template <typename Stream, typename Operation>
     inline void SerializationOp(Stream& s, Operation ser_action) {
-        READWRITE(*(CBlockHeader*)this);
+        READWRITE(*(BlockHeader*)this);
         READWRITE(vtx);
 #if defined(BRAND_grantcoin)
 	READWRITE(BlockSig);
@@ -136,9 +144,9 @@
 
     /* There is probably some C++ way to handle this with templates better,
      * rather than depending on a #define of CBlockHeader. Fix later */
-    CBlockHeader GetBlockHeader() const
+    BlockHeader GetBlockHeader() const
     {
-        CBlockHeader block;
+        BlockHeader block;
         block.nVersion       = nVersion;
         block.hashPrevBlock  = hashPrevBlock;
         block.hashMerkleRoot = hashMerkleRoot;
--- a/src/primitives/transaction.cpp	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/primitives/transaction.cpp	Thu Feb 01 22:51:37 2018 -0600
@@ -62,17 +62,20 @@
 MutableTransaction::MutableTransaction() : nVersion(Transaction::CURRENT_VERSION), nLockTime(0) {}
 MutableTransaction::MutableTransaction(const Transaction& tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) {}
 
+MutableSegwitTx::MutableSegwitTx() : MutableTransaction() {}
+MutableSegwitTx::MutableSegwitTx(const SegwitTx& tx) : MutableTransaction(tx) {}
+
 uint256 MutableTransaction::GetHash() const
 {
     return SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS);
 }
 
-uint256 CTransaction::ComputeHash() const
+uint256 Transaction::ComputeHash() const
 {
     return SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS);
 }
 
-uint256 Transaction::GetWitnessHash() const
+uint256 SegwitTx::GetWitnessHash() const
 {
     if (!HasWitness()) {
         return GetHash();
@@ -81,87 +84,56 @@
 }
 
 /* For backward compatibility, the hash is initialized to 0. TODO: remove the need for this default constructor entirely. */
-Transaction::Transaction() : nVersion(Transaction::CURRENT_VERSION), vin(), vout(), nLockTime(0), hash() {}
-Transaction::Transaction(const MutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), hash(ComputeHash()) {}
-Transaction::Transaction(MutableTransaction &&tx) : nVersion(tx.nVersion), vin(std::move(tx.vin)), vout(std::move(tx.vout)), nLockTime(tx.nLockTime), hash(ComputeHash()) {}
+/* TODO: init the hash when we actually ask for it */
+/* TODO: make templates of this boilerplate */
+Transaction::Transaction()
+	: vin(), vout(), nLockTime(0),
+	nVersion(Transaction::CURRENT_VERSION), hash() {}
+Transaction::Transaction(const MutableTransaction &tx, bool inithash) 
+	: vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime),
+	nVersion(tx.nVersion) {
+	if (inithash){ 
+#warning "this is probably evil and undefined"
+		uint256 *phash = const_cast <uint256*> (&hash);
+		*phash = ComputeHash();
+	}
+}
+Transaction::Transaction(MutableTransaction &&tx, bool inithash) 
+	: vin(std::move(tx.vin)), vout(std::move(tx.vout)), nLockTime(tx.nLockTime), 
+	nVersion(tx.nVersion) {
+	if (inithash) {
+		uint256 *phash = const_cast <uint256*> (&hash);
+		*phash = ComputeHash();
+	}
+}
+
+/* Segwit transactions keep the same hash as legacy??? */
+/* Revisit this: can we do interesting things with object models here */
+SegwitTx::SegwitTx() : Transaction() {}
+SegwitTx::SegwitTx(const MutableSegwitTx &tx) : Transaction(tx, true) {}
+SegwitTx::SegwitTx(MutableSegwitTx &&tx) : Transaction(tx, true) {}
 
 #if defined(BRAND_grantcoin)
-TransactionGRT::TransactionGRT() : Transaction(), nTime(0) {}
+StakeTx::StakeTx() : Transaction(), Time(0) {}
 
-TransactionGRT::TransactionGRT(const MutableTransactionGRT &tx) : 
-	Transaction((MutableTransaction)tx, /* Update = */ false), nTime(tx.nTime) {
-    UpdateHash();
+StakeTx::StakeTx(const MutableStakeTx &tx)
+	: Transaction(tx, false), Time(tx.Time){
+	uint256 *phash = const_cast <uint256*> (&hash);
+	*phash = ComputeHash();
+	//assert (hash == tx.hash);  /* extra sanity check, TODO remove later? */
 }
-
-MutableTransactionGRT::MutableTransactionGRT() : MutableTransaction(), nTime(0) {}
-MutableTransactionGRT::MutableTransactionGRT(const TransactionGRT& tx) : 
-		MutableTransaction((MutableTransaction)tx), nTime(tx.nTime) {}
-
-/* Same as Transaction::UpdateHash() above, but different types.
- * This seems like a good job for a template */
-void TransactionGRT::UpdateHash() const
-{
-    *const_cast<uint256*>(&hash) = SerializeHash(*this);
+StakeTx::StakeTx(MutableStakeTx &&tx)
+	: Transaction(tx, false), Time(tx.Time){
+	uint256 *phash = const_cast <uint256*> (&hash);
+	*phash = ComputeHash();
+	//assert (hash == tx.hash);  /* extra sanity check, TODO remove later? */
 }
 
 /* PPCoin/Grantcoin destroy the 0.01 COIN per kb fee to reduce money supply,
  * which does not quite line up with Bitcoin, so replicate the PPCoin code here */
 /* FIXME: nBytes is currently not used */
-int64_t TransactionGRT::GetMinFee(unsigned int nBlockSize, bool fAllowFree,
-				enum GetMinFee_mode mode, unsigned int optnBytes) const
-{
-    // Base fee is either nMinTxFee or nMinRelayTxFee
-    int64_t nBaseFee = (mode == GMF_RELAY) ? nMinRelayTxFee : nMinTxFee;
+/* FIXME: figure if this is needed here or not */
 
-// here be dragons. put on fireproof regression tests before taunting this code
-#if defined(BRAND_cleanwatercoin)
-    unsigned int nBytes = optnBytes;
-#elif defined(BRAND_kittycoin)
-    unsigned int nBytes = ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION);
-#else
-#warning "hack for coincontroldialog.cpp that needs nBytes"
-    unsigned int nBytes = std::max(optnBytes,
-                ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION));
-#endif
-    unsigned int nNewBlockSize = nBlockSize + nBytes;
-    int64_t nMinFee = (1 + (int64_t)nBytes / 1000) * nBaseFee;
-
-#if defined(FEATURE_ALLOW_FREE_TX) /* likely safe to deprecate this */
-    if (fAllowFree)
-    {
-        // There is a free transaction area in blocks created by most miners,
-        // * If we are relaying we allow transactions up to DEFAULT_BLOCK_PRIORITY_SIZE - 1000
-        //   to be considered to fall into this category. We don't want to encourage sending
-        //   multiple transactions instead of one big transaction to avoid fees.
-        // * If we are creating a transaction we allow transactions up to 1,000 bytes
-        //   to be considered safe and assume they can likely make it into this section.
-        if (nBytes < (mode == GMF_SEND ? 1000 : (DEFAULT_BLOCK_PRIORITY_SIZE - 1000)))
-            nMinFee = 0;
-    }
-#endif
-
-    // This code can be removed after enough miners have upgraded to version 0.9.
-    // Until then, be safe when sending and require a fee if any output
-    // is less than CENT:
-    if (nMinFee < nBaseFee && mode == GMF_SEND)
-    {
-        for (const CTxOut& txout: vout)
-            if (txout.nValue < CENT)
-                nMinFee = nBaseFee;
-    }
-
-    // Raise the price as the block approaches full
-    if (nBlockSize != 1 && nNewBlockSize >= MAX_BLOCK_SIZE_GEN/2)
-    {
-        if (nNewBlockSize >= MAX_BLOCK_SIZE_GEN)
-            return MAX_MONEY;
-        nMinFee *= MAX_BLOCK_SIZE_GEN / (MAX_BLOCK_SIZE_GEN - nNewBlockSize);
-    }
-
-    if (!MoneyRange(nMinFee))
-        nMinFee = MAX_MONEY;
-    return nMinFee;
-}
 #endif /* BRAND_grantcoin */
 
 CAmount Transaction::GetValueOut() const
@@ -175,7 +147,7 @@
     return nValueOut;
 }
 
-unsigned int CTransaction::GetTotalSize() const
+unsigned int Transaction::GetTotalSize() const
 {
     return ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION);
 }
--- a/src/primitives/transaction.h	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/primitives/transaction.h	Thu Feb 01 22:51:37 2018 -0600
@@ -11,6 +11,7 @@
 #ifndef CODECOIN_PRIMITIVES_TRANSACTION_H
 #define CODECOIN_PRIMITIVES_TRANSACTION_H
 
+#include <codecoin.h>
 #include <stdint.h>
 #include <amount.h>
 #include <script/script.h>
@@ -184,7 +185,6 @@
  * to eliminate duplicate code
  */
 
-class MutableTransaction;
 
 /**
  * Basic transaction serialization format:
@@ -192,8 +192,57 @@
  * - std::vector<CTxIn> vin
  * - std::vector<CTxOut> vout
  * - uint32_t nLockTime
- *
- * Extended transaction serialization format:
+ */
+
+template <typename Stream, typename TxType>
+inline void UnserializeTransaction(TxType &tx, Stream &s) {
+    s >> tx.nVersion;
+    tx.vin.clear();
+    tx.vout.clear();
+    s >> tx.vin;
+    s >> tx.vout;
+    s >> tx.nLockTime;
+}
+
+template <typename Stream, typename TxType>
+inline void SerializeTransaction(const TxType &tx, Stream &s) {
+    s << tx.nVersion;
+    s << tx.vin;
+    s << tx.vout;
+    s << tx.nLockTime;
+}
+
+/**
+ * Stake transaction serialization format:
+ * - int32_t nVersion
+ * - uint32_t nTime
+ * - std::vector<CTxIn> vin
+ * - std::vector<CTxOut> vout
+ * - uint32_t nLockTime
+ */
+
+template <typename Stream, typename TxType>
+inline void UnserializeStakeTx(TxType &tx, Stream &s) {
+    s >> tx.nVersion;
+    s >> tx.Time;
+    tx.vin.clear();
+    tx.vout.clear();
+    s >> tx.vin;
+    s >> tx.vout;
+    s >> tx.nLockTime;
+}
+
+template <typename Stream, typename TxType>
+inline void SerializeStakeTx(const TxType &tx, Stream &s) {
+    s << tx.nVersion;
+    s << tx.Time;
+    s << tx.vin;
+    s << tx.vout;
+    s << tx.nLockTime;
+}
+
+/**
+ * Extended transaction serialization format (class SegwitTx):
  * - int32_t nVersion
  * - unsigned char dummy = 0x00
  * - unsigned char flags (!= 0)
@@ -203,8 +252,9 @@
  *   - CTxWitness wit;
  * - uint32_t nLockTime
  */
+
 template<typename Stream, typename TxType>
-inline void UnserializeTransaction(TxType& tx, Stream& s) {
+inline void UnserializeSegwitTx(TxType& tx, Stream& s) {
     const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);
 
     s >> tx.nVersion;
@@ -239,7 +289,7 @@
 }
 
 template<typename Stream, typename TxType>
-inline void SerializeTransaction(const TxType& tx, Stream& s) {
+inline void SerializeSegwitTx(const TxType& tx, Stream& s) {
     const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);
 
     s << tx.nVersion;
@@ -267,6 +317,7 @@
     s << tx.nLockTime;
 }
 
+class MutableTransaction;
 
 /** The basic transaction that is broadcasted on the network and contained in
  * blocks.  A transaction can contain multiple inputs and outputs.
@@ -288,19 +339,16 @@
     // actually immutable; deserialization and assignment are implemented,
     // and bypass the constness. This is safe, as they update the entire
     // structure, including the hash.
-    // Catoshi sez: There needs to be a darn good reason why these might
-    // not be in the same order here as they are in the wire protocol.
-    // Claims of size reduction without confirmation on multiple architectures (as in
-    // https://github.com/bitcoin/bitcoin/commit/59e17899a762c08ce9a9edd7f464e884edbe8654
-    // are not particularly usefull
-    const int32_t nVersion;
     const std::vector<TxIn> vin;
     const std::vector<TxOut> vout;
     const uint32_t nLockTime;
+    const int32_t nVersion;
 
-private:
+/* TODO figure this out later */
+protected:
     /** Memory only. */
     const uint256 hash;
+    //uint256 hash;
 
     uint256 ComputeHash() const;
 
@@ -309,8 +357,8 @@
     Transaction();
 
     /** Convert a CMutableTransaction into a CTransaction. */
-    Transaction(const MutableTransaction &tx);
-    Transaction(MutableTransaction &&tx);
+    Transaction(const MutableTransaction &tx, bool inithash = true);
+    Transaction(MutableTransaction &&tx, bool inithash = true);
 
     template <typename Stream>
     inline void Serialize(Stream& s) const {
@@ -320,7 +368,7 @@
     /** This deserializing constructor is provided instead of an Unserialize method.
      *  Unserialize is not possible, since it would require overwriting const fields. */
     template <typename Stream>
-    Transaction(deserialize_type, Stream& s) : Transaction(CMutableTransaction(deserialize, s)) {}
+    Transaction(deserialize_type, Stream& s) : Transaction(MutableTransaction(deserialize, s)) {}
 
     bool IsNull() const {
         return vin.empty() && vout.empty();
@@ -330,8 +378,6 @@
         return hash;
     }
 
-    // Compute a hash that includes both transaction and witness data
-    uint256 GetWitnessHash() const;
 
     // Return sum of txouts.
     CAmount GetValueOut() const;
@@ -368,8 +414,33 @@
 
     std::string ToString() const;
 
+};
+
+class MutableSegwitTx;
+
+class SegwitTx : public Transaction {
+public:
+    SegwitTx();
+
+    SegwitTx(const MutableSegwitTx &tx);
+    SegwitTx(MutableSegwitTx &&tx);
+    
+    template <typename Stream>
+    inline void Serialize(Stream& s) const {
+        SerializeSegwitTx(*this, s);
+    }
+
+    /** This deserializing constructor is provided instead of an Unserialize method.
+     *  Unserialize is not possible, since it would require overwriting const fields. */
+    template <typename Stream>
+    SegwitTx(deserialize_type, Stream& s) : SegwitTx(MutableSegwitTx(deserialize, s)) {}
+
+    // Compute a hash that includes both transaction and witness data
+    uint256 GetWitnessHash() const;
+
     bool HasWitness() const
     {
+	// TODO: for (TxIn &in : vin ){ 
         for (size_t i = 0; i < vin.size(); i++) {
             if (!vin[i].scriptWitness.IsNull()) {
                 return true;
@@ -380,54 +451,31 @@
 };
 
 #if defined(BRAND_grantcoin) /* FIXME update this later */
-class MutableTransactionGRT;
+class MutableStakeTx;
 
-class TransactionGRT : public Transaction
+class StakeTx : public Transaction
 {
-private:
-	void UpdateHash() const;
-	
-	enum GetMinFee_mode
-	{
-		GMF_BLOCK,
-		GMF_RELAY,
-		GMF_SEND,
-	};
-
 public:
-/** TODO: this goes into src/policy/fees.cpp when latest bitcoin code is merged */
-/** Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) */
-	const static int64_t nMinTxFee = CENT;
-/** Fees smaller than this (in satoshi) are considered zero fee (for relaying) */
-	const static int64_t nMinRelayTxFee = CENT;
-
-    uint32_t nTime; // FIXME just make this 'Time'  
+    const uint32_t Time; // FIXME just make this 'Time'  
 
     /** Construct a CTransaction that qualifies as IsNull() */
-    TransactionGRT();
+    StakeTx();
 
     /** Convert a CMutableTransaction into a CTransaction. */
-    TransactionGRT(const MutableTransactionGRT &tx);
+    StakeTx(const MutableStakeTx &tx);
+    StakeTx(MutableStakeTx &&tx);
 
-    /* must be replicated or serialization is pulled from base object */
-    ADD_SERIALIZE_METHODS;
-
-    template <typename Stream, typename Operation>
-    inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
-        READWRITE(*const_cast<int32_t*>(&this->nVersion));
-        nVersion = this->nVersion;
-        READWRITE(*const_cast<uint32_t*>(&this->nTime));
-        READWRITE(*const_cast<std::vector<TxIn>*>(&vin));
-        READWRITE(*const_cast<std::vector<TxOut>*>(&vout));
-        READWRITE(*const_cast<uint32_t*>(&nLockTime));
-        if (ser_action.ForRead())
-            UpdateHash();
+    template <typename Stream>
+    inline void Serialize(Stream& s) const {
+        SerializeStakeTx(*this, s);
     }
 
-	// Apply the effects of this transaction on the UTXO set represented by view
-	//void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight, const uint256 &txhash);
+    /** This deserializing constructor is provided instead of an Unserialize method.
+     *  Unserialize is not possible, since it would require overwriting const fields. */
+    template <typename Stream>
+    StakeTx(deserialize_type, Stream& s) : StakeTx(MutableStakeTx(deserialize, s)) {}
 
-	int64_t GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=false, enum GetMinFee_mode mode=GMF_BLOCK, unsigned int nBytes=0) const;
+    uint256 ComputeHash() const;
 
     /* What stake (ppcoin derivatives, + grantcoin do */
     bool IsCoinBase() const
@@ -435,7 +483,17 @@
         return (vin.size() == 1 && vin[0].prevout.IsNull() && vout.size() >= 1);
     }
 
+    /* ugly compat for witness code. */
+    bool HasWitness() const
+    {
+        return false;
+    }
 
+    /* ugly compat for witness code. */
+    const uint256 GetWitnessHash() const
+    {
+	return GetHash();
+    }
 };
 #endif /* BRAND_grantcoin */
 
@@ -445,9 +503,6 @@
 {
 public:
     int32_t nVersion;
-#if 0 && defined(PPCOINSTAKE) || defined(BRAND_grantcoin)
-    uint32_t nTime;
-#endif
     std::vector<TxIn> vin;
     std::vector<TxOut> vout;
     uint32_t nLockTime;
@@ -476,13 +531,42 @@
      */
     uint256 GetHash() const;
 
-    friend bool operator==(const MutableTransaction& a, const CMutableTransaction& b)
+    friend bool operator==(const MutableTransaction& a, const MutableTransaction& b)
     {
         return a.GetHash() == b.GetHash();
     }
 
     bool HasWitness() const
     {
+        return false;
+    }
+};
+
+class MutableSegwitTx : public MutableTransaction
+{
+public:
+    MutableSegwitTx();
+    MutableSegwitTx(const Transaction& tx);
+    MutableSegwitTx(const SegwitTx& tx);
+
+    template <typename Stream>
+    inline void Serialize(Stream& s) const {
+        SerializeSegwitTx(*this, s);
+    }
+
+
+    template <typename Stream>
+    inline void Unserialize(Stream& s) {
+        UnserializeSegwitTx(*this, s);
+    }
+
+    template <typename Stream>
+    MutableSegwitTx(deserialize_type, Stream& s) {
+        Unserialize(s);
+    }
+
+    bool HasWitness() const
+    {
         for (size_t i = 0; i < vin.size(); i++) {
             if (!vin[i].scriptWitness.IsNull()) {
                 return true;
@@ -492,26 +576,31 @@
     }
 };
 
+
 #if defined(BRAND_grantcoin) // FIXME later
-class MutableTransactionGRT: public MutableTransaction
+class MutableStakeTx: public MutableTransaction
 {
 public:
-	uint32_t nTime; // FIXME: evaluate if this should be signed or unsigned
+    uint32_t Time; // FIXME: evaluate if this should be signed or unsigned
 
-	MutableTransactionGRT();
-	MutableTransactionGRT(const TransactionGRT& tx);
+    MutableStakeTx();
+    MutableStakeTx(const StakeTx& tx);
 
-	template <typename Stream, typename Operation>
-	inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
-		READWRITE(this->nVersion);
-		nVersion = this->nVersion;
-		READWRITE(nTime);
-		READWRITE(vin);
-		READWRITE(vout);
-		READWRITE(nLockTime);
-	}
+    template <typename Stream>
+    inline void Serialize(Stream& s) const {
+        SerializeStakeTx(*this, s);
+    }
 
-	uint256 GetHash() const;
+    template <typename Stream>
+    inline void Unserialize(Stream& s) {
+        UnserializeStakeTx(*this, s);
+    }
+
+    template <typename Stream>
+    MutableStakeTx(deserialize_type, Stream& s) {
+        Unserialize(s);
+    }
+
 };
 #endif
 
--- a/src/test/prevector_tests.cpp	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/test/prevector_tests.cpp	Thu Feb 01 22:51:37 2018 -0600
@@ -13,7 +13,7 @@
 
 #include <boost/test/unit_test.hpp>
 
-BOOST_FIXTURE_TEST_SUITE(PrevectorTests, TestingSetup)
+BOOST_FIXTURE_TEST_SUITE(prevector_tests, TestingSetup)
 
 template<unsigned int N, typename T>
 class prevector_tester {
--- a/src/test/txvalidationcache_tests.cpp	Sun Jan 28 22:05:15 2018 -0600
+++ b/src/test/txvalidationcache_tests.cpp	Thu Feb 01 22:51:37 2018 -0600
@@ -21,7 +21,7 @@
 
 bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks);
 
-BOOST_AUTO_TEST_SUITE(tx_validationcache_tests)
+BOOST_AUTO_TEST_SUITE(txvalidationcache_tests)
 
 static bool
 ToMemPool(CMutableTransaction& tx)