From 973800f3072954636a1158952819248bce088330 Mon Sep 17 00:00:00 2001 From: Integral Team M Date: Thu, 31 Oct 2019 15:46:21 +0700 Subject: [PATCH 001/152] spv: draft, WIP --- src/Makefile.am | 14 +- src/Makefile.bench.include | 1 + src/Makefile.qt.include | 2 +- src/Makefile.qttest.include | 2 +- src/Makefile.test.include | 3 +- src/init.cpp | 7 + src/spv/bcash/BRBCashAddr.c | 200 ++ src/spv/bcash/BRBCashAddr.h | 48 + src/spv/bcash/BRBCashParams.c | 190 ++ src/spv/bcash/BRBCashParams.h | 37 + src/spv/bitcoin/BRBIP38Key.c | 270 +++ src/spv/bitcoin/BRBIP38Key.h | 69 + src/spv/bitcoin/BRBloomFilter.c | 162 ++ src/spv/bitcoin/BRBloomFilter.h | 82 + src/spv/bitcoin/BRChainParams.c | 143 ++ src/spv/bitcoin/BRChainParams.h | 60 + src/spv/bitcoin/BRMerkleBlock.c | 374 +++ src/spv/bitcoin/BRMerkleBlock.h | 114 + src/spv/bitcoin/BRPaymentProtocol.c | 1420 +++++++++++ src/spv/bitcoin/BRPaymentProtocol.h | 263 +++ src/spv/bitcoin/BRPeer.c | 1650 +++++++++++++ src/spv/bitcoin/BRPeer.h | 249 ++ src/spv/bitcoin/BRPeerManager.c | 2039 ++++++++++++++++ src/spv/bitcoin/BRPeerManager.h | 128 + src/spv/bitcoin/BRTransaction.c | 747 ++++++ src/spv/bitcoin/BRTransaction.h | 160 ++ src/spv/bitcoin/BRWallet.c | 1268 ++++++++++ src/spv/bitcoin/BRWallet.h | 209 ++ src/spv/bitcoin/BRWalletManager.c | 626 +++++ src/spv/bitcoin/BRWalletManager.h | 157 ++ src/spv/bitcoin/test.c | 3369 +++++++++++++++++++++++++++ src/spv/spv_wrapper.cpp | 354 +++ src/spv/spv_wrapper.h | 177 ++ src/spv/support/BRAddress.c | 467 ++++ src/spv/support/BRAddress.h | 135 ++ src/spv/support/BRArray.h | 190 ++ src/spv/support/BRAssert.c | 312 +++ src/spv/support/BRAssert.h | 171 ++ src/spv/support/BRBIP32Sequence.c | 328 +++ src/spv/support/BRBIP32Sequence.h | 100 + src/spv/support/BRBIP39Mnemonic.c | 137 ++ src/spv/support/BRBIP39Mnemonic.h | 59 + src/spv/support/BRBIP39WordsEn.h | 2089 +++++++++++++++++ src/spv/support/BRBase58.c | 185 ++ src/spv/support/BRBase58.h | 54 + src/spv/support/BRBech32.c | 145 ++ src/spv/support/BRBech32.h | 49 + src/spv/support/BRCrypto.c | 1226 ++++++++++ src/spv/support/BRCrypto.h | 133 ++ src/spv/support/BRFileService.c | 534 +++++ src/spv/support/BRFileService.h | 187 ++ src/spv/support/BRInt.h | 231 ++ src/spv/support/BRKey.c | 529 +++++ src/spv/support/BRKey.h | 136 ++ src/spv/support/BRKeyECIES.c | 154 ++ src/spv/support/BRKeyECIES.h | 57 + src/spv/support/BRLargeInt.h | 120 + src/spv/support/BRSet.c | 341 +++ src/spv/support/BRSet.h | 104 + src/spv/support/testSup.c | 409 ++++ 60 files changed, 23172 insertions(+), 4 deletions(-) create mode 100644 src/spv/bcash/BRBCashAddr.c create mode 100644 src/spv/bcash/BRBCashAddr.h create mode 100644 src/spv/bcash/BRBCashParams.c create mode 100644 src/spv/bcash/BRBCashParams.h create mode 100644 src/spv/bitcoin/BRBIP38Key.c create mode 100644 src/spv/bitcoin/BRBIP38Key.h create mode 100644 src/spv/bitcoin/BRBloomFilter.c create mode 100644 src/spv/bitcoin/BRBloomFilter.h create mode 100644 src/spv/bitcoin/BRChainParams.c create mode 100644 src/spv/bitcoin/BRChainParams.h create mode 100644 src/spv/bitcoin/BRMerkleBlock.c create mode 100644 src/spv/bitcoin/BRMerkleBlock.h create mode 100644 src/spv/bitcoin/BRPaymentProtocol.c create mode 100644 src/spv/bitcoin/BRPaymentProtocol.h create mode 100644 src/spv/bitcoin/BRPeer.c create mode 100644 src/spv/bitcoin/BRPeer.h create mode 100644 src/spv/bitcoin/BRPeerManager.c create mode 100644 src/spv/bitcoin/BRPeerManager.h create mode 100644 src/spv/bitcoin/BRTransaction.c create mode 100644 src/spv/bitcoin/BRTransaction.h create mode 100644 src/spv/bitcoin/BRWallet.c create mode 100644 src/spv/bitcoin/BRWallet.h create mode 100644 src/spv/bitcoin/BRWalletManager.c create mode 100644 src/spv/bitcoin/BRWalletManager.h create mode 100644 src/spv/bitcoin/test.c create mode 100644 src/spv/spv_wrapper.cpp create mode 100644 src/spv/spv_wrapper.h create mode 100644 src/spv/support/BRAddress.c create mode 100644 src/spv/support/BRAddress.h create mode 100644 src/spv/support/BRArray.h create mode 100644 src/spv/support/BRAssert.c create mode 100644 src/spv/support/BRAssert.h create mode 100644 src/spv/support/BRBIP32Sequence.c create mode 100644 src/spv/support/BRBIP32Sequence.h create mode 100644 src/spv/support/BRBIP39Mnemonic.c create mode 100644 src/spv/support/BRBIP39Mnemonic.h create mode 100644 src/spv/support/BRBIP39WordsEn.h create mode 100644 src/spv/support/BRBase58.c create mode 100644 src/spv/support/BRBase58.h create mode 100644 src/spv/support/BRBech32.c create mode 100644 src/spv/support/BRBech32.h create mode 100644 src/spv/support/BRCrypto.c create mode 100644 src/spv/support/BRCrypto.h create mode 100644 src/spv/support/BRFileService.c create mode 100644 src/spv/support/BRFileService.h create mode 100644 src/spv/support/BRInt.h create mode 100644 src/spv/support/BRKey.c create mode 100644 src/spv/support/BRKey.h create mode 100644 src/spv/support/BRKeyECIES.c create mode 100644 src/spv/support/BRKeyECIES.h create mode 100644 src/spv/support/BRLargeInt.h create mode 100644 src/spv/support/BRSet.c create mode 100644 src/spv/support/BRSet.h create mode 100644 src/spv/support/testSup.c diff --git a/src/Makefile.am b/src/Makefile.am index 1451953f3b..11a820a2e0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,10 +19,17 @@ else LIBUNIVALUE = $(UNIVALUE_LIBS) endif -BITCOIN_INCLUDES=-I$(builddir) $(BDB_CPPFLAGS) $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) $(CRYPTO_CFLAGS) $(SSL_CFLAGS) +LIBSPV=spv/libspv.a +$(LIBSPV): + $(MAKE) -C spv lib +SPV_CFLAGS=-I./spv -I./spv/support -I./spv/bitcoin -I./spv/bcash +# -I./secp256k1 + +BITCOIN_INCLUDES=-I$(builddir) $(BDB_CPPFLAGS) $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) $(CRYPTO_CFLAGS) $(SSL_CFLAGS) BITCOIN_INCLUDES += -I$(srcdir)/secp256k1/include BITCOIN_INCLUDES += $(UNIVALUE_CFLAGS) +BITCOIN_INCLUDES += $(SPV_CFLAGS) LIBBITCOIN_SERVER=libbitcoin_server.a LIBBITCOIN_COMMON=libbitcoin_common.a @@ -193,6 +200,7 @@ BITCOIN_CORE_H = \ script/signingprovider.h \ script/standard.h \ shutdown.h \ + spv/spv_wrapper.h \ streams.h \ support/allocators/secure.h \ support/allocators/zeroafterfree.h \ @@ -305,6 +313,7 @@ libbitcoin_server_a_SOURCES = \ rpc/server.cpp \ script/sigcache.cpp \ shutdown.cpp \ + spv/spv_wrapper.cpp \ timedata.cpp \ torcontrol.cpp \ txdb.cpp \ @@ -552,6 +561,7 @@ bitcoind_LDADD = \ $(LIBBITCOIN_SERVER) \ $(LIBBITCOIN_COMMON) \ $(LIBUNIVALUE) \ + $(LIBSPV) \ $(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_ZMQ) \ $(LIBBITCOIN_CONSENSUS) \ @@ -618,6 +628,7 @@ bitcoin_wallet_LDADD = \ $(LIBBITCOIN_WALLET) \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_CONSENSUS) \ + $(LIBSPV) \ $(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_CRYPTO) \ $(LIBBITCOIN_ZMQ) \ @@ -682,6 +693,7 @@ $(top_srcdir)/$(subdir)/config/bitcoin-config.h.in: $(am__configure_deps) clean-local: -$(MAKE) -C secp256k1 clean -$(MAKE) -C univalue clean + -$(MAKE) -C spv clean -rm -f leveldb/*/*.gcda leveldb/*/*.gcno leveldb/helpers/memenv/*.gcda leveldb/helpers/memenv/*.gcno -rm -f config.h -rm -rf test/__pycache__ diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index e369a4614d..f4b68827d8 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -57,6 +57,7 @@ bench_bench_bitcoin_LDADD = \ $(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_CONSENSUS) \ $(LIBBITCOIN_CRYPTO) \ + $(LIBSPV) \ $(LIBLEVELDB) \ $(LIBLEVELDB_SSE42) \ $(LIBMEMENV) \ diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 6d8faf3883..2613e343a3 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -416,7 +416,7 @@ endif if ENABLE_ZMQ qt_bitcoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) endif -qt_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \ +qt_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBSPV) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \ $(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \ $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) if ENABLE_BIP70 diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include index 4acfff809e..f80fcc383c 100644 --- a/src/Makefile.qttest.include +++ b/src/Makefile.qttest.include @@ -71,7 +71,7 @@ endif if ENABLE_ZMQ qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) endif -qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) \ +qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBSPV) $(LIBLEVELDB) \ $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \ $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \ $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 10477fb3f9..4ec604c5e5 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -68,6 +68,7 @@ FUZZ_SUITE_LD_COMMON = \ $(LIBBITCOIN_CONSENSUS) \ $(LIBBITCOIN_CRYPTO) \ $(LIBUNIVALUE) \ + $(LIBSPV) \ $(LIBLEVELDB) \ $(LIBLEVELDB_SSE42) \ $(BOOST_LIBS) \ @@ -187,7 +188,7 @@ test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET) endif test_test_bitcoin_LDADD += $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) \ - $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) + $(LIBSPV) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) test_test_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) test_test_bitcoin_LDADD += $(BDB_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(RAPIDCHECK_LIBS) diff --git a/src/init.cpp b/src/init.cpp index 0a0d9e453b..defe368bbe 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -43,6 +43,7 @@ #include