Skip to content

Commit

Permalink
Merge pull request #1 from dexX7/omnicore-0.0.9.2-no-history
Browse files Browse the repository at this point in the history
Omnicore migration to bitcoin 0.10
  • Loading branch information
zathras-crypto committed Mar 24, 2015
2 parents 1d2cdd2 + 4ff7a4b commit d6a48bf
Show file tree
Hide file tree
Showing 30 changed files with 11,853 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,40 @@ JSON_H = \
json/json_spirit_writer.h \
json/json_spirit_writer_template.h

# Omni Core extensions
OMNICORE_H = \
mastercore.h \
mastercore_convert.h \
mastercore_dex.h \
mastercore_errors.h \
mastercore_parse_string.h \
mastercore_rpc.h \
mastercore_script.h \
mastercore_sp.h \
mastercore_tx.h \
mastercore_version.h

OMNICORE_CPP = \
mastercore.cpp \
mastercore_convert.cpp \
mastercore_dex.cpp \
mastercore_parse_string.cpp \
mastercore_rpc.cpp \
mastercore_script.cpp \
mastercore_sp.cpp \
mastercore_tx.cpp \
mastercore_version.cpp

BITCOIN_CORE_H += \
$(OMNICORE_H)
#

obj/build.h: FORCE
@$(MKDIR_P) $(builddir)/obj
@$(top_srcdir)/share/genbuild.sh $(abs_top_builddir)/src/obj/build.h \
$(abs_top_srcdir)
libbitcoin_util_a-clientversion.$(OBJEXT): obj/build.h
libbitcoin_common_a-mastercore_version.$(OBJEXT): obj/build.h # Omni Core

# server: shared between bitcoind and bitcoin-qt
libbitcoin_server_a_CPPFLAGS = $(BITCOIN_INCLUDES) $(MINIUPNPC_CPPFLAGS)
Expand Down Expand Up @@ -256,6 +285,10 @@ libbitcoin_common_a_SOURCES = \
script/script_error.cpp \
$(BITCOIN_CORE_H)

# Omni Core extensions
libbitcoin_common_a_SOURCES += \
$(OMNICORE_CPP)

# util: shared between all executables.
# This library *must* be included to make sure that the glibc
# backward-compatibility objects and their sanity checks are linked.
Expand Down
10 changes: 10 additions & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ BITCOIN_TESTS += \
test/rpc_wallet_tests.cpp
endif

# Omni Core extensions
OMNICORE_TESTS = \
test/mastercore_rounduint64_tests.cpp \
test/mastercore_strtoint64_tests.cpp \
test/mastercore_swapbyteorder_tests.cpp

BITCOIN_TESTS += \
$(OMNICORE_TESTS)
#

test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
test_test_bitcoin_CPPFLAGS = $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS)
test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \
Expand Down
34 changes: 34 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ enum BindFlags {
static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat";
CClientUIInterface uiInterface;

/** Omni Core initialization and shutdown handler */
int mastercore_init(void);
int mastercore_shutdown(void);

//////////////////////////////////////////////////////////////////////////////
//
// Shutdown
Expand Down Expand Up @@ -183,6 +187,10 @@ void Shutdown()
delete pblocktree;
pblocktree = NULL;
}

//! Omni Core shutdown
mastercore_shutdown();

#ifdef ENABLE_WALLET
if (pwalletMain)
bitdb.Flush(true);
Expand Down Expand Up @@ -1094,6 +1102,32 @@ bool AppInit2(boost::thread_group& threadGroup)
mempool.ReadFeeEstimates(est_filein);
fFeeEstimatesInitialized = true;

// ********************************************************* Step 7.5: load omni core

uiInterface.InitMessage(_("Performing out of order block detection..."));

if (fDisableWallet) {
return InitError(_(
"Disabled wallet detected.\n\n"
"Omni Core requires an enabled wallet. Please start your client "
"without the \"-disablewallet\" option to enable the wallet."
));
}

if (!fTxIndex) {
return InitError(_(
"Disabled transaction index detected.\n\n"
"Omni Core requires an enabled transaction index. To enable "
"transaction indexing, please use the \"-txindex\" option as "
"command line argument or add \"txindex=1\" to your client "
"configuration file."
));
}

