├── LICENSE ├── ccan ├── .gitignore ├── ccan │ ├── alignof │ │ ├── LICENSE │ │ └── alignof.h │ ├── endian │ │ ├── LICENSE │ │ └── test │ │ │ └── compile_ok-constant.c │ ├── err │ │ ├── LICENSE │ │ └── _info │ ├── hash │ │ ├── LICENSE │ │ └── _info │ ├── ilog │ │ └── LICENSE │ ├── io │ │ ├── LICENSE │ │ ├── test │ │ │ ├── run-02-read-debug.c │ │ │ ├── run-05-write-debug.c │ │ │ ├── run-07-break-debug.c │ │ │ ├── run-12-bidir-debug.c │ │ │ ├── run-18-errno-debug.c │ │ │ ├── run-19-always-debug.c │ │ │ ├── run-09-connect-debug.c │ │ │ ├── run-03-readpartial-debug.c │ │ │ ├── run-16-duplex-test-debug.c │ │ │ ├── run-17-homemade-io-debug.c │ │ │ ├── run-01-start-finish-debug.c │ │ │ ├── run-04-writepartial-debug.c │ │ │ ├── run-14-duplex-both-read-debug.c │ │ │ ├── run-13-all-idle.c │ │ │ └── run-08-read-after-hangup.c │ │ └── benchmarks │ │ │ └── Makefile │ ├── isaac │ │ └── LICENSE │ ├── likely │ │ ├── LICENSE │ │ └── test │ │ │ └── run.c │ ├── net │ │ ├── LICENSE │ │ └── tools │ │ │ └── Makefile │ ├── noerr │ │ ├── LICENSE │ │ ├── noerr.c │ │ └── noerr.h │ ├── opt │ │ ├── LICENSE │ │ ├── test │ │ │ ├── compile_ok-const-arg.c │ │ │ ├── utils.h │ │ │ └── run-no-options.c │ │ └── private.h │ ├── str │ │ ├── LICENSE │ │ ├── test │ │ │ ├── debug.c │ │ │ ├── compile_fail-strchr.c │ │ │ ├── compile_fail-strrchr.c │ │ │ ├── compile_fail-strstr.c │ │ │ ├── compile_fail-STR_MAX_CHARS.c │ │ │ ├── compile_fail-isalnum.c │ │ │ ├── compile_fail-isalpha.c │ │ │ ├── compile_fail-isascii.c │ │ │ ├── compile_fail-iscntrl.c │ │ │ ├── compile_fail-isdigit.c │ │ │ ├── compile_fail-islower.c │ │ │ ├── compile_fail-isprint.c │ │ │ ├── compile_fail-ispunct.c │ │ │ ├── compile_fail-isspace.c │ │ │ ├── compile_fail-isupper.c │ │ │ ├── compile_fail-isxdigit.c │ │ │ └── compile_fail-isblank.c │ │ ├── str.c │ │ └── str_debug.h │ ├── take │ │ └── LICENSE │ ├── tal │ │ ├── LICENSE │ │ ├── link │ │ │ └── LICENSE │ │ ├── path │ │ │ ├── LICENSE │ │ │ ├── path │ │ │ │ ├── LICENSE │ │ │ │ └── test │ │ │ │ │ ├── run-is_abs.c │ │ │ │ │ ├── run-ext_off.c │ │ │ │ │ ├── run-cwd.c │ │ │ │ │ ├── run-is_dir.c │ │ │ │ │ └── run-is_file.c │ │ │ └── test │ │ │ │ ├── run-is_abs.c │ │ │ │ ├── run-ext_off.c │ │ │ │ ├── run-cwd.c │ │ │ │ ├── run-is_dir.c │ │ │ │ └── run-is_file.c │ │ ├── str │ │ │ ├── LICENSE │ │ │ ├── str │ │ │ │ ├── LICENSE │ │ │ │ └── test │ │ │ │ │ ├── helper.h │ │ │ │ │ └── run-take.c │ │ │ └── test │ │ │ │ ├── helper.h │ │ │ │ └── run-take.c │ │ ├── talloc │ │ │ ├── LICENSE │ │ │ ├── talloc │ │ │ │ ├── LICENSE │ │ │ │ ├── test │ │ │ │ │ ├── run-free.c │ │ │ │ │ ├── run-count.c │ │ │ │ │ ├── run-named-nolabels.c │ │ │ │ │ ├── run-named.c │ │ │ │ │ ├── run-expand.c │ │ │ │ │ ├── run-named-debug.c │ │ │ │ │ ├── run.c │ │ │ │ │ ├── run-array.c │ │ │ │ │ ├── run-steal.c │ │ │ │ │ └── run-take.c │ │ │ │ └── _info │ │ │ ├── test │ │ │ │ ├── run-free.c │ │ │ │ ├── run-count.c │ │ │ │ ├── run-named-nolabels.c │ │ │ │ ├── run-expand.c │ │ │ │ ├── run-named.c │ │ │ │ ├── run-named-debug.c │ │ │ │ ├── run.c │ │ │ │ ├── run-array.c │ │ │ │ ├── run-steal.c │ │ │ │ └── run-take.c │ │ │ └── _info │ │ ├── grab_file │ │ │ ├── LICENSE │ │ │ └── test │ │ │ │ └── run-grab.c │ │ ├── str-Makefile │ │ ├── link-Makefile │ │ ├── path-Makefile │ │ ├── grab_file-Makefile │ │ ├── test │ │ │ ├── run-free.c │ │ │ ├── run-resizez.c │ │ │ ├── run-expand.c │ │ │ ├── run-iter.c │ │ │ ├── run-named-nolabels.c │ │ │ ├── run-named.c │ │ │ ├── run-named-debug.c │ │ │ ├── run-array.c │ │ │ ├── run-steal.c │ │ │ ├── run-groups-grow.c │ │ │ ├── run-take.c │ │ │ └── run.c │ │ └── benchmark │ │ │ └── Makefile │ ├── tcon │ │ ├── LICENSE │ │ └── test │ │ │ ├── compile_fail.c │ │ │ ├── compile_ok-void.c │ │ │ ├── compile_fail-tcon_cast.c │ │ │ └── compile_ok.c │ ├── array_size │ │ ├── LICENSE │ │ ├── test │ │ │ ├── compile_fail.c │ │ │ ├── compile_fail-function-param.c │ │ │ └── run.c │ │ ├── array_size.h │ │ └── _info │ ├── asort │ │ ├── LICENSE │ │ ├── test │ │ │ └── compile_fail-context-type.c │ │ └── asort.h │ ├── bitmap │ │ ├── LICENSE │ │ └── _info │ ├── breakpoint │ │ ├── LICENSE │ │ ├── test │ │ │ └── run.c │ │ ├── breakpoint.h │ │ ├── _info │ │ └── breakpoint.c │ ├── build_assert │ │ ├── LICENSE │ │ └── test │ │ │ ├── compile_ok.c │ │ │ ├── compile_fail.c │ │ │ ├── compile_fail-expr.c │ │ │ └── run-BUILD_ASSERT_OR_ZERO.c │ ├── cast │ │ ├── LICENSE │ │ └── test │ │ │ ├── compile_ok-cast_void.c │ │ │ ├── compile_ok-static.c │ │ │ ├── compile_fail-cast_signed.c │ │ │ ├── compile_fail-cast_static-3.c │ │ │ ├── compile_fail-cast_static-2.c │ │ │ ├── compile_fail-cast_static.c │ │ │ ├── compile_fail-cast_signed-const.c │ │ │ ├── compile_fail-cast_const.c │ │ │ ├── compile_fail-cast_const2.c │ │ │ ├── compile_fail-cast_const3.c │ │ │ └── compile_fail-cast_signed-sizesame.c │ ├── cdump │ │ ├── LICENSE │ │ ├── tools │ │ │ └── .gitignore │ │ └── test │ │ │ ├── run-enum-comma.c │ │ │ └── run-forward-decl.c │ ├── check_type │ │ ├── LICENSE │ │ ├── test │ │ │ ├── compile_fail-check_type.c │ │ │ ├── compile_fail-check_types_match.c │ │ │ ├── compile_fail-check_type_unsigned.c │ │ │ └── run.c │ │ └── _info │ ├── compiler │ │ ├── LICENSE │ │ └── test │ │ │ ├── run-is_compile_constant.c │ │ │ └── compile_fail-printf.c │ ├── container_of │ │ ├── LICENSE │ │ └── test │ │ │ ├── compile_fail-bad-type.c │ │ │ ├── compile_fail-types.c │ │ │ ├── compile_fail-var-types.c │ │ │ └── run.c │ ├── htable │ │ ├── LICENSE │ │ ├── test │ │ │ └── run-size.c │ │ └── tools │ │ │ └── Makefile │ ├── list │ │ ├── LICENSE │ │ ├── test │ │ │ ├── run-with-debug.c │ │ │ ├── helper.h │ │ │ ├── run-check-nonconst.c │ │ │ ├── run-list_del_from-assert.c │ │ │ └── compile_ok-constant.c │ │ └── list.c │ ├── short_types │ │ ├── LICENSE │ │ ├── test │ │ │ ├── run-endian.c │ │ │ └── run.c │ │ └── short_types.h │ ├── structeq │ │ ├── LICENSE │ │ ├── test │ │ │ ├── compile_fail-different.c │ │ │ └── run.c │ │ ├── structeq.h │ │ └── _info │ ├── time │ │ ├── LICENSE │ │ └── test │ │ │ └── run-monotonic.c │ ├── timer │ │ ├── LICENSE │ │ ├── benchmarks │ │ │ ├── Makefile │ │ │ └── benchmark.c │ │ └── test │ │ │ ├── run-expiry.c │ │ │ └── run-ff.c │ ├── typesafe_cb │ │ ├── LICENSE │ │ └── test │ │ │ ├── compile_ok-typesafe_cb-NULL.c │ │ │ ├── compile_fail-cast_if_type-promotable.c │ │ │ ├── compile_fail-typesafe_cb_cast.c │ │ │ ├── compile_fail-typesafe_cb-int.c │ │ │ ├── compile_fail-typesafe_cb_postargs.c │ │ │ ├── compile_fail-typesafe_cb_preargs.c │ │ │ ├── compile_fail-typesafe_cb_cast-multi.c │ │ │ ├── compile_fail-typesafe_cb.c │ │ │ ├── compile_ok-typesafe_cb_cast.c │ │ │ └── compile_ok-typesafe_cb-undefined.c │ ├── read_write_all │ │ ├── LICENSE │ │ ├── read_write_all.h │ │ ├── read_write_all.c │ │ └── _info │ └── strmap │ │ └── test │ │ └── run-iterate-const.c ├── README └── licenses │ └── BSD-MIT ├── CC0-for-protocol-headers ├── test ├── blackbox │ ├── .gitignore │ ├── test-01-blockfile1.xz │ ├── test-01-blockfile2.xz │ ├── test-issue-20-dumbwallet-import.sh │ └── Makefile ├── standalone │ ├── .gitignore │ ├── Makefile │ ├── run_local.sh │ └── simple_inject.sh ├── vg-suppressions ├── helper_gateway_key.h ├── helper_key.h ├── helper_fakenewstate.h ├── .gitignore ├── run-01-base16.c └── mockup.sh ├── tools ├── .gitignore ├── Makefile ├── gateway-report.sh ├── update-ccan.sh └── cdump-enum-names.c ├── web ├── Makefile ├── images │ └── who-has-time-and-skill-to-make-a-decent-pettycoin-logo.png └── stylesheets │ └── pettycoin.css ├── .travis.yml ├── genesis.h ├── pseudorand.h ├── gateways.c ├── jsmn ├── SOURCE ├── Makefile └── LICENSE ├── pettycoin_dir.h ├── gateways.h ├── .gitignore ├── generate.h ├── version.h ├── prev_blocks.h ├── signature.h ├── create_refs.h ├── json_add_tx.h ├── overflows.h ├── hash_block.h ├── recv_tx.h ├── tx_cmp.h ├── generating.h ├── features.h ├── blockfile.h ├── merkle_hashes.h ├── sslerrorstring.h ├── horizon.h ├── timeout.c ├── valgrind.h ├── addr.h ├── dns.h ├── horizon.c ├── timestamp.h ├── peer_wants.h ├── welcome.h ├── pkt_names.h ├── ecode_names.h ├── reward.h ├── hex.h ├── pseudorand.c ├── merkle_hashes.c ├── merkle_txs.h ├── shadouble.h ├── detached_block.h ├── shard.c ├── merkle_recurse.h ├── netaddr.h ├── petty-addr.c ├── prev_blocks.c ├── timeout.h ├── shadouble.c ├── proof.h ├── hash_tx.h ├── prev_txhashes.h ├── shard.h ├── pettycoin_dir.c ├── sync.h ├── doc └── DUMB-WALLET.md ├── features.c ├── merkle_txs.c ├── hash_tx.c ├── peer_wants.c ├── input_refs.h ├── packet_io.h ├── timestamp.c ├── create_tx.h ├── tal_arr.h ├── merkle_recurse.c └── hash_block.c /LICENSE: -------------------------------------------------------------------------------- 1 | ccan/licenses/LGPL-3 -------------------------------------------------------------------------------- /ccan/.gitignore: -------------------------------------------------------------------------------- 1 | config.h 2 | -------------------------------------------------------------------------------- /CC0-for-protocol-headers: -------------------------------------------------------------------------------- 1 | ccan/licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/alignof/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/endian/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/err/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/hash/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/ilog/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/io/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/LGPL-2.1 -------------------------------------------------------------------------------- /ccan/ccan/isaac/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/likely/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/net/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/BSD-MIT -------------------------------------------------------------------------------- /ccan/ccan/noerr/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/opt/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/GPL-2 -------------------------------------------------------------------------------- /ccan/ccan/str/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/take/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/tal/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/BSD-MIT -------------------------------------------------------------------------------- /ccan/ccan/tcon/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /test/blackbox/.gitignore: -------------------------------------------------------------------------------- 1 | test-*-dir 2 | -------------------------------------------------------------------------------- /ccan/ccan/array_size/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/asort/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/LGPL-2.1 -------------------------------------------------------------------------------- /ccan/ccan/bitmap/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/LGPL-2.1 -------------------------------------------------------------------------------- /ccan/ccan/breakpoint/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/build_assert/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/cast/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/LGPL-2.1 -------------------------------------------------------------------------------- /ccan/ccan/cdump/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/BSD-MIT -------------------------------------------------------------------------------- /ccan/ccan/check_type/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/compiler/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/container_of/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/htable/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/LGPL-2.1 -------------------------------------------------------------------------------- /ccan/ccan/list/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/BSD-MIT -------------------------------------------------------------------------------- /ccan/ccan/short_types/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/structeq/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/time/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/BSD-MIT -------------------------------------------------------------------------------- /ccan/ccan/timer/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/LGPL-2.1 -------------------------------------------------------------------------------- /ccan/ccan/typesafe_cb/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/ccan/cdump/tools/.gitignore: -------------------------------------------------------------------------------- 1 | cdump-enumstr 2 | -------------------------------------------------------------------------------- /ccan/ccan/tal/link/LICENSE: -------------------------------------------------------------------------------- 1 | ../../../licenses/BSD-MIT -------------------------------------------------------------------------------- /ccan/ccan/tal/path/LICENSE: -------------------------------------------------------------------------------- 1 | ../../../licenses/BSD-MIT -------------------------------------------------------------------------------- /ccan/ccan/tal/str/LICENSE: -------------------------------------------------------------------------------- 1 | ../../../licenses/BSD-MIT -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/LICENSE: -------------------------------------------------------------------------------- 1 | ../../../licenses/LGPL-3 -------------------------------------------------------------------------------- /tools/.gitignore: -------------------------------------------------------------------------------- 1 | make-peer-packet 2 | spv-blocks 3 | -------------------------------------------------------------------------------- /ccan/ccan/read_write_all/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/LGPL-2.1 -------------------------------------------------------------------------------- /ccan/ccan/tal/grab_file/LICENSE: -------------------------------------------------------------------------------- 1 | ../../../licenses/LGPL-2.1 -------------------------------------------------------------------------------- /ccan/ccan/tal/path/path/LICENSE: -------------------------------------------------------------------------------- 1 | ../../../licenses/BSD-MIT -------------------------------------------------------------------------------- /ccan/ccan/tal/str/str/LICENSE: -------------------------------------------------------------------------------- 1 | ../../../licenses/BSD-MIT -------------------------------------------------------------------------------- /test/standalone/.gitignore: -------------------------------------------------------------------------------- 1 | addresses 2 | pettycoin-* 3 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/talloc/LICENSE: -------------------------------------------------------------------------------- 1 | ../../../licenses/LGPL-3 -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-02-read-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-02-read.c" 3 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-05-write-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-05-write.c" 3 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-07-break-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-07-break.c" 3 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-12-bidir-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-12-bidir.c" 3 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-18-errno-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-18-errno.c" 3 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-19-always-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-19-always.c" 3 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-09-connect-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-09-connect.c" 3 | -------------------------------------------------------------------------------- /ccan/README: -------------------------------------------------------------------------------- 1 | CCAN imported from http://ccodearchive.net. 2 | 3 | CCAN version: init-1952-ga77ce0e 4 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-03-readpartial-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-03-readpartial.c" 3 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-16-duplex-test-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-16-duplex-test.c" 3 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-17-homemade-io-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-17-homemade-io.c" 3 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-01-start-finish-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-01-start-finish.c" 3 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-04-writepartial-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-04-writepartial.c" 3 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-14-duplex-both-read-debug.c: -------------------------------------------------------------------------------- 1 | #define DEBUG_CONN 2 | #include "run-14-duplex-both-read.c" 3 | -------------------------------------------------------------------------------- /web/Makefile: -------------------------------------------------------------------------------- 1 | #! /usr/bin/make 2 | 3 | cp: 4 | rsync -a . /home/rusty/www/html/pettycoin.org/ 5 | send-web 6 | -------------------------------------------------------------------------------- /test/blackbox/test-01-blockfile1.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rustyrussell/pettycoin/HEAD/test/blackbox/test-01-blockfile1.xz -------------------------------------------------------------------------------- /test/blackbox/test-01-blockfile2.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rustyrussell/pettycoin/HEAD/test/blackbox/test-01-blockfile2.xz -------------------------------------------------------------------------------- /test/vg-suppressions: -------------------------------------------------------------------------------- 1 | { 2 | OpenSSL-leaks-apparently 3 | Memcheck:Leak 4 | fun:malloc 5 | fun:CRYPTO_malloc 6 | } 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | before_install: 3 | - sudo apt-get update -qq 4 | - sudo apt-get install -qq -f valgrind libssl-dev 5 | -------------------------------------------------------------------------------- /ccan/ccan/tal/str-Makefile: -------------------------------------------------------------------------------- 1 | ccan/tal/str-Makefile: ccan/tal/str/str.c ccan/tal/str/str.h ccan/tal/str/_info 2 | ccan/tal/str.o: ccan/tal/str/str.o 3 | -------------------------------------------------------------------------------- /ccan/ccan/tal/link-Makefile: -------------------------------------------------------------------------------- 1 | ccan/tal/link-Makefile: ccan/tal/link/link.c ccan/tal/link/link.h ccan/tal/link/_info 2 | ccan/tal/link.o: ccan/tal/link/link.o 3 | -------------------------------------------------------------------------------- /ccan/ccan/tal/path-Makefile: -------------------------------------------------------------------------------- 1 | ccan/tal/path-Makefile: ccan/tal/path/path.c ccan/tal/path/path.h ccan/tal/path/_info 2 | ccan/tal/path.o: ccan/tal/path/path.o 3 | -------------------------------------------------------------------------------- /ccan/ccan/list/test/run-with-debug.c: -------------------------------------------------------------------------------- 1 | /* Just like run.c, but with all debug checks enabled. */ 2 | #define CCAN_LIST_DEBUG 1 3 | #include 4 | -------------------------------------------------------------------------------- /ccan/ccan/build_assert/test/compile_ok.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | BUILD_ASSERT(1 == 1); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /web/images/who-has-time-and-skill-to-make-a-decent-pettycoin-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rustyrussell/pettycoin/HEAD/web/images/who-has-time-and-skill-to-make-a-decent-pettycoin-logo.png -------------------------------------------------------------------------------- /ccan/ccan/tal/grab_file-Makefile: -------------------------------------------------------------------------------- 1 | ccan/tal/grab_file-Makefile: ccan/tal/grab_file/grab_file.c ccan/tal/grab_file/grab_file.h ccan/tal/grab_file/_info 2 | ccan/tal/grab_file.o: ccan/tal/grab_file/grab_file.o 3 | -------------------------------------------------------------------------------- /ccan/ccan/build_assert/test/compile_fail.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | #ifdef FAIL 6 | BUILD_ASSERT(1 == 0); 7 | #endif 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /ccan/ccan/check_type/test/compile_fail-check_type.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | #ifdef FAIL 6 | check_type(argc, char); 7 | #endif 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /ccan/ccan/build_assert/test/compile_fail-expr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | #ifdef FAIL 6 | return BUILD_ASSERT_OR_ZERO(1 == 0); 7 | #else 8 | return 0; 9 | #endif 10 | } 11 | -------------------------------------------------------------------------------- /ccan/ccan/net/tools/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-g -Wall -W -I../../.. 2 | 3 | test-net: test-net.o net.o noerr.o 4 | 5 | net.o: ../net.c 6 | $(COMPILE.c) $(OUTPUT_OPTION) $< 7 | 8 | noerr.o: ../../noerr/noerr.c 9 | $(COMPILE.c) $(OUTPUT_OPTION) $< 10 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/debug.c: -------------------------------------------------------------------------------- 1 | /* We can't use the normal "#include the .c file" trick, since this is 2 | contaminated by str.h's macro overrides. So we put it in all tests 3 | like this. */ 4 | #define CCAN_STR_DEBUG 1 5 | #include 6 | -------------------------------------------------------------------------------- /ccan/ccan/cast/test/compile_ok-cast_void.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void *remove_void(const void *p) 4 | { 5 | return cast_const(void *, p); 6 | } 7 | 8 | int main(void) 9 | { 10 | void *p = remove_void("foo"); 11 | return !p; 12 | } 13 | -------------------------------------------------------------------------------- /ccan/ccan/check_type/test/compile_fail-check_types_match.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | unsigned char x = argc; 6 | #ifdef FAIL 7 | check_types_match(argc, x); 8 | #endif 9 | return x; 10 | } 11 | -------------------------------------------------------------------------------- /genesis.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_GENESIS_H 2 | #define PETTYCOIN_GENESIS_H 3 | #include "config.h" 4 | #include "block.h" 5 | #include "block_shard.h" 6 | 7 | /* For new_state() to access. */ 8 | extern struct block genesis; 9 | 10 | #endif /* PETTYCOIN_GENESIS_H */ 11 | -------------------------------------------------------------------------------- /pseudorand.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_PSEUDORAND_H 2 | #define PETTYCOIN_PSEUDORAND_H 3 | #include "config.h" 4 | #include 5 | 6 | extern struct isaac64_ctx *isaac64; 7 | 8 | void pseudorand_init(void); 9 | #endif /* PETTYCOIN_PSEUDORAND_H */ 10 | -------------------------------------------------------------------------------- /ccan/ccan/build_assert/test/run-BUILD_ASSERT_OR_ZERO.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | plan_tests(1); 7 | ok1(BUILD_ASSERT_OR_ZERO(1 == 1) == 0); 8 | return exit_status(); 9 | } 10 | -------------------------------------------------------------------------------- /ccan/ccan/endian/test/compile_ok-constant.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct foo { 4 | char one[BSWAP_16(0xFF00)]; 5 | char two[BSWAP_32(0xFF000000)]; 6 | char three[BSWAP_64(0xFF00000000000000ULL)]; 7 | }; 8 | 9 | int main(void) 10 | { 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /gateways.c: -------------------------------------------------------------------------------- 1 | #include "gateways.h" 2 | #include "state.h" 3 | #include 4 | 5 | bool accept_gateway(const struct state *state, 6 | const struct protocol_address *addr) 7 | { 8 | /* Everyone can be a gateway on testnet! */ 9 | assert(state->test_net); 10 | return true; 11 | } 12 | -------------------------------------------------------------------------------- /jsmn/SOURCE: -------------------------------------------------------------------------------- 1 | Sourced from: http://bitbucket.org/zserge/jsmn 2 | 3 | Tip commit: 4 | changeset: 78:54f042505d20 5 | tag: tip 6 | user: Serge A. Zaitsev 7 | date: Fri Feb 21 11:04:16 2014 +0200 8 | summary: removed JSMN_SUCCESS value from the readme 9 | -------------------------------------------------------------------------------- /pettycoin_dir.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_PETTYCOIN_DIR_H 2 | #define PETTYCOIN_PETTYCOIN_DIR_H 3 | #include "config.h" 4 | #include 5 | 6 | void pettycoin_dir_register_opts(const tal_t *ctx, 7 | char **pettycoin_dir, char **rpc_filename); 8 | 9 | #endif /* PETTYCOIN_PETTYCOIN_DIR_H */ 10 | -------------------------------------------------------------------------------- /test/blackbox/test-issue-20-dumbwallet-import.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | set -e 4 | 5 | OUT=`$RUNPREFIX/dumbwallet --pettycoin-dir=$SCRATCHDIR setup P-cNkMqSEm5FsNGTPcKUaUjoVA8adAm9tezdAjsAeGfxtxjhps76M8` 6 | # Should give correct address. 7 | echo "$OUT" | grep P-mxEP2midj7DRBW4yCxBBSs2MWcMsQfqQVw > /dev/null 8 | 9 | -------------------------------------------------------------------------------- /ccan/ccan/list/test/helper.h: -------------------------------------------------------------------------------- 1 | /* These are in a separate C file so we can test undefined structures. */ 2 | struct opaque; 3 | typedef struct opaque opaque_t; 4 | 5 | opaque_t *create_opaque_blob(void); 6 | bool if_blobs_know_the_secret(opaque_t *blob); 7 | void destroy_opaque_blob(opaque_t *blob); 8 | 9 | 10 | -------------------------------------------------------------------------------- /ccan/ccan/cast/test/compile_ok-static.c: -------------------------------------------------------------------------------- 1 | /* OpenIndiana's CC (aka suncc) has issues with constants: make sure 2 | * we are one! */ 3 | #include 4 | 5 | static char *p = cast_const(char *, (const char *)"hello"); 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | return p[0] == argv[0][0]; 10 | } 11 | -------------------------------------------------------------------------------- /gateways.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_GATEWAYS_H 2 | #define PETTYCOIN_GATEWAYS_H 3 | #include "config.h" 4 | #include 5 | 6 | struct state; 7 | struct protocol_address; 8 | bool accept_gateway(const struct state *state, 9 | const struct protocol_address *addr); 10 | 11 | #endif /* PETTYCOIN_GATEWAYS_H */ 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.d 3 | *~ 4 | vgcore.* 5 | pettycoin-generate 6 | mkgenesis 7 | pettycoin 8 | pettycoin-query 9 | pettycoin-tx 10 | dumbwallet 11 | pettycoin-gateway 12 | TAGS 13 | mkpriv 14 | sizes 15 | ecode_names.c 16 | genesis.c 17 | pkt_names.c 18 | petty-addr 19 | ccan/tools/configurator/configurator 20 | Makefile 21 | -------------------------------------------------------------------------------- /test/standalone/Makefile: -------------------------------------------------------------------------------- 1 | default-test-standalone: 2 | @echo Run make from top dir. >&2 && exit 1 3 | 4 | test-clean: test-standalone-clean 5 | test-distclean: test-standalone-distclean 6 | 7 | test-standalone-clean: 8 | $(RM) -r test/standalone/pettycoin-* test/standalone/addresses 9 | 10 | test-standalone-distclean: 11 | 12 | -------------------------------------------------------------------------------- /ccan/ccan/str/str.c: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #include 3 | 4 | size_t strcount(const char *haystack, const char *needle) 5 | { 6 | size_t i = 0, nlen = strlen(needle); 7 | 8 | while ((haystack = strstr(haystack, needle)) != NULL) { 9 | i++; 10 | haystack += nlen; 11 | } 12 | return i; 13 | } 14 | -------------------------------------------------------------------------------- /ccan/ccan/check_type/test/compile_fail-check_type_unsigned.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | #ifdef FAIL 6 | #if HAVE_TYPEOF 7 | check_type(argc, unsigned int); 8 | #else 9 | /* This doesn't work without typeof, so just fail */ 10 | #error "Fail without typeof" 11 | #endif 12 | #endif 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /ccan/ccan/read_write_all/read_write_all.h: -------------------------------------------------------------------------------- 1 | /* Licensed under LGPLv2+ - see LICENSE file for details */ 2 | #ifndef _CCAN_READ_WRITE_H 3 | #define _CCAN_READ_WRITE_H 4 | #include 5 | #include 6 | 7 | bool write_all(int fd, const void *data, size_t size); 8 | bool read_all(int fd, void *data, size_t size); 9 | 10 | #endif /* _CCAN_READ_WRITE_H */ 11 | -------------------------------------------------------------------------------- /test/helper_gateway_key.h: -------------------------------------------------------------------------------- 1 | #ifndef HELPER_GATEWAY_KEY_H 2 | #define HELPER_GATEWAY_KEY_H 3 | #include 4 | #include 5 | 6 | EC_KEY *helper_gateway_key(const tal_t *ctx); 7 | const struct protocol_pubkey *helper_gateway_public_key(void); 8 | const struct protocol_address *helper_gateway_addr(void); 9 | 10 | #endif /* HELPER_GATEWAY_KEY_H */ 11 | -------------------------------------------------------------------------------- /ccan/ccan/cast/test/compile_fail-cast_signed.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | unsigned char *uc; 7 | #ifdef FAIL 8 | int 9 | #else 10 | char 11 | #endif 12 | *p = NULL; 13 | 14 | uc = cast_signed(unsigned char *, p); 15 | (void) uc; /* Suppress unused-but-set-variable warning. */ 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /generate.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_GENERATE_H 2 | #define PETTYCOIN_GENERATE_H 3 | #include "config.h" 4 | #include "protocol_net.h" 5 | 6 | /* Write this to generate's stdin to add a new transaction. */ 7 | struct gen_update { 8 | u16 shard; 9 | u8 txoff; 10 | u8 unused; 11 | u32 features; 12 | struct protocol_txrefhash hashes; 13 | }; 14 | 15 | #endif /* PETTYCOIN_GENERATE_H */ 16 | -------------------------------------------------------------------------------- /version.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_VERSION_H 2 | #define PETTYCOIN_VERSION_H 3 | #include "config.h" 4 | #include 5 | #include 6 | 7 | static inline u8 current_version(void) 8 | { 9 | return 1; 10 | } 11 | 12 | static inline bool version_ok(u8 version) 13 | { 14 | return version == current_version(); 15 | } 16 | #endif /* PETTYCOIN_VERSION_H */ 17 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-strchr.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_TYPEOF 8 | #error We need typeof to check strstr. 9 | #endif 10 | #else 11 | const 12 | #endif 13 | char *ret; 14 | const char *str = "hello"; 15 | 16 | ret = strchr(str, 'l'); 17 | return ret ? 0 : 1; 18 | } 19 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-strrchr.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_TYPEOF 8 | #error We need typeof to check strstr. 9 | #endif 10 | #else 11 | const 12 | #endif 13 | char *ret; 14 | const char *str = "hello"; 15 | 16 | ret = strrchr(str, 'l'); 17 | return ret ? 0 : 1; 18 | } 19 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-strstr.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_TYPEOF 8 | #error We need typeof to check strstr. 9 | #endif 10 | #else 11 | const 12 | #endif 13 | char *ret; 14 | const char *str = "hello"; 15 | 16 | ret = strstr(str, "hell"); 17 | return ret ? 0 : 1; 18 | } 19 | -------------------------------------------------------------------------------- /prev_blocks.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_PREV_BLOCKS_H 2 | #define PETTYCOIN_PREV_BLOCKS_H 3 | #include "config.h" 4 | #include "protocol.h" 5 | 6 | struct block; 7 | void make_prev_blocks(const struct block *prev, 8 | struct protocol_block_id prevs[PROTOCOL_NUM_PREV_IDS]); 9 | 10 | unsigned int num_prevs(const struct protocol_block_header *hdr); 11 | #endif /* PETTYCOIN_PREV_BLOCKS_H */ 12 | -------------------------------------------------------------------------------- /signature.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_SIGNATURES_H 2 | #define PETTYCOIN_SIGNATURES_H 3 | #include "config.h" 4 | #include "protocol.h" 5 | #include 6 | #include 7 | 8 | bool check_tx_sign(const union protocol_tx *tx, 9 | const struct protocol_pubkey *key); 10 | 11 | bool sign_tx(union protocol_tx *tx, EC_KEY *private_key); 12 | #endif /* PETTYCOIN_SIGNATURES_H */ 13 | -------------------------------------------------------------------------------- /ccan/ccan/opt/test/compile_ok-const-arg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | opt_register_noarg("-v", opt_version_and_exit, 10 | (const char *)"1.2.3", 11 | (const char *)"Print version"); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /create_refs.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_CREATE_REFS_H 2 | #define PETTYCOIN_CREATE_REFS_H 3 | #include "config.h" 4 | 5 | struct state; 6 | struct block; 7 | union protocol_tx; 8 | 9 | struct protocol_input_ref *create_refs(struct state *state, 10 | const struct block *block, 11 | const union protocol_tx *tx, 12 | int offset); 13 | 14 | #endif /* PETTYCOIN_CREATE_REFS_H */ 15 | -------------------------------------------------------------------------------- /ccan/ccan/structeq/test/compile_fail-different.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct mydata1 { 4 | int start, end; 5 | }; 6 | 7 | struct mydata2 { 8 | int start, end; 9 | }; 10 | 11 | int main(void) 12 | { 13 | struct mydata1 a = { 0, 100 }; 14 | #ifdef FAIL 15 | struct mydata2 16 | #else 17 | struct mydata1 18 | #endif 19 | b = { 0, 100 }; 20 | 21 | return structeq(&a, &b); 22 | } 23 | -------------------------------------------------------------------------------- /test/helper_key.h: -------------------------------------------------------------------------------- 1 | #ifndef HELPER_PRIVATE_KEY_H 2 | #define HELPER_PRIVATE_KEY_H 3 | #include 4 | #include 5 | 6 | EC_KEY *helper_private_key(const tal_t *ctx, int idx); 7 | /* Keys 0, 1 and 3 are all in shard 0 */ 8 | const struct protocol_pubkey *helper_public_key(int idx); 9 | const struct protocol_address *helper_addr(int idx); 10 | 11 | #endif /* HELPER_PRIVATE_KEY_H */ 12 | -------------------------------------------------------------------------------- /ccan/ccan/array_size/test/compile_fail.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[8]) 4 | { 5 | char array[100]; 6 | #ifdef FAIL 7 | return ARRAY_SIZE(argv) + ARRAY_SIZE(array); 8 | #if !HAVE_TYPEOF || !HAVE_BUILTIN_TYPES_COMPATIBLE_P 9 | #error "Unfortunately we don't fail if _array_size_chk is a noop." 10 | #endif 11 | #else 12 | return ARRAY_SIZE(array); 13 | #endif 14 | } 15 | -------------------------------------------------------------------------------- /ccan/ccan/compiler/test/run-is_compile_constant.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | plan_tests(2); 7 | 8 | ok1(!IS_COMPILE_CONSTANT(argc)); 9 | #if HAVE_BUILTIN_CONSTANT_P 10 | ok1(IS_COMPILE_CONSTANT(7)); 11 | #else 12 | pass("If !HAVE_BUILTIN_CONSTANT_P, IS_COMPILE_CONSTANT always false"); 13 | #endif 14 | return exit_status(); 15 | } 16 | -------------------------------------------------------------------------------- /json_add_tx.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_JSON_ADD_TX_H 2 | #define PETTYCOIN_JSON_ADD_TX_H 3 | 4 | struct state; 5 | union protocol_tx; 6 | struct block; 7 | struct json_result; 8 | 9 | void json_add_tx(struct json_result *response, const char *fieldname, 10 | struct state *state, 11 | const union protocol_tx *tx, 12 | const struct block *block, 13 | unsigned int confirms); 14 | 15 | #endif /* PETTYCOIN_JSON_ADD_TX_H */ 16 | -------------------------------------------------------------------------------- /overflows.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_OVERFLOWS_H 2 | #define PETTYCOIN_OVERFLOWS_H 3 | #include "config.h" 4 | #include 5 | #include 6 | 7 | static inline bool mul_overflows(size_t a, size_t b) 8 | { 9 | if (!b) 10 | return false; 11 | return a * b / b != a; 12 | } 13 | 14 | static inline bool add_overflows(size_t a, size_t b) 15 | { 16 | return a + b < b; 17 | } 18 | #endif /* PETTYCOIN_OVERFLOWS_H */ 19 | -------------------------------------------------------------------------------- /hash_block.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_HASH_BLOCK_H 2 | #define PETTYCOIN_HASH_BLOCK_H 3 | #include "config.h" 4 | #include "protocol.h" 5 | 6 | void hash_block(const struct protocol_block_header *hdr, 7 | const u8 *shard_nums, 8 | const struct protocol_double_sha *merkles, 9 | const u8 *prev_txhashes, 10 | const struct protocol_block_tailer *tailer, 11 | struct protocol_double_sha *sha); 12 | 13 | #endif /* PETTYCOIN_HASH_BLOCK_H */ 14 | -------------------------------------------------------------------------------- /ccan/ccan/breakpoint/test/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | /* This is how many tests you plan to run */ 8 | plan_tests(2); 9 | 10 | breakpoint(); 11 | 12 | ok1(breakpoint_initialized); 13 | ok1(!breakpoint_under_debug); 14 | 15 | /* This exits depending on whether all tests passed */ 16 | return exit_status(); 17 | } 18 | -------------------------------------------------------------------------------- /ccan/ccan/tal/path/test/run-is_abs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | plan_tests(5); 8 | 9 | ok1(path_is_abs(PATH_SEP_STR "foo")); 10 | ok1(!path_is_abs("foo")); 11 | ok1(!path_is_abs("foo" PATH_SEP_STR)); 12 | 13 | ok1(path_is_abs(PATH_SEP_STR "foo" PATH_SEP_STR)); 14 | ok1(path_is_abs(PATH_SEP_STR ".")); 15 | return exit_status(); 16 | } 17 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-STR_MAX_CHARS.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct s { 4 | int val; 5 | }; 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | struct s 10 | #ifdef FAIL 11 | #if !HAVE_TYPEOF 12 | #error We need typeof to check STR_MAX_CHARS. 13 | #endif 14 | #else 15 | /* A pointer is OK. */ 16 | * 17 | #endif 18 | val; 19 | char str[STR_MAX_CHARS(val)]; 20 | 21 | str[0] = '\0'; 22 | return str[0] ? 0 : 1; 23 | } 24 | -------------------------------------------------------------------------------- /ccan/ccan/tal/path/path/test/run-is_abs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | plan_tests(5); 8 | 9 | ok1(path_is_abs(PATH_SEP_STR "foo")); 10 | ok1(!path_is_abs("foo")); 11 | ok1(!path_is_abs("foo" PATH_SEP_STR)); 12 | 13 | ok1(path_is_abs(PATH_SEP_STR "foo" PATH_SEP_STR)); 14 | ok1(path_is_abs(PATH_SEP_STR ".")); 15 | return exit_status(); 16 | } 17 | -------------------------------------------------------------------------------- /recv_tx.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_RECV_TX_H 2 | #define PETTYCOIN_RECV_TX_H 3 | #include "config.h" 4 | 5 | struct peer; 6 | struct protocol_pkt_tx_in_block; 7 | struct state; 8 | 9 | enum protocol_ecode recv_tx_from_peer(struct peer *peer, 10 | const struct protocol_pkt_tx_in_block *pkt); 11 | 12 | enum protocol_ecode recv_tx_from_blockfile(struct state *state, 13 | const struct protocol_pkt_tx_in_block *pkt); 14 | 15 | #endif /* PETTYCOIN_RECV_TX_H */ 16 | -------------------------------------------------------------------------------- /test/helper_fakenewstate.h: -------------------------------------------------------------------------------- 1 | #ifndef HELPER_FAKENEWSTATE_H 2 | #define HELPER_FAKENEWSTATE_H 3 | #include 4 | #include "../state.h" 5 | #include "../protocol.h" 6 | 7 | static inline struct state *fake_new_state(void) 8 | { 9 | struct state *s = tal(NULL, struct state); 10 | 11 | /* longest_knowns is required in check_trans_from_gateway */ 12 | s->longest_knowns = tal_arr(s, const struct block *, 1); 13 | 14 | return s; 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /tx_cmp.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_TX_CMP_H 2 | #define PETTYCOIN_TX_CMP_H 3 | #include "config.h" 4 | #include 5 | #include 6 | 7 | union protocol_tx; 8 | int tx_cmp(const union protocol_tx *a, const union protocol_tx *b); 9 | 10 | static inline int tx_ptr_cmp(union protocol_tx *const *a, 11 | union protocol_tx *const *b, 12 | void *unused) 13 | { 14 | return tx_cmp(*a, *b); 15 | } 16 | 17 | #endif /* PETTYCOIN_TX_CMP_H */ 18 | -------------------------------------------------------------------------------- /ccan/ccan/tcon/test/compile_fail.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct container { 5 | void *p; 6 | }; 7 | 8 | struct int_container { 9 | struct container raw; 10 | TCON(int *canary); 11 | }; 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | struct int_container icon; 16 | #ifdef FAIL 17 | char * 18 | #else 19 | int * 20 | #endif 21 | x = NULL; 22 | 23 | tcon_check(&icon, canary, x)->raw.p = x; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /generating.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_GENERATING_H 2 | #define PETTYCOIN_GENERATING_H 3 | #include "config.h" 4 | #include 5 | 6 | struct state; 7 | struct block; 8 | void start_generating(struct state *state); 9 | void restart_generating(struct state *state); 10 | 11 | /* We use u32 so we can assert() if they don't fit in u16/u8 respectively */ 12 | void tell_generator_new_pending(struct state *state, u32 shard, u32 txoff); 13 | #endif 14 | -------------------------------------------------------------------------------- /features.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_FEATURES_H 2 | #define PETTYCOIN_FEATURES_H 3 | #include "config.h" 4 | #include 5 | #include 6 | 7 | static inline u8 current_features(void) 8 | { 9 | return 0; 10 | } 11 | 12 | static inline bool features_ok(u8 features) 13 | { 14 | return features == current_features(); 15 | } 16 | 17 | struct block; 18 | u8 pending_features(const struct block *block); 19 | 20 | #endif /* PETTYCOIN_FEATURES_H */ 21 | -------------------------------------------------------------------------------- /blockfile.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_BLOCKFILE_H 2 | #define PETTYCOIN_BLOCKFILE_H 3 | #include "config.h" 4 | #include 5 | 6 | struct state; 7 | struct block; 8 | void load_blocks(struct state *state); 9 | 10 | void save_block(struct state *state, struct block *new); 11 | 12 | /* We only save transactions within a saved block. */ 13 | void save_tx(struct state *state, struct block *block, u16 shard, u8 txoff); 14 | 15 | #endif /* PETTYCOIN_BLOCKFILE_H */ 16 | -------------------------------------------------------------------------------- /merkle_hashes.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_MERKLE_HASHES_H 2 | #define PETTYCOIN_MERKLE_HASHES_H 3 | #include "config.h" 4 | #include 5 | 6 | struct protocol_double_sha; 7 | struct protocol_txrefhash; 8 | 9 | /* For when we already has them as flat array of hashes. */ 10 | void merkle_hashes(const struct protocol_txrefhash *hashes, 11 | size_t off, size_t num_hashes, 12 | struct protocol_double_sha *merkle); 13 | 14 | #endif /* PETTYCOIN_MERKLE_HASHES_H */ 15 | 16 | 17 | -------------------------------------------------------------------------------- /sslerrorstring.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_SSLERRORSTRING_H 2 | #define PETTYCOIN_SSLERRORSTRING_H 3 | #include "config.h" 4 | #include 5 | 6 | static inline const char *ssl_error_string(void) 7 | { 8 | static char errbuf[120]; 9 | unsigned long e = ERR_get_error(); 10 | 11 | /* There can be multiple errors: drain the rest. */ 12 | while (ERR_get_error()); 13 | 14 | return ERR_error_string(e, errbuf); 15 | } 16 | 17 | #endif /* PETTYCOIN_SSLERRORSTRING_H */ 18 | -------------------------------------------------------------------------------- /ccan/ccan/cast/test/compile_fail-cast_static-3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | char *c; 7 | #ifdef FAIL 8 | const 9 | #endif 10 | char *p = 0; 11 | 12 | c = cast_static(char *, p); 13 | (void) c; /* Suppress unused-but-set-variable warning. */ 14 | return 0; 15 | } 16 | 17 | #ifdef FAIL 18 | #if !HAVE_COMPOUND_LITERALS 19 | #error "Unfortunately we don't fail if cast_static is a noop" 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /ccan/ccan/short_types/test/run-endian.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | plan_tests(6); 10 | 11 | ok1(sizeof(be64) == 8); 12 | ok1(sizeof(be32) == 4); 13 | ok1(sizeof(be16) == 2); 14 | 15 | ok1(sizeof(le64) == 8); 16 | ok1(sizeof(le32) == 4); 17 | ok1(sizeof(le16) == 2); 18 | 19 | return exit_status(); 20 | } 21 | -------------------------------------------------------------------------------- /horizon.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_HORIZON_H 2 | #define PETTYCOIN_HORIZON_H 3 | #include "config.h" 4 | #include 5 | #include 6 | 7 | struct state; 8 | struct block_info; 9 | 10 | /* When do transactions in this block expire? */ 11 | u32 block_expiry(struct state *state, const struct block_info *bi); 12 | 13 | /* Has this expiry time mean it's expired? */ 14 | bool block_expired_by(u32 expires, u32 now); 15 | 16 | #endif /* PETTYCOIN_HORIZON_H */ 17 | -------------------------------------------------------------------------------- /ccan/ccan/compiler/test/compile_fail-printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static void PRINTF_FMT(2,3) my_printf(int x, const char *fmt, ...) 4 | { 5 | } 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | unsigned int i = 0; 10 | 11 | my_printf(1, "Not a pointer " 12 | #ifdef FAIL 13 | "%p", 14 | #if !HAVE_ATTRIBUTE_PRINTF 15 | #error "Unfortunately we don't fail if !HAVE_ATTRIBUTE_PRINTF." 16 | #endif 17 | #else 18 | "%i", 19 | #endif 20 | i); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/container_of/test/compile_fail-bad-type.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct foo { 5 | int a; 6 | char b; 7 | }; 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | struct foo foo = { .a = 1, .b = 2 }; 12 | int *intp = &foo.a; 13 | char *p; 14 | 15 | #ifdef FAIL 16 | /* p is a char *, but this gives a struct foo * */ 17 | p = container_of(intp, struct foo, a); 18 | #else 19 | p = (char *)intp; 20 | #endif 21 | return p == NULL; 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-isalnum.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF 8 | #error We need typeof to check isalnum. 9 | #endif 10 | char 11 | #else 12 | unsigned char 13 | #endif 14 | c = argv[0][0]; 15 | 16 | #ifdef FAIL 17 | /* Fake fail on unsigned char platforms. */ 18 | BUILD_ASSERT((char)255 < 0); 19 | #endif 20 | 21 | return isalnum(c); 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-isalpha.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF 8 | #error We need typeof to check isalpha. 9 | #endif 10 | char 11 | #else 12 | unsigned char 13 | #endif 14 | c = argv[0][0]; 15 | 16 | #ifdef FAIL 17 | /* Fake fail on unsigned char platforms. */ 18 | BUILD_ASSERT((char)255 < 0); 19 | #endif 20 | 21 | return isalpha(c); 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-isascii.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF 8 | #error We need typeof to check isascii. 9 | #endif 10 | char 11 | #else 12 | unsigned char 13 | #endif 14 | c = argv[0][0]; 15 | 16 | #ifdef FAIL 17 | /* Fake fail on unsigned char platforms. */ 18 | BUILD_ASSERT((char)255 < 0); 19 | #endif 20 | 21 | return isascii(c); 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-iscntrl.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF 8 | #error We need typeof to check iscntrl. 9 | #endif 10 | char 11 | #else 12 | unsigned char 13 | #endif 14 | c = argv[0][0]; 15 | 16 | #ifdef FAIL 17 | /* Fake fail on unsigned char platforms. */ 18 | BUILD_ASSERT((char)255 < 0); 19 | #endif 20 | 21 | return iscntrl(c); 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-isdigit.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF 8 | #error We need typeof to check isdigit. 9 | #endif 10 | char 11 | #else 12 | unsigned char 13 | #endif 14 | c = argv[0][0]; 15 | 16 | #ifdef FAIL 17 | /* Fake fail on unsigned char platforms. */ 18 | BUILD_ASSERT((char)255 < 0); 19 | #endif 20 | 21 | return isdigit(c); 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-islower.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF 8 | #error We need typeof to check islower. 9 | #endif 10 | char 11 | #else 12 | unsigned char 13 | #endif 14 | c = argv[0][0]; 15 | 16 | #ifdef FAIL 17 | /* Fake fail on unsigned char platforms. */ 18 | BUILD_ASSERT((char)255 < 0); 19 | #endif 20 | 21 | return islower(c); 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-isprint.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF 8 | #error We need typeof to check isprint. 9 | #endif 10 | char 11 | #else 12 | unsigned char 13 | #endif 14 | c = argv[0][0]; 15 | 16 | #ifdef FAIL 17 | /* Fake fail on unsigned char platforms. */ 18 | BUILD_ASSERT((char)255 < 0); 19 | #endif 20 | 21 | return isprint(c); 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-ispunct.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF 8 | #error We need typeof to check ispunct. 9 | #endif 10 | char 11 | #else 12 | unsigned char 13 | #endif 14 | c = argv[0][0]; 15 | 16 | #ifdef FAIL 17 | /* Fake fail on unsigned char platforms. */ 18 | BUILD_ASSERT((char)255 < 0); 19 | #endif 20 | 21 | return ispunct(c); 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-isspace.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF 8 | #error We need typeof to check isspace. 9 | #endif 10 | char 11 | #else 12 | unsigned char 13 | #endif 14 | c = argv[0][0]; 15 | 16 | #ifdef FAIL 17 | /* Fake fail on unsigned char platforms. */ 18 | BUILD_ASSERT((char)255 < 0); 19 | #endif 20 | 21 | return isspace(c); 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-isupper.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF 8 | #error We need typeof to check isupper. 9 | #endif 10 | char 11 | #else 12 | unsigned char 13 | #endif 14 | c = argv[0][0]; 15 | 16 | #ifdef FAIL 17 | /* Fake fail on unsigned char platforms. */ 18 | BUILD_ASSERT((char)255 < 0); 19 | #endif 20 | 21 | return isupper(c); 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/tcon/test/compile_ok-void.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct container { 5 | void *p; 6 | }; 7 | 8 | struct void_container { 9 | struct container raw; 10 | TCON(void *canary); 11 | }; 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | struct void_container vcon; 16 | 17 | tcon_check(&vcon, canary, NULL)->raw.p = NULL; 18 | tcon_check(&vcon, canary, argv[0])->raw.p = NULL; 19 | tcon_check(&vcon, canary, main)->raw.p = NULL; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /timeout.c: -------------------------------------------------------------------------------- 1 | #include "state.h" 2 | #include "timeout.h" 3 | 4 | void init_timeout_(struct timeout *t, unsigned int interval, 5 | void (*cb)(void *), void *arg) 6 | { 7 | timer_init(&t->timer); 8 | t->interval = time_from_sec(interval); 9 | t->cb = cb; 10 | t->arg = arg; 11 | } 12 | 13 | void refresh_timeout(struct state *state, struct timeout *t) 14 | { 15 | timer_del(&state->timers, &t->timer); 16 | timer_add(&state->timers, &t->timer, 17 | timeabs_add(time_now(), t->interval)); 18 | } 19 | -------------------------------------------------------------------------------- /valgrind.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_VALGRIND_H 2 | #define PETTYCOIN_VALGRIND_H 3 | #include "config.h" 4 | 5 | #ifdef VALGRIND_HEADERS 6 | #include 7 | #elif !defined(VALGRIND_CHECK_MEM_IS_DEFINED) 8 | #define VALGRIND_CHECK_MEM_IS_DEFINED(p, len) 9 | #define RUNNING_ON_VALGRIND 0 10 | #endif 11 | 12 | static inline void *check_mem(const void *data, size_t len) 13 | { 14 | VALGRIND_CHECK_MEM_IS_DEFINED(data, len); 15 | return (void *)data; 16 | } 17 | #endif /* PETTYCOIN_VALGRIND_H */ 18 | -------------------------------------------------------------------------------- /addr.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_ADDR_H 2 | #define PETTYCOIN_ADDR_H 3 | #include "config.h" 4 | #include "protocol.h" 5 | 6 | static inline void pubkey_to_addr(const struct protocol_pubkey *key, 7 | struct protocol_address *addr) 8 | { 9 | SHA256_CTX ctx; 10 | u8 sha[SHA256_DIGEST_LENGTH]; 11 | 12 | SHA256_Init(&ctx); 13 | SHA256_Update(&ctx, key->key, sizeof(key->key)); 14 | SHA256_Final(sha, &ctx); 15 | 16 | RIPEMD160(sha, sizeof(sha), addr->addr); 17 | } 18 | 19 | #endif /* PETTYCOIN_ADDR_H */ 20 | -------------------------------------------------------------------------------- /ccan/ccan/cast/test/compile_fail-cast_static-2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | char *c; 7 | #ifdef FAIL 8 | long 9 | #else 10 | char 11 | #endif 12 | *p = 0; 13 | 14 | c = cast_static(char *, p); 15 | (void) c; /* Suppress unused-but-set-variable warning. */ 16 | return 0; 17 | } 18 | 19 | #ifdef FAIL 20 | #if !HAVE_COMPOUND_LITERALS 21 | #error "Unfortunately we don't fail if cast_static is a noop" 22 | #endif 23 | #endif 24 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-isxdigit.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF 8 | #error We need typeof to check isxdigit. 9 | #endif 10 | char 11 | #else 12 | unsigned char 13 | #endif 14 | c = argv[0][0]; 15 | 16 | #ifdef FAIL 17 | /* Fake fail on unsigned char platforms. */ 18 | BUILD_ASSERT((char)255 < 0); 19 | #endif 20 | 21 | return isxdigit(c); 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/time/test/run-monotonic.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | struct timemono t1, t2; 8 | struct timerel t3; 9 | 10 | plan_tests(2); 11 | 12 | /* Test time_mono */ 13 | t1 = time_mono(); 14 | t2 = time_mono(); 15 | 16 | ok1(!time_less_(t2.ts, t1.ts)); 17 | 18 | t3.ts.tv_sec = 1; 19 | t3.ts.tv_nsec = 0; 20 | 21 | ok1(time_less(timemono_between(t1, t2), t3)); 22 | 23 | return exit_status(); 24 | } 25 | -------------------------------------------------------------------------------- /dns.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_DNS_H 2 | #define PETTYCOIN_DNS_H 3 | #include "config.h" 4 | #include 5 | #include 6 | #include 7 | 8 | struct state; 9 | struct protocol_net_address; 10 | tal_t *dns_resolve_and_connect(struct state *state, 11 | const char *name, const char *port, 12 | struct io_plan *(*init)(struct io_conn *, 13 | struct state *, 14 | struct protocol_net_address *)); 15 | 16 | #endif /* PETTYCOIN_DNS_H */ 17 | -------------------------------------------------------------------------------- /horizon.c: -------------------------------------------------------------------------------- 1 | #include "block_info.h" 2 | #include "horizon.h" 3 | #include "state.h" 4 | #include "timestamp.h" 5 | 6 | /* When do transactions in this block expire? */ 7 | u32 block_expiry(struct state *state, const struct block_info *bi) 8 | { 9 | return block_timestamp(bi) 10 | + PROTOCOL_TX_HORIZON_SECS(state->test_net); 11 | } 12 | 13 | bool block_expired_by(u32 expires, u32 now) 14 | { 15 | /* We allow line-balls: ie. if exactly on horizon, it's *not* expired. */ 16 | return expires < now; 17 | } 18 | -------------------------------------------------------------------------------- /ccan/ccan/cast/test/compile_fail-cast_static.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | long c; 7 | #ifdef FAIL 8 | char * 9 | #else 10 | char 11 | #endif 12 | x = 0; 13 | 14 | c = cast_static(long, x); 15 | (void) c; /* Suppress unused-but-set-variable warning. */ 16 | return 0; 17 | } 18 | 19 | #ifdef FAIL 20 | #if !HAVE_COMPOUND_LITERALS 21 | #error "Unfortunately we don't fail if cast_static without compound literals" 22 | #endif 23 | #endif 24 | -------------------------------------------------------------------------------- /jsmn/Makefile: -------------------------------------------------------------------------------- 1 | # You can put your build options here 2 | -include config.mk 3 | 4 | all: libjsmn.a 5 | 6 | libjsmn.a: jsmn.o 7 | $(AR) rc $@ $^ 8 | 9 | %.o: %.c jsmn.h 10 | $(CC) -c $(CFLAGS) $< -o $@ 11 | 12 | test: jsmn_test 13 | ./jsmn_test 14 | 15 | jsmn_test: jsmn_test.o 16 | $(CC) -L. -ljsmn $< -o $@ 17 | 18 | jsmn_test.o: jsmn_test.c libjsmn.a 19 | 20 | clean: 21 | rm -f jsmn.o jsmn_test.o 22 | rm -f jsmn_test 23 | rm -f jsmn_test.exe 24 | rm -f libjsmn.a 25 | 26 | .PHONY: all clean test 27 | 28 | -------------------------------------------------------------------------------- /timestamp.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_TIMESTAMP_H 2 | #define PETTYCOIN_TIMESTAMP_H 3 | #include "config.h" 4 | #include 5 | #include 6 | #include 7 | 8 | struct state; 9 | struct block; 10 | 11 | bool check_timestamp(struct state *state, u32 timestamp, 12 | const struct block *prev); 13 | 14 | /* FIXME: Consensus time? */ 15 | static inline u32 current_time(void) 16 | { 17 | return time_now().ts.tv_sec; 18 | } 19 | #endif /* PETTYCOIN_TIMESTAMP_H */ 20 | -------------------------------------------------------------------------------- /ccan/ccan/tal/test/run-free.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static void destroy_errno(char *p) 6 | { 7 | errno = ENOENT; 8 | } 9 | 10 | int main(void) 11 | { 12 | char *p; 13 | 14 | plan_tests(2); 15 | 16 | p = tal(NULL, char); 17 | ok1(tal_add_destructor(p, destroy_errno)); 18 | 19 | /* Errno save/restored across free. */ 20 | errno = EINVAL; 21 | tal_free(p); 22 | ok1(errno == EINVAL); 23 | 24 | tal_cleanup(); 25 | return exit_status(); 26 | } 27 | -------------------------------------------------------------------------------- /peer_wants.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_PEER_WANTS_H 2 | #define PETTYCOIN_PEER_WANTS_H 3 | #include "config.h" 4 | #include 5 | 6 | struct peer; 7 | union protocol_tx; 8 | 9 | /* Is peer interested in the shard of this tx? */ 10 | bool peer_wants_tx(const struct peer *peer, 11 | const union protocol_tx *tx); 12 | 13 | /* Is peer interested in the (other) shard affected by this tx? */ 14 | bool peer_wants_tx_other(const struct peer *peer, 15 | const union protocol_tx *tx); 16 | #endif /* PETTYCOIN_PEER_WANTS_H */ 17 | -------------------------------------------------------------------------------- /tools/Makefile: -------------------------------------------------------------------------------- 1 | TOOL_BINS = tools/make-peer-packet tools/spv-blocks tools/cdump-enum-names 2 | 3 | default-tools: 4 | @echo Run make tools from top dir. >&2 && exit 1 5 | 6 | tools: $(TOOL_BINS) 7 | 8 | tools/make-peer-packet: tools/make-peer-packet.o netaddr.o tal_packet.o marshal.o minimal_log.o $(CCAN_OBJS) 9 | 10 | tools/cdump-enum-names: tools/cdump-enum-names.o $(CCAN_OBJS) 11 | 12 | clean: tools-clean 13 | distclean: tools-distclean 14 | 15 | tools-clean: 16 | $(RM) $(TOOL_BINS) tools/*.o 17 | 18 | tools-distclean: 19 | -------------------------------------------------------------------------------- /ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* NULL args for callback function should be OK for normal and _def. */ 5 | 6 | static void _register_callback(void (*cb)(const void *arg), const void *arg) 7 | { 8 | } 9 | 10 | #define register_callback(cb, arg) \ 11 | _register_callback(typesafe_cb(void, const void *, (cb), (arg)), (arg)) 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | register_callback(NULL, "hello world"); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | run-01-base16 2 | run-01-base58 3 | run-01-create_gateway_transaction 4 | run-01-difficulty 5 | run-01-json 6 | run-01-jsonrpc 7 | run-01-marshal 8 | run-02-create_block 9 | run-02-generate 10 | run-02-prev_txhashes 11 | run-03-check_block 12 | run-04-create_normal_transaction 13 | run-05-create_proof 14 | run-05-create_to_gateway_transaction 15 | run-05-proof 16 | run-06-log 17 | run-07-block_swizzle 18 | run-08-simple-chain 19 | run-08-tx_shard 20 | run-09-chain 21 | run-10-doublespend 22 | run-20-gateway 23 | easy_genesis.c 24 | -------------------------------------------------------------------------------- /ccan/ccan/container_of/test/compile_fail-types.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct foo { 5 | int a; 6 | char b; 7 | }; 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | struct foo foo = { .a = 1, .b = 2 }, *foop; 12 | int *intp = &foo.a; 13 | 14 | #ifdef FAIL 15 | /* b is a char, but intp is an int * */ 16 | foop = container_of(intp, struct foo, b); 17 | #else 18 | foop = NULL; 19 | #endif 20 | (void) foop; /* Suppress unused-but-set-variable warning. */ 21 | return intp == NULL; 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/structeq/test/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct mydata { 5 | int start, end; 6 | }; 7 | 8 | int main(void) 9 | { 10 | struct mydata a, b; 11 | 12 | /* This is how many tests you plan to run */ 13 | plan_tests(3); 14 | 15 | a.start = 0; 16 | a.end = 100; 17 | ok1(structeq(&a, &a)); 18 | 19 | b = a; 20 | ok1(structeq(&a, &b)); 21 | 22 | b.end++; 23 | ok1(!structeq(&a, &b)); 24 | 25 | /* This exits depending on whether all tests passed */ 26 | return exit_status(); 27 | } 28 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/test/run-free.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | static void destroy_errno(char *p) 7 | { 8 | errno = ENOENT; 9 | } 10 | 11 | int main(void) 12 | { 13 | char *p; 14 | 15 | plan_tests(2); 16 | 17 | p = tal(NULL, char); 18 | ok1(tal_add_destructor(p, destroy_errno)); 19 | 20 | /* Errno save/restored across free. */ 21 | errno = EINVAL; 22 | tal_free(p); 23 | ok1(errno == EINVAL); 24 | 25 | return exit_status(); 26 | } 27 | -------------------------------------------------------------------------------- /ccan/ccan/asort/test/compile_fail-context-type.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static int cmp(char *const *a, char *const *b, int *flag) 5 | { 6 | return 0; 7 | } 8 | 9 | int main(int argc, char **argv) 10 | { 11 | #ifdef FAIL 12 | #if HAVE_TYPEOF && HAVE_BUILTIN_CHOOSE_EXPR && HAVE_BUILTIN_TYPES_COMPATIBLE_P 13 | char flag; 14 | #else 15 | #error "Unfortunately we don't fail if no typecheck_cb support." 16 | #endif 17 | #else 18 | int flag; 19 | #endif 20 | asort(argv+1, argc-1, cmp, &flag); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/talloc/test/run-free.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | static void destroy_errno(char *p) 7 | { 8 | errno = ENOENT; 9 | } 10 | 11 | int main(void) 12 | { 13 | char *p; 14 | 15 | plan_tests(2); 16 | 17 | p = tal(NULL, char); 18 | ok1(tal_add_destructor(p, destroy_errno)); 19 | 20 | /* Errno save/restored across free. */ 21 | errno = EINVAL; 22 | tal_free(p); 23 | ok1(errno == EINVAL); 24 | 25 | return exit_status(); 26 | } 27 | -------------------------------------------------------------------------------- /welcome.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_WELCOME_H 2 | #define PETTYCOIN_WELCOME_H 3 | #include "config.h" 4 | #include "protocol_net.h" 5 | #include 6 | 7 | struct state; 8 | struct protocol_pkt_welcome *make_welcome(const tal_t *ctx, 9 | const struct state *state, 10 | const struct protocol_net_address *a); 11 | 12 | enum protocol_ecode check_welcome(const struct peer *peer, 13 | const struct protocol_pkt_welcome *w, 14 | const struct protocol_block_header **bhdr, 15 | size_t *blen); 16 | 17 | #endif /* PETTYCOIN_WELCOME_H */ 18 | -------------------------------------------------------------------------------- /ccan/ccan/cast/test/compile_fail-cast_signed-const.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | unsigned char *uc; 7 | #ifdef FAIL 8 | const 9 | #endif 10 | char 11 | *p = NULL; 12 | 13 | uc = cast_signed(unsigned char *, p); 14 | (void) uc; /* Suppress unused-but-set-variable warning. */ 15 | return 0; 16 | } 17 | 18 | #ifdef FAIL 19 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 20 | #error "Unfortunately we don't fail if cast_const can only use size" 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /ccan/ccan/str/test/compile_fail-isblank.c: -------------------------------------------------------------------------------- 1 | #define CCAN_STR_DEBUG 1 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | #ifdef FAIL 7 | #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF || !HAVE_ISBLANK 8 | #error We need typeof to check isblank. 9 | #endif 10 | char 11 | #else 12 | unsigned char 13 | #endif 14 | c = argv[0][0]; 15 | 16 | #ifdef FAIL 17 | /* Fake fail on unsigned char platforms. */ 18 | BUILD_ASSERT((char)255 < 0); 19 | #endif 20 | 21 | #if HAVE_ISBLANK 22 | return isblank(c); 23 | #else 24 | return c; 25 | #endif 26 | } 27 | -------------------------------------------------------------------------------- /pkt_names.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_PKT_NAMES_H 2 | #define PETTYCOIN_PKT_NAMES_H 3 | #include "config.h" 4 | #include "protocol_net.h" 5 | #include 6 | 7 | struct pkt_names { 8 | enum protocol_pkt_type type; 9 | const char *name; 10 | }; 11 | 12 | extern struct pkt_names pkt_names[]; 13 | 14 | static inline const char *pkt_name(enum protocol_pkt_type type) 15 | { 16 | unsigned int i; 17 | 18 | for (i = 0; pkt_names[i].name; i++) 19 | if (pkt_names[i].type == type) 20 | return pkt_names[i].name; 21 | 22 | return NULL; 23 | } 24 | #endif /* PETTYCOIN_PKT_NAMES_H */ 25 | -------------------------------------------------------------------------------- /ccan/ccan/tal/test/run-resizez.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *parent, *c; 8 | int i; 9 | 10 | plan_tests(1 + 3 * 100 + 98); 11 | 12 | parent = tal(NULL, char); 13 | ok1(parent); 14 | 15 | for (i = 0; i < 100; i++) { 16 | c = tal_arr(parent, char, 1); 17 | ok1(tal_resizez(&c, i)); 18 | ok1(tal_count(c) == i); 19 | ok1(tal_parent(c) == parent); 20 | if (i > 1) 21 | ok1(c[i-1] == '\0'); 22 | } 23 | tal_free(parent); 24 | 25 | tal_cleanup(); 26 | return exit_status(); 27 | } 28 | -------------------------------------------------------------------------------- /ccan/ccan/tal/path/test/run-ext_off.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | plan_tests(9); 8 | 9 | ok1(path_ext_off("foo") == 3); 10 | ok1(path_ext_off(".foo") == 4); 11 | ok1(path_ext_off("bar.foo") == 3); 12 | ok1(path_ext_off("bar/foo") == 7); 13 | ok1(path_ext_off("bar/.foo") == 8); 14 | ok1(path_ext_off(".bar/foo") == 8); 15 | ok1(path_ext_off("foo.bar/foo") == 11); 16 | ok1(path_ext_off("foo.bar/foo.") == 11); 17 | ok1(path_ext_off("foo.bar/foo..") == 12); 18 | return exit_status(); 19 | } 20 | -------------------------------------------------------------------------------- /ccan/ccan/alignof/alignof.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_ALIGNOF_H 3 | #define CCAN_ALIGNOF_H 4 | #include "config.h" 5 | 6 | /** 7 | * ALIGNOF - get the alignment of a type 8 | * @t: the type to test 9 | * 10 | * This returns a safe alignment for the given type. 11 | */ 12 | #if HAVE_ALIGNOF 13 | /* A GCC extension. */ 14 | #define ALIGNOF(t) __alignof__(t) 15 | #else 16 | /* Alignment by measuring structure padding. */ 17 | #define ALIGNOF(t) ((char *)(&((struct { char c; t _h; } *)0)->_h) - (char *)0) 18 | #endif 19 | 20 | #endif /* CCAN_ALIGNOF_H */ 21 | -------------------------------------------------------------------------------- /ccan/ccan/tal/path/path/test/run-ext_off.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | plan_tests(9); 8 | 9 | ok1(path_ext_off("foo") == 3); 10 | ok1(path_ext_off(".foo") == 4); 11 | ok1(path_ext_off("bar.foo") == 3); 12 | ok1(path_ext_off("bar/foo") == 7); 13 | ok1(path_ext_off("bar/.foo") == 8); 14 | ok1(path_ext_off(".bar/foo") == 8); 15 | ok1(path_ext_off("foo.bar/foo") == 11); 16 | ok1(path_ext_off("foo.bar/foo.") == 11); 17 | ok1(path_ext_off("foo.bar/foo..") == 12); 18 | return exit_status(); 19 | } 20 | -------------------------------------------------------------------------------- /ecode_names.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_ECODE_NAMES_H 2 | #define PETTYCOIN_ECODE_NAMES_H 3 | #include "config.h" 4 | #include "protocol_ecode.h" 5 | #include 6 | 7 | struct ecode_names { 8 | enum protocol_ecode ecode; 9 | const char *name; 10 | }; 11 | 12 | extern struct ecode_names ecode_names[]; 13 | 14 | static inline const char *ecode_name(enum protocol_ecode ecode) 15 | { 16 | unsigned int i; 17 | 18 | for (i = 0; ecode_names[i].name; i++) 19 | if (ecode_names[i].ecode == ecode) 20 | return ecode_names[i].name; 21 | 22 | return NULL; 23 | } 24 | #endif /* PETTYCOIN_ECODE_NAMES_H */ 25 | -------------------------------------------------------------------------------- /reward.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_REWARD_H 2 | #define PETTYCOIN_REWARD_H 3 | #include "config.h" 4 | #include 5 | 6 | struct state; 7 | struct block; 8 | 9 | /* Returns false if we for_block is empty, or reward tx not yet known */ 10 | bool reward_get_tx(struct state *state, 11 | const struct block *reward_block, 12 | const struct block *claim_block, 13 | u16 *shardnum, u8 *txoff); 14 | 15 | /* If tx is the reward tx for block, how much is reward? */ 16 | u32 reward_amount(const struct block *reward_block, 17 | const union protocol_tx *tx); 18 | 19 | #endif /* PETTYCOIN_REWARD_H */ 20 | -------------------------------------------------------------------------------- /hex.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_HEX_H 2 | #define PETTYCOIN_HEX_H 3 | #include "config.h" 4 | #include 5 | #include 6 | 7 | /* Unpack slen hex digits into buf; fail on bad char or not exact length */ 8 | bool from_hex(const char *str, size_t slen, void *buf, size_t bufsize); 9 | 10 | /* Allocate hex string off ctx */ 11 | char *to_hex(const tal_t *ctx, const void *buf, size_t bufsize); 12 | 13 | /* dest becomes nul terminated string, returns bufsize used. */ 14 | size_t to_hex_direct(char *dest, size_t destlen, 15 | const void *buf, size_t bufsize); 16 | 17 | #endif /* PETTYCOIN_HEX_H */ 18 | -------------------------------------------------------------------------------- /ccan/ccan/tcon/test/compile_fail-tcon_cast.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct container { 5 | void *p; 6 | }; 7 | 8 | struct int_and_charp_container { 9 | struct container raw; 10 | TCON(int *tc1; char *tc2); 11 | }; 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | struct int_and_charp_container icon; 16 | #ifdef FAIL 17 | #if !HAVE_TYPEOF 18 | #error We cannot detect type problems without HAVE_TYPEOF 19 | #endif 20 | char * 21 | #else 22 | int * 23 | #endif 24 | x; 25 | 26 | icon.raw.p = NULL; 27 | x = tcon_cast(&icon, tc1, icon.raw.p); 28 | return x != NULL ? 0 : 1; 29 | } 30 | -------------------------------------------------------------------------------- /pseudorand.c: -------------------------------------------------------------------------------- 1 | #include "pseudorand.h" 2 | #include 3 | #include 4 | #include 5 | 6 | static struct isaac64_ctx isaac64_initted; 7 | struct isaac64_ctx *isaac64; 8 | 9 | void pseudorand_init(void) 10 | { 11 | unsigned char seedbuf[16]; 12 | 13 | /* PRNG */ 14 | if (RAND_bytes(seedbuf, sizeof(seedbuf)) != 1) 15 | errx(1, "Could not seed PRNG: %s", 16 | ERR_error_string(ERR_get_error(), NULL)); 17 | 18 | isaac64_init(&isaac64_initted, seedbuf, sizeof(seedbuf)); 19 | /* We use a pointer so we will crash if unused before init */ 20 | isaac64 = &isaac64_initted; 21 | } 22 | -------------------------------------------------------------------------------- /ccan/ccan/tcon/test/compile_ok.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct container { 5 | void *p; 6 | }; 7 | 8 | struct int_container { 9 | struct container raw; 10 | TCON(int tc); 11 | }; 12 | 13 | struct charp_and_int_container { 14 | struct container raw; 15 | TCON(int tc1; char *tc2); 16 | }; 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | struct int_container icon; 21 | struct charp_and_int_container cicon; 22 | 23 | tcon_check(&icon, tc, 7)->raw.p = NULL; 24 | tcon_check(&cicon, tc1, 7)->raw.p = argv[0]; 25 | tcon_check(&cicon, tc2, argv[0])->raw.p = argv[0]; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /ccan/ccan/typesafe_cb/test/compile_fail-cast_if_type-promotable.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void _set_some_value(void *val) 5 | { 6 | } 7 | 8 | #define set_some_value(expr) \ 9 | _set_some_value(typesafe_cb_cast(void *, long, (expr))) 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | #ifdef FAIL 14 | bool x = 0; 15 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 16 | #error "Unfortunately we don't fail if typesafe_cb_cast is a noop." 17 | #endif 18 | #else 19 | long x = 0; 20 | #endif 21 | set_some_value(x); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /merkle_hashes.c: -------------------------------------------------------------------------------- 1 | #include "merkle_hashes.h" 2 | #include "merkle_recurse.h" 3 | #include "protocol.h" 4 | #include "protocol_net.h" 5 | 6 | static void merkle_hash(size_t n, void *data, 7 | struct protocol_double_sha *merkle) 8 | { 9 | const struct protocol_txrefhash *hashes = data; 10 | 11 | merkle_two_hashes(&hashes[n].txhash.sha, &hashes[n].refhash, merkle); 12 | } 13 | 14 | void merkle_hashes(const struct protocol_txrefhash *hashes, 15 | size_t off, size_t num_hashes, 16 | struct protocol_double_sha *merkle) 17 | { 18 | merkle_recurse(off, num_hashes, 256, merkle_hash, (void *)hashes, 19 | merkle); 20 | } 21 | -------------------------------------------------------------------------------- /ccan/ccan/container_of/test/compile_fail-var-types.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct foo { 5 | int a; 6 | char b; 7 | }; 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | struct foo foo = { .a = 1, .b = 2 }, *foop; 12 | int *intp = &foo.a; 13 | 14 | #ifdef FAIL 15 | /* b is a char, but intp is an int * */ 16 | foop = container_of_var(intp, foop, b); 17 | #if !HAVE_TYPEOF 18 | #error "Unfortunately we don't fail if we don't have typeof." 19 | #endif 20 | #else 21 | foop = NULL; 22 | #endif 23 | (void) foop; /* Suppress unused-but-set-variable warning. */ 24 | return intp == NULL; 25 | } 26 | -------------------------------------------------------------------------------- /ccan/ccan/tal/str/str/test/helper.h: -------------------------------------------------------------------------------- 1 | /* tal/talloc can't implement tal_first/tal_next. */ 2 | #ifdef TAL_USE_TALLOC 3 | static inline bool no_children(const void *ctx) 4 | { 5 | return talloc_total_blocks(ctx) == 1; 6 | } 7 | 8 | static inline bool single_child(const void *ctx, const void *child) 9 | { 10 | return talloc_total_blocks(ctx) == 2 && tal_parent(child) == ctx; 11 | } 12 | #else 13 | static inline bool no_children(const void *ctx) 14 | { 15 | return !tal_first(ctx); 16 | } 17 | 18 | static inline bool single_child(const void *ctx, const void *child) 19 | { 20 | return tal_first(ctx) == child && !tal_next(ctx, child); 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /ccan/ccan/tal/str/test/helper.h: -------------------------------------------------------------------------------- 1 | /* tal/talloc can't implement tal_first/tal_next. */ 2 | #ifdef TAL_USE_TALLOC 3 | static inline bool no_children(const void *ctx) 4 | { 5 | return talloc_total_blocks(ctx) == 1; 6 | } 7 | 8 | static inline bool single_child(const void *ctx, const void *child) 9 | { 10 | return talloc_total_blocks(ctx) == 2 && tal_parent(child) == ctx; 11 | } 12 | #else 13 | static inline bool no_children(const void *ctx) 14 | { 15 | return !tal_first(ctx); 16 | } 17 | 18 | static inline bool single_child(const void *ctx, const void *child) 19 | { 20 | return tal_first(ctx) == child && !tal_next(ctx, child); 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /merkle_txs.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_MERKLE_TXS_H 2 | #define PETTYCOIN_MERKLE_TXS_H 3 | #include "config.h" 4 | #include 5 | #include 6 | 7 | struct block_shard; 8 | struct protocol_double_sha; 9 | 10 | /* Merkle together a shard of transactions */ 11 | void merkle_txs(const struct block_shard *shard, 12 | struct protocol_double_sha *merkle); 13 | 14 | /* Merkle together some subset (for creating proofs). */ 15 | void merkle_some_txs(const struct block_shard *shard, 16 | size_t off, size_t max, 17 | struct protocol_double_sha *merkle); 18 | 19 | #endif /* PETTYCOIN_MERKLE_TXS_H */ 20 | 21 | 22 | -------------------------------------------------------------------------------- /ccan/ccan/array_size/test/compile_fail-function-param.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct foo { 5 | unsigned int a, b; 6 | }; 7 | 8 | int check_parameter(const struct foo array[4]); 9 | int check_parameter(const struct foo array[4]) 10 | { 11 | #ifdef FAIL 12 | return (ARRAY_SIZE(array) == 4); 13 | #if !HAVE_TYPEOF || !HAVE_BUILTIN_TYPES_COMPATIBLE_P 14 | #error "Unfortunately we don't fail if _array_size_chk is a noop." 15 | #endif 16 | #else 17 | return sizeof(array) == 4 * sizeof(struct foo); 18 | #endif 19 | } 20 | 21 | int main(int argc, char *argv[]) 22 | { 23 | return check_parameter(NULL); 24 | } 25 | -------------------------------------------------------------------------------- /ccan/ccan/structeq/structeq.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_STRUCTEQ_H 3 | #define CCAN_STRUCTEQ_H 4 | #include 5 | 6 | /** 7 | * structeq - are two structures bitwise equal (including padding!) 8 | * @a: a pointer to a structure 9 | * @b: a pointer to a structure of the same type. 10 | * 11 | * If you *know* a structure has no padding, you can memcmp them. At 12 | * least this way, the compiler will issue a warning if the structs are 13 | * different types! 14 | */ 15 | #define structeq(a, b) \ 16 | (memcmp((a), (b), sizeof(*(a)) + 0 * sizeof((a) == (b))) == 0) 17 | #endif /* CCAN_STRUCTEQ_H */ 18 | -------------------------------------------------------------------------------- /shadouble.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_SHADOUBLE_H 2 | #define PETTYCOIN_SHADOUBLE_H 3 | #include "config.h" 4 | #include 5 | 6 | struct protocol_double_sha; 7 | #define double_sha(shap, p) double_sha_of((shap), (p), sizeof(*p)) 8 | #define double_sha_arr(shap, p, n) double_sha_of((shap), (p), sizeof(*p)*(n)) 9 | 10 | void double_sha_of(struct protocol_double_sha *sha, const void *p, size_t len); 11 | 12 | /* Checks data is defined, if using valgrind */ 13 | int SHA256_CheckUpdate(SHA256_CTX *c, const void *data, size_t len); 14 | 15 | void SHA256_Double_Final(SHA256_CTX *ctx, struct protocol_double_sha *sha); 16 | #endif /* PETTYCOIN_SHADOUBLE_H */ 17 | -------------------------------------------------------------------------------- /ccan/ccan/typesafe_cb/test/compile_fail-typesafe_cb_cast.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void _set_some_value(void *val); 4 | 5 | void _set_some_value(void *val) 6 | { 7 | } 8 | 9 | #define set_some_value(expr) \ 10 | _set_some_value(typesafe_cb_cast(void *, unsigned long, (expr))) 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | #ifdef FAIL 15 | int x = 0; 16 | set_some_value(x); 17 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 18 | #error "Unfortunately we don't fail if typesafe_cb_cast is a noop." 19 | #endif 20 | #else 21 | void *p = 0; 22 | set_some_value(p); 23 | #endif 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /detached_block.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_DETACHED_BLOCK_H 2 | #define PETTYCOIN_DETACHED_BLOCK_H 3 | #include "config.h" 4 | #include 5 | 6 | struct block; 7 | struct state; 8 | struct protocol_block_id; 9 | struct block_info; 10 | struct protocol_pkt_block; 11 | 12 | void seek_detached_blocks(struct state *state, const struct block *block); 13 | 14 | bool have_detached_block(const struct state *state, 15 | const struct protocol_block_id *sha); 16 | 17 | void add_detached_block(struct state *state, 18 | const tal_t *pkt_ctx, 19 | const struct protocol_block_id *sha, 20 | const struct block_info *bi); 21 | 22 | #endif /* PETTYCOIN_DETACHED_BLOCK_H */ 23 | -------------------------------------------------------------------------------- /ccan/ccan/check_type/test/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | int x = 0, y = 0; 7 | 8 | plan_tests(9); 9 | 10 | ok1(check_type(argc, int) == 0); 11 | ok1(check_type(&argc, int *) == 0); 12 | ok1(check_types_match(argc, argc) == 0); 13 | ok1(check_types_match(argc, x) == 0); 14 | ok1(check_types_match(&argc, &x) == 0); 15 | 16 | ok1(check_type(x++, int) == 0); 17 | ok(x == 0, "check_type does not evaluate expression"); 18 | ok1(check_types_match(x++, y++) == 0); 19 | ok(x == 0 && y == 0, "check_types_match does not evaluate expressions"); 20 | 21 | return exit_status(); 22 | } 23 | -------------------------------------------------------------------------------- /shard.c: -------------------------------------------------------------------------------- 1 | #include "addr.h" 2 | #include "shard.h" 3 | #include "tx.h" 4 | #include 5 | 6 | /* This must match the order used in tx_cmp */ 7 | u32 shard_of_tx(const union protocol_tx *tx, u8 shard_order) 8 | { 9 | const struct protocol_address *addr; 10 | struct protocol_address tmp; 11 | 12 | switch (tx_type(tx)) { 13 | case TX_NORMAL: 14 | case TX_TO_GATEWAY: 15 | case TX_CLAIM: 16 | get_tx_input_address(tx, &tmp); 17 | addr = &tmp; 18 | goto known; 19 | case TX_FROM_GATEWAY: 20 | addr = &get_from_gateway_outputs(&tx->from_gateway)[0] 21 | .output_addr; 22 | goto known; 23 | } 24 | abort(); 25 | 26 | known: 27 | return shard_of(addr, shard_order); 28 | } 29 | -------------------------------------------------------------------------------- /ccan/ccan/breakpoint/breakpoint.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_BREAKPOINT_H 3 | #define CCAN_BREAKPOINT_H 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void breakpoint_init(void) COLD; 11 | extern bool breakpoint_initialized; 12 | extern bool breakpoint_under_debug; 13 | 14 | /** 15 | * breakpoint - stop if running under the debugger. 16 | */ 17 | static inline void breakpoint(void) 18 | { 19 | if (!breakpoint_initialized) 20 | breakpoint_init(); 21 | if (breakpoint_under_debug) 22 | kill(getpid(), SIGTRAP); 23 | } 24 | #endif /* CCAN_BREAKPOINT_H */ 25 | -------------------------------------------------------------------------------- /ccan/ccan/cast/test/compile_fail-cast_const.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* Note: this *isn't* sizeof(char) on all platforms. */ 5 | struct char_struct { 6 | char c; 7 | }; 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | char *uc; 12 | const 13 | #ifdef FAIL 14 | struct char_struct 15 | #else 16 | char 17 | #endif 18 | *p = NULL; 19 | 20 | uc = cast_const(char *, p); 21 | (void) uc; /* Suppress unused-but-set-variable warning. */ 22 | return 0; 23 | } 24 | 25 | #ifdef FAIL 26 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 27 | #error "Unfortunately we don't fail if cast_const can only use size" 28 | #endif 29 | #endif 30 | -------------------------------------------------------------------------------- /ccan/ccan/cast/test/compile_fail-cast_const2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* Note: this *isn't* sizeof(char) on all platforms. */ 5 | struct char_struct { 6 | char c; 7 | }; 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | char **uc; 12 | const 13 | #ifdef FAIL 14 | struct char_struct 15 | #else 16 | char 17 | #endif 18 | **p = NULL; 19 | 20 | uc = cast_const2(char **, p); 21 | (void) uc; /* Suppress unused-but-set-variable warning. */ 22 | return 0; 23 | } 24 | 25 | #ifdef FAIL 26 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 27 | #error "Unfortunately we don't fail if cast_const can only use size" 28 | #endif 29 | #endif 30 | -------------------------------------------------------------------------------- /merkle_recurse.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_MERKLE_RECURSE_H 2 | #define PETTYCOIN_MERKLE_RECURSE_H 3 | #include "config.h" 4 | #include 5 | 6 | struct protocol_double_sha; 7 | 8 | void merkle_recurse(size_t off, size_t max_off, size_t num, 9 | void (*fn)(size_t n, void *data, 10 | struct protocol_double_sha *merkle), 11 | void *data, 12 | struct protocol_double_sha *merkle); 13 | 14 | /* Helper to merkle two hashes together: SHA256(SHA256([a][b])) */ 15 | void merkle_two_hashes(const struct protocol_double_sha *a, 16 | const struct protocol_double_sha *b, 17 | struct protocol_double_sha *merkle); 18 | 19 | #endif /* PETTYCOIN_MERKLE_RECURSE_H */ 20 | 21 | 22 | -------------------------------------------------------------------------------- /netaddr.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_NETADDR_H 2 | #define PETTYCOIN_NETADDR_H 3 | #include "config.h" 4 | #include 5 | 6 | struct protocol_net_address; 7 | struct addrinfo *mk_addrinfo(const tal_t *ctx, 8 | const struct protocol_net_address *netaddr); 9 | 10 | bool addrinfo_to_netaddr(struct protocol_net_address *netaddr, 11 | const struct addrinfo *a); 12 | 13 | int socket_for_addr(const struct protocol_net_address *addr); 14 | bool get_peer_addr(int fd, struct protocol_net_address *addr); 15 | bool get_local_addr(int fd, struct protocol_net_address *addr); 16 | 17 | char *netaddr_string(const tal_t *ctx, const struct protocol_net_address *addr); 18 | #endif /* PETTYCOIN_NETADDR_H */ 19 | -------------------------------------------------------------------------------- /ccan/ccan/cast/test/compile_fail-cast_const3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* Note: this *isn't* sizeof(char) on all platforms. */ 5 | struct char_struct { 6 | char c; 7 | }; 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | char ***uc; 12 | const 13 | #ifdef FAIL 14 | struct char_struct 15 | #else 16 | char 17 | #endif 18 | ***p = NULL; 19 | 20 | uc = cast_const3(char ***, p); 21 | (void) uc; /* Suppress unused-but-set-variable warning. */ 22 | return 0; 23 | } 24 | 25 | #ifdef FAIL 26 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 27 | #error "Unfortunately we don't fail if cast_const can only use size" 28 | #endif 29 | #endif 30 | -------------------------------------------------------------------------------- /ccan/ccan/short_types/test/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | plan_tests(16); 9 | 10 | ok1(sizeof(u64) == 8); 11 | ok1(sizeof(s64) == 8); 12 | ok1(sizeof(u32) == 4); 13 | ok1(sizeof(s32) == 4); 14 | ok1(sizeof(u16) == 2); 15 | ok1(sizeof(s16) == 2); 16 | ok1(sizeof(u8) == 1); 17 | ok1(sizeof(s8) == 1); 18 | 19 | /* Signedness tests. */ 20 | ok1((u64)-1 > 0); 21 | ok1((u32)-1 > 0); 22 | ok1((u16)-1 > 0); 23 | ok1((u8)-1 > 0); 24 | ok1((s64)-1 < 0); 25 | ok1((s32)-1 < 0); 26 | ok1((s16)-1 < 0); 27 | ok1((s8)-1 < 0); 28 | 29 | return exit_status(); 30 | } 31 | -------------------------------------------------------------------------------- /petty-addr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Helper to decode and encode addresses. 3 | */ 4 | #include "base58.h" 5 | #include 6 | 7 | /* Simple test code to create a gateway transaction */ 8 | int main(int argc, char *argv[]) 9 | { 10 | char *ret; 11 | struct protocol_address addr; 12 | bool testnet; 13 | 14 | err_set_progname(argv[0]); 15 | 16 | if (argc != 2) 17 | errx(1, "Usage: %s
", argv[0]); 18 | 19 | if (!pettycoin_from_base58(&testnet, &addr, argv[1], strlen(argv[1]))) 20 | errx(1, "Address '%s' not valid", argv[1]); 21 | 22 | ret = pettycoin_to_base58(NULL, testnet, &addr, 23 | !strstarts(argv[1], "P-")); 24 | printf("%s\n", ret); 25 | tal_free(ret); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /prev_blocks.c: -------------------------------------------------------------------------------- 1 | #include "block.h" 2 | #include "chain.h" 3 | #include "prev_blocks.h" 4 | 5 | unsigned int num_prevs(const struct protocol_block_header *hdr) 6 | { 7 | unsigned int i; 8 | 9 | for (i = 0; i < PROTOCOL_NUM_PREV_IDS; i++) { 10 | if (le32_to_cpu(hdr->height) < (1 << i)) 11 | break; 12 | } 13 | 14 | return i; 15 | } 16 | 17 | void make_prev_blocks(const struct block *prev, 18 | struct protocol_block_id prevs[PROTOCOL_NUM_PREV_IDS]) 19 | { 20 | unsigned int i; 21 | 22 | for (i = 0; i < PROTOCOL_NUM_PREV_IDS && prev; i++) { 23 | prevs[i] = prev->sha; 24 | prev = block_ancestor(prev, 1 << i); 25 | } 26 | memset(prevs+i, 0, sizeof(*prevs) * (PROTOCOL_NUM_PREV_IDS-i)); 27 | } 28 | -------------------------------------------------------------------------------- /ccan/ccan/cast/test/compile_fail-cast_signed-sizesame.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* Note: this *isn't* sizeof(char) on all platforms. */ 5 | struct char_struct { 6 | char c; 7 | }; 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | unsigned char *uc; 12 | #ifdef FAIL 13 | struct char_struct 14 | #else 15 | char 16 | #endif 17 | *p = NULL; 18 | 19 | uc = cast_signed(unsigned char *, p); 20 | 21 | (void) uc; /* Suppress unused-but-set-variable warning. */ 22 | return 0; 23 | } 24 | 25 | #ifdef FAIL 26 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 27 | #error "Unfortunately we don't fail if cast_signed can only use size" 28 | #endif 29 | #endif 30 | -------------------------------------------------------------------------------- /ccan/ccan/tal/test/run-expand.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | int *a; 8 | const int arr[] = { 1, 2 }; 9 | 10 | plan_tests(13); 11 | 12 | a = tal_arrz(NULL, int, 1); 13 | ok1(a); 14 | 15 | ok1(tal_expand(&a, arr, 2)); 16 | ok1(tal_count(a) == 3); 17 | ok1(a[0] == 0); 18 | ok1(a[1] == 1); 19 | ok1(a[2] == 2); 20 | 21 | ok1(tal_expand(&a, take(tal_arrz(NULL, int, 1)), 1)); 22 | ok1(tal_count(a) == 4); 23 | ok1(a[0] == 0); 24 | ok1(a[1] == 1); 25 | ok1(a[2] == 2); 26 | ok1(a[3] == 0); 27 | ok1(tal_first(NULL) == a && !tal_next(NULL, a)); 28 | 29 | tal_free(a); 30 | 31 | tal_cleanup(); 32 | return exit_status(); 33 | } 34 | -------------------------------------------------------------------------------- /ccan/ccan/tal/test/run-iter.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define NUM 1000 6 | 7 | int main(void) 8 | { 9 | char *p[NUM] = { NULL }, *iter; 10 | int i; 11 | 12 | plan_tests(NUM + 1 + NUM); 13 | 14 | /* Create a random tree */ 15 | for (i = 0; i < NUM; i++) { 16 | p[i] = tal(p[rand() % (i + 1)], char); 17 | *p[i] = '0'; 18 | } 19 | 20 | i = 0; 21 | for (iter = tal_first(NULL); iter; iter = tal_next(NULL, iter)) { 22 | i++; 23 | ok1(*iter == '0'); 24 | *iter = '1'; 25 | } 26 | ok1(i == NUM); 27 | 28 | for (i = NUM-1; i >= 0; i--) { 29 | ok1(*p[i] == '1'); 30 | tal_free(p[i]); 31 | } 32 | tal_cleanup(); 33 | return exit_status(); 34 | } 35 | -------------------------------------------------------------------------------- /test/blackbox/Makefile: -------------------------------------------------------------------------------- 1 | BLACKBOX_ALL:=$(wildcard test/blackbox/test-*.sh) 2 | BLACKBOX_TESTS:=$(BLACKBOX_ALL:%=check-%) 3 | 4 | check: blackbox-check 5 | 6 | blackbox-check: $(BLACKBOX_TESTS) 7 | 8 | $(BLACKBOX_ALL): $(BINS) 9 | 10 | $(BLACKBOX_TESTS): check-test/blackbox/%: test/blackbox/% 11 | @$(RM) -r $<-dir && mkdir $<-dir 12 | @ulimit -c unlimited; if SCRATCHDIR="$<-dir" RUNPREFIX="./" $< > $<-dir/output 2>&1; then printf "[BLACKBOX] %-44s OK\n" $*; exit 0; else printf "[BLACKBOX] %-44s FAIL\n" $*; cat $<-dir/output; exit 1; fi 13 | 14 | test-clean: test-blackbox-clean 15 | test-distclean: test-blackbox-distclean 16 | 17 | test-blackbox-clean: 18 | $(RM) -r $(BLACKBOX_TESTS:%=%-dir) 19 | 20 | test-blackbox-distclean: 21 | 22 | -------------------------------------------------------------------------------- /ccan/ccan/likely/test/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | static bool one_seems_likely(unsigned int val) 7 | { 8 | if (likely(val == 1)) 9 | return true; 10 | return false; 11 | } 12 | 13 | static bool one_seems_unlikely(unsigned int val) 14 | { 15 | if (unlikely(val == 1)) 16 | return true; 17 | return false; 18 | } 19 | 20 | int main(int argc, char *argv[]) 21 | { 22 | plan_tests(4); 23 | 24 | /* Without debug, we can only check that it doesn't effect functions. */ 25 | ok1(one_seems_likely(1)); 26 | ok1(!one_seems_likely(2)); 27 | ok1(one_seems_unlikely(1)); 28 | ok1(!one_seems_unlikely(2)); 29 | exit(exit_status()); 30 | } 31 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/test/run-count.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *p1, *p2; 8 | 9 | plan_tests(12); 10 | 11 | p1 = tal(NULL, char); 12 | ok1(p1); 13 | ok1(tal_count(p1) == 1); 14 | 15 | p2 = tal_arr(p1, char, 1); 16 | ok1(p2); 17 | ok1(tal_count(p2) == 1); 18 | ok1(tal_resize(&p2, 2)); 19 | ok1(tal_count(p2) == 2); 20 | ok1(tal_check(NULL, NULL)); 21 | tal_free(p2); 22 | 23 | p2 = tal_arrz(p1, char, 7); 24 | ok1(p2); 25 | ok1(tal_count(p2) == 7); 26 | ok1(tal_resize(&p2, 0)); 27 | ok1(tal_count(p2) == 0); 28 | ok1(tal_check(NULL, NULL)); 29 | tal_free(p2); 30 | tal_free(p1); 31 | 32 | return exit_status(); 33 | } 34 | -------------------------------------------------------------------------------- /ccan/ccan/typesafe_cb/test/compile_fail-typesafe_cb-int.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void _callback(void (*fn)(void *arg), void *arg); 5 | void _callback(void (*fn)(void *arg), void *arg) 6 | { 7 | fn(arg); 8 | } 9 | 10 | /* Callback is set up to warn if arg isn't a pointer (since it won't 11 | * pass cleanly to _callback's second arg. */ 12 | #define callback(fn, arg) \ 13 | _callback(typesafe_cb(void, (fn), (arg)), (arg)) 14 | 15 | void my_callback(int something); 16 | void my_callback(int something) 17 | { 18 | } 19 | 20 | int main(int argc, char *argv[]) 21 | { 22 | #ifdef FAIL 23 | /* This fails due to arg, not due to cast. */ 24 | callback(my_callback, 100); 25 | #endif 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /timeout.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_TIMEOUT_H 2 | #define PETTYCOIN_TIMEOUT_H 3 | #include "config.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | struct timeout { 10 | struct timer timer; 11 | struct timerel interval; 12 | void (*cb)(void *); 13 | void *arg; 14 | }; 15 | 16 | struct state; 17 | 18 | void init_timeout_(struct timeout *t, unsigned int interval, 19 | void (*cb)(void *), void *arg); 20 | 21 | void refresh_timeout(struct state *state, struct timeout *t); 22 | 23 | #define init_timeout(t, interval, func, arg) \ 24 | init_timeout_((t), (interval), \ 25 | typesafe_cb(void, void *, (func), (arg)), (arg)) 26 | 27 | #endif /* PETTYCOIN_TIMEOUT_H */ 28 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/talloc/test/run-count.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *p1, *p2; 8 | 9 | plan_tests(12); 10 | 11 | p1 = tal(NULL, char); 12 | ok1(p1); 13 | ok1(tal_count(p1) == 1); 14 | 15 | p2 = tal_arr(p1, char, 1); 16 | ok1(p2); 17 | ok1(tal_count(p2) == 1); 18 | ok1(tal_resize(&p2, 2)); 19 | ok1(tal_count(p2) == 2); 20 | ok1(tal_check(NULL, NULL)); 21 | tal_free(p2); 22 | 23 | p2 = tal_arrz(p1, char, 7); 24 | ok1(p2); 25 | ok1(tal_count(p2) == 7); 26 | ok1(tal_resize(&p2, 0)); 27 | ok1(tal_count(p2) == 0); 28 | ok1(tal_check(NULL, NULL)); 29 | tal_free(p2); 30 | tal_free(p1); 31 | 32 | return exit_status(); 33 | } 34 | -------------------------------------------------------------------------------- /ccan/ccan/tal/test/run-named-nolabels.c: -------------------------------------------------------------------------------- 1 | #define CCAN_TAL_NO_LABELS 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) 7 | { 8 | int *p; 9 | char name[] = "test name"; 10 | 11 | plan_tests(5); 12 | 13 | p = tal(NULL, int); 14 | ok1(tal_name(p) == NULL); 15 | 16 | tal_set_name(p, "some literal"); 17 | ok1(strcmp(tal_name(p), "some literal") == 0); 18 | 19 | tal_set_name(p, name); 20 | ok1(strcmp(tal_name(p), name) == 0); 21 | /* You can't reuse my pointer though! */ 22 | ok1(tal_name(p) != name); 23 | 24 | tal_set_name(p, "some other literal"); 25 | ok1(strcmp(tal_name(p), "some other literal") == 0); 26 | 27 | tal_free(p); 28 | 29 | tal_cleanup(); 30 | return exit_status(); 31 | } 32 | -------------------------------------------------------------------------------- /ccan/ccan/tal/benchmark/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-O3 -Wall -flto -I../../.. 2 | #CFLAGS=-O3 -Wall -I../../.. 3 | #CFLAGS=-g -Wall -I../../.. 4 | LDFLAGS=-O3 -flto 5 | LDLIBS=-lrt 6 | 7 | all: speed samba-allocs 8 | 9 | speed: speed.o tal.o talloc.o time.o list.o take.o str.o 10 | samba-allocs: samba-allocs.o tal.o talloc.o time.o list.o take.o 11 | 12 | tal.o: ../tal.c 13 | $(CC) $(CFLAGS) -c -o $@ $< 14 | str.o: ../str/str.c 15 | $(CC) $(CFLAGS) -c -o $@ $< 16 | talloc.o: ../../talloc/talloc.c 17 | $(CC) $(CFLAGS) -c -o $@ $< 18 | time.o: ../../time/time.c 19 | $(CC) $(CFLAGS) -c -o $@ $< 20 | list.o: ../../list/list.c 21 | $(CC) $(CFLAGS) -c -o $@ $< 22 | take.o: ../../take/take.c 23 | $(CC) $(CFLAGS) -c -o $@ $< 24 | 25 | clean: 26 | rm -f speed samba-allocs *.o 27 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/test/run-named-nolabels.c: -------------------------------------------------------------------------------- 1 | #define CCAN_TAL_NO_LABELS 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) 7 | { 8 | int *p; 9 | char name[] = "test name"; 10 | 11 | plan_tests(5); 12 | 13 | p = tal(NULL, int); 14 | ok1(tal_name(p) == NULL); 15 | 16 | tal_set_name(p, "some literal"); 17 | ok1(strcmp(tal_name(p), "some literal") == 0); 18 | 19 | tal_set_name(p, name); 20 | ok1(strcmp(tal_name(p), name) == 0); 21 | /* You can't reuse my pointer though! */ 22 | ok1(tal_name(p) != name); 23 | 24 | tal_set_name(p, "some other literal"); 25 | ok1(strcmp(tal_name(p), "some other literal") == 0); 26 | 27 | tal_free(p); 28 | 29 | return exit_status(); 30 | } 31 | -------------------------------------------------------------------------------- /ccan/ccan/typesafe_cb/test/compile_fail-typesafe_cb_postargs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void _register_callback(void (*cb)(void *arg, int x), void *arg) 5 | { 6 | } 7 | #define register_callback(cb, arg) \ 8 | _register_callback(typesafe_cb_postargs(void, void *, (cb), (arg), int), (arg)) 9 | 10 | static void my_callback(char *p, int x) 11 | { 12 | } 13 | 14 | int main(int argc, char *argv[]) 15 | { 16 | #ifdef FAIL 17 | int *p; 18 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 19 | #error "Unfortunately we don't fail if typesafe_cb_cast is a noop." 20 | #endif 21 | #else 22 | char *p; 23 | #endif 24 | p = NULL; 25 | register_callback(my_callback, p); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/talloc/test/run-named-nolabels.c: -------------------------------------------------------------------------------- 1 | #define CCAN_TAL_NO_LABELS 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) 7 | { 8 | int *p; 9 | char name[] = "test name"; 10 | 11 | plan_tests(5); 12 | 13 | p = tal(NULL, int); 14 | ok1(tal_name(p) == NULL); 15 | 16 | tal_set_name(p, "some literal"); 17 | ok1(strcmp(tal_name(p), "some literal") == 0); 18 | 19 | tal_set_name(p, name); 20 | ok1(strcmp(tal_name(p), name) == 0); 21 | /* You can't reuse my pointer though! */ 22 | ok1(tal_name(p) != name); 23 | 24 | tal_set_name(p, "some other literal"); 25 | ok1(strcmp(tal_name(p), "some other literal") == 0); 26 | 27 | tal_free(p); 28 | 29 | return exit_status(); 30 | } 31 | -------------------------------------------------------------------------------- /ccan/ccan/typesafe_cb/test/compile_fail-typesafe_cb_preargs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void _register_callback(void (*cb)(int x, void *arg), void *arg) 5 | { 6 | } 7 | 8 | #define register_callback(cb, arg) \ 9 | _register_callback(typesafe_cb_preargs(void, void *, (cb), (arg), int), (arg)) 10 | 11 | static void my_callback(int x, char *p) 12 | { 13 | } 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | #ifdef FAIL 18 | int *p; 19 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 20 | #error "Unfortunately we don't fail if typesafe_cb_cast is a noop." 21 | #endif 22 | #else 23 | char *p; 24 | #endif 25 | p = NULL; 26 | register_callback(my_callback, p); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /shadouble.c: -------------------------------------------------------------------------------- 1 | #include "protocol.h" 2 | #include "shadouble.h" 3 | #include "valgrind.h" 4 | 5 | int SHA256_CheckUpdate(SHA256_CTX *c, const void *data, size_t len) 6 | { 7 | return SHA256_Update(c, check_mem(data, len), len); 8 | } 9 | 10 | /* Double SHA256, as per bitcoin */ 11 | void SHA256_Double_Final(SHA256_CTX *ctx, 12 | struct protocol_double_sha *sha) 13 | { 14 | SHA256_Final(sha->sha, ctx); 15 | SHA256_Init(ctx); 16 | SHA256_CheckUpdate(ctx, sha->sha, SHA256_DIGEST_LENGTH); 17 | SHA256_Final(sha->sha, ctx); 18 | } 19 | 20 | void double_sha_of(struct protocol_double_sha *sha, const void *p, size_t len) 21 | { 22 | SHA256_CTX sha256; 23 | 24 | SHA256_Init(&sha256); 25 | SHA256_CheckUpdate(&sha256, p, len); 26 | SHA256_Double_Final(&sha256, sha); 27 | } 28 | -------------------------------------------------------------------------------- /ccan/ccan/breakpoint/_info: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * breakpoint - break if the program is run under gdb. 7 | * 8 | * This code allows you to insert breakpoints within a program. These will 9 | * do nothing unless your program is run under GDB. 10 | * 11 | * License: CC0 (Public domain) 12 | * 13 | * Example: 14 | * #include 15 | * 16 | * int main(void) 17 | * { 18 | * breakpoint(); 19 | * return 0; 20 | * } 21 | */ 22 | int main(int argc, char *argv[]) 23 | { 24 | /* Expect exactly one argument */ 25 | if (argc != 2) 26 | return 1; 27 | 28 | if (strcmp(argv[1], "depends") == 0) { 29 | printf("ccan/compiler\n"); 30 | return 0; 31 | } 32 | 33 | return 1; 34 | } 35 | -------------------------------------------------------------------------------- /ccan/ccan/opt/test/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef CCAN_OPT_TEST_UTILS_H 2 | #define CCAN_OPT_TEST_UTILS_H 3 | #include 4 | #include 5 | 6 | bool parse_args(int *argc, char ***argv, ...); 7 | bool parse_early_args(int *argc, char ***argv, ...); 8 | extern char *err_output; 9 | void save_err_output(const char *fmt, ...); 10 | void reset_options(void); 11 | 12 | extern unsigned int test_cb_called; 13 | char *test_noarg(void *arg); 14 | char *test_arg(const char *optarg, const char *arg); 15 | void show_arg(char buf[OPT_SHOW_LEN], const char *arg); 16 | 17 | extern struct opt_table short_table[]; 18 | extern struct opt_table long_table[]; 19 | extern struct opt_table long_and_short_table[]; 20 | extern struct opt_table subtables[]; 21 | #endif /* CCAN_OPT_TEST_UTILS_H */ 22 | -------------------------------------------------------------------------------- /ccan/ccan/bitmap/_info: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * bitmap - bitmap handling 7 | * 8 | * This code handles manipulation of bitmaps, arbitrary length arrays 9 | * of bits. 10 | * 11 | * License: LGPL (v2.1 or any later version) 12 | * Author: David Gibson 13 | */ 14 | int main(int argc, char *argv[]) 15 | { 16 | /* Expect exactly one argument */ 17 | if (argc != 2) 18 | return 1; 19 | 20 | if (strcmp(argv[1], "depends") == 0) { 21 | printf("ccan/endian\n"); 22 | return 0; 23 | } 24 | 25 | if (strcmp(argv[1], "testdepends") == 0) { 26 | printf("ccan/array_size\n"); 27 | printf("ccan/foreach\n"); 28 | return 0; 29 | } 30 | 31 | return 1; 32 | } 33 | -------------------------------------------------------------------------------- /ccan/ccan/list/test/run-check-nonconst.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "helper.h" 5 | 6 | struct child { 7 | const char *name; 8 | struct list_node list; 9 | }; 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | struct child c1, c2; 14 | struct list_head list = LIST_HEAD_INIT(list); 15 | 16 | plan_tests(1); 17 | 18 | list_add(&list, &c1.list); 19 | list_add_tail(list_check(&list, "Bad list!"), &c2.list); 20 | list_del_from(list_check(&list, "Bad list!"), 21 | list_check_node(&c2.list, "Bad node!")); 22 | list_del_from(list_check(&list, "Bad list!"), 23 | list_check_node(&c1.list, "Bad node!")); 24 | ok1(list_empty(list_check(&list, "Bad emptied list"))); 25 | 26 | return exit_status(); 27 | } 28 | -------------------------------------------------------------------------------- /proof.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_PROOF_H 2 | #define PETTYCOIN_PROOF_H 3 | #include "config.h" 4 | #include 5 | #include 6 | 7 | struct protocol_proof; 8 | struct block; 9 | union protocol_tx; 10 | struct protocol_input_ref; 11 | struct block_shard; 12 | struct protocol_txrefhash; 13 | 14 | void create_proof(struct protocol_proof *proof, 15 | const struct block *block, u16 shard, u8 txoff); 16 | 17 | bool check_proof(const struct protocol_proof *proof, 18 | const struct block *b, 19 | const union protocol_tx *tx, 20 | const struct protocol_input_ref *refs); 21 | 22 | bool check_proof_byhash(const struct protocol_proof *proof, 23 | const struct block *b, 24 | const struct protocol_txrefhash *txrefhash); 25 | 26 | #endif /* PETTYCOIN_PROOF_H */ 27 | -------------------------------------------------------------------------------- /ccan/ccan/noerr/noerr.c: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #include "noerr.h" 3 | #include 4 | #include 5 | 6 | int close_noerr(int fd) 7 | { 8 | int saved_errno = errno, ret; 9 | 10 | if (close(fd) != 0) 11 | ret = errno; 12 | else 13 | ret = 0; 14 | 15 | errno = saved_errno; 16 | return ret; 17 | } 18 | 19 | int fclose_noerr(FILE *fp) 20 | { 21 | int saved_errno = errno, ret; 22 | 23 | if (fclose(fp) != 0) 24 | ret = errno; 25 | else 26 | ret = 0; 27 | 28 | errno = saved_errno; 29 | return ret; 30 | } 31 | 32 | int unlink_noerr(const char *pathname) 33 | { 34 | int saved_errno = errno, ret; 35 | 36 | if (unlink(pathname) != 0) 37 | ret = errno; 38 | else 39 | ret = 0; 40 | 41 | errno = saved_errno; 42 | return ret; 43 | } 44 | -------------------------------------------------------------------------------- /ccan/ccan/tal/test/run-named.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | int *p; 8 | char name[] = "test name"; 9 | 10 | plan_tests(6); 11 | 12 | p = tal(NULL, int); 13 | ok1(strcmp(tal_name(p), "int") == 0); 14 | 15 | tal_set_name(p, "some literal"); 16 | ok1(strcmp(tal_name(p), "some literal") == 0); 17 | 18 | tal_set_name(p, name); 19 | ok1(strcmp(tal_name(p), name) == 0); 20 | /* You can't reuse my pointer though! */ 21 | ok1(tal_name(p) != name); 22 | 23 | tal_set_name(p, "some other literal"); 24 | ok1(strcmp(tal_name(p), "some other literal") == 0); 25 | 26 | tal_free(p); 27 | 28 | p = tal_arr(NULL, int, 2); 29 | ok1(strcmp(tal_name(p), "int[]") == 0); 30 | tal_free(p); 31 | 32 | tal_cleanup(); 33 | return exit_status(); 34 | } 35 | -------------------------------------------------------------------------------- /hash_tx.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_HASH_TX_H 2 | #define PETTYCOIN_HASH_TX_H 3 | #include "config.h" 4 | #include 5 | 6 | union protocol_tx; 7 | struct protocol_double_sha; 8 | struct protocol_tx_id; 9 | struct protocol_input_ref; 10 | struct protocol_txrefhash; 11 | 12 | /* Get hash, by which we refer to transaction. */ 13 | void hash_tx(const union protocol_tx *tx, struct protocol_tx_id *txid); 14 | 15 | /* Get refhash, which we merkle with txhash inside a block. */ 16 | void hash_refs(const struct protocol_input_ref *refs, 17 | size_t num_refs, 18 | struct protocol_double_sha *sha); 19 | 20 | /* Combo deal. */ 21 | void hash_tx_and_refs(const union protocol_tx *tx, 22 | const struct protocol_input_ref *refs, 23 | struct protocol_txrefhash *txrefhash); 24 | 25 | #endif /* PETTYCOIN_HASH_TX_H */ 26 | -------------------------------------------------------------------------------- /ccan/ccan/strmap/test/run-iterate-const.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static bool found = false; 6 | 7 | /* Make sure const args work. */ 8 | static bool find_string(const char *str, char *member, const char *cmp) 9 | { 10 | if (strcmp(member, cmp) == 0) 11 | found = true; 12 | return false; 13 | } 14 | 15 | int main(void) 16 | { 17 | struct strmap_charp { 18 | STRMAP_MEMBERS(char *); 19 | } map; 20 | 21 | plan_tests(3); 22 | 23 | strmap_init(&map); 24 | ok1(strmap_add(&map, "hello", "hello")); 25 | ok1(strmap_add(&map, "world", "world")); 26 | strmap_iterate(&map, find_string, (const char *)"hello"); 27 | ok1(found); 28 | strmap_clear(&map); 29 | 30 | /* This exits depending on whether all tests passed */ 31 | return exit_status(); 32 | } 33 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/test/run-expand.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | int *a; 8 | const int arr[] = { 1, 2 }; 9 | 10 | plan_tests(14); 11 | talloc_enable_null_tracking_no_autofree(); 12 | 13 | a = tal_arrz(NULL, int, 1); 14 | ok1(a); 15 | 16 | ok1(tal_expand(&a, arr, 2)); 17 | ok1(tal_count(a) == 3); 18 | ok1(a[0] == 0); 19 | ok1(a[1] == 1); 20 | ok1(a[2] == 2); 21 | 22 | ok1(tal_expand(&a, take(tal_arrz(NULL, int, 1)), 1)); 23 | ok1(tal_count(a) == 4); 24 | ok1(a[0] == 0); 25 | ok1(a[1] == 1); 26 | ok1(a[2] == 2); 27 | ok1(a[3] == 0); 28 | ok1(talloc_total_blocks(NULL) == 2); 29 | ok1(talloc_total_blocks(a) == 1); 30 | 31 | tal_free(a); 32 | 33 | talloc_disable_null_tracking(); 34 | return exit_status(); 35 | } 36 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/test/run-named.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | int *p; 8 | char name[] = "test name"; 9 | 10 | plan_tests(6); 11 | 12 | p = tal(NULL, int); 13 | ok1(strcmp(tal_name(p), "int") == 0); 14 | 15 | tal_set_name(p, "some literal"); 16 | ok1(strcmp(tal_name(p), "some literal") == 0); 17 | 18 | tal_set_name(p, name); 19 | ok1(strcmp(tal_name(p), name) == 0); 20 | /* You can't reuse my pointer though! */ 21 | ok1(tal_name(p) != name); 22 | 23 | tal_set_name(p, "some other literal"); 24 | ok1(strcmp(tal_name(p), "some other literal") == 0); 25 | 26 | tal_free(p); 27 | 28 | p = tal_arr(NULL, int, 2); 29 | ok1(strcmp(tal_name(p), "int[]") == 0); 30 | tal_free(p); 31 | 32 | return exit_status(); 33 | } 34 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/talloc/test/run-named.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | int *p; 8 | char name[] = "test name"; 9 | 10 | plan_tests(6); 11 | 12 | p = tal(NULL, int); 13 | ok1(strcmp(tal_name(p), "int") == 0); 14 | 15 | tal_set_name(p, "some literal"); 16 | ok1(strcmp(tal_name(p), "some literal") == 0); 17 | 18 | tal_set_name(p, name); 19 | ok1(strcmp(tal_name(p), name) == 0); 20 | /* You can't reuse my pointer though! */ 21 | ok1(tal_name(p) != name); 22 | 23 | tal_set_name(p, "some other literal"); 24 | ok1(strcmp(tal_name(p), "some other literal") == 0); 25 | 26 | tal_free(p); 27 | 28 | p = tal_arr(NULL, int, 2); 29 | ok1(strcmp(tal_name(p), "int[]") == 0); 30 | tal_free(p); 31 | 32 | return exit_status(); 33 | } 34 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/talloc/test/run-expand.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | int *a; 8 | const int arr[] = { 1, 2 }; 9 | 10 | plan_tests(14); 11 | talloc_enable_null_tracking_no_autofree(); 12 | 13 | a = tal_arrz(NULL, int, 1); 14 | ok1(a); 15 | 16 | ok1(tal_expand(&a, arr, 2)); 17 | ok1(tal_count(a) == 3); 18 | ok1(a[0] == 0); 19 | ok1(a[1] == 1); 20 | ok1(a[2] == 2); 21 | 22 | ok1(tal_expand(&a, take(tal_arrz(NULL, int, 1)), 1)); 23 | ok1(tal_count(a) == 4); 24 | ok1(a[0] == 0); 25 | ok1(a[1] == 1); 26 | ok1(a[2] == 2); 27 | ok1(a[3] == 0); 28 | ok1(talloc_total_blocks(NULL) == 2); 29 | ok1(talloc_total_blocks(a) == 1); 30 | 31 | tal_free(a); 32 | 33 | talloc_disable_null_tracking(); 34 | return exit_status(); 35 | } 36 | -------------------------------------------------------------------------------- /ccan/ccan/typesafe_cb/test/compile_fail-typesafe_cb_cast-multi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct foo { 5 | int x; 6 | }; 7 | 8 | struct bar { 9 | int x; 10 | }; 11 | 12 | struct baz { 13 | int x; 14 | }; 15 | 16 | struct any { 17 | int x; 18 | }; 19 | 20 | struct other { 21 | int x; 22 | }; 23 | 24 | static void take_any(struct any *any) 25 | { 26 | } 27 | 28 | int main(int argc, char *argv[]) 29 | { 30 | #ifdef FAIL 31 | struct other 32 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 33 | #error "Unfortunately we don't fail if typesafe_cb_cast is a noop." 34 | #endif 35 | #else 36 | struct foo 37 | #endif 38 | *arg = NULL; 39 | take_any(typesafe_cb_cast3(struct any *, 40 | struct foo *, struct bar *, struct baz *, 41 | arg)); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /prev_txhashes.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_PREV_TXHASHES_H 2 | #define PETTYCOIN_PREV_TXHASHES_H 3 | #include "config.h" 4 | #include "block.h" 5 | #include 6 | 7 | /* We go back by powers of two from start. So, S, S-1, S-2, S-4, S-8... 8 | * We're at S-1 already, so it's still powers of two backe relative each step */ 9 | #define for_each_prev_txhash(i, b, prev) \ 10 | for (i = 0, b = (prev); \ 11 | i < PROTOCOL_PREV_BLOCK_TXHASHES && b; \ 12 | b = block_ancestor(b, 1 << i), i++) 13 | 14 | size_t num_prev_txhashes(const struct block *prev); 15 | 16 | u8 *make_prev_txhashes(const tal_t *ctx, const struct block *prev, 17 | const struct protocol_address *my_addr); 18 | 19 | u8 prev_txhash(const struct protocol_address *addr, 20 | const struct block *block, u16 shard); 21 | 22 | #endif /* PETTYCOIN_PREV_TXHASHES_H */ 23 | -------------------------------------------------------------------------------- /shard.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_SHARD_H 2 | #define PETTYCOIN_SHARD_H 3 | #include "config.h" 4 | #include "protocol.h" 5 | #include 6 | 7 | /* Shard of an address is the top shard_order bits */ 8 | static inline u16 shard_of(const struct protocol_address *addr, u8 shard_order) 9 | { 10 | be16 shard; 11 | 12 | memcpy(&shard, addr->addr, sizeof(shard)); 13 | return be16_to_cpu(shard) >> (16 - shard_order); 14 | } 15 | 16 | struct block; 17 | 18 | u32 shard_of_tx(const union protocol_tx *tx, u8 shard_order); 19 | 20 | /* FIXME: voting mechanism to bump shard_order. */ 21 | static inline u8 next_shard_order(const struct block *prev) 22 | { 23 | return PROTOCOL_INITIAL_SHARD_ORDER; 24 | } 25 | 26 | static inline u32 num_shards(const struct protocol_block_header *hdr) 27 | { 28 | return 1 << hdr->shard_order; 29 | } 30 | 31 | #endif /* PETTYCOIN_SHARD_H */ 32 | -------------------------------------------------------------------------------- /ccan/ccan/read_write_all/read_write_all.c: -------------------------------------------------------------------------------- 1 | /* Licensed under LGPLv2+ - see LICENSE file for details */ 2 | #include "read_write_all.h" 3 | #include 4 | #include 5 | 6 | bool write_all(int fd, const void *data, size_t size) 7 | { 8 | while (size) { 9 | ssize_t done; 10 | 11 | done = write(fd, data, size); 12 | if (done < 0 && errno == EINTR) 13 | continue; 14 | if (done <= 0) 15 | return false; 16 | data = (const char *)data + done; 17 | size -= done; 18 | } 19 | 20 | return true; 21 | } 22 | 23 | bool read_all(int fd, void *data, size_t size) 24 | { 25 | while (size) { 26 | ssize_t done; 27 | 28 | done = read(fd, data, size); 29 | if (done < 0 && errno == EINTR) 30 | continue; 31 | if (done <= 0) 32 | return false; 33 | data = (char *)data + done; 34 | size -= done; 35 | } 36 | 37 | return true; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-13-all-idle.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* Include the C files directly. */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static struct io_plan *setup_waiter(struct io_conn *conn, int *status) 11 | { 12 | return io_wait(conn, status, io_close_cb, NULL); 13 | } 14 | 15 | int main(void) 16 | { 17 | int status; 18 | 19 | plan_tests(3); 20 | 21 | if (fork() == 0) { 22 | int fds[2]; 23 | 24 | ok1(pipe(fds) == 0); 25 | io_new_conn(NULL, fds[0], setup_waiter, &status); 26 | io_loop(NULL, NULL); 27 | exit(1); 28 | } 29 | 30 | ok1(wait(&status) != -1); 31 | ok1(WIFSIGNALED(status)); 32 | ok1(WTERMSIG(status) == SIGABRT); 33 | 34 | /* This exits depending on whether all tests passed */ 35 | return exit_status(); 36 | } 37 | -------------------------------------------------------------------------------- /pettycoin_dir.c: -------------------------------------------------------------------------------- 1 | #include "pettycoin_dir.h" 2 | #include 3 | #include 4 | 5 | static char *default_pettycoin_dir(const tal_t *ctx) 6 | { 7 | char *path; 8 | const char *env = getenv("HOME"); 9 | if (!env) 10 | return "."; 11 | 12 | path = path_join(ctx, env, ".pettycoin"); 13 | return path; 14 | } 15 | 16 | void pettycoin_dir_register_opts(const tal_t *ctx, 17 | char **pettycoin_dir, char **rpc_filename) 18 | { 19 | *pettycoin_dir = default_pettycoin_dir(ctx); 20 | *rpc_filename = "pettycoin-rpc"; 21 | 22 | opt_register_early_arg("--pettycoin-dir", opt_set_charp, opt_show_charp, 23 | pettycoin_dir, 24 | "working directory: all other files are relative to this"); 25 | 26 | opt_register_arg("--rpc-file", opt_set_charp, opt_show_charp, 27 | rpc_filename, 28 | "Set JSON-RPC socket (or /dev/tty)"); 29 | } 30 | -------------------------------------------------------------------------------- /ccan/ccan/breakpoint/breakpoint.c: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details 2 | * 3 | * Idea for implementation thanks to stackoverflow.com: 4 | * http://stackoverflow.com/questions/3596781/detect-if-gdb-is-running 5 | */ 6 | #include 7 | 8 | bool breakpoint_initialized; 9 | bool breakpoint_under_debug; 10 | 11 | /* This doesn't get called if we're under GDB. */ 12 | static void trap(int signum) 13 | { 14 | breakpoint_initialized = true; 15 | } 16 | 17 | void breakpoint_init(void) 18 | { 19 | struct sigaction old, new; 20 | 21 | new.sa_handler = trap; 22 | new.sa_flags = 0; 23 | sigemptyset(&new.sa_mask); 24 | sigaction(SIGTRAP, &new, &old); 25 | kill(getpid(), SIGTRAP); 26 | sigaction(SIGTRAP, &old, NULL); 27 | 28 | if (!breakpoint_initialized) { 29 | breakpoint_initialized = true; 30 | breakpoint_under_debug = true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ccan/ccan/io/benchmarks/Makefile: -------------------------------------------------------------------------------- 1 | ALL:=run-loop run-different-speed run-length-prefix 2 | CCANDIR:=../../.. 3 | CFLAGS:=-Wall -I$(CCANDIR) -O3 -flto 4 | LDFLAGS:=-O3 -flto 5 | LDLIBS:=-lrt 6 | 7 | OBJS:=time.o poll.o io.o err.o timer.o list.o 8 | 9 | default: $(ALL) 10 | 11 | run-loop: run-loop.o $(OBJS) 12 | run-different-speed: run-different-speed.o $(OBJS) 13 | run-length-prefix: run-length-prefix.o $(OBJS) 14 | 15 | time.o: $(CCANDIR)/ccan/time/time.c 16 | $(CC) $(CFLAGS) -c -o $@ $< 17 | timer.o: $(CCANDIR)/ccan/timer/timer.c 18 | $(CC) $(CFLAGS) -c -o $@ $< 19 | list.o: $(CCANDIR)/ccan/list/list.c 20 | $(CC) $(CFLAGS) -c -o $@ $< 21 | poll.o: $(CCANDIR)/ccan/io/poll.c 22 | $(CC) $(CFLAGS) -c -o $@ $< 23 | io.o: $(CCANDIR)/ccan/io/io.c 24 | $(CC) $(CFLAGS) -c -o $@ $< 25 | err.o: $(CCANDIR)/ccan/err/err.c 26 | $(CC) $(CFLAGS) -c -o $@ $< 27 | 28 | clean: 29 | $(RM) -f *.o $(ALL) 30 | -------------------------------------------------------------------------------- /ccan/ccan/tal/test/run-named-debug.c: -------------------------------------------------------------------------------- 1 | #define CCAN_TAL_DEBUG 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) 7 | { 8 | int *p; 9 | char name[] = "test name"; 10 | 11 | plan_tests(6); 12 | 13 | p = tal(NULL, int); 14 | ok1(strcmp(tal_name(p), __FILE__ ":13:int") == 0); 15 | 16 | tal_set_name(p, "some literal"); 17 | ok1(strcmp(tal_name(p), "some literal") == 0); 18 | 19 | tal_set_name(p, name); 20 | ok1(strcmp(tal_name(p), name) == 0); 21 | /* You can't reuse my pointer though! */ 22 | ok1(tal_name(p) != name); 23 | 24 | tal_set_name(p, "some other literal"); 25 | ok1(strcmp(tal_name(p), "some other literal") == 0); 26 | 27 | tal_free(p); 28 | 29 | p = tal_arr(NULL, int, 2); 30 | ok1(strcmp(tal_name(p), __FILE__ ":29:int[]") == 0); 31 | tal_free(p); 32 | 33 | tal_cleanup(); 34 | return exit_status(); 35 | } 36 | -------------------------------------------------------------------------------- /ccan/ccan/htable/test/run-size.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define NUM_VALS 512 8 | 9 | /* We use the number divided by two as the hash (for lots of 10 | collisions). */ 11 | static size_t hash(const void *elem, void *unused) 12 | { 13 | size_t h = *(uint64_t *)elem / 2; 14 | return h; 15 | } 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | struct htable ht; 20 | uint64_t val[NUM_VALS]; 21 | unsigned int i; 22 | 23 | plan_tests((NUM_VALS) * 2); 24 | for (i = 0; i < NUM_VALS; i++) 25 | val[i] = i; 26 | 27 | htable_init(&ht, hash, NULL); 28 | for (i = 0; i < NUM_VALS; i++) { 29 | ok1(ht.max >= i); 30 | ok1(ht.max <= i * 2); 31 | htable_add(&ht, hash(&val[i], NULL), &val[i]); 32 | } 33 | htable_clear(&ht); 34 | 35 | return exit_status(); 36 | } 37 | -------------------------------------------------------------------------------- /ccan/ccan/list/test/run-list_del_from-assert.c: -------------------------------------------------------------------------------- 1 | #define CCAN_LIST_DEBUG 1 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | struct list_head list1, list2; 13 | struct list_node n1, n2, n3; 14 | pid_t child; 15 | int status; 16 | 17 | plan_tests(1); 18 | list_head_init(&list1); 19 | list_head_init(&list2); 20 | list_add(&list1, &n1); 21 | list_add(&list2, &n2); 22 | list_add_tail(&list2, &n3); 23 | 24 | child = fork(); 25 | if (child) { 26 | wait(&status); 27 | } else { 28 | /* This should abort. */ 29 | list_del_from(&list1, &n3); 30 | exit(0); 31 | } 32 | 33 | ok1(WIFSIGNALED(status) && WTERMSIG(status) == SIGABRT); 34 | list_del_from(&list2, &n3); 35 | return exit_status(); 36 | } 37 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/test/run-named-debug.c: -------------------------------------------------------------------------------- 1 | #define CCAN_TAL_DEBUG 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) 7 | { 8 | int *p; 9 | char name[] = "test name"; 10 | 11 | plan_tests(6); 12 | 13 | p = tal(NULL, int); 14 | ok1(strcmp(tal_name(p), __FILE__ ":13:int") == 0); 15 | 16 | tal_set_name(p, "some literal"); 17 | ok1(strcmp(tal_name(p), "some literal") == 0); 18 | 19 | tal_set_name(p, name); 20 | ok1(strcmp(tal_name(p), name) == 0); 21 | /* You can't reuse my pointer though! */ 22 | ok1(tal_name(p) != name); 23 | 24 | tal_set_name(p, "some other literal"); 25 | ok1(strcmp(tal_name(p), "some other literal") == 0); 26 | 27 | tal_free(p); 28 | 29 | p = tal_arr(NULL, int, 2); 30 | ok1(strcmp(tal_name(p), __FILE__ ":29:int[]") == 0); 31 | tal_free(p); 32 | 33 | return exit_status(); 34 | } 35 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/talloc/test/run-named-debug.c: -------------------------------------------------------------------------------- 1 | #define CCAN_TAL_DEBUG 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) 7 | { 8 | int *p; 9 | char name[] = "test name"; 10 | 11 | plan_tests(6); 12 | 13 | p = tal(NULL, int); 14 | ok1(strcmp(tal_name(p), __FILE__ ":13:int") == 0); 15 | 16 | tal_set_name(p, "some literal"); 17 | ok1(strcmp(tal_name(p), "some literal") == 0); 18 | 19 | tal_set_name(p, name); 20 | ok1(strcmp(tal_name(p), name) == 0); 21 | /* You can't reuse my pointer though! */ 22 | ok1(tal_name(p) != name); 23 | 24 | tal_set_name(p, "some other literal"); 25 | ok1(strcmp(tal_name(p), "some other literal") == 0); 26 | 27 | tal_free(p); 28 | 29 | p = tal_arr(NULL, int, 2); 30 | ok1(strcmp(tal_name(p), __FILE__ ":29:int[]") == 0); 31 | tal_free(p); 32 | 33 | return exit_status(); 34 | } 35 | -------------------------------------------------------------------------------- /ccan/ccan/typesafe_cb/test/compile_fail-typesafe_cb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void _register_callback(void (*cb)(void *arg), void *arg) 5 | { 6 | } 7 | 8 | #define register_callback(cb, arg) \ 9 | _register_callback(typesafe_cb(void, void *, (cb), (arg)), (arg)) 10 | 11 | static void my_callback(char *p) 12 | { 13 | } 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | char str[] = "hello world"; 18 | #ifdef FAIL 19 | int *p; 20 | #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P 21 | #error "Unfortunately we don't fail if typesafe_cb_cast is a noop." 22 | #endif 23 | #else 24 | char *p; 25 | #endif 26 | p = NULL; 27 | 28 | /* This should work always. */ 29 | register_callback(my_callback, str); 30 | 31 | /* This will fail with FAIL defined */ 32 | register_callback(my_callback, p); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /ccan/ccan/opt/test/run-no-options.c: -------------------------------------------------------------------------------- 1 | /* Make sure we still work with no options registered */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "utils.h" 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | const char *myname = argv[0]; 13 | 14 | plan_tests(7); 15 | 16 | /* Simple short arg.*/ 17 | ok1(!parse_args(&argc, &argv, "-a", NULL)); 18 | /* Simple long arg.*/ 19 | ok1(!parse_args(&argc, &argv, "--aaa", NULL)); 20 | 21 | /* Extra arguments preserved. */ 22 | ok1(parse_args(&argc, &argv, "extra", "args", NULL)); 23 | ok1(argc == 3); 24 | ok1(argv[0] == myname); 25 | ok1(strcmp(argv[1], "extra") == 0); 26 | ok1(strcmp(argv[2], "args") == 0); 27 | 28 | /* parse_args allocates argv */ 29 | free(argv); 30 | 31 | return exit_status(); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /sync.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_SYNC_H 2 | #define PETTYCOIN_SYNC_H 3 | #include "config.h" 4 | 5 | struct peer; 6 | struct block; 7 | struct state; 8 | struct protocol_pkt_sync; 9 | struct protocol_pkt_horizon; 10 | struct protocol_pkt_children; 11 | struct protocol_pkt_get_children; 12 | struct protocol_pkt_get_block; 13 | 14 | /* Process protocol_pkt_get_children, fill in *reply if no error. */ 15 | enum protocol_ecode 16 | recv_get_children(struct peer *peer, 17 | const struct protocol_pkt_get_children *pkt, 18 | void **reply); 19 | 20 | /* Process protocol_pkt_children. */ 21 | enum protocol_ecode recv_children(struct peer *peer, 22 | const struct protocol_pkt_children *pkt); 23 | 24 | /* Process protocol_pkt_get_block */ 25 | enum protocol_ecode 26 | recv_get_block(struct peer *peer, 27 | const struct protocol_pkt_get_block *pkt, 28 | void **reply); 29 | #endif /* PETTYCOIN_SYNC_H */ 30 | -------------------------------------------------------------------------------- /ccan/ccan/str/str_debug.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_STR_DEBUG_H 3 | #define CCAN_STR_DEBUG_H 4 | 5 | /* #define CCAN_STR_DEBUG 1 */ 6 | 7 | #ifdef CCAN_STR_DEBUG 8 | /* Because we mug the real ones with macros, we need our own wrappers. */ 9 | int str_isalnum(int i); 10 | int str_isalpha(int i); 11 | int str_isascii(int i); 12 | #if HAVE_ISBLANK 13 | int str_isblank(int i); 14 | #endif 15 | int str_iscntrl(int i); 16 | int str_isdigit(int i); 17 | int str_isgraph(int i); 18 | int str_islower(int i); 19 | int str_isprint(int i); 20 | int str_ispunct(int i); 21 | int str_isspace(int i); 22 | int str_isupper(int i); 23 | int str_isxdigit(int i); 24 | 25 | char *str_strstr(const char *haystack, const char *needle); 26 | char *str_strchr(const char *s, int c); 27 | char *str_strrchr(const char *s, int c); 28 | #endif /* CCAN_STR_DEBUG */ 29 | 30 | #endif /* CCAN_STR_DEBUG_H */ 31 | -------------------------------------------------------------------------------- /ccan/ccan/array_size/test/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static char array1[1]; 5 | static int array2[2]; 6 | static unsigned long array3[3][5]; 7 | struct foo { 8 | unsigned int a, b; 9 | char string[100]; 10 | }; 11 | static struct foo array4[4]; 12 | 13 | /* Make sure they can be used in initializers. */ 14 | static int array1_size = ARRAY_SIZE(array1); 15 | static int array2_size = ARRAY_SIZE(array2); 16 | static int array3_size = ARRAY_SIZE(array3); 17 | static int array4_size = ARRAY_SIZE(array4); 18 | 19 | int main(int argc, char *argv[]) 20 | { 21 | plan_tests(8); 22 | ok1(array1_size == 1); 23 | ok1(array2_size == 2); 24 | ok1(array3_size == 3); 25 | ok1(array4_size == 4); 26 | 27 | ok1(ARRAY_SIZE(array1) == 1); 28 | ok1(ARRAY_SIZE(array2) == 2); 29 | ok1(ARRAY_SIZE(array3) == 3); 30 | ok1(ARRAY_SIZE(array4) == 4); 31 | 32 | return exit_status(); 33 | } 34 | -------------------------------------------------------------------------------- /ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb_cast.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct foo { 5 | int x; 6 | }; 7 | 8 | struct bar { 9 | int x; 10 | }; 11 | 12 | struct baz { 13 | int x; 14 | }; 15 | 16 | struct any { 17 | int x; 18 | }; 19 | 20 | static void take_any(struct any *any) 21 | { 22 | } 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | /* Otherwise we get unused warnings for these. */ 27 | struct foo *foo = NULL; 28 | struct bar *bar = NULL; 29 | struct baz *baz = NULL; 30 | 31 | take_any(typesafe_cb_cast3(struct any *, 32 | struct foo *, struct bar *, struct baz *, 33 | foo)); 34 | take_any(typesafe_cb_cast3(struct any *, 35 | struct foo *, struct bar *, struct baz *, 36 | bar)); 37 | take_any(typesafe_cb_cast3(struct any *, 38 | struct foo *, struct bar *, struct baz *, 39 | baz)); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /web/stylesheets/pettycoin.css: -------------------------------------------------------------------------------- 1 | img.logo { 2 | width: 10%; 3 | float: left; 4 | padding: 0px 50px; 5 | } 6 | 7 | .details { 8 | display: none; 9 | } 10 | 11 | div.boxed, div.boxthird { 12 | padding: 0.25% 0.5%; 13 | border-radius: 1em 1em; 14 | background: #F8F0E7; 15 | border: thin solid #e0e0e0; 16 | box-shadow: 5px 5px 5px #c0c0c0; 17 | } 18 | 19 | div.boxthird { 20 | float: left; 21 | width: 31%; 22 | margin: 0.5%; 23 | } 24 | 25 | div { 26 | margin: 10px; 27 | } 28 | 29 | .rawtext { 30 | padding: 5px 10px; 31 | clear: both; 32 | } 33 | 34 | h1 { 35 | text-align: center; 36 | text-shadow: 2px 2px 2px #a0a0a0; 37 | } 38 | 39 | h2 { 40 | clear: both; 41 | padding-top: 20px; 42 | text-shadow: 1px 1px 1px #c0c0c0; 43 | } 44 | 45 | footer { 46 | clear: both; 47 | padding-top: 20px; 48 | } 49 | 50 | .praisequote { 51 | float: left; 52 | } 53 | -------------------------------------------------------------------------------- /ccan/ccan/timer/benchmarks/Makefile: -------------------------------------------------------------------------------- 1 | ALL:=expected-usage 2 | CCANDIR:=../../.. 3 | CFLAGS:=-Wall -I$(CCANDIR) -O3 -flto 4 | LDFLAGS:=-O3 -flto 5 | LDLIBS:=-lrt 6 | 7 | OBJS:=time.o timer.o list.o opt_opt.o opt_parse.o opt_usage.o opt_helpers.o expected-usage.o 8 | 9 | default: $(ALL) 10 | 11 | expected-usage: $(OBJS) 12 | 13 | opt_parse.o: $(CCANDIR)/ccan/opt/parse.c 14 | $(CC) $(CFLAGS) -c -o $@ $< 15 | 16 | opt_usage.o: $(CCANDIR)/ccan/opt/usage.c 17 | $(CC) $(CFLAGS) -c -o $@ $< 18 | 19 | opt_helpers.o: $(CCANDIR)/ccan/opt/helpers.c 20 | $(CC) $(CFLAGS) -c -o $@ $< 21 | 22 | opt_opt.o: $(CCANDIR)/ccan/opt/opt.c 23 | $(CC) $(CFLAGS) -c -o $@ $< 24 | 25 | time.o: $(CCANDIR)/ccan/time/time.c 26 | $(CC) $(CFLAGS) -c -o $@ $< 27 | 28 | timer.o: $(CCANDIR)/ccan/timer/timer.c 29 | $(CC) $(CFLAGS) -c -o $@ $< 30 | 31 | list.o: $(CCANDIR)/ccan/list/list.c 32 | $(CC) $(CFLAGS) -c -o $@ $< 33 | 34 | clean: 35 | $(RM) *.o $(ALL) 36 | -------------------------------------------------------------------------------- /doc/DUMB-WALLET.md: -------------------------------------------------------------------------------- 1 | Using the dumbwallet 2 | ==================== 3 | 4 | We provide a very simple "dumbwallet" program for testing. It only 5 | has a single key, and doesn't handle any complex cases. 6 | 7 | Setting up the dumbwallet 8 | ------------------------- 9 | 10 | Run `dumbwallet setup` and it will generate your private key and 11 | place it in `dumbwallet.dat`. You can also use a bitcoin test 12 | network private key, like so (note the P- prefix used to convert 13 | a bitcoin key to a pettycoin key): 14 | 15 | $ KEY=`bitcoind -testnet dumppriv
` 16 | $ ./dumbwallet setup P-$KEY 17 | 18 | Using up the dumbwallet 19 | ----------------------- 20 | 21 | It has two commands: "balance" and "send". Balance shows the confirmed and 22 | unconfirmed amounts (it's wrong if you have outgoing transactions though, 23 | since they're not deducted from the confirmed balance). 24 | 25 | Good luck!
26 | Rusty Russell. 27 | -------------------------------------------------------------------------------- /tools/gateway-report.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Read request. 4 | while read LINE; do 5 | LINE=$(echo "$LINE" | tr -d '\015') 6 | if [ x"$LINE" = x ]; then 7 | break 8 | fi 9 | done 10 | 11 | # Whatever they said, give canned answer. 12 | echo 'HTTP/1.1 200 OK' 13 | echo 'Content-Type: text/html' 14 | echo 15 | echo '' 16 | echo '' 17 | echo 'Pettycoin Gateway Status Page' 18 | echo '' 19 | echo '

Pettycoin Gateway Status Page

' 20 | 21 | if pidof pettycoin-gateway >/dev/null; then 22 | echo '

Gateway is active

' 23 | else 24 | echo '

Gateway is DOWN

' 25 | fi 26 | 27 | if [ -r /home/pettycoin/gateway-info.html ]; then 28 | cat /home/pettycoin/gateway-info.html 29 | fi 30 | 31 | LOG=`ls /home/pettycoin/pettycoin-gateway.log* | tail -n1` 32 | echo "

Log $LOG

"
33 | cat $LOG
34 | echo '
' 35 | 36 | -------------------------------------------------------------------------------- /test/run-01-base16.c: -------------------------------------------------------------------------------- 1 | #include "../base58.c" 2 | #include "../shadouble.c" 3 | 4 | int main(void) 5 | { 6 | /* Address: 1PtcjakvZBeggokcAGb1KbVvMRi3NT6LMk. */ 7 | const char priv_b16[] = 8 | "4e111544df178877C7e8483e92b7ef1b40cE7dc4e944261f4f32e2ed13340c0A"; 9 | const char priv_b10[] = 10 | "35310585383039988783548932038956396952442822145226977502125905800903068486666"; 11 | 12 | BIGNUM *bn_priv; 13 | BIGNUM *bn_priv_from_dec = NULL; 14 | BIGNUM *bn_priv_from_hex = NULL; 15 | 16 | bn_priv = BN_new(); 17 | assert(raw_decode_base_n(bn_priv, priv_b16, strlen(priv_b16), 16)); 18 | assert(BN_dec2bn(&bn_priv_from_dec, priv_b10) == strlen(priv_b10)); 19 | assert(BN_hex2bn(&bn_priv_from_hex, priv_b16) == strlen(priv_b16)); 20 | 21 | assert(BN_cmp(bn_priv, bn_priv_from_dec) == 0); 22 | assert(BN_cmp(bn_priv, bn_priv_from_hex) == 0); 23 | 24 | BN_free(bn_priv_from_hex); 25 | BN_free(bn_priv_from_dec); 26 | BN_free(bn_priv); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /ccan/ccan/timer/test/run-expiry.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* Include the C files directly. */ 3 | #include 4 | #include 5 | 6 | int main(void) 7 | { 8 | struct timers timers; 9 | struct timer t; 10 | 11 | /* This is how many tests you plan to run */ 12 | plan_tests(7); 13 | 14 | timers_init(&timers, grains_to_time(1364984760903400ULL)); 15 | ok1(timers.base == 1364984760903400ULL); 16 | timer_init(&t); 17 | timer_add(&timers, &t, grains_to_time(1364984761003398ULL)); 18 | ok1(t.time == 1364984761003398ULL); 19 | ok1(timers.first == 1364984761003398ULL); 20 | ok1(!timers_expire(&timers, grains_to_time(1364984760903444ULL))); 21 | ok1(timers_check(&timers, NULL)); 22 | ok1(!timers_expire(&timers, grains_to_time(1364984761002667ULL))); 23 | ok1(timers_check(&timers, NULL)); 24 | 25 | timers_cleanup(&timers); 26 | 27 | /* This exits depending on whether all tests passed */ 28 | return exit_status(); 29 | } 30 | -------------------------------------------------------------------------------- /ccan/ccan/short_types/short_types.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_SHORT_TYPES_H 3 | #define CCAN_SHORT_TYPES_H 4 | #include 5 | 6 | /** 7 | * u64/s64/u32/s32/u16/s16/u8/s8 - short names for explicitly-sized types. 8 | */ 9 | typedef uint64_t u64; 10 | typedef int64_t s64; 11 | typedef uint32_t u32; 12 | typedef int32_t s32; 13 | typedef uint16_t u16; 14 | typedef int16_t s16; 15 | typedef uint8_t u8; 16 | typedef int8_t s8; 17 | 18 | /* Whichever they include first, they get these definitions. */ 19 | #ifdef CCAN_ENDIAN_H 20 | /** 21 | * be64/be32/be16 - 64/32/16 bit big-endian representation. 22 | */ 23 | typedef beint64_t be64; 24 | typedef beint32_t be32; 25 | typedef beint16_t be16; 26 | 27 | /** 28 | * le64/le32/le16 - 64/32/16 bit little-endian representation. 29 | */ 30 | typedef leint64_t le64; 31 | typedef leint32_t le32; 32 | typedef leint16_t le16; 33 | #endif 34 | 35 | #endif /* CCAN_SHORT_TYPES_H */ 36 | -------------------------------------------------------------------------------- /features.c: -------------------------------------------------------------------------------- 1 | #include "block.h" 2 | #include "features.h" 3 | #include 4 | 5 | u8 pending_features(const struct block *block) 6 | { 7 | u32 feature_counts[8] = { 0 }; 8 | const struct block *b; 9 | unsigned int i, j; 10 | u8 result = 0; 11 | 12 | /* We only update pending features every FEATURE_VOTE_BLOCKS blocks */ 13 | if (block_height(&block->bi) % PROTOCOL_FEATURE_VOTE_BLOCKS != 0) 14 | return block->prev->pending_features; 15 | 16 | for (b = block, i = 0; 17 | i < PROTOCOL_FEATURE_VOTE_BLOCKS; 18 | i++, b = b->prev) { 19 | for (j = 0; j < ARRAY_SIZE(feature_counts); j++) { 20 | if (b->bi.hdr->features_vote & (1 << j)) 21 | feature_counts[j]++; 22 | } 23 | } 24 | 25 | /* If 75% of blocks accept feature, we have supermajority. */ 26 | for (j = 0; j < ARRAY_SIZE(feature_counts); j++) { 27 | if (feature_counts[j] * 4 / PROTOCOL_FEATURE_VOTE_BLOCKS >= 3) 28 | result |= 1 << j; 29 | } 30 | return result; 31 | } 32 | -------------------------------------------------------------------------------- /ccan/ccan/opt/private.h: -------------------------------------------------------------------------------- 1 | /* Licensed under GPLv2+ - see LICENSE file for details */ 2 | #ifndef CCAN_OPT_PRIVATE_H 3 | #define CCAN_OPT_PRIVATE_H 4 | 5 | extern struct opt_table *opt_table; 6 | extern unsigned int opt_count, opt_num_short, opt_num_short_arg, opt_num_long; 7 | 8 | extern const char *opt_argv0; 9 | 10 | #define subtable_of(entry) ((const struct opt_table *)((entry)->names)) 11 | 12 | const char *first_sopt(unsigned *i); 13 | const char *next_sopt(const char *names, unsigned *i); 14 | const char *first_lopt(unsigned *i, unsigned *len); 15 | const char *next_lopt(const char *p, unsigned *i, unsigned *len); 16 | 17 | struct opt_alloc { 18 | void *(*alloc)(size_t size); 19 | void *(*realloc)(void *ptr, size_t size); 20 | void (*free)(void *ptr); 21 | }; 22 | extern struct opt_alloc opt_alloc; 23 | 24 | int parse_one(int *argc, char *argv[], enum opt_type is_early, unsigned *offset, 25 | void (*errlog)(const char *fmt, ...)); 26 | 27 | #endif /* CCAN_OPT_PRIVATE_H */ 28 | -------------------------------------------------------------------------------- /ccan/ccan/check_type/_info: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * check_type - routines for compile time type checking 7 | * 8 | * C has fairly weak typing: ints get automatically converted to longs, signed 9 | * to unsigned, etc. There are some cases where this is best avoided, and 10 | * these macros provide methods for evoking warnings (or build errors) when 11 | * a precise type isn't used. 12 | * 13 | * On compilers which don't support typeof() these routines are less effective, 14 | * since they have to use sizeof() which can only distiguish between types of 15 | * different size. 16 | * 17 | * License: CC0 (Public domain) 18 | * Author: Rusty Russell 19 | */ 20 | int main(int argc, char *argv[]) 21 | { 22 | if (argc != 2) 23 | return 1; 24 | 25 | if (strcmp(argv[1], "depends") == 0) { 26 | #if !HAVE_TYPEOF 27 | printf("ccan/build_assert\n"); 28 | #endif 29 | return 0; 30 | } 31 | 32 | return 1; 33 | } 34 | -------------------------------------------------------------------------------- /merkle_txs.c: -------------------------------------------------------------------------------- 1 | #include "block.h" 2 | #include "block_shard.h" 3 | #include "hash_tx.h" 4 | #include "merkle_recurse.h" 5 | #include "merkle_txs.h" 6 | #include "protocol.h" 7 | #include "tx.h" 8 | #include 9 | #include 10 | #include 11 | 12 | static void merkle_tx(size_t n, void *data, struct protocol_double_sha *merkle) 13 | { 14 | const struct block_shard *shard = data; 15 | struct protocol_txrefhash scratch; 16 | const struct protocol_txrefhash *h; 17 | 18 | h = txrefhash_in_shard(shard, n, &scratch); 19 | merkle_two_hashes(&h->txhash.sha, &h->refhash, merkle); 20 | } 21 | 22 | void merkle_some_txs(const struct block_shard *shard, 23 | size_t off, size_t max, 24 | struct protocol_double_sha *merkle) 25 | { 26 | merkle_recurse(off, shard->size, max, merkle_tx, (void *)shard, merkle); 27 | } 28 | 29 | void merkle_txs(const struct block_shard *shard, 30 | struct protocol_double_sha *merkle) 31 | { 32 | merkle_some_txs(shard, 0, 256, merkle); 33 | } 34 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/test/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *parent, *c[4]; 8 | int i, j; 9 | 10 | plan_tests(9); 11 | 12 | /* tal_free(NULL) works. */ 13 | ok1(tal_free(NULL) == NULL); 14 | 15 | parent = tal(NULL, char); 16 | ok1(parent); 17 | ok1(tal_parent(parent) == NULL); 18 | ok1(tal_parent(NULL) == NULL); 19 | 20 | for (i = 0; i < 4; i++) 21 | c[i] = tal(parent, char); 22 | 23 | for (i = 0; i < 4; i++) 24 | ok1(tal_parent(c[i]) == parent); 25 | 26 | /* Free parent. */ 27 | ok1(tal_free(parent) == NULL); 28 | 29 | parent = tal(NULL, char); 30 | 31 | /* Test freeing in every order */ 32 | for (i = 0; i < 4; i++) { 33 | for (j = 0; j < 4; j++) 34 | c[j] = tal(parent, char); 35 | 36 | tal_free(c[i]); 37 | tal_free(c[(i+1) % 4]); 38 | tal_free(c[(i+2) % 4]); 39 | tal_free(c[(i+3) % 4]); 40 | } 41 | tal_free(parent); 42 | 43 | return exit_status(); 44 | } 45 | -------------------------------------------------------------------------------- /ccan/ccan/array_size/array_size.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_ARRAY_SIZE_H 3 | #define CCAN_ARRAY_SIZE_H 4 | #include "config.h" 5 | #include 6 | 7 | /** 8 | * ARRAY_SIZE - get the number of elements in a visible array 9 | * @arr: the array whose size you want. 10 | * 11 | * This does not work on pointers, or arrays declared as [], or 12 | * function parameters. With correct compiler support, such usage 13 | * will cause a build error (see build_assert). 14 | */ 15 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr)) 16 | 17 | #if HAVE_BUILTIN_TYPES_COMPATIBLE_P && HAVE_TYPEOF 18 | /* Two gcc extensions. 19 | * &a[0] degrades to a pointer: a different type from an array */ 20 | #define _array_size_chk(arr) \ 21 | BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \ 22 | typeof(&(arr)[0]))) 23 | #else 24 | #define _array_size_chk(arr) 0 25 | #endif 26 | #endif /* CCAN_ALIGNOF_H */ 27 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/talloc/test/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *parent, *c[4]; 8 | int i, j; 9 | 10 | plan_tests(9); 11 | 12 | /* tal_free(NULL) works. */ 13 | ok1(tal_free(NULL) == NULL); 14 | 15 | parent = tal(NULL, char); 16 | ok1(parent); 17 | ok1(tal_parent(parent) == NULL); 18 | ok1(tal_parent(NULL) == NULL); 19 | 20 | for (i = 0; i < 4; i++) 21 | c[i] = tal(parent, char); 22 | 23 | for (i = 0; i < 4; i++) 24 | ok1(tal_parent(c[i]) == parent); 25 | 26 | /* Free parent. */ 27 | ok1(tal_free(parent) == NULL); 28 | 29 | parent = tal(NULL, char); 30 | 31 | /* Test freeing in every order */ 32 | for (i = 0; i < 4; i++) { 33 | for (j = 0; j < 4; j++) 34 | c[j] = tal(parent, char); 35 | 36 | tal_free(c[i]); 37 | tal_free(c[(i+1) % 4]); 38 | tal_free(c[(i+2) % 4]); 39 | tal_free(c[(i+3) % 4]); 40 | } 41 | tal_free(parent); 42 | 43 | return exit_status(); 44 | } 45 | -------------------------------------------------------------------------------- /ccan/ccan/cdump/test/run-enum-comma.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* Include the C files directly. */ 3 | #include 4 | #include 5 | 6 | int main(void) 7 | { 8 | struct cdump_definitions *defs; 9 | const struct cdump_type *t; 10 | char *problems; 11 | 12 | /* This is how many tests you plan to run */ 13 | plan_tests(12); 14 | 15 | defs = cdump_extract(NULL, "enum foo { BAR, BAZ, };", &problems); 16 | ok1(defs); 17 | ok1(!problems); 18 | 19 | ok1(strmap_empty(&defs->structs)); 20 | ok1(strmap_empty(&defs->unions)); 21 | t = strmap_get(&defs->enums, "foo"); 22 | ok1(t); 23 | ok1(t->kind == CDUMP_ENUM); 24 | ok1(streq(t->name, "foo")); 25 | ok1(tal_count(t->u.enum_vals) == 2); 26 | ok1(streq(t->u.enum_vals[0].name, "BAR")); 27 | ok1(!t->u.enum_vals[0].value); 28 | ok1(streq(t->u.enum_vals[1].name, "BAZ")); 29 | ok1(!t->u.enum_vals[1].value); 30 | tal_free(defs); 31 | 32 | /* This exits depending on whether all tests passed */ 33 | return exit_status(); 34 | } 35 | -------------------------------------------------------------------------------- /ccan/ccan/hash/_info: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * hash - routines for hashing bytes 7 | * 8 | * When creating a hash table it's important to have a hash function 9 | * which mixes well and is fast. This package supplies such functions. 10 | * 11 | * The hash functions come in two flavors: the normal ones and the 12 | * stable ones. The normal ones can vary from machine-to-machine and 13 | * may change if we find better or faster hash algorithms in future. 14 | * The stable ones will always give the same results on any computer, 15 | * and on any version of this package. 16 | * 17 | * License: CC0 (Public domain) 18 | * Maintainer: Rusty Russell 19 | * Author: Bob Jenkins 20 | */ 21 | int main(int argc, char *argv[]) 22 | { 23 | if (argc != 2) 24 | return 1; 25 | 26 | if (strcmp(argv[1], "depends") == 0) { 27 | printf("ccan/build_assert\n"); 28 | return 0; 29 | } 30 | 31 | return 1; 32 | } 33 | -------------------------------------------------------------------------------- /ccan/ccan/noerr/noerr.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef NOERR_H 3 | #define NOERR_H 4 | #include 5 | 6 | /** 7 | * close_noerr - close without stomping errno. 8 | * @fd: the file descriptor to close. 9 | * 10 | * errno is saved and restored across the call to close: if an error occurs, 11 | * the resulting (non-zero) errno is returned. 12 | */ 13 | int close_noerr(int fd); 14 | 15 | /** 16 | * fclose_noerr - close without stomping errno. 17 | * @fp: the FILE pointer. 18 | * 19 | * errno is saved and restored across the call to fclose: if an error occurs, 20 | * the resulting (non-zero) errno is returned. 21 | */ 22 | int fclose_noerr(FILE *fp); 23 | 24 | /** 25 | * unlink_noerr - unlink a file without stomping errno. 26 | * @pathname: the path to unlink. 27 | * 28 | * errno is saved and restored across the call to unlink: if an error occurs, 29 | * the resulting (non-zero) errno is returned. 30 | */ 31 | int unlink_noerr(const char *pathname); 32 | 33 | #endif /* NOERR_H */ 34 | -------------------------------------------------------------------------------- /tools/update-ccan.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | set -e 4 | 5 | if [ x"$1" = x-f ]; then 6 | UNCLEAN="" 7 | shift 8 | else 9 | UNCLEAN=$(git status --porcelain | grep -v '^??' || true) 10 | fi 11 | 12 | CCANDIR=${1:-../ccan} 13 | NEW_VERSION=${2:-$(git --git-dir=$CCANDIR/.git describe --always)} 14 | OLD_VERSION=$(grep '^CCAN version: ' ccan/README | cut -d: -f2) 15 | 16 | if [ $NEW_VERSION = $OLD_VERSION ]; then 17 | echo Already at $OLD_VERSION 18 | exit 0 19 | fi 20 | 21 | # Make sure we have a clean tree. 22 | if [ -n "$UNCLEAN" ]; then 23 | echo "Dirty tree" >&2 24 | exit 1 25 | fi 26 | 27 | MODULES=$(cd ccan; ls -d ccan/* | grep -v ccan/Makefile) 28 | (cd $CCANDIR && git diff $OLD_VERSION $NEW_VERSION $MODULES licenses/ tools/configurator) > ccan/diff 29 | (cd ccan && patch -p1 < diff) 30 | diffstat ccan/diff 31 | rm ccan/diff 32 | grep -v '^CCAN version: ' ccan/README > ccan/README.new 33 | echo "CCAN version: $NEW_VERSION" >> ccan/README.new 34 | mv ccan/README.new ccan/README 35 | 36 | echo "Updated to $NEW_VERSION" 37 | -------------------------------------------------------------------------------- /ccan/ccan/timer/test/run-ff.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* Include the C files directly. */ 3 | #include 4 | #include 5 | 6 | static struct timeabs timeabs_from_usec(unsigned long long usec) 7 | { 8 | struct timeabs epoch = { { 0, 0 } }; 9 | return timeabs_add(epoch, time_from_usec(usec)); 10 | } 11 | 12 | int main(void) 13 | { 14 | struct timers timers; 15 | struct timer t, *expired; 16 | 17 | /* This is how many tests you plan to run */ 18 | plan_tests(3); 19 | 20 | timers_init(&timers, timeabs_from_usec(1364726722653919ULL)); 21 | timer_init(&t); 22 | timer_add(&timers, &t, timeabs_from_usec(1364726722703919ULL)); 23 | ok1(!timers_expire(&timers, timeabs_from_usec(1364726722653920ULL))); 24 | expired = timers_expire(&timers, timeabs_from_usec(1364726725454187ULL)); 25 | ok1(expired == &t); 26 | ok1(!timers_expire(&timers, timeabs_from_usec(1364726725454187ULL))); 27 | timers_cleanup(&timers); 28 | 29 | /* This exits depending on whether all tests passed */ 30 | return exit_status(); 31 | } 32 | -------------------------------------------------------------------------------- /ccan/ccan/container_of/test/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct foo { 5 | int a; 6 | char b; 7 | }; 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | struct foo foo = { .a = 1, .b = 2 }; 12 | int *intp = &foo.a; 13 | char *charp = &foo.b; 14 | 15 | plan_tests(12); 16 | ok1(container_of(intp, struct foo, a) == &foo); 17 | ok1(container_of(charp, struct foo, b) == &foo); 18 | ok1(container_of_or_null(intp, struct foo, a) == &foo); 19 | ok1(container_of_or_null(charp, struct foo, b) == &foo); 20 | ok1(container_of_or_null((int *)NULL, struct foo, a) == NULL); 21 | ok1(container_of_or_null((char *)NULL, struct foo, b) == NULL); 22 | ok1(container_of_var(intp, &foo, a) == &foo); 23 | ok1(container_of_var(charp, &foo, b) == &foo); 24 | 25 | ok1(container_off(struct foo, a) == 0); 26 | ok1(container_off(struct foo, b) == offsetof(struct foo, b)); 27 | ok1(container_off_var(&foo, a) == 0); 28 | ok1(container_off_var(&foo, b) == offsetof(struct foo, b)); 29 | return exit_status(); 30 | } 31 | -------------------------------------------------------------------------------- /ccan/ccan/err/_info: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * err - err(), errx(), warn() and warnx(), as per BSD's err.h. 7 | * 8 | * A few platforms don't provide err.h; for those, this provides replacements. 9 | * For most, it simple includes the system err.h. 10 | * 11 | * Unfortunately, you have to call err_set_progname() to tell the replacements 12 | * your program name, otherwise it prints "unknown program". 13 | * 14 | * Example: 15 | * #include 16 | * 17 | * int main(int argc, char *argv[]) 18 | * { 19 | * err_set_progname(argv[0]); 20 | * if (argc != 1) 21 | * errx(1, "Expect no arguments"); 22 | * exit(0); 23 | * } 24 | * 25 | * License: CC0 (Public domain) 26 | * Author: Rusty Russell 27 | */ 28 | int main(int argc, char *argv[]) 29 | { 30 | if (argc != 2) 31 | return 1; 32 | 33 | if (strcmp(argv[1], "depends") == 0) { 34 | #if !HAVE_ERR_H 35 | printf("ccan/compiler\n"); 36 | #endif 37 | return 0; 38 | } 39 | 40 | return 1; 41 | } 42 | -------------------------------------------------------------------------------- /hash_tx.c: -------------------------------------------------------------------------------- 1 | #include "hash_tx.h" 2 | #include "marshal.h" 3 | #include "merkle_recurse.h" 4 | #include "protocol.h" 5 | #include "shadouble.h" 6 | #include "tx.h" 7 | #include 8 | 9 | void hash_refs(const struct protocol_input_ref *refs, 10 | size_t num_refs, 11 | struct protocol_double_sha *sha) 12 | { 13 | SHA256_CTX shactx; 14 | 15 | /* Get double sha of references (may be 0 for non-normal trans) */ 16 | SHA256_Init(&shactx); 17 | SHA256_Update(&shactx, refs, sizeof(refs[0]) * num_refs); 18 | SHA256_Double_Final(&shactx, sha); 19 | } 20 | 21 | void hash_tx_and_refs(const union protocol_tx *tx, 22 | const struct protocol_input_ref *refs, 23 | struct protocol_txrefhash *txrefhash) 24 | { 25 | hash_tx(tx, &txrefhash->txhash); 26 | hash_refs(refs, num_inputs(tx), &txrefhash->refhash); 27 | } 28 | 29 | void hash_tx(const union protocol_tx *tx, struct protocol_tx_id *txid) 30 | { 31 | SHA256_CTX shactx; 32 | 33 | SHA256_Init(&shactx); 34 | SHA256_Update(&shactx, tx, tx_len(tx)); 35 | SHA256_Double_Final(&shactx, &txid->sha); 36 | } 37 | -------------------------------------------------------------------------------- /ccan/ccan/tal/path/test/run-cwd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char path1[1024], *cwd, *ctx = tal_strdup(NULL, "ctx"); 8 | 9 | /* This is how many tests you plan to run */ 10 | plan_tests(5); 11 | 12 | if (!getcwd(path1, sizeof(path1))) 13 | abort(); 14 | 15 | cwd = path_cwd(ctx); 16 | ok1(cwd); 17 | ok1(tal_parent(cwd) == ctx); 18 | tal_free(cwd); 19 | 20 | rmdir("run-cwd-long-long-long-name/bar-long-long-long-long-name"); 21 | rmdir("run-cwd-long-long-long-name"); 22 | if (mkdir("run-cwd-long-long-long-name", 0700) != 0) 23 | abort(); 24 | if (mkdir("run-cwd-long-long-long-name/bar-long-long-long-long-name", 0700) != 0) 25 | abort(); 26 | if (chdir("run-cwd-long-long-long-name/bar-long-long-long-long-name") != 0) 27 | abort(); 28 | 29 | cwd = path_cwd(ctx); 30 | ok1(cwd); 31 | ok1(tal_parent(cwd) == ctx); 32 | ok1(strends(cwd, 33 | "run-cwd-long-long-long-name/bar-long-long-long-long-name")); 34 | tal_free(ctx); 35 | 36 | return exit_status(); 37 | } 38 | -------------------------------------------------------------------------------- /ccan/ccan/tal/path/path/test/run-cwd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char path1[1024], *cwd, *ctx = tal_strdup(NULL, "ctx"); 8 | 9 | /* This is how many tests you plan to run */ 10 | plan_tests(5); 11 | 12 | if (!getcwd(path1, sizeof(path1))) 13 | abort(); 14 | 15 | cwd = path_cwd(ctx); 16 | ok1(cwd); 17 | ok1(tal_parent(cwd) == ctx); 18 | tal_free(cwd); 19 | 20 | rmdir("run-cwd-long-long-long-name/bar-long-long-long-long-name"); 21 | rmdir("run-cwd-long-long-long-name"); 22 | if (mkdir("run-cwd-long-long-long-name", 0700) != 0) 23 | abort(); 24 | if (mkdir("run-cwd-long-long-long-name/bar-long-long-long-long-name", 0700) != 0) 25 | abort(); 26 | if (chdir("run-cwd-long-long-long-name/bar-long-long-long-long-name") != 0) 27 | abort(); 28 | 29 | cwd = path_cwd(ctx); 30 | ok1(cwd); 31 | ok1(tal_parent(cwd) == ctx); 32 | ok1(strends(cwd, 33 | "run-cwd-long-long-long-name/bar-long-long-long-long-name")); 34 | tal_free(ctx); 35 | 36 | return exit_status(); 37 | } 38 | -------------------------------------------------------------------------------- /ccan/ccan/tal/test/run-array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *parent, *c[4]; 8 | int i; 9 | 10 | plan_tests(11); 11 | 12 | parent = tal(NULL, char); 13 | ok1(parent); 14 | 15 | /* Zeroing allocations. */ 16 | for (i = 0; i < 4; i++) { 17 | c[i] = talz(parent, char); 18 | ok1(*c[i] == '\0'); 19 | tal_free(c[i]); 20 | } 21 | 22 | /* Array allocation. */ 23 | for (i = 0; i < 4; i++) { 24 | c[i] = tal_arr(parent, char, 4); 25 | strcpy(c[i], "abc"); 26 | tal_free(c[i]); 27 | } 28 | 29 | /* Zeroing array allocation. */ 30 | for (i = 0; i < 4; i++) { 31 | c[i] = tal_arrz(parent, char, 4); 32 | ok1(!c[i][0] && !c[i][1] && !c[i][2] && !c[i][3]); 33 | strcpy(c[i], "abc"); 34 | tal_free(c[i]); 35 | } 36 | 37 | /* Resizing. */ 38 | c[0] = tal_arrz(parent, char, 4); 39 | ok1(tal_resize(&c[0], 6)); 40 | strcpy(c[0], "hello"); 41 | tal_free(c[0]); 42 | ok1(tal_first(parent) == NULL); 43 | 44 | tal_free(parent); 45 | 46 | tal_cleanup(); 47 | return exit_status(); 48 | } 49 | -------------------------------------------------------------------------------- /ccan/ccan/tal/test/run-steal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *p[5]; 8 | unsigned int i; 9 | 10 | plan_tests(9); 11 | 12 | p[0] = tal(NULL, char); 13 | for (i = 1; i < 5; i++) 14 | p[i] = tal(p[i-1], char); 15 | 16 | tal_check(NULL, "check"); 17 | /* Steal node with no children. */ 18 | ok1(tal_steal(p[0], p[4]) == p[4]); 19 | tal_check(NULL, "check"); 20 | /* Noop steal. */ 21 | ok1(tal_steal(p[0], p[4]) == p[4]); 22 | tal_check(NULL, "check"); 23 | /* Steal with children. */ 24 | ok1(tal_steal(p[0], p[1]) == p[1]); 25 | tal_check(NULL, "check"); 26 | /* Noop steal. */ 27 | ok1(tal_steal(p[0], p[1]) == p[1]); 28 | tal_check(NULL, "check"); 29 | /* Steal from direct child. */ 30 | ok1(tal_steal(p[0], p[2]) == p[2]); 31 | tal_check(NULL, "check"); 32 | 33 | ok1(tal_parent(p[1]) == p[0]); 34 | ok1(tal_parent(p[2]) == p[0]); 35 | ok1(tal_parent(p[3]) == p[2]); 36 | ok1(tal_parent(p[4]) == p[0]); 37 | tal_free(p[0]); 38 | 39 | tal_cleanup(); 40 | return exit_status(); 41 | } 42 | -------------------------------------------------------------------------------- /ccan/licenses/BSD-MIT: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/test/run-array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *parent, *c[4]; 8 | int i; 9 | 10 | plan_tests(11); 11 | 12 | parent = tal(NULL, char); 13 | ok1(parent); 14 | 15 | /* Zeroing allocations. */ 16 | for (i = 0; i < 4; i++) { 17 | c[i] = talz(parent, char); 18 | ok1(*c[i] == '\0'); 19 | tal_free(c[i]); 20 | } 21 | 22 | /* Array allocation. */ 23 | for (i = 0; i < 4; i++) { 24 | c[i] = tal_arr(parent, char, 4); 25 | strcpy(c[i], "abc"); 26 | tal_free(c[i]); 27 | } 28 | 29 | /* Zeroing array allocation. */ 30 | for (i = 0; i < 4; i++) { 31 | c[i] = tal_arrz(parent, char, 4); 32 | ok1(!c[i][0] && !c[i][1] && !c[i][2] && !c[i][3]); 33 | strcpy(c[i], "abc"); 34 | tal_free(c[i]); 35 | } 36 | 37 | /* Resizing. */ 38 | c[0] = tal_arrz(parent, char, 4); 39 | ok1(tal_resize(&c[0], 6)); 40 | strcpy(c[0], "hello"); 41 | tal_free(c[0]); 42 | ok1(talloc_total_blocks(parent) == 1); 43 | tal_free(parent); 44 | 45 | return exit_status(); 46 | } 47 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/test/run-steal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *p[5]; 8 | unsigned int i; 9 | 10 | plan_tests(9); 11 | 12 | p[0] = tal(NULL, char); 13 | for (i = 1; i < 5; i++) 14 | p[i] = tal(p[i-1], char); 15 | 16 | tal_check(NULL, "check"); 17 | /* Steal node with no children. */ 18 | ok1(tal_steal(p[0], p[4]) == p[4]); 19 | tal_check(NULL, "check"); 20 | /* Noop steal. */ 21 | ok1(tal_steal(p[0], p[4]) == p[4]); 22 | tal_check(NULL, "check"); 23 | /* Steal with children. */ 24 | ok1(tal_steal(p[0], p[1]) == p[1]); 25 | tal_check(NULL, "check"); 26 | /* Noop steal. */ 27 | ok1(tal_steal(p[0], p[1]) == p[1]); 28 | tal_check(NULL, "check"); 29 | /* Steal from direct child. */ 30 | ok1(tal_steal(p[0], p[2]) == p[2]); 31 | tal_check(NULL, "check"); 32 | 33 | ok1(tal_parent(p[1]) == p[0]); 34 | ok1(tal_parent(p[2]) == p[0]); 35 | ok1(tal_parent(p[3]) == p[2]); 36 | ok1(tal_parent(p[4]) == p[0]); 37 | tal_free(p[0]); 38 | 39 | return exit_status(); 40 | } 41 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/talloc/test/run-array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *parent, *c[4]; 8 | int i; 9 | 10 | plan_tests(11); 11 | 12 | parent = tal(NULL, char); 13 | ok1(parent); 14 | 15 | /* Zeroing allocations. */ 16 | for (i = 0; i < 4; i++) { 17 | c[i] = talz(parent, char); 18 | ok1(*c[i] == '\0'); 19 | tal_free(c[i]); 20 | } 21 | 22 | /* Array allocation. */ 23 | for (i = 0; i < 4; i++) { 24 | c[i] = tal_arr(parent, char, 4); 25 | strcpy(c[i], "abc"); 26 | tal_free(c[i]); 27 | } 28 | 29 | /* Zeroing array allocation. */ 30 | for (i = 0; i < 4; i++) { 31 | c[i] = tal_arrz(parent, char, 4); 32 | ok1(!c[i][0] && !c[i][1] && !c[i][2] && !c[i][3]); 33 | strcpy(c[i], "abc"); 34 | tal_free(c[i]); 35 | } 36 | 37 | /* Resizing. */ 38 | c[0] = tal_arrz(parent, char, 4); 39 | ok1(tal_resize(&c[0], 6)); 40 | strcpy(c[0], "hello"); 41 | tal_free(c[0]); 42 | ok1(talloc_total_blocks(parent) == 1); 43 | tal_free(parent); 44 | 45 | return exit_status(); 46 | } 47 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/talloc/test/run-steal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *p[5]; 8 | unsigned int i; 9 | 10 | plan_tests(9); 11 | 12 | p[0] = tal(NULL, char); 13 | for (i = 1; i < 5; i++) 14 | p[i] = tal(p[i-1], char); 15 | 16 | tal_check(NULL, "check"); 17 | /* Steal node with no children. */ 18 | ok1(tal_steal(p[0], p[4]) == p[4]); 19 | tal_check(NULL, "check"); 20 | /* Noop steal. */ 21 | ok1(tal_steal(p[0], p[4]) == p[4]); 22 | tal_check(NULL, "check"); 23 | /* Steal with children. */ 24 | ok1(tal_steal(p[0], p[1]) == p[1]); 25 | tal_check(NULL, "check"); 26 | /* Noop steal. */ 27 | ok1(tal_steal(p[0], p[1]) == p[1]); 28 | tal_check(NULL, "check"); 29 | /* Steal from direct child. */ 30 | ok1(tal_steal(p[0], p[2]) == p[2]); 31 | tal_check(NULL, "check"); 32 | 33 | ok1(tal_parent(p[1]) == p[0]); 34 | ok1(tal_parent(p[2]) == p[0]); 35 | ok1(tal_parent(p[3]) == p[2]); 36 | ok1(tal_parent(p[4]) == p[0]); 37 | tal_free(p[0]); 38 | 39 | return exit_status(); 40 | } 41 | -------------------------------------------------------------------------------- /ccan/ccan/tal/test/run-groups-grow.c: -------------------------------------------------------------------------------- 1 | #define CCAN_TAL_DEBUG 2 | #include 3 | #include 4 | #include 5 | 6 | static size_t num_allocated; 7 | 8 | static void *alloc_account(size_t len) 9 | { 10 | num_allocated++; 11 | return malloc(len); 12 | } 13 | 14 | static void free_account(void *p) 15 | { 16 | num_allocated--; 17 | return free(p); 18 | } 19 | 20 | #define NUM_ALLOCS 1000 21 | 22 | int main(void) 23 | { 24 | void *p, *c[NUM_ALLOCS]; 25 | int i; 26 | size_t allocated_after_first; 27 | 28 | plan_tests(1); 29 | 30 | tal_set_backend(alloc_account, NULL, free_account, NULL); 31 | 32 | p = tal(NULL, char); 33 | c[0] = tal(p, char); 34 | 35 | allocated_after_first = num_allocated; 36 | for (i = 1; i < NUM_ALLOCS; i++) 37 | c[i] = tal(p, char); 38 | 39 | /* Now free them all. */ 40 | for (i = 0; i < NUM_ALLOCS; i++) 41 | tal_free(c[i]); 42 | 43 | /* We can expect some residue from having any child, but limited! */ 44 | ok1(num_allocated <= allocated_after_first); 45 | tal_free(p); 46 | tal_cleanup(); 47 | return exit_status(); 48 | } 49 | -------------------------------------------------------------------------------- /ccan/ccan/tal/grab_file/test/run-grab.c: -------------------------------------------------------------------------------- 1 | /* This is test for grab_file() function 2 | */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int 13 | main(int argc, char *argv[]) 14 | { 15 | unsigned int i; 16 | char **split, *str; 17 | int length; 18 | struct stat st; 19 | 20 | str = grab_file(NULL, "test/run-grab.c"); 21 | split = tal_strsplit(str, str, "\n", STR_EMPTY_OK); 22 | length = strlen(split[0]); 23 | ok1(!strcmp(split[0], "/* This is test for grab_file() function")); 24 | for (i = 1; split[i]; i++) 25 | length += strlen(split[i]); 26 | ok1(!strcmp(split[i-1], "/* End of grab_file() test */")); 27 | if (stat("test/run-grab.c", &st) != 0) 28 | /* FIXME: ditto */ 29 | if (stat("ccan/tal/grab_file/test/run-grab.c", &st) != 0) 30 | err(1, "Could not stat self"); 31 | ok1(st.st_size == length + i); 32 | tal_free(str); 33 | 34 | return 0; 35 | } 36 | 37 | /* End of grab_file() test */ 38 | -------------------------------------------------------------------------------- /test/standalone/run_local.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | set -e 4 | 5 | if [ $# -ne 1 ]; then 6 | echo "Usage: run_local.sh " >&2 7 | exit 1 8 | fi 9 | 10 | setup_dir() 11 | { 12 | mkdir $1 13 | ln -s ../addresses $1/addresses 14 | cat > $1/config < 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | struct child { 8 | const char *name; 9 | struct list_node list; 10 | }; 11 | 12 | static bool children(const struct list_head *list) 13 | { 14 | return !list_empty(list); 15 | } 16 | 17 | static const struct child *first_child(const struct list_head *list) 18 | { 19 | return list_top(list, struct child, list); 20 | } 21 | 22 | static const struct child *last_child(const struct list_head *list) 23 | { 24 | return list_tail(list, struct child, list); 25 | } 26 | 27 | static void check_children(const struct list_head *list) 28 | { 29 | list_check(list, "bad child list"); 30 | } 31 | 32 | static void print_children(const struct list_head *list) 33 | { 34 | const struct child *c; 35 | list_for_each(list, c, list) 36 | printf("%s\n", c->name); 37 | } 38 | 39 | int main(void) 40 | { 41 | LIST_HEAD(h); 42 | 43 | children(&h); 44 | first_child(&h); 45 | last_child(&h); 46 | check_children(&h); 47 | print_children(&h); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /test/mockup.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | if [ $# -eq 0 ]; then 4 | # With no args, read stdin to scrape compiler output. 5 | set -- $(while read LINE; do 6 | case "$LINE" in 7 | *undefined\ reference\ to*) 8 | LINE=${LINE#*undefined reference to \`} 9 | echo ${LINE%\'*} 10 | ;; 11 | *) 12 | continue 13 | ;; 14 | esac; done | sort -u) 15 | fi 16 | 17 | for SYMBOL; do 18 | WHERE=$(grep -nH "^[a-z0-9_ ]* [*]*$SYMBOL(" *.h) 19 | if [ x"$WHERE" != x ]; then 20 | STUB='\n{ fprintf(stderr, "'$SYMBOL' called!\\n"); abort(); }' 21 | else 22 | WHERE=$(grep -nH "^extern \(const \)\?struct [a-zA-Z0-9_]* $SYMBOL;$" *.h) 23 | if [ x"$WHERE" != x ]; then 24 | STUB=';' 25 | else 26 | echo "/* Could not find declaration for $SYMBOL */" 27 | continue 28 | fi 29 | fi 30 | 31 | echo "/* Generated stub for $SYMBOL */" 32 | FILE=${WHERE%%:*} 33 | FILE_AND_LINE=${WHERE%:*} 34 | LINE=${FILE_AND_LINE#*:} 35 | END=$(tail -n +$LINE < $FILE | grep -n ';$'); 36 | NUM=${END%%:*} 37 | 38 | tail -n +$LINE < $FILE | head -n $NUM | sed 's/^extern *//' | sed "s/;\$/$STUB/" 39 | done 40 | -------------------------------------------------------------------------------- /jsmn/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Serge A. Zaitsev 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 | 21 | -------------------------------------------------------------------------------- /peer_wants.c: -------------------------------------------------------------------------------- 1 | #include "peer.h" 2 | #include "peer_wants.h" 3 | #include "shard.h" 4 | #include "tx.h" 5 | #include "welcome.h" 6 | 7 | static bool peer_wants_shard(const struct peer *peer, u16 shard) 8 | { 9 | const u8 *interests = peer->welcome->interests; 10 | 11 | return interests[shard/8] & (1 << (shard % 8)); 12 | } 13 | 14 | /* Is this tx in a shard wanted by this peer? */ 15 | bool peer_wants_tx(const struct peer *peer, const union protocol_tx *tx) 16 | { 17 | return peer_wants_shard(peer, shard_of_tx(tx, 16)); 18 | } 19 | 20 | /* Is this tx in the (other) shard affected by this tx? */ 21 | bool peer_wants_tx_other(const struct peer *peer, const union protocol_tx *tx) 22 | { 23 | u16 shard; 24 | 25 | switch (tx_type(tx)) { 26 | case TX_FROM_GATEWAY: 27 | /* These only affect one shard. */ 28 | return false; 29 | case TX_NORMAL: 30 | /* This also affects shard of output address. */ 31 | shard = shard_of(&tx->normal.output_addr, 16); 32 | return peer_wants_shard(peer, shard); 33 | case TX_TO_GATEWAY: 34 | case TX_CLAIM: 35 | /* These only affect one shard (inputs). */ 36 | return false; 37 | } 38 | abort(); 39 | } 40 | -------------------------------------------------------------------------------- /input_refs.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_INPUT_REFS_H 2 | #define PETTYCOIN_INPUT_REFS_H 3 | #include "config.h" 4 | #include "protocol_ecode.h" 5 | 6 | struct state; 7 | struct block; 8 | union protocol_tx; 9 | struct protocol_input_ref; 10 | 11 | /* This simply checks that refs are sane with what every node should know */ 12 | enum protocol_ecode check_refs(struct state *state, 13 | const struct block *block, 14 | const struct protocol_input_ref *refs, 15 | unsigned int num_refs); 16 | 17 | /* This actually does the lookup, makes sure ref is what we expected. */ 18 | enum ref_ecode { 19 | ECODE_REF_OK, 20 | /* Ref is unknown. */ 21 | ECODE_REF_UNKNOWN, 22 | /* Hash of that tx is not what input was expecting. */ 23 | ECODE_REF_BAD_HASH 24 | }; 25 | 26 | /* You must have called check_refs() to check for obvious errors. */ 27 | enum ref_ecode check_tx_refs(struct state *state, 28 | const struct block *block, 29 | const union protocol_tx *tx, 30 | const struct protocol_input_ref *refs, 31 | unsigned int *bad_ref, 32 | struct block **block_referred_to); 33 | 34 | #endif /* PETTYCOIN_INPUT_REFS_H */ 35 | -------------------------------------------------------------------------------- /ccan/ccan/tal/path/test/run-is_dir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(void) 9 | { 10 | char cwd[1024], *path, *ctx = tal_strdup(NULL, "ctx"); 11 | 12 | plan_tests(6); 13 | 14 | if (!getcwd(cwd, sizeof(cwd))) 15 | abort(); 16 | 17 | unlink("run-is_dir-dir-link"); 18 | unlink("run-is_dir-file-link"); 19 | unlink("run-is_dir-dir/file"); 20 | rmdir("run-is_dir-dir"); 21 | if (mkdir("run-is_dir-dir", 0700) != 0) 22 | abort(); 23 | if (symlink("run-is_dir-dir", "run-is_dir-dir-link") != 0) 24 | abort(); 25 | if (symlink("run-is_dir-dir/file", "run-is_dir-file-link") != 0) 26 | abort(); 27 | close(open("run-is_dir-dir/file", O_WRONLY|O_CREAT, 0600)); 28 | 29 | ok1(path_is_dir("run-is_dir-dir-link")); 30 | ok1(!path_is_dir("run-is_dir-file-link")); 31 | ok1(!path_is_dir("run-is_dir-dir/file")); 32 | ok1(path_is_dir("run-is_dir-dir")); 33 | 34 | path = path_join(ctx, cwd, "run-is_dir-dir/file"); 35 | ok1(!path_is_dir(path)); 36 | ok1(path_is_dir(cwd)); 37 | 38 | tal_free(ctx); 39 | 40 | return exit_status(); 41 | } 42 | -------------------------------------------------------------------------------- /ccan/ccan/list/list.c: -------------------------------------------------------------------------------- 1 | /* Licensed under BSD-MIT - see LICENSE file for details */ 2 | #include 3 | #include 4 | #include "list.h" 5 | 6 | static void *corrupt(const char *abortstr, 7 | const struct list_node *head, 8 | const struct list_node *node, 9 | unsigned int count) 10 | { 11 | if (abortstr) { 12 | fprintf(stderr, 13 | "%s: prev corrupt in node %p (%u) of %p\n", 14 | abortstr, node, count, head); 15 | abort(); 16 | } 17 | return NULL; 18 | } 19 | 20 | struct list_node *list_check_node(const struct list_node *node, 21 | const char *abortstr) 22 | { 23 | const struct list_node *p, *n; 24 | int count = 0; 25 | 26 | for (p = node, n = node->next; n != node; p = n, n = n->next) { 27 | count++; 28 | if (n->prev != p) 29 | return corrupt(abortstr, node, n, count); 30 | } 31 | /* Check prev on head node. */ 32 | if (node->prev != p) 33 | return corrupt(abortstr, node, node, 0); 34 | 35 | return (struct list_node *)node; 36 | } 37 | 38 | struct list_head *list_check(const struct list_head *h, const char *abortstr) 39 | { 40 | if (!list_check_node(&h->n, abortstr)) 41 | return NULL; 42 | return (struct list_head *)h; 43 | } 44 | -------------------------------------------------------------------------------- /ccan/ccan/tal/path/path/test/run-is_dir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(void) 9 | { 10 | char cwd[1024], *path, *ctx = tal_strdup(NULL, "ctx"); 11 | 12 | plan_tests(6); 13 | 14 | if (!getcwd(cwd, sizeof(cwd))) 15 | abort(); 16 | 17 | unlink("run-is_dir-dir-link"); 18 | unlink("run-is_dir-file-link"); 19 | unlink("run-is_dir-dir/file"); 20 | rmdir("run-is_dir-dir"); 21 | if (mkdir("run-is_dir-dir", 0700) != 0) 22 | abort(); 23 | if (symlink("run-is_dir-dir", "run-is_dir-dir-link") != 0) 24 | abort(); 25 | if (symlink("run-is_dir-dir/file", "run-is_dir-file-link") != 0) 26 | abort(); 27 | close(open("run-is_dir-dir/file", O_WRONLY|O_CREAT, 0600)); 28 | 29 | ok1(path_is_dir("run-is_dir-dir-link")); 30 | ok1(!path_is_dir("run-is_dir-file-link")); 31 | ok1(!path_is_dir("run-is_dir-dir/file")); 32 | ok1(path_is_dir("run-is_dir-dir")); 33 | 34 | path = path_join(ctx, cwd, "run-is_dir-dir/file"); 35 | ok1(!path_is_dir(path)); 36 | ok1(path_is_dir(cwd)); 37 | 38 | tal_free(ctx); 39 | 40 | return exit_status(); 41 | } 42 | -------------------------------------------------------------------------------- /packet_io.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_PACKET_IO_H 2 | #define PETTYCOIN_PACKET_IO_H 3 | #include "config.h" 4 | #include 5 | 6 | /* All packets are "le32 len, type" then len-8 bytes. */ 7 | struct peer; 8 | 9 | /* Takes any pointer to pointer, fills it in. */ 10 | #define io_read_packet(conn, ppkt, cb, arg) \ 11 | ((void)sizeof(**(ppkt)), \ 12 | io_read_packet_(conn, ppkt, \ 13 | typesafe_cb_preargs(struct io_plan *, void *, \ 14 | (cb), (arg), \ 15 | struct io_conn *), \ 16 | (arg))) 17 | 18 | struct io_plan *io_read_packet_(struct io_conn *conn, void *ppkt, 19 | struct io_plan *(*cb)(struct io_conn *, void *), 20 | void *arg); 21 | 22 | /* Peer-specific functions */ 23 | struct io_plan *peer_read_packet(struct peer *peer, 24 | struct io_plan *(*cb)(struct io_conn *, 25 | struct peer *)); 26 | 27 | /* Frees pkt on next write! */ 28 | struct io_plan *peer_write_packet(struct peer *peer, const void *pkt, 29 | struct io_plan *(*next)(struct io_conn *, 30 | struct peer *)); 31 | 32 | struct log; 33 | void add_log_for_fd(int fd, struct log *log); 34 | void del_log_for_fd(int fd, struct log *log); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /ccan/ccan/read_write_all/_info: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * read_write_all - read_all and write_all routines. 7 | * 8 | * Successful read and write calls may only partly complete if a 9 | * signal is received or they are not operating on a normal file. 10 | * 11 | * read_all() and write_all() do the looping for you. 12 | * 13 | * Example: 14 | * #include 15 | * #include 16 | * #include 17 | * #include 18 | * 19 | * #define BUFFER_SIZE 10 20 | * int main(int argc, char *argv[]) 21 | * { 22 | * char buffer[BUFFER_SIZE+1]; 23 | * 24 | * if (!read_all(STDIN_FILENO, buffer, BUFFER_SIZE)) 25 | * err(1, "Could not read %u characters", BUFFER_SIZE); 26 | * buffer[BUFFER_SIZE] = '\0'; 27 | * printf("I read '%.*s'\n", BUFFER_SIZE, buffer); 28 | * return 0; 29 | * } 30 | * 31 | * License: LGPL (v2.1 or any later version) 32 | * Author: Rusty Russell 33 | */ 34 | int main(int argc, char *argv[]) 35 | { 36 | if (argc != 2) 37 | return 1; 38 | 39 | if (strcmp(argv[1], "depends") == 0) { 40 | return 0; 41 | } 42 | 43 | return 1; 44 | } 45 | -------------------------------------------------------------------------------- /ccan/ccan/tal/str/test/run-take.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "helper.h" 5 | 6 | int main(void) 7 | { 8 | char *parent, *c; 9 | 10 | plan_tests(14); 11 | 12 | parent = tal(NULL, char); 13 | ok1(parent); 14 | 15 | c = tal_strdup(parent, "hello"); 16 | 17 | c = tal_strdup(parent, take(c)); 18 | ok1(strcmp(c, "hello") == 0); 19 | ok1(tal_parent(c) == parent); 20 | 21 | c = tal_strndup(parent, take(c), 5); 22 | ok1(strcmp(c, "hello") == 0); 23 | ok1(tal_parent(c) == parent); 24 | 25 | c = tal_strndup(parent, take(c), 3); 26 | ok1(strcmp(c, "hel") == 0); 27 | ok1(tal_parent(c) == parent); 28 | tal_free(c); 29 | 30 | c = tal_strdup(parent, "hello %s"); 31 | c = tal_fmt(parent, take(c), "there"); 32 | ok1(strcmp(c, "hello there") == 0); 33 | ok1(tal_parent(c) == parent); 34 | /* No leftover allocations. */ 35 | tal_free(c); 36 | ok1(no_children(parent)); 37 | 38 | tal_free(parent); 39 | ok1(!taken_any()); 40 | 41 | /* NULL pass-through. */ 42 | c = NULL; 43 | ok1(tal_strdup(NULL, take(c)) == NULL); 44 | ok1(tal_strndup(NULL, take(c), 5) == NULL); 45 | ok1(tal_fmt(NULL, take(c), 0) == NULL); 46 | 47 | return exit_status(); 48 | } 49 | -------------------------------------------------------------------------------- /ccan/ccan/tal/str/str/test/run-take.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "helper.h" 5 | 6 | int main(void) 7 | { 8 | char *parent, *c; 9 | 10 | plan_tests(14); 11 | 12 | parent = tal(NULL, char); 13 | ok1(parent); 14 | 15 | c = tal_strdup(parent, "hello"); 16 | 17 | c = tal_strdup(parent, take(c)); 18 | ok1(strcmp(c, "hello") == 0); 19 | ok1(tal_parent(c) == parent); 20 | 21 | c = tal_strndup(parent, take(c), 5); 22 | ok1(strcmp(c, "hello") == 0); 23 | ok1(tal_parent(c) == parent); 24 | 25 | c = tal_strndup(parent, take(c), 3); 26 | ok1(strcmp(c, "hel") == 0); 27 | ok1(tal_parent(c) == parent); 28 | tal_free(c); 29 | 30 | c = tal_strdup(parent, "hello %s"); 31 | c = tal_fmt(parent, take(c), "there"); 32 | ok1(strcmp(c, "hello there") == 0); 33 | ok1(tal_parent(c) == parent); 34 | /* No leftover allocations. */ 35 | tal_free(c); 36 | ok1(no_children(parent)); 37 | 38 | tal_free(parent); 39 | ok1(!taken_any()); 40 | 41 | /* NULL pass-through. */ 42 | c = NULL; 43 | ok1(tal_strdup(NULL, take(c)) == NULL); 44 | ok1(tal_strndup(NULL, take(c), 5) == NULL); 45 | ok1(tal_fmt(NULL, take(c), 0) == NULL); 46 | 47 | return exit_status(); 48 | } 49 | -------------------------------------------------------------------------------- /timestamp.c: -------------------------------------------------------------------------------- 1 | #include "block.h" 2 | #include "state.h" 3 | #include "timestamp.h" 4 | #include 5 | #include 6 | #include 7 | 8 | /* Note: timestamps in pettycoin are *unsigned* */ 9 | static int cmp_times(const u32 *a, const u32 *b, void *unused) 10 | { 11 | if (*a > *b) 12 | return 1; 13 | else if (*a < *b) 14 | return -1; 15 | return 0; 16 | } 17 | 18 | /* Straight bitcoin algorithm: must be before now + 2 hours, after median 19 | * of last 11 transactions */ 20 | bool check_timestamp(struct state *state, u32 timestamp, 21 | const struct block *prev) 22 | { 23 | u32 times[11]; 24 | unsigned int i; 25 | 26 | /* Genesis timestamp doesn't count: it's canned. */ 27 | for (i = 0; 28 | i < ARRAY_SIZE(times) && prev->prev; 29 | i++, prev = prev->prev) 30 | times[i] = block_timestamp(&prev->bi); 31 | 32 | /* Must be after median. */ 33 | asort(times, i, cmp_times, NULL); 34 | if (i && timestamp <= times[i / 2]) { 35 | log_unusual(state->log, "Timestamp %u is <= times[%i] (%u)", 36 | timestamp, i / 2, times[i/2]); 37 | return false; 38 | } 39 | 40 | /* FIXME: Use network time? */ 41 | return timestamp < time(NULL) + 2 * 60 * 60; 42 | } 43 | -------------------------------------------------------------------------------- /ccan/ccan/array_size/_info: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * array_size - routine for safely deriving the size of a visible array. 7 | * 8 | * This provides a simple ARRAY_SIZE() macro, which (given a good compiler) 9 | * will also break compile if you try to use it on a pointer. 10 | * 11 | * This can ensure your code is robust to changes, without needing a gratuitous 12 | * macro or constant. 13 | * 14 | * Example: 15 | * // Outputs "Initialized 32 values" 16 | * #include 17 | * #include 18 | * #include 19 | * 20 | * // We currently use 32 random values. 21 | * static unsigned int vals[32]; 22 | * 23 | * int main(void) 24 | * { 25 | * unsigned int i; 26 | * for (i = 0; i < ARRAY_SIZE(vals); i++) 27 | * vals[i] = random(); 28 | * printf("Initialized %u values\n", i); 29 | * return 0; 30 | * } 31 | * 32 | * License: CC0 (Public domain) 33 | * Author: Rusty Russell 34 | */ 35 | int main(int argc, char *argv[]) 36 | { 37 | if (argc != 2) 38 | return 1; 39 | 40 | if (strcmp(argv[1], "depends") == 0) { 41 | printf("ccan/build_assert\n"); 42 | return 0; 43 | } 44 | 45 | return 1; 46 | } 47 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/_info: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * tal/talloc - an implementation of the tal interface in terms of talloc. 7 | * 8 | * Tal and talloc are both hierarchical allocators, but have different APIs. 9 | * The tal API is mostly a subset of talloc, but if your project already 10 | * uses talloc then having both tal and talloc pointers is confusing, and 11 | * a waste of resources. 12 | * 13 | * The standard convention to tell ccan modules to use this instead of 14 | * ccan/tal is to define TAL_USE_TALLOC, usually on the commandline. 15 | * 16 | * Bugs: 17 | * tal_first() and tal_next() can't be implemented. 18 | * tal_set_backend() can only change the error function. 19 | * 20 | * License: LGPL 21 | */ 22 | int main(int argc, char *argv[]) 23 | { 24 | if (argc != 2) 25 | return 1; 26 | 27 | if (strcmp(argv[1], "depends") == 0) { 28 | printf("ccan/take\n"); 29 | printf("ccan/typesafe_cb\n"); 30 | printf("ccan/compiler\n"); 31 | printf("ccan/likely\n"); 32 | printf("ccan/str\n"); 33 | printf("talloc\n"); 34 | return 0; 35 | } 36 | 37 | if (strcmp(argv[1], "libs") == 0) { 38 | printf("talloc\n"); 39 | return 0; 40 | } 41 | 42 | return 1; 43 | } 44 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/talloc/_info: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * tal/talloc - an implementation of the tal interface in terms of talloc. 7 | * 8 | * Tal and talloc are both hierarchical allocators, but have different APIs. 9 | * The tal API is mostly a subset of talloc, but if your project already 10 | * uses talloc then having both tal and talloc pointers is confusing, and 11 | * a waste of resources. 12 | * 13 | * The standard convention to tell ccan modules to use this instead of 14 | * ccan/tal is to define TAL_USE_TALLOC, usually on the commandline. 15 | * 16 | * Bugs: 17 | * tal_first() and tal_next() can't be implemented. 18 | * tal_set_backend() can only change the error function. 19 | * 20 | * License: LGPL 21 | */ 22 | int main(int argc, char *argv[]) 23 | { 24 | if (argc != 2) 25 | return 1; 26 | 27 | if (strcmp(argv[1], "depends") == 0) { 28 | printf("ccan/take\n"); 29 | printf("ccan/typesafe_cb\n"); 30 | printf("ccan/compiler\n"); 31 | printf("ccan/likely\n"); 32 | printf("ccan/str\n"); 33 | printf("talloc\n"); 34 | return 0; 35 | } 36 | 37 | if (strcmp(argv[1], "libs") == 0) { 38 | printf("talloc\n"); 39 | return 0; 40 | } 41 | 42 | return 1; 43 | } 44 | -------------------------------------------------------------------------------- /ccan/ccan/tal/path/test/run-is_file.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(void) 9 | { 10 | char cwd[1024], *path, *ctx = tal_strdup(NULL, "ctx"); 11 | 12 | plan_tests(7); 13 | 14 | if (!getcwd(cwd, sizeof(cwd))) 15 | abort(); 16 | 17 | unlink("run-is_file-dir-link"); 18 | unlink("run-is_file-file-link"); 19 | unlink("run-is_file-dir/file"); 20 | rmdir("run-is_file-dir"); 21 | if (mkdir("run-is_file-dir", 0700) != 0) 22 | abort(); 23 | if (symlink("run-is_file-dir", "run-is_file-dir-link") != 0) 24 | abort(); 25 | if (symlink("run-is_file-dir/file", "run-is_file-file-link") != 0) 26 | abort(); 27 | close(open("run-is_file-dir/file", O_WRONLY|O_CREAT, 0600)); 28 | 29 | ok1(!path_is_file("run-is_file-dir-link")); 30 | ok1(path_is_file("run-is_file-file-link")); 31 | ok1(path_is_file("run-is_file-dir/file")); 32 | ok1(!path_is_file("run-is_file-dir")); 33 | ok1(!path_is_file("run-is_file-nonexist")); 34 | 35 | path = path_join(ctx, cwd, "run-is_file-dir/file"); 36 | ok1(path_is_file(path)); 37 | ok1(!path_is_file(cwd)); 38 | 39 | tal_free(ctx); 40 | 41 | return exit_status(); 42 | } 43 | -------------------------------------------------------------------------------- /ccan/ccan/tal/path/path/test/run-is_file.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(void) 9 | { 10 | char cwd[1024], *path, *ctx = tal_strdup(NULL, "ctx"); 11 | 12 | plan_tests(7); 13 | 14 | if (!getcwd(cwd, sizeof(cwd))) 15 | abort(); 16 | 17 | unlink("run-is_file-dir-link"); 18 | unlink("run-is_file-file-link"); 19 | unlink("run-is_file-dir/file"); 20 | rmdir("run-is_file-dir"); 21 | if (mkdir("run-is_file-dir", 0700) != 0) 22 | abort(); 23 | if (symlink("run-is_file-dir", "run-is_file-dir-link") != 0) 24 | abort(); 25 | if (symlink("run-is_file-dir/file", "run-is_file-file-link") != 0) 26 | abort(); 27 | close(open("run-is_file-dir/file", O_WRONLY|O_CREAT, 0600)); 28 | 29 | ok1(!path_is_file("run-is_file-dir-link")); 30 | ok1(path_is_file("run-is_file-file-link")); 31 | ok1(path_is_file("run-is_file-dir/file")); 32 | ok1(!path_is_file("run-is_file-dir")); 33 | ok1(!path_is_file("run-is_file-nonexist")); 34 | 35 | path = path_join(ctx, cwd, "run-is_file-dir/file"); 36 | ok1(path_is_file(path)); 37 | ok1(!path_is_file(cwd)); 38 | 39 | tal_free(ctx); 40 | 41 | return exit_status(); 42 | } 43 | -------------------------------------------------------------------------------- /tools/cdump-enum-names.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static bool create_file(const char *name, struct cdump_type *t, 6 | const char *prefix) 7 | { 8 | size_t i; 9 | 10 | printf("/* Generated from enum %s by tools/cdump-enum-names */\n" 11 | "#include \"%s_names.h\"\n" 12 | "\n" 13 | "struct %s_names %s_names[] = {\n", 14 | name, prefix, prefix, prefix); 15 | 16 | for (i = 0; i < tal_count(t->u.enum_vals); i++) 17 | printf(" { %s, \"%s\" },\n", 18 | t->u.enum_vals[i].name, t->u.enum_vals[i].name); 19 | printf(" { 0, NULL }\n" 20 | "};\n"); 21 | return true; 22 | } 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | struct cdump_definitions *defs; 27 | const char *code; 28 | char *problems; 29 | 30 | err_set_progname(argv[0]); 31 | if (argc != 4) 32 | errx(1, "Usage: %s ", argv[0]); 33 | code = grab_file(NULL, argv[1]); 34 | if (!code) 35 | err(1, "Reading %s", argv[1]); 36 | defs = cdump_extract(code, code, &problems); 37 | if (!defs) 38 | errx(1, "Parsing %s: %s", argv[1], problems); 39 | 40 | create_file(argv[2], strmap_get(&defs->enums, argv[2]), argv[3]); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /create_tx.h: -------------------------------------------------------------------------------- 1 | #ifndef PETTYCOIN_CREATE_TX_H 2 | #define PETTYCOIN_CREATE_TX_H 3 | #include "config.h" 4 | #include "protocol.h" 5 | #include 6 | #include 7 | 8 | union protocol_tx * 9 | create_from_gateway_tx(const tal_t *ctx, 10 | const struct protocol_pubkey *gateway_key, 11 | u16 num_payments, 12 | struct protocol_gateway_payment *payment, 13 | bool pay_fee, 14 | EC_KEY *private_key); 15 | 16 | union protocol_tx * 17 | create_normal_tx(const tal_t *ctx, 18 | const struct protocol_address *pay_to, 19 | u32 send_amount, 20 | u32 change_amount, 21 | u32 num_inputs, 22 | bool pay_fee, 23 | const struct protocol_input inputs[], 24 | EC_KEY *private_key); 25 | 26 | union protocol_tx * 27 | create_to_gateway_tx(const tal_t *ctx, 28 | const struct protocol_address *pay_to, 29 | u32 send_amount, 30 | u32 change_amount, 31 | u32 num_inputs, 32 | bool pay_fee, 33 | const struct protocol_input inputs[], 34 | EC_KEY *private_key); 35 | 36 | union protocol_tx * 37 | create_claim_tx(const tal_t *ctx, 38 | const struct protocol_tx_id *reward_tx, 39 | u32 amount, 40 | bool pay_fee, 41 | EC_KEY *private_key); 42 | #endif /* PETTYCOIN_CREATE_TX_H */ 43 | -------------------------------------------------------------------------------- /ccan/ccan/structeq/_info: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * structeq - bitwise comparison of structs. 7 | * 8 | * This is a replacement for memcmp, which checks the argument types are the 9 | * same. 10 | * 11 | * License: CC0 (Public domain) 12 | * Author: Rusty Russell 13 | * 14 | * Example: 15 | * #include 16 | * #include 17 | * #include 18 | * 19 | * struct mydata { 20 | * int start, end; 21 | * }; 22 | * 23 | * int main(void) 24 | * { 25 | * struct mydata a, b; 26 | * 27 | * // No padding in struct, otherwise this doesn't work! 28 | * BUILD_ASSERT(sizeof(a) == sizeof(a.start) + sizeof(a.end)); 29 | * 30 | * a.start = 100; 31 | * a.end = 101; 32 | * 33 | * b.start = 100; 34 | * b.end = 101; 35 | * 36 | * // They are equal. 37 | * assert(structeq(&a, &b)); 38 | * 39 | * b.end++; 40 | * // Now they are not. 41 | * assert(!structeq(&a, &b)); 42 | * 43 | * return 0; 44 | * } 45 | */ 46 | int main(int argc, char *argv[]) 47 | { 48 | /* Expect exactly one argument */ 49 | if (argc != 2) 50 | return 1; 51 | 52 | if (strcmp(argv[1], "depends") == 0) { 53 | return 0; 54 | } 55 | 56 | return 1; 57 | } 58 | -------------------------------------------------------------------------------- /test/standalone/simple_inject.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | set -e 4 | 5 | DIR=${1:-pettycoin-1} 6 | 7 | GATEADDR=muzRJJzenB7uKzokx21W2QGobfDEZfiH1u 8 | GATEPRIVKEY=cRhETWFwVpi7q8Vjs7KqvYYGZC5htvT3ddnd9hJk5znSohTBHRkT 9 | ADDR2=mopv7T2T7szaYdJNxm7jAF8x16dbMfGerN 10 | ADDR3=mu1LMYYHAWDvRRRdT4or3vqHYZyQ7YNpEu 11 | PRIVKEY2=cVxWbCJ11bcQCsz98fkUzozzhkrwd44QZ8ajLe8ZY6FwtsBfy92X 12 | PRIVKEY3=cPfA1cE78BtzTaNGEfQN5H89bgmyV1BzVz8ppMo3tcVjK21WsagM 13 | ADDR4=qZJLNHV1vQiM4n8oALQ3Mq2LceF48eSne7 14 | 15 | # Gateway injects 100 satoshi to ADDR2. 16 | TX=`../../pettycoin-tx from-gateway P-$GATEPRIVKEY P-$ADDR2 100` 17 | ../../pettycoin-query --pettycoin-dir=$DIR sendrawtransaction $TX 18 | 19 | # ADDR2 pays half to ADDR3 (no fee) 20 | TX2=`../../pettycoin-tx --no-fee tx P-$PRIVKEY2 P-$ADDR3 50 50 raw:$TX` 21 | #TX2=`../../inject tx $PRIVKEY2 localhost $PORT P-$ADDR3 50 49 $TX` 22 | ../../pettycoin-query --pettycoin-dir=$DIR sendrawtransaction $TX2 23 | 24 | # ADDR3 sends half back to gateway (minus fee) 25 | TX3=`../../pettycoin-tx to-gateway P-$PRIVKEY3 P-$GATEADDR 25 24 raw:$TX2` 26 | ../../pettycoin-query --pettycoin-dir=$DIR sendrawtransaction $TX3 27 | 28 | # ADDR3 sends change to ADDR4 29 | TX4=`../../pettycoin-tx tx P-$PRIVKEY3 $ADDR4 24 0 raw:$TX3/1` 30 | ../../pettycoin-query --pettycoin-dir=$DIR sendrawtransaction $TX4 31 | -------------------------------------------------------------------------------- /tal_arr.h: -------------------------------------------------------------------------------- 1 | /* Helpers for handling tal'ed arrays of pointers. */ 2 | #ifndef PETTYCOIN_TAL_ARR_H 3 | #define PETTYCOIN_TAL_ARR_H 4 | #include "config.h" 5 | #include 6 | #include 7 | 8 | #define tal_arr_append(pptr, p) \ 9 | tal_arr_append_((void ***)(pptr) + 0*sizeof(**(pptr)==(p)), (p)) 10 | 11 | static inline void tal_arr_append_(tal_t ***ctxp, const void *p) 12 | { 13 | size_t num = tal_count(*ctxp); 14 | tal_resize(ctxp, num + 1); 15 | (*ctxp)[num] = (void *)p; 16 | } 17 | 18 | #define tal_arr_add(pptr, pos, p) \ 19 | tal_arr_add_((void ***)(pptr) + 0*sizeof(**(pptr)==(p)), (pos), (p)) 20 | 21 | static inline void tal_arr_add_(tal_t ***ctxp, size_t pos, void *p) 22 | { 23 | size_t num = tal_count(*ctxp); 24 | assert(pos <= num); 25 | tal_resize(ctxp, num + 1); 26 | memmove(&(*ctxp)[pos + 1], &(*ctxp)[pos], (num - pos) * sizeof(void *)); 27 | (*ctxp)[pos] = (void *)p; 28 | } 29 | 30 | #define tal_arr_del(pptr, pos) \ 31 | tal_arr_del_((void ***)pptr, (pos)) 32 | 33 | static inline void tal_arr_del_(tal_t ***ctxp, size_t pos) 34 | { 35 | size_t num = tal_count(*ctxp); 36 | assert(pos < num); 37 | memmove(&(*ctxp)[pos], &(*ctxp)[pos + 1], 38 | (num - pos - 1) * sizeof(void *)); 39 | tal_resize(ctxp, num - 1); 40 | } 41 | 42 | #endif /* PETTYCOIN_TAL_ARR_H */ 43 | -------------------------------------------------------------------------------- /merkle_recurse.c: -------------------------------------------------------------------------------- 1 | #include "merkle_recurse.h" 2 | #include "protocol.h" 3 | #include "shadouble.h" 4 | #include 5 | #include 6 | 7 | void merkle_two_hashes(const struct protocol_double_sha *a, 8 | const struct protocol_double_sha *b, 9 | struct protocol_double_sha *merkle) 10 | { 11 | SHA256_CTX shactx; 12 | 13 | SHA256_Init(&shactx); 14 | SHA256_Update(&shactx, a, sizeof(*a)); 15 | SHA256_Update(&shactx, b, sizeof(*b)); 16 | SHA256_Double_Final(&shactx, merkle); 17 | } 18 | 19 | void merkle_recurse(size_t off, size_t max_off, size_t num, 20 | void (*fn)(size_t, void *, struct protocol_double_sha *), 21 | void *data, 22 | struct protocol_double_sha *merkle) 23 | { 24 | /* Always a power of 2. */ 25 | assert((num & (num-1)) == 0); 26 | assert(num != 0); 27 | 28 | if (num == 1) { 29 | if (off >= max_off) 30 | memset(merkle, 0, sizeof(*merkle)); 31 | else 32 | fn(off, data, merkle); 33 | } else { 34 | SHA256_CTX shactx; 35 | struct protocol_double_sha sub[2]; 36 | 37 | num /= 2; 38 | merkle_recurse(off, max_off, num, fn, data, sub); 39 | merkle_recurse(off + num, max_off, num, fn, data, sub+1); 40 | 41 | SHA256_Init(&shactx); 42 | SHA256_Update(&shactx, sub, sizeof(sub)); 43 | SHA256_Double_Final(&shactx, merkle); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ccan/ccan/cdump/test/run-forward-decl.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* Include the C files directly. */ 3 | #include 4 | #include 5 | 6 | int main(void) 7 | { 8 | struct cdump_definitions *defs; 9 | const struct cdump_type *t, *t2; 10 | char *ctx = tal(NULL, char), *problems; 11 | 12 | /* This is how many tests you plan to run */ 13 | plan_tests(16); 14 | 15 | defs = cdump_extract(ctx, "struct foo { struct bar *bar; };\n" 16 | "struct bar { int x; };", &problems); 17 | ok1(defs); 18 | ok1(tal_parent(defs) == ctx); 19 | ok1(!problems); 20 | 21 | t = strmap_get(&defs->structs, "foo"); 22 | ok1(t); 23 | t2 = strmap_get(&defs->structs, "bar"); 24 | ok1(t2); 25 | 26 | ok1(t2->kind == CDUMP_STRUCT); 27 | ok1(streq(t2->name, "bar")); 28 | ok1(tal_count(t2->u.members) == 1); 29 | ok1(t2->u.members[0].type->kind == CDUMP_UNKNOWN); 30 | ok1(streq(t2->u.members[0].type->name, "int")); 31 | 32 | ok1(t->kind == CDUMP_STRUCT); 33 | ok1(streq(t->name, "foo")); 34 | ok1(tal_count(t->u.members) == 1); 35 | ok1(streq(t->u.members[0].name, "bar")); 36 | ok1(t->u.members[0].type->kind == CDUMP_POINTER); 37 | ok1(t->u.members[0].type->u.ptr == t2); 38 | 39 | tal_free(ctx); 40 | 41 | /* This exits depending on whether all tests passed */ 42 | return exit_status(); 43 | } 44 | -------------------------------------------------------------------------------- /ccan/ccan/io/test/run-08-read-after-hangup.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* Include the C files directly. */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static char inbuf[8]; 11 | 12 | static struct io_plan *wake_it(struct io_conn *conn, struct io_conn *reader) 13 | { 14 | io_wake(inbuf); 15 | return io_close(conn); 16 | } 17 | 18 | static struct io_plan *read_buf(struct io_conn *conn, void *unused) 19 | { 20 | return io_read(conn, inbuf, 8, io_close_cb, NULL); 21 | } 22 | 23 | static struct io_plan *init_writer(struct io_conn *conn, struct io_conn *wakeme) 24 | { 25 | return io_write(conn, "EASYTEST", 8, wake_it, wakeme); 26 | } 27 | 28 | static struct io_plan *init_waiter(struct io_conn *conn, void *unused) 29 | { 30 | return io_wait(conn, inbuf, read_buf, NULL); 31 | } 32 | 33 | int main(void) 34 | { 35 | int fds[2]; 36 | struct io_conn *conn; 37 | 38 | plan_tests(3); 39 | 40 | ok1(pipe(fds) == 0); 41 | conn = io_new_conn(NULL, fds[0], init_waiter, NULL); 42 | io_new_conn(conn, fds[1], init_writer, conn); 43 | 44 | ok1(io_loop(NULL, NULL) == NULL); 45 | ok1(memcmp(inbuf, "EASYTEST", sizeof(inbuf)) == 0); 46 | 47 | /* This exits depending on whether all tests passed */ 48 | return exit_status(); 49 | } 50 | -------------------------------------------------------------------------------- /ccan/ccan/htable/tools/Makefile: -------------------------------------------------------------------------------- 1 | CCANDIR=../../.. 2 | CFLAGS=-Wall -Werror -O3 -I$(CCANDIR) 3 | #CFLAGS=-Wall -Werror -g -I$(CCANDIR) 4 | 5 | CCAN_OBJS:=ccan-tal.o ccan-tal-str.o ccan-tal-grab_file.o ccan-take.o ccan-time.o ccan-str.o ccan-noerr.o ccan-list.o 6 | 7 | all: speed stringspeed hsearchspeed 8 | 9 | speed: speed.o hash.o $(CCAN_OBJS) 10 | 11 | speed.o: speed.c ../htable.h ../htable.c 12 | 13 | hash.o: ../../hash/hash.c 14 | $(CC) $(CFLAGS) -c -o $@ $< 15 | 16 | stringspeed: stringspeed.o hash.o $(CCAN_OBJS) 17 | 18 | stringspeed.o: speed.c ../htable.h ../htable.c 19 | 20 | hsearchspeed: hsearchspeed.o $(CCAN_OBJS) 21 | 22 | clean: 23 | rm -f stringspeed speed hsearchspeed *.o 24 | 25 | ccan-tal.o: $(CCANDIR)/ccan/tal/tal.c 26 | $(CC) $(CFLAGS) -c -o $@ $< 27 | ccan-tal-str.o: $(CCANDIR)/ccan/tal/str/str.c 28 | $(CC) $(CFLAGS) -c -o $@ $< 29 | ccan-take.o: $(CCANDIR)/ccan/take/take.c 30 | $(CC) $(CFLAGS) -c -o $@ $< 31 | ccan-tal-grab_file.o: $(CCANDIR)/ccan/tal/grab_file/grab_file.c 32 | $(CC) $(CFLAGS) -c -o $@ $< 33 | ccan-time.o: $(CCANDIR)/ccan/time/time.c 34 | $(CC) $(CFLAGS) -c -o $@ $< 35 | ccan-list.o: $(CCANDIR)/ccan/list/list.c 36 | $(CC) $(CFLAGS) -c -o $@ $< 37 | ccan-str.o: $(CCANDIR)/ccan/str/str.c 38 | $(CC) $(CFLAGS) -c -o $@ $< 39 | ccan-noerr.o: $(CCANDIR)/ccan/noerr/noerr.c 40 | $(CC) $(CFLAGS) -c -o $@ $< 41 | -------------------------------------------------------------------------------- /ccan/ccan/tal/test/run-take.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *parent, *c; 8 | 9 | plan_tests(21); 10 | 11 | /* We can take NULL. */ 12 | ok1(take(NULL) == NULL); 13 | ok1(is_taken(NULL)); 14 | ok1(taken(NULL)); /* Undoes take() */ 15 | ok1(!is_taken(NULL)); 16 | ok1(!taken(NULL)); 17 | 18 | parent = tal(NULL, char); 19 | ok1(parent); 20 | 21 | ok1(take(parent) == parent); 22 | ok1(is_taken(parent)); 23 | ok1(taken(parent)); /* Undoes take() */ 24 | ok1(!is_taken(parent)); 25 | ok1(!taken(parent)); 26 | 27 | c = tal(parent, char); 28 | *c = 'h'; 29 | c = tal_dup(parent, char, take(c), 1, 0); 30 | ok1(c[0] == 'h'); 31 | ok1(tal_parent(c) == parent); 32 | 33 | c = tal_dup(parent, char, take(c), 1, 2); 34 | ok1(c[0] == 'h'); 35 | strcpy(c, "hi"); 36 | ok1(tal_parent(c) == parent); 37 | 38 | /* dup must reparent child. */ 39 | c = tal_dup(NULL, char, take(c), 1, 0); 40 | ok1(c[0] == 'h'); 41 | ok1(tal_parent(c) == NULL); 42 | 43 | /* No leftover allocations. */ 44 | tal_free(c); 45 | ok1(tal_first(parent) == NULL); 46 | 47 | tal_free(parent); 48 | ok1(!taken_any()); 49 | 50 | /* NULL pass-through. */ 51 | c = NULL; 52 | ok1(tal_dup(NULL, char, take(c), 5, 5) == NULL); 53 | ok1(!taken_any()); 54 | 55 | tal_cleanup(); 56 | return exit_status(); 57 | } 58 | -------------------------------------------------------------------------------- /ccan/ccan/asort/asort.h: -------------------------------------------------------------------------------- 1 | /* Licensed under LGPLv2.1+ - see LICENSE file for details */ 2 | #ifndef CCAN_ASORT_H 3 | #define CCAN_ASORT_H 4 | #include "config.h" 5 | #include 6 | #include 7 | 8 | /** 9 | * asort - sort an array of elements 10 | * @base: pointer to data to sort 11 | * @num: number of elements 12 | * @cmp: pointer to comparison function 13 | * @ctx: a context pointer for the cmp function 14 | * 15 | * This function does a sort on the given array. The resulting array 16 | * will be in ascending sorted order by the provided comparison function. 17 | * 18 | * The @cmp function should exactly match the type of the @base and 19 | * @ctx arguments. Otherwise it can take three const void *. 20 | */ 21 | #define asort(base, num, cmp, ctx) \ 22 | _asort((base), (num), sizeof(*(base)), \ 23 | typesafe_cb_cast(int (*)(const void *, const void *, void *), \ 24 | int (*)(const __typeof__(*(base)) *, \ 25 | const __typeof__(*(base)) *, \ 26 | __typeof__(ctx)), \ 27 | (cmp)), \ 28 | (ctx)) 29 | 30 | #if HAVE_QSORT_R_PRIVATE_LAST 31 | #define _asort(b, n, s, cmp, ctx) qsort_r(b, n, s, cmp, ctx) 32 | #else 33 | void _asort(void *base, size_t nmemb, size_t size, 34 | int(*compar)(const void *, const void *, void *), 35 | void *ctx); 36 | #endif 37 | 38 | #endif /* CCAN_ASORT_H */ 39 | -------------------------------------------------------------------------------- /ccan/ccan/timer/benchmarks/benchmark.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #ifdef FIRST_APPROX 7 | #include "first-approx.c" 8 | #endif 9 | #ifdef SECOND_APPROX 10 | #include "second-approx.c" 11 | #endif 12 | #ifdef NO_APPROX 13 | #include "no-approx.c" 14 | #endif 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | struct timespec start, val, val2, end, diff; 19 | unsigned int i, j, limit = atoi(argv[1] ?: "100000"); 20 | uint64_t val64; 21 | 22 | val = start = time_now(); 23 | val64 = to_u64(start); 24 | val2.tv_sec = 0; 25 | val2.tv_nsec = 1; 26 | 27 | for (j = 0; j < limit; j++) { 28 | for (i = 0; i < limit; i++) { 29 | val = time_add(val, val2); 30 | val64 += to_u64(val2); 31 | } 32 | } 33 | 34 | end = time_now(); 35 | 36 | printf("val64 says %lu.%09lu\n", 37 | from_u64(val64).tv_sec, 38 | from_u64(val64).tv_nsec); 39 | 40 | printf("val says %lu.%09lu\n", 41 | val.tv_sec, 42 | val.tv_nsec); 43 | 44 | if (time_greater(val, from_u64(val64))) 45 | diff = time_sub(val, from_u64(val64)); 46 | else 47 | diff = time_sub(from_u64(val64), val); 48 | 49 | printf("Time %lluns, error = %i%%\n", 50 | (long long)time_to_nsec(time_sub(end, start)), 51 | (int)(100 * time_to_nsec(diff) / time_to_nsec(time_sub(val, start)))); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/test/run-take.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *parent, *c; 8 | 9 | plan_tests(21); 10 | 11 | /* We can take NULL. */ 12 | ok1(take(NULL) == NULL); 13 | ok1(is_taken(NULL)); 14 | ok1(taken(NULL)); /* Undoes take() */ 15 | ok1(!is_taken(NULL)); 16 | ok1(!taken(NULL)); 17 | 18 | parent = tal(NULL, char); 19 | ok1(parent); 20 | 21 | ok1(take(parent) == parent); 22 | ok1(is_taken(parent)); 23 | ok1(taken(parent)); /* Undoes take() */ 24 | ok1(!is_taken(parent)); 25 | ok1(!taken(parent)); 26 | 27 | c = tal(parent, char); 28 | *c = 'h'; 29 | c = tal_dup(parent, char, take(c), 1, 0); 30 | ok1(c[0] == 'h'); 31 | ok1(tal_parent(c) == parent); 32 | 33 | c = tal_dup(parent, char, take(c), 1, 2); 34 | ok1(c[0] == 'h'); 35 | strcpy(c, "hi"); 36 | ok1(tal_parent(c) == parent); 37 | 38 | /* dup must reparent child. */ 39 | c = tal_dup(NULL, char, take(c), 1, 0); 40 | ok1(c[0] == 'h'); 41 | ok1(tal_parent(c) == NULL); 42 | 43 | /* No leftover allocations. */ 44 | tal_free(c); 45 | ok1(talloc_total_blocks(parent) == 1); 46 | 47 | tal_free(parent); 48 | ok1(!taken_any()); 49 | 50 | /* NULL pass-through. */ 51 | c = NULL; 52 | ok1(tal_dup(NULL, char, take(c), 5, 5) == NULL); 53 | ok1(!taken_any()); 54 | 55 | return exit_status(); 56 | } 57 | -------------------------------------------------------------------------------- /ccan/ccan/tal/talloc/talloc/test/run-take.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *parent, *c; 8 | 9 | plan_tests(21); 10 | 11 | /* We can take NULL. */ 12 | ok1(take(NULL) == NULL); 13 | ok1(is_taken(NULL)); 14 | ok1(taken(NULL)); /* Undoes take() */ 15 | ok1(!is_taken(NULL)); 16 | ok1(!taken(NULL)); 17 | 18 | parent = tal(NULL, char); 19 | ok1(parent); 20 | 21 | ok1(take(parent) == parent); 22 | ok1(is_taken(parent)); 23 | ok1(taken(parent)); /* Undoes take() */ 24 | ok1(!is_taken(parent)); 25 | ok1(!taken(parent)); 26 | 27 | c = tal(parent, char); 28 | *c = 'h'; 29 | c = tal_dup(parent, char, take(c), 1, 0); 30 | ok1(c[0] == 'h'); 31 | ok1(tal_parent(c) == parent); 32 | 33 | c = tal_dup(parent, char, take(c), 1, 2); 34 | ok1(c[0] == 'h'); 35 | strcpy(c, "hi"); 36 | ok1(tal_parent(c) == parent); 37 | 38 | /* dup must reparent child. */ 39 | c = tal_dup(NULL, char, take(c), 1, 0); 40 | ok1(c[0] == 'h'); 41 | ok1(tal_parent(c) == NULL); 42 | 43 | /* No leftover allocations. */ 44 | tal_free(c); 45 | ok1(talloc_total_blocks(parent) == 1); 46 | 47 | tal_free(parent); 48 | ok1(!taken_any()); 49 | 50 | /* NULL pass-through. */ 51 | c = NULL; 52 | ok1(tal_dup(NULL, char, take(c), 5, 5) == NULL); 53 | ok1(!taken_any()); 54 | 55 | return exit_status(); 56 | } 57 | -------------------------------------------------------------------------------- /ccan/ccan/typesafe_cb/test/compile_ok-typesafe_cb-undefined.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* const args in callbacks should be OK. */ 5 | 6 | static void _register_callback(void (*cb)(void *arg), void *arg) 7 | { 8 | } 9 | 10 | #define register_callback(cb, arg) \ 11 | _register_callback(typesafe_cb(void, void *, (cb), (arg)), (arg)) 12 | 13 | static void _register_callback_pre(void (*cb)(int x, void *arg), void *arg) 14 | { 15 | } 16 | 17 | #define register_callback_pre(cb, arg) \ 18 | _register_callback_pre(typesafe_cb_preargs(void, void *, (cb), (arg), int), (arg)) 19 | 20 | static void _register_callback_post(void (*cb)(void *arg, int x), void *arg) 21 | { 22 | } 23 | 24 | #define register_callback_post(cb, arg) \ 25 | _register_callback_post(typesafe_cb_postargs(void, void *, (cb), (arg), int), (arg)) 26 | 27 | struct undefined; 28 | 29 | static void my_callback(struct undefined *undef) 30 | { 31 | } 32 | 33 | static void my_callback_pre(int x, struct undefined *undef) 34 | { 35 | } 36 | 37 | static void my_callback_post(struct undefined *undef, int x) 38 | { 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | struct undefined *handle = NULL; 44 | 45 | register_callback(my_callback, handle); 46 | register_callback_pre(my_callback_pre, handle); 47 | register_callback_post(my_callback_post, handle); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /ccan/ccan/tal/test/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) 6 | { 7 | char *parent, *c[4], *p; 8 | int i, j; 9 | 10 | plan_tests(14); 11 | 12 | /* tal_free(NULL) works. */ 13 | ok1(tal_free(NULL) == NULL); 14 | 15 | parent = tal(NULL, char); 16 | ok1(parent); 17 | ok1(tal_parent(parent) == NULL); 18 | ok1(tal_parent(NULL) == NULL); 19 | 20 | for (i = 0; i < 4; i++) 21 | c[i] = tal(parent, char); 22 | 23 | for (i = 0; i < 4; i++) 24 | ok1(tal_parent(c[i]) == parent); 25 | 26 | /* Iteration test. */ 27 | i = 0; 28 | for (p = tal_first(parent); p; p = tal_next(parent, p)) { 29 | *p = '1'; 30 | i++; 31 | } 32 | ok1(i == 4); 33 | ok1(*c[0] == '1'); 34 | ok1(*c[1] == '1'); 35 | ok1(*c[2] == '1'); 36 | ok1(*c[3] == '1'); 37 | 38 | /* Free parent. */ 39 | ok1(tal_free(parent) == NULL); 40 | 41 | parent = tal(NULL, char); 42 | 43 | /* Test freeing in every order */ 44 | for (i = 0; i < 4; i++) { 45 | for (j = 0; j < 4; j++) 46 | c[j] = tal(parent, char); 47 | 48 | tal_free(c[i]); 49 | debug_tal(to_tal_hdr(parent)); 50 | tal_free(c[(i+1) % 4]); 51 | debug_tal(to_tal_hdr(parent)); 52 | tal_free(c[(i+2) % 4]); 53 | debug_tal(to_tal_hdr(parent)); 54 | tal_free(c[(i+3) % 4]); 55 | debug_tal(to_tal_hdr(parent)); 56 | } 57 | tal_free(parent); 58 | 59 | tal_cleanup(); 60 | return exit_status(); 61 | } 62 | -------------------------------------------------------------------------------- /hash_block.c: -------------------------------------------------------------------------------- 1 | #include "block.h" 2 | #include "hash_block.h" 3 | #include "shadouble.h" 4 | #include "shard.h" 5 | #include 6 | 7 | void hash_block(const struct protocol_block_header *hdr, 8 | const u8 *num_txs, 9 | const struct protocol_double_sha *merkles, 10 | const u8 *prev_txhashes, 11 | const struct protocol_block_tailer *tailer, 12 | struct protocol_double_sha *sha) 13 | { 14 | SHA256_CTX shactx; 15 | struct protocol_double_sha hash_of_prev, hash_of_merkles; 16 | 17 | /* First hash the prev_txhashes. */ 18 | SHA256_Init(&shactx); 19 | SHA256_Update(&shactx, prev_txhashes, 20 | le32_to_cpu(hdr->num_prev_txhashes) 21 | * sizeof(prev_txhashes[0])); 22 | SHA256_Double_Final(&shactx, &hash_of_prev); 23 | 24 | /* Now hash the merkles of this block's transactions. */ 25 | SHA256_Init(&shactx); 26 | SHA256_Update(&shactx, merkles, sizeof(merkles[0]) << hdr->shard_order); 27 | SHA256_Double_Final(&shactx, &hash_of_merkles); 28 | 29 | /* Now hash them all together. */ 30 | SHA256_Init(&shactx); 31 | SHA256_Update(&shactx, &hash_of_prev, sizeof(hash_of_prev)); 32 | SHA256_Update(&shactx, &hash_of_merkles, sizeof(hash_of_merkles)); 33 | SHA256_Update(&shactx, hdr, sizeof(*hdr)); 34 | SHA256_Update(&shactx, num_txs, 35 | sizeof(*num_txs) << hdr->shard_order); 36 | SHA256_Update(&shactx, tailer, sizeof(*tailer)); 37 | SHA256_Double_Final(&shactx, sha); 38 | } 39 | 40 | --------------------------------------------------------------------------------