Skip to content

Commit

Permalink
Merge branch 'merge_upstream' into dev-0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Terracoin committed Dec 20, 2012
2 parents d7d43fb + 8122367 commit 33f0099
Show file tree
Hide file tree
Showing 42 changed files with 825 additions and 328 deletions.
2 changes: 1 addition & 1 deletion doc/build-osx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sudo port install qrencode
4. Now you should be able to build bitcoind:

cd bitcoin/src
make -f makefile.osx USE_IPV6=1
make -f makefile.osx

Run:
./bitcoind --help # for a list of command-line options.
Expand Down
4 changes: 2 additions & 2 deletions doc/build-unix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ turned off by default. Set USE_UPNP to a different value to control this:
USE_UPNP=0 (the default) UPnP support turned off by default at runtime
USE_UPNP=1 UPnP support turned on by default at runtime

IPv6 support may be enabled by setting:
USE_IPV6=1 Enable IPv6 support
IPv6 support may be disabled by setting:
USE_IPV6=0 Disable IPv6 support

Licenses of statically linked libraries:
Berkeley DB New BSD license with additional requirement that linked
Expand Down
14 changes: 13 additions & 1 deletion doc/readme-qt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@ Debian
-------

First, make sure that the required packages for Qt4 development of your
distribution are installed, for Debian and Ubuntu these are:
distribution are installed, these are

::

for Debian and Ubuntu <= 11.10 :

::

apt-get install qt4-qmake libqt4-dev build-essential libboost-dev libboost-system-dev \
libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev \
libssl-dev libdb4.8++-dev

for Ubuntu >= 12.04 (please read the 'Berkely DB version warning' below):

::

apt-get install qt4-qmake libqt4-dev build-essential libboost-dev libboost-system-dev \
libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev \
libssl-dev libdb++-dev libminiupnpc-dev

then execute the following:

::
Expand Down
72 changes: 57 additions & 15 deletions src/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ class CBigNum : public BIGNUM

if (sn < (int64)0)
{
// Since the minimum signed integer cannot be represented as positive so long as its type is signed, and it's not well-defined what happens if you make it unsigned before negating it, we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
// Since the minimum signed integer cannot be represented as positive so long as its type is signed,
// and it's not well-defined what happens if you make it unsigned before negating it,
// we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
n = -(sn + 1);
++n;
fNegative = true;
Expand Down Expand Up @@ -262,28 +264,68 @@ class CBigNum : public BIGNUM
return vch;
}

// The "compact" format is a representation of a whole
// number N using an unsigned 32bit number similar to a
// floating point format.
// The most significant 8 bits are the unsigned exponent of base 256.
// This exponent can be thought of as "number of bytes of N".
// The lower 23 bits are the mantissa.
// Bit number 24 (0x800000) represents the sign of N.
// N = (-1^sign) * mantissa * 256^(exponent-3)
//
// Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn().
// MPI uses the most significant bit of the first byte as sign.
// Thus 0x1234560000 is compact (0x05123456)
// and 0xc0de000000 is compact (0x0600c0de)
// (0x05c0de00) would be -0x40de000000
//
// Bitcoin only uses this "compact" format for encoding difficulty
// targets, which are unsigned 256bit quantities. Thus, all the
// complexities of the sign bit and using base 256 are probably an
// implementation accident.
//
// This implementation directly uses shifts instead of going
// through an intermediate MPI representation.
CBigNum& SetCompact(unsigned int nCompact)
{
unsigned int nSize = nCompact >> 24;
std::vector<unsigned char> vch(4 + nSize);
vch[3] = nSize;
if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff;
if (nSize >= 2) vch[5] = (nCompact >> 8) & 0xff;
if (nSize >= 3) vch[6] = (nCompact >> 0) & 0xff;
BN_mpi2bn(&vch[0], vch.size(), this);
bool fNegative =(nCompact & 0x00800000) != 0;
unsigned int nWord = nCompact & 0x007fffff;
if (nSize <= 3)
{
nWord >>= 8*(3-nSize);
BN_set_word(this, nWord);
}
else
{
BN_set_word(this, nWord);
BN_lshift(this, this, 8*(nSize-3));
}
BN_set_negative(this, fNegative);
return *this;
}

