├── src ├── univalue │ ├── test │ │ ├── fail29.json │ │ ├── fail16.json │ │ ├── fail30.json │ │ ├── fail31.json │ │ ├── round4.json │ │ ├── round5.json │ │ ├── round7.json │ │ ├── fail33.json │ │ ├── fail34.json │ │ ├── fail36.json │ │ ├── round6.json │ │ ├── fail2.json │ │ ├── fail24.json │ │ ├── fail27.json │ │ ├── fail28.json │ │ ├── fail37.json │ │ ├── fail38.json │ │ ├── fail39.json │ │ ├── fail4.json │ │ ├── fail8.json │ │ ├── round2.json │ │ ├── fail19.json │ │ ├── fail20.json │ │ ├── fail23.json │ │ ├── fail5.json │ │ ├── fail9.json │ │ ├── fail11.json │ │ ├── fail25.json │ │ ├── fail6.json │ │ ├── fail7.json │ │ ├── fail12.json │ │ ├── fail14.json │ │ ├── fail15.json │ │ ├── fail17.json │ │ ├── fail21.json │ │ ├── fail22.json │ │ ├── fail35.json │ │ ├── round3.json │ │ ├── fail26.json │ │ ├── fail3.json │ │ ├── fail13.json │ │ ├── fail32.json │ │ ├── fail42.json │ │ ├── fail44.json │ │ ├── fail18.json │ │ ├── pass2.json │ │ ├── fail10.json │ │ ├── fail1.json │ │ ├── .gitignore │ │ ├── fail40.json │ │ ├── fail41.json │ │ ├── pass3.json │ │ ├── no_nul.cpp │ │ ├── round1.json │ │ ├── test_json.cpp │ │ └── pass1.json │ ├── build-aux │ │ └── m4 │ │ │ └── .gitignore │ ├── lib │ │ └── .gitignore │ ├── autogen.sh │ ├── TODO │ ├── pc │ │ ├── libunivalue.pc.in │ │ └── libunivalue-uninstalled.pc.in │ ├── .gitignore │ ├── README.md │ ├── COPYING │ ├── .travis.yml │ ├── gen │ │ └── gen.cpp │ └── configure.ac ├── libbtc │ ├── src │ │ ├── secp256k1 │ │ │ ├── obj │ │ │ │ └── .gitignore │ │ │ ├── autogen.sh │ │ │ ├── TODO │ │ │ ├── src │ │ │ │ ├── modules │ │ │ │ │ ├── ecdh │ │ │ │ │ │ ├── Makefile.am.include │ │ │ │ │ │ └── main_impl.h │ │ │ │ │ ├── recovery │ │ │ │ │ │ └── Makefile.am.include │ │ │ │ │ └── schnorr │ │ │ │ │ │ ├── Makefile.am.include │ │ │ │ │ │ └── schnorr.h │ │ │ │ ├── java │ │ │ │ │ ├── org_bitcoin_Secp256k1Context.c │ │ │ │ │ ├── org_bitcoin_Secp256k1Context.h │ │ │ │ │ └── org │ │ │ │ │ │ └── bitcoin │ │ │ │ │ │ ├── NativeSecp256k1Util.java │ │ │ │ │ │ └── Secp256k1Context.java │ │ │ │ ├── ecmult_const.h │ │ │ │ ├── num_gmp.h │ │ │ │ ├── num_impl.h │ │ │ │ ├── scalar_8x32.h │ │ │ │ ├── scalar_4x64.h │ │ │ │ ├── basic-config.h │ │ │ │ ├── ecdsa.h │ │ │ │ ├── eckey.h │ │ │ │ ├── ecmult.h │ │ │ │ ├── testrand.h │ │ │ │ ├── bench_sign.c │ │ │ │ ├── hash.h │ │ │ │ ├── bench_ecdh.c │ │ │ │ ├── field_5x52.h │ │ │ │ ├── bench.h │ │ │ │ ├── field_10x26.h │ │ │ │ ├── bench_recover.c │ │ │ │ └── ecmult_gen.h │ │ │ ├── libsecp256k1.pc.in │ │ │ ├── .gitignore │ │ │ ├── COPYING │ │ │ └── include │ │ │ │ └── secp256k1_ecdh.h │ │ ├── buffer.c │ │ ├── headersdb.c │ │ ├── ripemd160.h │ │ └── logdb │ │ │ ├── include │ │ │ └── logdb │ │ │ │ ├── logdb_base.h │ │ │ │ └── logdb.h │ │ │ └── test │ │ │ └── tests_red_black_tree.c │ ├── rpctest │ │ ├── test_framework │ │ │ ├── __init__.py │ │ │ ├── siphash.py │ │ │ └── bignum.py │ │ └── .gitignore │ ├── autogen.sh │ ├── depends │ │ ├── .gitignore │ │ ├── builders │ │ │ ├── linux.mk │ │ │ ├── default.mk │ │ │ └── darwin.mk │ │ ├── packages │ │ │ ├── packages.mk │ │ │ ├── native_ccache.mk │ │ │ └── libevent.mk │ │ ├── hosts │ │ │ ├── mingw32.mk │ │ │ ├── darwin.mk │ │ │ ├── linux.mk │ │ │ └── default.mk │ │ └── patches │ │ │ └── libevent │ │ │ └── reuseaddr.patch │ ├── contrib │ │ └── format.sh │ ├── libbtc.pc.in │ ├── .gitignore │ ├── m4 │ │ └── macros │ │ │ └── with.m4 │ ├── test │ │ ├── buffer_tests.c │ │ ├── netspv_tests.c │ │ ├── hash_tests.c │ │ ├── random_tests.c │ │ └── memory_tests.c │ ├── include │ │ └── btc │ │ │ ├── blockchain.h │ │ │ ├── aes256_cbc.h │ │ │ ├── buffer.h │ │ │ ├── ctaes.h │ │ │ ├── random.h │ │ │ ├── base58.h │ │ │ ├── memory.h │ │ │ ├── block.h │ │ │ ├── vector.h │ │ │ ├── tool.h │ │ │ └── chainparams.h │ └── .clang-format ├── leveldb │ ├── .gitignore │ ├── .travis.yml │ ├── AUTHORS │ ├── util │ │ ├── filter_policy.cc │ │ ├── hash.h │ │ ├── options.cc │ │ ├── env_posix_test_helper.h │ │ ├── histogram.h │ │ ├── mutexlock.h │ │ ├── hash.cc │ │ ├── logging.h │ │ ├── crc32c.h │ │ ├── testutil.cc │ │ ├── hash_test.cc │ │ ├── arena_test.cc │ │ ├── testharness.cc │ │ ├── logging.cc │ │ ├── crc32c_test.cc │ │ ├── arena.h │ │ ├── status.cc │ │ ├── arena.cc │ │ ├── testutil.h │ │ ├── env_posix_test.cc │ │ └── random.h │ ├── port │ │ ├── README │ │ ├── port.h │ │ ├── win │ │ │ └── stdint.h │ │ ├── thread_annotations.h │ │ └── port_posix.cc │ ├── NEWS │ ├── TODO │ ├── helpers │ │ └── memenv │ │ │ └── memenv.h │ ├── db │ │ ├── db_iter.h │ │ ├── log_format.h │ │ ├── builder.h │ │ ├── version_edit_test.cc │ │ ├── log_writer.h │ │ ├── write_batch_internal.h │ │ ├── leveldbutil.cc │ │ ├── snapshot.h │ │ └── table_cache.h │ ├── table │ │ ├── merger.h │ │ ├── block.h │ │ ├── two_level_iterator.h │ │ ├── iterator.cc │ │ ├── block_builder.h │ │ └── iterator_wrapper.h │ ├── include │ │ └── leveldb │ │ │ ├── dumpfile.h │ │ │ └── write_batch.h │ ├── WINDOWS.md │ ├── LICENSE │ ├── CONTRIBUTING.md │ └── issues │ │ └── issue200_test.cc ├── shutdown.h ├── shutdown.cpp ├── hash.h ├── dbinterface.h └── Makefile.am ├── autogen.sh ├── Makefile.am ├── .gitignore └── README.md /src/univalue/test/fail29.json: -------------------------------------------------------------------------------- 1 | [0e] -------------------------------------------------------------------------------- /src/univalue/test/fail16.json: -------------------------------------------------------------------------------- 1 | [\naked] -------------------------------------------------------------------------------- /src/univalue/test/fail30.json: -------------------------------------------------------------------------------- 1 | [0e+] -------------------------------------------------------------------------------- /src/univalue/test/fail31.json: -------------------------------------------------------------------------------- 1 | [0e+-1] -------------------------------------------------------------------------------- /src/univalue/test/round4.json: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /src/univalue/test/round5.json: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /src/univalue/test/round7.json: -------------------------------------------------------------------------------- 1 | null 2 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/obj/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/univalue/test/fail33.json: -------------------------------------------------------------------------------- 1 | ["mismatch"} -------------------------------------------------------------------------------- /src/univalue/test/fail34.json: -------------------------------------------------------------------------------- 1 | {} garbage -------------------------------------------------------------------------------- /src/univalue/test/fail36.json: -------------------------------------------------------------------------------- 1 | {"a":} 2 | -------------------------------------------------------------------------------- /src/univalue/test/round6.json: -------------------------------------------------------------------------------- 1 | false 2 | -------------------------------------------------------------------------------- /src/libbtc/rpctest/test_framework/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/univalue/build-aux/m4/.gitignore: -------------------------------------------------------------------------------- 1 | /*.m4 2 | -------------------------------------------------------------------------------- /src/univalue/lib/.gitignore: -------------------------------------------------------------------------------- 1 | gen 2 | .libs 3 | -------------------------------------------------------------------------------- /src/univalue/test/fail2.json: -------------------------------------------------------------------------------- 1 | ["Unclosed array" -------------------------------------------------------------------------------- /src/univalue/test/fail24.json: -------------------------------------------------------------------------------- 1 | ['single quote'] -------------------------------------------------------------------------------- /src/univalue/test/fail27.json: -------------------------------------------------------------------------------- 1 | ["line 2 | break"] -------------------------------------------------------------------------------- /src/univalue/test/fail28.json: -------------------------------------------------------------------------------- 1 | ["line\ 2 | break"] -------------------------------------------------------------------------------- /src/univalue/test/fail37.json: -------------------------------------------------------------------------------- 1 | {"a":1 "b":2} 2 | -------------------------------------------------------------------------------- /src/univalue/test/fail38.json: -------------------------------------------------------------------------------- 1 | ["\ud834"] 2 | -------------------------------------------------------------------------------- /src/univalue/test/fail39.json: -------------------------------------------------------------------------------- 1 | ["\udd61"] 2 | -------------------------------------------------------------------------------- /src/univalue/test/fail4.json: -------------------------------------------------------------------------------- 1 | ["extra comma",] -------------------------------------------------------------------------------- /src/univalue/test/fail8.json: -------------------------------------------------------------------------------- 1 | ["Extra close"]] -------------------------------------------------------------------------------- /src/univalue/test/round2.json: -------------------------------------------------------------------------------- 1 | ["a§■𐎒𝅘𝅥𝅯"] 2 | -------------------------------------------------------------------------------- /src/libbtc/rpctest/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | cache 3 | -------------------------------------------------------------------------------- /src/univalue/test/fail19.json: -------------------------------------------------------------------------------- 1 | {"Missing colon" null} -------------------------------------------------------------------------------- /src/univalue/test/fail20.json: -------------------------------------------------------------------------------- 1 | {"Double colon":: null} -------------------------------------------------------------------------------- /src/univalue/test/fail23.json: -------------------------------------------------------------------------------- 1 | ["Bad value", truth] -------------------------------------------------------------------------------- /src/univalue/test/fail5.json: -------------------------------------------------------------------------------- 1 | ["double extra comma",,] -------------------------------------------------------------------------------- /src/univalue/test/fail9.json: -------------------------------------------------------------------------------- 1 | {"Extra comma": true,} -------------------------------------------------------------------------------- /src/univalue/test/fail11.json: -------------------------------------------------------------------------------- 1 | {"Illegal expression": 1 + 2} -------------------------------------------------------------------------------- /src/univalue/test/fail25.json: -------------------------------------------------------------------------------- 1 | [" tab character in string "] -------------------------------------------------------------------------------- /src/univalue/test/fail6.json: -------------------------------------------------------------------------------- 1 | [ , "<-- missing value"] -------------------------------------------------------------------------------- /src/univalue/test/fail7.json: -------------------------------------------------------------------------------- 1 | ["Comma after the close"], -------------------------------------------------------------------------------- /src/univalue/test/fail12.json: -------------------------------------------------------------------------------- 1 | {"Illegal invocation": alert()} -------------------------------------------------------------------------------- /src/univalue/test/fail14.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot be hex": 0x14} -------------------------------------------------------------------------------- /src/univalue/test/fail15.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \x15"] -------------------------------------------------------------------------------- /src/univalue/test/fail17.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \017"] -------------------------------------------------------------------------------- /src/univalue/test/fail21.json: -------------------------------------------------------------------------------- 1 | {"Comma instead of colon", null} -------------------------------------------------------------------------------- /src/univalue/test/fail22.json: -------------------------------------------------------------------------------- 1 | ["Colon instead of comma": false] -------------------------------------------------------------------------------- /src/univalue/test/fail35.json: -------------------------------------------------------------------------------- 1 | [ true true true [] [] [] ] 2 | -------------------------------------------------------------------------------- /src/univalue/test/round3.json: -------------------------------------------------------------------------------- 1 | "abcdefghijklmnopqrstuvwxyz" 2 | -------------------------------------------------------------------------------- /src/univalue/test/fail26.json: -------------------------------------------------------------------------------- 1 | ["tab\ character\ in\ string\ "] -------------------------------------------------------------------------------- /src/univalue/test/fail3.json: -------------------------------------------------------------------------------- 1 | {unquoted_key: "keys must be quoted"} -------------------------------------------------------------------------------- /src/univalue/test/fail13.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot have leading zeroes": 013} -------------------------------------------------------------------------------- /src/univalue/test/fail32.json: -------------------------------------------------------------------------------- 1 | {"Comma instead if closing brace": true, -------------------------------------------------------------------------------- /src/univalue/test/fail42.json: -------------------------------------------------------------------------------- 1 | ["before nul byte"]"after nul byte" 2 | -------------------------------------------------------------------------------- /src/univalue/test/fail44.json: -------------------------------------------------------------------------------- 1 | "This file ends without a newline or close-quote. -------------------------------------------------------------------------------- /src/libbtc/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | autoreconf -if --warnings=all 4 | -------------------------------------------------------------------------------- /src/univalue/test/fail18.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /src/univalue/test/pass2.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /src/univalue/test/fail10.json: -------------------------------------------------------------------------------- 1 | {"Extra value after close": true} "misplaced quoted value" -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | autoreconf -if --warnings=all 4 | -------------------------------------------------------------------------------- /src/univalue/test/fail1.json: -------------------------------------------------------------------------------- 1 | "This is a string that never ends, yes it goes on and on, my friends. 2 | -------------------------------------------------------------------------------- /src/univalue/test/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | object 3 | unitester 4 | test_json 5 | no_nul 6 | 7 | *.trs 8 | *.log 9 | -------------------------------------------------------------------------------- /src/univalue/test/fail40.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonasschnelli/bitcoincore-indexd/master/src/univalue/test/fail40.json -------------------------------------------------------------------------------- /src/univalue/test/fail41.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonasschnelli/bitcoincore-indexd/master/src/univalue/test/fail41.json -------------------------------------------------------------------------------- /src/libbtc/depends/.gitignore: -------------------------------------------------------------------------------- 1 | SDKs/ 2 | work/ 3 | built/ 4 | sources/ 5 | config.site 6 | x86_64* 7 | i686* 8 | mips* 9 | arm* 10 | aarch64* 11 | -------------------------------------------------------------------------------- /src/leveldb/.gitignore: -------------------------------------------------------------------------------- 1 | build_config.mk 2 | *.a 3 | *.o 4 | *.dylib* 5 | *.so 6 | *.so.* 7 | *_test 8 | db_bench 9 | leveldbutil 10 | Release 11 | Debug 12 | Benchmark 13 | vs2010.* 14 | -------------------------------------------------------------------------------- /src/libbtc/depends/builders/linux.mk: -------------------------------------------------------------------------------- 1 | build_linux_SHA256SUM = sha256sum 2 | build_linux_DOWNLOAD = curl --location --fail --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -o 3 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/TODO: -------------------------------------------------------------------------------- 1 | * Unit tests for fieldelem/groupelem, including ones intended to 2 | trigger fieldelem's boundary cases. 3 | * Complete constant-time operations for signing/keygen 4 | -------------------------------------------------------------------------------- /src/univalue/test/pass3.json: -------------------------------------------------------------------------------- 1 | { 2 | "JSON Test Pattern pass3": { 3 | "The outermost value": "must be an object or array.", 4 | "In this test": "It is an object." 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/libbtc/contrib/format.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "execute from git root dir" 4 | find . \( -not -path './src/secp256k1/*' -and \( -name '*.h' -or -name '*.c' \) \) -prune -print0 | xargs -0 "clang-format" -i 5 | -------------------------------------------------------------------------------- /src/univalue/test/no_nul.cpp: -------------------------------------------------------------------------------- 1 | #include "univalue.h" 2 | 3 | int main (int argc, char *argv[]) 4 | { 5 | char buf[] = "___[1,2,3]___"; 6 | UniValue val; 7 | return val.read(buf + 3, 7) ? 0 : 1; 8 | } 9 | -------------------------------------------------------------------------------- /src/leveldb/.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - clang 4 | - gcc 5 | os: 6 | - linux 7 | - osx 8 | sudo: false 9 | before_install: 10 | - echo $LANG 11 | - echo $LC_ALL 12 | script: 13 | - make -j 4 check 14 | -------------------------------------------------------------------------------- /src/univalue/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | srcdir="$(dirname $0)" 4 | cd "$srcdir" 5 | if [ -z ${LIBTOOLIZE} ] && GLIBTOOLIZE="`which glibtoolize 2>/dev/null`"; then 6 | LIBTOOLIZE="${GLIBTOOLIZE}" 7 | export LIBTOOLIZE 8 | fi 9 | autoreconf --install --force 10 | -------------------------------------------------------------------------------- /src/libbtc/depends/packages/packages.mk: -------------------------------------------------------------------------------- 1 | packages:=libevent 2 | native_packages := native_ccache 3 | 4 | wallet_packages= 5 | 6 | upnp_packages= 7 | 8 | darwin_native_packages = 9 | 10 | ifneq ($(build_os),darwin) 11 | darwin_native_packages += native_cctools 12 | endif 13 | -------------------------------------------------------------------------------- /src/univalue/TODO: -------------------------------------------------------------------------------- 1 | 2 | Rearrange tree for easier 'git subtree' style use 3 | 4 | Move towards C++11 etc. 5 | 6 | Namespace support - must come up with useful shorthand, avoiding 7 | long Univalue::Univalue::Univalue usages forced upon library users. 8 | 9 | Improve test suite 10 | 11 | -------------------------------------------------------------------------------- /src/univalue/test/round1.json: -------------------------------------------------------------------------------- 1 | ["\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007f"] 2 | -------------------------------------------------------------------------------- /src/univalue/pc/libunivalue.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libunivalue 7 | Description: libunivalue, C++ universal value object and JSON library 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lunivalue 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /src/univalue/pc/libunivalue-uninstalled.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libunivalue 7 | Description: libunivalue, C++ universal value object and JSON library 8 | Version: @VERSION@ 9 | Libs: ${pc_top_builddir}/${pcfiledir}/libunivalue.la 10 | -------------------------------------------------------------------------------- /src/libbtc/depends/hosts/mingw32.mk: -------------------------------------------------------------------------------- 1 | mingw32_CFLAGS=-pipe 2 | mingw32_CXXFLAGS=$(mingw32_CFLAGS) 3 | 4 | mingw32_release_CFLAGS=-O2 5 | mingw32_release_CXXFLAGS=$(mingw32_release_CFLAGS) 6 | 7 | mingw32_debug_CFLAGS=-O1 8 | mingw32_debug_CXXFLAGS=$(mingw32_debug_CFLAGS) 9 | 10 | mingw32_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC 11 | -------------------------------------------------------------------------------- /src/libbtc/libbtc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libbtc 7 | Description: C library for manipulating bitcoin data structures 8 | URL: https://github.com/jonasschnelli/libbtc 9 | Version: @PACKAGE_VERSION@ 10 | Cflags: -I${includedir} 11 | Libs: -L${libdir} -lbtc 12 | 13 | -------------------------------------------------------------------------------- /src/leveldb/AUTHORS: -------------------------------------------------------------------------------- 1 | # Names should be added to this file like so: 2 | # Name or Organization 3 | 4 | Google Inc. 5 | 6 | # Initial version authors: 7 | Jeffrey Dean 8 | Sanjay Ghemawat 9 | 10 | # Partial list of contributors: 11 | Kevin Regan 12 | Johan Bilien 13 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/modules/ecdh/Makefile.am.include: -------------------------------------------------------------------------------- 1 | include_HEADERS += include/secp256k1_ecdh.h 2 | noinst_HEADERS += src/modules/ecdh/main_impl.h 3 | noinst_HEADERS += src/modules/ecdh/tests_impl.h 4 | if USE_BENCHMARK 5 | noinst_PROGRAMS += bench_ecdh 6 | bench_ecdh_SOURCES = src/bench_ecdh.c 7 | bench_ecdh_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) 8 | endif 9 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/modules/recovery/Makefile.am.include: -------------------------------------------------------------------------------- 1 | include_HEADERS += include/secp256k1_recovery.h 2 | noinst_HEADERS += src/modules/recovery/main_impl.h 3 | noinst_HEADERS += src/modules/recovery/tests_impl.h 4 | if USE_BENCHMARK 5 | noinst_PROGRAMS += bench_recover 6 | bench_recover_SOURCES = src/bench_recover.c 7 | bench_recover_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) 8 | endif 9 | -------------------------------------------------------------------------------- /src/leveldb/util/filter_policy.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/filter_policy.h" 6 | 7 | namespace leveldb { 8 | 9 | FilterPolicy::~FilterPolicy() { } 10 | 11 | } // namespace leveldb 12 | -------------------------------------------------------------------------------- /src/shutdown.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 The Bitcoin Core developers 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef BITCOINCORE_INDEXD_SHUTDOWN_H 6 | #define BITCOINCORE_INDEXD_SHUTDOWN_H 7 | 8 | bool isShutdownRequested(); 9 | void requestShutdown(); 10 | 11 | #endif // BITCOINCORE_INDEXD_SHUTDOWN_H 12 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/libsecp256k1.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libsecp256k1 7 | Description: Optimized C library for EC operations on curve secp256k1 8 | URL: https://github.com/bitcoin-core/secp256k1 9 | Version: @PACKAGE_VERSION@ 10 | Cflags: -I${includedir} 11 | Libs.private: @SECP_LIBS@ 12 | Libs: -L${libdir} -lsecp256k1 13 | 14 | -------------------------------------------------------------------------------- /src/univalue/.gitignore: -------------------------------------------------------------------------------- 1 | .deps/ 2 | INSTALL 3 | Makefile 4 | Makefile.in 5 | aclocal.m4 6 | autom4te.cache/ 7 | compile 8 | config.log 9 | config.status 10 | config.guess 11 | config.sub 12 | configure 13 | depcomp 14 | install-sh 15 | missing 16 | stamp-h1 17 | univalue-config.h* 18 | test-driver 19 | libtool 20 | ltmain.sh 21 | test-suite.log 22 | 23 | *.a 24 | *.la 25 | *.lo 26 | *.logs 27 | *.o 28 | *.pc 29 | *.trs 30 | 31 | .dirstamp 32 | .libs 33 | -------------------------------------------------------------------------------- /src/leveldb/port/README: -------------------------------------------------------------------------------- 1 | This directory contains interfaces and implementations that isolate the 2 | rest of the package from platform details. 3 | 4 | Code in the rest of the package includes "port.h" from this directory. 5 | "port.h" in turn includes a platform specific "port_.h" file 6 | that provides the platform specific implementation. 7 | 8 | See port_posix.h for an example of what must be provided in a platform 9 | specific header file. 10 | 11 | -------------------------------------------------------------------------------- /src/shutdown.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 The Bitcoin Core developers 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include "shutdown.h" 6 | 7 | #include 8 | 9 | std::atomic fRequestShutdown(false); 10 | 11 | bool isShutdownRequested() { 12 | return fRequestShutdown; 13 | } 14 | void requestShutdown() { 15 | fRequestShutdown = true; 16 | } 17 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/java/org_bitcoin_Secp256k1Context.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "org_bitcoin_Secp256k1Context.h" 4 | #include "include/secp256k1.h" 5 | 6 | SECP256K1_API jlong JNICALL Java_org_bitcoin_Secp256k1Context_secp256k1_1init_1context 7 | (JNIEnv* env, jclass classObject) 8 | { 9 | secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); 10 | 11 | (void)classObject;(void)env; 12 | 13 | return (uintptr_t)ctx; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/modules/schnorr/Makefile.am.include: -------------------------------------------------------------------------------- 1 | include_HEADERS += include/secp256k1_schnorr.h 2 | noinst_HEADERS += src/modules/schnorr/main_impl.h 3 | noinst_HEADERS += src/modules/schnorr/schnorr.h 4 | noinst_HEADERS += src/modules/schnorr/schnorr_impl.h 5 | noinst_HEADERS += src/modules/schnorr/tests_impl.h 6 | if USE_BENCHMARK 7 | noinst_PROGRAMS += bench_schnorr_verify 8 | bench_schnorr_verify_SOURCES = src/bench_schnorr_verify.c 9 | bench_schnorr_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) 10 | endif 11 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2013-2016 The Bitcoin Core developers 3 | # Distributed under the MIT software license, see the accompanying 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 | 6 | set -e 7 | srcdir="$(dirname $0)" 8 | cd "$srcdir" 9 | if [ -z ${LIBTOOLIZE} ] && GLIBTOOLIZE="`which glibtoolize 2>/dev/null`"; then 10 | LIBTOOLIZE="${GLIBTOOLIZE}" 11 | export LIBTOOLIZE 12 | fi 13 | which autoreconf >/dev/null || \ 14 | (echo "configuration failed, please install autoconf first" && exit 1) 15 | autoreconf --install --force --warnings=all 16 | -------------------------------------------------------------------------------- /src/leveldb/NEWS: -------------------------------------------------------------------------------- 1 | Release 1.2 2011-05-16 2 | ---------------------- 3 | 4 | Fixes for larger databases (tested up to one billion 100-byte entries, 5 | i.e., ~100GB). 6 | 7 | (1) Place hard limit on number of level-0 files. This fixes errors 8 | of the form "too many open files". 9 | 10 | (2) Fixed memtable management. Before the fix, a heavy write burst 11 | could cause unbounded memory usage. 12 | 13 | A fix for a logging bug where the reader would incorrectly complain 14 | about corruption. 15 | 16 | Allow public access to WriteBatch contents so that users can easily 17 | wrap a DB. 18 | -------------------------------------------------------------------------------- /src/leveldb/TODO: -------------------------------------------------------------------------------- 1 | ss 2 | - Stats 3 | 4 | db 5 | - Maybe implement DB::BulkDeleteForRange(start_key, end_key) 6 | that would blow away files whose ranges are entirely contained 7 | within [start_key..end_key]? For Chrome, deletion of obsolete 8 | object stores, etc. can be done in the background anyway, so 9 | probably not that important. 10 | - There have been requests for MultiGet. 11 | 12 | After a range is completely deleted, what gets rid of the 13 | corresponding files if we do no future changes to that range. Make 14 | the conditions for triggering compactions fire in more situations? 15 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018 Jonas Schnelli 2 | # Distributed under the MIT software license, see the accompanying 3 | # file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | ACLOCAL_AMFLAGS = -I build-aux/m4 6 | SUBDIRS = src 7 | .PHONY: deploy FORCE 8 | 9 | export PYTHONPATH 10 | 11 | BITCOINCOREINDEXD_BIN=$(top_builddir)/src/$(BITCOINCOREINDEXD_DAEMON_NAME)$(EXEEXT) 12 | 13 | empty := 14 | space := $(empty) $(empty) 15 | 16 | $(BITCOINCOREINDEXD_BIN): FORCE 17 | $(MAKE) -C src $(@F) 18 | 19 | dist_noinst_SCRIPTS = autogen.sh 20 | 21 | CLEANFILES = $(OSX_DMG) $(BITCOIN_WIN_INSTALLER) 22 | -------------------------------------------------------------------------------- /src/leveldb/util/hash.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Simple hash function used for internal data structures 6 | 7 | #ifndef STORAGE_LEVELDB_UTIL_HASH_H_ 8 | #define STORAGE_LEVELDB_UTIL_HASH_H_ 9 | 10 | #include 11 | #include 12 | 13 | namespace leveldb { 14 | 15 | extern uint32_t Hash(const char* data, size_t n, uint32_t seed); 16 | 17 | } 18 | 19 | #endif // STORAGE_LEVELDB_UTIL_HASH_H_ 20 | -------------------------------------------------------------------------------- /src/libbtc/.gitignore: -------------------------------------------------------------------------------- 1 | tests 2 | tests.* 3 | test-suite.log 4 | *.exe 5 | *.so 6 | *.a 7 | !.gitignore 8 | bitcointool 9 | bitcoin-send-tx 10 | bitcoin-spv 11 | bitcoin-txref 12 | 13 | Makefile 14 | configure 15 | .libs/ 16 | Makefile.in 17 | aclocal.m4 18 | autom4te.cache/ 19 | config.log 20 | config.status 21 | *.db 22 | *.tar.gz 23 | *.la 24 | libtool 25 | .deps/ 26 | .dirstamp 27 | build-aux/ 28 | *.lo 29 | *.o 30 | *~ 31 | src/libbtc-config.h 32 | src/libbtc-config.h.in 33 | m4/libtool.m4 34 | m4/ltoptions.m4 35 | m4/ltsugar.m4 36 | m4/ltversion.m4 37 | m4/lt~obsolete.m4 38 | src/stamp-h1 39 | libbtc.pc 40 | *.DS_Store 41 | *.gcda 42 | *.gcov 43 | *.gcno 44 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/ecmult_const.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECMULT_CONST_ 8 | #define _SECP256K1_ECMULT_CONST_ 9 | 10 | #include "scalar.h" 11 | #include "group.h" 12 | 13 | static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/java/org_bitcoin_Secp256k1Context.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | #include "include/secp256k1.h" 4 | /* Header for class org_bitcoin_Secp256k1Context */ 5 | 6 | #ifndef _Included_org_bitcoin_Secp256k1Context 7 | #define _Included_org_bitcoin_Secp256k1Context 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | /* 12 | * Class: org_bitcoin_Secp256k1Context 13 | * Method: secp256k1_init_context 14 | * Signature: ()J 15 | */ 16 | SECP256K1_API jlong JNICALL Java_org_bitcoin_Secp256k1Context_secp256k1_1init_1context 17 | (JNIEnv *, jclass); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /src/libbtc/depends/packages/native_ccache.mk: -------------------------------------------------------------------------------- 1 | package=native_ccache 2 | $(package)_version=3.3.3 3 | $(package)_download_path=https://samba.org/ftp/ccache 4 | $(package)_file_name=ccache-$($(package)_version).tar.bz2 5 | $(package)_sha256_hash=2985bc5e32ebe38d2958d508eb54ddcad39eed909489c0c2988035214597ca54 6 | 7 | define $(package)_set_vars 8 | $(package)_config_opts= 9 | endef 10 | 11 | define $(package)_config_cmds 12 | $($(package)_autoconf) 13 | endef 14 | 15 | define $(package)_build_cmds 16 | $(MAKE) 17 | endef 18 | 19 | define $(package)_stage_cmds 20 | $(MAKE) DESTDIR=$($(package)_staging_dir) install 21 | endef 22 | 23 | define $(package)_postprocess_cmds 24 | rm -rf lib include 25 | endef 26 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/num_gmp.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_NUM_REPR_ 8 | #define _SECP256K1_NUM_REPR_ 9 | 10 | #include 11 | 12 | #define NUM_LIMBS ((256+GMP_NUMB_BITS-1)/GMP_NUMB_BITS) 13 | 14 | typedef struct { 15 | mp_limb_t data[2*NUM_LIMBS]; 16 | int neg; 17 | int limbs; 18 | } secp256k1_num; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/libbtc/depends/hosts/darwin.mk: -------------------------------------------------------------------------------- 1 | OSX_MIN_VERSION=10.8 2 | OSX_SDK_VERSION=10.11 3 | OSX_SDK=$(SDK_PATH)/MacOSX$(OSX_SDK_VERSION).sdk 4 | LD64_VERSION=253.9 5 | darwin_CC=clang -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) 6 | darwin_CXX=clang++ -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -stdlib=libc++ 7 | 8 | darwin_CFLAGS=-pipe 9 | darwin_CXXFLAGS=$(darwin_CFLAGS) 10 | 11 | darwin_release_CFLAGS=-O2 12 | darwin_release_CXXFLAGS=$(darwin_release_CFLAGS) 13 | 14 | darwin_debug_CFLAGS=-O1 15 | darwin_debug_CXXFLAGS=$(darwin_debug_CFLAGS) 16 | 17 | darwin_native_toolchain=native_cctools 18 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/num_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_NUM_IMPL_H_ 8 | #define _SECP256K1_NUM_IMPL_H_ 9 | 10 | #if defined HAVE_CONFIG_H 11 | #include "libsecp256k1-config.h" 12 | #endif 13 | 14 | #include "num.h" 15 | 16 | #if defined(USE_NUM_GMP) 17 | #include "num_gmp_impl.h" 18 | #elif defined(USE_NUM_NONE) 19 | /* Nothing. */ 20 | #else 21 | #error "Please select num implementation" 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/scalar_8x32.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint32_t d[8]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)}} 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/leveldb/helpers/memenv/memenv.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 6 | #define STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Env; 11 | 12 | // Returns a new environment that stores its data in memory and delegates 13 | // all non-file-storage tasks to base_env. The caller must delete the result 14 | // when it is no longer needed. 15 | // *base_env must remain live while the result is in use. 16 | Env* NewMemEnv(Env* base_env); 17 | 18 | } // namespace leveldb 19 | 20 | #endif // STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 21 | -------------------------------------------------------------------------------- /src/univalue/test/test_json.cpp: -------------------------------------------------------------------------------- 1 | // Test program that can be called by the JSON test suite at 2 | // https://github.com/nst/JSONTestSuite. 3 | // 4 | // It reads JSON input from stdin and exits with code 0 if it can be parsed 5 | // successfully. It also pretty prints the parsed JSON value to stdout. 6 | 7 | #include 8 | #include 9 | #include "univalue.h" 10 | 11 | using namespace std; 12 | 13 | int main (int argc, char *argv[]) 14 | { 15 | UniValue val; 16 | if (val.read(string(istreambuf_iterator(cin), 17 | istreambuf_iterator()))) { 18 | cout << val.write(1 /* prettyIndent */, 4 /* indentLevel */) << endl; 19 | return 0; 20 | } else { 21 | cerr << "JSON Parse Error." << endl; 22 | return 1; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/libbtc/depends/patches/libevent/reuseaddr.patch: -------------------------------------------------------------------------------- 1 | --- old/evutil.c 2015-08-28 19:26:23.488765923 -0400 2 | +++ new/evutil.c 2015-08-28 19:27:41.392767019 -0400 3 | @@ -321,15 +321,16 @@ 4 | int 5 | evutil_make_listen_socket_reuseable(evutil_socket_t sock) 6 | { 7 | -#ifndef WIN32 8 | int one = 1; 9 | +#ifndef WIN32 10 | /* REUSEADDR on Unix means, "don't hang on to this address after the 11 | * listener is closed." On Windows, though, it means "don't keep other 12 | * processes from binding to this address while we're using it. */ 13 | return setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*) &one, 14 | (ev_socklen_t)sizeof(one)); 15 | #else 16 | - return 0; 17 | + return setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*) &one, 18 | + (ev_socklen_t)sizeof(one)); 19 | #endif 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/libbtc/m4/macros/with.m4: -------------------------------------------------------------------------------- 1 | 2 | # ARG_WITH_SUBST(option, default, help) 3 | # ----------------------------------- 4 | # Create a --with-$1 option with helptext, AC_SUBST($1) to $withval/default 5 | AC_DEFUN([ARG_WITH_SUBST], 6 | [AC_ARG_WITH( 7 | [$1], 8 | AS_HELP_STRING([--with-$1=arg], [$3 (default: $2).]), 9 | [AC_SUBST(patsubst([$1], [-], [_]), ["$withval"])], 10 | [AC_SUBST(patsubst([$1], [-], [_]), ["$2"])] 11 | )] 12 | ) 13 | 14 | # ARG_WITH_SET(option, default, help) 15 | # ----------------------------------- 16 | # Create a --with-$1 option with helptext, set a variable $1 to $withval/default 17 | AC_DEFUN([ARG_WITH_SET], 18 | [AC_ARG_WITH( 19 | [$1], 20 | AS_HELP_STRING([--with-$1=arg], [$3 (default: $2).]), 21 | patsubst([$1], [-], [_])="$withval", 22 | patsubst([$1], [-], [_])=$2 23 | )] 24 | ) 25 | -------------------------------------------------------------------------------- /src/leveldb/port/port.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_PORT_PORT_H_ 6 | #define STORAGE_LEVELDB_PORT_PORT_H_ 7 | 8 | #include 9 | 10 | // Include the appropriate platform specific file below. If you are 11 | // porting to a new platform, see "port_example.h" for documentation 12 | // of what the new port_.h file must provide. 13 | #if defined(LEVELDB_PLATFORM_POSIX) 14 | # include "port/port_posix.h" 15 | #elif defined(LEVELDB_PLATFORM_CHROMIUM) 16 | # include "port/port_chromium.h" 17 | #elif defined(LEVELDB_PLATFORM_WINDOWS) 18 | # include "port/port_win.h" 19 | #endif 20 | 21 | #endif // STORAGE_LEVELDB_PORT_PORT_H_ 22 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/scalar_4x64.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint64_t d[4]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{((uint64_t)(d1)) << 32 | (d0), ((uint64_t)(d3)) << 32 | (d2), ((uint64_t)(d5)) << 32 | (d4), ((uint64_t)(d7)) << 32 | (d6)}} 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/libbtc/depends/builders/default.mk: -------------------------------------------------------------------------------- 1 | default_build_CC = gcc 2 | default_build_CXX = g++ 3 | default_build_AR = ar 4 | default_build_RANLIB = ranlib 5 | default_build_STRIP = strip 6 | default_build_NM = nm 7 | default_build_OTOOL = otool 8 | default_build_INSTALL_NAME_TOOL = install_name_tool 9 | 10 | define add_build_tool_func 11 | build_$(build_os)_$1 ?= $$(default_build_$1) 12 | build_$(build_arch)_$(build_os)_$1 ?= $$(build_$(build_os)_$1) 13 | build_$1=$$(build_$(build_arch)_$(build_os)_$1) 14 | endef 15 | $(foreach var,CC CXX AR RANLIB NM STRIP SHA256SUM DOWNLOAD OTOOL INSTALL_NAME_TOOL,$(eval $(call add_build_tool_func,$(var)))) 16 | define add_build_flags_func 17 | build_$(build_arch)_$(build_os)_$1 += $(build_$(build_os)_$1) 18 | build_$1=$$(build_$(build_arch)_$(build_os)_$1) 19 | endef 20 | $(foreach flags, CFLAGS CXXFLAGS LDFLAGS, $(eval $(call add_build_flags_func,$(flags)))) 21 | -------------------------------------------------------------------------------- /src/libbtc/depends/hosts/linux.mk: -------------------------------------------------------------------------------- 1 | linux_CFLAGS=-pipe 2 | linux_CXXFLAGS=$(linux_CFLAGS) 3 | 4 | linux_release_CFLAGS=-O2 5 | linux_release_CXXFLAGS=$(linux_release_CFLAGS) 6 | 7 | linux_debug_CFLAGS=-O1 8 | linux_debug_CXXFLAGS=$(linux_debug_CFLAGS) 9 | 10 | linux_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC 11 | 12 | ifeq (86,$(findstring 86,$(build_arch))) 13 | i686_linux_CC=gcc -m32 14 | i686_linux_CXX=g++ -m32 15 | i686_linux_AR=ar 16 | i686_linux_RANLIB=ranlib 17 | i686_linux_NM=nm 18 | i686_linux_STRIP=strip 19 | 20 | x86_64_linux_CC=gcc -m64 21 | x86_64_linux_CXX=g++ -m64 22 | x86_64_linux_AR=ar 23 | x86_64_linux_RANLIB=ranlib 24 | x86_64_linux_NM=nm 25 | x86_64_linux_STRIP=strip 26 | else 27 | i686_linux_CC=$(default_host_CC) -m32 28 | i686_linux_CXX=$(default_host_CXX) -m32 29 | x86_64_linux_CC=$(default_host_CC) -m64 30 | x86_64_linux_CXX=$(default_host_CXX) -m64 31 | endif 32 | -------------------------------------------------------------------------------- /src/univalue/README.md: -------------------------------------------------------------------------------- 1 | 2 | # UniValue 3 | 4 | ## Summary 5 | 6 | A universal value class, with JSON encoding and decoding. 7 | 8 | UniValue is an abstract data type that may be a null, boolean, string, 9 | number, array container, or a key/value dictionary container, nested to 10 | an arbitrary depth. 11 | 12 | This class is aligned with the JSON standard, [RFC 13 | 7159](https://tools.ietf.org/html/rfc7159.html). 14 | 15 | ## Installation 16 | 17 | This project is a standard GNU 18 | [autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html) 19 | project. Build and install instructions are available in the `INSTALL` 20 | file provided with GNU autotools. 21 | 22 | ``` 23 | $ ./autogen.sh 24 | $ ./configure 25 | $ make 26 | ``` 27 | 28 | ## Design 29 | 30 | UniValue provides a single dynamic RAII C++ object class, 31 | and minimizes template use (contra json_spirit). 32 | 33 | -------------------------------------------------------------------------------- /src/libbtc/depends/packages/libevent.mk: -------------------------------------------------------------------------------- 1 | package=libevent 2 | $(package)_version=2.1.7 3 | $(package)_download_path=https://github.com/libevent/libevent/archive/ 4 | $(package)_file_name=release-$($(package)_version)-rc.tar.gz 5 | $(package)_sha256_hash=548362d202e22fe24d4c3fad38287b4f6d683e6c21503341373b89785fa6f991 6 | 7 | define $(package)_preprocess_cmds 8 | ./autogen.sh 9 | endef 10 | 11 | define $(package)_set_vars 12 | $(package)_config_opts=--disable-shared --disable-openssl --disable-libevent-regress 13 | $(package)_config_opts_release=--disable-debug-mode 14 | $(package)_config_opts_linux=--with-pic 15 | endef 16 | 17 | define $(package)_config_cmds 18 | $($(package)_autoconf) 19 | endef 20 | 21 | define $(package)_build_cmds 22 | $(MAKE) 23 | endef 24 | 25 | define $(package)_stage_cmds 26 | $(MAKE) DESTDIR=$($(package)_staging_dir) install 27 | endef 28 | 29 | define $(package)_postprocess_cmds 30 | endef 31 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/.gitignore: -------------------------------------------------------------------------------- 1 | bench_inv 2 | bench_ecdh 3 | bench_sign 4 | bench_verify 5 | bench_schnorr_verify 6 | bench_recover 7 | bench_internal 8 | tests 9 | gen_context 10 | *.exe 11 | *.so 12 | *.a 13 | !.gitignore 14 | 15 | Makefile 16 | configure 17 | .libs/ 18 | Makefile.in 19 | aclocal.m4 20 | autom4te.cache/ 21 | config.log 22 | config.status 23 | *.tar.gz 24 | *.la 25 | libtool 26 | .deps/ 27 | .dirstamp 28 | *.lo 29 | *.o 30 | *~ 31 | src/libsecp256k1-config.h 32 | src/libsecp256k1-config.h.in 33 | src/ecmult_static_context.h 34 | build-aux/config.guess 35 | build-aux/config.sub 36 | build-aux/depcomp 37 | build-aux/install-sh 38 | build-aux/ltmain.sh 39 | build-aux/m4/libtool.m4 40 | build-aux/m4/lt~obsolete.m4 41 | build-aux/m4/ltoptions.m4 42 | build-aux/m4/ltsugar.m4 43 | build-aux/m4/ltversion.m4 44 | build-aux/missing 45 | build-aux/compile 46 | build-aux/test-driver 47 | src/stamp-h1 48 | libsecp256k1.pc 49 | -------------------------------------------------------------------------------- /src/leveldb/db/db_iter.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_DB_ITER_H_ 6 | #define STORAGE_LEVELDB_DB_DB_ITER_H_ 7 | 8 | #include 9 | #include "leveldb/db.h" 10 | #include "db/dbformat.h" 11 | 12 | namespace leveldb { 13 | 14 | class DBImpl; 15 | 16 | // Return a new iterator that converts internal keys (yielded by 17 | // "*internal_iter") that were live at the specified "sequence" number 18 | // into appropriate user keys. 19 | extern Iterator* NewDBIterator( 20 | DBImpl* db, 21 | const Comparator* user_key_comparator, 22 | Iterator* internal_iter, 23 | SequenceNumber sequence, 24 | uint32_t seed); 25 | 26 | } // namespace leveldb 27 | 28 | #endif // STORAGE_LEVELDB_DB_DB_ITER_H_ 29 | -------------------------------------------------------------------------------- /src/libbtc/test/buffer_tests.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Jonas Schnelli * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include "limits.h" 11 | 12 | #include 13 | 14 | void test_buffer() 15 | { 16 | struct const_buffer buf0 = {"data", 4}; 17 | struct const_buffer buf0a= {"data1", 5}; 18 | struct const_buffer buf1 = {"data", 4}; 19 | struct buffer* buf2; 20 | 21 | assert(buffer_equal(&buf0, &buf1) == 1); 22 | assert(buffer_equal(&buf0, &buf0a) == 0); 23 | 24 | buf2 = buffer_copy(&buf0.p, buf0.len); 25 | buffer_free(buf2); 26 | } 27 | -------------------------------------------------------------------------------- /src/leveldb/util/options.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/options.h" 6 | 7 | #include "leveldb/comparator.h" 8 | #include "leveldb/env.h" 9 | 10 | namespace leveldb { 11 | 12 | Options::Options() 13 | : comparator(BytewiseComparator()), 14 | create_if_missing(false), 15 | error_if_exists(false), 16 | paranoid_checks(false), 17 | env(Env::Default()), 18 | info_log(NULL), 19 | write_buffer_size(4<<20), 20 | max_open_files(1000), 21 | block_cache(NULL), 22 | block_size(4096), 23 | block_restart_interval(16), 24 | max_file_size(2<<20), 25 | compression(kSnappyCompression), 26 | reuse_logs(false), 27 | filter_policy(NULL) { 28 | } 29 | 30 | } // namespace leveldb 31 | -------------------------------------------------------------------------------- /src/leveldb/port/win/stdint.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // MSVC didn't ship with this file until the 2010 version. 6 | 7 | #ifndef STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 8 | #define STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 9 | 10 | #if !defined(_MSC_VER) 11 | #error This file should only be included when compiling with MSVC. 12 | #endif 13 | 14 | // Define C99 equivalent types. 15 | typedef signed char int8_t; 16 | typedef signed short int16_t; 17 | typedef signed int int32_t; 18 | typedef signed long long int64_t; 19 | typedef unsigned char uint8_t; 20 | typedef unsigned short uint16_t; 21 | typedef unsigned int uint32_t; 22 | typedef unsigned long long uint64_t; 23 | 24 | #endif // STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 25 | -------------------------------------------------------------------------------- /src/leveldb/table/merger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_MERGER_H_ 6 | #define STORAGE_LEVELDB_TABLE_MERGER_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Comparator; 11 | class Iterator; 12 | 13 | // Return an iterator that provided the union of the data in 14 | // children[0,n-1]. Takes ownership of the child iterators and 15 | // will delete them when the result iterator is deleted. 16 | // 17 | // The result does no duplicate suppression. I.e., if a particular 18 | // key is present in K child iterators, it will be yielded K times. 19 | // 20 | // REQUIRES: n >= 0 21 | extern Iterator* NewMergingIterator( 22 | const Comparator* comparator, Iterator** children, int n); 23 | 24 | } // namespace leveldb 25 | 26 | #endif // STORAGE_LEVELDB_TABLE_MERGER_H_ 27 | -------------------------------------------------------------------------------- /src/leveldb/include/leveldb/dumpfile.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 7 | 8 | #include 9 | #include "leveldb/env.h" 10 | #include "leveldb/status.h" 11 | 12 | namespace leveldb { 13 | 14 | // Dump the contents of the file named by fname in text format to 15 | // *dst. Makes a sequence of dst->Append() calls; each call is passed 16 | // the newline-terminated text corresponding to a single item found 17 | // in the file. 18 | // 19 | // Returns a non-OK result if fname does not name a leveldb storage 20 | // file, or if the file cannot be read. 21 | Status DumpFile(Env* env, const std::string& fname, WritableFile* dst); 22 | 23 | } // namespace leveldb 24 | 25 | #endif // STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 26 | -------------------------------------------------------------------------------- /src/leveldb/util/env_posix_test_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_ENV_POSIX_TEST_HELPER_H_ 6 | #define STORAGE_LEVELDB_UTIL_ENV_POSIX_TEST_HELPER_H_ 7 | 8 | namespace leveldb { 9 | 10 | class EnvPosixTest; 11 | 12 | // A helper for the POSIX Env to facilitate testing. 13 | class EnvPosixTestHelper { 14 | private: 15 | friend class EnvPosixTest; 16 | 17 | // Set the maximum number of read-only files that will be opened. 18 | // Must be called before creating an Env. 19 | static void SetReadOnlyFDLimit(int limit); 20 | 21 | // Set the maximum number of read-only files that will be mapped via mmap. 22 | // Must be called before creating an Env. 23 | static void SetReadOnlyMMapLimit(int limit); 24 | }; 25 | 26 | } // namespace leveldb 27 | 28 | #endif // STORAGE_LEVELDB_UTIL_ENV_POSIX_TEST_HELPER_H_ 29 | -------------------------------------------------------------------------------- /src/leveldb/db/log_format.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Log format information shared by reader and writer. 6 | // See ../doc/log_format.md for more detail. 7 | 8 | #ifndef STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 9 | #define STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 10 | 11 | namespace leveldb { 12 | namespace log { 13 | 14 | enum RecordType { 15 | // Zero is reserved for preallocated files 16 | kZeroType = 0, 17 | 18 | kFullType = 1, 19 | 20 | // For fragments 21 | kFirstType = 2, 22 | kMiddleType = 3, 23 | kLastType = 4 24 | }; 25 | static const int kMaxRecordType = kLastType; 26 | 27 | static const int kBlockSize = 32768; 28 | 29 | // Header is checksum (4 bytes), length (2 bytes), type (1 byte). 30 | static const int kHeaderSize = 4 + 2 + 1; 31 | 32 | } // namespace log 33 | } // namespace leveldb 34 | 35 | #endif // STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 36 | -------------------------------------------------------------------------------- /src/univalue/COPYING: -------------------------------------------------------------------------------- 1 | 2 | Permission is hereby granted, free of charge, to any person obtaining a copy 3 | of this software and associated documentation files (the "Software"), to deal 4 | in the Software without restriction, including without limitation the rights 5 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 6 | copies of the Software, and to permit persons to whom the Software is 7 | furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in 10 | all copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 18 | THE SOFTWARE. 19 | 20 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/basic-config.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_BASIC_CONFIG_ 8 | #define _SECP256K1_BASIC_CONFIG_ 9 | 10 | #ifdef USE_BASIC_CONFIG 11 | 12 | #undef USE_ASM_X86_64 13 | #undef USE_ENDOMORPHISM 14 | #undef USE_FIELD_10X26 15 | #undef USE_FIELD_5X52 16 | #undef USE_FIELD_INV_BUILTIN 17 | #undef USE_FIELD_INV_NUM 18 | #undef USE_NUM_GMP 19 | #undef USE_NUM_NONE 20 | #undef USE_SCALAR_4X64 21 | #undef USE_SCALAR_8X32 22 | #undef USE_SCALAR_INV_BUILTIN 23 | #undef USE_SCALAR_INV_NUM 24 | 25 | #define USE_NUM_NONE 1 26 | #define USE_FIELD_INV_BUILTIN 1 27 | #define USE_SCALAR_INV_BUILTIN 1 28 | #define USE_FIELD_10X26 1 29 | #define USE_SCALAR_8X32 1 30 | 31 | #endif // USE_BASIC_CONFIG 32 | #endif // _SECP256K1_BASIC_CONFIG_ 33 | -------------------------------------------------------------------------------- /src/leveldb/util/histogram.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 6 | #define STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | class Histogram { 13 | public: 14 | Histogram() { } 15 | ~Histogram() { } 16 | 17 | void Clear(); 18 | void Add(double value); 19 | void Merge(const Histogram& other); 20 | 21 | std::string ToString() const; 22 | 23 | private: 24 | double min_; 25 | double max_; 26 | double num_; 27 | double sum_; 28 | double sum_squares_; 29 | 30 | enum { kNumBuckets = 154 }; 31 | static const double kBucketLimit[kNumBuckets]; 32 | double buckets_[kNumBuckets]; 33 | 34 | double Median() const; 35 | double Percentile(double p) const; 36 | double Average() const; 37 | double StandardDeviation() const; 38 | }; 39 | 40 | } // namespace leveldb 41 | 42 | #endif // STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 43 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Pieter Wuille 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/include/secp256k1_ecdh.h: -------------------------------------------------------------------------------- 1 | #ifndef _SECP256K1_ECDH_ 2 | # define _SECP256K1_ECDH_ 3 | 4 | # include "secp256k1.h" 5 | 6 | # ifdef __cplusplus 7 | extern "C" { 8 | # endif 9 | 10 | /** Compute an EC Diffie-Hellman secret in constant time 11 | * Returns: 1: exponentiation was successful 12 | * 0: scalar was invalid (zero or overflow) 13 | * Args: ctx: pointer to a context object (cannot be NULL) 14 | * Out: result: a 32-byte array which will be populated by an ECDH 15 | * secret computed from the point and scalar 16 | * In: pubkey: a pointer to a secp256k1_pubkey containing an 17 | * initialized public key 18 | * privkey: a 32-byte scalar with which to multiply the point 19 | */ 20 | SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh( 21 | const secp256k1_context* ctx, 22 | unsigned char *result, 23 | const secp256k1_pubkey *pubkey, 24 | const unsigned char *privkey 25 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); 26 | 27 | # ifdef __cplusplus 28 | } 29 | # endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/libbtc/depends/builders/darwin.mk: -------------------------------------------------------------------------------- 1 | build_darwin_CC: = $(shell xcrun -f clang) 2 | build_darwin_CXX: = $(shell xcrun -f clang++) 3 | build_darwin_AR: = $(shell xcrun -f ar) 4 | build_darwin_RANLIB: = $(shell xcrun -f ranlib) 5 | build_darwin_STRIP: = $(shell xcrun -f strip) 6 | build_darwin_OTOOL: = $(shell xcrun -f otool) 7 | build_darwin_NM: = $(shell xcrun -f nm) 8 | build_darwin_INSTALL_NAME_TOOL:=$(shell xcrun -f install_name_tool) 9 | build_darwin_SHA256SUM = shasum -a 256 10 | build_darwin_DOWNLOAD = curl --location --fail --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -o 11 | 12 | #darwin host on darwin builder. overrides darwin host preferences. 13 | darwin_CC=$(shell xcrun -f clang) -mmacosx-version-min=$(OSX_MIN_VERSION) 14 | darwin_CXX:=$(shell xcrun -f clang++) -mmacosx-version-min=$(OSX_MIN_VERSION) -stdlib=libc++ 15 | darwin_AR:=$(shell xcrun -f ar) 16 | darwin_RANLIB:=$(shell xcrun -f ranlib) 17 | darwin_STRIP:=$(shell xcrun -f strip) 18 | darwin_LIBTOOL:=$(shell xcrun -f libtool) 19 | darwin_OTOOL:=$(shell xcrun -f otool) 20 | darwin_NM:=$(shell xcrun -f nm) 21 | darwin_INSTALL_NAME_TOOL:=$(shell xcrun -f install_name_tool) 22 | darwin_native_toolchain= 23 | -------------------------------------------------------------------------------- /src/libbtc/src/buffer.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2012 exMULTI, Inc. 2 | * Distributed under the MIT/X11 software license, see the accompanying 3 | * file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | int buffer_equal(const void* a_, const void* b_) 10 | { 11 | const struct buffer* a = a_; 12 | const struct buffer* b = b_; 13 | 14 | if (a->len != b->len) 15 | return 0; 16 | return memcmp(a->p, b->p, a->len) == 0; 17 | } 18 | 19 | void buffer_free(void* struct_buffer) 20 | { 21 | struct buffer* buf = struct_buffer; 22 | if (!buf) 23 | return; 24 | 25 | btc_free(buf->p); 26 | btc_free(buf); 27 | } 28 | 29 | struct buffer* buffer_copy(const void* data, size_t data_len) 30 | { 31 | struct buffer* buf; 32 | buf = btc_malloc(sizeof(*buf)); 33 | if (!buf) 34 | goto err_out; 35 | 36 | buf->p = btc_malloc(data_len); 37 | if (!buf->p) 38 | goto err_out_free; 39 | 40 | memcpy(buf->p, data, data_len); 41 | buf->len = data_len; 42 | 43 | return buf; 44 | 45 | err_out_free: 46 | btc_free(buf); 47 | err_out: 48 | return NULL; 49 | } 50 | -------------------------------------------------------------------------------- /src/libbtc/src/headersdb.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2017 Jonas Schnelli 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | -------------------------------------------------------------------------------- /src/libbtc/depends/hosts/default.mk: -------------------------------------------------------------------------------- 1 | default_host_CC = $(host_toolchain)gcc 2 | default_host_CXX = $(host_toolchain)g++ 3 | default_host_AR = $(host_toolchain)ar 4 | default_host_RANLIB = $(host_toolchain)ranlib 5 | default_host_STRIP = $(host_toolchain)strip 6 | default_host_LIBTOOL = $(host_toolchain)libtool 7 | default_host_INSTALL_NAME_TOOL = $(host_toolchain)install_name_tool 8 | default_host_OTOOL = $(host_toolchain)otool 9 | default_host_NM = $(host_toolchain)nm 10 | 11 | define add_host_tool_func 12 | $(host_os)_$1?=$$(default_host_$1) 13 | $(host_arch)_$(host_os)_$1?=$$($(host_os)_$1) 14 | $(host_arch)_$(host_os)_$(release_type)_$1?=$$($(host_os)_$1) 15 | host_$1=$$($(host_arch)_$(host_os)_$1) 16 | endef 17 | 18 | define add_host_flags_func 19 | $(host_arch)_$(host_os)_$1 += $($(host_os)_$1) 20 | $(host_arch)_$(host_os)_$(release_type)_$1 += $($(host_os)_$(release_type)_$1) 21 | host_$1 = $$($(host_arch)_$(host_os)_$1) 22 | host_$(release_type)_$1 = $$($(host_arch)_$(host_os)_$(release_type)_$1) 23 | endef 24 | 25 | $(foreach tool,CC CXX AR RANLIB STRIP NM LIBTOOL OTOOL INSTALL_NAME_TOOL,$(eval $(call add_host_tool_func,$(tool)))) 26 | $(foreach flags,CFLAGS CXXFLAGS CPPFLAGS LDFLAGS, $(eval $(call add_host_flags_func,$(flags)))) 27 | -------------------------------------------------------------------------------- /src/leveldb/table/block.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_H_ 7 | 8 | #include 9 | #include 10 | #include "leveldb/iterator.h" 11 | 12 | namespace leveldb { 13 | 14 | struct BlockContents; 15 | class Comparator; 16 | 17 | class Block { 18 | public: 19 | // Initialize the block with the specified contents. 20 | explicit Block(const BlockContents& contents); 21 | 22 | ~Block(); 23 | 24 | size_t size() const { return size_; } 25 | Iterator* NewIterator(const Comparator* comparator); 26 | 27 | private: 28 | uint32_t NumRestarts() const; 29 | 30 | const char* data_; 31 | size_t size_; 32 | uint32_t restart_offset_; // Offset in data_ of restart array 33 | bool owned_; // Block owns data_[] 34 | 35 | // No copying allowed 36 | Block(const Block&); 37 | void operator=(const Block&); 38 | 39 | class Iter; 40 | }; 41 | 42 | } // namespace leveldb 43 | 44 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_H_ 45 | -------------------------------------------------------------------------------- /src/leveldb/db/builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_BUILDER_H_ 6 | #define STORAGE_LEVELDB_DB_BUILDER_H_ 7 | 8 | #include "leveldb/status.h" 9 | 10 | namespace leveldb { 11 | 12 | struct Options; 13 | struct FileMetaData; 14 | 15 | class Env; 16 | class Iterator; 17 | class TableCache; 18 | class VersionEdit; 19 | 20 | // Build a Table file from the contents of *iter. The generated file 21 | // will be named according to meta->number. On success, the rest of 22 | // *meta will be filled with metadata about the generated table. 23 | // If no data is present in *iter, meta->file_size will be set to 24 | // zero, and no Table file will be produced. 25 | extern Status BuildTable(const std::string& dbname, 26 | Env* env, 27 | const Options& options, 28 | TableCache* table_cache, 29 | Iterator* iter, 30 | FileMetaData* meta); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_DB_BUILDER_H_ 35 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/ecdsa.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECDSA_ 8 | #define _SECP256K1_ECDSA_ 9 | 10 | #include 11 | 12 | #include "scalar.h" 13 | #include "group.h" 14 | #include "ecmult.h" 15 | 16 | static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size); 17 | static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s); 18 | static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context *ctx, const secp256k1_scalar* r, const secp256k1_scalar* s, const secp256k1_ge *pubkey, const secp256k1_scalar *message); 19 | static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/hash.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 The Bitcoin Core developers 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef BITCOINCORE_INDEXD_HASH_H 6 | #define BITCOINCORE_INDEXD_HASH_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class Hash256 { 14 | public: 15 | uint8_t m_data[32]; 16 | Hash256() { 17 | memset(m_data, 0, sizeof(m_data)); 18 | } 19 | Hash256(uint8_t *t) { 20 | memcpy(m_data, t, sizeof(m_data)); 21 | } 22 | inline std::string GetHex() const 23 | { 24 | return HexStr(std::reverse_iterator(m_data + sizeof(m_data)), std::reverse_iterator(m_data)); 25 | } 26 | inline int Compare(const Hash256& other) const { return memcmp(m_data, other.m_data, sizeof(m_data)); } 27 | friend inline bool operator==(const Hash256& a, const Hash256& b) { return a.Compare(b) == 0; } 28 | friend inline bool operator!=(const Hash256& a, const Hash256& b) { return a.Compare(b) != 0; } 29 | friend inline bool operator<(const Hash256& a, const Hash256& b) { return a.Compare(b) < 0; } 30 | }; 31 | 32 | #endif // BITCOINCORE_INDEXD_HASH_H 33 | -------------------------------------------------------------------------------- /src/libbtc/test/netspv_tests.c: -------------------------------------------------------------------------------- 1 | #include "utest.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | void test_spv_sync_completed(btc_spv_client* client) { 9 | printf("Sync completed, at height %d\n", client->headers_db->getchaintip(client->headers_db_ctx)->height); 10 | btc_node_group_shutdown(client->nodegroup); 11 | } 12 | 13 | btc_bool test_spv_header_message_processed(struct btc_spv_client_ *client, btc_node *node, btc_blockindex *newtip) { 14 | UNUSED(client); 15 | UNUSED(node); 16 | if (newtip) { 17 | printf("New headers tip height %d\n", newtip->height); 18 | } 19 | return true; 20 | } 21 | 22 | void test_netspv() 23 | { 24 | unlink("headers.db"); 25 | btc_spv_client* client = btc_spv_client_new(&btc_chainparams_main, true, false); 26 | client->header_message_processed = test_spv_header_message_processed; 27 | client->sync_completed = test_spv_sync_completed; 28 | 29 | btc_spv_client_load(client, "headers.db"); 30 | 31 | printf("Discover peers..."); 32 | btc_spv_client_discover_peers(client, NULL); 33 | printf("done\n"); 34 | printf("Start interacting with the p2p network...\n"); 35 | btc_spv_client_runloop(client); 36 | btc_spv_client_free(client); 37 | } 38 | -------------------------------------------------------------------------------- /src/leveldb/WINDOWS.md: -------------------------------------------------------------------------------- 1 | # Building LevelDB On Windows 2 | 3 | ## Prereqs 4 | 5 | Install the [Windows Software Development Kit version 7.1](http://www.microsoft.com/downloads/dlx/en-us/listdetailsview.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b). 6 | 7 | Download and extract the [Snappy source distribution](http://snappy.googlecode.com/files/snappy-1.0.5.tar.gz) 8 | 9 | 1. Open the "Windows SDK 7.1 Command Prompt" : 10 | Start Menu -> "Microsoft Windows SDK v7.1" > "Windows SDK 7.1 Command Prompt" 11 | 2. Change the directory to the leveldb project 12 | 13 | ## Building the Static lib 14 | 15 | * 32 bit Version 16 | 17 | setenv /x86 18 | msbuild.exe /p:Configuration=Release /p:Platform=Win32 /p:Snappy=..\snappy-1.0.5 19 | 20 | * 64 bit Version 21 | 22 | setenv /x64 23 | msbuild.exe /p:Configuration=Release /p:Platform=x64 /p:Snappy=..\snappy-1.0.5 24 | 25 | 26 | ## Building and Running the Benchmark app 27 | 28 | * 32 bit Version 29 | 30 | setenv /x86 31 | msbuild.exe /p:Configuration=Benchmark /p:Platform=Win32 /p:Snappy=..\snappy-1.0.5 32 | Benchmark\leveldb.exe 33 | 34 | * 64 bit Version 35 | 36 | setenv /x64 37 | msbuild.exe /p:Configuration=Benchmark /p:Platform=x64 /p:Snappy=..\snappy-1.0.5 38 | x64\Benchmark\leveldb.exe 39 | 40 | -------------------------------------------------------------------------------- /src/leveldb/util/mutexlock.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 6 | #define STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 7 | 8 | #include "port/port.h" 9 | #include "port/thread_annotations.h" 10 | 11 | namespace leveldb { 12 | 13 | // Helper class that locks a mutex on construction and unlocks the mutex when 14 | // the destructor of the MutexLock object is invoked. 15 | // 16 | // Typical usage: 17 | // 18 | // void MyClass::MyMethod() { 19 | // MutexLock l(&mu_); // mu_ is an instance variable 20 | // ... some complex code, possibly with multiple return paths ... 21 | // } 22 | 23 | class SCOPED_LOCKABLE MutexLock { 24 | public: 25 | explicit MutexLock(port::Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu) 26 | : mu_(mu) { 27 | this->mu_->Lock(); 28 | } 29 | ~MutexLock() UNLOCK_FUNCTION() { this->mu_->Unlock(); } 30 | 31 | private: 32 | port::Mutex *const mu_; 33 | // No copying allowed 34 | MutexLock(const MutexLock&); 35 | void operator=(const MutexLock&); 36 | }; 37 | 38 | } // namespace leveldb 39 | 40 | 41 | #endif // STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 42 | -------------------------------------------------------------------------------- /src/libbtc/test/hash_tests.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Jonas Schnelli * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | void test_bitcoin_hash() 18 | { 19 | const char data[] = "cea946542b91ca50e2afecba73cf546ce1383d82668ecb6265f79ffaa07daa49abb43e21a19c6b2b15c8882b4bc01085a8a5b00168139dcb8f4b2bbe22929ce196d43532898d98a3b0ea4d63112ba25e724bb50711e3cf55954cf30b4503b73d785253104c2df8c19b5b63e92bd6b1ff2573751ec9c508085f3f206c719aa4643776bf425344348cbf63f1450389"; 20 | 21 | const char expected[] = "52aa8dd6c598d91d580cc446624909e52a076064ffab67a1751f5758c9f76d26"; 22 | uint256* digest_expected; 23 | digest_expected = (uint256*)utils_hex_to_uint8(expected); 24 | 25 | uint256 hashout; 26 | btc_hash((const unsigned char *)data, strlen(data), hashout); 27 | assert(memcmp(hashout, digest_expected, sizeof(hashout)) == 0); 28 | } 29 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/eckey.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECKEY_ 8 | #define _SECP256K1_ECKEY_ 9 | 10 | #include 11 | 12 | #include "group.h" 13 | #include "scalar.h" 14 | #include "ecmult.h" 15 | #include "ecmult_gen.h" 16 | 17 | static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size); 18 | static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed); 19 | 20 | static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak); 21 | static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak); 22 | static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak); 23 | static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/leveldb/table/two_level_iterator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 6 | #define STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 7 | 8 | #include "leveldb/iterator.h" 9 | 10 | namespace leveldb { 11 | 12 | struct ReadOptions; 13 | 14 | // Return a new two level iterator. A two-level iterator contains an 15 | // index iterator whose values point to a sequence of blocks where 16 | // each block is itself a sequence of key,value pairs. The returned 17 | // two-level iterator yields the concatenation of all key/value pairs 18 | // in the sequence of blocks. Takes ownership of "index_iter" and 19 | // will delete it when no longer needed. 20 | // 21 | // Uses a supplied function to convert an index_iter value into 22 | // an iterator over the contents of the corresponding block. 23 | extern Iterator* NewTwoLevelIterator( 24 | Iterator* index_iter, 25 | Iterator* (*block_function)( 26 | void* arg, 27 | const ReadOptions& options, 28 | const Slice& index_value), 29 | void* arg, 30 | const ReadOptions& options); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 35 | -------------------------------------------------------------------------------- /src/libbtc/src/ripemd160.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013-2014 Tomas Dzetkulic 3 | * Copyright (c) 2013-2014 Pavol Rusnak 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 19 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 | * OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | #ifndef __RIPEMD160_H__ 26 | #define __RIPEMD160_H__ 27 | 28 | #include 29 | 30 | void ripemd160(const uint8_t* msg, uint32_t msg_len, uint8_t* hash); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/libbtc/test/random_tests.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Jonas Schnelli * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include 8 | 9 | #include "utest.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | void test_random_init_cb(void) 17 | { 18 | 19 | } 20 | 21 | 22 | btc_bool test_random_bytes_cb(uint8_t* buf, uint32_t len, const uint8_t update_seed) { 23 | 24 | (void)(update_seed); 25 | for (uint32_t i = 0; i < len; i++) { 26 | buf[i] = 0; 27 | } 28 | return false; 29 | } 30 | 31 | void test_random() 32 | { 33 | unsigned char r_buf[32]; 34 | memset(r_buf, 0, 32); 35 | btc_random_init(); 36 | u_assert_int_eq(btc_random_bytes(r_buf, 32, 0), true); 37 | 38 | btc_rnd_mapper mymapper = {test_random_init_cb, test_random_bytes_cb}; 39 | btc_rnd_set_mapper(mymapper); 40 | 41 | u_assert_int_eq(btc_random_bytes(r_buf, 32, 0), false); 42 | 43 | for (uint8_t i = 0; i < 32; i++) { 44 | u_assert_int_eq(r_buf[i], 0); 45 | } 46 | 47 | // switch back to the default random callback mapper 48 | btc_rnd_set_mapper_default(); 49 | } 50 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/modules/schnorr/schnorr.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Copyright (c) 2014-2015 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php. * 5 | ***********************************************************************/ 6 | 7 | #ifndef _SECP256K1_MODULE_SCHNORR_H_ 8 | #define _SECP256K1_MODULE_SCHNORR_H_ 9 | 10 | #include "scalar.h" 11 | #include "group.h" 12 | 13 | typedef void (*secp256k1_schnorr_msghash)(unsigned char *h32, const unsigned char *r32, const unsigned char *msg32); 14 | 15 | static int secp256k1_schnorr_sig_sign(const secp256k1_ecmult_gen_context* ctx, unsigned char *sig64, const secp256k1_scalar *key, const secp256k1_scalar *nonce, const secp256k1_ge *pubnonce, secp256k1_schnorr_msghash hash, const unsigned char *msg32); 16 | static int secp256k1_schnorr_sig_verify(const secp256k1_ecmult_context* ctx, const unsigned char *sig64, const secp256k1_ge *pubkey, secp256k1_schnorr_msghash hash, const unsigned char *msg32); 17 | static int secp256k1_schnorr_sig_recover(const secp256k1_ecmult_context* ctx, const unsigned char *sig64, secp256k1_ge *pubkey, secp256k1_schnorr_msghash hash, const unsigned char *msg32); 18 | static int secp256k1_schnorr_sig_combine(unsigned char *sig64, size_t n, const unsigned char * const *sig64ins); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/univalue/.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | compiler: 4 | - clang 5 | - gcc 6 | 7 | os: 8 | - linux 9 | - osx 10 | 11 | sudo: false 12 | 13 | env: 14 | global: 15 | - MAKEJOBS=-j3 16 | - RUN_TESTS=true 17 | - BASE_OUTDIR=$TRAVIS_BUILD_DIR/out 18 | 19 | cache: 20 | apt: true 21 | 22 | addons: 23 | apt: 24 | packages: 25 | - pkg-config 26 | 27 | before_script: 28 | - if [ -n "$USE_SHELL" ]; then export CONFIG_SHELL="$USE_SHELL"; fi 29 | - test -n "$USE_SHELL" && eval '"$USE_SHELL" -c "./autogen.sh"' || ./autogen.sh 30 | 31 | script: 32 | - if [ -n "$UNIVALUE_CONFIG" ]; then unset CC; unset CXX; fi 33 | - OUTDIR=$BASE_OUTDIR/$TRAVIS_PULL_REQUEST/$TRAVIS_JOB_NUMBER-$HOST 34 | - UNIVALUE_CONFIG_ALL="--prefix=$TRAVIS_BUILD_DIR/depends/$HOST --bindir=$OUTDIR/bin --libdir=$OUTDIR/lib" 35 | - ./configure --cache-file=config.cache $UNIVALUE_CONFIG_ALL $UNIVALUE_CONFIG || ( cat config.log && false) 36 | - make -s $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL ; false ) 37 | - export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib 38 | - if [ "$RUN_TESTS" = "true" ]; then make $MAKEJOBS distcheck; fi 39 | 40 | matrix: 41 | fast_finish: true 42 | include: 43 | - os: linux 44 | compiler: gcc 45 | env: UNIVALUE_CONFIG=--host=x86_64-w64-mingw32 RUN_TESTS=false 46 | addons: 47 | apt: 48 | packages: 49 | - g++-mingw-w64-x86-64 50 | - gcc-mingw-w64-x86-64 51 | - binutils-mingw-w64-x86-64 52 | -------------------------------------------------------------------------------- /src/leveldb/db/version_edit_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "db/version_edit.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | static void TestEncodeDecode(const VersionEdit& edit) { 11 | std::string encoded, encoded2; 12 | edit.EncodeTo(&encoded); 13 | VersionEdit parsed; 14 | Status s = parsed.DecodeFrom(encoded); 15 | ASSERT_TRUE(s.ok()) << s.ToString(); 16 | parsed.EncodeTo(&encoded2); 17 | ASSERT_EQ(encoded, encoded2); 18 | } 19 | 20 | class VersionEditTest { }; 21 | 22 | TEST(VersionEditTest, EncodeDecode) { 23 | static const uint64_t kBig = 1ull << 50; 24 | 25 | VersionEdit edit; 26 | for (int i = 0; i < 4; i++) { 27 | TestEncodeDecode(edit); 28 | edit.AddFile(3, kBig + 300 + i, kBig + 400 + i, 29 | InternalKey("foo", kBig + 500 + i, kTypeValue), 30 | InternalKey("zoo", kBig + 600 + i, kTypeDeletion)); 31 | edit.DeleteFile(4, kBig + 700 + i); 32 | edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue)); 33 | } 34 | 35 | edit.SetComparatorName("foo"); 36 | edit.SetLogNumber(kBig + 100); 37 | edit.SetNextFile(kBig + 200); 38 | edit.SetLastSequence(kBig + 1000); 39 | TestEncodeDecode(edit); 40 | } 41 | 42 | } // namespace leveldb 43 | 44 | int main(int argc, char** argv) { 45 | return leveldb::test::RunAllTests(); 46 | } 47 | -------------------------------------------------------------------------------- /src/dbinterface.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 The Bitcoin Core developers 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef BITCOINCORE_INDEXD_DBINTERFACE_H 6 | #define BITCOINCORE_INDEXD_DBINTERFACE_H 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | //! Interface for the database 15 | class IndexDatabaseInterface 16 | { 17 | public: 18 | virtual ~IndexDatabaseInterface() {} 19 | 20 | virtual bool close() = 0; 21 | 22 | // loads the blockmap table (maps internal-blockhash-key to blockhash) 23 | virtual bool loadBlockMap(std::map& blockhash_map, std::map& blockhash_map_rev, unsigned int &counter) = 0; 24 | 25 | // writes an tx index entry 26 | virtual bool putTxIndex(const uint8_t* key, unsigned int key_len, const uint8_t* value, unsigned int value_len, bool avoid_flush = false) = 0; 27 | 28 | // writes an blockmap-key entry 29 | virtual bool putBlockMap(const uint8_t* key, unsigned int key_len, const uint8_t* value, unsigned int value_len) = 0; 30 | 31 | // loopup a txid and writes back its blockhash. Returns true if found or false if not found 32 | virtual bool lookupTXID(const uint8_t* key, unsigned int key_len, Hash256& blockhash) = 0; 33 | 34 | // flush the database if flush requirements are given 35 | virtual bool flush(bool force = false) = 0; 36 | }; 37 | 38 | #endif // BITCOINCORE_INDEXD_DBINTERFACE_H 39 | -------------------------------------------------------------------------------- /src/leveldb/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /src/leveldb/util/hash.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "util/coding.h" 7 | #include "util/hash.h" 8 | 9 | // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through 10 | // between switch labels. The real definition should be provided externally. 11 | // This one is a fallback version for unsupported compilers. 12 | #ifndef FALLTHROUGH_INTENDED 13 | #define FALLTHROUGH_INTENDED do { } while (0) 14 | #endif 15 | 16 | namespace leveldb { 17 | 18 | uint32_t Hash(const char* data, size_t n, uint32_t seed) { 19 | // Similar to murmur hash 20 | const uint32_t m = 0xc6a4a793; 21 | const uint32_t r = 24; 22 | const char* limit = data + n; 23 | uint32_t h = seed ^ (n * m); 24 | 25 | // Pick up four bytes at a time 26 | while (data + 4 <= limit) { 27 | uint32_t w = DecodeFixed32(data); 28 | data += 4; 29 | h += w; 30 | h *= m; 31 | h ^= (h >> 16); 32 | } 33 | 34 | // Pick up remaining bytes 35 | switch (limit - data) { 36 | case 3: 37 | h += static_cast(data[2]) << 16; 38 | FALLTHROUGH_INTENDED; 39 | case 2: 40 | h += static_cast(data[1]) << 8; 41 | FALLTHROUGH_INTENDED; 42 | case 1: 43 | h += static_cast(data[0]); 44 | h *= m; 45 | h ^= (h >> r); 46 | break; 47 | } 48 | return h; 49 | } 50 | 51 | 52 | } // namespace leveldb 53 | -------------------------------------------------------------------------------- /src/leveldb/util/logging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Must not be included from any .h files to avoid polluting the namespace 6 | // with macros. 7 | 8 | #ifndef STORAGE_LEVELDB_UTIL_LOGGING_H_ 9 | #define STORAGE_LEVELDB_UTIL_LOGGING_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "port/port.h" 15 | 16 | namespace leveldb { 17 | 18 | class Slice; 19 | class WritableFile; 20 | 21 | // Append a human-readable printout of "num" to *str 22 | extern void AppendNumberTo(std::string* str, uint64_t num); 23 | 24 | // Append a human-readable printout of "value" to *str. 25 | // Escapes any non-printable characters found in "value". 26 | extern void AppendEscapedStringTo(std::string* str, const Slice& value); 27 | 28 | // Return a human-readable printout of "num" 29 | extern std::string NumberToString(uint64_t num); 30 | 31 | // Return a human-readable version of "value". 32 | // Escapes any non-printable characters found in "value". 33 | extern std::string EscapeString(const Slice& value); 34 | 35 | // Parse a human-readable number from "*in" into *value. On success, 36 | // advances "*in" past the consumed number and sets "*val" to the 37 | // numeric value. Otherwise, returns false and leaves *in in an 38 | // unspecified state. 39 | extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val); 40 | 41 | } // namespace leveldb 42 | 43 | #endif // STORAGE_LEVELDB_UTIL_LOGGING_H_ 44 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/ecmult.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECMULT_ 8 | #define _SECP256K1_ECMULT_ 9 | 10 | #include "num.h" 11 | #include "group.h" 12 | 13 | typedef struct { 14 | /* For accelerating the computation of a*P + b*G: */ 15 | secp256k1_ge_storage (*pre_g)[]; /* odd multiples of the generator */ 16 | #ifdef USE_ENDOMORPHISM 17 | secp256k1_ge_storage (*pre_g_128)[]; /* odd multiples of 2^128*generator */ 18 | #endif 19 | } secp256k1_ecmult_context; 20 | 21 | static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx); 22 | static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, const secp256k1_callback *cb); 23 | static void secp256k1_ecmult_context_clone(secp256k1_ecmult_context *dst, 24 | const secp256k1_ecmult_context *src, const secp256k1_callback *cb); 25 | static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context *ctx); 26 | static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx); 27 | 28 | /** Double multiply: R = na*A + ng*G */ 29 | static void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/leveldb/port/thread_annotations.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 6 | #define STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 7 | 8 | // Some environments provide custom macros to aid in static thread-safety 9 | // analysis. Provide empty definitions of such macros unless they are already 10 | // defined. 11 | 12 | #ifndef EXCLUSIVE_LOCKS_REQUIRED 13 | #define EXCLUSIVE_LOCKS_REQUIRED(...) 14 | #endif 15 | 16 | #ifndef SHARED_LOCKS_REQUIRED 17 | #define SHARED_LOCKS_REQUIRED(...) 18 | #endif 19 | 20 | #ifndef LOCKS_EXCLUDED 21 | #define LOCKS_EXCLUDED(...) 22 | #endif 23 | 24 | #ifndef LOCK_RETURNED 25 | #define LOCK_RETURNED(x) 26 | #endif 27 | 28 | #ifndef LOCKABLE 29 | #define LOCKABLE 30 | #endif 31 | 32 | #ifndef SCOPED_LOCKABLE 33 | #define SCOPED_LOCKABLE 34 | #endif 35 | 36 | #ifndef EXCLUSIVE_LOCK_FUNCTION 37 | #define EXCLUSIVE_LOCK_FUNCTION(...) 38 | #endif 39 | 40 | #ifndef SHARED_LOCK_FUNCTION 41 | #define SHARED_LOCK_FUNCTION(...) 42 | #endif 43 | 44 | #ifndef EXCLUSIVE_TRYLOCK_FUNCTION 45 | #define EXCLUSIVE_TRYLOCK_FUNCTION(...) 46 | #endif 47 | 48 | #ifndef SHARED_TRYLOCK_FUNCTION 49 | #define SHARED_TRYLOCK_FUNCTION(...) 50 | #endif 51 | 52 | #ifndef UNLOCK_FUNCTION 53 | #define UNLOCK_FUNCTION(...) 54 | #endif 55 | 56 | #ifndef NO_THREAD_SAFETY_ANALYSIS 57 | #define NO_THREAD_SAFETY_ANALYSIS 58 | #endif 59 | 60 | #endif // STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 61 | -------------------------------------------------------------------------------- /src/libbtc/include/btc/blockchain.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Libbtc Developers 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #ifndef __LIBBTC_BLOCKCHAIN_H__ 28 | #define __LIBBTC_BLOCKCHAIN_H__ 29 | 30 | #include "btc.h" 31 | #include "block.h" 32 | 33 | LIBBTC_BEGIN_DECL 34 | 35 | typedef struct btc_blockindex { 36 | uint32_t height; 37 | uint256 hash; 38 | btc_block_header header; 39 | struct btc_blockindex* prev; 40 | } btc_blockindex; 41 | 42 | LIBBTC_END_DECL 43 | 44 | #endif // __LIBBTC_BLOCKCHAIN_H__ 45 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/testrand.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_TESTRAND_H_ 8 | #define _SECP256K1_TESTRAND_H_ 9 | 10 | #if defined HAVE_CONFIG_H 11 | #include "libsecp256k1-config.h" 12 | #endif 13 | 14 | /* A non-cryptographic RNG used only for test infrastructure. */ 15 | 16 | /** Seed the pseudorandom number generator for testing. */ 17 | SECP256K1_INLINE static void secp256k1_rand_seed(const unsigned char *seed16); 18 | 19 | /** Generate a pseudorandom number in the range [0..2**32-1]. */ 20 | static uint32_t secp256k1_rand32(void); 21 | 22 | /** Generate a pseudorandom number in the range [0..2**bits-1]. Bits must be 1 or 23 | * more. */ 24 | static uint32_t secp256k1_rand_bits(int bits); 25 | 26 | /** Generate a pseudorandom number in the range [0..range-1]. */ 27 | static uint32_t secp256k1_rand_int(uint32_t range); 28 | 29 | /** Generate a pseudorandom 32-byte array. */ 30 | static void secp256k1_rand256(unsigned char *b32); 31 | 32 | /** Generate a pseudorandom 32-byte array with long sequences of zero and one bits. */ 33 | static void secp256k1_rand256_test(unsigned char *b32); 34 | 35 | /** Generate pseudorandom bytes with long sequences of zero and one bits. */ 36 | static void secp256k1_rand_bytes_test(unsigned char *bytes, size_t len); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/leveldb/util/crc32c.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_CRC32C_H_ 6 | #define STORAGE_LEVELDB_UTIL_CRC32C_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace leveldb { 12 | namespace crc32c { 13 | 14 | // Return the crc32c of concat(A, data[0,n-1]) where init_crc is the 15 | // crc32c of some string A. Extend() is often used to maintain the 16 | // crc32c of a stream of data. 17 | extern uint32_t Extend(uint32_t init_crc, const char* data, size_t n); 18 | 19 | // Return the crc32c of data[0,n-1] 20 | inline uint32_t Value(const char* data, size_t n) { 21 | return Extend(0, data, n); 22 | } 23 | 24 | static const uint32_t kMaskDelta = 0xa282ead8ul; 25 | 26 | // Return a masked representation of crc. 27 | // 28 | // Motivation: it is problematic to compute the CRC of a string that 29 | // contains embedded CRCs. Therefore we recommend that CRCs stored 30 | // somewhere (e.g., in files) should be masked before being stored. 31 | inline uint32_t Mask(uint32_t crc) { 32 | // Rotate right by 15 bits and add a constant. 33 | return ((crc >> 15) | (crc << 17)) + kMaskDelta; 34 | } 35 | 36 | // Return the crc whose masked representation is masked_crc. 37 | inline uint32_t Unmask(uint32_t masked_crc) { 38 | uint32_t rot = masked_crc - kMaskDelta; 39 | return ((rot >> 17) | (rot << 15)); 40 | } 41 | 42 | } // namespace crc32c 43 | } // namespace leveldb 44 | 45 | #endif // STORAGE_LEVELDB_UTIL_CRC32C_H_ 46 | -------------------------------------------------------------------------------- /src/libbtc/test/memory_tests.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Jonas Schnelli * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include 8 | 9 | #include "utest.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | void* test_memory_malloc(size_t size) 17 | { 18 | (void)(size); 19 | 20 | return NULL; 21 | } 22 | 23 | void* test_memory_calloc(size_t count, size_t size) 24 | { 25 | (void)(count); 26 | (void)(size); 27 | 28 | return NULL; 29 | } 30 | 31 | void* test_memory_realloc(void *ptr, size_t size) 32 | { 33 | (void)(ptr); 34 | (void)(size); 35 | 36 | return NULL; 37 | } 38 | 39 | void test_memory_free(void *ptr) 40 | { 41 | free(ptr); 42 | } 43 | 44 | 45 | void test_memory() 46 | { 47 | btc_mem_mapper mymapper = {test_memory_malloc, test_memory_calloc, test_memory_realloc, test_memory_free}; 48 | btc_mem_set_mapper(mymapper); 49 | 50 | void *ptr = btc_malloc(32); 51 | u_assert_int_eq((ptr == NULL), 1); 52 | ptr = btc_calloc(32, 1); 53 | u_assert_int_eq((ptr == NULL), 1); 54 | 55 | void *buf = malloc(100); 56 | void *obuf = buf; 57 | ptr = btc_realloc(buf, 1000); 58 | u_assert_int_eq((ptr == NULL), 1); 59 | free(obuf); 60 | // switch back to the default memory callback mapper 61 | btc_mem_set_mapper_default(); 62 | } 63 | -------------------------------------------------------------------------------- /src/leveldb/util/testutil.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/testutil.h" 6 | 7 | #include "util/random.h" 8 | 9 | namespace leveldb { 10 | namespace test { 11 | 12 | Slice RandomString(Random* rnd, int len, std::string* dst) { 13 | dst->resize(len); 14 | for (int i = 0; i < len; i++) { 15 | (*dst)[i] = static_cast(' ' + rnd->Uniform(95)); // ' ' .. '~' 16 | } 17 | return Slice(*dst); 18 | } 19 | 20 | std::string RandomKey(Random* rnd, int len) { 21 | // Make sure to generate a wide variety of characters so we 22 | // test the boundary conditions for short-key optimizations. 23 | static const char kTestChars[] = { 24 | '\0', '\1', 'a', 'b', 'c', 'd', 'e', '\xfd', '\xfe', '\xff' 25 | }; 26 | std::string result; 27 | for (int i = 0; i < len; i++) { 28 | result += kTestChars[rnd->Uniform(sizeof(kTestChars))]; 29 | } 30 | return result; 31 | } 32 | 33 | 34 | extern Slice CompressibleString(Random* rnd, double compressed_fraction, 35 | size_t len, std::string* dst) { 36 | int raw = static_cast(len * compressed_fraction); 37 | if (raw < 1) raw = 1; 38 | std::string raw_data; 39 | RandomString(rnd, raw, &raw_data); 40 | 41 | // Duplicate the random data until we have filled "len" bytes 42 | dst->clear(); 43 | while (dst->size() < len) { 44 | dst->append(raw_data); 45 | } 46 | dst->resize(len); 47 | return Slice(*dst); 48 | } 49 | 50 | } // namespace test 51 | } // namespace leveldb 52 | -------------------------------------------------------------------------------- /src/univalue/test/pass1.json: -------------------------------------------------------------------------------- 1 | [ 2 | "JSON Test Pattern pass1", 3 | {"object with 1 member":["array with 1 element"]}, 4 | {}, 5 | [], 6 | -42, 7 | true, 8 | false, 9 | null, 10 | { 11 | "integer": 1234567890, 12 | "real": -9876.543210, 13 | "e": 0.123456789e-12, 14 | "E": 1.234567890E+34, 15 | "": 23456789012E66, 16 | "zero": 0, 17 | "one": 1, 18 | "space": " ", 19 | "quote": "\"", 20 | "backslash": "\\", 21 | "controls": "\b\f\n\r\t", 22 | "slash": "/ & \/", 23 | "alpha": "abcdefghijklmnopqrstuvwyz", 24 | "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", 25 | "digit": "0123456789", 26 | "0123456789": "digit", 27 | "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", 28 | "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", 29 | "true": true, 30 | "false": false, 31 | "null": null, 32 | "array":[ ], 33 | "object":{ }, 34 | "address": "50 St. James Street", 35 | "url": "http://www.JSON.org/", 36 | "comment": "// /* */": " ", 38 | " s p a c e d " :[1,2 , 3 39 | 40 | , 41 | 42 | 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], 43 | "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", 44 | "quotes": "" \u0022 %22 0x22 034 "", 45 | "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" 46 | : "A key can be any string" 47 | }, 48 | 0.5 ,98.6 49 | , 50 | 99.44 51 | , 52 | 53 | 1066, 54 | 1e1, 55 | 0.1e1, 56 | 1e-1, 57 | 1e00,2e+00,2e-00 58 | ,"rosebud"] -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.tar.gz 2 | 3 | *.exe 4 | src/bitcoincore-indexd 5 | 6 | # autoreconf 7 | Makefile.in 8 | aclocal.m4 9 | autom4te.cache/ 10 | build-aux/config.guess 11 | build-aux/config.sub 12 | build-aux/depcomp 13 | build-aux/install-sh 14 | build-aux/ltmain.sh 15 | build-aux/m4/libtool.m4 16 | build-aux/m4/lt~obsolete.m4 17 | build-aux/m4/ltoptions.m4 18 | build-aux/m4/ltsugar.m4 19 | build-aux/m4/ltversion.m4 20 | build-aux/missing 21 | build-aux/compile 22 | build-aux/test-driver 23 | config.log 24 | config.status 25 | configure 26 | libtool 27 | src/config/application-config.h 28 | src/config/application-config.h.in 29 | src/config/stamp-h1 30 | share/setup.nsi 31 | share/qt/Info.plist 32 | 33 | src/univalue/gen 34 | 35 | src/qt/*.moc 36 | src/qt/moc_*.cpp 37 | src/qt/forms/ui_*.h 38 | 39 | src/qt/test/moc*.cpp 40 | 41 | .deps 42 | .dirstamp 43 | .libs 44 | .*.swp 45 | *.*~* 46 | *.bak 47 | *.rej 48 | *.orig 49 | *.pyc 50 | *.o 51 | *.o-* 52 | *.patch 53 | *.a 54 | *.pb.cc 55 | *.pb.h 56 | 57 | *.log 58 | *.trs 59 | *.dmg 60 | 61 | *.json.h 62 | *.raw.h 63 | 64 | #libtool object files 65 | *.lo 66 | *.la 67 | 68 | # Compilation and Qt preprocessor part 69 | *.qm 70 | Makefile 71 | Application.app 72 | background.tiff* 73 | 74 | # Unit-tests 75 | Makefile.test 76 | 77 | # Resources cpp 78 | qrc_*.cpp 79 | 80 | # Mac specific 81 | .DS_Store 82 | build 83 | 84 | #lcov 85 | *.gcno 86 | *.gcda 87 | /*.info 88 | total.coverage/ 89 | coverage_percent.txt 90 | 91 | #build tests 92 | linux-coverage-build 93 | linux-build 94 | win32-build 95 | test/config.ini 96 | test/cache/* 97 | 98 | /doc/doxygen/ 99 | 100 | contrib/devtools/split-debug.sh 101 | -------------------------------------------------------------------------------- /src/leveldb/db/log_writer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_ 6 | #define STORAGE_LEVELDB_DB_LOG_WRITER_H_ 7 | 8 | #include 9 | #include "db/log_format.h" 10 | #include "leveldb/slice.h" 11 | #include "leveldb/status.h" 12 | 13 | namespace leveldb { 14 | 15 | class WritableFile; 16 | 17 | namespace log { 18 | 19 | class Writer { 20 | public: 21 | // Create a writer that will append data to "*dest". 22 | // "*dest" must be initially empty. 23 | // "*dest" must remain live while this Writer is in use. 24 | explicit Writer(WritableFile* dest); 25 | 26 | // Create a writer that will append data to "*dest". 27 | // "*dest" must have initial length "dest_length". 28 | // "*dest" must remain live while this Writer is in use. 29 | Writer(WritableFile* dest, uint64_t dest_length); 30 | 31 | ~Writer(); 32 | 33 | Status AddRecord(const Slice& slice); 34 | 35 | private: 36 | WritableFile* dest_; 37 | int block_offset_; // Current offset in block 38 | 39 | // crc32c values for all supported record types. These are 40 | // pre-computed to reduce the overhead of computing the crc of the 41 | // record type stored in the header. 42 | uint32_t type_crc_[kMaxRecordType + 1]; 43 | 44 | Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length); 45 | 46 | // No copying allowed 47 | Writer(const Writer&); 48 | void operator=(const Writer&); 49 | }; 50 | 51 | } // namespace log 52 | } // namespace leveldb 53 | 54 | #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_ 55 | -------------------------------------------------------------------------------- /src/leveldb/db/write_batch_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 6 | #define STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 7 | 8 | #include "db/dbformat.h" 9 | #include "leveldb/write_batch.h" 10 | 11 | namespace leveldb { 12 | 13 | class MemTable; 14 | 15 | // WriteBatchInternal provides static methods for manipulating a 16 | // WriteBatch that we don't want in the public WriteBatch interface. 17 | class WriteBatchInternal { 18 | public: 19 | // Return the number of entries in the batch. 20 | static int Count(const WriteBatch* batch); 21 | 22 | // Set the count for the number of entries in the batch. 23 | static void SetCount(WriteBatch* batch, int n); 24 | 25 | // Return the sequence number for the start of this batch. 26 | static SequenceNumber Sequence(const WriteBatch* batch); 27 | 28 | // Store the specified number as the sequence number for the start of 29 | // this batch. 30 | static void SetSequence(WriteBatch* batch, SequenceNumber seq); 31 | 32 | static Slice Contents(const WriteBatch* batch) { 33 | return Slice(batch->rep_); 34 | } 35 | 36 | static size_t ByteSize(const WriteBatch* batch) { 37 | return batch->rep_.size(); 38 | } 39 | 40 | static void SetContents(WriteBatch* batch, const Slice& contents); 41 | 42 | static Status InsertInto(const WriteBatch* batch, MemTable* memtable); 43 | 44 | static void Append(WriteBatch* dst, const WriteBatch* src); 45 | }; 46 | 47 | } // namespace leveldb 48 | 49 | 50 | #endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 51 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/java/org/bitcoin/NativeSecp256k1Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the libsecp256k1 contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoin; 18 | 19 | public class NativeSecp256k1Util{ 20 | 21 | public static void assertEquals( int val, int val2, String message ) throws AssertFailException{ 22 | if( val != val2 ) 23 | throw new AssertFailException("FAIL: " + message); 24 | } 25 | 26 | public static void assertEquals( boolean val, boolean val2, String message ) throws AssertFailException{ 27 | if( val != val2 ) 28 | throw new AssertFailException("FAIL: " + message); 29 | else 30 | System.out.println("PASS: " + message); 31 | } 32 | 33 | public static void assertEquals( String val, String val2, String message ) throws AssertFailException{ 34 | if( !val.equals(val2) ) 35 | throw new AssertFailException("FAIL: " + message); 36 | else 37 | System.out.println("PASS: " + message); 38 | } 39 | 40 | public static class AssertFailException extends Exception { 41 | public AssertFailException(String message) { 42 | super( message ); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/leveldb/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We'd love to accept your code patches! However, before we can take them, we 4 | have to jump a couple of legal hurdles. 5 | 6 | ## Contributor License Agreements 7 | 8 | Please fill out either the individual or corporate Contributor License 9 | Agreement as appropriate. 10 | 11 | * If you are an individual writing original source code and you're sure you 12 | own the intellectual property, then sign an [individual CLA](https://developers.google.com/open-source/cla/individual). 13 | * If you work for a company that wants to allow you to contribute your work, 14 | then sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate). 15 | 16 | Follow either of the two links above to access the appropriate CLA and 17 | instructions for how to sign and return it. 18 | 19 | ## Submitting a Patch 20 | 21 | 1. Sign the contributors license agreement above. 22 | 2. Decide which code you want to submit. A submission should be a set of changes 23 | that addresses one issue in the [issue tracker](https://github.com/google/leveldb/issues). 24 | Please don't mix more than one logical change per submission, because it makes 25 | the history hard to follow. If you want to make a change 26 | (e.g. add a sample or feature) that doesn't have a corresponding issue in the 27 | issue tracker, please create one. 28 | 3. **Submitting**: When you are ready to submit, send us a Pull Request. Be 29 | sure to include the issue number you fixed and the name you used to sign 30 | the CLA. 31 | 32 | ## Writing Code ## 33 | 34 | If your contribution contains code, please make sure that it follows 35 | [the style guide](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml). 36 | Otherwise we will have to ask you to make changes, and that's no fun for anyone. 37 | -------------------------------------------------------------------------------- /src/libbtc/include/btc/aes256_cbc.h: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 Jonas Schnelli 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | The above copyright notice and this permission notice shall be included 13 | in all copies or substantial portions of the Software. 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 18 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | */ 23 | 24 | #ifndef __LIBBTC_AES256_CBC_H__ 25 | #define __LIBBTC_AES256_CBC_H__ 26 | 27 | #include "btc.h" 28 | 29 | #define AES_BLOCK_SIZE 16 30 | 31 | LIBBTC_BEGIN_DECL 32 | 33 | LIBBTC_API int aes256_cbc_encrypt(const unsigned char aes_key[32], const unsigned char iv[AES_BLOCK_SIZE], const unsigned char* data, int size, int pad, unsigned char* out); 34 | LIBBTC_API int aes256_cbc_decrypt(const unsigned char aes_key[32], const unsigned char iv[AES_BLOCK_SIZE], const unsigned char* data, int size, int pad, unsigned char* out); 35 | 36 | LIBBTC_END_DECL 37 | 38 | #endif // __LIBBTC_AES256_CBC_H__ 39 | -------------------------------------------------------------------------------- /src/libbtc/include/btc/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2012 exMULTI, Inc. 6 | Copyright (c) 2015 Jonas Schnelli 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining 9 | a copy of this software and associated documentation files (the "Software"), 10 | to deal in the Software without restriction, including without limitation 11 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 | and/or sell copies of the Software, and to permit persons to whom the 13 | Software is furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included 16 | in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 22 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | OTHER DEALINGS IN THE SOFTWARE. 25 | 26 | */ 27 | 28 | #ifndef __LIBBTC_BUFFER_H__ 29 | #define __LIBBTC_BUFFER_H__ 30 | 31 | #include "btc.h" 32 | 33 | LIBBTC_BEGIN_DECL 34 | 35 | struct buffer { 36 | void* p; 37 | size_t len; 38 | }; 39 | 40 | struct const_buffer { 41 | const void* p; 42 | size_t len; 43 | }; 44 | 45 | LIBBTC_API int buffer_equal(const void* a, const void* b); 46 | LIBBTC_API void buffer_free(void* struct_buffer); 47 | LIBBTC_API struct buffer* buffer_copy(const void* data, size_t data_len); 48 | 49 | LIBBTC_END_DECL 50 | 51 | #endif // __LIBBTC_BUFFER_H__ 52 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/java/org/bitcoin/Secp256k1Context.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the libsecp256k1 contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoin; 18 | 19 | /** 20 | * This class holds the context reference used in native methods 21 | * to handle ECDSA operations. 22 | */ 23 | public class Secp256k1Context { 24 | private static final boolean enabled; //true if the library is loaded 25 | private static final long context; //ref to pointer to context obj 26 | 27 | static { //static initializer 28 | boolean isEnabled = true; 29 | long contextRef = -1; 30 | try { 31 | System.loadLibrary("secp256k1"); 32 | contextRef = secp256k1_init_context(); 33 | } catch (UnsatisfiedLinkError e) { 34 | System.out.println("UnsatisfiedLinkError: " + e.toString()); 35 | isEnabled = false; 36 | } 37 | enabled = isEnabled; 38 | context = contextRef; 39 | } 40 | 41 | public static boolean isEnabled() { 42 | return enabled; 43 | } 44 | 45 | public static long getContext() { 46 | if(!enabled) return -1; //sanity check 47 | return context; 48 | } 49 | 50 | private static native long secp256k1_init_context(); 51 | } 52 | -------------------------------------------------------------------------------- /src/leveldb/util/hash_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/hash.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | class HASH { }; 11 | 12 | TEST(HASH, SignedUnsignedIssue) { 13 | const unsigned char data1[1] = {0x62}; 14 | const unsigned char data2[2] = {0xc3, 0x97}; 15 | const unsigned char data3[3] = {0xe2, 0x99, 0xa5}; 16 | const unsigned char data4[4] = {0xe1, 0x80, 0xb9, 0x32}; 17 | const unsigned char data5[48] = { 18 | 0x01, 0xc0, 0x00, 0x00, 19 | 0x00, 0x00, 0x00, 0x00, 20 | 0x00, 0x00, 0x00, 0x00, 21 | 0x00, 0x00, 0x00, 0x00, 22 | 0x14, 0x00, 0x00, 0x00, 23 | 0x00, 0x00, 0x04, 0x00, 24 | 0x00, 0x00, 0x00, 0x14, 25 | 0x00, 0x00, 0x00, 0x18, 26 | 0x28, 0x00, 0x00, 0x00, 27 | 0x00, 0x00, 0x00, 0x00, 28 | 0x02, 0x00, 0x00, 0x00, 29 | 0x00, 0x00, 0x00, 0x00, 30 | }; 31 | 32 | ASSERT_EQ(Hash(0, 0, 0xbc9f1d34), 0xbc9f1d34); 33 | ASSERT_EQ( 34 | Hash(reinterpret_cast(data1), sizeof(data1), 0xbc9f1d34), 35 | 0xef1345c4); 36 | ASSERT_EQ( 37 | Hash(reinterpret_cast(data2), sizeof(data2), 0xbc9f1d34), 38 | 0x5b663814); 39 | ASSERT_EQ( 40 | Hash(reinterpret_cast(data3), sizeof(data3), 0xbc9f1d34), 41 | 0x323c078f); 42 | ASSERT_EQ( 43 | Hash(reinterpret_cast(data4), sizeof(data4), 0xbc9f1d34), 44 | 0xed21633a); 45 | ASSERT_EQ( 46 | Hash(reinterpret_cast(data5), sizeof(data5), 0x12345678), 47 | 0xf333dabb); 48 | } 49 | 50 | } // namespace leveldb 51 | 52 | int main(int argc, char** argv) { 53 | return leveldb::test::RunAllTests(); 54 | } 55 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/bench_sign.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include "include/secp256k1.h" 8 | #include "util.h" 9 | #include "bench.h" 10 | 11 | typedef struct { 12 | secp256k1_context* ctx; 13 | unsigned char msg[32]; 14 | unsigned char key[32]; 15 | } bench_sign_t; 16 | 17 | static void bench_sign_setup(void* arg) { 18 | int i; 19 | bench_sign_t *data = (bench_sign_t*)arg; 20 | 21 | for (i = 0; i < 32; i++) { 22 | data->msg[i] = i + 1; 23 | } 24 | for (i = 0; i < 32; i++) { 25 | data->key[i] = i + 65; 26 | } 27 | } 28 | 29 | static void bench_sign(void* arg) { 30 | int i; 31 | bench_sign_t *data = (bench_sign_t*)arg; 32 | 33 | unsigned char sig[74]; 34 | for (i = 0; i < 20000; i++) { 35 | size_t siglen = 74; 36 | int j; 37 | secp256k1_ecdsa_signature signature; 38 | CHECK(secp256k1_ecdsa_sign(data->ctx, &signature, data->msg, data->key, NULL, NULL)); 39 | CHECK(secp256k1_ecdsa_signature_serialize_der(data->ctx, sig, &siglen, &signature)); 40 | for (j = 0; j < 32; j++) { 41 | data->msg[j] = sig[j]; 42 | data->key[j] = sig[j + 32]; 43 | } 44 | } 45 | } 46 | 47 | int main(void) { 48 | bench_sign_t data; 49 | 50 | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); 51 | 52 | run_benchmark("ecdsa_sign", bench_sign, bench_sign_setup, NULL, &data, 10, 20000); 53 | 54 | secp256k1_context_destroy(data.ctx); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /src/libbtc/.clang-format: -------------------------------------------------------------------------------- 1 | AccessModifierOffset: -4 2 | AlignEscapedNewlinesLeft: true 3 | AlignTrailingComments: true 4 | AllowAllParametersOfDeclarationOnNextLine: false 5 | AllowShortBlocksOnASingleLine: false 6 | AllowShortFunctionsOnASingleLine: All 7 | AllowShortIfStatementsOnASingleLine: false 8 | AllowShortLoopsOnASingleLine: false 9 | AlwaysBreakBeforeMultilineStrings: false 10 | AlwaysBreakTemplateDeclarations: true 11 | BinPackParameters: false 12 | BreakBeforeBinaryOperators: false 13 | BreakBeforeBraces: Linux 14 | BreakBeforeTernaryOperators: false 15 | BreakConstructorInitializersBeforeComma: false 16 | ColumnLimit: 0 17 | CommentPragmas: '^ IWYU pragma:' 18 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 19 | ConstructorInitializerIndentWidth: 4 20 | ContinuationIndentWidth: 4 21 | Cpp11BracedListStyle: true 22 | DerivePointerAlignment: false 23 | DisableFormat: false 24 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, BOOST_REVERSE_FOREACH ] 25 | IndentCaseLabels: false 26 | IndentFunctionDeclarationAfterType: false 27 | IndentWidth: 4 28 | KeepEmptyLinesAtTheStartOfBlocks: false 29 | Language: Cpp 30 | MaxEmptyLinesToKeep: 2 31 | NamespaceIndentation: None 32 | ObjCSpaceAfterProperty: false 33 | ObjCSpaceBeforeProtocolList: false 34 | PenaltyBreakBeforeFirstCallParameter: 1 35 | PenaltyBreakComment: 300 36 | PenaltyBreakFirstLessLess: 120 37 | PenaltyBreakString: 1000 38 | PenaltyExcessCharacter: 1000000 39 | PenaltyReturnTypeOnItsOwnLine: 200 40 | PointerAlignment: Left 41 | SpaceBeforeAssignmentOperators: true 42 | SpaceBeforeParens: ControlStatements 43 | SpaceInEmptyParentheses: false 44 | SpacesBeforeTrailingComments: 1 45 | SpacesInAngles: false 46 | SpacesInContainerLiterals: true 47 | SpacesInCStyleCastParentheses: false 48 | SpacesInParentheses: false 49 | Standard: Cpp03 50 | TabWidth: 8 51 | UseTab: Never 52 | -------------------------------------------------------------------------------- /src/libbtc/include/btc/ctaes.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Copyright (c) 2016 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef __LIBBTC_CTAES_H__ 8 | #define __LIBBTC_CTAES_H__ 9 | 10 | #include "btc.h" 11 | 12 | LIBBTC_BEGIN_DECL 13 | 14 | typedef struct { 15 | uint16_t slice[8]; 16 | } AES_state; 17 | 18 | typedef struct { 19 | AES_state rk[11]; 20 | } AES128_ctx; 21 | 22 | typedef struct { 23 | AES_state rk[13]; 24 | } AES192_ctx; 25 | 26 | typedef struct { 27 | AES_state rk[15]; 28 | } AES256_ctx; 29 | 30 | LIBBTC_API void AES128_init(AES128_ctx* ctx, const unsigned char* key16); 31 | LIBBTC_API void AES128_encrypt(const AES128_ctx* ctx, size_t blocks, unsigned char* cipher16, const unsigned char* plain16); 32 | LIBBTC_API void AES128_decrypt(const AES128_ctx* ctx, size_t blocks, unsigned char* plain16, const unsigned char* cipher16); 33 | 34 | LIBBTC_API void AES192_init(AES192_ctx* ctx, const unsigned char* key24); 35 | LIBBTC_API void AES192_encrypt(const AES192_ctx* ctx, size_t blocks, unsigned char* cipher16, const unsigned char* plain16); 36 | LIBBTC_API void AES192_decrypt(const AES192_ctx* ctx, size_t blocks, unsigned char* plain16, const unsigned char* cipher16); 37 | 38 | LIBBTC_API void AES256_init(AES256_ctx* ctx, const unsigned char* key32); 39 | LIBBTC_API void AES256_encrypt(const AES256_ctx* ctx, size_t blocks, unsigned char* cipher16, const unsigned char* plain16); 40 | LIBBTC_API void AES256_decrypt(const AES256_ctx* ctx, size_t blocks, unsigned char* plain16, const unsigned char* cipher16); 41 | 42 | LIBBTC_END_DECL 43 | 44 | #endif // __LIBBTC_CTAES_H__ 45 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/hash.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_HASH_ 8 | #define _SECP256K1_HASH_ 9 | 10 | #include 11 | #include 12 | 13 | typedef struct { 14 | uint32_t s[8]; 15 | uint32_t buf[16]; /* In big endian */ 16 | size_t bytes; 17 | } secp256k1_sha256_t; 18 | 19 | static void secp256k1_sha256_initialize(secp256k1_sha256_t *hash); 20 | static void secp256k1_sha256_write(secp256k1_sha256_t *hash, const unsigned char *data, size_t size); 21 | static void secp256k1_sha256_finalize(secp256k1_sha256_t *hash, unsigned char *out32); 22 | 23 | typedef struct { 24 | secp256k1_sha256_t inner, outer; 25 | } secp256k1_hmac_sha256_t; 26 | 27 | static void secp256k1_hmac_sha256_initialize(secp256k1_hmac_sha256_t *hash, const unsigned char *key, size_t size); 28 | static void secp256k1_hmac_sha256_write(secp256k1_hmac_sha256_t *hash, const unsigned char *data, size_t size); 29 | static void secp256k1_hmac_sha256_finalize(secp256k1_hmac_sha256_t *hash, unsigned char *out32); 30 | 31 | typedef struct { 32 | unsigned char v[32]; 33 | unsigned char k[32]; 34 | int retry; 35 | } secp256k1_rfc6979_hmac_sha256_t; 36 | 37 | static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256_t *rng, const unsigned char *key, size_t keylen); 38 | static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256_t *rng, unsigned char *out, size_t outlen); 39 | static void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256_t *rng); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/bench_ecdh.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Pieter Wuille, Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include 8 | 9 | #include "include/secp256k1.h" 10 | #include "include/secp256k1_ecdh.h" 11 | #include "util.h" 12 | #include "bench.h" 13 | 14 | typedef struct { 15 | secp256k1_context *ctx; 16 | secp256k1_pubkey point; 17 | unsigned char scalar[32]; 18 | } bench_ecdh_t; 19 | 20 | static void bench_ecdh_setup(void* arg) { 21 | int i; 22 | bench_ecdh_t *data = (bench_ecdh_t*)arg; 23 | const unsigned char point[] = { 24 | 0x03, 25 | 0x54, 0x94, 0xc1, 0x5d, 0x32, 0x09, 0x97, 0x06, 26 | 0xc2, 0x39, 0x5f, 0x94, 0x34, 0x87, 0x45, 0xfd, 27 | 0x75, 0x7c, 0xe3, 0x0e, 0x4e, 0x8c, 0x90, 0xfb, 28 | 0xa2, 0xba, 0xd1, 0x84, 0xf8, 0x83, 0xc6, 0x9f 29 | }; 30 | 31 | /* create a context with no capabilities */ 32 | data->ctx = secp256k1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT); 33 | for (i = 0; i < 32; i++) { 34 | data->scalar[i] = i + 1; 35 | } 36 | CHECK(secp256k1_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1); 37 | } 38 | 39 | static void bench_ecdh(void* arg) { 40 | int i; 41 | unsigned char res[32]; 42 | bench_ecdh_t *data = (bench_ecdh_t*)arg; 43 | 44 | for (i = 0; i < 20000; i++) { 45 | CHECK(secp256k1_ecdh(data->ctx, res, &data->point, data->scalar) == 1); 46 | } 47 | } 48 | 49 | int main(void) { 50 | bench_ecdh_t data; 51 | 52 | run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, 20000); 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /src/leveldb/db/leveldbutil.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "leveldb/dumpfile.h" 7 | #include "leveldb/env.h" 8 | #include "leveldb/status.h" 9 | 10 | namespace leveldb { 11 | namespace { 12 | 13 | class StdoutPrinter : public WritableFile { 14 | public: 15 | virtual Status Append(const Slice& data) { 16 | fwrite(data.data(), 1, data.size(), stdout); 17 | return Status::OK(); 18 | } 19 | virtual Status Close() { return Status::OK(); } 20 | virtual Status Flush() { return Status::OK(); } 21 | virtual Status Sync() { return Status::OK(); } 22 | virtual std::string GetName() const { return "[stdout]"; } 23 | }; 24 | 25 | bool HandleDumpCommand(Env* env, char** files, int num) { 26 | StdoutPrinter printer; 27 | bool ok = true; 28 | for (int i = 0; i < num; i++) { 29 | Status s = DumpFile(env, files[i], &printer); 30 | if (!s.ok()) { 31 | fprintf(stderr, "%s\n", s.ToString().c_str()); 32 | ok = false; 33 | } 34 | } 35 | return ok; 36 | } 37 | 38 | } // namespace 39 | } // namespace leveldb 40 | 41 | static void Usage() { 42 | fprintf( 43 | stderr, 44 | "Usage: leveldbutil command...\n" 45 | " dump files... -- dump contents of specified files\n" 46 | ); 47 | } 48 | 49 | int main(int argc, char** argv) { 50 | leveldb::Env* env = leveldb::Env::Default(); 51 | bool ok = true; 52 | if (argc < 2) { 53 | Usage(); 54 | ok = false; 55 | } else { 56 | std::string command = argv[1]; 57 | if (command == "dump") { 58 | ok = leveldb::HandleDumpCommand(env, argv+2, argc-2); 59 | } else { 60 | Usage(); 61 | ok = false; 62 | } 63 | } 64 | return (ok ? 0 : 1); 65 | } 66 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/field_5x52.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_FIELD_REPR_ 8 | #define _SECP256K1_FIELD_REPR_ 9 | 10 | #include 11 | 12 | typedef struct { 13 | /* X = sum(i=0..4, elem[i]*2^52) mod n */ 14 | uint64_t n[5]; 15 | #ifdef VERIFY 16 | int magnitude; 17 | int normalized; 18 | #endif 19 | } secp256k1_fe; 20 | 21 | /* Unpacks a constant into a overlapping multi-limbed FE element. */ 22 | #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \ 23 | (d0) | (((uint64_t)(d1) & 0xFFFFFUL) << 32), \ 24 | ((uint64_t)(d1) >> 20) | (((uint64_t)(d2)) << 12) | (((uint64_t)(d3) & 0xFFUL) << 44), \ 25 | ((uint64_t)(d3) >> 8) | (((uint64_t)(d4) & 0xFFFFFFFUL) << 24), \ 26 | ((uint64_t)(d4) >> 28) | (((uint64_t)(d5)) << 4) | (((uint64_t)(d6) & 0xFFFFUL) << 36), \ 27 | ((uint64_t)(d6) >> 16) | (((uint64_t)(d7)) << 16) \ 28 | } 29 | 30 | #ifdef VERIFY 31 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)), 1, 1} 32 | #else 33 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))} 34 | #endif 35 | 36 | typedef struct { 37 | uint64_t n[4]; 38 | } secp256k1_fe_storage; 39 | 40 | #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ \ 41 | (d0) | (((uint64_t)(d1)) << 32), \ 42 | (d2) | (((uint64_t)(d3)) << 32), \ 43 | (d4) | (((uint64_t)(d5)) << 32), \ 44 | (d6) | (((uint64_t)(d7)) << 32) \ 45 | }} 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/leveldb/issues/issue200_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // Test for issue 200: when iterator switches direction from backward 6 | // to forward, the current key can be yielded unexpectedly if a new 7 | // mutation has been added just before the current key. 8 | 9 | #include "leveldb/db.h" 10 | #include "util/testharness.h" 11 | 12 | namespace leveldb { 13 | 14 | class Issue200 { }; 15 | 16 | TEST(Issue200, Test) { 17 | // Get rid of any state from an old run. 18 | std::string dbpath = test::TmpDir() + "/leveldb_issue200_test"; 19 | DestroyDB(dbpath, Options()); 20 | 21 | DB *db; 22 | Options options; 23 | options.create_if_missing = true; 24 | ASSERT_OK(DB::Open(options, dbpath, &db)); 25 | 26 | WriteOptions write_options; 27 | ASSERT_OK(db->Put(write_options, "1", "b")); 28 | ASSERT_OK(db->Put(write_options, "2", "c")); 29 | ASSERT_OK(db->Put(write_options, "3", "d")); 30 | ASSERT_OK(db->Put(write_options, "4", "e")); 31 | ASSERT_OK(db->Put(write_options, "5", "f")); 32 | 33 | ReadOptions read_options; 34 | Iterator *iter = db->NewIterator(read_options); 35 | 36 | // Add an element that should not be reflected in the iterator. 37 | ASSERT_OK(db->Put(write_options, "25", "cd")); 38 | 39 | iter->Seek("5"); 40 | ASSERT_EQ(iter->key().ToString(), "5"); 41 | iter->Prev(); 42 | ASSERT_EQ(iter->key().ToString(), "4"); 43 | iter->Prev(); 44 | ASSERT_EQ(iter->key().ToString(), "3"); 45 | iter->Next(); 46 | ASSERT_EQ(iter->key().ToString(), "4"); 47 | iter->Next(); 48 | ASSERT_EQ(iter->key().ToString(), "5"); 49 | 50 | delete iter; 51 | delete db; 52 | DestroyDB(dbpath, options); 53 | } 54 | 55 | } // namespace leveldb 56 | 57 | int main(int argc, char** argv) { 58 | return leveldb::test::RunAllTests(); 59 | } 60 | -------------------------------------------------------------------------------- /src/leveldb/db/snapshot.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_ 6 | #define STORAGE_LEVELDB_DB_SNAPSHOT_H_ 7 | 8 | #include "db/dbformat.h" 9 | #include "leveldb/db.h" 10 | 11 | namespace leveldb { 12 | 13 | class SnapshotList; 14 | 15 | // Snapshots are kept in a doubly-linked list in the DB. 16 | // Each SnapshotImpl corresponds to a particular sequence number. 17 | class SnapshotImpl : public Snapshot { 18 | public: 19 | SequenceNumber number_; // const after creation 20 | 21 | private: 22 | friend class SnapshotList; 23 | 24 | // SnapshotImpl is kept in a doubly-linked circular list 25 | SnapshotImpl* prev_; 26 | SnapshotImpl* next_; 27 | 28 | SnapshotList* list_; // just for sanity checks 29 | }; 30 | 31 | class SnapshotList { 32 | public: 33 | SnapshotList() { 34 | list_.prev_ = &list_; 35 | list_.next_ = &list_; 36 | } 37 | 38 | bool empty() const { return list_.next_ == &list_; } 39 | SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; } 40 | SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; } 41 | 42 | const SnapshotImpl* New(SequenceNumber seq) { 43 | SnapshotImpl* s = new SnapshotImpl; 44 | s->number_ = seq; 45 | s->list_ = this; 46 | s->next_ = &list_; 47 | s->prev_ = list_.prev_; 48 | s->prev_->next_ = s; 49 | s->next_->prev_ = s; 50 | return s; 51 | } 52 | 53 | void Delete(const SnapshotImpl* s) { 54 | assert(s->list_ == this); 55 | s->prev_->next_ = s->next_; 56 | s->next_->prev_ = s->prev_; 57 | delete s; 58 | } 59 | 60 | private: 61 | // Dummy head of doubly-linked list of snapshots 62 | SnapshotImpl list_; 63 | }; 64 | 65 | } // namespace leveldb 66 | 67 | #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_ 68 | -------------------------------------------------------------------------------- /src/leveldb/util/arena_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/arena.h" 6 | 7 | #include "util/random.h" 8 | #include "util/testharness.h" 9 | 10 | namespace leveldb { 11 | 12 | class ArenaTest { }; 13 | 14 | TEST(ArenaTest, Empty) { 15 | Arena arena; 16 | } 17 | 18 | TEST(ArenaTest, Simple) { 19 | std::vector > allocated; 20 | Arena arena; 21 | const int N = 100000; 22 | size_t bytes = 0; 23 | Random rnd(301); 24 | for (int i = 0; i < N; i++) { 25 | size_t s; 26 | if (i % (N / 10) == 0) { 27 | s = i; 28 | } else { 29 | s = rnd.OneIn(4000) ? rnd.Uniform(6000) : 30 | (rnd.OneIn(10) ? rnd.Uniform(100) : rnd.Uniform(20)); 31 | } 32 | if (s == 0) { 33 | // Our arena disallows size 0 allocations. 34 | s = 1; 35 | } 36 | char* r; 37 | if (rnd.OneIn(10)) { 38 | r = arena.AllocateAligned(s); 39 | } else { 40 | r = arena.Allocate(s); 41 | } 42 | 43 | for (size_t b = 0; b < s; b++) { 44 | // Fill the "i"th allocation with a known bit pattern 45 | r[b] = i % 256; 46 | } 47 | bytes += s; 48 | allocated.push_back(std::make_pair(s, r)); 49 | ASSERT_GE(arena.MemoryUsage(), bytes); 50 | if (i > N/10) { 51 | ASSERT_LE(arena.MemoryUsage(), bytes * 1.10); 52 | } 53 | } 54 | for (size_t i = 0; i < allocated.size(); i++) { 55 | size_t num_bytes = allocated[i].first; 56 | const char* p = allocated[i].second; 57 | for (size_t b = 0; b < num_bytes; b++) { 58 | // Check the "i"th allocation for the known bit pattern 59 | ASSERT_EQ(int(p[b]) & 0xff, i % 256); 60 | } 61 | } 62 | } 63 | 64 | } // namespace leveldb 65 | 66 | int main(int argc, char** argv) { 67 | return leveldb::test::RunAllTests(); 68 | } 69 | -------------------------------------------------------------------------------- /src/leveldb/table/iterator.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/iterator.h" 6 | 7 | namespace leveldb { 8 | 9 | Iterator::Iterator() { 10 | cleanup_.function = NULL; 11 | cleanup_.next = NULL; 12 | } 13 | 14 | Iterator::~Iterator() { 15 | if (cleanup_.function != NULL) { 16 | (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2); 17 | for (Cleanup* c = cleanup_.next; c != NULL; ) { 18 | (*c->function)(c->arg1, c->arg2); 19 | Cleanup* next = c->next; 20 | delete c; 21 | c = next; 22 | } 23 | } 24 | } 25 | 26 | void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) { 27 | assert(func != NULL); 28 | Cleanup* c; 29 | if (cleanup_.function == NULL) { 30 | c = &cleanup_; 31 | } else { 32 | c = new Cleanup; 33 | c->next = cleanup_.next; 34 | cleanup_.next = c; 35 | } 36 | c->function = func; 37 | c->arg1 = arg1; 38 | c->arg2 = arg2; 39 | } 40 | 41 | namespace { 42 | class EmptyIterator : public Iterator { 43 | public: 44 | EmptyIterator(const Status& s) : status_(s) { } 45 | virtual bool Valid() const { return false; } 46 | virtual void Seek(const Slice& target) { } 47 | virtual void SeekToFirst() { } 48 | virtual void SeekToLast() { } 49 | virtual void Next() { assert(false); } 50 | virtual void Prev() { assert(false); } 51 | Slice key() const { assert(false); return Slice(); } 52 | Slice value() const { assert(false); return Slice(); } 53 | virtual Status status() const { return status_; } 54 | private: 55 | Status status_; 56 | }; 57 | } // namespace 58 | 59 | Iterator* NewEmptyIterator() { 60 | return new EmptyIterator(Status::OK()); 61 | } 62 | 63 | Iterator* NewErrorIterator(const Status& status) { 64 | return new EmptyIterator(status); 65 | } 66 | 67 | } // namespace leveldb 68 | -------------------------------------------------------------------------------- /src/libbtc/include/btc/random.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #ifndef __LIBBTC_RANDOM_H__ 28 | #define __LIBBTC_RANDOM_H__ 29 | 30 | #include "btc.h" 31 | 32 | LIBBTC_BEGIN_DECL 33 | 34 | typedef struct btc_rnd_mapper_ { 35 | void (*btc_random_init)(void); 36 | btc_bool (*btc_random_bytes)(uint8_t* buf, uint32_t len, const uint8_t update_seed); 37 | } btc_rnd_mapper; 38 | 39 | // set's a custom random callback mapper 40 | // this function is _not_ thread safe and should be called before anything else 41 | LIBBTC_API void btc_rnd_set_mapper(const btc_rnd_mapper mapper); 42 | LIBBTC_API void btc_rnd_set_mapper_default(); 43 | 44 | LIBBTC_API void btc_random_init(void); 45 | LIBBTC_API btc_bool btc_random_bytes(uint8_t* buf, uint32_t len, const uint8_t update_seed); 46 | 47 | LIBBTC_END_DECL 48 | 49 | #endif // __LIBBTC_TX_H__ 50 | -------------------------------------------------------------------------------- /src/leveldb/table/block_builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include "leveldb/slice.h" 12 | 13 | namespace leveldb { 14 | 15 | struct Options; 16 | 17 | class BlockBuilder { 18 | public: 19 | explicit BlockBuilder(const Options* options); 20 | 21 | // Reset the contents as if the BlockBuilder was just constructed. 22 | void Reset(); 23 | 24 | // REQUIRES: Finish() has not been called since the last call to Reset(). 25 | // REQUIRES: key is larger than any previously added key 26 | void Add(const Slice& key, const Slice& value); 27 | 28 | // Finish building the block and return a slice that refers to the 29 | // block contents. The returned slice will remain valid for the 30 | // lifetime of this builder or until Reset() is called. 31 | Slice Finish(); 32 | 33 | // Returns an estimate of the current (uncompressed) size of the block 34 | // we are building. 35 | size_t CurrentSizeEstimate() const; 36 | 37 | // Return true iff no entries have been added since the last Reset() 38 | bool empty() const { 39 | return buffer_.empty(); 40 | } 41 | 42 | private: 43 | const Options* options_; 44 | std::string buffer_; // Destination buffer 45 | std::vector restarts_; // Restart points 46 | int counter_; // Number of entries emitted since restart 47 | bool finished_; // Has Finish() been called? 48 | std::string last_key_; 49 | 50 | // No copying allowed 51 | BlockBuilder(const BlockBuilder&); 52 | void operator=(const BlockBuilder&); 53 | }; 54 | 55 | } // namespace leveldb 56 | 57 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 58 | -------------------------------------------------------------------------------- /src/leveldb/util/testharness.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/testharness.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace leveldb { 13 | namespace test { 14 | 15 | namespace { 16 | struct Test { 17 | const char* base; 18 | const char* name; 19 | void (*func)(); 20 | }; 21 | std::vector* tests; 22 | } 23 | 24 | bool RegisterTest(const char* base, const char* name, void (*func)()) { 25 | if (tests == NULL) { 26 | tests = new std::vector; 27 | } 28 | Test t; 29 | t.base = base; 30 | t.name = name; 31 | t.func = func; 32 | tests->push_back(t); 33 | return true; 34 | } 35 | 36 | int RunAllTests() { 37 | const char* matcher = getenv("LEVELDB_TESTS"); 38 | 39 | int num = 0; 40 | if (tests != NULL) { 41 | for (size_t i = 0; i < tests->size(); i++) { 42 | const Test& t = (*tests)[i]; 43 | if (matcher != NULL) { 44 | std::string name = t.base; 45 | name.push_back('.'); 46 | name.append(t.name); 47 | if (strstr(name.c_str(), matcher) == NULL) { 48 | continue; 49 | } 50 | } 51 | fprintf(stderr, "==== Test %s.%s\n", t.base, t.name); 52 | (*t.func)(); 53 | ++num; 54 | } 55 | } 56 | fprintf(stderr, "==== PASSED %d tests\n", num); 57 | return 0; 58 | } 59 | 60 | std::string TmpDir() { 61 | std::string dir; 62 | Status s = Env::Default()->GetTestDirectory(&dir); 63 | ASSERT_TRUE(s.ok()) << s.ToString(); 64 | return dir; 65 | } 66 | 67 | int RandomSeed() { 68 | const char* env = getenv("TEST_RANDOM_SEED"); 69 | int result = (env != NULL ? atoi(env) : 301); 70 | if (result <= 0) { 71 | result = 301; 72 | } 73 | return result; 74 | } 75 | 76 | } // namespace test 77 | } // namespace leveldb 78 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/bench.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_BENCH_H_ 8 | #define _SECP256K1_BENCH_H_ 9 | 10 | #include 11 | #include 12 | #include "sys/time.h" 13 | 14 | static double gettimedouble(void) { 15 | struct timeval tv; 16 | gettimeofday(&tv, NULL); 17 | return tv.tv_usec * 0.000001 + tv.tv_sec; 18 | } 19 | 20 | void print_number(double x) { 21 | double y = x; 22 | int c = 0; 23 | if (y < 0.0) { 24 | y = -y; 25 | } 26 | while (y < 100.0) { 27 | y *= 10.0; 28 | c++; 29 | } 30 | printf("%.*f", c, x); 31 | } 32 | 33 | void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), void (*teardown)(void*), void* data, int count, int iter) { 34 | int i; 35 | double min = HUGE_VAL; 36 | double sum = 0.0; 37 | double max = 0.0; 38 | for (i = 0; i < count; i++) { 39 | double begin, total; 40 | if (setup != NULL) { 41 | setup(data); 42 | } 43 | begin = gettimedouble(); 44 | benchmark(data); 45 | total = gettimedouble() - begin; 46 | if (teardown != NULL) { 47 | teardown(data); 48 | } 49 | if (total < min) { 50 | min = total; 51 | } 52 | if (total > max) { 53 | max = total; 54 | } 55 | sum += total; 56 | } 57 | printf("%s: min ", name); 58 | print_number(min * 1000000.0 / iter); 59 | printf("us / avg "); 60 | print_number((sum / count) * 1000000.0 / iter); 61 | printf("us / max "); 62 | print_number(max * 1000000.0 / iter); 63 | printf("us\n"); 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/leveldb/util/logging.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/logging.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "leveldb/env.h" 12 | #include "leveldb/slice.h" 13 | 14 | namespace leveldb { 15 | 16 | void AppendNumberTo(std::string* str, uint64_t num) { 17 | char buf[30]; 18 | snprintf(buf, sizeof(buf), "%llu", (unsigned long long) num); 19 | str->append(buf); 20 | } 21 | 22 | void AppendEscapedStringTo(std::string* str, const Slice& value) { 23 | for (size_t i = 0; i < value.size(); i++) { 24 | char c = value[i]; 25 | if (c >= ' ' && c <= '~') { 26 | str->push_back(c); 27 | } else { 28 | char buf[10]; 29 | snprintf(buf, sizeof(buf), "\\x%02x", 30 | static_cast(c) & 0xff); 31 | str->append(buf); 32 | } 33 | } 34 | } 35 | 36 | std::string NumberToString(uint64_t num) { 37 | std::string r; 38 | AppendNumberTo(&r, num); 39 | return r; 40 | } 41 | 42 | std::string EscapeString(const Slice& value) { 43 | std::string r; 44 | AppendEscapedStringTo(&r, value); 45 | return r; 46 | } 47 | 48 | bool ConsumeDecimalNumber(Slice* in, uint64_t* val) { 49 | uint64_t v = 0; 50 | int digits = 0; 51 | while (!in->empty()) { 52 | unsigned char c = (*in)[0]; 53 | if (c >= '0' && c <= '9') { 54 | ++digits; 55 | const int delta = (c - '0'); 56 | static const uint64_t kMaxUint64 = ~static_cast(0); 57 | if (v > kMaxUint64/10 || 58 | (v == kMaxUint64/10 && delta > kMaxUint64%10)) { 59 | // Overflow 60 | return false; 61 | } 62 | v = (v * 10) + delta; 63 | in->remove_prefix(1); 64 | } else { 65 | break; 66 | } 67 | } 68 | *val = v; 69 | return (digits > 0); 70 | } 71 | 72 | } // namespace leveldb 73 | -------------------------------------------------------------------------------- /src/leveldb/port/port_posix.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "port/port_posix.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #if (defined(__x86_64__) || defined(__i386__)) && defined(__GNUC__) 12 | #include 13 | #endif 14 | 15 | namespace leveldb { 16 | namespace port { 17 | 18 | static void PthreadCall(const char* label, int result) { 19 | if (result != 0) { 20 | fprintf(stderr, "pthread %s: %s\n", label, strerror(result)); 21 | abort(); 22 | } 23 | } 24 | 25 | Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); } 26 | 27 | Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); } 28 | 29 | void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); } 30 | 31 | void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); } 32 | 33 | CondVar::CondVar(Mutex* mu) 34 | : mu_(mu) { 35 | PthreadCall("init cv", pthread_cond_init(&cv_, NULL)); 36 | } 37 | 38 | CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); } 39 | 40 | void CondVar::Wait() { 41 | PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_)); 42 | } 43 | 44 | void CondVar::Signal() { 45 | PthreadCall("signal", pthread_cond_signal(&cv_)); 46 | } 47 | 48 | void CondVar::SignalAll() { 49 | PthreadCall("broadcast", pthread_cond_broadcast(&cv_)); 50 | } 51 | 52 | void InitOnce(OnceType* once, void (*initializer)()) { 53 | PthreadCall("once", pthread_once(once, initializer)); 54 | } 55 | 56 | bool HasAcceleratedCRC32C() { 57 | #if (defined(__x86_64__) || defined(__i386__)) && defined(__GNUC__) 58 | unsigned int eax, ebx, ecx, edx; 59 | __get_cpuid(1, &eax, &ebx, &ecx, &edx); 60 | return (ecx & (1 << 20)) != 0; 61 | #else 62 | return false; 63 | #endif 64 | } 65 | 66 | } // namespace port 67 | } // namespace leveldb 68 | -------------------------------------------------------------------------------- /src/leveldb/util/crc32c_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/crc32c.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | namespace crc32c { 10 | 11 | class CRC { }; 12 | 13 | TEST(CRC, StandardResults) { 14 | // From rfc3720 section B.4. 15 | char buf[32]; 16 | 17 | memset(buf, 0, sizeof(buf)); 18 | ASSERT_EQ(0x8a9136aa, Value(buf, sizeof(buf))); 19 | 20 | memset(buf, 0xff, sizeof(buf)); 21 | ASSERT_EQ(0x62a8ab43, Value(buf, sizeof(buf))); 22 | 23 | for (int i = 0; i < 32; i++) { 24 | buf[i] = i; 25 | } 26 | ASSERT_EQ(0x46dd794e, Value(buf, sizeof(buf))); 27 | 28 | for (int i = 0; i < 32; i++) { 29 | buf[i] = 31 - i; 30 | } 31 | ASSERT_EQ(0x113fdb5c, Value(buf, sizeof(buf))); 32 | 33 | unsigned char data[48] = { 34 | 0x01, 0xc0, 0x00, 0x00, 35 | 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 38 | 0x14, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x04, 0x00, 40 | 0x00, 0x00, 0x00, 0x14, 41 | 0x00, 0x00, 0x00, 0x18, 42 | 0x28, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 44 | 0x02, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 46 | }; 47 | ASSERT_EQ(0xd9963a56, Value(reinterpret_cast(data), sizeof(data))); 48 | } 49 | 50 | TEST(CRC, Values) { 51 | ASSERT_NE(Value("a", 1), Value("foo", 3)); 52 | } 53 | 54 | TEST(CRC, Extend) { 55 | ASSERT_EQ(Value("hello world", 11), 56 | Extend(Value("hello ", 6), "world", 5)); 57 | } 58 | 59 | TEST(CRC, Mask) { 60 | uint32_t crc = Value("foo", 3); 61 | ASSERT_NE(crc, Mask(crc)); 62 | ASSERT_NE(crc, Mask(Mask(crc))); 63 | ASSERT_EQ(crc, Unmask(Mask(crc))); 64 | ASSERT_EQ(crc, Unmask(Unmask(Mask(Mask(crc))))); 65 | } 66 | 67 | } // namespace crc32c 68 | } // namespace leveldb 69 | 70 | int main(int argc, char** argv) { 71 | return leveldb::test::RunAllTests(); 72 | } 73 | -------------------------------------------------------------------------------- /src/leveldb/util/arena.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_ARENA_H_ 6 | #define STORAGE_LEVELDB_UTIL_ARENA_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "port/port.h" 13 | 14 | namespace leveldb { 15 | 16 | class Arena { 17 | public: 18 | Arena(); 19 | ~Arena(); 20 | 21 | // Return a pointer to a newly allocated memory block of "bytes" bytes. 22 | char* Allocate(size_t bytes); 23 | 24 | // Allocate memory with the normal alignment guarantees provided by malloc 25 | char* AllocateAligned(size_t bytes); 26 | 27 | // Returns an estimate of the total memory usage of data allocated 28 | // by the arena. 29 | size_t MemoryUsage() const { 30 | return reinterpret_cast(memory_usage_.NoBarrier_Load()); 31 | } 32 | 33 | private: 34 | char* AllocateFallback(size_t bytes); 35 | char* AllocateNewBlock(size_t block_bytes); 36 | 37 | // Allocation state 38 | char* alloc_ptr_; 39 | size_t alloc_bytes_remaining_; 40 | 41 | // Array of new[] allocated memory blocks 42 | std::vector blocks_; 43 | 44 | // Total memory usage of the arena. 45 | port::AtomicPointer memory_usage_; 46 | 47 | // No copying allowed 48 | Arena(const Arena&); 49 | void operator=(const Arena&); 50 | }; 51 | 52 | inline char* Arena::Allocate(size_t bytes) { 53 | // The semantics of what to return are a bit messy if we allow 54 | // 0-byte allocations, so we disallow them here (we don't need 55 | // them for our internal use). 56 | assert(bytes > 0); 57 | if (bytes <= alloc_bytes_remaining_) { 58 | char* result = alloc_ptr_; 59 | alloc_ptr_ += bytes; 60 | alloc_bytes_remaining_ -= bytes; 61 | return result; 62 | } 63 | return AllocateFallback(bytes); 64 | } 65 | 66 | } // namespace leveldb 67 | 68 | #endif // STORAGE_LEVELDB_UTIL_ARENA_H_ 69 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/field_10x26.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_FIELD_REPR_ 8 | #define _SECP256K1_FIELD_REPR_ 9 | 10 | #include 11 | 12 | typedef struct { 13 | /* X = sum(i=0..9, elem[i]*2^26) mod n */ 14 | uint32_t n[10]; 15 | #ifdef VERIFY 16 | int magnitude; 17 | int normalized; 18 | #endif 19 | } secp256k1_fe; 20 | 21 | /* Unpacks a constant into a overlapping multi-limbed FE element. */ 22 | #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \ 23 | (d0) & 0x3FFFFFFUL, \ 24 | (((uint32_t)d0) >> 26) | (((uint32_t)(d1) & 0xFFFFFUL) << 6), \ 25 | (((uint32_t)d1) >> 20) | (((uint32_t)(d2) & 0x3FFFUL) << 12), \ 26 | (((uint32_t)d2) >> 14) | (((uint32_t)(d3) & 0xFFUL) << 18), \ 27 | (((uint32_t)d3) >> 8) | (((uint32_t)(d4) & 0x3UL) << 24), \ 28 | (((uint32_t)d4) >> 2) & 0x3FFFFFFUL, \ 29 | (((uint32_t)d4) >> 28) | (((uint32_t)(d5) & 0x3FFFFFUL) << 4), \ 30 | (((uint32_t)d5) >> 22) | (((uint32_t)(d6) & 0xFFFFUL) << 10), \ 31 | (((uint32_t)d6) >> 16) | (((uint32_t)(d7) & 0x3FFUL) << 16), \ 32 | (((uint32_t)d7) >> 10) \ 33 | } 34 | 35 | #ifdef VERIFY 36 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)), 1, 1} 37 | #else 38 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))} 39 | #endif 40 | 41 | typedef struct { 42 | uint32_t n[8]; 43 | } secp256k1_fe_storage; 44 | 45 | #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }} 46 | #define SECP256K1_FE_STORAGE_CONST_GET(d) d.n[7], d.n[6], d.n[5], d.n[4],d.n[3], d.n[2], d.n[1], d.n[0] 47 | #endif 48 | -------------------------------------------------------------------------------- /src/libbtc/src/logdb/include/logdb/logdb_base.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Jonas Schnelli 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #ifndef __LIBLOGDB_BASE_H__ 31 | #define __LIBLOGDB_BASE_H__ 32 | 33 | #define UNUSED(x) (void)(x) 34 | 35 | typedef uint8_t logdb_bool; /*!serialize, c/c++ save bool*/ 36 | 37 | #ifndef true 38 | #define true 1 39 | #endif 40 | 41 | #ifndef false 42 | #define false 0 43 | #endif 44 | 45 | #ifndef NULL 46 | #define NULL 0 47 | #endif 48 | 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | 53 | #ifndef LIBLOGDB_API 54 | #if defined(_WIN32) 55 | #ifdef LIBBTC_BUILD 56 | #define LIBLOGDB_API __declspec(dllexport) 57 | #else 58 | #define LIBLOGDB_API 59 | #endif 60 | #elif defined(__GNUC__) && defined(LIBBTC_BUILD) 61 | #define LIBLOGDB_API __attribute__((visibility("default"))) 62 | #else 63 | #define LIBLOGDB_API 64 | #endif 65 | #endif 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* __LIBLOGDB_BASE_H__ */ 72 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/modules/ecdh/main_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_MODULE_ECDH_MAIN_ 8 | #define _SECP256K1_MODULE_ECDH_MAIN_ 9 | 10 | #include "include/secp256k1_ecdh.h" 11 | #include "ecmult_const_impl.h" 12 | 13 | int secp256k1_ecdh(const secp256k1_context* ctx, unsigned char *result, const secp256k1_pubkey *point, const unsigned char *scalar) { 14 | int ret = 0; 15 | int overflow = 0; 16 | secp256k1_gej res; 17 | secp256k1_ge pt; 18 | secp256k1_scalar s; 19 | ARG_CHECK(result != NULL); 20 | ARG_CHECK(point != NULL); 21 | ARG_CHECK(scalar != NULL); 22 | (void)ctx; 23 | 24 | secp256k1_pubkey_load(ctx, &pt, point); 25 | secp256k1_scalar_set_b32(&s, scalar, &overflow); 26 | if (overflow || secp256k1_scalar_is_zero(&s)) { 27 | ret = 0; 28 | } else { 29 | unsigned char x[32]; 30 | unsigned char y[1]; 31 | secp256k1_sha256_t sha; 32 | 33 | secp256k1_ecmult_const(&res, &pt, &s); 34 | secp256k1_ge_set_gej(&pt, &res); 35 | /* Compute a hash of the point in compressed form 36 | * Note we cannot use secp256k1_eckey_pubkey_serialize here since it does not 37 | * expect its output to be secret and has a timing sidechannel. */ 38 | secp256k1_fe_normalize(&pt.x); 39 | secp256k1_fe_normalize(&pt.y); 40 | secp256k1_fe_get_b32(x, &pt.x); 41 | y[0] = 0x02 | secp256k1_fe_is_odd(&pt.y); 42 | 43 | secp256k1_sha256_initialize(&sha); 44 | secp256k1_sha256_write(&sha, y, sizeof(y)); 45 | secp256k1_sha256_write(&sha, x, sizeof(x)); 46 | secp256k1_sha256_finalize(&sha, result); 47 | ret = 1; 48 | } 49 | 50 | secp256k1_scalar_clear(&s); 51 | return ret; 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/leveldb/include/leveldb/write_batch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // WriteBatch holds a collection of updates to apply atomically to a DB. 6 | // 7 | // The updates are applied in the order in which they are added 8 | // to the WriteBatch. For example, the value of "key" will be "v3" 9 | // after the following batch is written: 10 | // 11 | // batch.Put("key", "v1"); 12 | // batch.Delete("key"); 13 | // batch.Put("key", "v2"); 14 | // batch.Put("key", "v3"); 15 | // 16 | // Multiple threads can invoke const methods on a WriteBatch without 17 | // external synchronization, but if any of the threads may call a 18 | // non-const method, all threads accessing the same WriteBatch must use 19 | // external synchronization. 20 | 21 | #ifndef STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 22 | #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 23 | 24 | #include 25 | #include "leveldb/status.h" 26 | 27 | namespace leveldb { 28 | 29 | class Slice; 30 | 31 | class WriteBatch { 32 | public: 33 | WriteBatch(); 34 | ~WriteBatch(); 35 | 36 | // Store the mapping "key->value" in the database. 37 | void Put(const Slice& key, const Slice& value); 38 | 39 | // If the database contains a mapping for "key", erase it. Else do nothing. 40 | void Delete(const Slice& key); 41 | 42 | // Clear all updates buffered in this batch. 43 | void Clear(); 44 | 45 | // Support for iterating over the contents of a batch. 46 | class Handler { 47 | public: 48 | virtual ~Handler(); 49 | virtual void Put(const Slice& key, const Slice& value) = 0; 50 | virtual void Delete(const Slice& key) = 0; 51 | }; 52 | Status Iterate(Handler* handler) const; 53 | 54 | private: 55 | friend class WriteBatchInternal; 56 | 57 | std::string rep_; // See comment in write_batch.cc for the format of rep_ 58 | 59 | // Intentionally copyable 60 | }; 61 | 62 | } // namespace leveldb 63 | 64 | #endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 65 | -------------------------------------------------------------------------------- /src/libbtc/include/btc/base58.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013-2014 Tomas Dzetkulic 3 | * Copyright (c) 2013-2014 Pavol Rusnak 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 19 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 | * OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef __LIBBTC_BASE58_H__ 25 | #define __LIBBTC_BASE58_H__ 26 | 27 | #include "btc.h" 28 | 29 | #include 30 | 31 | #include 32 | 33 | LIBBTC_BEGIN_DECL 34 | 35 | LIBBTC_API int btc_base58_encode_check(const uint8_t* data, int len, char* str, int strsize); 36 | LIBBTC_API int btc_base58_decode_check(const char* str, uint8_t* data, size_t datalen); 37 | 38 | LIBBTC_API int btc_base58_encode(char* b58, size_t* b58sz, const void* data, size_t binsz); 39 | LIBBTC_API int btc_base58_decode(void* bin, size_t* binszp, const char* b58); 40 | 41 | LIBBTC_API btc_bool btc_p2pkh_addr_from_hash160(const uint160 hashin, const btc_chainparams* chain, char *addrout, int len); 42 | LIBBTC_API btc_bool btc_p2wpkh_addr_from_hash160(const uint160 hashin, const btc_chainparams* chain, char *addrout); 43 | 44 | LIBBTC_END_DECL 45 | 46 | #endif // __LIBBTC_BASE58_H__ 47 | -------------------------------------------------------------------------------- /src/libbtc/src/logdb/test/tests_red_black_tree.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "../../../test/utest.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | /* this file has functions to test a red-black tree of integers */ 11 | 12 | void free_key(void* a) { 13 | free((int*)a); 14 | } 15 | 16 | void free_value(void *a){ 17 | free((int*)a); 18 | } 19 | 20 | int IntComp(const void* a,const void* b) { 21 | if( *(int*)a > *(int*)b) return(1); 22 | if( *(int*)a < *(int*)b) return(-1); 23 | return(0); 24 | } 25 | 26 | void IntPrint(const void* a) { 27 | printf("%i",*(int*)a); 28 | } 29 | 30 | void InfoPrint(void* a) { 31 | UNUSED(a); 32 | } 33 | 34 | 35 | void test_red_black_tree() { 36 | char *akey; 37 | char *avalue; 38 | char *akey2; 39 | char *avalue2; 40 | rb_red_blk_node* newNode; 41 | rb_red_blk_node* newNode2; 42 | rb_red_blk_tree* tree; 43 | size_t size; 44 | 45 | tree=RBTreeCreate(IntComp,free_key,free_value,IntPrint,InfoPrint); 46 | 47 | 48 | akey = malloc(10); 49 | memcpy(akey, (void *)"akey", 4); 50 | avalue = malloc(10); 51 | memcpy(avalue, (void *)"avalue", 6); 52 | RBTreeInsert(tree,akey,avalue); 53 | 54 | akey2 = malloc(10); 55 | memcpy(akey2, (void *)"bkey", 4); 56 | avalue2 = malloc(10); 57 | memcpy(avalue2, (void *)"bvalue", 6); 58 | RBTreeInsert(tree,akey2,avalue2); 59 | 60 | newNode2 = RBExactQuery(tree,akey2); 61 | newNode = RBExactQuery(tree,akey); 62 | newNode = TreeSuccessor(tree,newNode); 63 | newNode = TreePredecessor(tree,newNode); 64 | 65 | size = rbtree_count(tree); 66 | while((newNode2 = rbtree_enumerate_next(tree))) 67 | { 68 | size--; 69 | } 70 | /* test reset */ 71 | while((newNode2 = rbtree_enumerate_next(tree))) 72 | { 73 | size++; 74 | } 75 | while((newNode2 = rbtree_enumerate_next(tree))) 76 | { 77 | size--; 78 | } 79 | 80 | u_assert_int_eq(size, 0); 81 | 82 | RBDelete(tree, newNode); 83 | 84 | RBTreePrint(tree); 85 | RBTreeDestroy(tree); 86 | } 87 | -------------------------------------------------------------------------------- /src/libbtc/include/btc/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2017 Jonas Schnelli 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #ifndef __LIBBTC_MEMORY_H__ 28 | #define __LIBBTC_MEMORY_H__ 29 | 30 | #include "btc.h" 31 | 32 | LIBBTC_BEGIN_DECL 33 | 34 | typedef struct btc_mem_mapper_ { 35 | void* (*btc_malloc)(size_t size); 36 | void* (*btc_calloc)(size_t count, size_t size); 37 | void* (*btc_realloc)(void* ptr, size_t size); 38 | void (*btc_free)(void* ptr); 39 | } btc_mem_mapper; 40 | 41 | // set's a custom memory mapper 42 | // this function is _not_ thread safe and must be called before anything else 43 | LIBBTC_API void btc_mem_set_mapper(const btc_mem_mapper mapper); 44 | LIBBTC_API void btc_mem_set_mapper_default(); 45 | 46 | LIBBTC_API void* btc_malloc(size_t size); 47 | LIBBTC_API void* btc_calloc(size_t count, size_t size); 48 | LIBBTC_API void* btc_realloc(void* ptr, size_t size); 49 | LIBBTC_API void btc_free(void* ptr); 50 | 51 | LIBBTC_API volatile void *btc_mem_zero(volatile void *dst, size_t len); 52 | 53 | LIBBTC_END_DECL 54 | 55 | #endif // __LIBBTC_MEMORY_H__ 56 | -------------------------------------------------------------------------------- /src/univalue/gen/gen.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 BitPay Inc. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | // 6 | // To re-create univalue_escapes.h: 7 | // $ g++ -o gen gen.cpp 8 | // $ ./gen > univalue_escapes.h 9 | // 10 | 11 | #include 12 | #include 13 | #include "univalue.h" 14 | 15 | using namespace std; 16 | 17 | static bool initEscapes; 18 | static std::string escapes[256]; 19 | 20 | static void initJsonEscape() 21 | { 22 | // Escape all lower control characters (some get overridden with smaller sequences below) 23 | for (int ch=0x00; ch<0x20; ++ch) { 24 | char tmpbuf[20]; 25 | snprintf(tmpbuf, sizeof(tmpbuf), "\\u%04x", ch); 26 | escapes[ch] = std::string(tmpbuf); 27 | } 28 | 29 | escapes[(int)'"'] = "\\\""; 30 | escapes[(int)'\\'] = "\\\\"; 31 | escapes[(int)'\b'] = "\\b"; 32 | escapes[(int)'\f'] = "\\f"; 33 | escapes[(int)'\n'] = "\\n"; 34 | escapes[(int)'\r'] = "\\r"; 35 | escapes[(int)'\t'] = "\\t"; 36 | escapes[(int)'\x7f'] = "\\u007f"; // U+007F DELETE 37 | 38 | initEscapes = true; 39 | } 40 | 41 | static void outputEscape() 42 | { 43 | printf( "// Automatically generated file. Do not modify.\n" 44 | "#ifndef BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n" 45 | "#define BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n" 46 | "static const char *escapes[256] = {\n"); 47 | 48 | for (unsigned int i = 0; i < 256; i++) { 49 | if (escapes[i].empty()) { 50 | printf("\tNULL,\n"); 51 | } else { 52 | printf("\t\""); 53 | 54 | unsigned int si; 55 | for (si = 0; si < escapes[i].size(); si++) { 56 | char ch = escapes[i][si]; 57 | switch (ch) { 58 | case '"': 59 | printf("\\\""); 60 | break; 61 | case '\\': 62 | printf("\\\\"); 63 | break; 64 | default: 65 | printf("%c", escapes[i][si]); 66 | break; 67 | } 68 | } 69 | 70 | printf("\",\n"); 71 | } 72 | } 73 | 74 | printf( "};\n" 75 | "#endif // BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n"); 76 | } 77 | 78 | int main (int argc, char *argv[]) 79 | { 80 | initJsonEscape(); 81 | outputEscape(); 82 | return 0; 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/libbtc/include/btc/block.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Thomas Kerin 6 | Copyright (c) 2016 libbtc developers 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining 9 | a copy of this software and associated documentation files (the "Software"), 10 | to deal in the Software without restriction, including without limitation 11 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 | and/or sell copies of the Software, and to permit persons to whom the 13 | Software is furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included 16 | in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 22 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | OTHER DEALINGS IN THE SOFTWARE. 25 | 26 | */ 27 | 28 | #ifndef __LIBBTC_BLOCK_H__ 29 | #define __LIBBTC_BLOCK_H__ 30 | 31 | #include "btc.h" 32 | #include "buffer.h" 33 | #include "cstr.h" 34 | #include "hash.h" 35 | 36 | LIBBTC_BEGIN_DECL 37 | 38 | typedef struct btc_block_header_ { 39 | int32_t version; 40 | uint256 prev_block; 41 | uint256 merkle_root; 42 | uint32_t timestamp; 43 | uint32_t bits; 44 | uint32_t nonce; 45 | } btc_block_header; 46 | 47 | LIBBTC_API btc_block_header* btc_block_header_new(); 48 | LIBBTC_API void btc_block_header_free(btc_block_header* header); 49 | LIBBTC_API int btc_block_header_deserialize(btc_block_header* header, struct const_buffer* buf); 50 | LIBBTC_API void btc_block_header_serialize(cstring* s, const btc_block_header* header); 51 | LIBBTC_API void btc_block_header_copy(btc_block_header* dest, const btc_block_header* src); 52 | LIBBTC_API btc_bool btc_block_header_hash(btc_block_header* header, uint256 hash); 53 | 54 | LIBBTC_END_DECL 55 | 56 | #endif // __LIBBTC_BLOCK_H__ 57 | -------------------------------------------------------------------------------- /src/libbtc/include/btc/vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015 Jonas Schnelli 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #ifndef __LIBBTC_VECTOR_H__ 28 | #define __LIBBTC_VECTOR_H__ 29 | 30 | #include "btc.h" 31 | 32 | LIBBTC_BEGIN_DECL 33 | 34 | typedef struct vector { 35 | void** data; /* array of pointers */ 36 | size_t len; /* array element count */ 37 | size_t alloc; /* allocated array elements */ 38 | 39 | void (*elem_free_f)(void*); 40 | } vector; 41 | 42 | LIBBTC_API vector* vector_new(size_t res, void (*free_f)(void*)); 43 | LIBBTC_API void vector_free(vector* vec, btc_bool free_array); 44 | 45 | LIBBTC_API btc_bool vector_add(vector* vec, void* data); 46 | LIBBTC_API btc_bool vector_remove(vector* vec, void* data); 47 | LIBBTC_API void vector_remove_idx(vector* vec, size_t idx); 48 | LIBBTC_API void vector_remove_range(vector* vec, size_t idx, size_t len); 49 | LIBBTC_API btc_bool vector_resize(vector* vec, size_t newsz); 50 | 51 | LIBBTC_API ssize_t vector_find(vector* vec, void* data); 52 | 53 | #define vector_idx(vec, idx) ((vec)->data[(idx)]) 54 | 55 | LIBBTC_END_DECL 56 | 57 | #endif // __LIBBTC_VECTOR_H__ 58 | -------------------------------------------------------------------------------- /src/leveldb/util/status.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "port/port.h" 7 | #include "leveldb/status.h" 8 | 9 | namespace leveldb { 10 | 11 | const char* Status::CopyState(const char* state) { 12 | uint32_t size; 13 | memcpy(&size, state, sizeof(size)); 14 | char* result = new char[size + 5]; 15 | memcpy(result, state, size + 5); 16 | return result; 17 | } 18 | 19 | Status::Status(Code code, const Slice& msg, const Slice& msg2) { 20 | assert(code != kOk); 21 | const uint32_t len1 = msg.size(); 22 | const uint32_t len2 = msg2.size(); 23 | const uint32_t size = len1 + (len2 ? (2 + len2) : 0); 24 | char* result = new char[size + 5]; 25 | memcpy(result, &size, sizeof(size)); 26 | result[4] = static_cast(code); 27 | memcpy(result + 5, msg.data(), len1); 28 | if (len2) { 29 | result[5 + len1] = ':'; 30 | result[6 + len1] = ' '; 31 | memcpy(result + 7 + len1, msg2.data(), len2); 32 | } 33 | state_ = result; 34 | } 35 | 36 | std::string Status::ToString() const { 37 | if (state_ == NULL) { 38 | return "OK"; 39 | } else { 40 | char tmp[30]; 41 | const char* type; 42 | switch (code()) { 43 | case kOk: 44 | type = "OK"; 45 | break; 46 | case kNotFound: 47 | type = "NotFound: "; 48 | break; 49 | case kCorruption: 50 | type = "Corruption: "; 51 | break; 52 | case kNotSupported: 53 | type = "Not implemented: "; 54 | break; 55 | case kInvalidArgument: 56 | type = "Invalid argument: "; 57 | break; 58 | case kIOError: 59 | type = "IO error: "; 60 | break; 61 | default: 62 | snprintf(tmp, sizeof(tmp), "Unknown code(%d): ", 63 | static_cast(code())); 64 | type = tmp; 65 | break; 66 | } 67 | std::string result(type); 68 | uint32_t length; 69 | memcpy(&length, state_, sizeof(length)); 70 | result.append(state_ + 5, length); 71 | return result; 72 | } 73 | } 74 | 75 | } // namespace leveldb 76 | -------------------------------------------------------------------------------- /src/leveldb/db/table_cache.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Thread-safe (provides internal synchronization) 6 | 7 | #ifndef STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 8 | #define STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 9 | 10 | #include 11 | #include 12 | #include "db/dbformat.h" 13 | #include "leveldb/cache.h" 14 | #include "leveldb/table.h" 15 | #include "port/port.h" 16 | 17 | namespace leveldb { 18 | 19 | class Env; 20 | 21 | class TableCache { 22 | public: 23 | TableCache(const std::string& dbname, const Options* options, int entries); 24 | ~TableCache(); 25 | 26 | // Return an iterator for the specified file number (the corresponding 27 | // file length must be exactly "file_size" bytes). If "tableptr" is 28 | // non-NULL, also sets "*tableptr" to point to the Table object 29 | // underlying the returned iterator, or NULL if no Table object underlies 30 | // the returned iterator. The returned "*tableptr" object is owned by 31 | // the cache and should not be deleted, and is valid for as long as the 32 | // returned iterator is live. 33 | Iterator* NewIterator(const ReadOptions& options, 34 | uint64_t file_number, 35 | uint64_t file_size, 36 | Table** tableptr = NULL); 37 | 38 | // If a seek to internal key "k" in specified file finds an entry, 39 | // call (*handle_result)(arg, found_key, found_value). 40 | Status Get(const ReadOptions& options, 41 | uint64_t file_number, 42 | uint64_t file_size, 43 | const Slice& k, 44 | void* arg, 45 | void (*handle_result)(void*, const Slice&, const Slice&)); 46 | 47 | // Evict any entry for the specified file number 48 | void Evict(uint64_t file_number); 49 | 50 | private: 51 | Env* const env_; 52 | const std::string dbname_; 53 | const Options* options_; 54 | Cache* cache_; 55 | 56 | Status FindTable(uint64_t file_number, uint64_t file_size, Cache::Handle**); 57 | }; 58 | 59 | } // namespace leveldb 60 | 61 | #endif // STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 62 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/bench_recover.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014-2015 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include "include/secp256k1.h" 8 | #include "include/secp256k1_recovery.h" 9 | #include "util.h" 10 | #include "bench.h" 11 | 12 | typedef struct { 13 | secp256k1_context *ctx; 14 | unsigned char msg[32]; 15 | unsigned char sig[64]; 16 | } bench_recover_t; 17 | 18 | void bench_recover(void* arg) { 19 | int i; 20 | bench_recover_t *data = (bench_recover_t*)arg; 21 | secp256k1_pubkey pubkey; 22 | unsigned char pubkeyc[33]; 23 | 24 | for (i = 0; i < 20000; i++) { 25 | int j; 26 | size_t pubkeylen = 33; 27 | secp256k1_ecdsa_recoverable_signature sig; 28 | CHECK(secp256k1_ecdsa_recoverable_signature_parse_compact(data->ctx, &sig, data->sig, i % 2)); 29 | CHECK(secp256k1_ecdsa_recover(data->ctx, &pubkey, &sig, data->msg)); 30 | CHECK(secp256k1_ec_pubkey_serialize(data->ctx, pubkeyc, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED)); 31 | for (j = 0; j < 32; j++) { 32 | data->sig[j + 32] = data->msg[j]; /* Move former message to S. */ 33 | data->msg[j] = data->sig[j]; /* Move former R to message. */ 34 | data->sig[j] = pubkeyc[j + 1]; /* Move recovered pubkey X coordinate to R (which must be a valid X coordinate). */ 35 | } 36 | } 37 | } 38 | 39 | void bench_recover_setup(void* arg) { 40 | int i; 41 | bench_recover_t *data = (bench_recover_t*)arg; 42 | 43 | for (i = 0; i < 32; i++) { 44 | data->msg[i] = 1 + i; 45 | } 46 | for (i = 0; i < 64; i++) { 47 | data->sig[i] = 65 + i; 48 | } 49 | } 50 | 51 | int main(void) { 52 | bench_recover_t data; 53 | 54 | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY); 55 | 56 | run_benchmark("ecdsa_recover", bench_recover, bench_recover_setup, NULL, &data, 10, 20000); 57 | 58 | secp256k1_context_destroy(data.ctx); 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /src/libbtc/rpctest/test_framework/siphash.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) 2016 The Bitcoin Core developers 3 | # Distributed under the MIT software license, see the accompanying 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 | """Specialized SipHash-2-4 implementations. 6 | 7 | This implements SipHash-2-4 for 256-bit integers. 8 | """ 9 | 10 | def rotl64(n, b): 11 | return n >> (64 - b) | (n & ((1 << (64 - b)) - 1)) << b 12 | 13 | def siphash_round(v0, v1, v2, v3): 14 | v0 = (v0 + v1) & ((1 << 64) - 1) 15 | v1 = rotl64(v1, 13) 16 | v1 ^= v0 17 | v0 = rotl64(v0, 32) 18 | v2 = (v2 + v3) & ((1 << 64) - 1) 19 | v3 = rotl64(v3, 16) 20 | v3 ^= v2 21 | v0 = (v0 + v3) & ((1 << 64) - 1) 22 | v3 = rotl64(v3, 21) 23 | v3 ^= v0 24 | v2 = (v2 + v1) & ((1 << 64) - 1) 25 | v1 = rotl64(v1, 17) 26 | v1 ^= v2 27 | v2 = rotl64(v2, 32) 28 | return (v0, v1, v2, v3) 29 | 30 | def siphash256(k0, k1, h): 31 | n0 = h & ((1 << 64) - 1) 32 | n1 = (h >> 64) & ((1 << 64) - 1) 33 | n2 = (h >> 128) & ((1 << 64) - 1) 34 | n3 = (h >> 192) & ((1 << 64) - 1) 35 | v0 = 0x736f6d6570736575 ^ k0 36 | v1 = 0x646f72616e646f6d ^ k1 37 | v2 = 0x6c7967656e657261 ^ k0 38 | v3 = 0x7465646279746573 ^ k1 ^ n0 39 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 40 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 41 | v0 ^= n0 42 | v3 ^= n1 43 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 44 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 45 | v0 ^= n1 46 | v3 ^= n2 47 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 48 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 49 | v0 ^= n2 50 | v3 ^= n3 51 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 52 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 53 | v0 ^= n3 54 | v3 ^= 0x2000000000000000 55 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 56 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 57 | v0 ^= 0x2000000000000000 58 | v2 ^= 0xFF 59 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 60 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 61 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 62 | v0, v1, v2, v3 = siphash_round(v0, v1, v2, v3) 63 | return v0 ^ v1 ^ v2 ^ v3 64 | -------------------------------------------------------------------------------- /src/leveldb/util/arena.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/arena.h" 6 | #include 7 | 8 | namespace leveldb { 9 | 10 | static const int kBlockSize = 4096; 11 | 12 | Arena::Arena() : memory_usage_(0) { 13 | alloc_ptr_ = NULL; // First allocation will allocate a block 14 | alloc_bytes_remaining_ = 0; 15 | } 16 | 17 | Arena::~Arena() { 18 | for (size_t i = 0; i < blocks_.size(); i++) { 19 | delete[] blocks_[i]; 20 | } 21 | } 22 | 23 | char* Arena::AllocateFallback(size_t bytes) { 24 | if (bytes > kBlockSize / 4) { 25 | // Object is more than a quarter of our block size. Allocate it separately 26 | // to avoid wasting too much space in leftover bytes. 27 | char* result = AllocateNewBlock(bytes); 28 | return result; 29 | } 30 | 31 | // We waste the remaining space in the current block. 32 | alloc_ptr_ = AllocateNewBlock(kBlockSize); 33 | alloc_bytes_remaining_ = kBlockSize; 34 | 35 | char* result = alloc_ptr_; 36 | alloc_ptr_ += bytes; 37 | alloc_bytes_remaining_ -= bytes; 38 | return result; 39 | } 40 | 41 | char* Arena::AllocateAligned(size_t bytes) { 42 | const int align = (sizeof(void*) > 8) ? sizeof(void*) : 8; 43 | assert((align & (align-1)) == 0); // Pointer size should be a power of 2 44 | size_t current_mod = reinterpret_cast(alloc_ptr_) & (align-1); 45 | size_t slop = (current_mod == 0 ? 0 : align - current_mod); 46 | size_t needed = bytes + slop; 47 | char* result; 48 | if (needed <= alloc_bytes_remaining_) { 49 | result = alloc_ptr_ + slop; 50 | alloc_ptr_ += needed; 51 | alloc_bytes_remaining_ -= needed; 52 | } else { 53 | // AllocateFallback always returned aligned memory 54 | result = AllocateFallback(bytes); 55 | } 56 | assert((reinterpret_cast(result) & (align-1)) == 0); 57 | return result; 58 | } 59 | 60 | char* Arena::AllocateNewBlock(size_t block_bytes) { 61 | char* result = new char[block_bytes]; 62 | blocks_.push_back(result); 63 | memory_usage_.NoBarrier_Store( 64 | reinterpret_cast(MemoryUsage() + block_bytes + sizeof(char*))); 65 | return result; 66 | } 67 | 68 | } // namespace leveldb 69 | -------------------------------------------------------------------------------- /src/leveldb/util/testutil.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 6 | #define STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 7 | 8 | #include "leveldb/env.h" 9 | #include "leveldb/slice.h" 10 | #include "util/random.h" 11 | 12 | namespace leveldb { 13 | namespace test { 14 | 15 | // Store in *dst a random string of length "len" and return a Slice that 16 | // references the generated data. 17 | extern Slice RandomString(Random* rnd, int len, std::string* dst); 18 | 19 | // Return a random key with the specified length that may contain interesting 20 | // characters (e.g. \x00, \xff, etc.). 21 | extern std::string RandomKey(Random* rnd, int len); 22 | 23 | // Store in *dst a string of length "len" that will compress to 24 | // "N*compressed_fraction" bytes and return a Slice that references 25 | // the generated data. 26 | extern Slice CompressibleString(Random* rnd, double compressed_fraction, 27 | size_t len, std::string* dst); 28 | 29 | // A wrapper that allows injection of errors. 30 | class ErrorEnv : public EnvWrapper { 31 | public: 32 | bool writable_file_error_; 33 | int num_writable_file_errors_; 34 | 35 | ErrorEnv() : EnvWrapper(Env::Default()), 36 | writable_file_error_(false), 37 | num_writable_file_errors_(0) { } 38 | 39 | virtual Status NewWritableFile(const std::string& fname, 40 | WritableFile** result) { 41 | if (writable_file_error_) { 42 | ++num_writable_file_errors_; 43 | *result = NULL; 44 | return Status::IOError(fname, "fake error"); 45 | } 46 | return target()->NewWritableFile(fname, result); 47 | } 48 | 49 | virtual Status NewAppendableFile(const std::string& fname, 50 | WritableFile** result) { 51 | if (writable_file_error_) { 52 | ++num_writable_file_errors_; 53 | *result = NULL; 54 | return Status::IOError(fname, "fake error"); 55 | } 56 | return target()->NewAppendableFile(fname, result); 57 | } 58 | }; 59 | 60 | } // namespace test 61 | } // namespace leveldb 62 | 63 | #endif // STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 64 | -------------------------------------------------------------------------------- /src/libbtc/rpctest/test_framework/bignum.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Distributed under the MIT software license, see the accompanying 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 | """Big number routines. 6 | 7 | This file is copied from python-bitcoinlib. 8 | """ 9 | 10 | import struct 11 | 12 | 13 | # generic big endian MPI format 14 | 15 | def bn_bytes(v, have_ext=False): 16 | ext = 0 17 | if have_ext: 18 | ext = 1 19 | return ((v.bit_length()+7)//8) + ext 20 | 21 | def bn2bin(v): 22 | s = bytearray() 23 | i = bn_bytes(v) 24 | while i > 0: 25 | s.append((v >> ((i-1) * 8)) & 0xff) 26 | i -= 1 27 | return s 28 | 29 | def bin2bn(s): 30 | l = 0 31 | for ch in s: 32 | l = (l << 8) | ch 33 | return l 34 | 35 | def bn2mpi(v): 36 | have_ext = False 37 | if v.bit_length() > 0: 38 | have_ext = (v.bit_length() & 0x07) == 0 39 | 40 | neg = False 41 | if v < 0: 42 | neg = True 43 | v = -v 44 | 45 | s = struct.pack(b">I", bn_bytes(v, have_ext)) 46 | ext = bytearray() 47 | if have_ext: 48 | ext.append(0) 49 | v_bin = bn2bin(v) 50 | if neg: 51 | if have_ext: 52 | ext[0] |= 0x80 53 | else: 54 | v_bin[0] |= 0x80 55 | return s + ext + v_bin 56 | 57 | def mpi2bn(s): 58 | if len(s) < 4: 59 | return None 60 | s_size = bytes(s[:4]) 61 | v_len = struct.unpack(b">I", s_size)[0] 62 | if len(s) != (v_len + 4): 63 | return None 64 | if v_len == 0: 65 | return 0 66 | 67 | v_str = bytearray(s[4:]) 68 | neg = False 69 | i = v_str[0] 70 | if i & 0x80: 71 | neg = True 72 | i &= ~0x80 73 | v_str[0] = i 74 | 75 | v = bin2bn(v_str) 76 | 77 | if neg: 78 | return -v 79 | return v 80 | 81 | # bitcoin-specific little endian format, with implicit size 82 | def mpi2vch(s): 83 | r = s[4:] # strip size 84 | r = r[::-1] # reverse string, converting BE->LE 85 | return r 86 | 87 | def bn2vch(v): 88 | return bytes(mpi2vch(bn2mpi(v))) 89 | 90 | def vch2mpi(s): 91 | r = struct.pack(b">I", len(s)) # size 92 | r += s[::-1] # reverse string, converting LE->BE 93 | return r 94 | 95 | def vch2bn(s): 96 | return mpi2bn(vch2mpi(s)) 97 | 98 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018 Jonas Schnelli 2 | # Distributed under the MIT software license, see the accompanying 3 | # file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | DIST_SUBDIRS = univalue libbtc 6 | 7 | AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) 8 | AM_CXXFLAGS = $(HARDENED_CXXFLAGS) $(ERROR_CXXFLAGS) 9 | AM_CPPFLAGS = $(HARDENED_CPPFLAGS) 10 | EXTRA_LIBRARIES = 11 | 12 | if EMBEDDED_UNIVALUE 13 | LIBUNIVALUE = univalue/libunivalue.la 14 | 15 | $(LIBUNIVALUE): $(wildcard univalue/lib/*) $(wildcard univalue/include/*) 16 | $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) 17 | else 18 | LIBUNIVALUE = $(UNIVALUE_LIBS) 19 | endif 20 | 21 | LIBBTC = libbtc/libbtc.la 22 | $(LIBBTC): $(wildcard libbtc/src/*) $(wildcard univalue/include/*) 23 | $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) 24 | 25 | bin_PROGRAMS = bitcoincore-indexd 26 | 27 | BITCOINCORE_INDEXD_H = \ 28 | btcnode.h \ 29 | compat.h \ 30 | dbinterface.h \ 31 | hash.h \ 32 | httpserver.h \ 33 | logging.h \ 34 | netaddress.h \ 35 | shutdown.h \ 36 | sync.h \ 37 | threadsafety.h \ 38 | tinyformat.h \ 39 | utils.h 40 | 41 | DATABASE_LEVELDB_SOURCES = \ 42 | db_leveldb.h \ 43 | db_leveldb.cpp 44 | 45 | BITCOINCORE_INDEXD_SOURCES = \ 46 | btcnode.cpp \ 47 | httpserver.cpp \ 48 | logging.cpp \ 49 | main.cpp \ 50 | netaddress.cpp \ 51 | shutdown.cpp \ 52 | sync.cpp \ 53 | utils.cpp \ 54 | $(BITCOINCORE_INDEXD_H) \ 55 | $(DATABASE_LEVELDB_SOURCES) 56 | 57 | # application binary # 58 | bitcoincore_indexd_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir) $(UNIVALUE_CFLAGS) $(LIBUNIVALUE_CFLAGS) $(LIBBTC_CFLAGS) $(LEVELDB_CPPFLAGS) 59 | bitcoincore_indexd_CXXFLAGS = $(AM_CXXFLAGS) 60 | bitcoincore_indexd_SOURCES = $(BITCOINCORE_INDEXD_SOURCES) 61 | bitcoincore_indexd_LDADD = $(LIBUNIVALUE) $(LIBBTC) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) 62 | bitcoincore_indexd_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) 63 | bitcoincore_indexd_LIBTOOLFLAGS = --tag CXX 64 | 65 | 66 | clean-local: 67 | -$(MAKE) -C univalue clean 68 | -$(MAKE) -C libbtc clean 69 | -rm -f leveldb/*/*.gcda leveldb/*/*.gcno leveldb/helpers/memenv/*.gcda leveldb/helpers/memenv/*.gcno 70 | -rm -f config.h 71 | 72 | include Makefile.leveldb.include 73 | -------------------------------------------------------------------------------- /src/leveldb/table/iterator_wrapper.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 6 | #define STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 7 | 8 | #include "leveldb/iterator.h" 9 | #include "leveldb/slice.h" 10 | 11 | namespace leveldb { 12 | 13 | // A internal wrapper class with an interface similar to Iterator that 14 | // caches the valid() and key() results for an underlying iterator. 15 | // This can help avoid virtual function calls and also gives better 16 | // cache locality. 17 | class IteratorWrapper { 18 | public: 19 | IteratorWrapper(): iter_(NULL), valid_(false) { } 20 | explicit IteratorWrapper(Iterator* iter): iter_(NULL) { 21 | Set(iter); 22 | } 23 | ~IteratorWrapper() { delete iter_; } 24 | Iterator* iter() const { return iter_; } 25 | 26 | // Takes ownership of "iter" and will delete it when destroyed, or 27 | // when Set() is invoked again. 28 | void Set(Iterator* iter) { 29 | delete iter_; 30 | iter_ = iter; 31 | if (iter_ == NULL) { 32 | valid_ = false; 33 | } else { 34 | Update(); 35 | } 36 | } 37 | 38 | 39 | // Iterator interface methods 40 | bool Valid() const { return valid_; } 41 | Slice key() const { assert(Valid()); return key_; } 42 | Slice value() const { assert(Valid()); return iter_->value(); } 43 | // Methods below require iter() != NULL 44 | Status status() const { assert(iter_); return iter_->status(); } 45 | void Next() { assert(iter_); iter_->Next(); Update(); } 46 | void Prev() { assert(iter_); iter_->Prev(); Update(); } 47 | void Seek(const Slice& k) { assert(iter_); iter_->Seek(k); Update(); } 48 | void SeekToFirst() { assert(iter_); iter_->SeekToFirst(); Update(); } 49 | void SeekToLast() { assert(iter_); iter_->SeekToLast(); Update(); } 50 | 51 | private: 52 | void Update() { 53 | valid_ = iter_->Valid(); 54 | if (valid_) { 55 | key_ = iter_->key(); 56 | } 57 | } 58 | 59 | Iterator* iter_; 60 | bool valid_; 61 | Slice key_; 62 | }; 63 | 64 | } // namespace leveldb 65 | 66 | #endif // STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 67 | -------------------------------------------------------------------------------- /src/libbtc/include/btc/tool.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Jonas Schnelli 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #ifndef __LIBBTC_TOOL_H__ 28 | #define __LIBBTC_TOOL_H__ 29 | 30 | #include "btc.h" 31 | #include "tx.h" 32 | 33 | LIBBTC_BEGIN_DECL 34 | 35 | /* generate the p2pkh address from a given hex pubkey */ 36 | LIBBTC_API btc_bool addresses_from_pubkey(const btc_chainparams* chain, const char* pubkey_hex, char* p2pkh_address, char* p2sh_p2wpkh_address, char *p2wpkh_address); 37 | 38 | /* generate the hex publickey from a given hex private key */ 39 | LIBBTC_API btc_bool pubkey_from_privatekey(const btc_chainparams* chain, const char* privkey_hex, char* pubkey_hex, size_t* sizeout); 40 | 41 | /* generate a new private key (hex) */ 42 | LIBBTC_API btc_bool gen_privatekey(const btc_chainparams* chain, char* privkey_wif, size_t strsize_wif, char* privkey_hex); 43 | 44 | LIBBTC_API btc_bool hd_gen_master(const btc_chainparams* chain, char* masterkeyhex, size_t strsize); 45 | LIBBTC_API btc_bool hd_print_node(const btc_chainparams* chain, const char* nodeser); 46 | LIBBTC_API btc_bool hd_derive(const btc_chainparams* chain, const char* masterkey, const char* keypath, char* extkeyout, size_t extkeyout_size); 47 | 48 | LIBBTC_END_DECL 49 | 50 | #endif // __LIBBTC_TOOL_H__ 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # External transaction index for Bitcoin Core 2 | 3 | [![Build Status](https://travis-ci.org/jonasschnelli/bitcoincore-indexd.svg?branch=master)](https://travis-ci.org/jonasschnelli/bitcoincore-indexd) 4 | 5 | ### Status 6 | This project is still experimental, use at your own risk! 7 | 8 | ### How does it work 9 | The indexer connects to a fullnode over the p2p protocol (at the moment 127.0.0.1:8333 mainnet) and performs the following actions: 10 | * opens database 11 | * connect to the peer 12 | * sync all headers, find unindexed blocks 13 | * requests blocks that are not yet indexed 14 | * index all found transactions txid->blockhash 15 | * once all blocks (found via header) has been requested, idle for new inv/block messaged 16 | 17 | ### Be aware! 18 | The indexer trusts the remote peer! Only connect to a trusted peer, ideally via localhost. 19 | If you connect via the public internet, make sure you connect through a secure channel. 20 | 21 | ### Database 22 | * The indexer currently works only with leveldb (there was a LMDB implementation, check git history). 23 | * In order to save space, each block will get an internal blockmap-key (uint32 / 4bytes). That internal blockmap-key must not be confused with the block-height. The blockmap-key may be different on other systems/instances. 24 | 25 | ### Space requirements 26 | * ~14.3GB up to block 522081 (May 10th 2018) 27 | * complete index up to 522081 takes about ~60min on a fast CPU with SSD 28 | 29 | ### REST interface 30 | * Lookup can be done via HTTP 18445 31 | * Two endpoints 32 | ** `/blockhash/` will return the blockhash of the requested transaction id 33 | ** `/tx/` will return the transaction of the requested txid (will fetch the relevant block via p2p and return the tx) 34 | 35 | ### TODO: 36 | * Reduce memory usage with internal header maps 37 | * Lookup should also respect the non-flushed cache 38 | * Make sure that incoming block invs during sync-via-headers do not confuse the indexer 39 | * Add file based logging 40 | * Add runtime option to switch network (testnet, regtest) and the IP to connect to 41 | 42 | ### Build 43 | ```shell 44 | ./autogen.sh 45 | ./configure 46 | make -j 47 | ``` 48 | 49 | ### run 50 | `./src/bitcoincore-indexd` 51 | 52 | Options 53 | * `./src/bitcoincore-indexd --datadir=/tmp` (change datadir, default is ~/.bitcoincore-indexd) 54 | * `./src/bitcoincore-indexd --dbcache=xxx` (change the leveldb dbcache) -------------------------------------------------------------------------------- /src/leveldb/util/env_posix_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/env.h" 6 | 7 | #include "port/port.h" 8 | #include "util/testharness.h" 9 | #include "util/env_posix_test_helper.h" 10 | 11 | namespace leveldb { 12 | 13 | static const int kDelayMicros = 100000; 14 | static const int kReadOnlyFileLimit = 4; 15 | static const int kMMapLimit = 4; 16 | 17 | class EnvPosixTest { 18 | public: 19 | Env* env_; 20 | EnvPosixTest() : env_(Env::Default()) { } 21 | 22 | static void SetFileLimits(int read_only_file_limit, int mmap_limit) { 23 | EnvPosixTestHelper::SetReadOnlyFDLimit(read_only_file_limit); 24 | EnvPosixTestHelper::SetReadOnlyMMapLimit(mmap_limit); 25 | } 26 | }; 27 | 28 | TEST(EnvPosixTest, TestOpenOnRead) { 29 | // Write some test data to a single file that will be opened |n| times. 30 | std::string test_dir; 31 | ASSERT_OK(env_->GetTestDirectory(&test_dir)); 32 | std::string test_file = test_dir + "/open_on_read.txt"; 33 | 34 | FILE* f = fopen(test_file.c_str(), "w"); 35 | ASSERT_TRUE(f != NULL); 36 | const char kFileData[] = "abcdefghijklmnopqrstuvwxyz"; 37 | fputs(kFileData, f); 38 | fclose(f); 39 | 40 | // Open test file some number above the sum of the two limits to force 41 | // open-on-read behavior of POSIX Env leveldb::RandomAccessFile. 42 | const int kNumFiles = kReadOnlyFileLimit + kMMapLimit + 5; 43 | leveldb::RandomAccessFile* files[kNumFiles] = {0}; 44 | for (int i = 0; i < kNumFiles; i++) { 45 | ASSERT_OK(env_->NewRandomAccessFile(test_file, &files[i])); 46 | } 47 | char scratch; 48 | Slice read_result; 49 | for (int i = 0; i < kNumFiles; i++) { 50 | ASSERT_OK(files[i]->Read(i, 1, &read_result, &scratch)); 51 | ASSERT_EQ(kFileData[i], read_result[0]); 52 | } 53 | for (int i = 0; i < kNumFiles; i++) { 54 | delete files[i]; 55 | } 56 | ASSERT_OK(env_->DeleteFile(test_file)); 57 | } 58 | 59 | } // namespace leveldb 60 | 61 | int main(int argc, char** argv) { 62 | // All tests currently run with the same read-only file limits. 63 | leveldb::EnvPosixTest::SetFileLimits(leveldb::kReadOnlyFileLimit, 64 | leveldb::kMMapLimit); 65 | return leveldb::test::RunAllTests(); 66 | } 67 | -------------------------------------------------------------------------------- /src/libbtc/src/logdb/include/logdb/logdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Jonas Schnelli 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | /* 29 | File Format 30 | 31 | [8 bytes] per file magic 0xF9, 0xAA, 0x03, 0xBA 32 | [int32_t/4 bytes] version number 33 | [int32_t/4 bytes] version flags 34 | ---- records 35 | [8 bytes] static per record magic 0x88, 0x61, 0xAD, 0xFC, 0x5A, 0x11, 0x22, 0xF8 36 | [16 bytes] partial sha256 hash (first 16 bytes) of the record body 37 | ---- record-body start ---- 38 | [1 byte] record type (0 = write | 1 = erase) 39 | [varint] length of the key 40 | [variable] key data 41 | [varint] length of the value 42 | [variable] value data 43 | ---- record-body end ---- 44 | [16 bytes] partial sha256 of *all data* up to this point in logdb 45 | ---- record end --- 46 | ---- more records 47 | */ 48 | 49 | #ifndef __LIBLOGDB_H__ 50 | #define __LIBLOGDB_H__ 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | #include 57 | 58 | #include 59 | #include 60 | #include 61 | #include 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* __LIBLOGDB_H__ */ 68 | -------------------------------------------------------------------------------- /src/leveldb/util/random.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_RANDOM_H_ 6 | #define STORAGE_LEVELDB_UTIL_RANDOM_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | // A very simple random number generator. Not especially good at 13 | // generating truly random bits, but good enough for our needs in this 14 | // package. 15 | class Random { 16 | private: 17 | uint32_t seed_; 18 | public: 19 | explicit Random(uint32_t s) : seed_(s & 0x7fffffffu) { 20 | // Avoid bad seeds. 21 | if (seed_ == 0 || seed_ == 2147483647L) { 22 | seed_ = 1; 23 | } 24 | } 25 | uint32_t Next() { 26 | static const uint32_t M = 2147483647L; // 2^31-1 27 | static const uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0 28 | // We are computing 29 | // seed_ = (seed_ * A) % M, where M = 2^31-1 30 | // 31 | // seed_ must not be zero or M, or else all subsequent computed values 32 | // will be zero or M respectively. For all other values, seed_ will end 33 | // up cycling through every number in [1,M-1] 34 | uint64_t product = seed_ * A; 35 | 36 | // Compute (product % M) using the fact that ((x << 31) % M) == x. 37 | seed_ = static_cast((product >> 31) + (product & M)); 38 | // The first reduction may overflow by 1 bit, so we may need to 39 | // repeat. mod == M is not possible; using > allows the faster 40 | // sign-bit-based test. 41 | if (seed_ > M) { 42 | seed_ -= M; 43 | } 44 | return seed_; 45 | } 46 | // Returns a uniformly distributed value in the range [0..n-1] 47 | // REQUIRES: n > 0 48 | uint32_t Uniform(int n) { return Next() % n; } 49 | 50 | // Randomly returns true ~"1/n" of the time, and false otherwise. 51 | // REQUIRES: n > 0 52 | bool OneIn(int n) { return (Next() % n) == 0; } 53 | 54 | // Skewed: pick "base" uniformly from range [0,max_log] and then 55 | // return "base" random bits. The effect is to pick a number in the 56 | // range [0,2^max_log-1] with exponential bias towards smaller numbers. 57 | uint32_t Skewed(int max_log) { 58 | return Uniform(1 << Uniform(max_log + 1)); 59 | } 60 | }; 61 | 62 | } // namespace leveldb 63 | 64 | #endif // STORAGE_LEVELDB_UTIL_RANDOM_H_ 65 | -------------------------------------------------------------------------------- /src/univalue/configure.ac: -------------------------------------------------------------------------------- 1 | m4_define([libunivalue_major_version], [1]) 2 | m4_define([libunivalue_minor_version], [1]) 3 | m4_define([libunivalue_micro_version], [3]) 4 | m4_define([libunivalue_interface_age], [3]) 5 | # If you need a modifier for the version number. 6 | # Normally empty, but can be used to make "fixup" releases. 7 | m4_define([libunivalue_extraversion], []) 8 | 9 | dnl libtool versioning from libunivalue 10 | m4_define([libunivalue_current], [m4_eval(100 * libunivalue_minor_version + libunivalue_micro_version - libunivalue_interface_age)]) 11 | m4_define([libunivalue_binary_age], [m4_eval(100 * libunivalue_minor_version + libunivalue_micro_version)]) 12 | m4_define([libunivalue_revision], [libunivalue_interface_age]) 13 | m4_define([libunivalue_age], [m4_eval(libunivalue_binary_age - libunivalue_interface_age)]) 14 | m4_define([libunivalue_version], [libunivalue_major_version().libunivalue_minor_version().libunivalue_micro_version()libunivalue_extraversion()]) 15 | 16 | 17 | AC_INIT([univalue], [1.0.3], 18 | [http://github.com/jgarzik/univalue/]) 19 | 20 | dnl make the compilation flags quiet unless V=1 is used 21 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 22 | 23 | AC_PREREQ(2.60) 24 | AC_CONFIG_SRCDIR([lib/univalue.cpp]) 25 | AC_CONFIG_AUX_DIR([build-aux]) 26 | AC_CONFIG_MACRO_DIR([build-aux/m4]) 27 | AC_CONFIG_HEADERS([univalue-config.h]) 28 | AM_INIT_AUTOMAKE([subdir-objects foreign]) 29 | 30 | LIBUNIVALUE_MAJOR_VERSION=libunivalue_major_version 31 | LIBUNIVALUE_MINOR_VERSION=libunivalue_minor_version 32 | LIBUNIVALUE_MICRO_VERSION=libunivalue_micro_version 33 | LIBUNIVALUE_INTERFACE_AGE=libunivalue_interface_age 34 | 35 | # ABI version 36 | # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html 37 | LIBUNIVALUE_CURRENT=libunivalue_current 38 | LIBUNIVALUE_REVISION=libunivalue_revision 39 | LIBUNIVALUE_AGE=libunivalue_age 40 | 41 | AC_SUBST(LIBUNIVALUE_CURRENT) 42 | AC_SUBST(LIBUNIVALUE_REVISION) 43 | AC_SUBST(LIBUNIVALUE_AGE) 44 | 45 | LT_INIT 46 | LT_LANG([C++]) 47 | 48 | case $host in 49 | *mingw*) 50 | LIBTOOL_APP_LDFLAGS="$LIBTOOL_APP_LDFLAGS -all-static" 51 | ;; 52 | esac 53 | 54 | BUILD_EXEEXT= 55 | case $build in 56 | *mingw*) 57 | BUILD_EXEEXT=".exe" 58 | ;; 59 | esac 60 | 61 | AC_CONFIG_FILES([ 62 | Makefile 63 | pc/libunivalue.pc 64 | pc/libunivalue-uninstalled.pc]) 65 | 66 | AC_SUBST(LIBTOOL_APP_LDFLAGS) 67 | AC_SUBST(BUILD_EXEEXT) 68 | AC_OUTPUT 69 | 70 | -------------------------------------------------------------------------------- /src/libbtc/src/secp256k1/src/ecmult_gen.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECMULT_GEN_ 8 | #define _SECP256K1_ECMULT_GEN_ 9 | 10 | #include "scalar.h" 11 | #include "group.h" 12 | 13 | typedef struct { 14 | /* For accelerating the computation of a*G: 15 | * To harden against timing attacks, use the following mechanism: 16 | * * Break up the multiplicand into groups of 4 bits, called n_0, n_1, n_2, ..., n_63. 17 | * * Compute sum(n_i * 16^i * G + U_i, i=0..63), where: 18 | * * U_i = U * 2^i (for i=0..62) 19 | * * U_i = U * (1-2^63) (for i=63) 20 | * where U is a point with no known corresponding scalar. Note that sum(U_i, i=0..63) = 0. 21 | * For each i, and each of the 16 possible values of n_i, (n_i * 16^i * G + U_i) is 22 | * precomputed (call it prec(i, n_i)). The formula now becomes sum(prec(i, n_i), i=0..63). 23 | * None of the resulting prec group elements have a known scalar, and neither do any of 24 | * the intermediate sums while computing a*G. 25 | */ 26 | secp256k1_ge_storage (*prec)[64][16]; /* prec[j][i] = 16^j * i * G + U_i */ 27 | secp256k1_scalar blind; 28 | secp256k1_gej initial; 29 | } secp256k1_ecmult_gen_context; 30 | 31 | static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context* ctx); 32 | static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context* ctx, const secp256k1_callback* cb); 33 | static void secp256k1_ecmult_gen_context_clone(secp256k1_ecmult_gen_context *dst, 34 | const secp256k1_ecmult_gen_context* src, const secp256k1_callback* cb); 35 | static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context* ctx); 36 | static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context* ctx); 37 | 38 | /** Multiply with the generator: R = a*G */ 39 | static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context* ctx, secp256k1_gej *r, const secp256k1_scalar *a); 40 | 41 | static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const unsigned char *seed32); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/libbtc/include/btc/chainparams.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015 Jonas Schnelli 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #ifndef __LIBBTC_CHAINPARAMS_H__ 28 | #define __LIBBTC_CHAINPARAMS_H__ 29 | 30 | #include "btc.h" 31 | 32 | LIBBTC_BEGIN_DECL 33 | 34 | typedef struct btc_dns_seed_ { 35 | char domain[256]; 36 | } btc_dns_seed; 37 | 38 | typedef struct btc_chainparams_ { 39 | char chainname[32]; 40 | uint8_t b58prefix_pubkey_address; 41 | uint8_t b58prefix_script_address; 42 | const char bech32_hrp[5]; 43 | uint8_t b58prefix_secret_address; //!private key 44 | uint32_t b58prefix_bip32_privkey; 45 | uint32_t b58prefix_bip32_pubkey; 46 | const unsigned char netmagic[4]; 47 | uint256 genesisblockhash; 48 | int default_port; 49 | btc_dns_seed dnsseeds[8]; 50 | } btc_chainparams; 51 | 52 | typedef struct btc_checkpoint_ { 53 | uint32_t height; 54 | const char* hash; 55 | uint32_t timestamp; 56 | uint32_t target; 57 | } btc_checkpoint; 58 | 59 | extern const btc_chainparams btc_chainparams_main; 60 | extern const btc_chainparams btc_chainparams_test; 61 | extern const btc_chainparams btc_chainparams_regtest; 62 | 63 | // the mainnet checkpoins, needs a fix size 64 | extern const btc_checkpoint btc_mainnet_checkpoint_array[21]; 65 | 66 | LIBBTC_END_DECL 67 | 68 | #endif // __LIBBTC_CHAINPARAMS_H__ 69 | --------------------------------------------------------------------------------