Skip to content

Commit

Permalink
Talkcoin - Restructure changes
Browse files Browse the repository at this point in the history
Move hard fork variables to util.cpp where they will be made readily
accessible to the rest of the code. Change the developer address
functions in base58.h to always get a height argument and change all
calls to provide that argument. Make building of static binaries default
on Windows.
  • Loading branch information
Talkcoin-Team committed Aug 30, 2014
1 parent e12f13e commit 47a1d24
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 183 deletions.
42 changes: 18 additions & 24 deletions src/base58.h
Expand Up @@ -23,88 +23,82 @@
#include "key.h"
#include "script.h"
#include "allocators.h"
#include "main.h"

static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

std::string GET_A_GENESIS() {
int height = GetBlockHeight();
inline std::string GET_A_GENESIS(int nHeight) {
if (fTestNet) {
if (height < nTestnetFork) {
if (nHeight < nTestnetFork) {
return "dG9haDhyNHZzWWtKWldiUUVhckx0U3VLNjFlakR0dXZ2bQ==";
} else {
return "";
}
} else {
if (height < nHardFork) {
if (nHeight < nHardFork) {
return "VHBtZnVHcmp2Z240M0dvUjhNUlYzVUtmUEVaQnJzQlZHTg==";
} else {
return "VG9aTHc5REdHdzJlNlVTYXpYUU5ZMjVZcGRpVUR3TU5wTQ==";
}
}
}

std::string GET_A_VOTE1(int nHeight=HF1) {
int height = GetBlockHeight();
inline std::string GET_A_VOTE1(int nHeight) {
if (fTestNet) {
if (height < nTestnetFork) {
if (nHeight < nTestnetFork) {
return "dG9haDhyNHZzWWtKWldiUUVhckx0U3VLNjFlakR0dXZ2bQ==";
} else {
return "";
}
} else {
if (height < nHardFork) {
return (nHeight<HF1)? "VHRENDZ6WmgxVEtqM0JaZHhLa0tzcmMyUHE3TDlqTUFxdw==" : GET_A_GENESIS();
if (nHeight < nHardFork) {
return (nHeight<HF1)? "VHRENDZ6WmgxVEtqM0JaZHhLa0tzcmMyUHE3TDlqTUFxdw==" : GET_A_GENESIS(nHeight);
} else {
return "";
}
}
}

std::string GET_A_VOTE2(int nHeight=HF1) {
int height = GetBlockHeight();
inline std::string GET_A_VOTE2(int nHeight) {
if (fTestNet) {
if (height < nTestnetFork) {
if (nHeight < nTestnetFork) {
return "dG9haDhyNHZzWWtKWldiUUVhckx0U3VLNjFlakR0dXZ2bQ==";
} else {
return "";
}
} else {
if (height < nHardFork) {
return (nHeight<HF1)? "VFpaR1I4NTk3QWV6VG1hVXNLMW1QS0dqYzRWbkZIaUJDcg==" : GET_A_GENESIS();
if (nHeight < nHardFork) {
return (nHeight<HF1)? "VFpaR1I4NTk3QWV6VG1hVXNLMW1QS0dqYzRWbkZIaUJDcg==" : GET_A_GENESIS(nHeight);
} else {
return "";
}
}
}

std::string GET_A_CHAT(int nHeight=HF1) {
int height = GetBlockHeight();
inline std::string GET_A_CHAT(int nHeight) {
if (fTestNet) {
if (height < nTestnetFork) {
if (nHeight < nTestnetFork) {
return "dG9haDhyNHZzWWtKWldiUUVhckx0U3VLNjFlakR0dXZ2bQ==";
} else {
return "dGc3WE1FVHlaaUZQYkpRZngxYkdkVlJ6S3JacGtMdlFRdQ==";
}
} else {
if (height < nHardFork) {
return (nHeight<HF1)? "VFpaR1I4NTk3QWV6VG1hVXNLMW1QS0dqYzRWbkZIaUJDcg==" : GET_A_GENESIS();
if (nHeight < nHardFork) {
return (nHeight<HF1)? "VFpaR1I4NTk3QWV6VG1hVXNLMW1QS0dqYzRWbkZIaUJDcg==" : GET_A_GENESIS(nHeight);
} else {
return "VHdkellCTnhDSHpXd1NpdURiN1RnTWpReE1MYkdlVnN3TQ==";
}
}
}

std::string GET_A_SHARE() {
int height = GetBlockHeight();
inline std::string GET_A_SHARE(int nHeight) {
if (fTestNet) {
if (height < nTestnetFork) {
if (nHeight < nTestnetFork) {
return "dG9haDhyNHZzWWtKWldiUUVhckx0U3VLNjFlakR0dXZ2bQ==";
} else {
return "dGc3WE1FVHlaaUZQYkpRZngxYkdkVlJ6S3JacGtMdlFRdQ==";
}
} else {
if (height < nHardFork) {
if (nHeight < nHardFork) {
return "VGdEN0VScmdnQlBleng2SlBQMmJwV2pBRlFXMXJhZnpDbg==";
} else {
return "VG9aTHc5REdHdzJlNlVTYXpYUU5ZMjVZcGRpVUR3TU5wTQ==";
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Expand Up @@ -1843,7 +1843,7 @@ bool CBlock::ConnectBlock(CValidationState &state, CBlockIndex* pindex, CCoinsVi

const CTxOut& txout = vtx[0].vout[1];
CTxDestination address;
if (!(ExtractDestination(txout.scriptPubKey, address) && CTalkcoinAddress(address).ToBase64() == GET_A_SHARE() && txout.nValue == _V2))
if (!(ExtractDestination(txout.scriptPubKey, address) && CTalkcoinAddress(address).ToBase64() == GET_A_SHARE(pindex->nHeight) && txout.nValue == _V2))
return state.DoS(100, error("ConnectBlock() : Share to beneficiary is insufficient"));

if (!control.Wait())
Expand Down Expand Up @@ -4506,7 +4506,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
txNew.vin[0].prevout.SetNull();
txNew.vout.resize(2);
txNew.vout[0].scriptPubKey = scriptPubKeyIn;
txNew.vout[1].scriptPubKey << OP_DUP << OP_HASH160 << GetHash160(GET_A_SHARE()) << OP_EQUALVERIFY << OP_CHECKSIG;
txNew.vout[1].scriptPubKey << OP_DUP << OP_HASH160 << GetHash160(GET_A_SHARE(pindexBest->nHeight + 1)) << OP_EQUALVERIFY << OP_CHECKSIG;

// Add our coinbase tx as first transaction
pblock->vtx.push_back(txNew);
Expand Down
12 changes: 1 addition & 11 deletions src/main.h
Expand Up @@ -72,15 +72,6 @@ static const int fHaveUPnP = false;
inline int64 rndVal(int64 nValue) { return (nValue/CENT)*CENT; }
inline int64 pVal(int64 nValue, int64 p) { return nValue * (((double)p/COIN)/100.0); }

// Hard fork one
static const int HF1 = 241920;

// Temp fork dates to be decided later
static const int nHardFork = 541110; // Approx: Thu, 25 Sep 2014 17:00:00 GMT
static const int nTestnetFork = 600;
static const unsigned int nSwitchV2 = 1411948800; // Mon, 29 Sep 2014 00:00:00 GMT
static const unsigned int nTestnetSwitchV2 = 1409270400; // Fri, 29 Aug 2014 00:00:00 GMT

extern CScript COINBASE_FLAGS;


Expand Down Expand Up @@ -213,8 +204,7 @@ CBlockIndex * InsertBlockIndex(uint256 hash);
bool VerifySignature(const CCoins& txFrom, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType);
/** Abort with a message */
bool AbortNode(const std::string &msg);
/** Return current block height **/
int GetBlockHeight();




Expand Down
139 changes: 0 additions & 139 deletions src/makefile.linux-mingw

This file was deleted.

8 changes: 4 additions & 4 deletions src/makefile.mingw
Expand Up @@ -17,16 +17,16 @@

CXX ?= g++

USE_UPNP:=-
USE_UPNP:=1
USE_IPV6:=1

DEPSDIR?=/usr/local
BOOST_SUFFIX?=-mgw46-mt-sd-1_55
BOOST_SUFFIX?=-mgw48-mt-s-1_55

INCLUDEPATHS= \
-I"$(CURDIR)" \
-I"$(DEPSDIR)/include"

LIBPATHS= \
-L"$(CURDIR)/leveldb" \
-L"$(CURDIR)/cryptopp" \
Expand All @@ -49,7 +49,7 @@ DEFS=-D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -DBOOST_SPIRIT_THREADSAFE
DEBUGFLAGS=-g
CFLAGS=-mthreads -O2 -w -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
# enable: ASLR, DEP and large address aware
LDFLAGS=-Wl,--dynamicbase -Wl,--nxcompat -Wl,--large-address-aware
LDFLAGS=-Wl,--dynamicbase -Wl,--nxcompat -Wl,--large-address-aware -static

TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)

Expand Down
5 changes: 3 additions & 2 deletions src/txdb.cpp
Expand Up @@ -163,7 +163,8 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats, bool fMoney) {
}
}
delete pcursor;
stats.nHeight = GetBestBlock()->nHeight;
int nHeight = GetBestBlock()->nHeight;
stats.nHeight = nHeight;
stats.hashSerialized = ss.GetHash();
stats.nTotalAmount = nTotalAmount;

Expand All @@ -183,7 +184,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats, bool fMoney) {
{
const CTxOut& txout = tx.vout[i];
CTxDestination address;
if (ExtractDestination(txout.scriptPubKey, address) && CTalkcoinAddress(address).ToBase64() == GET_A_GENESIS())
if (ExtractDestination(txout.scriptPubKey, address) && CTalkcoinAddress(address).ToBase64() == GET_A_GENESIS(nHeight))
nTotalAmountDestroyed += txout.nValue;
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/util.cpp
Expand Up @@ -90,6 +90,15 @@ CMedianFilter<int64> vTimeOffsets(200,0);
volatile bool fReopenDebugLog = false;
bool fCachedPath[2] = {false, false};

// Hard fork 1
const int HF1 = 241920;

// Temp fork dates to be decided later
const int nHardFork = 541110; // Approx: Thu, 25 Sep 2014 17:00:00 GMT
const int nTestnetFork = 600;
const unsigned int nSwitchV2 = 1411948800; // Mon, 29 Sep 2014 00:00:00 GMT
const unsigned int nTestnetSwitchV2 = 1409270400; // Fri, 29 Aug 2014 00:00:00 GMT

// Init OpenSSL library multithreading support
static CCriticalSection** ppmutexOpenSSL;
void locking_callback(int mode, int i, const char* file, int line)
Expand Down
5 changes: 5 additions & 0 deletions src/util.h
Expand Up @@ -150,6 +150,11 @@ extern bool fBloomFilters;
extern bool fNoListen;
extern bool fLogTimestamps;
extern volatile bool fReopenDebugLog;
extern const int HF1;
extern const int nHardFork;
extern const int nTestnetFork;
extern const unsigned int nSwitchV2;
extern const unsigned int nTestnetSwitchV2;

void RandAddSeed();
void RandAddSeedPerfmon();
Expand Down
3 changes: 2 additions & 1 deletion talkcoin-qt.pro
Expand Up @@ -8,6 +8,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE
CONFIG += no_include_pwd
CONFIG += thread
CONFIG += static

# for boost 1.37, add -mt to the boost libraries
# use: qmake BOOST_LIB_SUFFIX=-mt
Expand Down Expand Up @@ -48,7 +49,7 @@ QMAKE_CXXFLAGS *= -D_FORTIFY_SOURCE=2
# for extra security on Windows: enable ASLR and DEP via GCC linker flags
win32:QMAKE_LFLAGS *= -Wl,--dynamicbase -Wl,--nxcompat
# on Windows: enable GCC large address aware linker flag
win32:QMAKE_LFLAGS *= -Wl,--large-address-aware
win32:QMAKE_LFLAGS *= -Wl,--large-address-aware -static
# i686-w64-mingw32
#win32:QMAKE_LFLAGS *= -static-libgcc -static-libstdc++

Expand Down

0 comments on commit 47a1d24

Please sign in to comment.