unsigned int GetCompact() const
{
unsigned int nSize = BN_bn2mpi(this, NULL);
std::vector<unsigned char> vch(nSize);
nSize -= 4;
BN_bn2mpi(this, &vch[0]);
unsigned int nCompact = nSize << 24;
if (nSize >= 1) nCompact |= (vch[4] << 16);
if (nSize >= 2) nCompact |= (vch[5] << 8);
if (nSize >= 3) nCompact |= (vch[6] << 0);
unsigned int nSize = BN_num_bytes(this);
unsigned int nCompact = 0;
if (nSize <= 3)
nCompact = BN_get_word(this) << 8*(3-nSize);
else
{
CBigNum bn;
BN_rshift(&bn, this, 8*(nSize-3));
nCompact = BN_get_word(&bn);
}
// The 0x00800000 bit denotes the sign.
// Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
if (nCompact & 0x00800000)
{
nCompact >>= 8;
nSize++;
}
nCompact |= nSize << 24;
nCompact |= (BN_is_negative(this) ? 0x00800000 : 0);
return nCompact;
}

Expand Down
8 changes: 6 additions & 2 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ static const CRPCCommand vRPCCommands[] =
{ "sendrawtransaction", &sendrawtransaction, false, false },
{ "gettxoutsetinfo", &gettxoutsetinfo, true, false },
{ "gettxout", &gettxout, true, false },
{ "lockunspent", &lockunspent, false, false },
{ "listlockunspent", &listlockunspent, false, false },
};

CRPCTable::CRPCTable()
Expand Down Expand Up @@ -769,7 +771,7 @@ void ThreadRPCServer2(void* parg)
strWhatAmI.c_str(),
GetConfigFile().string().c_str(),
EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()),
_("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL);
"", CClientUIInterface::MSG_ERROR);
StartShutdown();
return;
}
Expand Down Expand Up @@ -860,7 +862,7 @@ void ThreadRPCServer2(void* parg)
}