uiInterface.InitMessage(_("Parsing Omni Layer transactions..."));

mastercore_init();

// ********************************************************* Step 8: load wallet
#ifdef ENABLE_WALLET
if (fDisableWallet) {
Expand Down
45 changes: 45 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ void SyncWithWallets(const CTransaction &tx, const CBlock *pblock) {
g_signals.SyncTransaction(tx, pblock);
}

//////////////////////////////////////////////////////////////////////////////
//
// Omni Core notification handlers
//

// TODO: replace handlers with signals
int mastercore_handler_disc_begin(int nBlockNow, CBlockIndex const * pBlockIndex);
int mastercore_handler_disc_end(int nBlockNow, CBlockIndex const * pBlockIndex);
int mastercore_handler_block_begin(int nBlockNow, CBlockIndex const * pBlockIndex);
int mastercore_handler_block_end(int nBlockNow, CBlockIndex const * pBlockIndex, unsigned int);
int mastercore_handler_tx(const CTransaction &tx, int nBlock, unsigned int idx, CBlockIndex const * pBlockIndex);

//////////////////////////////////////////////////////////////////////////////
//
// Registration of network node signals.
Expand Down Expand Up @@ -1951,11 +1963,25 @@ bool static DisconnectTip(CValidationState &state) {
mempool.check(pcoinsTip);
// Update chainActive and related variables.
UpdateTip(pindexDelete->pprev);

//! Omni Core: begin block disconnect notification
LogPrint("handler", "Omni Core handler: block disconnect begin [height: %d, reindex: %d]\n", GetHeight(), (int)fReindex);
if (!fReindex) {
mastercore_handler_disc_begin(GetHeight(), pindexDelete);
}

// Let wallets know transactions went from 1-confirmed to
// 0-confirmed or conflicted:
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
SyncWithWallets(tx, NULL);
}

//! Omni Core: end of block disconnect notification
LogPrint("handler", "Omni Core handler: block disconnect end [height: %d, reindex: %d]\n", GetHeight(), (int)fReindex);
if (!fReindex) {
mastercore_handler_disc_end(GetHeight(), pindexDelete);
}

return true;
}

Expand All @@ -1971,6 +1997,16 @@ static int64_t nTimePostConnect = 0;
*/
bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *pblock) {
assert(pindexNew->pprev == chainActive.Tip());

//! Omni Core: transaction position within the block
unsigned int nTxIdx = 0;
//! Omni Core: number of meta transactions found
unsigned int nNumMetaTxs = 0;

//! Omni Core: begin block connect notification
LogPrint("handler", "Omni Core handler: block connect begin [height: %d]\n", GetHeight());
mastercore_handler_block_begin(GetHeight(), pindexNew);

mempool.check(pcoinsTip);
// Read block from disk.
int64_t nTime1 = GetTimeMicros();
Expand Down Expand Up @@ -2017,11 +2053,20 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
BOOST_FOREACH(const CTransaction &tx, txConflicted) {
SyncWithWallets(tx, NULL);
}

// ... and about transactions that got confirmed:
BOOST_FOREACH(const CTransaction &tx, pblock->vtx) {
SyncWithWallets(tx, pblock);

//! Omni Core: new confirmed transaction notification
LogPrint("handler", "Omni Core handler: new confirmed transaction [height: %d, idx: %u]\n", GetHeight(), nTxIdx);
if (0 == mastercore_handler_tx(tx, GetHeight(), nTxIdx++, pindexNew)) ++nNumMetaTxs;
}

//! Omni Core: end of block connect notification
LogPrint("handler", "Omni Core handler: block connect end [new height: %d, found: %u txs]\n", GetHeight(), nNumMetaTxs);
mastercore_handler_block_end(GetHeight(), pindexNew, nNumMetaTxs);

int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001);
LogPrint("bench", "- Connect block: %.2fms [%.2fs]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001);
Expand Down

0 comments on commit d6a48bf

Please sign in to comment.