if (!fListening) {
uiInterface.ThreadSafeMessageBox(strerr, _("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL);
uiInterface.ThreadSafeMessageBox(strerr, "", CClientUIInterface::MSG_ERROR);
StartShutdown();
return;
}
Expand Down Expand Up @@ -1215,6 +1217,8 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "signrawtransaction" && n > 2) ConvertTo<Array>(params[2], true);
if (strMethod == "gettxout" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "gettxout" && n > 2) ConvertTo<bool>(params[2]);
if (strMethod == "lockunspent" && n > 0) ConvertTo<bool>(params[0]);
if (strMethod == "lockunspent" && n > 1) ConvertTo<Array>(params[1]);

return params;
}
Expand Down
2 changes: 2 additions & 0 deletions src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value lockunspent(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value listlockunspent(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value createrawtransaction(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value decoderawtransaction(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, bool fHelp);
Expand Down
9 changes: 9 additions & 0 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ namespace Checkpoints

bool CheckBlock(int nHeight, const uint256& hash)
{
if (!GetBoolArg("-checkpoints", true))
return true;

MapCheckpoints& checkpoints = (fTestNet ? mapCheckpointsTestnet : mapCheckpoints);

MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
Expand All @@ -76,13 +79,19 @@ namespace Checkpoints

int GetTotalBlocksEstimate()
{
if (!GetBoolArg("-checkpoints", true))
return 0;

MapCheckpoints& checkpoints = (fTestNet ? mapCheckpointsTestnet : mapCheckpoints);

return checkpoints.rbegin()->first;
}

CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
{
if (!GetBoolArg("-checkpoints", true))
return NULL;

MapCheckpoints& checkpoints = (fTestNet ? mapCheckpointsTestnet : mapCheckpoints);

BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
Expand Down
33 changes: 17 additions & 16 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "txdb.h"
#include "walletdb.h"
#include "bitcoinrpc.h"
#include "net.h"
#include "init.h"
#include "util.h"
#include "ui_interface.h"

#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/convenience.hpp>
Expand Down Expand Up @@ -209,17 +211,16 @@ int main(int argc, char* argv[])

bool static InitError(const std::string &str)
{
uiInterface.ThreadSafeMessageBox(str, _("Terracoin"), CClientUIInterface::OK | CClientUIInterface::MODAL);
uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR);
return false;
}

bool static InitWarning(const std::string &str)
{
uiInterface.ThreadSafeMessageBox(str, _("Terracoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL);
uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING);
return true;
}


bool static Bind(const CService &addr, unsigned int flags) {
if (!(flags & BF_EXPLICIT) && IsLimited(addr))
return false;
Expand Down Expand Up @@ -257,6 +258,7 @@ std::string HelpMessage()
" -onlynet=<net> " + _("Only connect to nodes in network <net> (IPv4, IPv6 or Tor)") + "\n" +
" -discover " + _("Discover own IP address (default: 1 when listening and no -externalip)") + "\n" +
" -irc " + _("Find peers using internet relay chat (default: 0)") + "\n" +
" -checkpoints " + _("Lock in block chain with compiled-in checkpoints (default: 1)") + "\n" +
" -listen " + _("Accept connections from outside (default: 1 if no -proxy or -connect)") + "\n" +
" -bind=<addr> " + _("Bind to given address and always listen on it. Use [host]:port notation for IPv6") + "\n" +
" -dnsseed " + _("Find peers using DNS lookup (default: 1 unless -connect)") + "\n" +
Expand Down Expand Up @@ -336,26 +338,24 @@ struct CImportData {
void ThreadImport(void *data) {
CImportData *import = reinterpret_cast<CImportData*>(data);

RenameThread("bitcoin-loadblk");
RenameThread("terracoin-loadblk");

vnThreadsRunning[THREAD_IMPORT]++;

// -reindex
if (fReindex) {
CImportingNow imp;
int nFile = 0;
while (!fShutdown) {
CDiskBlockPos pos;
pos.nFile = nFile;
pos.nPos = 0;
while (!fRequestShutdown) {
CDiskBlockPos pos(nFile, 0);
FILE *file = OpenBlockFile(pos, true);
if (!file)
break;
printf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile);
LoadExternalBlockFile(file, &pos);
nFile++;
}
if (!fShutdown) {
if (!fRequestShutdown) {
pblocktree->WriteReindexing(false);
fReindex = false;
printf("Reindexing finished\n");
Expand All @@ -364,7 +364,7 @@ void ThreadImport(void *data) {

// hardcoded $DATADIR/bootstrap.dat
filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat";
if (filesystem::exists(pathBootstrap) && !fShutdown) {
if (filesystem::exists(pathBootstrap) && !fRequestShutdown) {
FILE *file = fopen(pathBootstrap.string().c_str(), "rb");
if (file) {
CImportingNow imp;
Expand All @@ -377,7 +377,7 @@ void ThreadImport(void *data) {

// -loadblock=
BOOST_FOREACH(boost::filesystem::path &path, import->vFiles) {
if (fShutdown)
if (fRequestShutdown)
break;
FILE *file = fopen(path.string().c_str(), "rb");
if (file) {
Expand Down Expand Up @@ -482,6 +482,7 @@ bool AppInit2()
// ********************************************************* Step 3: parameter-to-internal-flags

fDebug = GetBoolArg("-debug");
fBenchmark = GetBoolArg("-benchmark");

// -debug implies fDebug*
if (fDebug)
Expand Down Expand Up @@ -570,7 +571,7 @@ bool AppInit2()
printf("Terracoin version %s (%s)\n", FormatFullVersion().c_str(), CLIENT_DATE.c_str());
printf("Using OpenSSL version %s\n", SSLeay_version(SSLEAY_VERSION));
if (!fLogTimestamps)
printf("Startup time: %s\n", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
printf("Startup time: %s\n", DateTimeStrFormat("%Y-%m-%dT%H:%M:%S", GetTime()).c_str());
printf("Default data directory %s\n", GetDefaultDataDir().string().c_str());
printf("Used data directory %s\n", strDataDir.c_str());
std::ostringstream strErrors;
Expand Down Expand Up @@ -608,7 +609,7 @@ bool AppInit2()
" Original wallet.dat saved as wallet.{timestamp}.bak in %s; if"
" your balance or transactions are incorrect you should"
" restore from a backup."), strDataDir.c_str());
uiInterface.ThreadSafeMessageBox(msg, _("Terracoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL);
InitWarning(msg);
}
if (r == CDBEnv::RECOVER_FAIL)
return InitError(_("wallet.dat corrupt, salvage failed"));
Expand Down Expand Up @@ -808,7 +809,7 @@ bool AppInit2()
{
string msg(_("Warning: error reading wallet.dat! All keys read correctly, but transaction data"
" or address book entries might be missing or incorrect."));
uiInterface.ThreadSafeMessageBox(msg, _("Terracoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL);
InitWarning(msg);
}
else if (nLoadWalletRet == DB_TOO_NEW)
strErrors << _("Error loading wallet.dat: Wallet requires newer version of Terracoin") << "\n";
Expand Down Expand Up @@ -866,7 +867,7 @@ bool AppInit2()
if (walletdb.ReadBestBlock(locator))
pindexRescan = locator.GetBlockIndex();
}
if (pindexBest != pindexRescan)
if (pindexBest && pindexBest != pindexRescan)
{
uiInterface.InitMessage(_("Rescanning..."));
printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
Expand Down Expand Up @@ -914,7 +915,7 @@ bool AppInit2()

//// debug print
printf("mapBlockIndex.size() = %"PRIszu"\n", mapBlockIndex.size());
printf("nBestHeight = %d\n", nBestHeight);
printf("nBestHeight = %d\n", nBestHeight);
printf("setKeyPool.size() = %"PRIszu"\n", pwalletMain->setKeyPool.size());
printf("mapWallet.size() = %"PRIszu"\n", pwalletMain->mapWallet.size());
printf("mapAddressBook.size() = %"PRIszu"\n", pwalletMain->mapAddressBook.size());
Expand Down
10 changes: 10 additions & 0 deletions src/leveldb/build_detect_platform
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ case "$TARGET_OS" in
PLATFORM_EXTRALIBS="-lboost_system-mt-s -lboost_filesystem-mt-s -lboost_thread_win32-mt-s"
CROSS_COMPILE=true
;;
NATIVE_WINDOWS)
PLATFORM=OS_WINDOWS
COMMON_FLAGS="-fno-builtin-memcmp -D_REENTRANT -DOS_WINDOWS -DLEVELDB_PLATFORM_WINDOWS -DBOOST_THREAD_USE_LIB"
PLATFORM_CXXFLAGS=""
PLATFORM_LDFLAGS=""
PLATFORM_SHARED_CFLAGS=""
PLATFORM_SOURCES="port/port_win.cc util/env_boost.cc util/win_logger.cc"
PLATFORM_EXTRALIBS="-lboost_system-mgw45-mt-s-1_50 -lboost_filesystem-mgw45-mt-s-1_50 -lboost_thread-mgw45-mt-s-1_50 -lboost_chrono-mgw45-mt-s-1_50"
CROSS_COMPILE=true
;;
*)
echo "Unknown platform!" >&2
exit 1
Expand Down
Loading

0 comments on commit 33f0099

Please sign in to comment.