├── .clang-format ├── .github ├── ISSUE_TEMPLATE │ └── issue-template.md └── workflows │ ├── dockerhub_push.yml │ ├── pre_release.yml │ └── release.yml ├── .gitignore ├── .gitmodules ├── Dockerfile ├── LICENSE ├── README.md ├── crosscompile ├── aarch64-macOS.txt └── x86_64-w64-mingw32.txt ├── doc ├── API.md └── img │ ├── bitcointalk.png │ ├── discord.png │ ├── janus.svg │ ├── telegram.png │ ├── tokenomics.png │ └── warthog_logo.png ├── dockerfiles ├── Dockerfile ├── build_linux ├── build_macos ├── build_windows └── run_tests ├── meson.build ├── meson_options.txt ├── src ├── node │ ├── api │ │ ├── callbacks.hpp │ │ ├── http │ │ │ ├── endpoint.cpp │ │ │ ├── endpoint.hpp │ │ │ ├── json.cpp │ │ │ ├── json.hpp │ │ │ ├── parse.cpp │ │ │ └── parse.hpp │ │ ├── interface.cpp │ │ ├── interface.hpp │ │ ├── stratum │ │ │ ├── stratum_server.cpp │ │ │ └── stratum_server.hpp │ │ └── types │ │ │ ├── accountid_or_address.hpp │ │ │ ├── all.cpp │ │ │ ├── all.hpp │ │ │ ├── forward_declarations.hpp │ │ │ └── height_or_hash.hpp │ ├── asyncio │ │ ├── conman.cpp │ │ ├── conman.hpp │ │ ├── connection.cpp │ │ ├── connection.hpp │ │ ├── helpers │ │ │ ├── per_ip_counter.cpp │ │ │ └── per_ip_counter.hpp │ │ └── stratum │ │ │ └── stratum_server.hpp │ ├── block │ │ ├── body │ │ │ ├── generator.cpp │ │ │ ├── generator.hpp │ │ │ ├── parse.hpp │ │ │ ├── primitives.cpp │ │ │ ├── primitives.hpp │ │ │ └── rollback.hpp │ │ ├── chain │ │ │ ├── batch_slot.hpp │ │ │ ├── binary_forksearch.hpp │ │ │ ├── consensus_headers.cpp │ │ │ ├── consensus_headers.hpp │ │ │ ├── fork_range.cpp │ │ │ ├── fork_range.hpp │ │ │ ├── header_chain.cpp │ │ │ ├── header_chain.hpp │ │ │ ├── history │ │ │ │ ├── history.cpp │ │ │ │ ├── history.hpp │ │ │ │ └── index.hpp │ │ │ ├── offender.hpp │ │ │ ├── offsts.hpp │ │ │ ├── pin.cpp │ │ │ ├── pin.hpp │ │ │ ├── range.cpp │ │ │ ├── range.hpp │ │ │ ├── signed_snapshot.cpp │ │ │ ├── signed_snapshot.hpp │ │ │ ├── state.cpp │ │ │ └── state.hpp │ │ ├── header │ │ │ ├── batch.cpp │ │ │ ├── batch.hpp │ │ │ ├── difficulty_scale.hpp │ │ │ ├── shared_batch.cpp │ │ │ ├── shared_batch.hpp │ │ │ ├── timestamprule.cpp │ │ │ └── timestamprule.hpp │ │ └── id.hpp │ ├── chainserver │ │ ├── account_cache.cpp │ │ ├── account_cache.hpp │ │ ├── mining_subscription.cpp │ │ ├── mining_subscription.hpp │ │ ├── server.cpp │ │ ├── server.hpp │ │ ├── state │ │ │ ├── helpers │ │ │ │ ├── consensus.cpp │ │ │ │ ├── consensus.hpp │ │ │ │ ├── past_chains.cpp │ │ │ │ └── past_chains.hpp │ │ │ ├── state.cpp │ │ │ ├── state.hpp │ │ │ ├── transactions │ │ │ │ ├── apply_stage.cpp │ │ │ │ ├── apply_stage.hpp │ │ │ │ ├── block_applier.cpp │ │ │ │ └── block_applier.hpp │ │ │ └── update │ │ │ │ ├── chainstate_update.hpp │ │ │ │ ├── mempool_update.hpp │ │ │ │ ├── stage_update.hpp │ │ │ │ └── update.hpp │ │ └── transaction_ids.hpp │ ├── cmdline │ │ ├── cmdline.c │ │ ├── cmdline.cpp │ │ ├── cmdline.h │ │ ├── cmdline.hpp │ │ └── cmdoptions.ggo │ ├── communication │ │ ├── buffers │ │ │ ├── recvbuffer.cpp │ │ │ ├── recvbuffer.hpp │ │ │ ├── sndbuffer.cpp │ │ │ └── sndbuffer.hpp │ │ ├── messages.cpp │ │ ├── messages.hpp │ │ └── stage_operation │ │ │ ├── request.hpp │ │ │ └── result.hpp │ ├── config │ │ ├── config.cpp │ │ └── config.hpp │ ├── db │ │ ├── chain │ │ │ └── deletion_key.hpp │ │ ├── chain_db.cpp │ │ ├── chain_db.hpp │ │ ├── offense_entry.hpp │ │ ├── peer_db.cpp │ │ └── peer_db.hpp │ ├── eventloop │ │ ├── address_manager │ │ │ ├── address_manager.cpp │ │ │ ├── address_manager.hpp │ │ │ ├── address_manager_impl.hpp │ │ │ ├── flat_address_set.cpp │ │ │ └── flat_address_set.hpp │ │ ├── chain_cache.cpp │ │ ├── chain_cache.hpp │ │ ├── eventloop.cpp │ │ ├── eventloop.hpp │ │ ├── peer_chain.cpp │ │ ├── peer_chain.hpp │ │ ├── sync │ │ │ ├── block_download │ │ │ │ ├── attorney.cpp │ │ │ │ ├── attorney.hpp │ │ │ │ ├── attorney_declaration.hpp │ │ │ │ ├── block_download.cpp │ │ │ │ ├── block_download.hpp │ │ │ │ ├── connection_data.cpp │ │ │ │ ├── connection_data.hpp │ │ │ │ ├── focus.cpp │ │ │ │ ├── focus.hpp │ │ │ │ ├── forks.cpp │ │ │ │ ├── forks.hpp │ │ │ │ ├── stage_state.cpp │ │ │ │ └── stage_state.hpp │ │ │ ├── header_download │ │ │ │ ├── connection_data.cpp │ │ │ │ ├── connection_data.hpp │ │ │ │ ├── header_download.cpp │ │ │ │ ├── header_download.hpp │ │ │ │ ├── probe_balanced.cpp │ │ │ │ └── probe_balanced.hpp │ │ │ ├── request_sender_declaration.hpp │ │ │ ├── sync.hpp │ │ │ └── sync_state.hpp │ │ ├── timer.cpp │ │ ├── timer.hpp │ │ └── types │ │ │ ├── chainstate.cpp │ │ │ ├── chainstate.hpp │ │ │ ├── conndata.cpp │ │ │ ├── conndata.hpp │ │ │ ├── conndata_impl.hpp │ │ │ ├── conref_declaration.hpp │ │ │ ├── conref_impl.hpp │ │ │ ├── peer_requests.hpp │ │ │ └── probe_data.hpp │ ├── general │ │ ├── address_funds.hpp │ │ ├── descriptor.hpp │ │ ├── error_time.hpp │ │ ├── filelock │ │ │ ├── filelock.hpp │ │ │ ├── filelock_unix.hpp │ │ │ └── filelock_windows.hpp │ │ ├── logging.hpp │ │ ├── page.hpp │ │ ├── tcp_util.cpp │ │ ├── tcp_util.hpp │ │ └── util.hpp │ ├── global │ │ ├── globals.cpp │ │ └── globals.hpp │ ├── main.cpp │ ├── mempool │ │ ├── comparators.hpp │ │ ├── entry.hpp │ │ ├── log.hpp │ │ ├── mempool.cpp │ │ ├── mempool.hpp │ │ ├── order_key.hpp │ │ ├── subscription.cpp │ │ ├── subscription.hpp │ │ ├── subscription_declaration.hpp │ │ ├── txmap.cpp │ │ └── txmap.hpp │ ├── meson.build │ └── peerserver │ │ ├── ban_cache.cpp │ │ ├── ban_cache.hpp │ │ ├── peerserver.cpp │ │ └── peerserver.hpp ├── shared │ ├── meson.build │ ├── platformassert.cpp │ └── src │ │ ├── block │ │ ├── block.hpp │ │ ├── body │ │ │ ├── account_id.hpp │ │ │ ├── container.cpp │ │ │ ├── container.hpp │ │ │ ├── nonce.cpp │ │ │ ├── nonce.hpp │ │ │ ├── transaction_id.cpp │ │ │ ├── transaction_id.hpp │ │ │ ├── view.cpp │ │ │ └── view.hpp │ │ ├── chain │ │ │ ├── height.cpp │ │ │ ├── height.hpp │ │ │ ├── worksum.cpp │ │ │ └── worksum.hpp │ │ └── header │ │ │ ├── custom_float.hpp │ │ │ ├── difficulty.hpp │ │ │ ├── difficulty_declaration.hpp │ │ │ ├── generator.cpp │ │ │ ├── generator.hpp │ │ │ ├── hash_exponential_request.cpp │ │ │ ├── hash_exponential_request.hpp │ │ │ ├── header.cpp │ │ │ ├── header.hpp │ │ │ ├── header_impl.hpp │ │ │ ├── pow_version.cpp │ │ │ ├── pow_version.hpp │ │ │ ├── view.cpp │ │ │ ├── view.hpp │ │ │ └── view_inline.hpp │ │ ├── commit_info.hpp.in │ │ ├── communication │ │ ├── create_payment.cpp │ │ ├── create_payment.hpp │ │ ├── mining_task.hpp │ │ └── unonce.hpp │ │ ├── crypto │ │ ├── address.cpp │ │ ├── address.hpp │ │ ├── crypto.cpp │ │ ├── crypto.hpp │ │ ├── hash.cpp │ │ ├── hash.hpp │ │ ├── hasher_sha256.hpp │ │ ├── sse2neon.h │ │ └── verushash │ │ │ ├── LICENSE_VERUSCOIN │ │ │ ├── README.md │ │ │ ├── u128.h │ │ │ ├── verus_clhash_port.cpp │ │ │ ├── verus_clhash_port.hpp │ │ │ ├── verus_constants.hpp │ │ │ ├── verushash.cpp │ │ │ └── verushash.hpp │ │ ├── general │ │ ├── byte_order.hpp │ │ ├── compact_uint.cpp │ │ ├── compact_uint.hpp │ │ ├── errors.cpp │ │ ├── errors.hpp │ │ ├── funds.cpp │ │ ├── funds.hpp │ │ ├── hex.cpp │ │ ├── hex.hpp │ │ ├── is_testnet.cpp │ │ ├── is_testnet.hpp │ │ ├── now.hpp │ │ ├── params.hpp │ │ ├── reader.hpp │ │ ├── reader_declaration.hpp │ │ ├── view.hpp │ │ ├── with_uint64.cpp │ │ ├── with_uint64.hpp │ │ └── writer.hpp │ │ └── version.hpp.in ├── test │ ├── custom_float.cpp │ └── meson.build └── wallet │ ├── api_call.cpp │ ├── api_call.hpp │ ├── cmdline │ ├── cmdline.c │ ├── cmdline.cpp │ ├── cmdline.h │ └── cmdoptions.ggo │ ├── main.cpp │ └── meson.build ├── subprojects ├── .gitignore ├── libuv.wrap └── sqlite3.wrap └── thirdparty ├── cpp-httplib ├── LICENSE ├── include │ └── httplib.hpp └── meson.build ├── json ├── LICENSE.MIT ├── include │ └── nlohmann │ │ ├── adl_serializer.hpp │ │ ├── byte_container_with_subtype.hpp │ │ ├── detail │ │ ├── conversions │ │ │ ├── from_json.hpp │ │ │ ├── to_chars.hpp │ │ │ └── to_json.hpp │ │ ├── exceptions.hpp │ │ ├── hash.hpp │ │ ├── input │ │ │ ├── binary_reader.hpp │ │ │ ├── input_adapters.hpp │ │ │ ├── json_sax.hpp │ │ │ ├── lexer.hpp │ │ │ ├── parser.hpp │ │ │ └── position_t.hpp │ │ ├── iterators │ │ │ ├── internal_iterator.hpp │ │ │ ├── iter_impl.hpp │ │ │ ├── iteration_proxy.hpp │ │ │ ├── iterator_traits.hpp │ │ │ ├── json_reverse_iterator.hpp │ │ │ └── primitive_iterator.hpp │ │ ├── json_pointer.hpp │ │ ├── json_ref.hpp │ │ ├── macro_scope.hpp │ │ ├── macro_unscope.hpp │ │ ├── meta │ │ │ ├── call_std │ │ │ │ ├── begin.hpp │ │ │ │ └── end.hpp │ │ │ ├── cpp_future.hpp │ │ │ ├── detected.hpp │ │ │ ├── identity_tag.hpp │ │ │ ├── is_sax.hpp │ │ │ ├── type_traits.hpp │ │ │ └── void_t.hpp │ │ ├── output │ │ │ ├── binary_writer.hpp │ │ │ ├── output_adapters.hpp │ │ │ └── serializer.hpp │ │ ├── string_escape.hpp │ │ └── value_t.hpp │ │ ├── json.hpp │ │ ├── json_fwd.hpp │ │ ├── ordered_map.hpp │ │ └── thirdparty │ │ └── hedley │ │ ├── hedley.hpp │ │ └── hedley_undef.hpp └── meson.build ├── meson.build ├── secp256k1 ├── LICENSE ├── include │ ├── secp256k1.h │ ├── secp256k1_preallocated.h │ └── secp256k1_recovery.h ├── meson.build └── src │ ├── assumptions.h │ ├── ecdsa.h │ ├── ecdsa_impl.h │ ├── eckey.h │ ├── eckey_impl.h │ ├── ecmult.h │ ├── ecmult_const.h │ ├── ecmult_const_impl.h │ ├── ecmult_gen.h │ ├── ecmult_gen_impl.h │ ├── ecmult_impl.h │ ├── ecmult_static_pre_g.h │ ├── field.h │ ├── field_5x52.h │ ├── field_5x52_impl.h │ ├── field_5x52_int128_impl.h │ ├── field_impl.h │ ├── group.h │ ├── group_impl.h │ ├── hash.h │ ├── hash_impl.h │ ├── modinv64.h │ ├── modinv64_impl.h │ ├── modules │ └── recovery │ │ └── main_impl.h │ ├── scalar.h │ ├── scalar_4x64.h │ ├── scalar_4x64_impl.h │ ├── scalar_impl.h │ ├── scratch.h │ ├── scratch_impl.h │ ├── secp256k1.cpp │ ├── selftest.h │ └── util.h ├── spdlog ├── LICENSE ├── README ├── include │ └── spdlog │ │ ├── async.h │ │ ├── async_logger-inl.h │ │ ├── async_logger.h │ │ ├── cfg │ │ ├── argv.h │ │ ├── env.h │ │ ├── helpers-inl.h │ │ └── helpers.h │ │ ├── common-inl.h │ │ ├── common.h │ │ ├── details │ │ ├── backtracer-inl.h │ │ ├── backtracer.h │ │ ├── circular_q.h │ │ ├── console_globals.h │ │ ├── file_helper-inl.h │ │ ├── file_helper.h │ │ ├── fmt_helper.h │ │ ├── log_msg-inl.h │ │ ├── log_msg.h │ │ ├── log_msg_buffer-inl.h │ │ ├── log_msg_buffer.h │ │ ├── mpmc_blocking_q.h │ │ ├── null_mutex.h │ │ ├── os-inl.h │ │ ├── os.h │ │ ├── periodic_worker-inl.h │ │ ├── periodic_worker.h │ │ ├── registry-inl.h │ │ ├── registry.h │ │ ├── synchronous_factory.h │ │ ├── tcp_client-windows.h │ │ ├── tcp_client.h │ │ ├── thread_pool-inl.h │ │ ├── thread_pool.h │ │ ├── udp_client-windows.h │ │ ├── udp_client.h │ │ └── windows_include.h │ │ ├── fmt │ │ ├── bin_to_hex.h │ │ ├── bundled │ │ │ ├── args.h │ │ │ ├── chrono.h │ │ │ ├── color.h │ │ │ ├── compile.h │ │ │ ├── core.h │ │ │ ├── fmt.license.rst │ │ │ ├── format-inl.h │ │ │ ├── format.h │ │ │ ├── locale.h │ │ │ ├── os.h │ │ │ ├── ostream.h │ │ │ ├── printf.h │ │ │ ├── ranges.h │ │ │ └── xchar.h │ │ ├── chrono.h │ │ ├── compile.h │ │ ├── fmt.h │ │ ├── ostr.h │ │ └── xchar.h │ │ ├── formatter.h │ │ ├── fwd.h │ │ ├── logger-inl.h │ │ ├── logger.h │ │ ├── pattern_formatter-inl.h │ │ ├── pattern_formatter.h │ │ ├── sinks │ │ ├── android_sink.h │ │ ├── ansicolor_sink-inl.h │ │ ├── ansicolor_sink.h │ │ ├── base_sink-inl.h │ │ ├── base_sink.h │ │ ├── basic_file_sink-inl.h │ │ ├── basic_file_sink.h │ │ ├── daily_file_sink.h │ │ ├── dist_sink.h │ │ ├── dup_filter_sink.h │ │ ├── hourly_file_sink.h │ │ ├── mongo_sink.h │ │ ├── msvc_sink.h │ │ ├── null_sink.h │ │ ├── ostream_sink.h │ │ ├── qt_sinks.h │ │ ├── ringbuffer_sink.h │ │ ├── rotating_file_sink-inl.h │ │ ├── rotating_file_sink.h │ │ ├── sink-inl.h │ │ ├── sink.h │ │ ├── stdout_color_sinks-inl.h │ │ ├── stdout_color_sinks.h │ │ ├── stdout_sinks-inl.h │ │ ├── stdout_sinks.h │ │ ├── syslog_sink.h │ │ ├── systemd_sink.h │ │ ├── tcp_sink.h │ │ ├── udp_sink.h │ │ ├── win_eventlog_sink.h │ │ ├── wincolor_sink-inl.h │ │ └── wincolor_sink.h │ │ ├── spdlog-inl.h │ │ ├── spdlog.h │ │ ├── stopwatch.h │ │ ├── tweakme.h │ │ └── version.h ├── meson.build └── src │ ├── async.cpp │ ├── cfg.cpp │ ├── color_sinks.cpp │ ├── file_sinks.cpp │ ├── fmt.cpp │ ├── spdlog.cpp │ └── stdout_sinks.cpp ├── sqlitecpp ├── LICENSE ├── include │ └── SQLiteCpp │ │ ├── Assertion.h │ │ ├── Backup.h │ │ ├── Column.h │ │ ├── Database.h │ │ ├── Exception.h │ │ ├── ExecuteMany.h │ │ ├── SQLiteCpp.h │ │ ├── Statement.h │ │ ├── Transaction.h │ │ ├── Utils.h │ │ └── VariadicBind.h ├── meson.build └── src │ ├── Backup.cpp │ ├── Column.cpp │ ├── Database.cpp │ ├── Exception.cpp │ ├── Statement.cpp │ └── Transaction.cpp ├── tl ├── LICENSE ├── include │ └── expected.hpp └── meson.build ├── tomlplusplus ├── LICENSE ├── include │ └── toml++ │ │ └── toml.hpp └── meson.build ├── trezor-crypto ├── LICENSE ├── include │ ├── memzero.hpp │ ├── ripemd160.hpp │ └── sha2.hpp ├── meson.build └── src │ ├── memzero.cpp │ ├── ripemd160.cpp │ └── sha2.cpp ├── uSockets ├── LICENSE ├── meson.build └── src │ ├── bsd.c │ ├── context.c │ ├── crypto │ ├── openssl.c │ ├── sni_tree.cpp │ └── wolfssl.c │ ├── eventing │ ├── asio.cpp │ ├── epoll_kqueue.c │ ├── gcd.c │ └── libuv.c │ ├── internal │ ├── eventing │ │ ├── asio.h │ │ ├── epoll_kqueue.h │ │ ├── gcd.h │ │ └── libuv.h │ ├── internal.h │ ├── loop_data.h │ └── networking │ │ └── bsd.h │ ├── libusockets.h │ ├── loop.c │ └── socket.c ├── uWebsockets ├── LICENSE ├── README ├── include │ └── uwebsockets │ │ ├── App.h │ │ ├── AsyncSocket.h │ │ ├── AsyncSocketData.h │ │ ├── BloomFilter.h │ │ ├── HttpContext.h │ │ ├── HttpContextData.h │ │ ├── HttpParser.h │ │ ├── HttpResponse.h │ │ ├── HttpResponseData.h │ │ ├── HttpRouter.h │ │ ├── Loop.h │ │ ├── LoopData.h │ │ ├── MessageParser.h │ │ ├── MoveOnlyFunction.h │ │ ├── Multipart.h │ │ ├── PerMessageDeflate.h │ │ ├── ProxyParser.h │ │ ├── QueryParser.h │ │ ├── TopicTree.h │ │ ├── Utilities.h │ │ ├── WebSocket.h │ │ ├── WebSocketContext.h │ │ ├── WebSocketContextData.h │ │ ├── WebSocketData.h │ │ ├── WebSocketExtensions.h │ │ ├── WebSocketHandshake.h │ │ └── WebSocketProtocol.h └── meson.build └── uvw ├── LICENSE ├── meson.build ├── uvw.hpp └── uvw ├── async.cpp ├── async.h ├── check.cpp ├── check.h ├── config.h ├── dns.cpp ├── dns.h ├── emitter.cpp ├── emitter.h ├── enum.hpp ├── fs.cpp ├── fs.h ├── fs_event.cpp ├── fs_event.h ├── fs_poll.cpp ├── fs_poll.h ├── handle.hpp ├── idle.cpp ├── idle.h ├── lib.cpp ├── lib.h ├── loop.cpp ├── loop.h ├── pipe.cpp ├── pipe.h ├── poll.cpp ├── poll.h ├── prepare.cpp ├── prepare.h ├── process.cpp ├── process.h ├── request.hpp ├── resource.hpp ├── signal.cpp ├── signal.h ├── stream.cpp ├── stream.h ├── tcp.cpp ├── tcp.h ├── thread.cpp ├── thread.h ├── timer.cpp ├── timer.h ├── tty.cpp ├── tty.h ├── type_info.hpp ├── udp.cpp ├── udp.h ├── util.cpp ├── util.h ├── uv_type.hpp ├── work.cpp └── work.h /.github/ISSUE_TEMPLATE/issue-template.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | 12 | ## Expected Behavior 13 | 14 | 15 | 16 | ## Current Behavior 17 | 18 | 19 | 20 | ## Possible Solution 21 | 22 | 23 | 24 | ## Steps to Reproduce (for bugs) 25 | 26 | 27 | 1. 28 | 2. 29 | 3. 30 | 4. 31 | 32 | ## Context 33 | 34 | 35 | 36 | ## Your Environment 37 | 38 | * Version used: 39 | * Environment name and version (e.g. PHP 5.4 on nginx 1.9.1): 40 | * Server type and version: 41 | * Operating System and version: 42 | * Link to your project: 43 | -------------------------------------------------------------------------------- /.github/workflows/dockerhub_push.yml: -------------------------------------------------------------------------------- 1 | name: DockerHub Push 2 | 3 | on: 4 | repository_dispatch: 5 | types: [docker] 6 | workflow_dispatch: 7 | 8 | jobs: 9 | docker: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - 13 | name: Check out repository 14 | uses: actions/checkout@v2 15 | - 16 | name: Set up QEMU 17 | uses: docker/setup-qemu-action@v3 18 | - 19 | name: Set up Docker Buildx 20 | uses: docker/setup-buildx-action@v3 21 | - 22 | name: Login to Docker Hub 23 | uses: docker/login-action@v3 24 | with: 25 | username: ${{ secrets.DOCKERHUB_USERNAME }} 26 | password: ${{ secrets.DOCKERHUB_TOKEN }} 27 | 28 | - name: Get version 29 | id: get_version 30 | run: | 31 | echo "VERSION=$(grep 'version :' meson.build | cut -d "'" -f 2)" >> $GITHUB_ENV 32 | - 33 | name: Build and push 34 | uses: docker/build-push-action@v5 35 | with: 36 | file: ./dockerfiles/Dockerfile 37 | push: true 38 | tags: | 39 | zzjulien/warthog_node:latest 40 | zzjulien/warthog_node:${{ env.VERSION }} 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | compile_commands.json 2 | .cache 3 | .ccls-cache 4 | build/ 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "doc/docs"] 2 | path = doc/docs 3 | url = https://github.com/warthog-network/docs/ 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | dockerfiles/Dockerfile -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Pumbaa, Timon & Rafiki 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /crosscompile/aarch64-macOS.txt: -------------------------------------------------------------------------------- 1 | [binaries] 2 | c = 'aarch64-apple-darwin22.2-clang' 3 | cpp = 'aarch64-apple-darwin22.2-clang++' 4 | ar = 'aarch64-apple-darwin22.2-ar' 5 | ld = 'aarch64-apple-darwin22.2-ld' 6 | ranlib = 'aarch64-apple-darwin22.2-ranlib' 7 | 8 | [host_machine] 9 | system = 'darwin' 10 | cpu_family = 'aarch64' 11 | cpu = 'aarch64' 12 | endian = 'little' 13 | 14 | -------------------------------------------------------------------------------- /crosscompile/x86_64-w64-mingw32.txt: -------------------------------------------------------------------------------- 1 | [binaries] 2 | c = 'x86_64-w64-mingw32-gcc' 3 | cpp = 'x86_64-w64-mingw32-g++' 4 | ar = 'x86_64-w64-mingw32-ar' 5 | strip = 'x86_64-w64-mingw32-strip' 6 | exe_wrapper = 'wine64' 7 | 8 | [host_machine] 9 | system = 'windows' 10 | cpu_family = 'x86_64' 11 | cpu = 'x86_64' 12 | endian = 'little' 13 | 14 | -------------------------------------------------------------------------------- /doc/img/bitcointalk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warthog-network/Warthog/868a69355981e3ab3a55ffa692cd8a8aa229e592/doc/img/bitcointalk.png -------------------------------------------------------------------------------- /doc/img/discord.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warthog-network/Warthog/868a69355981e3ab3a55ffa692cd8a8aa229e592/doc/img/discord.png -------------------------------------------------------------------------------- /doc/img/telegram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warthog-network/Warthog/868a69355981e3ab3a55ffa692cd8a8aa229e592/doc/img/telegram.png -------------------------------------------------------------------------------- /doc/img/tokenomics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warthog-network/Warthog/868a69355981e3ab3a55ffa692cd8a8aa229e592/doc/img/tokenomics.png -------------------------------------------------------------------------------- /doc/img/warthog_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warthog-network/Warthog/868a69355981e3ab3a55ffa692cd8a8aa229e592/doc/img/warthog_logo.png -------------------------------------------------------------------------------- /dockerfiles/Dockerfile: -------------------------------------------------------------------------------- 1 | build_linux -------------------------------------------------------------------------------- /dockerfiles/build_linux: -------------------------------------------------------------------------------- 1 | FROM alpine:3.17.2 AS build 2 | RUN apk add meson libgcc musl-dev gcc g++ upx 3 | COPY . /code 4 | RUN mkdir /build 5 | WORKDIR /code 6 | RUN --mount=type=cache,target=/build LDFLAGS='-static' meson /build/code --default-library static --buildtype=release 7 | WORKDIR /build/code 8 | RUN --mount=type=cache,target=/build ninja 9 | RUN mkdir /install 10 | RUN --mount=type=cache,target=/build DESTDIR=/install meson install 11 | RUN upx /install/usr/local/bin/wart-node 12 | 13 | FROM scratch AS export-stage 14 | COPY --from=build install/usr/local/bin/wart-node ./wart-node-linux 15 | COPY --from=build install/usr/local/bin/wart-wallet ./wart-wallet-linux 16 | 17 | VOLUME ["/warthog/.warthog"] 18 | ENTRYPOINT ["./wart-node-linux", "--chain-db=/warthog/.warthog/chain.db", "--peers-db=/warthog/.warthog/peers.db"] 19 | EXPOSE 9186 3000 20 | -------------------------------------------------------------------------------- /dockerfiles/build_macos: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | ARG OSXCROSS_VERSION=13.1-r0 4 | FROM --platform=$BUILDPLATFORM crazymax/osxcross:${OSXCROSS_VERSION}-alpine AS osxcross 5 | 6 | FROM alpine as build 7 | RUN apk add --no-cache clang lld musl-dev fts-dev 8 | ENV PATH="/osxcross/bin:$PATH" 9 | ENV LD_LIBRARY_PATH="/osxcross/lib:$LD_LIBRARY_PATH" 10 | COPY --from=osxcross /osxcross /osxcross 11 | RUN apk add meson libgcc musl-dev gcc g++ upx 12 | COPY . /code 13 | RUN mkdir /build 14 | WORKDIR /code 15 | 16 | RUN meson setup /build-macos --cross-file crosscompile/aarch64-macOS.txt --default-library static --buildtype=release 17 | RUN meson compile -C /build-macos 18 | RUN mkdir /install 19 | RUN DESTDIR=/install meson install -C /build-macos 20 | 21 | FROM scratch AS export-stage 22 | COPY --from=build install/usr/local/bin/wart-node ./wart-node-aarch64 23 | COPY --from=build install/usr/local/bin/wart-wallet ./wart-wallet-aarch64 24 | -------------------------------------------------------------------------------- /dockerfiles/build_windows: -------------------------------------------------------------------------------- 1 | FROM alpine:3.17.2 AS build 2 | RUN apk add meson libgcc musl-dev gcc g++ mingw-w64-gcc 3 | COPY . /code 4 | RUN mkdir /build-mingw 5 | WORKDIR /code 6 | RUN --mount=type=cache,target=/build-mingw LDFLAGS='-static' meson setup /build-mingw --cross-file crosscompile/x86_64-w64-mingw32.txt --default-library static --buildtype=release 7 | 8 | RUN --mount=type=cache,target=/build-mingw meson compile -C /build-mingw 9 | RUN mkdir /install 10 | RUN --mount=type=cache,target=/build-mingw DESTDIR=/install meson install -C /build-mingw 11 | 12 | 13 | FROM scratch AS export-stage 14 | COPY --from=build install/usr/local/bin/wart-node.exe ./wart-node-windows.exe 15 | COPY --from=build install/usr/local/bin/wart-wallet.exe ./wart-wallet-windows.exe 16 | -------------------------------------------------------------------------------- /dockerfiles/run_tests: -------------------------------------------------------------------------------- 1 | FROM alpine:3.17.2 AS build 2 | RUN apk add meson libgcc musl-dev gcc g++ upx 3 | COPY . /code 4 | RUN mkdir /build 5 | WORKDIR /code 6 | RUN --mount=type=cache,target=/build LDFLAGS='-static' meson /build/code --default-library static --buildtype=release 7 | WORKDIR /build/code 8 | RUN --mount=type=cache,target=/build meson test -v 9 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | project( 'Warthog', ['c','cpp'], 2 | version : '0.8.8', 3 | default_options : ['warning_level=3', 'cpp_std=c++20']) 4 | 5 | libuv_dep = subproject('libuv', default_options : ['warning_level=0', 'werror=false', 'build_tests=false']).get_variable('libuv_dep') 6 | sqlite3_dep = subproject('sqlite3',default_options : ['warning_level=0', 'werror=false']).get_variable('sqlite3_dep') 7 | 8 | subdir('./thirdparty') 9 | subdir('./src/shared') 10 | subdir('./src/node') 11 | subdir('./src/wallet') 12 | subdir('./src/test') 13 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | option('enable-gpu-miner', type : 'boolean', value : false) 2 | option('opencl-legacy', type : 'boolean', value : false) 3 | -------------------------------------------------------------------------------- /src/node/api/http/parse.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "communication/create_payment.hpp" 3 | #include "communication/mining_task.hpp" 4 | ChainMiningTask parse_mining_task(const std::vector& s); 5 | PaymentCreateMessage parse_payment_create(const std::vector& s); 6 | Funds parse_funds(const std::vector& s); 7 | -------------------------------------------------------------------------------- /src/node/api/types/accountid_or_address.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/body/account_id.hpp" 3 | #include "crypto/address.hpp" 4 | #include 5 | namespace API{ 6 | struct AccountIdOrAddress{ 7 | std::variant data; 8 | auto visit(const auto& lambda){ 9 | return std::visit(lambda,data); 10 | } 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /src/node/api/types/all.cpp: -------------------------------------------------------------------------------- 1 | #include "all.hpp" 2 | #include "block/chain/history/history.hpp" 3 | #include "chainserver/account_cache.hpp" 4 | #include "general/address_funds.hpp" 5 | 6 | namespace API { 7 | void Block::push_history(const Hash& txid, 8 | const std::vector& data, chainserver::AccountCache& cache, 9 | PinFloor pinFloor) 10 | { 11 | auto parsed = history::parse_throw(data); 12 | if (std::holds_alternative(parsed)) { 13 | auto& d = std::get(parsed); 14 | transfers.push_back( 15 | API::Block::Transfer { 16 | .fromAddress = cache[d.fromAccountId].address, 17 | .fee = d.compactFee.uncompact(), 18 | .nonceId = d.pinNonce.id, 19 | .pinHeight = d.pinNonce.pin_height(pinFloor), 20 | .txhash = txid, 21 | .toAddress = cache[d.toAccountId].address, 22 | .amount = d.amount }); 23 | } else { 24 | auto& d = std::get(parsed); 25 | auto toAddress = cache[d.toAccountId].address; 26 | rewards.push_back({ txid, toAddress, d.miningReward }); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/node/api/types/forward_declarations.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | namespace API { 4 | struct MempoolEntries; 5 | struct TransferTransaction; 6 | struct Head; 7 | struct ChainHead; 8 | struct MiningState; 9 | struct RewardTransaction; 10 | struct Balance; 11 | struct HashrateInfo; 12 | struct Block; 13 | struct AccountHistory; 14 | struct TransactionsByBlocks; 15 | struct HashrateChart; 16 | struct HashrateChartRequest; 17 | struct Richlist; 18 | struct Peerinfo; 19 | struct HeightOrHash; 20 | struct Round16Bit; 21 | struct PeerinfoConnections; 22 | struct AccountIdOrAddress;; 23 | struct Wallet; 24 | struct Rollback; 25 | struct Raw; 26 | using Transaction = std::variant; 27 | } 28 | -------------------------------------------------------------------------------- /src/node/api/types/height_or_hash.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include"block/chain/height.hpp" 4 | #include"crypto/hash.hpp" 5 | 6 | namespace API { 7 | struct HeightOrHash{ 8 | std::variant data; 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /src/node/asyncio/helpers/per_ip_counter.cpp: -------------------------------------------------------------------------------- 1 | #include "per_ip_counter.hpp" 2 | #include 3 | 4 | bool PerIpCounter::insert(IPv4 ip, size_t max) 5 | { 6 | size_t& count = counts.try_emplace(ip, 0).first->second; 7 | if (count >= max) 8 | return false; 9 | count += 1; 10 | return true; 11 | } 12 | void PerIpCounter::erase(IPv4 ip) 13 | { 14 | auto iter = counts.find(ip); 15 | if (iter == counts.end()) { 16 | return; 17 | } 18 | size_t& count = iter->second; 19 | assert(count != 0); 20 | count -= 1; 21 | if (count == 0) { 22 | counts.erase(iter); 23 | } 24 | } 25 | 26 | size_t PerIpCounter::count(IPv4 ip) 27 | { 28 | auto iter = counts.find(ip); 29 | if (iter == counts.end()) 30 | return 0; 31 | size_t& count = iter->second; 32 | assert(count != 0); 33 | return count; 34 | } 35 | -------------------------------------------------------------------------------- /src/node/asyncio/helpers/per_ip_counter.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "general/tcp_util.hpp" 4 | #include 5 | #include 6 | 7 | class PerIpCounter { 8 | public: 9 | bool insert(IPv4 ip, size_t max = std::numeric_limits::max()); 10 | void erase(IPv4); 11 | size_t count(IPv4); 12 | const auto& data() const { return counts; } 13 | 14 | private: 15 | std::map counts; 16 | }; 17 | -------------------------------------------------------------------------------- /src/node/asyncio/stratum/stratum_server.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/block.hpp" 3 | #include 4 | #include 5 | 6 | 7 | class StratumCoordinator; 8 | class StratumSession 9 | { 10 | friend class StratumCoordinator; 11 | public: 12 | 13 | }; 14 | 15 | class StratumCoordinator 16 | { 17 | public: 18 | void new_prev_hash(const Hash& h); 19 | private: 20 | std::map sessions; 21 | 22 | std::optional prevHash; 23 | std::map blocks; 24 | }; 25 | -------------------------------------------------------------------------------- /src/node/block/body/generator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/body/container.hpp" 3 | #include "block/body/primitives.hpp" 4 | #include "general/byte_order.hpp" 5 | 6 | class ChainDB; 7 | BodyContainer generate_body(const ChainDB& db, NonzeroHeight height, const Address& miner, const std::vector& payments); 8 | 9 | -------------------------------------------------------------------------------- /src/node/block/body/primitives.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/body/transaction_id.hpp" 3 | #include "block/chain/height.hpp" 4 | #include "crypto/address.hpp" 5 | #include "crypto/crypto.hpp" 6 | #include "crypto/hash.hpp" 7 | 8 | class Address; 9 | class HashView; 10 | class TransferView; 11 | 12 | class PaymentCreateMessage; 13 | 14 | namespace mempool { 15 | struct EntryValue; 16 | } 17 | 18 | struct TransferTxExchangeMessage { 19 | public: 20 | // layout: 21 | static constexpr size_t bytesize = 16 + 3 + 2 + 20 + 8 + 65; 22 | TransferTxExchangeMessage(ReaderCheck r); 23 | TransferTxExchangeMessage(AccountId fromId, const PaymentCreateMessage& pcm); 24 | TransferTxExchangeMessage(const TransactionId& txid, const mempool::EntryValue&); 25 | TransferTxExchangeMessage(TransferView, PinHeight, AddressView toAddr); 26 | 27 | friend Writer& operator<<(Writer&, TransferTxExchangeMessage); 28 | [[nodiscard]] TxHash txhash(HashView pinHash) const; 29 | [[nodiscard]] Address from_address(HashView txHash) const; 30 | [[nodiscard]] Funds spend_throw() const { return Funds::sum_throw(fee(), amount); } 31 | Funds fee() const { return compactFee.uncompact(); } 32 | AccountId from_id() const { return txid.accountId; } 33 | PinHeight pin_height() const { return txid.pinHeight; } 34 | NonceId nonce_id() const { return txid.nonceId; } 35 | 36 | TransactionId txid; 37 | NonceReserved reserved; 38 | CompactUInt compactFee; 39 | Address toAddr; 40 | Funds amount; 41 | RecoverableSignature signature; 42 | }; 43 | -------------------------------------------------------------------------------- /src/node/block/chain/batch_slot.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/height.hpp" 3 | 4 | struct Batchslot { 5 | explicit Batchslot(uint32_t i) 6 | : i(i) 7 | { 8 | } 9 | explicit Batchslot(Height h) 10 | : Batchslot((h.val - 1) / HEADERBATCHSIZE) 11 | { 12 | } 13 | [[nodiscard]] Height offset() const 14 | { 15 | return Height(i * HEADERBATCHSIZE); 16 | } 17 | [[nodiscard]] NonzeroHeight lower() const 18 | { 19 | return (i * HEADERBATCHSIZE + 1); 20 | } 21 | [[nodiscard]] NonzeroHeight upper() const 22 | { 23 | return (i + 1) * HEADERBATCHSIZE; 24 | } 25 | [[nodiscard]] Batchslot operator+(uint32_t add) const{ 26 | return Batchslot(i+add); 27 | } 28 | [[nodiscard]] uint32_t operator-(Batchslot s) const{ 29 | return i-s.i; 30 | } 31 | Batchslot& operator++() 32 | { 33 | i += 1; 34 | return *this; 35 | } 36 | size_t index() { return i; } 37 | [[nodiscard]] Batchslot operator-(uint32_t j){ 38 | assert(i >= j ); 39 | return Batchslot(i-j); 40 | } 41 | 42 | friend bool operator==(const Batchslot&, const Batchslot&) = default; 43 | 44 | auto operator<=>(const Batchslot& h2) const = default; 45 | private: 46 | uint32_t i; 47 | }; 48 | -------------------------------------------------------------------------------- /src/node/block/chain/binary_forksearch.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | template 6 | [[nodiscard]] inline size_t binary_forksearch(const T1& v1, const T2& v2, size_t lower, size_t upper) 7 | { 8 | // Verified, OK. 9 | while (upper > lower) { 10 | size_t pos = lower + (upper-lower) / 2; 11 | if (v1[pos] == v2[pos]) 12 | lower = pos + 1; 13 | else 14 | upper = pos; 15 | } 16 | return upper; 17 | } 18 | 19 | template 20 | [[nodiscard]] inline std::pair binary_forksearch(const T1& v1, const T2& v2, size_t lower = 0) 21 | { 22 | const size_t s1 = v1.size(); 23 | const size_t s2 = v2.size(); 24 | const size_t len = (s1 > s2 ? s2 : s1); 25 | size_t res = binary_forksearch(v1, v2, lower, len); 26 | return {res,res != len}; 27 | } 28 | -------------------------------------------------------------------------------- /src/node/block/chain/history/index.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "general/with_uint64.hpp" 3 | struct HistoryId : public IsUint64 { 4 | using IsUint64::IsUint64; 5 | bool operator==(const HistoryId&) const = default; 6 | size_t operator-(HistoryId a) 7 | { 8 | return val - a.val; 9 | } 10 | HistoryId operator-(size_t i) const{ 11 | return HistoryId(val - i); 12 | } 13 | HistoryId operator+(size_t i) const 14 | { 15 | return HistoryId(val + i); 16 | } 17 | HistoryId operator++(int) 18 | { 19 | return HistoryId(val++); 20 | } 21 | HistoryId operator++() 22 | { 23 | return HistoryId(++val); 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /src/node/block/chain/offender.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/height.hpp" 3 | #include "eventloop/types/conref_declaration.hpp" 4 | #include "general/errors.hpp" 5 | struct ChainOffender : public ChainError { 6 | ChainOffender(const ChainError& ce, Conref cr) 7 | : ChainError(ce) 8 | , conId(cr.id()) 9 | { 10 | } 11 | ChainOffender(const ChainError& ce, uint64_t connectionId) 12 | : ChainError(ce) 13 | , conId(connectionId) 14 | { 15 | } 16 | ChainOffender(int32_t e, NonzeroHeight height, uint64_t connectionId) 17 | : ChainError(e, height) 18 | , conId(connectionId) {}; 19 | uint64_t conId; 20 | }; 21 | -------------------------------------------------------------------------------- /src/node/block/chain/offsts.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/body/account_id.hpp" 3 | #include "block/chain/height.hpp" 4 | #include "block/chain/history/index.hpp" 5 | #include 6 | 7 | template 8 | struct Heights { 9 | Heights(std::vector data = {}) 10 | : data(std::move(data)) {}; 11 | const T& at(NonzeroHeight h) const 12 | { 13 | return data.at((h - 1).value()); 14 | } 15 | void shrink(Height newlength) 16 | { 17 | assert(size() >= newlength.value()); 18 | data.erase(data.begin() + newlength.value(), data.end()); 19 | } 20 | void append(T v) 21 | { 22 | data.push_back(std::move(v)); 23 | } 24 | [[nodiscard]] HeightType height(const T& t) const 25 | { 26 | auto iter = std::upper_bound(data.begin(), data.end(), 27 | t); 28 | assert(iter != data.begin()); 29 | return HeightType(uint32_t((iter - 1) - data.begin() + 1)); 30 | } 31 | void append_vector(const std::vector& v) 32 | { 33 | data.insert(data.end(), v.begin(), v.end()); 34 | } 35 | size_t size() const 36 | { 37 | return data.size(); 38 | } 39 | 40 | protected: 41 | std::vector data; 42 | }; 43 | using HistoryHeights = Heights; 44 | using AccountHeights = Heights; 45 | -------------------------------------------------------------------------------- /src/node/block/chain/pin.cpp: -------------------------------------------------------------------------------- 1 | #include "pin.hpp" 2 | #include "block/header/header.hpp" 3 | 4 | std::optional GridPin::checkpoint(){ 5 | // UPDATE GRID PIN HERE (HARD-CODED CHAIN CHECKPOINT) 6 | static Header h("34b4064fced07341204e3b2283477d5fc6423d7f8244f83d6e1fa1551a74ad470ba7c02fc4c7d16b758e8af266349dc1070727b5ecd5d7fc6c6417d2458018e328818355000000036748585daf74da6b"); 7 | return GridPin{Batchslot(259),h}; 8 | } 9 | -------------------------------------------------------------------------------- /src/node/block/chain/pin.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/batch_slot.hpp" 3 | #include "block/header/view.hpp" 4 | struct ChainPin { 5 | Height height; 6 | HeaderView header; 7 | }; 8 | struct GridPin { 9 | Batchslot slot; 10 | HeaderView finalHeader; 11 | static std::optional checkpoint(); 12 | }; 13 | -------------------------------------------------------------------------------- /src/node/block/chain/range.cpp: -------------------------------------------------------------------------------- 1 | #include "range.hpp" 2 | #include "general/reader.hpp" 3 | #include "general/writer.hpp" 4 | bool BlockRange::valid() 5 | { 6 | return lower <= upper 7 | && (upper - lower + 1 <= MAXBLOCKBATCHSIZE); 8 | } 9 | 10 | Writer& operator<<(Writer& w, BlockRange br) 11 | { 12 | return w << br.lower << br.upper; 13 | } 14 | 15 | BlockRange::BlockRange(Reader& r) 16 | : lower(r) 17 | , upper(r) 18 | { 19 | if (!valid()) 20 | throw Error(EBLOCKRANGE); 21 | } 22 | 23 | DescriptedBlockRange::DescriptedBlockRange(Reader& r) 24 | : BlockRange(r) 25 | , descriptor(r) {} 26 | 27 | Writer& operator<<(Writer& w, DescriptedBlockRange dbr) 28 | { 29 | return w << *static_cast(&dbr) << dbr.descriptor; 30 | } 31 | -------------------------------------------------------------------------------- /src/node/block/chain/range.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/height.hpp" 3 | #include "general/descriptor.hpp" 4 | 5 | struct BlockRange { 6 | BlockRange(NonzeroHeight lower, NonzeroHeight upper) 7 | : lower(lower) 8 | , upper(upper) 9 | { 10 | assert(valid()); 11 | } 12 | 13 | // data 14 | NonzeroHeight lower; 15 | NonzeroHeight upper; 16 | uint32_t length() const { return upper - lower + 1; } 17 | BlockRange(Reader&); 18 | friend Writer& operator<<(Writer&, BlockRange); 19 | 20 | private: 21 | bool valid(); 22 | }; 23 | 24 | struct DescriptedBlockRange:public BlockRange { 25 | Descriptor descriptor; 26 | DescriptedBlockRange(Descriptor descriptor, NonzeroHeight lowerHeight, NonzeroHeight upperHeight) 27 | : BlockRange{lowerHeight, upperHeight}, 28 | descriptor(descriptor) {} 29 | DescriptedBlockRange(Reader& r); 30 | friend Writer& operator<<(Writer&, DescriptedBlockRange); 31 | }; 32 | -------------------------------------------------------------------------------- /src/node/block/chain/state.cpp: -------------------------------------------------------------------------------- 1 | #include "block/chain/state.hpp" 2 | #include "communication/messages.hpp" 3 | 4 | bool Descripted::valid() 5 | { 6 | return ((_chainLength == 0) == (_worksum.is_zero()) 7 | && _grid.slot_end().upper() > _chainLength 8 | && _grid.slot_end().offset() <= _chainLength); 9 | } 10 | 11 | Descripted::Descripted(Descriptor descriptor, Height chainLength, Worksum worksum, Grid grid) 12 | : descriptor(descriptor) 13 | , _chainLength(chainLength) 14 | , _worksum(worksum) 15 | , _grid(grid) { 16 | if (!valid()) { 17 | throw Error(EINVDSC); 18 | } 19 | } 20 | void Descripted::append_throw(const AppendMsg& msg) 21 | { 22 | if (worksum() >= msg.worksum || chain_length() >= msg.newLength) { 23 | throw Error(EAPPEND); 24 | } 25 | _chainLength = msg.newLength; 26 | _worksum = msg.worksum; 27 | _grid.append(msg.grid); 28 | if (!valid()) { 29 | throw Error(EAPPEND); 30 | } 31 | } 32 | 33 | void Descripted::deprecate() 34 | { 35 | deprecation_time = std::chrono::steady_clock::now(); 36 | } 37 | bool Descripted::expired() const 38 | { 39 | using namespace std::chrono; 40 | if (!deprecation_time) 41 | return false; 42 | return *deprecation_time + minutes(8) < steady_clock::now(); 43 | } 44 | -------------------------------------------------------------------------------- /src/node/block/chain/state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/fork_range.hpp" 3 | #include "block/chain/worksum.hpp" 4 | #include "block/header/batch.hpp" 5 | #include "general/descriptor.hpp" 6 | #include 7 | 8 | struct AppendMsg; 9 | struct Descripted { 10 | // data 11 | const Descriptor descriptor; 12 | std::optional deprecation_time; 13 | 14 | Descripted(Descriptor descriptor, Height chainLength, Worksum worksum, Grid grid); 15 | void deprecate(); 16 | void append_throw(const AppendMsg& msg); //throws 17 | 18 | //getters 19 | [[nodiscard]] bool expired() const; 20 | [[nodiscard]] Height chain_length() const{return _chainLength;} 21 | [[nodiscard]] const Worksum& worksum() const {return _worksum;} 22 | [[nodiscard]] const Grid& grid() const {return _grid;} 23 | 24 | 25 | private: 26 | bool valid(); 27 | Height _chainLength { 0u }; 28 | Worksum _worksum; 29 | Grid _grid; 30 | }; 31 | 32 | -------------------------------------------------------------------------------- /src/node/block/header/timestamprule.cpp: -------------------------------------------------------------------------------- 1 | #include "timestamprule.hpp" 2 | #include "general/now.hpp" 3 | #include 4 | 5 | uint32_t TimestampValidator::get_valid_timestamp() const 6 | { 7 | auto cpy { data }; 8 | size_t index { (cpy.size() + 1) / 2 }; 9 | std::nth_element(cpy.begin(), cpy.begin() + index, cpy.end()); 10 | 11 | auto v = std::max(cpy[index], uint64_t(now_timestamp())); 12 | if (v + TOLERANCEMINUTES * 60 < tmax) { 13 | v = tmax - TOLERANCEMINUTES * 60; 14 | } 15 | return v; 16 | } 17 | -------------------------------------------------------------------------------- /src/node/block/header/timestamprule.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "general/params.hpp" 3 | #include 4 | #include 5 | 6 | class TimestampValidator { 7 | public: 8 | TimestampValidator() 9 | { 10 | clear(); 11 | } 12 | void clear() 13 | { 14 | tmax = 0; 15 | for (size_t i = 0; i < N; ++i) 16 | data[i] = 0; 17 | } 18 | bool valid(const uint64_t tnew) const 19 | { 20 | if (tnew == 0) 21 | return false; 22 | 23 | // no time drops 24 | if (tnew + TOLERANCEMINUTES * 60 < tmax) 25 | return false; 26 | 27 | // check median rule 28 | size_t n = 0; 29 | for (auto t : data) { 30 | constexpr size_t bound = N / 2; 31 | if (tnew >= t) { 32 | n += 1; 33 | if (n > bound) { 34 | return true; 35 | } 36 | } 37 | } 38 | return false; 39 | } 40 | uint32_t get_valid_timestamp() const; 41 | void append(uint64_t tnew) 42 | { 43 | if (tmax > tnew) 44 | tmax = tnew; 45 | data[pos++] = tnew; 46 | if (pos >= N) 47 | pos = 0; 48 | } 49 | 50 | static constexpr uint32_t N = MEDIAN_N; 51 | 52 | private: 53 | size_t pos = 0; 54 | uint64_t tmax = 0; 55 | std::array data; 56 | }; 57 | -------------------------------------------------------------------------------- /src/node/block/id.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "general/with_uint64.hpp" 4 | class BlockId :public IsUint64{ 5 | public: 6 | explicit BlockId(int64_t val) 7 | : IsUint64(val) 8 | { 9 | } 10 | bool operator==(const BlockId&) const = default; 11 | auto operator<=>(const BlockId&) const = default; 12 | }; 13 | -------------------------------------------------------------------------------- /src/node/chainserver/account_cache.cpp: -------------------------------------------------------------------------------- 1 | #include "account_cache.hpp" 2 | #include "db/chain_db.hpp" 3 | #include "general/address_funds.hpp" 4 | 5 | namespace chainserver { 6 | const AddressFunds& AccountCache::operator[](AccountId id) 7 | { 8 | auto iter = map.find(id); 9 | if (iter != map.end()) 10 | return iter->second; 11 | auto p = db.fetch_account(id); 12 | return map.emplace(id, p).first->second; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/node/chainserver/account_cache.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/body/account_id.hpp" 3 | #include 4 | class ChainDB; 5 | class AddressFunds; 6 | namespace chainserver { 7 | struct AccountCache { 8 | AccountCache(const ChainDB& db) 9 | : db(db) 10 | { 11 | } 12 | 13 | public: 14 | const AddressFunds& operator[](AccountId id); 15 | 16 | private: 17 | std::map map; 18 | const ChainDB& db; 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /src/node/chainserver/mining_subscription.cpp: -------------------------------------------------------------------------------- 1 | #include "mining_subscription.hpp" 2 | #include "chainserver/server.hpp" 3 | #include "communication/mining_task.hpp" 4 | #include 5 | namespace { 6 | static std::atomic gid { 0 }; 7 | } 8 | namespace mining_subscription { 9 | 10 | SubscriptionId::SubscriptionId() 11 | : id(gid++) {}; 12 | 13 | void MiningSubscriptions::dispatch(std::function(const Address&)> blockGenerator) 14 | { 15 | for (auto& [addr, v] : subscriptions) { 16 | auto b { blockGenerator(addr) }; 17 | for (auto& [_, f] : v) { 18 | if (b.has_value()) 19 | f(ChainMiningTask { b.value() }); 20 | } 21 | } 22 | } 23 | 24 | void MiningSubscriptions::subscribe(SubscriptionRequest&& r) 25 | { 26 | auto [iter, _] = subscriptions.try_emplace(r.address); 27 | iter->second.push_back({ r.id, std::move(r.callback) }); 28 | lookupSubscription.emplace(r.id, iter); 29 | } 30 | 31 | void MiningSubscriptions::unsubscribe(SubscriptionId id) 32 | { 33 | auto iter { lookupSubscription.find(id) }; 34 | if (iter == lookupSubscription.end()) 35 | return; 36 | auto subiter { iter->second }; 37 | assert(1 == std::erase_if(subiter->second, [id](Elem& e) { return e.id == id; })); 38 | if (subiter->second.size() == 0) { 39 | subscriptions.erase(subiter); 40 | } 41 | lookupSubscription.erase(iter); 42 | }; 43 | 44 | MiningSubscription::~MiningSubscription() 45 | { 46 | auto l { chainServer.lock() }; 47 | if (l) 48 | l->api_unsubscribe_mining(id); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/node/chainserver/state/helpers/past_chains.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/header_chain.hpp" 3 | #include "db/chain/deletion_key.hpp" 4 | class ChainDB; 5 | 6 | namespace chainserver { 7 | class BlockCache { 8 | public: 9 | [[nodiscard]] std::shared_ptr add_old_chain(const Chainstate&, DeletionKey); //OK 10 | void schedule_discard(DeletionKey); 11 | Batch get_batch(const BatchSelector& s) const; 12 | std::optional get_header(Descriptor descriptor, Height height) const; 13 | void garbage_collect(ChainDB&); 14 | std::vector get_hashes(const DescriptedBlockRange&) const; 15 | 16 | private: 17 | struct Entry { 18 | std::shared_ptr headers; 19 | Entry(std::shared_ptr headers) 20 | : headers(std::move(headers)){} 21 | }; 22 | mutable std::mutex mutex; 23 | std::map chains; // by chain id 24 | // 25 | 26 | struct DiscardedStageSchedule { 27 | }; 28 | struct ChainSchedule { 29 | decltype(chains)::iterator iter; 30 | }; 31 | 32 | void handle(DiscardedStageSchedule); 33 | void handle(ChainSchedule); 34 | struct DeleteScheduleEntry { 35 | std::variant data; 36 | DeletionKey deletionKey; 37 | }; 38 | void schedule(std::variant, DeletionKey); 39 | 40 | using tp = std::chrono::system_clock::time_point; 41 | std::map gcSchedule; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /src/node/chainserver/state/transactions/apply_stage.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../state.hpp" 3 | #include "db/chain_db.hpp" 4 | #include "api/types/forward_declarations.hpp" 5 | 6 | namespace chainserver { 7 | class ApplyStageTransaction { 8 | using StateUpdate = state_update::StateUpdate; 9 | public: 10 | ApplyStageTransaction(const State& s, ChainDBTransaction&& transaction); 11 | 12 | void consider_rollback(Height shrinkLength); 13 | [[nodiscard]] std::pair,ChainError> apply_stage_blocks(); 14 | [[nodiscard]] StateUpdate commit(State&); 15 | 16 | private: 17 | const State& ccs; // const ref 18 | ChainDBTransaction transaction; 19 | Height chainlength; 20 | std::optional rb; 21 | std::optional applyResult; 22 | 23 | bool commited = false; 24 | }; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/node/chainserver/state/transactions/block_applier.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "crypto/address.hpp" 3 | #include "../../transaction_ids.hpp" 4 | #include "api/types/forward_declarations.hpp" 5 | class ChainDB; 6 | class Headerchain; 7 | class BodyView; 8 | class BlockId; 9 | class HeaderView; 10 | 11 | namespace chainserver { 12 | struct Preparation; 13 | struct BlockApplier { 14 | BlockApplier(ChainDB& db, const Headerchain& hc, const std::set& baseTxIds, bool fromStage) 15 | : preparer { db, hc, baseTxIds, {} } 16 | , db(db) 17 | , fromStage(fromStage) 18 | { 19 | } 20 | TransactionIds&& move_new_txids() { return std::move(preparer.newTxIds); }; 21 | auto&& move_balance_updates() { return std::move(balanceUpdates); }; 22 | [[nodiscard]] API::Block apply_block(const BodyView& bv, HeaderView, NonzeroHeight height, BlockId blockId); 23 | 24 | private: // private methods 25 | struct Preparer { 26 | const ChainDB& db; // preparer cannot modify db! 27 | const Headerchain& hc; 28 | const std::set& baseTxIds; 29 | TransactionIds newTxIds; 30 | Preparation prepare(const BodyView& bv, const NonzeroHeight height) const; 31 | }; 32 | 33 | private: // private data 34 | Preparer preparer; 35 | std::map balanceUpdates; 36 | ChainDB& db; 37 | bool fromStage; 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /src/node/chainserver/state/update/chainstate_update.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "block/chain/header_chain.hpp" 4 | #include 5 | 6 | namespace chainserver { 7 | namespace state_update { 8 | struct Fork : public HeaderchainFork { 9 | std::shared_ptr prevChain; 10 | std::optional signedSnapshot; 11 | }; 12 | 13 | struct RollbackData { 14 | struct Data { 15 | HeaderchainRollback rollback; 16 | std::shared_ptr prevChain; 17 | }; 18 | std::optional data; 19 | SignedSnapshot signedSnapshot; 20 | }; 21 | 22 | struct Append { 23 | HeaderchainAppend headerchainAppend; 24 | std::optional signedSnapshot; 25 | }; 26 | 27 | using ChainstateUpdate = std::variant< 28 | Fork, 29 | Append, 30 | RollbackData>; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/node/chainserver/state/update/mempool_update.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "mempool/log.hpp" 4 | namespace chainserver{ 5 | namespace state_update { 6 | using MempoolUpdate = mempool::Log; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/node/chainserver/state/update/stage_update.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "block/chain/height.hpp" 4 | namespace chainserver { 5 | namespace state_update { 6 | struct StageUpdate { 7 | std::optional shrinkLength; 8 | }; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/node/chainserver/state/update/update.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "chainstate_update.hpp" 3 | #include "mempool_update.hpp" 4 | #include "stage_update.hpp" 5 | 6 | namespace chainserver { 7 | namespace state_update { 8 | 9 | struct StateUpdate { 10 | ChainstateUpdate chainstateUpdate; 11 | MempoolUpdate mempoolUpdate; 12 | }; 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/node/chainserver/transaction_ids.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/body/transaction_id.hpp" 3 | #include 4 | namespace chainserver { 5 | 6 | struct ByPinHeight { 7 | bool operator()(const TransactionId& tid1, const TransactionId& tid2) const 8 | { 9 | if (tid1.pinHeight == tid2.pinHeight) 10 | return tid1 < tid2; 11 | return tid1.pinHeight < tid2.pinHeight; 12 | } 13 | }; 14 | struct TransactionIds : public std::set { 15 | static std::pair block_range(Height length) 16 | { 17 | Height end { length + 1 }; // height of next block 18 | Height begin = end.pin_begin() + 1; // +1 because at pin_begin we cannot have 19 | // the same pinHeight 20 | return { begin, end }; 21 | } 22 | void prune(Height length) 23 | { 24 | const Height minPinHeight { (length + 1).pin_begin() }; 25 | auto iter = begin(); 26 | while (iter != end() && iter->pinHeight < minPinHeight) 27 | erase(iter++); 28 | } 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /src/node/cmdline/cmdline.cpp: -------------------------------------------------------------------------------- 1 | #include"version.hpp" 2 | #include"cmdline.c" 3 | -------------------------------------------------------------------------------- /src/node/cmdline/cmdline.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "version.hpp" 3 | #include "cmdline.h" 4 | -------------------------------------------------------------------------------- /src/node/communication/buffers/sndbuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "sndbuffer.hpp" 2 | #include "crypto/hasher_sha256.hpp" 3 | 4 | void Sndbuffer::writeChecksum() 5 | { 6 | auto tmp = hashSHA256(reinterpret_cast(ptr.get() + 8), len - 8); 7 | memcpy(ptr.get() + 4, tmp.data(), 4); 8 | } 9 | -------------------------------------------------------------------------------- /src/node/communication/buffers/sndbuffer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "general/byte_order.hpp" 3 | #include 4 | #include 5 | #include 6 | 7 | class Sndbuffer { 8 | public: 9 | const uint32_t len; 10 | std::unique_ptr ptr; 11 | Sndbuffer(uint8_t msgtype, uint32_t msglen) 12 | : len(msglen + 10), ptr(new char[len]) { 13 | ptr[8] = 0; 14 | ptr[9] = msgtype; 15 | uint32_t n=hton32(len-8); 16 | memcpy(ptr.get(),&n,4); 17 | } 18 | void writeChecksum(); 19 | uint8_t* msgdata() { return reinterpret_cast(ptr.get() + 10); }; 20 | size_t msgsize() { return len - 10; } 21 | size_t fullsize() { return len; } 22 | }; 23 | -------------------------------------------------------------------------------- /src/node/communication/stage_operation/request.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "block/block.hpp" 4 | #include "block/chain/header_chain.hpp" 5 | #include 6 | namespace stage_operation { 7 | 8 | struct StageSetOperation { 9 | Headerchain headers; 10 | }; 11 | 12 | struct StageAddOperation { 13 | Headerchain headers;// LATER: remove if no more bugs 14 | std::vector blocks; 15 | }; 16 | 17 | using Operation = std::variant; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/node/communication/stage_operation/result.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/height.hpp" 3 | #include "general/errors.hpp" 4 | #include "chainserver/state/update/update.hpp" 5 | #include 6 | #include 7 | namespace stage_operation { 8 | 9 | struct StageSetResult { 10 | std::optional firstMissHeight; 11 | }; 12 | struct StageAddResult { 13 | ChainError ce; 14 | }; 15 | using Result = std::variant; 16 | } 17 | -------------------------------------------------------------------------------- /src/node/config/config.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "block/chain/signed_snapshot.hpp" 4 | #include "general/tcp_util.hpp" 5 | #include 6 | struct gengetopt_args_info; 7 | struct EndpointVector: public std::vector { 8 | using vector::vector; 9 | EndpointVector(std::vector v):vector(std::move(v)){} 10 | EndpointVector(std::initializer_list l){ 11 | for (auto &s : l) { 12 | push_back({s}); 13 | } 14 | } 15 | }; 16 | struct Config { 17 | struct Data { 18 | std::string chaindb; 19 | std::string peersdb; 20 | } data; 21 | struct JSONRPC { 22 | EndpointAddress bind; 23 | } jsonrpc; 24 | struct PublicAPI { 25 | EndpointAddress bind; 26 | }; 27 | struct StratumPool { 28 | EndpointAddress bind; 29 | }; 30 | std::optional publicAPI; 31 | std::optional stratumPool; 32 | struct Node { 33 | std::optional snapshotSigner; 34 | EndpointAddress bind; 35 | bool isolated { false }; 36 | bool disableTxsMining { false }; // don't mine transactions 37 | std::atomic logCommunication { false }; 38 | } node; 39 | struct Peers { 40 | bool allowLocalhostIp = false; // do not ignore 127.xxx.xxx.xxx peer node addresses provided by peers 41 | EndpointVector connect; 42 | bool enableBan { true }; 43 | } peers; 44 | bool localDebug { false }; 45 | 46 | std::string dump(); 47 | const std::string defaultDataDir; 48 | int init(int argc, char** argv); 49 | 50 | Config(); 51 | private: 52 | int process_gengetopt(gengetopt_args_info&); 53 | }; 54 | -------------------------------------------------------------------------------- /src/node/db/chain/deletion_key.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "general/with_uint64.hpp" 5 | struct DeletionKey :IsUint64{ 6 | DeletionKey(uint64_t i):IsUint64(i){ 7 | assert(i!=0); 8 | } 9 | DeletionKey operator++(int){ 10 | return val++; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /src/node/db/offense_entry.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "general/tcp_util.hpp" 3 | #include "general/errors.hpp" 4 | struct OffenseEntry { 5 | IPv4 ip; 6 | uint32_t timestamp; 7 | Error offense; 8 | }; 9 | -------------------------------------------------------------------------------- /src/node/eventloop/address_manager/address_manager_impl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "address_manager.hpp" 3 | #include "eventloop/types/conndata_impl.hpp" 4 | 5 | namespace address_manager { 6 | inline void AddressManager::All::Iterator::find_next() 7 | { 8 | while (true) { 9 | if (iter == ref.conndatamap.end() || !iter->second.erased()) 10 | break; 11 | ++iter; 12 | } 13 | } 14 | inline void AddressManager::Initialized::Iterator::find_next() 15 | { 16 | while (true) { 17 | if (iter == ref.conndatamap.end() || ((!iter->second.erased()) && (*iter).initialized())) 18 | break; 19 | ++iter; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/node/eventloop/address_manager/flat_address_set.cpp: -------------------------------------------------------------------------------- 1 | #include "flat_address_set.hpp" 2 | #include 3 | 4 | namespace address_manager { 5 | bool FlatAddressSet::contains(EndpointAddress a) 6 | { 7 | auto iter = std::lower_bound(vec.begin(),vec.end(), a); 8 | return iter != vec.end() && *iter == a; 9 | } 10 | void FlatAddressSet::insert(EndpointAddress& a) 11 | { 12 | auto iter = std::lower_bound(vec.begin(),vec.end(), a); 13 | if (iter == vec.end()) 14 | vec.insert(iter, a); 15 | else if (*iter != a) { 16 | vec.insert(std::next(iter), a); 17 | } 18 | } 19 | void FlatAddressSet::erase(EndpointAddress a) 20 | { 21 | auto iter = std::lower_bound(vec.begin(),vec.end(), a); 22 | if (iter != vec.end() && *iter == a) { 23 | vec.erase(iter); 24 | } 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /src/node/eventloop/address_manager/flat_address_set.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "general/tcp_util.hpp" 3 | #include 4 | 5 | namespace address_manager { 6 | 7 | class FlatAddressSet { 8 | size_t maxAddresses = 500; 9 | std::vector vec; 10 | 11 | public: 12 | const std::vector& data() const { return vec; } 13 | size_t size() const { return vec.size(); } 14 | void clear() { vec.clear(); } 15 | bool full() { return vec.size() < maxAddresses; } 16 | bool contains(EndpointAddress a); 17 | void insert(EndpointAddress& a); 18 | void erase(EndpointAddress a); 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /src/node/eventloop/sync/block_download/attorney.cpp: -------------------------------------------------------------------------------- 1 | #include "attorney.hpp" 2 | #include "../../eventloop.hpp" 3 | #include "eventloop/address_manager/address_manager_impl.hpp" 4 | 5 | 6 | namespace BlockDownload { 7 | void Attorney::clear_blockdownload() { 8 | eventloop.chains.stage_clear(); 9 | for (auto c : eventloop.connections.initialized()) { 10 | c->chain.on_stage_set(Height(0)); 11 | } 12 | } 13 | const Headerchain& Attorney::headers() const{ 14 | 15 | return eventloop.chains.stage_headers(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/node/eventloop/sync/block_download/attorney.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "attorney_declaration.hpp" 3 | #include "block/chain/header_chain.hpp" 4 | #include "eventloop/eventloop.hpp" 5 | class Eventloop; 6 | namespace BlockDownload { 7 | inline auto Attorney::connections() const 8 | { 9 | return eventloop.connections.initialized(); 10 | } 11 | 12 | inline auto Attorney::set_stage_headers(Headerchain&& newheaders) 13 | { 14 | return eventloop.set_stage_headers(std::move(newheaders)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/node/eventloop/sync/block_download/attorney_declaration.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/header_chain.hpp" 3 | class Eventloop; 4 | namespace BlockDownload { 5 | 6 | class Attorney { 7 | public: 8 | Attorney(Eventloop& eventloop) 9 | : eventloop(eventloop) {}; 10 | void clear_blockdownload() ; 11 | auto set_stage_headers(Headerchain&& newheaders); 12 | const Headerchain& headers() const; 13 | auto connections() const; 14 | 15 | private: 16 | Eventloop& eventloop; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /src/node/eventloop/sync/block_download/connection_data.cpp: -------------------------------------------------------------------------------- 1 | #include "connection_data.hpp" 2 | #include "block/chain/state.hpp" 3 | #include "eventloop/types/conref_declaration.hpp" 4 | #include "eventloop/types/conref_impl.hpp" 5 | #include "focus.hpp" 6 | class Focus; 7 | namespace BlockDownload { 8 | 9 | [[nodiscard]] ConnectionData& data(Conref cr) 10 | { 11 | return cr->usage.data_blockdownload; 12 | }; 13 | 14 | ConnectionData::ForkData::IterRange::IterRange(ForkIter iter, ForkRange r) 15 | : _iter(iter) 16 | , _range(std::move(r)) 17 | { 18 | assert(iter->first == _range.lower()); 19 | } 20 | 21 | ConnectionData::ForkData::ForkData(std::shared_ptr d, ForkIter fi, ForkRange forkRange) 22 | : _descripted(std::move(d)) 23 | , iterRange { fi, forkRange } 24 | { 25 | assert(iterRange._range.lower() <= _descripted->chain_length() + 1); 26 | } 27 | 28 | void ConnectionData::ForkData::ForkData::udpate_iter_range(ForkIter iter, ForkRange range) 29 | { 30 | iterRange = { iter, range }; 31 | assert(iterRange._range.lower() <= _descripted->chain_length() + 1); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/node/eventloop/sync/block_download/forks.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "eventloop/sync/block_download/connection_data.hpp" 3 | #include "eventloop/types/conref_declaration.hpp" 4 | namespace BlockDownload { 5 | 6 | class Forks { 7 | public: 8 | size_t size() const { return forks.size(); } 9 | void pin_current_chain(Conref c); 10 | void pin_leader_chain(Conref, std::shared_ptr, ForkRange); 11 | std::optional reachable_length() const; 12 | void match(Conref c, const Headerchain& hc, NonzeroHeight h, HeaderView hv); 13 | void clear(); 14 | auto lower_bound(NonzeroHeight h) 15 | { 16 | return forks.lower_bound(h); 17 | } 18 | auto end() { return forks.end(); } 19 | void erase(Conref); 20 | auto rbegin() { return forks.rbegin(); } 21 | 22 | private: 23 | void replace_fork_iter(ConnectionData::ForkData& fd,Conref c, ForkRange fr); 24 | auto& forkdata(Conref c); 25 | Forkmap forks; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /src/node/eventloop/sync/header_download/connection_data.cpp: -------------------------------------------------------------------------------- 1 | #include "connection_data.hpp" 2 | #include "header_download.hpp" 3 | 4 | namespace HeaderDownload{ 5 | ConnectionData::ConnectionData(Downloader& d) 6 | : leaderIter(d.leaders_end()) {}; 7 | } 8 | -------------------------------------------------------------------------------- /src/node/eventloop/sync/header_download/connection_data.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "block/header/header.hpp" 4 | #include "eventloop/types/probe_data.hpp" 5 | #include 6 | #include 7 | #include 8 | 9 | // forward declaration 10 | namespace HeaderDownload { 11 | class Downloader; 12 | struct LeaderNode; 13 | using Lead_list = std::list; 14 | using Lead_iter = Lead_list::iterator; 15 | struct QueueBatchNode; 16 | using Queued_iter = std::map::iterator; 17 | 18 | struct ConnectionData { 19 | ConnectionData(HeaderDownload::Downloader& d); 20 | 21 | private: 22 | HeaderDownload::Lead_iter leaderIter; 23 | struct ProbeInfo : ProbeData { 24 | std::shared_ptr dsc; 25 | HeaderDownload::Queued_iter qiter; 26 | }; 27 | std::optional probeData; 28 | HeaderDownload::QueueBatchNode* jobPtr = nullptr; 29 | std::optional ignoreDescriptor; 30 | 31 | friend class HeaderDownload::Downloader; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /src/node/eventloop/sync/header_download/probe_balanced.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../types/peer_requests.hpp" 3 | struct ProbeData; 4 | struct ProbeBalanced { 5 | 6 | [[nodiscard]] static std::optional slot_batch_request(const ProbeData&, const std::shared_ptr&, Batchslot s, Header h); 7 | [[nodiscard]] static std::optional final_partial_batch_request(const ProbeData&, const std::shared_ptr&, NonzeroHeight maxLength, Worksum minWork); 8 | [[nodiscard]] static std::optional probe_request(const ProbeData&, const std::shared_ptr&, Height maxLength); 9 | 10 | [[nodiscard]] static NonzeroHeight lower(const ProbeData&); 11 | [[nodiscard]] static NonzeroHeight upper(const ProbeData&, Height maxLength); 12 | 13 | const ProbeData& probeData; 14 | Height maxLength; 15 | 16 | private: 17 | [[nodiscard]] std::optional batch_request(const std::shared_ptr& desc, std::optional
, Batchslot); 18 | [[nodiscard]] std::optional probe_request(const std::shared_ptr& desc); 19 | 20 | [[nodiscard]] NonzeroHeight lower(); 21 | [[nodiscard]] NonzeroHeight upper(); 22 | }; 23 | -------------------------------------------------------------------------------- /src/node/eventloop/sync/request_sender_declaration.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "eventloop/timer.hpp" 3 | #include 4 | class Eventloop; 5 | struct IsRequest; 6 | class RequestSender { 7 | public: 8 | template 9 | requires std::derived_from 10 | void send(Conref cr, const T& req); 11 | bool finished(); 12 | private: 13 | RequestSender(const RequestSender&) = default; 14 | RequestSender(RequestSender&&) = delete; 15 | friend class Eventloop; 16 | RequestSender(Eventloop& e) 17 | : e(e) 18 | { 19 | } 20 | Eventloop& e; 21 | }; 22 | -------------------------------------------------------------------------------- /src/node/eventloop/sync/sync.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "header_download/header_download.hpp" 4 | #include "block_download/block_download.hpp" 5 | -------------------------------------------------------------------------------- /src/node/eventloop/sync/sync_state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class SyncState { 5 | public: 6 | void set_block_download(bool val) 7 | { 8 | blockDownloadActive = val; 9 | } 10 | 11 | void set_header_download(bool val) 12 | { 13 | headerDownloadActive = val; 14 | } 15 | 16 | void set_has_connections(bool hasConnections) 17 | { 18 | hasInitializedConnections = hasConnections; 19 | } 20 | 21 | [[nodiscard]] std::optional detect_change() 22 | { 23 | bool newState; 24 | if (oldState == true) { 25 | newState = hasInitializedConnections; 26 | } else { 27 | newState = hasInitializedConnections && !blockDownloadActive && !headerDownloadActive; 28 | } 29 | bool changed = (newState != oldState); 30 | oldState = newState; 31 | if (changed) { 32 | return newState; 33 | } 34 | return {}; 35 | } 36 | 37 | private: 38 | bool hasInitializedConnections { false }; 39 | bool blockDownloadActive { false }; 40 | bool headerDownloadActive { false }; 41 | bool oldState { false }; 42 | }; 43 | -------------------------------------------------------------------------------- /src/node/eventloop/timer.cpp: -------------------------------------------------------------------------------- 1 | #include "timer.hpp" 2 | 3 | 4 | std::vector Timer::pop_expired() { 5 | const auto now = std::chrono::steady_clock::now(); 6 | std::vector res; 7 | for (auto iter = ordered.begin(); iter != ordered.end();) { 8 | if (iter->first > now) 9 | break; 10 | res.push_back(iter->second); 11 | ordered.erase(iter++); 12 | } 13 | return res; 14 | } 15 | 16 | Timer::time_point Timer::next() { 17 | if (ordered.empty()){ 18 | return std::chrono::steady_clock::now()+std::chrono::days(1); 19 | // this does not work on docker alpine 3.15 (wait_until fires immediately) 20 | // return time_point::max(); 21 | } 22 | return ordered.begin()->first; 23 | }; 24 | -------------------------------------------------------------------------------- /src/node/eventloop/timer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types/peer_requests.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | class Timer { 9 | 10 | public: 11 | struct WithConnecitonId { 12 | uint64_t conId; 13 | }; 14 | struct SendPing: public WithConnecitonId { 15 | }; 16 | struct Expire: public WithConnecitonId { 17 | }; 18 | struct Req { 19 | Request req; 20 | }; 21 | struct CloseNoReply: public WithConnecitonId { 22 | }; 23 | struct CloseNoPong: public WithConnecitonId { 24 | }; 25 | struct Connect { 26 | }; 27 | using Event = std::variant; 28 | 29 | private: 30 | using time_point = std::chrono::steady_clock::time_point; 31 | using Ordered = std::multimap; 32 | 33 | public: 34 | using iterator = Ordered::iterator; 35 | // Methods 36 | 37 | template 38 | auto insert(std::chrono::duration<_Rep,_Period> duration, Event e){ 39 | auto expires = std::chrono::steady_clock::now() + duration; 40 | return insert(expires,e); 41 | } 42 | auto insert(std::chrono::steady_clock::time_point expires, Event e){ 43 | return ordered.emplace(expires,e); 44 | } 45 | void cancel(Timer::iterator iter) 46 | { 47 | if (iter != ordered.end()) 48 | ordered.erase(iter); 49 | } 50 | iterator end() { return ordered.end(); } 51 | std::vector pop_expired(); 52 | time_point next(); 53 | 54 | private: 55 | Ordered ordered; 56 | }; 57 | 58 | -------------------------------------------------------------------------------- /src/node/eventloop/types/chainstate.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/header_chain.hpp" 3 | #include "chainserver/state/update/update.hpp" 4 | #include 5 | 6 | class ConsensusSlave { 7 | using Append = chainserver::state_update::Append; 8 | using Fork = chainserver::state_update::Fork; 9 | using RollbackData = chainserver::state_update::RollbackData; 10 | 11 | public: 12 | ConsensusSlave(std::optional, Descriptor descriptor, Headerchain headerchain); 13 | Worksum total_work() const 14 | { 15 | return headerchain->total_work(); 16 | }; 17 | Descriptor descriptor() const { return descriptor_; } 18 | const Headerchain& headers() const 19 | { 20 | return *headerchain; 21 | } 22 | Headerchain::pin_t get_pin() const; 23 | Grid grid() const{ return headerchain->grid();}; 24 | 25 | const SignedSnapshot::Priority get_signed_snapshot_priority() const; 26 | const auto& get_signed_snapshot() const { return signedSnapshot; } 27 | 28 | [[nodiscard]] auto apply(Append&& append) -> std::pair; 29 | [[nodiscard]] auto apply(Fork&& fork) -> ForkMsg; 30 | [[nodiscard]] auto apply(const RollbackData&) -> std::optional; 31 | 32 | private: 33 | std::optional signedSnapshot; 34 | Descriptor descriptor_ {0}; 35 | std::shared_ptr headerchain; 36 | mutable std::shared_ptr> pinGenerator; 37 | }; 38 | -------------------------------------------------------------------------------- /src/node/eventloop/types/conndata.cpp: -------------------------------------------------------------------------------- 1 | #include "conndata.hpp" 2 | #include "asyncio/connection.hpp" 3 | #include "eventloop/sync/sync.hpp" 4 | #include "eventloop/types/peer_requests.hpp" 5 | 6 | using namespace std::chrono_literals; 7 | 8 | ConnectionJob::ConnectionJob(uint64_t conId, Timer& t) 9 | : Timerref(t.insert(30s, Timer::CloseNoReply { conId })) 10 | { 11 | } 12 | 13 | PeerState::PeerState(std::shared_ptr p, HeaderDownload::Downloader& h, BlockDownload::Downloader& b, Timer& t) 14 | : c(std::move(p)) 15 | , job(c->id, t) 16 | , ping(t) 17 | , usage(h, b) 18 | { 19 | } 20 | void Conref::send(Sndbuffer b) 21 | { 22 | if (!(*this)->c->eventloop_erased) { 23 | data.iter->second.c->asyncsend(std::move(b)); 24 | } 25 | }; 26 | 27 | Usage::Usage(HeaderDownload::Downloader& h, BlockDownload::Downloader& b) 28 | : data_headerdownload(h) 29 | , data_blockdownload(b.focus_end()) {}; 30 | -------------------------------------------------------------------------------- /src/node/eventloop/types/conndata_impl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "asyncio/connection.hpp" 3 | #include "conndata.hpp" 4 | 5 | inline bool PeerState::erased() 6 | { 7 | return this->c->eventloop_erased; 8 | } 9 | -------------------------------------------------------------------------------- /src/node/eventloop/types/conref_impl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "asyncio/connection.hpp" 3 | #include "conndata.hpp" 4 | #include "spdlog/fmt/fmt.h" 5 | 6 | inline std::string Conref::str() const 7 | { 8 | return static_cast(*this)->to_string(); 9 | } 10 | -------------------------------------------------------------------------------- /src/node/eventloop/types/probe_data.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/fork_range.hpp" 3 | #include "block/chain/header_chain.hpp" 4 | 5 | struct ProbeData { 6 | ProbeData(ForkRange fr, Headerchain::pin_t headers) 7 | : _forkRange(fr) 8 | , _headers(std::move(headers)) 9 | { 10 | } 11 | void match(NonzeroHeight h, HeaderView hv) 12 | { 13 | _forkRange.match(*_headers, h, hv); 14 | } 15 | auto& fork_range() const { return _forkRange; } 16 | auto& headers() const { return _headers; } 17 | 18 | private: 19 | ForkRange _forkRange; 20 | Headerchain::pin_t _headers; 21 | }; 22 | -------------------------------------------------------------------------------- /src/node/general/address_funds.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/body/account_id.hpp" 3 | #include "crypto/address.hpp" 4 | #include "general/funds.hpp" 5 | struct AddressFunds { 6 | Address address; 7 | Funds funds; 8 | }; 9 | struct AccountFunds { 10 | AccountId accointId; 11 | Funds funds; 12 | }; 13 | -------------------------------------------------------------------------------- /src/node/general/descriptor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "general/with_uint64.hpp" 3 | 4 | struct Descriptor : public IsUint32 { 5 | Descriptor(uint32_t i):IsUint32(i){}; 6 | Descriptor operator+(uint32_t i) const{ 7 | return {value()+i}; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /src/node/general/error_time.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "general/errors.hpp" 3 | #include 4 | 5 | struct ErrorTimestamp { 6 | using steady_clock = std::chrono::steady_clock; 7 | Error error; 8 | uint32_t timestamp; 9 | steady_clock::time_point time_point() const 10 | { 11 | using namespace std::chrono; 12 | return steady_clock::now() + (system_clock::time_point(seconds { timestamp }) - system_clock::now()); 13 | } 14 | }; 15 | 16 | struct ErrorTimepoint { 17 | using steady_clock = std::chrono::steady_clock; 18 | using time_point = steady_clock::time_point; 19 | // data 20 | Error error; 21 | time_point timepoint; 22 | 23 | ErrorTimepoint(Error error, time_point timepoint) 24 | : error(error) 25 | , timepoint(timepoint) 26 | { 27 | } 28 | ErrorTimepoint(const ErrorTimestamp& et) 29 | : ErrorTimepoint(et.error, et.time_point()) 30 | { 31 | } 32 | 33 | static ErrorTimepoint from_duration(Error e, steady_clock::duration duration) 34 | { 35 | return ErrorTimepoint { e, steady_clock::now() + duration }; 36 | } 37 | 38 | operator ErrorTimestamp() const 39 | { 40 | return { error, timestamp() }; 41 | } 42 | 43 | uint32_t timestamp() const 44 | { 45 | using namespace std::chrono; 46 | return duration_cast((system_clock::now() + (timepoint - steady_clock::now())).time_since_epoch()).count(); 47 | } 48 | }; 49 | -------------------------------------------------------------------------------- /src/node/general/filelock/filelock.hpp: -------------------------------------------------------------------------------- 1 | #if defined(_WIN32) 2 | # include "filelock_windows.hpp" 3 | #else 4 | # include "filelock_unix.hpp" 5 | #endif 6 | 7 | -------------------------------------------------------------------------------- /src/node/general/filelock/filelock_unix.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class Filelock { 10 | public: 11 | Filelock(const std::string &path) { 12 | #ifndef __APPLE__ 13 | if (path == "") 14 | return ; 15 | fd = open(path.c_str(), 0); 16 | if (fd < 0) { 17 | throw std::runtime_error("Cannot open file \"" + path + 18 | "\": " + strerror(errno)); 19 | } 20 | if (flock(fd, LOCK_EX | LOCK_NB) < 0) { 21 | throw std::runtime_error("Another instance is accessing the database \"" + path + 22 | "\": " + strerror(errno)); 23 | } 24 | #endif 25 | }; 26 | Filelock(const Filelock &) = delete; 27 | ~Filelock() { 28 | if (fd > 0) { 29 | close(fd); 30 | } 31 | }; 32 | 33 | private: 34 | int fd = -1; 35 | }; 36 | -------------------------------------------------------------------------------- /src/node/general/filelock/filelock_windows.hpp: -------------------------------------------------------------------------------- 1 | // WINDOWS: implement file lock using LockFileEx 2 | // 3 | #include 4 | class Filelock { 5 | public: 6 | Filelock(const std::string &) {} 7 | }; 8 | -------------------------------------------------------------------------------- /src/node/general/page.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "general/errors.hpp" 3 | #include 4 | #include 5 | 6 | struct Page { 7 | Page(uint32_t page) 8 | : p(page) 9 | { 10 | if (p == 0) 11 | throw Error(EINV_PAGE); 12 | }; 13 | uint32_t val() { return p; } 14 | 15 | private: 16 | const uint32_t p; 17 | }; 18 | -------------------------------------------------------------------------------- /src/node/general/tcp_util.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "general/params.hpp" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class Reader; 10 | 11 | struct IPv4 { 12 | IPv4(Reader& r); 13 | IPv4(const sockaddr_in& sin); 14 | IPv4(uint32_t data = 0) 15 | : data(data) 16 | { 17 | } 18 | bool is_valid(bool allowLocalhost = true) const; 19 | auto operator<=>(const IPv4& rhs) const = default; 20 | static std::optional parse(const std::string_view&); 21 | uint32_t data; 22 | std::string to_string() const; 23 | }; 24 | 25 | struct EndpointAddress { 26 | EndpointAddress(Reader& r); 27 | EndpointAddress(IPv4 ipv4, uint16_t port = DEFAULT_ENDPOINT_PORT) 28 | : ipv4(ipv4) 29 | , port(port) 30 | { 31 | } 32 | EndpointAddress(std::string_view); 33 | static EndpointAddress from_sql_id(int64_t id) 34 | { 35 | return EndpointAddress( 36 | IPv4(uint64_t(id & 0x0000FFFFFFFF0000) >> 16), 37 | uint16_t(0x000000000000FFFF & id)); 38 | }; 39 | int64_t to_sql_id() 40 | { 41 | return (int64_t(ipv4.data) << 16) + (int64_t(port)); 42 | }; 43 | auto operator<=>(const EndpointAddress&) const = default; 44 | EndpointAddress() {}; 45 | static std::optional parse(const std::string_view&); 46 | std::string to_string() const; 47 | sockaddr_in sock_addr() const; 48 | 49 | IPv4 ipv4; 50 | uint16_t port = 0; 51 | }; 52 | -------------------------------------------------------------------------------- /src/node/general/util.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | template 6 | std::ostream& operator<<(std::ostream& os, const std::array& data){ 7 | os<<"0x"; 8 | for (size_t i = 0; i < data.size(); ++i) { 9 | char map[]="0123456789abcdef"; 10 | uint8_t d=data[i]; 11 | os<>4]< 5 | 6 | class BatchRegistry; 7 | class HTTPEndpoint; 8 | class PeerServer; 9 | class ChainServer; 10 | class Eventloop; 11 | class Conman; 12 | namespace spdlog { 13 | class logger; 14 | } 15 | 16 | struct Global { 17 | ChainServer* pcs; 18 | PeerServer* pps; 19 | Conman* pcm; 20 | Eventloop* pel; 21 | BatchRegistry* pbr; 22 | HTTPEndpoint* httpEndpoint; 23 | std::shared_ptr connLogger; 24 | std::optional timingLogger; 25 | std::shared_ptr syncdebugLogger; 26 | Config conf; 27 | }; 28 | 29 | const Global& global(); 30 | HTTPEndpoint& http_endpoint(); 31 | inline spdlog::logger& connection_log() { return *global().connLogger; } 32 | inline auto& timing_log() { return global().timingLogger.value(); } 33 | inline spdlog::logger& syncdebug_log() { return *global().syncdebugLogger; } 34 | const Config& config(); 35 | int init_config(int argc, char** argv); 36 | void global_init(BatchRegistry* pbr, PeerServer* pps, ChainServer* pcs, Conman* pcm, Eventloop* pel, HTTPEndpoint* httpEndpoint); 37 | -------------------------------------------------------------------------------- /src/node/mempool/comparators.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/height.hpp" 3 | #include "txmap.hpp" 4 | #include 5 | 6 | namespace mempool { 7 | struct ComparatorPin { 8 | using const_iter_t = Txmap::const_iterator; 9 | using is_transparent = std::true_type; 10 | inline bool operator()(const_iter_t i1, Height h2) const 11 | { 12 | return (i1->first.pinHeight < h2); 13 | } 14 | inline bool operator()(const_iter_t i1, const_iter_t i2) const 15 | { 16 | if (i1->first.pinHeight == i2->first.pinHeight) 17 | return i1->first < i2->first; 18 | return (i1->first.pinHeight < i2->first.pinHeight); 19 | } 20 | }; 21 | struct ComparatorFee { 22 | using const_iter_t = Txmap::const_iterator; 23 | inline bool operator()(const_iter_t i1, const_iter_t i2) const 24 | { 25 | if (i1->second.fee == i2->second.fee) { 26 | return i1->first < i2->first; 27 | }; 28 | return i1->second.fee > i2->second.fee; 29 | } 30 | }; 31 | struct ComparatorHash { 32 | using const_iter_t = Txmap::const_iterator; 33 | using is_transparent = std::true_type; 34 | inline bool operator()(const_iter_t i1, const_iter_t i2) const 35 | { 36 | return i1->second.hash < i2->second.hash; 37 | } 38 | inline bool operator()(const_iter_t i1, const HashView rhs) const 39 | { 40 | return i1->second.hash < rhs; 41 | } 42 | inline bool operator()(HashView lhs, const_iter_t i2) const 43 | { 44 | return lhs < i2->second.hash; 45 | } 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /src/node/mempool/entry.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/body/primitives.hpp" 3 | #include "block/body/transaction_id.hpp" 4 | #include "block/chain/pin.hpp" 5 | #include "crypto/hash.hpp" 6 | #include "general/compact_uint.hpp" 7 | #include "general/funds.hpp" 8 | #include "mempool/order_key.hpp" 9 | class TransferTxExchangeMessageView; 10 | 11 | namespace mempool { 12 | struct EntryValue; 13 | using Entry = std::pair; 14 | struct EntryValue { 15 | EntryValue(NonceReserved noncep2, CompactUInt fee, Address toAddr, Funds amount, RecoverableSignature signature, Hash hash, Height transactionHeight) 16 | : noncep2(noncep2) 17 | , fee(fee) 18 | , toAddr(toAddr) 19 | , amount(amount) 20 | , signature(signature) 21 | , hash(hash) 22 | , transactionHeight(transactionHeight) 23 | { 24 | } 25 | [[nodiscard]] auto spend_assert() const { return Funds::sum_assert(fee.uncompact(), amount); } 26 | NonceReserved noncep2; 27 | CompactUInt fee; 28 | Address toAddr; 29 | Funds amount; 30 | RecoverableSignature signature; 31 | Hash hash; 32 | Height transactionHeight; // when was the account first registered 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /src/node/mempool/log.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "entry.hpp" 3 | #include 4 | 5 | 6 | namespace mempool{ 7 | 8 | struct Put { 9 | Entry entry; 10 | }; 11 | struct Erase { 12 | TransactionId id; 13 | }; 14 | using Action = std::variant; 15 | using Log = std::vector; 16 | } 17 | -------------------------------------------------------------------------------- /src/node/mempool/order_key.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/height.hpp" 3 | #include "block/body/transaction_id.hpp" 4 | namespace mempool{ 5 | struct OrderKey { 6 | Height transactionHeight; 7 | TransactionId txid; 8 | auto operator<=>(const OrderKey& h)const = default; 9 | }; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/node/mempool/subscription.cpp: -------------------------------------------------------------------------------- 1 | #include "subscription.hpp" 2 | #include "eventloop/types/conref_declaration.hpp" 3 | 4 | namespace mempool { 5 | void Subscription::set(std::optional iter, const mempool::OrderKey& k, Conref cr) 6 | { 7 | if (iter) 8 | m.erase(*iter); 9 | m.insert({ k, cr }); 10 | }; 11 | void Subscription::erase(iter_t iter) 12 | { 13 | m.erase(iter); 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /src/node/mempool/subscription.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "subscription_declaration.hpp" 3 | #include "mempool/order_key.hpp" 4 | 5 | struct Conref; 6 | 7 | namespace mempool{ 8 | struct Subscription { 9 | private: 10 | SubscriptionMap m; 11 | public: 12 | using iter_t = SubscriptionIter; 13 | auto& subscriptions() const{return m;} 14 | void set(std::optional iter, const mempool::OrderKey&, Conref); 15 | void erase(iter_t iter); 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /src/node/mempool/subscription_declaration.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | struct Conref; 5 | namespace mempool { 6 | struct OrderKey; 7 | using SubscriptionMap = std::multimap; 8 | using SubscriptionIter = SubscriptionMap::iterator; 9 | } 10 | -------------------------------------------------------------------------------- /src/node/mempool/txmap.cpp: -------------------------------------------------------------------------------- 1 | #include "txmap.hpp" 2 | #include 3 | #include 4 | #include 5 | namespace mempool { 6 | auto Txmap::by_fee_inc(AccountId id) const -> std::vector 7 | { 8 | auto lb { _map.lower_bound(id) }; 9 | auto ub { _map.upper_bound(id) }; 10 | std::vector iterators; 11 | for (auto iter { lb }; iter != ub; ++iter) 12 | iterators.push_back(iter); 13 | std::sort(iterators.begin(), iterators.end(), [](auto iter1, auto iter2) { 14 | return iter1->second.fee < iter2->second.fee; 15 | }); 16 | return iterators; 17 | }; 18 | 19 | bool ByFeeDesc::insert(const_iter_t iter) 20 | { 21 | auto pos = std::lower_bound(data.begin(), data.end(), iter, [](const_iter_t i1, const_iter_t i2) { return i1->second.fee > i2->second.fee; }); 22 | if (pos != data.end() && *pos == iter) 23 | return false; 24 | data.insert(pos, iter); 25 | return true; 26 | } 27 | 28 | size_t ByFeeDesc::erase(const_iter_t iter) 29 | { 30 | return std::erase(data, iter); 31 | } 32 | 33 | auto ByFeeDesc::sample(size_t n, size_t k) const -> std::vector 34 | { 35 | n = std::min(n, data.size()); 36 | k = std::min(n, k); 37 | 38 | std::vector res; 39 | std::sample(data.begin(), data.begin() + n, std::back_inserter(res), k, 40 | std::mt19937 { std::random_device {}() }); 41 | return res; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/node/mempool/txmap.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "block/body/transaction_id.hpp" 4 | #include "entry.hpp" 5 | #include 6 | 7 | class HashView; 8 | class TransferTxExchangeMessageView; 9 | namespace mempool { 10 | class Txmap { 11 | public: 12 | using map_t = std::map>; 13 | using const_iterator = map_t::const_iterator; 14 | using iterator = map_t::iterator; 15 | 16 | private: 17 | map_t _map; 18 | int _cacheValidity { 0 }; // incremented on mempool change 19 | public: 20 | auto cache_validity() const { return _cacheValidity; } 21 | 22 | auto size() const{return _map.size();} 23 | auto& operator()() 24 | { 25 | _cacheValidity += 1; 26 | return _map; 27 | } 28 | auto& operator()() const { return _map; } 29 | [[nodiscard]] std::vector by_fee_inc(AccountId) const; 30 | }; 31 | struct ByFeeDesc { 32 | using const_iter_t = Txmap::const_iterator; 33 | bool insert(const_iter_t iter); 34 | [[nodiscard]] size_t erase(const_iter_t iter); 35 | const_iter_t smallest() const { return data.back(); } 36 | std::vector sample(size_t n, size_t k) const; 37 | size_t size() const { return data.size(); } 38 | auto begin() const { return data.begin(); } 39 | auto end() const { return data.end(); } 40 | 41 | private: 42 | std::vector data; 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /src/node/peerserver/ban_cache.cpp: -------------------------------------------------------------------------------- 1 | #include "ban_cache.hpp" 2 | 3 | void BanCache::clear() 4 | { 5 | map.clear(); 6 | iters = {}; 7 | }; 8 | void BanCache::set(IPv4 ip, const Value& v) 9 | { 10 | auto [it, inserted] = map.try_emplace(ip.data, v); 11 | if (inserted) { // newly inserted 12 | iters.push(it); 13 | if (iters.size() > maxSize) { 14 | map.erase(iters.front()); 15 | iters.pop(); 16 | } 17 | } else { 18 | auto& ban = it->second; 19 | if (ban.timepoint < v.timepoint) 20 | ban = v; 21 | } 22 | } 23 | 24 | auto BanCache::get(IPv4 ip) const -> std::optional 25 | { 26 | auto iter = map.find(ip.data); 27 | if (iter == map.end()) 28 | return std::nullopt; 29 | return iter->second; 30 | }; 31 | -------------------------------------------------------------------------------- /src/node/peerserver/ban_cache.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "general/error_time.hpp" 4 | #include "general/errors.hpp" 5 | #include "general/tcp_util.hpp" 6 | #include 7 | #include 8 | #include 9 | class BanCache { 10 | using Value = ErrorTimepoint; 11 | 12 | using sc = std::chrono::steady_clock; 13 | 14 | public: 15 | BanCache(size_t maxSize = 5000) 16 | : maxSize(maxSize) {}; 17 | void set(IPv4 ip, const Value&); 18 | std::optional get(IPv4 ip) const; 19 | void clear(); 20 | 21 | private: 22 | using map_t = std::map; 23 | map_t map; 24 | std::queue iters; 25 | const size_t maxSize; 26 | }; 27 | -------------------------------------------------------------------------------- /src/shared/meson.build: -------------------------------------------------------------------------------- 1 | 2 | include_wh=[include_trezorcrypto,include_directories('./src')] 3 | src_wh=[ 4 | src_trezorcrypto, 5 | files( 6 | [ 7 | './platformassert.cpp', 8 | './src/block/body/container.cpp', 9 | './src/block/body/nonce.cpp', 10 | './src/block/body/transaction_id.cpp', 11 | './src/block/body/view.cpp', 12 | './src/block/chain/height.cpp', 13 | './src/block/chain/worksum.cpp', 14 | './src/block/header/generator.cpp', 15 | './src/block/header/header.cpp', 16 | './src/block/header/view.cpp', 17 | './src/block/header/pow_version.cpp', 18 | './src/communication/create_payment.cpp', 19 | './src/crypto/address.cpp', 20 | './src/crypto/crypto.cpp', 21 | './src/crypto/hash.cpp', 22 | './src/crypto/verushash/verus_clhash_port.cpp', 23 | './src/crypto/verushash/verushash.cpp', 24 | './src/general/compact_uint.cpp', 25 | './src/general/errors.cpp', 26 | './src/general/is_testnet.cpp', 27 | './src/general/funds.cpp', 28 | './src/general/hex.cpp', 29 | './src/general/with_uint64.cpp', 30 | ] 31 | )] 32 | 33 | 34 | versions = meson.project_version().split('.') 35 | conf_version = configuration_data() 36 | conf_version.set('VERSION_MAJOR', versions.get(0)) 37 | conf_version.set('VERSION_MINOR', versions.get(1)) 38 | conf_version.set('VERSION_PATCH', versions.get(2)) 39 | configure_file(input : './src/version.hpp.in', 40 | output : 'version.hpp', 41 | configuration : conf_version) 42 | 43 | 44 | vcs_dep=vcs_tag(command : 45 | ['git', 'rev-parse', '--short', 'HEAD'], 46 | input:'./src/commit_info.hpp.in', 47 | output:'commit_info.hpp', 48 | replace_string:'@GIT_COMMIT_INFO@') 49 | -------------------------------------------------------------------------------- /src/shared/platformassert.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | static_assert(CHAR_BIT == 8); 4 | static_assert(sizeof(uint32_t) == 4); 5 | -------------------------------------------------------------------------------- /src/shared/src/block/block.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "block/body/view.hpp" 4 | #include "block/header/header.hpp" 5 | #include "block/chain/height.hpp" 6 | #include "block/body/container.hpp" 7 | #include 8 | 9 | struct Block { 10 | NonzeroHeight height; 11 | Header header; 12 | BodyContainer body; 13 | BodyView body_view() const {return body.view(height);} 14 | bool operator==(const Block&)const=default; 15 | operator bool() { return body.size() > 0; } 16 | }; 17 | -------------------------------------------------------------------------------- /src/shared/src/block/body/account_id.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "general/with_uint64.hpp" 3 | #include 4 | #include 5 | #include 6 | 7 | class AccountId : public IsUint64 {// NOTE: >=0 is important for AccountHeights 8 | public: 9 | using IsUint64::IsUint64; 10 | bool operator==(const AccountId&) const = default; 11 | size_t operator-(AccountId a) 12 | { 13 | return val - a.val; 14 | } 15 | AccountId operator-(size_t i) const{ 16 | return AccountId(val - i); 17 | } 18 | AccountId operator+(size_t i) const 19 | { 20 | return AccountId(val + i); 21 | } 22 | AccountId operator++(int) 23 | { 24 | return AccountId(val++); 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /src/shared/src/block/body/container.cpp: -------------------------------------------------------------------------------- 1 | #include "container.hpp" 2 | #include "block/body/view.hpp" 3 | #include "general/errors.hpp" 4 | #include "general/params.hpp" 5 | #include "general/reader.hpp" 6 | #include "general/writer.hpp" 7 | 8 | BodyContainer::BodyContainer(std::span s) 9 | : bytes(s.begin(), s.end()) 10 | { 11 | if (s.size() > MAXBLOCKSIZE) { 12 | throw Error(EBLOCKSIZE); 13 | } 14 | } 15 | 16 | BodyView BodyContainer::view(NonzeroHeight h) const 17 | { 18 | return { bytes, h }; 19 | } 20 | 21 | BodyContainer::BodyContainer(Reader& r) 22 | { 23 | auto s { r.span() }; 24 | bytes.assign(s.begin(), s.end()); 25 | } 26 | 27 | Writer& operator<<(Writer& r, const BodyContainer& b) 28 | { 29 | return r << (uint32_t)b.bytes.size() << Range(b.bytes); 30 | } 31 | -------------------------------------------------------------------------------- /src/shared/src/block/body/container.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/chain/height.hpp" 3 | #include 4 | #include 5 | #include 6 | 7 | class Reader; 8 | class Writer; 9 | class BodyView; 10 | class BodyContainer { 11 | public: 12 | BodyContainer(std::span); 13 | BodyContainer(std::vector bytes) 14 | : bytes(std::move(bytes)) 15 | { 16 | } 17 | BodyContainer(Reader& r); 18 | friend Writer& operator<<(Writer&, const BodyContainer&); 19 | size_t serialized_size() const { return size() + 4; } 20 | size_t size() const { return bytes.size(); } 21 | auto& data() const { return bytes; } 22 | auto& data() { return bytes; } 23 | BodyView view(NonzeroHeight h) const; 24 | bool operator==(const BodyContainer&) const = default; 25 | 26 | private: 27 | std::vector bytes; 28 | }; 29 | -------------------------------------------------------------------------------- /src/shared/src/block/body/nonce.cpp: -------------------------------------------------------------------------------- 1 | #include "nonce.hpp" 2 | #include "block/chain/height.hpp" 3 | #include "crypto/hasher_sha256.hpp" 4 | #include "general/reader.hpp" 5 | #include 6 | #include 7 | #include 8 | NonceId NonceId::random() 9 | { 10 | std::array rand; 11 | std::independent_bits_engine e; 12 | std::generate(std::begin(rand), std::end(rand), std::ref(e)); 13 | uint32_t val; 14 | memcpy(&val, rand.data(), rand.size()); 15 | return NonceId(val); 16 | }; 17 | 18 | PinNonce::PinNonce(ReaderCheck r) 19 | : id(r.r) 20 | , relativePin(r.r.uint8()) 21 | , reserved(r.r) 22 | { 23 | r.assert_read_bytes(); 24 | } 25 | 26 | PinNonce::PinNonce(Reader& r) 27 | : PinNonce(ReaderCheck(r)) {}; 28 | 29 | PinHeight PinNonce::pin_height(PinFloor pf) const 30 | { 31 | Height h(pf - std::min(pin_offset(), pf.value())); 32 | assert(h.is_pin_height()); 33 | return PinHeight(h); 34 | } 35 | 36 | std::optional PinNonce::make_pin_nonce(NonceId nid, NonzeroHeight height, PinHeight pinHeight) 37 | { 38 | PinFloor ph { PrevHeight(height) }; 39 | if (ph < pinHeight) 40 | return {}; 41 | uint64_t index = ((ph - pinHeight) >> 5); 42 | if (index > 255u) 43 | return {}; 44 | return PinNonce(nid, (uint8_t)index); 45 | } 46 | 47 | // PinNonce 48 | 49 | Writer& operator<<(Writer& w, const PinNonce& n) 50 | { 51 | return w << n.id << n.relativePin << n.reserved; 52 | }; 53 | -------------------------------------------------------------------------------- /src/shared/src/block/body/transaction_id.cpp: -------------------------------------------------------------------------------- 1 | #include "transaction_id.hpp" 2 | #include "block/chain/height.hpp" 3 | #include "general/writer.hpp" 4 | 5 | Writer& operator<<(Writer& w, const TransactionId& id) 6 | { 7 | return w 8 | << id.accountId 9 | << id.pinHeight 10 | << id.nonceId; 11 | }; 12 | TransactionId::TransactionId(Reader& r) 13 | : accountId(r.uint64()) 14 | , pinHeight(Height(r.uint32())) 15 | , nonceId(r.uint32()) {}; 16 | -------------------------------------------------------------------------------- /src/shared/src/block/body/transaction_id.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/body/account_id.hpp" 3 | #include "block/body/nonce.hpp" 4 | #include "block/chain/height.hpp" 5 | #include "general/compact_uint.hpp" 6 | #include "general/reader.hpp" 7 | #include "general/view.hpp" 8 | #include 9 | #include 10 | class Height; 11 | class PinHeight; 12 | 13 | struct TransactionId { 14 | TransactionId(AccountId accountId, PinHeight pinHeight, NonceId nonceId) 15 | : accountId(accountId) 16 | , pinHeight(pinHeight) 17 | , nonceId(nonceId) {}; 18 | constexpr static size_t bytesize = 16; 19 | 20 | TransactionId(Reader& r); 21 | friend Writer& operator<<(Writer&, const TransactionId&); 22 | auto operator<=>(const TransactionId& rhs) const = default; 23 | auto operator<=>(AccountId aid) const { return accountId <=> aid; } 24 | 25 | AccountId accountId; 26 | PinHeight pinHeight; 27 | NonceId nonceId; 28 | }; 29 | 30 | struct TxidWithFee { 31 | TransactionId txid; 32 | CompactUInt fee; 33 | }; 34 | -------------------------------------------------------------------------------- /src/shared/src/block/chain/height.cpp: -------------------------------------------------------------------------------- 1 | #include "height.hpp" 2 | #include "general/errors.hpp" 3 | Writer& operator<<(Writer& w, Height h) 4 | { 5 | return w << h.value(); 6 | }; 7 | PinHeight::PinHeight(const Height h) 8 | : Height(h) 9 | { 10 | if (!h.is_pin_height()) 11 | throw Error(ENOPINHEIGHT); 12 | }; 13 | 14 | NonzeroHeight::NonzeroHeight(Reader& r) 15 | : IsUint32(Height(r).nonzero_throw(EBADHEIGHT).value()) {}; 16 | -------------------------------------------------------------------------------- /src/shared/src/block/header/generator.cpp: -------------------------------------------------------------------------------- 1 | #include "generator.hpp" 2 | #include "block/body/view.hpp" 3 | #include "block/header/view_inline.hpp" 4 | #include "general/is_testnet.hpp" 5 | namespace { 6 | uint32_t header_version(NonzeroHeight h) 7 | { 8 | if (is_testnet()) { 9 | if (h.value() <= 2) 10 | return 2; 11 | return 3; 12 | } else { 13 | if (h.value() <= JANUSV8BLOCKV3START) 14 | return 2; 15 | return 3; 16 | } 17 | } 18 | } 19 | HeaderGenerator::HeaderGenerator(std::array prevhash, 20 | const BodyView& bv, Target target, 21 | uint32_t timestamp, NonzeroHeight height) 22 | : version(target.is_janushash() ? header_version(height) : 1) 23 | , prevhash(prevhash) 24 | , merkleroot(bv.merkle_root(height)) 25 | , timestamp(timestamp) 26 | , target(target) 27 | , nonce(0u) { 28 | 29 | }; 30 | [[nodiscard]] Header HeaderGenerator::serialize(uint32_t nonce) const 31 | { 32 | Header out; 33 | uint32_t nversion = hton32(version); 34 | memcpy(out.data() + HeaderView::offset_version, &nversion, 4); 35 | memcpy(out.data() + HeaderView::offset_prevhash, prevhash.data(), 32); 36 | memcpy(out.data() + HeaderView::offset_merkleroot, merkleroot.data(), 32); 37 | uint32_t ntimestamp = hton32(timestamp); 38 | memcpy(out.data() + HeaderView::offset_timestamp, &ntimestamp, 4); 39 | uint32_t rawtarget { target.binary() }; 40 | memcpy(out.data() + HeaderView::offset_target, &rawtarget, 4); 41 | memcpy(out.data() + HeaderView::offset_nonce, &nonce, 4); 42 | return out; 43 | } 44 | -------------------------------------------------------------------------------- /src/shared/src/block/header/generator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "block/header/difficulty.hpp" 4 | #include "block/header/header.hpp" 5 | #include "general/now.hpp" 6 | #include 7 | #include 8 | class BodyView; 9 | class HeaderGenerator { 10 | public: 11 | HeaderGenerator(std::array prevhash, const BodyView& bv, 12 | Target target, 13 | uint32_t timestamp, NonzeroHeight height); 14 | // member elements 15 | int32_t version = 1; // 4 bytes 16 | std::array prevhash; // 32 bytes 17 | std::array merkleroot; // 32 bytes 18 | uint32_t timestamp; // 4 bytes 19 | Target target; // 4 bytes 20 | uint32_t nonce; // 4 bytes 21 | 22 | // 23 | Header serialize(uint32_t nonce) const; 24 | }; 25 | -------------------------------------------------------------------------------- /src/shared/src/block/header/hash_exponential_request.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warthog-network/Warthog/868a69355981e3ab3a55ffa692cd8a8aa229e592/src/shared/src/block/header/hash_exponential_request.cpp -------------------------------------------------------------------------------- /src/shared/src/block/header/hash_exponential_request.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "crypto/hash.hpp" 5 | class HashExponentialDigest { 6 | friend struct Target; 7 | 8 | public: 9 | uint32_t negExp{0}; // negative exponent of 2 10 | uint32_t data{0x80000000}; 11 | 12 | HashExponentialDigest(){}; 13 | HashExponentialDigest& digest(const Hash &); 14 | }; 15 | 16 | inline HashExponentialDigest& HashExponentialDigest::digest(const Hash &h) { 17 | negExp += 1; // we are considering hashes as number in (0,1), padded with 18 | // infinite amount of trailing 1's 19 | size_t i = 0; 20 | for (; i < h.size(); ++i) { 21 | if (h[i] != 0) 22 | break; 23 | negExp += 8; 24 | } 25 | uint64_t tmpData{0}; 26 | for (size_t j = 0;; ++j) { 27 | if (i < h.size()) 28 | tmpData |= h[i++]; 29 | else 30 | tmpData |= 0xFFu; // "infinite amount of trailing 1's" 31 | 32 | if (j >= 3) 33 | break; 34 | tmpData <<= 8; 35 | } 36 | size_t shifts = 0; 37 | while ((tmpData & 0x80000000ul) == 0) { 38 | shifts += 1; 39 | negExp += 1; 40 | tmpData <<= 1; 41 | } 42 | assert(shifts < 8); 43 | assert((tmpData >> 32) == 0); 44 | tmpData *= uint64_t(data); 45 | if (tmpData >= uint64_t(1) << 63) { 46 | tmpData >>= 1; 47 | negExp -= 1; 48 | } 49 | tmpData >>= 31; 50 | assert(tmpData < uint64_t(1) << 32); 51 | assert(tmpData >= uint64_t(1) << 31); 52 | data = tmpData; 53 | return *this; 54 | }; 55 | -------------------------------------------------------------------------------- /src/shared/src/block/header/header.cpp: -------------------------------------------------------------------------------- 1 | #include "header.hpp" 2 | #include "general/hex.hpp" 3 | 4 | Header::Header(const char* v) 5 | : Header(hex_to_arr<80>(v)) 6 | { 7 | } 8 | 9 | 10 | void Header::set_timestamp(std::array arr) 11 | { 12 | std::copy(arr.begin(), arr.end(), begin() + HeaderView::offset_timestamp); 13 | } 14 | void Header::set_nonce(std::array arr) 15 | { 16 | std::copy(arr.begin(), arr.end(), begin() + HeaderView::offset_nonce); 17 | } 18 | -------------------------------------------------------------------------------- /src/shared/src/block/header/header.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/header/view.hpp" 3 | #include 4 | #include 5 | 6 | class Height; 7 | class POWVersion; 8 | constexpr size_t HEADERBYTELENGTH = 80; 9 | class Header : public std::array { 10 | public: 11 | using array::array; 12 | using array::operator=; 13 | using array::data; 14 | using array::size; 15 | Header() {}; 16 | Header(const char*); 17 | Header(const std::array& arr) 18 | : array(arr) {}; 19 | Header(HeaderView hv) 20 | { 21 | memcpy(data(), hv.data(), 80); 22 | } 23 | Header& operator=(HeaderView hv) { return *this = Header(hv); } 24 | operator HeaderView() const { return HeaderView(data()); } 25 | Target target(NonzeroHeight, bool testnet) const; 26 | inline bool validPOW(const Hash&, POWVersion) const; 27 | inline HashView prevhash() const; 28 | inline HashView merkleroot() const; 29 | void set_merkleroot(std::array); 30 | inline uint32_t timestamp() const; 31 | void set_timestamp(std::array); 32 | inline uint32_t version() const; 33 | inline TargetV1 target_v1() const; 34 | inline TargetV2 target_v2() const; 35 | inline double janus_number() const; 36 | inline uint32_t nonce() const; 37 | void set_nonce(std::array); 38 | inline Hash hash() const; 39 | constexpr static size_t byte_size() 40 | { 41 | return HEADERBYTELENGTH; 42 | } 43 | }; 44 | -------------------------------------------------------------------------------- /src/shared/src/block/header/header_impl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block/header/header.hpp" 3 | #include "block/header/pow_version.hpp" 4 | #include "block/header/view_inline.hpp" 5 | 6 | inline Target Header::target(NonzeroHeight h, bool testnet) const 7 | { 8 | return static_cast(*this).target(h, testnet); 9 | } 10 | inline bool Header::validPOW(const Hash& h, POWVersion v) const 11 | { 12 | return static_cast(*this).validPOW(h, v); 13 | } 14 | inline HashView Header::prevhash() const 15 | { 16 | return static_cast(*this).prevhash(); 17 | } 18 | inline HashView Header::merkleroot() const 19 | { 20 | return static_cast(*this).merkleroot(); 21 | } 22 | inline void Header::set_merkleroot(std::array a) 23 | { 24 | memcpy(data() + HeaderView::offset_merkleroot, a.data(), 32); 25 | } 26 | inline uint32_t Header::version() const 27 | { 28 | return static_cast(*this).version(); 29 | } 30 | inline uint32_t Header::timestamp() const 31 | { 32 | return static_cast(*this).timestamp(); 33 | } 34 | inline TargetV1 Header::target_v1() const 35 | { 36 | return static_cast(*this).target_v1(); 37 | } 38 | inline TargetV2 Header::target_v2() const 39 | { 40 | return static_cast(*this).target_v2(); 41 | } 42 | inline double Header::janus_number() const 43 | { 44 | return static_cast(*this).janus_number(); 45 | } 46 | inline uint32_t Header::nonce() const 47 | { 48 | return static_cast(*this).nonce(); 49 | } 50 | inline Hash Header::hash() const 51 | { 52 | return static_cast(*this).hash(); 53 | } 54 | -------------------------------------------------------------------------------- /src/shared/src/block/header/pow_version.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "block/chain/height.hpp" 4 | #include 5 | #include 6 | class POWVersion { 7 | struct NonV2_2 { 8 | static constexpr bool verusv2_2 = false; 9 | }; 10 | struct V2_2 { 11 | static constexpr bool verusv2_2 = true; 12 | }; 13 | 14 | public: 15 | struct Original : public NonV2_2 { }; 16 | struct Janus1 : public NonV2_2 { }; 17 | struct Janus2 : public NonV2_2 { }; 18 | struct Janus3 : public NonV2_2 { }; 19 | struct Janus4 : public NonV2_2 { }; 20 | struct Janus5 : public NonV2_2 { }; 21 | struct Janus6 : public NonV2_2 { }; 22 | struct Janus7 : public NonV2_2 { }; 23 | struct Janus8 : public V2_2 { }; 24 | [[nodiscard]] static std::optional from_params( 25 | NonzeroHeight height, uint32_t version, bool testnet); 26 | auto visit(const auto& lambda) const 27 | { 28 | return std::visit(lambda, data); 29 | } 30 | [[nodiscard]] bool uses_verus_2_2() const 31 | { 32 | return visit([](auto& e) { return e.verusv2_2; }); 33 | } 34 | 35 | private: 36 | using variant_t = std::variant; 37 | POWVersion(variant_t data) 38 | : data(data) 39 | { 40 | } 41 | 42 | variant_t data; 43 | }; 44 | -------------------------------------------------------------------------------- /src/shared/src/commit_info.hpp.in: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define GIT_COMMIT_INFO "@GIT_COMMIT_INFO@" 3 | -------------------------------------------------------------------------------- /src/shared/src/communication/mining_task.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "block/block.hpp" 4 | 5 | struct ChainMiningTask { 6 | Block block; 7 | }; 8 | -------------------------------------------------------------------------------- /src/shared/src/communication/unonce.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | inline uint64_t to_unonce(int64_t nonce){ 6 | return nonce;// let the C++ standard do the correct conversion 7 | } 8 | 9 | inline int64_t to_nonce(uint64_t unonce){ 10 | constexpr uint64_t threshold=std::numeric_limits::max(); 11 | if (unonce > threshold) return -(int64_t)((-unonce)-1)-1; 12 | return unonce; 13 | } 14 | -------------------------------------------------------------------------------- /src/shared/src/crypto/address.cpp: -------------------------------------------------------------------------------- 1 | #include "address.hpp" 2 | #include "crypto/hasher_sha256.hpp" 3 | #include "general/hex.hpp" 4 | 5 | std::array AddressView::serialize() const 6 | { 7 | std::array ret; 8 | memcpy(ret.data(), data(), size()); 9 | Hash h { hashSHA256(data(), size()) }; 10 | memcpy(ret.data() + 20, h.data(), 4); 11 | return ret; 12 | }; 13 | 14 | std::string AddressView::to_string() const 15 | { 16 | return serialize_hex(serialize()); 17 | }; 18 | 19 | Address::Address(const std::string_view address) 20 | { 21 | using namespace std::literals; 22 | std::array bytes; 23 | if (!parse_hex(address, bytes)) 24 | throw Error(EBADADDRESS); 25 | 26 | auto hash = hashSHA256(bytes.data(), 20); 27 | if (memcmp(bytes.data() + 20, hash.data(), 4) != 0) { 28 | throw Error(EBADADDRESS); 29 | } 30 | memcpy(data(), bytes.data(), 20); 31 | } 32 | 33 | Address& Address::operator=(const AddressView rhs) 34 | { 35 | memcpy(data(), rhs.data(), 20); 36 | return *this; 37 | }; 38 | -------------------------------------------------------------------------------- /src/shared/src/crypto/hash.cpp: -------------------------------------------------------------------------------- 1 | #include "hash.hpp" 2 | #include "hasher_sha256.hpp" 3 | 4 | Hash Hash::genesis(){ 5 | return hashSHA256(reinterpret_cast(GENESISSEED), 6 | strlen(GENESISSEED)); 7 | }; 8 | -------------------------------------------------------------------------------- /src/shared/src/crypto/hash.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "general/params.hpp" 3 | #include "general/view.hpp" 4 | #include 5 | #include 6 | 7 | class Hash; 8 | class HashView : public View<32> { 9 | public: 10 | inline HashView(const uint8_t* pos) 11 | : View<32>(pos) {}; 12 | inline bool operator==(HashView hv) const 13 | { 14 | return View::operator==(hv); 15 | }; 16 | }; 17 | 18 | class Hash : public std::array { 19 | public: 20 | Hash() = default; 21 | Hash(const std::array& other) 22 | : array(other) 23 | { 24 | } 25 | Hash(const Hash&) = default; 26 | Hash(Hash&&) = default; 27 | operator HashView() const 28 | { 29 | return HashView(data()); 30 | } 31 | Hash(HashView hv) 32 | { 33 | memcpy(data(), hv.data(), 32); 34 | } 35 | Hash& operator=(const Hash&) = default; 36 | bool operator==(const Hash&) const = default; 37 | bool operator!=(const Hash&) const = default; 38 | static Hash genesis(); 39 | }; 40 | 41 | inline bool operator==(const Hash& h, const HashView& hv) 42 | { 43 | return (HashView(h) == hv); 44 | }; 45 | inline bool operator==(const HashView& hv, const Hash& h) 46 | { 47 | return (HashView(h) == hv); 48 | }; 49 | 50 | class TxHash : public Hash { 51 | public: 52 | explicit TxHash(Hash h) 53 | : Hash(h) 54 | { 55 | } 56 | }; 57 | -------------------------------------------------------------------------------- /src/shared/src/crypto/verushash/README.md: -------------------------------------------------------------------------------- 1 | This directory contains heaviliy modified code from the VerusCoin project. 2 | -------------------------------------------------------------------------------- /src/shared/src/crypto/verushash/u128.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #if defined(__arm__) || defined(__aarch64__) 3 | #include "crypto/sse2neon.h" 4 | #else 5 | #include "immintrin.h" 6 | #endif 7 | #ifdef _WIN32 8 | typedef unsigned long long u64; 9 | #else 10 | typedef unsigned long u64; 11 | #endif 12 | typedef __m128i u128; 13 | -------------------------------------------------------------------------------- /src/shared/src/crypto/verushash/verus_clhash_port.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "crypto/hash.hpp" 3 | #include "u128.h" 4 | #include "verus_constants.hpp" 5 | #include "verushash.hpp" 6 | #include 7 | #include 8 | #include 9 | #include 10 | uint64_t verusclhash_sv2_1_port(void *random, const unsigned char buf[64], 11 | uint64_t keyMask, __m128i **pMoveScratch); 12 | 13 | uint64_t verusclhash_sv2_2_port(void *random, const unsigned char buf[64], 14 | uint64_t keyMask, __m128i **pMoveScratch); 15 | 16 | void haraka512_port(unsigned char *out, const unsigned char *in); 17 | 18 | /* Implementation of Haraka-512 */ 19 | void haraka512_port_keyed(unsigned char *out, const unsigned char *in, 20 | const u128 *rc); 21 | 22 | /* Implementation of Haraka-256 */ 23 | void haraka256_port(unsigned char *out, const unsigned char *in); 24 | 25 | -------------------------------------------------------------------------------- /src/shared/src/crypto/verushash/verus_constants.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | namespace Verus{ 4 | 5 | constexpr uint64_t keymask(uint64_t keysize) { 6 | int i = 0; 7 | while (keysize >>= 1) { 8 | i++; 9 | } 10 | return i ? (((uint64_t)1) << i) - 1 : 0; 11 | } 12 | static constexpr uint64_t keysize = 1024 * 8 + (40 * 16); 13 | static constexpr uint64_t keySizeInBytes = (keysize >> 5) << 5; 14 | static constexpr uint64_t keyMask{keymask(keysize)}; 15 | static constexpr uint64_t keyMask16{keyMask >> 4}; 16 | static constexpr uint64_t keyRefreshsize{keyMask + 1}; 17 | static constexpr uint64_t key256blocks{keySizeInBytes >> 5}; 18 | static constexpr uint64_t key256extra{keySizeInBytes & 0x1f}; 19 | } 20 | -------------------------------------------------------------------------------- /src/shared/src/general/compact_uint.cpp: -------------------------------------------------------------------------------- 1 | #include "compact_uint.hpp" 2 | #include "general/writer.hpp" 3 | Writer& operator<<(Writer& w, CompactUInt cf){ 4 | return w< threshold) { 13 | e += 1; 14 | e8 >>= 1; 15 | } 16 | while (e8 < uint64_t(0x0400u)) { 17 | e -= 1; 18 | e8 <<= 1; 19 | } 20 | return (e << 10) | (uint16_t(e8) & uint16_t(0x03FF)); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/shared/src/general/errors.cpp: -------------------------------------------------------------------------------- 1 | #include "errors.hpp" 2 | #include "block/chain/height.hpp" 3 | #include 4 | 5 | namespace errors { 6 | #define ERR_NAME_GEN(code, name, _) \ 7 | case code: \ 8 | return #name; 9 | const char* err_name(int err) 10 | { 11 | 12 | switch (err) { 13 | ADDITIONAL_ERRNO_MAP(ERR_NAME_GEN) 14 | } 15 | return uv_err_name(err); 16 | } 17 | #undef ERR_NAME_GEN 18 | 19 | #define STRERROR_GEN(code, name, str) \ 20 | case code: \ 21 | return str; 22 | const char* strerror(int err) 23 | { 24 | switch (err) { 25 | ADDITIONAL_ERRNO_MAP(STRERROR_GEN) 26 | } 27 | return uv_strerror(err); 28 | } 29 | #undef STRERROR_GEN 30 | 31 | } // namespace errors 32 | 33 | ChainError::ChainError(Error e, NonzeroHeight height) 34 | : Error(e) 35 | , h(height.value()) {}; 36 | 37 | NonzeroHeight ChainError::height() const 38 | { 39 | return NonzeroHeight(h); 40 | }; 41 | -------------------------------------------------------------------------------- /src/shared/src/general/is_testnet.cpp: -------------------------------------------------------------------------------- 1 | #include"is_testnet.hpp" 2 | namespace{ 3 | bool isTestnet{false}; 4 | } 5 | bool is_testnet(){ 6 | return isTestnet; 7 | }; 8 | void enable_testnet(){ 9 | isTestnet=true; 10 | }; 11 | -------------------------------------------------------------------------------- /src/shared/src/general/is_testnet.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | bool is_testnet(); 3 | void enable_testnet(); 4 | -------------------------------------------------------------------------------- /src/shared/src/general/now.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | inline uint32_t now_timestamp() 5 | { 6 | using namespace std::chrono; 7 | return std::chrono::seconds(std::time(NULL)).count(); 8 | } 9 | -------------------------------------------------------------------------------- /src/shared/src/general/reader_declaration.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | class Reader; 4 | template 5 | class ReaderCheck; 6 | -------------------------------------------------------------------------------- /src/shared/src/general/view.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | template 9 | struct View { 10 | static constexpr size_t size() { return N; } 11 | bool is_null() const { return pos == nullptr; } 12 | const uint8_t* data() const { return pos; } 13 | operator std::array() 14 | { 15 | std::array res; 16 | std::copy(pos, pos + N, res.begin()); 17 | return res; 18 | } 19 | auto operator<=>(const View& v) const 20 | { 21 | assert(!is_null() && !v.is_null()); 22 | auto i = memcmp(pos, v.pos, N); 23 | if (i < 0) 24 | return std::strong_ordering::less; 25 | else if (i > 0) 26 | return std::strong_ordering::greater; 27 | else 28 | return std::strong_ordering::equal; 29 | } 30 | bool operator==(const View& v) const 31 | { 32 | return operator<=>(v) == 0; 33 | } 34 | View(const std::array& a) 35 | : View(a.data()) 36 | { 37 | } 38 | explicit View(const uint8_t* pos) 39 | : pos(pos) 40 | { 41 | } 42 | 43 | protected: 44 | const uint8_t* pos; 45 | }; 46 | -------------------------------------------------------------------------------- /src/shared/src/general/with_uint64.cpp: -------------------------------------------------------------------------------- 1 | #include "with_uint64.hpp" 2 | #include "nlohmann/json.hpp" 3 | #include "reader.hpp" 4 | #include 5 | 6 | IsUint32::IsUint32(Reader& r) 7 | : val(r.uint32()) {}; 8 | // IsUint32::IsUint32(int64_t w) 9 | // : val(w) 10 | // { 11 | // assert(w >= 0); 12 | // assert(w <= std::numeric_limits::max()); 13 | // }; 14 | // IsUint32::IsUint32(size_t w) 15 | // : val(w) 16 | // { 17 | // assert(w <= std::numeric_limits::max()); 18 | // }; 19 | 20 | IsUint64::IsUint64(Reader& r) 21 | : val(r.uint64()) {}; 22 | 23 | IsUint32::operator nlohmann::json() const 24 | { 25 | return nlohmann::json(val); 26 | }; 27 | IsUint64::operator nlohmann::json() const 28 | { 29 | return nlohmann::json(val); 30 | }; 31 | -------------------------------------------------------------------------------- /src/test/meson.build: -------------------------------------------------------------------------------- 1 | e = executable('custom_float', vcs_dep, ['./custom_float.cpp'], 2 | include_directories:['./' ,include_thirdparty] 3 | ) 4 | test('Custom float operations',e) 5 | 6 | -------------------------------------------------------------------------------- /src/wallet/api_call.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "crypto/hash.hpp" 3 | #include "general/funds.hpp" 4 | #include 5 | #include 6 | #include 7 | #include 8 | struct PinHeight; 9 | class Endpoint { 10 | std::string host; 11 | uint16_t port; 12 | 13 | public: 14 | struct Error{ 15 | int code; 16 | std::string message; 17 | }; 18 | Endpoint(std::string host, uint16_t port) 19 | : host(host) 20 | , port(port) {}; 21 | Funds get_balance(const std::string& account); 22 | std::variant send_transaction(const std::string& txjson); 23 | std::pair get_pin(); 24 | private: 25 | bool http_get(const std::string& get, std::string& out); 26 | int http_post(const std::string& path, const std::vector& postdata, std::string& out); 27 | std::runtime_error failed_msg(); 28 | }; 29 | -------------------------------------------------------------------------------- /src/wallet/cmdline/cmdline.cpp: -------------------------------------------------------------------------------- 1 | #include"version.hpp" 2 | #include"cmdline.c" 3 | -------------------------------------------------------------------------------- /src/wallet/cmdline/cmdoptions.ggo: -------------------------------------------------------------------------------- 1 | package "wart-wallet" 2 | purpose "The reference implementation wallet of the Warthog Network. 3 | 4 | 5 | By Pumbaa, Timon & Rafiki" 6 | 7 | 8 | # Options 9 | option "create" c "Create new wallet" optional 10 | option "restore" r "Restore wallet from private key" optional string typestr="PRIVATEKEY" 11 | option "print-only" - "Do not save generated/restored wallet to disk but print result instead" optional 12 | option "file" f "Specify wallet file" string typestr="FILENAME" default="wallet.json" optional 13 | option "address" a "Print wallet address" optional 14 | option "balance" b "Print wallet balance" optional 15 | option "send" s "Create send transaction" optional 16 | option "to" - "Specify transaction receipent address" string optional 17 | option "amount" - "Specify transaction amount" string optional 18 | option "fee" - "Specify transaction fee" string optional 19 | option "nonce" - "Specify transaction nonce" longlong optional 20 | option "host" h "Host (RPC-Node)" string default="localhost" optional 21 | option "port" p "Port (RPC-Node)" int default="3000" optional 22 | -------------------------------------------------------------------------------- /src/wallet/meson.build: -------------------------------------------------------------------------------- 1 | executable('wart-wallet', vcs_dep, 2 | [ 3 | './api_call.cpp', 4 | './cmdline/cmdline.cpp', 5 | './main.cpp', 6 | src_wh, 7 | src_spdlog 8 | ], 9 | include_directories : [include_secp256k1,include_wh,include_json, include_httplib, include_spdlog], 10 | link_with: libsecp256k1, 11 | dependencies: [libuv_dep,], 12 | install : true) 13 | -------------------------------------------------------------------------------- /subprojects/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !*.wrap 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /subprojects/libuv.wrap: -------------------------------------------------------------------------------- 1 | [wrap-file] 2 | directory = libuv-v1.46.0 3 | source_url = https://dist.libuv.org/dist/v1.46.0/libuv-v1.46.0.tar.gz 4 | source_filename = libuv-v1.46.0.tar.gz 5 | source_hash = 111f83958b9fdc65f1489195d25f342b9f7a3e683140c60e62c00fbaccddddce 6 | patch_filename = libuv_1.46.0-1_patch.zip 7 | patch_url = https://wrapdb.mesonbuild.com/v2/libuv_1.46.0-1/get_patch 8 | patch_hash = 41b1834129f13efcb4a94a137335eb85fe0662509010c157617954d2feb20ac8 9 | source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/libuv_1.46.0-1/libuv-v1.46.0.tar.gz 10 | wrapdb_version = 1.46.0-1 11 | 12 | [provide] 13 | libuv = libuv_dep 14 | -------------------------------------------------------------------------------- /subprojects/sqlite3.wrap: -------------------------------------------------------------------------------- 1 | [wrap-file] 2 | directory = sqlite-amalgamation-3390300 3 | source_url = https://sqlite.org/2022/sqlite-amalgamation-3390300.zip 4 | source_filename = sqlite-amalgamation-3390300.zip 5 | source_hash = a89db3030d229d860ae56a8bac50ac9761434047ae886e47e7c8f9f428fa98ad 6 | patch_filename = sqlite3_3.39.3-1_patch.zip 7 | patch_url = https://wrapdb.mesonbuild.com/v2/sqlite3_3.39.3-1/get_patch 8 | patch_hash = f5c41ff7b3da1108ed221b9a820b41188550cafb8a6c3d247bb40bd598775050 9 | wrapdb_version = 3.39.3-1 10 | 11 | [provide] 12 | sqlite3 = sqlite3_dep 13 | -------------------------------------------------------------------------------- /thirdparty/cpp-httplib/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 yhirose 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /thirdparty/cpp-httplib/meson.build: -------------------------------------------------------------------------------- 1 | include_httplib=include_directories( [ './include',]) 2 | -------------------------------------------------------------------------------- /thirdparty/json/LICENSE.MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2013-2022 Niels Lohmann 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /thirdparty/json/include/nlohmann/detail/input/position_t.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include // size_t 4 | 5 | namespace nlohmann 6 | { 7 | namespace detail 8 | { 9 | /// struct to capture the start position of the current token 10 | struct position_t 11 | { 12 | /// the total number of characters read 13 | std::size_t chars_read_total = 0; 14 | /// the number of characters read in the current line 15 | std::size_t chars_read_current_line = 0; 16 | /// the number of lines read 17 | std::size_t lines_read = 0; 18 | 19 | /// conversion to size_t to preserve SAX interface 20 | constexpr operator size_t() const 21 | { 22 | return chars_read_total; 23 | } 24 | }; 25 | 26 | } // namespace detail 27 | } // namespace nlohmann 28 | -------------------------------------------------------------------------------- /thirdparty/json/include/nlohmann/detail/iterators/internal_iterator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nlohmann 6 | { 7 | namespace detail 8 | { 9 | /*! 10 | @brief an iterator value 11 | 12 | @note This structure could easily be a union, but MSVC currently does not allow 13 | unions members with complex constructors, see https://github.com/nlohmann/json/pull/105. 14 | */ 15 | template struct internal_iterator 16 | { 17 | /// iterator for JSON objects 18 | typename BasicJsonType::object_t::iterator object_iterator {}; 19 | /// iterator for JSON arrays 20 | typename BasicJsonType::array_t::iterator array_iterator {}; 21 | /// generic iterator for all other types 22 | primitive_iterator_t primitive_iterator {}; 23 | }; 24 | } // namespace detail 25 | } // namespace nlohmann 26 | -------------------------------------------------------------------------------- /thirdparty/json/include/nlohmann/detail/iterators/iterator_traits.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include // random_access_iterator_tag 4 | 5 | #include 6 | #include 7 | 8 | namespace nlohmann 9 | { 10 | namespace detail 11 | { 12 | template 13 | struct iterator_types {}; 14 | 15 | template 16 | struct iterator_types < 17 | It, 18 | void_t> 20 | { 21 | using difference_type = typename It::difference_type; 22 | using value_type = typename It::value_type; 23 | using pointer = typename It::pointer; 24 | using reference = typename It::reference; 25 | using iterator_category = typename It::iterator_category; 26 | }; 27 | 28 | // This is required as some compilers implement std::iterator_traits in a way that 29 | // doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341. 30 | template 31 | struct iterator_traits 32 | { 33 | }; 34 | 35 | template 36 | struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> 37 | : iterator_types 38 | { 39 | }; 40 | 41 | template 42 | struct iterator_traits::value>> 43 | { 44 | using iterator_category = std::random_access_iterator_tag; 45 | using value_type = T; 46 | using difference_type = ptrdiff_t; 47 | using pointer = T*; 48 | using reference = T&; 49 | }; 50 | } // namespace detail 51 | } // namespace nlohmann 52 | -------------------------------------------------------------------------------- /thirdparty/json/include/nlohmann/detail/macro_unscope.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // restore clang diagnostic settings 4 | #if defined(__clang__) 5 | #pragma clang diagnostic pop 6 | #endif 7 | 8 | // clean up 9 | #undef JSON_ASSERT 10 | #undef JSON_INTERNAL_CATCH 11 | #undef JSON_CATCH 12 | #undef JSON_THROW 13 | #undef JSON_TRY 14 | #undef JSON_PRIVATE_UNLESS_TESTED 15 | #undef JSON_HAS_CPP_11 16 | #undef JSON_HAS_CPP_14 17 | #undef JSON_HAS_CPP_17 18 | #undef JSON_HAS_CPP_20 19 | #undef JSON_HAS_FILESYSTEM 20 | #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM 21 | #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION 22 | #undef NLOHMANN_BASIC_JSON_TPL 23 | #undef JSON_EXPLICIT 24 | #undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL 25 | 26 | #include 27 | -------------------------------------------------------------------------------- /thirdparty/json/include/nlohmann/detail/meta/call_std/begin.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nlohmann 6 | { 7 | NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); 8 | } // namespace nlohmann 9 | -------------------------------------------------------------------------------- /thirdparty/json/include/nlohmann/detail/meta/call_std/end.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nlohmann 6 | { 7 | NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); 8 | } // namespace nlohmann 9 | -------------------------------------------------------------------------------- /thirdparty/json/include/nlohmann/detail/meta/identity_tag.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace nlohmann 4 | { 5 | namespace detail 6 | { 7 | // dispatching helper struct 8 | template struct identity_tag {}; 9 | } // namespace detail 10 | } // namespace nlohmann 11 | -------------------------------------------------------------------------------- /thirdparty/json/include/nlohmann/detail/meta/void_t.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace nlohmann 4 | { 5 | namespace detail 6 | { 7 | template struct make_void 8 | { 9 | using type = void; 10 | }; 11 | template using void_t = typename make_void::type; 12 | } // namespace detail 13 | } // namespace nlohmann 14 | -------------------------------------------------------------------------------- /thirdparty/json/meson.build: -------------------------------------------------------------------------------- 1 | include_json = include_directories('include') 2 | -------------------------------------------------------------------------------- /thirdparty/meson.build: -------------------------------------------------------------------------------- 1 | subdir('./secp256k1') 2 | subdir('./sqlitecpp') 3 | subdir('./spdlog') 4 | subdir('./uSockets') 5 | subdir('./uWebsockets') 6 | subdir('./json') 7 | subdir('./tomlplusplus') 8 | subdir('./trezor-crypto') 9 | subdir('./cpp-httplib') 10 | subdir('./tl') 11 | subdir('./uvw') 12 | -------------------------------------------------------------------------------- /thirdparty/secp256k1/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Pieter Wuille 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /thirdparty/secp256k1/meson.build: -------------------------------------------------------------------------------- 1 | args=['-DENABLE_MODULE_RECOVERY', '-DECMULT_GEN_PREC_BITS=4', '-DECMULT_WINDOW_SIZE=15', '-w'] 2 | # args=[ '-DECMULT_GEN_PREC_BITS=4', '-DECMULT_WINDOW_SIZE=15', '-w'] 3 | include_secp256k1=include_directories('./include') 4 | 5 | libsecp256k1=library('warthogsecp256k1', 'src/secp256k1.cpp', include_directories:'./include', cpp_args: args, 6 | gnu_symbol_visibility:'hidden', 7 | install: true 8 | ) 9 | 10 | -------------------------------------------------------------------------------- /thirdparty/secp256k1/src/ecdsa.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.* 5 | ***********************************************************************/ 6 | 7 | #ifndef SECP256K1_ECDSA_H 8 | #define SECP256K1_ECDSA_H 9 | 10 | #include 11 | 12 | #include "scalar.h" 13 | #include "group.h" 14 | #include "ecmult.h" 15 | 16 | static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size); 17 | static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s); 18 | static int secp256k1_ecdsa_sig_verify(const secp256k1_scalar* r, const secp256k1_scalar* s, const secp256k1_ge *pubkey, const secp256k1_scalar *message); 19 | static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid); 20 | 21 | #endif /* SECP256K1_ECDSA_H */ 22 | -------------------------------------------------------------------------------- /thirdparty/secp256k1/src/eckey.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.* 5 | ***********************************************************************/ 6 | 7 | #ifndef SECP256K1_ECKEY_H 8 | #define SECP256K1_ECKEY_H 9 | 10 | #include 11 | 12 | #include "group.h" 13 | #include "scalar.h" 14 | #include "ecmult.h" 15 | #include "ecmult_gen.h" 16 | 17 | static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size); 18 | static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed); 19 | 20 | static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak); 21 | static int secp256k1_eckey_pubkey_tweak_add(secp256k1_ge *key, const secp256k1_scalar *tweak); 22 | static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak); 23 | static int secp256k1_eckey_pubkey_tweak_mul(secp256k1_ge *key, const secp256k1_scalar *tweak); 24 | 25 | #endif /* SECP256K1_ECKEY_H */ 26 | -------------------------------------------------------------------------------- /thirdparty/secp256k1/src/ecmult_const.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.* 5 | ***********************************************************************/ 6 | 7 | #ifndef SECP256K1_ECMULT_CONST_H 8 | #define SECP256K1_ECMULT_CONST_H 9 | 10 | #include "scalar.h" 11 | #include "group.h" 12 | 13 | /** 14 | * Multiply: R = q*A (in constant-time) 15 | * Here `bits` should be set to the maximum bitlength of the _absolute value_ of `q`, plus 16 | * one because we internally sometimes add 2 to the number during the WNAF conversion. 17 | */ 18 | static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q, int bits); 19 | 20 | #endif /* SECP256K1_ECMULT_CONST_H */ 21 | -------------------------------------------------------------------------------- /thirdparty/secp256k1/src/scalar_4x64.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.* 5 | ***********************************************************************/ 6 | 7 | #ifndef SECP256K1_SCALAR_REPR_H 8 | #define SECP256K1_SCALAR_REPR_H 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint64_t d[4]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{((uint64_t)(d1)) << 32 | (d0), ((uint64_t)(d3)) << 32 | (d2), ((uint64_t)(d5)) << 32 | (d4), ((uint64_t)(d7)) << 32 | (d6)}} 18 | 19 | #endif /* SECP256K1_SCALAR_REPR_H */ 20 | -------------------------------------------------------------------------------- /thirdparty/secp256k1/src/selftest.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * Copyright (c) 2020 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.* 5 | ***********************************************************************/ 6 | 7 | #ifndef SECP256K1_SELFTEST_H 8 | #define SECP256K1_SELFTEST_H 9 | 10 | #include "hash.h" 11 | 12 | #include 13 | 14 | static int secp256k1_selftest_sha256(void) { 15 | static const char *input63 = "For this sample, this 63-byte string will be used as input data"; 16 | static const unsigned char output32[32] = { 17 | 0xf0, 0x8a, 0x78, 0xcb, 0xba, 0xee, 0x08, 0x2b, 0x05, 0x2a, 0xe0, 0x70, 0x8f, 0x32, 0xfa, 0x1e, 18 | 0x50, 0xc5, 0xc4, 0x21, 0xaa, 0x77, 0x2b, 0xa5, 0xdb, 0xb4, 0x06, 0xa2, 0xea, 0x6b, 0xe3, 0x42, 19 | }; 20 | unsigned char out[32]; 21 | secp256k1_sha256 hasher; 22 | secp256k1_sha256_initialize(&hasher); 23 | secp256k1_sha256_write(&hasher, (const unsigned char*)input63, 63); 24 | secp256k1_sha256_finalize(&hasher, out); 25 | return secp256k1_memcmp_var(out, output32, 32) == 0; 26 | } 27 | 28 | static int secp256k1_selftest(void) { 29 | return secp256k1_selftest_sha256(); 30 | } 31 | 32 | #endif /* SECP256K1_SELFTEST_H */ 33 | -------------------------------------------------------------------------------- /thirdparty/spdlog/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Gabi Melman. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | -- NOTE: Third party dependency used by this software -- 24 | This software depends on the fmt lib (MIT License), 25 | and users must comply to its license: https://github.com/fmtlib/fmt/blob/master/LICENSE.rst 26 | 27 | 28 | -------------------------------------------------------------------------------- /thirdparty/spdlog/README: -------------------------------------------------------------------------------- 1 | This is a snapshot of https://github.com/gabime/spdlog/commit/4cfdc8c5c84f696774cb9acde2f95c9e87c11a5e patched to behave as compiled with '-DSPDLOG_COMPILED_LIB' to use of the compiled version of spdlog (not the header-only version) in this project. 2 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/cfg/argv.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | #include 6 | #include 7 | 8 | // 9 | // Init log levels using each argv entry that starts with "SPDLOG_LEVEL=" 10 | // 11 | // set all loggers to debug level: 12 | // example.exe "SPDLOG_LEVEL=debug" 13 | 14 | // set logger1 to trace level 15 | // example.exe "SPDLOG_LEVEL=logger1=trace" 16 | 17 | // turn off all logging except for logger1 and logger2: 18 | // example.exe "SPDLOG_LEVEL=off,logger1=debug,logger2=info" 19 | 20 | namespace spdlog { 21 | namespace cfg { 22 | 23 | // search for SPDLOG_LEVEL= in the args and use it to init the levels 24 | inline void load_argv_levels(int argc, const char **argv) 25 | { 26 | const std::string spdlog_level_prefix = "SPDLOG_LEVEL="; 27 | for (int i = 1; i < argc; i++) 28 | { 29 | std::string arg = argv[i]; 30 | if (arg.find(spdlog_level_prefix) == 0) 31 | { 32 | auto levels_string = arg.substr(spdlog_level_prefix.size()); 33 | helpers::load_levels(levels_string); 34 | } 35 | } 36 | } 37 | 38 | inline void load_argv_levels(int argc, char **argv) 39 | { 40 | load_argv_levels(argc, const_cast(argv)); 41 | } 42 | 43 | } // namespace cfg 44 | } // namespace spdlog 45 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/cfg/env.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | #include 6 | #include 7 | #include 8 | 9 | // 10 | // Init levels and patterns from env variables SPDLOG_LEVEL 11 | // Inspired from Rust's "env_logger" crate (https://crates.io/crates/env_logger). 12 | // Note - fallback to "info" level on unrecognized levels 13 | // 14 | // Examples: 15 | // 16 | // set global level to debug: 17 | // export SPDLOG_LEVEL=debug 18 | // 19 | // turn off all logging except for logger1: 20 | // export SPDLOG_LEVEL="*=off,logger1=debug" 21 | // 22 | 23 | // turn off all logging except for logger1 and logger2: 24 | // export SPDLOG_LEVEL="off,logger1=debug,logger2=info" 25 | 26 | namespace spdlog { 27 | namespace cfg { 28 | inline void load_env_levels() 29 | { 30 | auto env_val = details::os::getenv("SPDLOG_LEVEL"); 31 | if (!env_val.empty()) 32 | { 33 | helpers::load_levels(env_val); 34 | } 35 | } 36 | 37 | } // namespace cfg 38 | } // namespace spdlog 39 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/cfg/helpers.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | namespace cfg { 11 | namespace helpers { 12 | // 13 | // Init levels from given string 14 | // 15 | // Examples: 16 | // 17 | // set global level to debug: "debug" 18 | // turn off all logging except for logger1: "off,logger1=debug" 19 | // turn off all logging except for logger1 and logger2: "off,logger1=debug,logger2=info" 20 | // 21 | SPDLOG_API void load_levels(const std::string &txt); 22 | } // namespace helpers 23 | 24 | } // namespace cfg 25 | } // namespace spdlog 26 | 27 | #ifdef SPDLOG_HEADER_ONLY 28 | # include "helpers-inl.h" 29 | #endif // SPDLOG_HEADER_ONLY 30 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/details/backtracer.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | // Store log messages in circular buffer. 14 | // Useful for storing debug data in case of error/warning happens. 15 | 16 | namespace spdlog { 17 | namespace details { 18 | class SPDLOG_API backtracer 19 | { 20 | mutable std::mutex mutex_; 21 | std::atomic enabled_{false}; 22 | circular_q messages_; 23 | 24 | public: 25 | backtracer() = default; 26 | backtracer(const backtracer &other); 27 | 28 | backtracer(backtracer &&other) SPDLOG_NOEXCEPT; 29 | backtracer &operator=(backtracer other); 30 | 31 | void enable(size_t size); 32 | void disable(); 33 | bool enabled() const; 34 | void push_back(const log_msg &msg); 35 | 36 | // pop all items in the q and apply the given fun on each of them. 37 | void foreach_pop(std::function fun); 38 | }; 39 | 40 | } // namespace details 41 | } // namespace spdlog 42 | 43 | #ifdef SPDLOG_HEADER_ONLY 44 | # include "backtracer-inl.h" 45 | #endif 46 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/details/console_globals.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | 12 | struct console_mutex 13 | { 14 | using mutex_t = std::mutex; 15 | static mutex_t &mutex() 16 | { 17 | static mutex_t s_mutex; 18 | return s_mutex; 19 | } 20 | }; 21 | 22 | struct console_nullmutex 23 | { 24 | using mutex_t = null_mutex; 25 | static mutex_t &mutex() 26 | { 27 | static mutex_t s_mutex; 28 | return s_mutex; 29 | } 30 | }; 31 | } // namespace details 32 | } // namespace spdlog 33 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/details/log_msg-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | # include 8 | #endif 9 | 10 | #include 11 | 12 | namespace spdlog { 13 | namespace details { 14 | 15 | SPDLOG_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, spdlog::source_loc loc, string_view_t a_logger_name, 16 | spdlog::level::level_enum lvl, spdlog::string_view_t msg) 17 | : logger_name(a_logger_name) 18 | , level(lvl) 19 | , time(log_time) 20 | #ifndef SPDLOG_NO_THREAD_ID 21 | , thread_id(os::thread_id()) 22 | #endif 23 | , source(loc) 24 | , payload(msg) 25 | {} 26 | 27 | SPDLOG_INLINE log_msg::log_msg( 28 | spdlog::source_loc loc, string_view_t a_logger_name, spdlog::level::level_enum lvl, spdlog::string_view_t msg) 29 | : log_msg(os::now(), loc, a_logger_name, lvl, msg) 30 | {} 31 | 32 | SPDLOG_INLINE log_msg::log_msg(string_view_t a_logger_name, spdlog::level::level_enum lvl, spdlog::string_view_t msg) 33 | : log_msg(os::now(), source_loc{}, a_logger_name, lvl, msg) 34 | {} 35 | 36 | } // namespace details 37 | } // namespace spdlog 38 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/details/log_msg.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | struct SPDLOG_API log_msg 12 | { 13 | log_msg() = default; 14 | log_msg(log_clock::time_point log_time, source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg); 15 | log_msg(source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg); 16 | log_msg(string_view_t logger_name, level::level_enum lvl, string_view_t msg); 17 | log_msg(const log_msg &other) = default; 18 | log_msg &operator=(const log_msg &other) = default; 19 | 20 | string_view_t logger_name; 21 | level::level_enum level{level::off}; 22 | log_clock::time_point time; 23 | size_t thread_id{0}; 24 | 25 | // wrapping the formatted text with color (updated by pattern_formatter). 26 | mutable size_t color_range_start{0}; 27 | mutable size_t color_range_end{0}; 28 | 29 | source_loc source; 30 | string_view_t payload; 31 | }; 32 | } // namespace details 33 | } // namespace spdlog 34 | 35 | #ifdef SPDLOG_HEADER_ONLY 36 | # include "log_msg-inl.h" 37 | #endif 38 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/details/log_msg_buffer.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace spdlog { 9 | namespace details { 10 | 11 | // Extend log_msg with internal buffer to store its payload. 12 | // This is needed since log_msg holds string_views that points to stack data. 13 | 14 | class SPDLOG_API log_msg_buffer : public log_msg 15 | { 16 | memory_buf_t buffer; 17 | void update_string_views(); 18 | 19 | public: 20 | log_msg_buffer() = default; 21 | explicit log_msg_buffer(const log_msg &orig_msg); 22 | log_msg_buffer(const log_msg_buffer &other); 23 | log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT; 24 | log_msg_buffer &operator=(const log_msg_buffer &other); 25 | log_msg_buffer &operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT; 26 | }; 27 | 28 | } // namespace details 29 | } // namespace spdlog 30 | 31 | #ifdef SPDLOG_HEADER_ONLY 32 | # include "log_msg_buffer-inl.h" 33 | #endif 34 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/details/null_mutex.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | // null, no cost dummy "mutex" and dummy "atomic" int 9 | 10 | namespace spdlog { 11 | namespace details { 12 | struct null_mutex 13 | { 14 | void lock() const {} 15 | void unlock() const {} 16 | bool try_lock() const 17 | { 18 | return true; 19 | } 20 | }; 21 | 22 | struct null_atomic_int 23 | { 24 | int value; 25 | null_atomic_int() = default; 26 | 27 | explicit null_atomic_int(int new_value) 28 | : value(new_value) 29 | {} 30 | 31 | int load(std::memory_order = std::memory_order_relaxed) const 32 | { 33 | return value; 34 | } 35 | 36 | void store(int new_value, std::memory_order = std::memory_order_relaxed) 37 | { 38 | value = new_value; 39 | } 40 | 41 | int exchange(int new_value, std::memory_order = std::memory_order_relaxed) 42 | { 43 | std::swap(new_value, value); 44 | return new_value; // return value before the call 45 | } 46 | }; 47 | 48 | } // namespace details 49 | } // namespace spdlog 50 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/details/periodic_worker-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | # include 8 | #endif 9 | 10 | namespace spdlog { 11 | namespace details { 12 | 13 | SPDLOG_INLINE periodic_worker::periodic_worker(const std::function &callback_fun, std::chrono::seconds interval) 14 | { 15 | active_ = (interval > std::chrono::seconds::zero()); 16 | if (!active_) 17 | { 18 | return; 19 | } 20 | 21 | worker_thread_ = std::thread([this, callback_fun, interval]() { 22 | for (;;) 23 | { 24 | std::unique_lock lock(this->mutex_); 25 | if (this->cv_.wait_for(lock, interval, [this] { return !this->active_; })) 26 | { 27 | return; // active_ == false, so exit this thread 28 | } 29 | callback_fun(); 30 | } 31 | }); 32 | } 33 | 34 | // stop the worker thread and join it 35 | SPDLOG_INLINE periodic_worker::~periodic_worker() 36 | { 37 | if (worker_thread_.joinable()) 38 | { 39 | { 40 | std::lock_guard lock(mutex_); 41 | active_ = false; 42 | } 43 | cv_.notify_one(); 44 | worker_thread_.join(); 45 | } 46 | } 47 | 48 | } // namespace details 49 | } // namespace spdlog 50 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/details/periodic_worker.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // periodic worker thread - periodically executes the given callback function. 7 | // 8 | // RAII over the owned thread: 9 | // creates the thread on construction. 10 | // stops and joins the thread on destruction (if the thread is executing a callback, wait for it to finish first). 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | namespace spdlog { 18 | namespace details { 19 | 20 | class SPDLOG_API periodic_worker 21 | { 22 | public: 23 | periodic_worker(const std::function &callback_fun, std::chrono::seconds interval); 24 | periodic_worker(const periodic_worker &) = delete; 25 | periodic_worker &operator=(const periodic_worker &) = delete; 26 | // stop the worker thread and join it 27 | ~periodic_worker(); 28 | 29 | private: 30 | bool active_; 31 | std::thread worker_thread_; 32 | std::mutex mutex_; 33 | std::condition_variable cv_; 34 | }; 35 | } // namespace details 36 | } // namespace spdlog 37 | 38 | #ifdef SPDLOG_HEADER_ONLY 39 | # include "periodic_worker-inl.h" 40 | #endif 41 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/details/synchronous_factory.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "registry.h" 7 | 8 | namespace spdlog { 9 | 10 | // Default logger factory- creates synchronous loggers 11 | class logger; 12 | 13 | struct synchronous_factory 14 | { 15 | template 16 | static std::shared_ptr create(std::string logger_name, SinkArgs &&... args) 17 | { 18 | auto sink = std::make_shared(std::forward(args)...); 19 | auto new_logger = std::make_shared(std::move(logger_name), std::move(sink)); 20 | details::registry::instance().initialize_logger(new_logger); 21 | return new_logger; 22 | } 23 | }; 24 | } // namespace spdlog 25 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/details/windows_include.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef NOMINMAX 4 | # define NOMINMAX // prevent windows redefining min/max 5 | #endif 6 | 7 | #ifndef WIN32_LEAN_AND_MEAN 8 | # define WIN32_LEAN_AND_MEAN 9 | #endif 10 | 11 | #include 12 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/fmt/bundled/fmt.license.rst: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 - present, Victor Zverovich 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | --- Optional exception to the license --- 23 | 24 | As an exception, if, as a result of your compiling your source code, portions 25 | of this Software are embedded into a machine-executable object form of such 26 | source code, you may redistribute such embedded portions in such object form 27 | without including the above copyright and permission notices. 28 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/fmt/bundled/locale.h: -------------------------------------------------------------------------------- 1 | #include "xchar.h" 2 | #warning fmt/locale.h is deprecated, include fmt/format.h or fmt/xchar.h instead 3 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/fmt/chrono.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's chrono support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | # if !defined(SPDLOG_FMT_EXTERNAL) 13 | # ifdef SPDLOG_HEADER_ONLY 14 | # ifndef FMT_HEADER_ONLY 15 | # define FMT_HEADER_ONLY 16 | # endif 17 | # endif 18 | # include 19 | # else 20 | # include 21 | # endif 22 | #endif 23 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/fmt/compile.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's compile-time support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | # if !defined(SPDLOG_FMT_EXTERNAL) 13 | # ifdef SPDLOG_HEADER_ONLY 14 | # ifndef FMT_HEADER_ONLY 15 | # define FMT_HEADER_ONLY 16 | # endif 17 | # endif 18 | # include 19 | # else 20 | # include 21 | # endif 22 | #endif 23 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/fmt/fmt.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016-2018 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | 8 | // 9 | // Include a bundled header-only copy of fmtlib or an external one. 10 | // By default spdlog include its own copy. 11 | // 12 | 13 | #if defined(SPDLOG_USE_STD_FORMAT) // SPDLOG_USE_STD_FORMAT is defined - use std::format 14 | # include 15 | #elif !defined(SPDLOG_FMT_EXTERNAL) 16 | # ifndef FMT_USE_WINDOWS_H 17 | # define FMT_USE_WINDOWS_H 0 18 | # endif 19 | // enable the 'n' flag in for backward compatibility with fmt 6.x 20 | # define FMT_DEPRECATED_N_SPECIFIER 21 | # include 22 | # include 23 | #else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib 24 | # include 25 | # include 26 | #endif 27 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/fmt/ostr.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's ostream support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | # if !defined(SPDLOG_FMT_EXTERNAL) 13 | # ifdef SPDLOG_HEADER_ONLY 14 | # ifndef FMT_HEADER_ONLY 15 | # define FMT_HEADER_ONLY 16 | # endif 17 | # endif 18 | # include 19 | # else 20 | # include 21 | # endif 22 | #endif 23 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/fmt/xchar.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | // 8 | // include bundled or external copy of fmtlib's xchar support 9 | // 10 | 11 | #if !defined(SPDLOG_USE_STD_FORMAT) 12 | # if !defined(SPDLOG_FMT_EXTERNAL) 13 | # ifdef SPDLOG_HEADER_ONLY 14 | # ifndef FMT_HEADER_ONLY 15 | # define FMT_HEADER_ONLY 16 | # endif 17 | # endif 18 | # include 19 | # else 20 | # include 21 | # endif 22 | #endif 23 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/formatter.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | 11 | class formatter 12 | { 13 | public: 14 | virtual ~formatter() = default; 15 | virtual void format(const details::log_msg &msg, memory_buf_t &dest) = 0; 16 | virtual std::unique_ptr clone() const = 0; 17 | }; 18 | } // namespace spdlog 19 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/fwd.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | namespace spdlog { 7 | class logger; 8 | class formatter; 9 | 10 | namespace sinks { 11 | class sink; 12 | } 13 | 14 | namespace level { 15 | enum level_enum : int; 16 | } 17 | 18 | } // namespace spdlog 19 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/sinks/basic_file_sink-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | # include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | namespace sinks { 15 | 16 | template 17 | SPDLOG_INLINE basic_file_sink::basic_file_sink(const filename_t &filename, bool truncate, const file_event_handlers &event_handlers) 18 | : file_helper_{event_handlers} 19 | { 20 | file_helper_.open(filename, truncate); 21 | } 22 | 23 | template 24 | SPDLOG_INLINE const filename_t &basic_file_sink::filename() const 25 | { 26 | return file_helper_.filename(); 27 | } 28 | 29 | template 30 | SPDLOG_INLINE void basic_file_sink::sink_it_(const details::log_msg &msg) 31 | { 32 | memory_buf_t formatted; 33 | base_sink::formatter_->format(msg, formatted); 34 | file_helper_.write(formatted); 35 | } 36 | 37 | template 38 | SPDLOG_INLINE void basic_file_sink::flush_() 39 | { 40 | file_helper_.flush(); 41 | } 42 | 43 | } // namespace sinks 44 | } // namespace spdlog 45 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/sinks/msvc_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2016 Alexander Dalshov. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #if defined(_WIN32) 7 | 8 | # include 9 | # include 10 | 11 | # include 12 | # include 13 | 14 | // Avoid including windows.h (https://stackoverflow.com/a/30741042) 15 | extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString); 16 | 17 | namespace spdlog { 18 | namespace sinks { 19 | /* 20 | * MSVC sink (logging using OutputDebugStringA) 21 | */ 22 | template 23 | class msvc_sink : public base_sink 24 | { 25 | public: 26 | msvc_sink() = default; 27 | 28 | protected: 29 | void sink_it_(const details::log_msg &msg) override 30 | { 31 | memory_buf_t formatted; 32 | base_sink::formatter_->format(msg, formatted); 33 | # ifdef SPDLOG_USE_STD_FORMAT 34 | OutputDebugStringA(formatted.c_str()); 35 | # else 36 | OutputDebugStringA(fmt::to_string(formatted).c_str()); 37 | # endif 38 | } 39 | 40 | void flush_() override {} 41 | }; 42 | 43 | using msvc_sink_mt = msvc_sink; 44 | using msvc_sink_st = msvc_sink; 45 | 46 | using windebug_sink_mt = msvc_sink_mt; 47 | using windebug_sink_st = msvc_sink_st; 48 | 49 | } // namespace sinks 50 | } // namespace spdlog 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/sinks/null_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace spdlog { 13 | namespace sinks { 14 | 15 | template 16 | class null_sink : public base_sink 17 | { 18 | protected: 19 | void sink_it_(const details::log_msg &) override {} 20 | void flush_() override {} 21 | }; 22 | 23 | using null_sink_mt = null_sink; 24 | using null_sink_st = null_sink; 25 | 26 | } // namespace sinks 27 | 28 | template 29 | inline std::shared_ptr null_logger_mt(const std::string &logger_name) 30 | { 31 | auto null_logger = Factory::template create(logger_name); 32 | null_logger->set_level(level::off); 33 | return null_logger; 34 | } 35 | 36 | template 37 | inline std::shared_ptr null_logger_st(const std::string &logger_name) 38 | { 39 | auto null_logger = Factory::template create(logger_name); 40 | null_logger->set_level(level::off); 41 | return null_logger; 42 | } 43 | 44 | } // namespace spdlog 45 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/sinks/ostream_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace spdlog { 13 | namespace sinks { 14 | template 15 | class ostream_sink final : public base_sink 16 | { 17 | public: 18 | explicit ostream_sink(std::ostream &os, bool force_flush = false) 19 | : ostream_(os) 20 | , force_flush_(force_flush) 21 | {} 22 | ostream_sink(const ostream_sink &) = delete; 23 | ostream_sink &operator=(const ostream_sink &) = delete; 24 | 25 | protected: 26 | void sink_it_(const details::log_msg &msg) override 27 | { 28 | memory_buf_t formatted; 29 | base_sink::formatter_->format(msg, formatted); 30 | ostream_.write(formatted.data(), static_cast(formatted.size())); 31 | if (force_flush_) 32 | { 33 | ostream_.flush(); 34 | } 35 | } 36 | 37 | void flush_() override 38 | { 39 | ostream_.flush(); 40 | } 41 | 42 | std::ostream &ostream_; 43 | bool force_flush_; 44 | }; 45 | 46 | using ostream_sink_mt = ostream_sink; 47 | using ostream_sink_st = ostream_sink; 48 | 49 | } // namespace sinks 50 | } // namespace spdlog 51 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/sinks/sink-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | # include 8 | #endif 9 | 10 | #include 11 | 12 | SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level::level_enum msg_level) const 13 | { 14 | return msg_level >= level_.load(std::memory_order_relaxed); 15 | } 16 | 17 | SPDLOG_INLINE void spdlog::sinks::sink::set_level(level::level_enum log_level) 18 | { 19 | level_.store(log_level, std::memory_order_relaxed); 20 | } 21 | 22 | SPDLOG_INLINE spdlog::level::level_enum spdlog::sinks::sink::level() const 23 | { 24 | return static_cast(level_.load(std::memory_order_relaxed)); 25 | } 26 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/sinks/sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | 11 | namespace sinks { 12 | class SPDLOG_API sink 13 | { 14 | public: 15 | virtual ~sink() = default; 16 | virtual void log(const details::log_msg &msg) = 0; 17 | virtual void flush() = 0; 18 | virtual void set_pattern(const std::string &pattern) = 0; 19 | virtual void set_formatter(std::unique_ptr sink_formatter) = 0; 20 | 21 | void set_level(level::level_enum log_level); 22 | level::level_enum level() const; 23 | bool should_log(level::level_enum msg_level) const; 24 | 25 | protected: 26 | // sink log level - default is all 27 | level_t level_{level::trace}; 28 | }; 29 | 30 | } // namespace sinks 31 | } // namespace spdlog 32 | 33 | #ifdef SPDLOG_HEADER_ONLY 34 | # include "sink-inl.h" 35 | #endif 36 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/sinks/stdout_color_sinks-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | # include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | 15 | template 16 | SPDLOG_INLINE std::shared_ptr stdout_color_mt(const std::string &logger_name, color_mode mode) 17 | { 18 | return Factory::template create(logger_name, mode); 19 | } 20 | 21 | template 22 | SPDLOG_INLINE std::shared_ptr stdout_color_st(const std::string &logger_name, color_mode mode) 23 | { 24 | return Factory::template create(logger_name, mode); 25 | } 26 | 27 | template 28 | SPDLOG_INLINE std::shared_ptr stderr_color_mt(const std::string &logger_name, color_mode mode) 29 | { 30 | return Factory::template create(logger_name, mode); 31 | } 32 | 33 | template 34 | SPDLOG_INLINE std::shared_ptr stderr_color_st(const std::string &logger_name, color_mode mode) 35 | { 36 | return Factory::template create(logger_name, mode); 37 | } 38 | } // namespace spdlog 39 | -------------------------------------------------------------------------------- /thirdparty/spdlog/include/spdlog/version.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define SPDLOG_VER_MAJOR 1 7 | #define SPDLOG_VER_MINOR 9 8 | #define SPDLOG_VER_PATCH 2 9 | 10 | #define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH) 11 | -------------------------------------------------------------------------------- /thirdparty/spdlog/meson.build: -------------------------------------------------------------------------------- 1 | src_spdlog=files( 2 | [ './src/cfg.cpp', 3 | './src/fmt.cpp', 4 | './src/async.cpp', 5 | './src/spdlog.cpp', 6 | './src/file_sinks.cpp', 7 | './src/color_sinks.cpp', 8 | './src/stdout_sinks.cpp']) 9 | include_spdlog=include_directories( [ './include',]) 10 | -------------------------------------------------------------------------------- /thirdparty/spdlog/src/async.cpp: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | template class SPDLOG_API spdlog::details::mpmc_blocking_queue; 10 | -------------------------------------------------------------------------------- /thirdparty/spdlog/src/cfg.cpp: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | -------------------------------------------------------------------------------- /thirdparty/spdlog/src/file_sinks.cpp: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | template class SPDLOG_API spdlog::sinks::basic_file_sink; 12 | template class SPDLOG_API spdlog::sinks::basic_file_sink; 13 | 14 | #include 15 | template class SPDLOG_API spdlog::sinks::rotating_file_sink; 16 | template class SPDLOG_API spdlog::sinks::rotating_file_sink; 17 | -------------------------------------------------------------------------------- /thirdparty/spdlog/src/spdlog.cpp: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | // template instantiate logger constructor with sinks init list 20 | template SPDLOG_API spdlog::logger::logger(std::string name, sinks_init_list::iterator begin, sinks_init_list::iterator end); 21 | template class SPDLOG_API spdlog::sinks::base_sink; 22 | template class SPDLOG_API spdlog::sinks::base_sink; 23 | -------------------------------------------------------------------------------- /thirdparty/sqlitecpp/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2012-2021 Sebastien Rombauts (sebastien.rombauts@gmail.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is furnished 10 | to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 20 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /thirdparty/sqlitecpp/include/SQLiteCpp/Assertion.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Assertion.h 3 | * @ingroup SQLiteCpp 4 | * @brief Definition of the SQLITECPP_ASSERT() macro. 5 | * 6 | * Copyright (c) 2012-2020 Sebastien Rombauts (sebastien.rombauts@gmail.com) 7 | * 8 | * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt 9 | * or copy at http://opensource.org/licenses/MIT) 10 | */ 11 | #pragma once 12 | 13 | #include 14 | 15 | 16 | /** 17 | * SQLITECPP_ASSERT SQLITECPP_ASSERT() is used in destructors, where exceptions shall not be thrown 18 | * 19 | * Define SQLITECPP_ENABLE_ASSERT_HANDLER at the project level 20 | * and define a SQLite::assertion_failed() assertion handler 21 | * to tell SQLiteC++ to use it instead of assert() when an assertion fail. 22 | */ 23 | #ifdef SQLITECPP_ENABLE_ASSERT_HANDLER 24 | 25 | // if an assert handler is provided by user code, use it instead of assert() 26 | namespace SQLite 27 | { 28 | // declaration of the assert handler to define in user code 29 | void assertion_failed(const char* apFile, const long apLine, const char* apFunc, 30 | const char* apExpr, const char* apMsg); 31 | 32 | #ifdef _MSC_VER 33 | #define __func__ __FUNCTION__ 34 | #endif 35 | // call the assert handler provided by user code 36 | #define SQLITECPP_ASSERT(expression, message) \ 37 | if (!(expression)) SQLite::assertion_failed(__FILE__, __LINE__, __func__, #expression, message) 38 | } // namespace SQLite 39 | 40 | #else 41 | 42 | // if no assert handler provided by user code, use standard assert() 43 | // (note: in release mode assert() does nothing) 44 | #define SQLITECPP_ASSERT(expression, message) assert(expression && message) 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /thirdparty/sqlitecpp/include/SQLiteCpp/Utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Utils.h 3 | * @ingroup SQLiteCpp 4 | * @brief Definition of the SQLITECPP_PURE_FUNC macro. 5 | * 6 | * Copyright (c) 2012-2020 Sebastien Rombauts (sebastien.rombauts@gmail.com) 7 | * 8 | * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt 9 | * or copy at http://opensource.org/licenses/MIT) 10 | */ 11 | #pragma once 12 | 13 | // macro taken from https://github.com/nemequ/hedley/blob/master/hedley.h that was in public domain at this time 14 | #if defined(__GNUC__) || defined(__GNUG__) || defined(__clang__) ||\ 15 | (defined(__INTEL_COMPILER) && __INTEL_COMPILER > 1600) ||\ 16 | (defined(__ARMCC_VERSION) && __ARMCC_VERSION > 4010000) ||\ 17 | (\ 18 | defined(__TI_COMPILER_VERSION__) && (\ 19 | __TI_COMPILER_VERSION__ > 8003000 ||\ 20 | (__TI_COMPILER_VERSION__ > 7003000 && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))\ 21 | )\ 22 | ) 23 | #if defined(__has_attribute) 24 | #if !defined(SQLITECPP_PURE_FUNC) && __has_attribute(pure) 25 | #define SQLITECPP_PURE_FUNC __attribute__((pure)) 26 | #endif 27 | #endif 28 | #endif 29 | #if !defined(SQLITECPP_PURE_FUNC) 30 | #define SQLITECPP_PURE_FUNC 31 | #endif 32 | -------------------------------------------------------------------------------- /thirdparty/sqlitecpp/meson.build: -------------------------------------------------------------------------------- 1 | src_sqlitecpp=files( 2 | [ './src/Backup.cpp', 3 | './src/Column.cpp', 4 | './src/Database.cpp', 5 | './src/Exception.cpp', 6 | './src/Statement.cpp', 7 | './src/Transaction.cpp']) 8 | dep_thread = dependency('threads') 9 | include_sqlitecpp=include_directories( [ './include',]) 10 | -------------------------------------------------------------------------------- /thirdparty/sqlitecpp/src/Exception.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Exception.cpp 3 | * @ingroup SQLiteCpp 4 | * @brief Encapsulation of the error message from SQLite3 on a std::runtime_error. 5 | * 6 | * Copyright (c) 2012-2020 Sebastien Rombauts (sebastien.rombauts@gmail.com) 7 | * 8 | * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt 9 | * or copy at http://opensource.org/licenses/MIT) 10 | */ 11 | #include 12 | 13 | #include 14 | 15 | 16 | namespace SQLite 17 | { 18 | 19 | Exception::Exception(const char* aErrorMessage, int ret) : 20 | std::runtime_error(aErrorMessage), 21 | mErrcode(ret), 22 | mExtendedErrcode(-1) 23 | { 24 | } 25 | 26 | Exception::Exception(sqlite3* apSQLite) : 27 | std::runtime_error(sqlite3_errmsg(apSQLite)), 28 | mErrcode(sqlite3_errcode(apSQLite)), 29 | mExtendedErrcode(sqlite3_extended_errcode(apSQLite)) 30 | { 31 | } 32 | 33 | Exception::Exception(sqlite3* apSQLite, int ret) : 34 | std::runtime_error(sqlite3_errmsg(apSQLite)), 35 | mErrcode(ret), 36 | mExtendedErrcode(sqlite3_extended_errcode(apSQLite)) 37 | { 38 | } 39 | 40 | // Return a string, solely based on the error code 41 | const char* Exception::getErrorStr() const noexcept 42 | { 43 | return sqlite3_errstr(mErrcode); 44 | } 45 | 46 | 47 | } // namespace SQLite 48 | -------------------------------------------------------------------------------- /thirdparty/sqlitecpp/src/Transaction.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Transaction.cpp 3 | * @ingroup SQLiteCpp 4 | * @brief A Transaction is way to group multiple SQL statements into an atomic secured operation. 5 | * 6 | * Copyright (c) 2012-2019 Sebastien Rombauts (sebastien.rombauts@gmail.com) 7 | * 8 | * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt 9 | * or copy at http://opensource.org/licenses/MIT) 10 | */ 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | 17 | namespace SQLite 18 | { 19 | 20 | 21 | // Begins the SQLite transaction 22 | Transaction::Transaction(Database& aDatabase) : 23 | mDatabase(aDatabase), 24 | mbCommited(false) 25 | { 26 | mDatabase.exec("BEGIN"); 27 | } 28 | 29 | // Safely rollback the transaction if it has not been committed. 30 | Transaction::~Transaction() 31 | { 32 | if (false == mbCommited) 33 | { 34 | try 35 | { 36 | mDatabase.exec("ROLLBACK"); 37 | } 38 | catch (SQLite::Exception&) 39 | { 40 | // Never throw an exception in a destructor: error if already rollbacked, but no harm is caused by this. 41 | } 42 | } 43 | } 44 | 45 | // Commit the transaction. 46 | void Transaction::commit() 47 | { 48 | if (false == mbCommited) 49 | { 50 | mDatabase.exec("COMMIT"); 51 | mbCommited = true; 52 | } 53 | else 54 | { 55 | throw SQLite::Exception("Transaction already committed."); 56 | } 57 | } 58 | void Transaction::commit_restart() 59 | { 60 | commit(); 61 | mDatabase.exec("BEGIN"); 62 | mbCommited=false; 63 | } 64 | 65 | 66 | } // namespace SQLite 67 | -------------------------------------------------------------------------------- /thirdparty/tl/meson.build: -------------------------------------------------------------------------------- 1 | include_tl=include_directories( [ './include',]) 2 | -------------------------------------------------------------------------------- /thirdparty/tomlplusplus/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Mark Gillard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 7 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 11 | Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | -------------------------------------------------------------------------------- /thirdparty/tomlplusplus/meson.build: -------------------------------------------------------------------------------- 1 | include_tomlplusplus=include_directories( [ './include',]) 2 | -------------------------------------------------------------------------------- /thirdparty/trezor-crypto/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Tomas Dzetkulic 4 | Copyright (c) 2013 Pavol Rusnak 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /thirdparty/trezor-crypto/include/memzero.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __MEMZERO_H__ 2 | #define __MEMZERO_H__ 3 | 4 | #include 5 | 6 | void memzero(void* const pnt, const size_t len); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /thirdparty/trezor-crypto/include/ripemd160.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __RIPEMD160_H__ 2 | #define __RIPEMD160_H__ 3 | 4 | #include 5 | 6 | #define RIPEMD160_BLOCK_LENGTH 64 7 | #define RIPEMD160_DIGEST_LENGTH 20 8 | 9 | typedef struct _RIPEMD160_CTX { 10 | uint32_t total[2]; /*!< number of bytes processed */ 11 | uint32_t state[5]; /*!< intermediate digest state */ 12 | uint8_t buffer[RIPEMD160_BLOCK_LENGTH]; /*!< data block being processed */ 13 | } RIPEMD160_CTX; 14 | 15 | void ripemd160_Init(RIPEMD160_CTX *ctx); 16 | void ripemd160_Update(RIPEMD160_CTX *ctx, const uint8_t *input, uint32_t ilen); 17 | void ripemd160_Final(RIPEMD160_CTX *ctx, 18 | uint8_t output[RIPEMD160_DIGEST_LENGTH]); 19 | void ripemd160(const uint8_t *msg, uint32_t msg_len, 20 | uint8_t hash[RIPEMD160_DIGEST_LENGTH]); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /thirdparty/trezor-crypto/meson.build: -------------------------------------------------------------------------------- 1 | include_trezorcrypto=include_directories( [ './include',]) 2 | 3 | src_trezorcrypto=files([ 4 | './src/memzero.cpp', 5 | './src/ripemd160.cpp', 6 | './src/sha2.cpp' 7 | ]) 8 | -------------------------------------------------------------------------------- /thirdparty/uSockets/meson.build: -------------------------------------------------------------------------------- 1 | include_usockets=include_directories( [ './src',]) 2 | 3 | libusockets = library('usockets', [ 4 | './src/eventing/libuv.c', 5 | './src/bsd.c', 6 | './src/context.c', 7 | './src/loop.c', 8 | './src/socket.c', 9 | ], 10 | c_args: ['-DLIBUS_USE_LIBUV','-DLIBUS_NO_SSL', '-w'], 11 | cpp_args: ['-DLIBUS_USE_LIBUV','-DLIBUS_NO_SSL'], 12 | dependencies: libuv_dep, 13 | include_directories : ['./src'], 14 | install: true 15 | ) 16 | 17 | -------------------------------------------------------------------------------- /thirdparty/uSockets/src/internal/eventing/asio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Authored by Alex Hultman, 2018-2021. 3 | * Intellectual property of third-party. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef ASIO_H 19 | #define ASIO_H 20 | 21 | #include "internal/loop_data.h" 22 | 23 | #define LIBUS_SOCKET_READABLE 1 24 | #define LIBUS_SOCKET_WRITABLE 2 25 | 26 | struct us_loop_t { 27 | alignas(LIBUS_EXT_ALIGNMENT) struct us_internal_loop_data_t data; 28 | 29 | // a loop is an io_context 30 | void *io; 31 | 32 | // whether or not we got an io_context as hint or not 33 | int is_default; 34 | }; 35 | 36 | // it is no longer valid to cast a pointer to us_poll_t to a pointer of uv_poll_t 37 | struct us_poll_t { 38 | void *boost_block; 39 | 40 | LIBUS_SOCKET_DESCRIPTOR fd; 41 | unsigned char poll_type; 42 | int events; 43 | }; 44 | 45 | #endif // ASIO_H 46 | -------------------------------------------------------------------------------- /thirdparty/uSockets/src/internal/eventing/gcd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Authored by Alex Hultman, 2018-2019. 3 | * Intellectual property of third-party. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef GCD_H 19 | #define GCD_H 20 | 21 | #include "internal/loop_data.h" 22 | 23 | #include 24 | #define LIBUS_SOCKET_READABLE 1 25 | #define LIBUS_SOCKET_WRITABLE 2 26 | 27 | struct us_loop_t { 28 | alignas(LIBUS_EXT_ALIGNMENT) struct us_internal_loop_data_t data; 29 | 30 | dispatch_queue_t gcd_queue; 31 | }; 32 | 33 | struct us_poll_t { 34 | int events; 35 | dispatch_source_t gcd_read, gcd_write; 36 | LIBUS_SOCKET_DESCRIPTOR fd; 37 | unsigned char poll_type; 38 | }; 39 | 40 | #endif // GCD_H 41 | -------------------------------------------------------------------------------- /thirdparty/uSockets/src/internal/eventing/libuv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Authored by Alex Hultman, 2018-2019. 3 | * Intellectual property of third-party. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef LIBUV_H 19 | #define LIBUV_H 20 | 21 | #include "internal/loop_data.h" 22 | 23 | #include 24 | #define LIBUS_SOCKET_READABLE UV_READABLE 25 | #define LIBUS_SOCKET_WRITABLE UV_WRITABLE 26 | 27 | struct us_loop_t { 28 | alignas(LIBUS_EXT_ALIGNMENT) struct us_internal_loop_data_t data; 29 | 30 | uv_loop_t *uv_loop; 31 | int is_default; 32 | 33 | uv_prepare_t *uv_pre; 34 | uv_check_t *uv_check; 35 | }; 36 | 37 | // it is no longer valid to cast a pointer to us_poll_t to a pointer of uv_poll_t 38 | struct us_poll_t { 39 | /* We need to hold a pointer to this uv_poll_t since we need to be able to resize our block */ 40 | uv_poll_t *uv_p; 41 | LIBUS_SOCKET_DESCRIPTOR fd; 42 | unsigned char poll_type; 43 | }; 44 | 45 | #endif // LIBUV_H 46 | -------------------------------------------------------------------------------- /thirdparty/uSockets/src/internal/loop_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Authored by Alex Hultman, 2018-2019. 3 | * Intellectual property of third-party. 4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef LOOP_DATA_H 19 | #define LOOP_DATA_H 20 | 21 | struct us_internal_loop_data_t { 22 | struct us_timer_t *sweep_timer; 23 | struct us_internal_async *wakeup_async; 24 | int last_write_failed; 25 | struct us_socket_context_t *head; 26 | struct us_socket_context_t *iterator; 27 | char *recv_buf; 28 | void *ssl_data; 29 | void (*pre_cb)(struct us_loop_t *); 30 | void (*post_cb)(struct us_loop_t *); 31 | struct us_socket_t *closed_head; 32 | struct us_socket_t *low_prio_head; 33 | int low_prio_budget; 34 | /* We do not care if this flips or not, it doesn't matter */ 35 | long long iteration_nr; 36 | }; 37 | 38 | #endif // LOOP_DATA_H 39 | -------------------------------------------------------------------------------- /thirdparty/uWebsockets/README: -------------------------------------------------------------------------------- 1 | This is a modified version of uWebsockets where the stupid per thread singleton design `Loop::get()` is replaced. 2 | The reason is that Loop::get() returns a thread local variable which is needed for inter-thread communication such that the spawning thread needs to wait until the newly spawned thread has constructed its thread local loop. Otherwise an immediate shutdown where the spawning thread needs to communicate to the newly spawned thread will lead to a crash because a copy of the loop variable is not yet initialized. 3 | -------------------------------------------------------------------------------- /thirdparty/uWebsockets/meson.build: -------------------------------------------------------------------------------- 1 | include_uwebsockets=include_directories( [ './include',]) 2 | -------------------------------------------------------------------------------- /thirdparty/uvw/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2024 Michele Caini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copy of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copy or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /thirdparty/uvw/meson.build: -------------------------------------------------------------------------------- 1 | 2 | sources = [ 3 | 'uvw/async.cpp', 4 | 'uvw/check.cpp', 5 | 'uvw/dns.cpp', 6 | 'uvw/emitter.cpp', 7 | 'uvw/fs.cpp', 8 | 'uvw/fs_event.cpp', 9 | 'uvw/fs_poll.cpp', 10 | 'uvw/idle.cpp', 11 | 'uvw/lib.cpp', 12 | 'uvw/loop.cpp', 13 | 'uvw/pipe.cpp', 14 | 'uvw/poll.cpp', 15 | 'uvw/prepare.cpp', 16 | 'uvw/process.cpp', 17 | 'uvw/signal.cpp', 18 | 'uvw/stream.cpp', 19 | 'uvw/tcp.cpp', 20 | 'uvw/thread.cpp', 21 | 'uvw/timer.cpp', 22 | 'uvw/tty.cpp', 23 | 'uvw/udp.cpp', 24 | 'uvw/util.cpp', 25 | 'uvw/work.cpp', 26 | ] 27 | 28 | uvw_lib = library( 29 | 'uvw', sources, 30 | include_directories: '.', 31 | dependencies: [libuv_dep], 32 | cpp_args: ['-DUVW_AS_LIB'], 33 | install: true, 34 | ) 35 | 36 | uvw_dep = declare_dependency( 37 | include_directories: ['.'], 38 | dependencies: [libuv_dep], 39 | link_with: [uvw_lib], 40 | ) 41 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw.hpp: -------------------------------------------------------------------------------- 1 | #include "uvw/async.h" 2 | #include "uvw/check.h" 3 | #include "uvw/config.h" 4 | #include "uvw/dns.h" 5 | #include "uvw/emitter.h" 6 | #include "uvw/enum.hpp" 7 | #include "uvw/fs.h" 8 | #include "uvw/fs_event.h" 9 | #include "uvw/fs_poll.h" 10 | #include "uvw/handle.hpp" 11 | #include "uvw/idle.h" 12 | #include "uvw/lib.h" 13 | #include "uvw/loop.h" 14 | #include "uvw/pipe.h" 15 | #include "uvw/poll.h" 16 | #include "uvw/prepare.h" 17 | #include "uvw/process.h" 18 | #include "uvw/request.hpp" 19 | #include "uvw/resource.hpp" 20 | #include "uvw/signal.h" 21 | #include "uvw/tcp.h" 22 | #include "uvw/thread.h" 23 | #include "uvw/timer.h" 24 | #include "uvw/tty.h" 25 | #include "uvw/udp.h" 26 | #include "uvw/util.h" 27 | #include "uvw/uv_type.hpp" 28 | #include "uvw/work.h" 29 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/async.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "async.h" 3 | #endif 4 | 5 | #include "config.h" 6 | 7 | namespace uvw { 8 | 9 | UVW_INLINE void async_handle::send_callback(uv_async_t *hndl) { 10 | async_handle &async = *(static_cast(hndl->data)); 11 | async.publish(async_event{}); 12 | } 13 | 14 | UVW_INLINE int async_handle::init() { 15 | return leak_if(uv_async_init(parent().raw(), raw(), &send_callback)); 16 | } 17 | 18 | UVW_INLINE int async_handle::send() { 19 | return uv_async_send(raw()); 20 | } 21 | 22 | } // namespace uvw 23 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/async.h: -------------------------------------------------------------------------------- 1 | #ifndef UVW_ASYNC_INCLUDE_H 2 | #define UVW_ASYNC_INCLUDE_H 3 | 4 | #include 5 | #include "handle.hpp" 6 | #include "loop.h" 7 | 8 | namespace uvw { 9 | 10 | /*! @brief Async event. */ 11 | struct async_event {}; 12 | 13 | /** 14 | * @brief The async handle. 15 | * 16 | * Async handles allow the user to _wakeup_ the event loop and get an event 17 | * emitted from another thread. 18 | * 19 | * To create an `async_handle` through a `loop`, no arguments are required. 20 | */ 21 | class async_handle final: public handle { 22 | static void send_callback(uv_async_t *hndl); 23 | 24 | public: 25 | using handle::handle; 26 | 27 | /** 28 | * @brief Initializes the handle. 29 | * 30 | * Unlike other handle initialization functions, it immediately starts the 31 | * handle. 32 | * 33 | * @return Underlying return value. 34 | */ 35 | int init(); 36 | 37 | /** 38 | * @brief Wakeups the event loop and emits the async event. 39 | * 40 | * It’s safe to call this function from any thread.
41 | * An async event is emitted on the loop thread. 42 | * 43 | * See the official 44 | * [documentation](http://docs.libuv.org/en/v1.x/async.html#c.uv_async_send) 45 | * for further details. 46 | * 47 | * @return Underlying return value. 48 | */ 49 | int send(); 50 | }; 51 | 52 | } // namespace uvw 53 | 54 | #ifndef UVW_AS_LIB 55 | # include "async.cpp" 56 | #endif 57 | 58 | #endif // UVW_ASYNC_INCLUDE_H 59 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/check.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "check.h" 3 | #endif 4 | 5 | #include "config.h" 6 | 7 | namespace uvw { 8 | 9 | UVW_INLINE void check_handle::start_callback(uv_check_t *hndl) { 10 | check_handle &check = *(static_cast(hndl->data)); 11 | check.publish(check_event{}); 12 | } 13 | 14 | UVW_INLINE int check_handle::init() { 15 | return leak_if(uv_check_init(parent().raw(), raw())); 16 | } 17 | 18 | UVW_INLINE int check_handle::start() { 19 | return uv_check_start(raw(), &start_callback); 20 | } 21 | 22 | UVW_INLINE int check_handle::stop() { 23 | return uv_check_stop(raw()); 24 | } 25 | 26 | } // namespace uvw 27 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/check.h: -------------------------------------------------------------------------------- 1 | #ifndef UVW_CHECK_INCLUDE_H 2 | #define UVW_CHECK_INCLUDE_H 3 | 4 | #include 5 | #include "handle.hpp" 6 | #include "loop.h" 7 | 8 | namespace uvw { 9 | 10 | /*! @brief Check event. */ 11 | struct check_event {}; 12 | 13 | /** 14 | * @brief The check handle. 15 | * 16 | * Check handles will emit a check event once per loop iteration, right after 17 | * polling for I/O. 18 | * 19 | * To create a `check_handle` through a `loop`, no arguments are required. 20 | */ 21 | class check_handle final: public handle { 22 | static void start_callback(uv_check_t *hndl); 23 | 24 | public: 25 | using handle::handle; 26 | 27 | /** 28 | * @brief Initializes the handle. 29 | * @return Underlying return value. 30 | */ 31 | int init(); 32 | 33 | /** 34 | * @brief Starts the handle. 35 | * 36 | * A check event will be emitted once per loop iteration, right after 37 | * polling for I/O. 38 | * 39 | * @return Underlying return value. 40 | */ 41 | int start(); 42 | 43 | /** 44 | * @brief Stops the handle. 45 | * @return Underlying return value. 46 | */ 47 | int stop(); 48 | }; 49 | 50 | } // namespace uvw 51 | 52 | #ifndef UVW_AS_LIB 53 | # include "check.cpp" 54 | #endif 55 | 56 | #endif // UVW_CHECK_INCLUDE_H 57 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/config.h: -------------------------------------------------------------------------------- 1 | #ifndef UVW_CONFIG_H 2 | #define UVW_CONFIG_H 3 | 4 | #ifndef UVW_AS_LIB 5 | # define UVW_INLINE inline 6 | #else 7 | # define UVW_INLINE 8 | #endif 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/emitter.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "emitter.h" 3 | #endif 4 | 5 | #include "config.h" 6 | 7 | namespace uvw { 8 | 9 | UVW_INLINE int error_event::translate(int sys) noexcept { 10 | return uv_translate_sys_error(sys); 11 | } 12 | 13 | UVW_INLINE const char *error_event::what() const noexcept { 14 | return uv_strerror(ec); 15 | } 16 | 17 | UVW_INLINE const char *error_event::name() const noexcept { 18 | return uv_err_name(ec); 19 | } 20 | 21 | UVW_INLINE int error_event::code() const noexcept { 22 | return ec; 23 | } 24 | 25 | UVW_INLINE error_event::operator bool() const noexcept { 26 | return ec < 0; 27 | } 28 | 29 | } // namespace uvw 30 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/fs_event.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "fs_event.h" 3 | #endif 4 | 5 | #include 6 | #include "config.h" 7 | 8 | namespace uvw { 9 | 10 | UVW_INLINE fs_event_event::fs_event_event(const char *pathname, details::uvw_fs_event events) 11 | : filename{pathname}, flags{std::move(events)} {} 12 | 13 | UVW_INLINE void fs_event_handle::start_callback(uv_fs_event_t *hndl, const char *filename, int events, int status) { 14 | if(fs_event_handle &fsEvent = *(static_cast(hndl->data)); status) { 15 | fsEvent.publish(error_event{status}); 16 | } else { 17 | fsEvent.publish(fs_event_event{filename, details::uvw_fs_event(events)}); 18 | } 19 | } 20 | 21 | UVW_INLINE int fs_event_handle::init() { 22 | return leak_if(uv_fs_event_init(parent().raw(), raw())); 23 | } 24 | 25 | UVW_INLINE int fs_event_handle::start(const std::string &path, event_flags flags) { 26 | return uv_fs_event_start(raw(), &start_callback, path.data(), static_cast(flags)); 27 | } 28 | 29 | UVW_INLINE int fs_event_handle::stop() { 30 | return uv_fs_event_stop(raw()); 31 | } 32 | 33 | UVW_INLINE std::string fs_event_handle::path() noexcept { 34 | return details::try_read(&uv_fs_event_getpath, raw()); 35 | } 36 | 37 | } // namespace uvw 38 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/fs_poll.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "fs_poll.h" 3 | #endif 4 | 5 | #include 6 | #include "config.h" 7 | 8 | namespace uvw { 9 | 10 | UVW_INLINE fs_poll_event::fs_poll_event(file_info previous, file_info current) noexcept 11 | : prev{std::move(previous)}, curr{std::move(current)} {} 12 | 13 | UVW_INLINE void fs_poll_handle::start_callback(uv_fs_poll_t *hndl, int status, const uv_stat_t *prev, const uv_stat_t *curr) { 14 | if(fs_poll_handle &fsPoll = *(static_cast(hndl->data)); status) { 15 | fsPoll.publish(error_event{status}); 16 | } else { 17 | fsPoll.publish(fs_poll_event{*prev, *curr}); 18 | } 19 | } 20 | 21 | UVW_INLINE int fs_poll_handle::init() { 22 | return leak_if(uv_fs_poll_init(parent().raw(), raw())); 23 | } 24 | 25 | UVW_INLINE int fs_poll_handle::start(const std::string &file, fs_poll_handle::time interval) { 26 | return uv_fs_poll_start(raw(), &start_callback, file.data(), interval.count()); 27 | } 28 | 29 | UVW_INLINE int fs_poll_handle::stop() { 30 | return uv_fs_poll_stop(raw()); 31 | } 32 | 33 | UVW_INLINE std::string fs_poll_handle::path() noexcept { 34 | return details::try_read(&uv_fs_poll_getpath, raw()); 35 | } 36 | 37 | } // namespace uvw 38 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/idle.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "idle.h" 3 | #endif 4 | 5 | #include "config.h" 6 | 7 | namespace uvw { 8 | 9 | UVW_INLINE void idle_handle::start_callback(uv_idle_t *hndl) { 10 | idle_handle &idle = *(static_cast(hndl->data)); 11 | idle.publish(idle_event{}); 12 | } 13 | 14 | UVW_INLINE int idle_handle::init() { 15 | return leak_if(uv_idle_init(parent().raw(), raw())); 16 | } 17 | 18 | UVW_INLINE int idle_handle::start() { 19 | return uv_idle_start(raw(), &start_callback); 20 | } 21 | 22 | UVW_INLINE int idle_handle::stop() { 23 | return uv_idle_stop(raw()); 24 | } 25 | 26 | } // namespace uvw 27 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/idle.h: -------------------------------------------------------------------------------- 1 | #ifndef UVW_IDLE_INCLUDE_H 2 | #define UVW_IDLE_INCLUDE_H 3 | 4 | #include 5 | #include "handle.hpp" 6 | #include "loop.h" 7 | 8 | namespace uvw { 9 | 10 | /*! @brief Idle event. */ 11 | struct idle_event {}; 12 | 13 | /** 14 | * @brief The idle handle. 15 | * 16 | * Idle handles will emit a idle event once per loop iteration, right before the 17 | * prepare handles. 18 | * 19 | * The notable difference with prepare handles is that when there are active 20 | * idle handles, the loop will perform a zero timeout poll instead of blocking 21 | * for I/O. 22 | * 23 | * @note 24 | * Despite the name, idle handles will emit events on every loop iteration, not 25 | * when the loop is actually _idle_. 26 | * 27 | * To create an `idle_handle` through a `loop`, no arguments are required. 28 | */ 29 | class idle_handle final: public handle { 30 | static void start_callback(uv_idle_t *hndl); 31 | 32 | public: 33 | using handle::handle; 34 | 35 | /** 36 | * @brief Initializes the handle. 37 | * @return Underlying return value. 38 | */ 39 | int init(); 40 | 41 | /** 42 | * @brief Starts the handle. 43 | * 44 | * An idle event will be emitted once per loop iteration, right before 45 | * polling the prepare handles. 46 | * 47 | * @return Underlying return value. 48 | */ 49 | int start(); 50 | 51 | /** 52 | * @brief Stops the handle. 53 | * 54 | * @return Underlying return value. 55 | */ 56 | int stop(); 57 | }; 58 | 59 | } // namespace uvw 60 | 61 | #ifndef UVW_AS_LIB 62 | # include "idle.cpp" 63 | #endif 64 | 65 | #endif // UVW_IDLE_INCLUDE_H 66 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/lib.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "lib.h" 3 | #endif 4 | 5 | #include 6 | #include "config.h" 7 | 8 | namespace uvw { 9 | 10 | UVW_INLINE shared_lib::shared_lib(loop::token token, std::shared_ptr ref, const std::string &filename) noexcept 11 | : uv_type{token, std::move(ref)} { 12 | opened = (0 == uv_dlopen(filename.data(), raw())); 13 | } 14 | 15 | UVW_INLINE shared_lib::~shared_lib() noexcept { 16 | uv_dlclose(raw()); 17 | } 18 | 19 | UVW_INLINE shared_lib::operator bool() const noexcept { 20 | return opened; 21 | } 22 | 23 | UVW_INLINE const char *shared_lib::error() const noexcept { 24 | return uv_dlerror(raw()); 25 | } 26 | 27 | } // namespace uvw 28 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/poll.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "poll.h" 3 | #endif 4 | 5 | #include 6 | #include "config.h" 7 | 8 | namespace uvw { 9 | 10 | UVW_INLINE poll_event::poll_event(details::uvw_poll_event events) noexcept 11 | : flags{std::move(events)} {} 12 | 13 | UVW_INLINE poll_handle::poll_handle(loop::token token, std::shared_ptr ref, int desc) 14 | : handle{token, std::move(ref)}, tag{FD}, file_desc{desc} {} 15 | 16 | UVW_INLINE poll_handle::poll_handle(loop::token token, std::shared_ptr ref, os_socket_handle sock) 17 | : handle{token, std::move(ref)}, tag{SOCKET}, socket{sock} {} 18 | 19 | UVW_INLINE void poll_handle::start_callback(uv_poll_t *hndl, int status, int events) { 20 | if(poll_handle &poll = *(static_cast(hndl->data)); status) { 21 | poll.publish(error_event{status}); 22 | } else { 23 | poll.publish(poll_event{poll_event_flags(events)}); 24 | } 25 | } 26 | 27 | UVW_INLINE int poll_handle::init() { 28 | if(tag == SOCKET) { 29 | return leak_if(uv_poll_init_socket(parent().raw(), raw(), socket)); 30 | } else { 31 | return leak_if(uv_poll_init(parent().raw(), raw(), file_desc)); 32 | } 33 | } 34 | 35 | UVW_INLINE int poll_handle::start(poll_event_flags flags) { 36 | return uv_poll_start(raw(), static_cast(flags), &start_callback); 37 | } 38 | 39 | UVW_INLINE int poll_handle::stop() { 40 | return uv_poll_stop(raw()); 41 | } 42 | 43 | } // namespace uvw 44 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/prepare.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "prepare.h" 3 | #endif 4 | 5 | #include "config.h" 6 | 7 | namespace uvw { 8 | 9 | UVW_INLINE void prepare_handle::start_callback(uv_prepare_t *hndl) { 10 | prepare_handle &prepare = *(static_cast(hndl->data)); 11 | prepare.publish(prepare_event{}); 12 | } 13 | 14 | UVW_INLINE int prepare_handle::init() { 15 | return leak_if(uv_prepare_init(parent().raw(), raw())); 16 | } 17 | 18 | UVW_INLINE int prepare_handle::start() { 19 | return uv_prepare_start(raw(), &start_callback); 20 | } 21 | 22 | UVW_INLINE int prepare_handle::stop() { 23 | return uv_prepare_stop(raw()); 24 | } 25 | 26 | } // namespace uvw 27 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/prepare.h: -------------------------------------------------------------------------------- 1 | #ifndef UVW_PREPARE_INCLUDE_H 2 | #define UVW_PREPARE_INCLUDE_H 3 | 4 | #include 5 | #include "handle.hpp" 6 | #include "loop.h" 7 | 8 | namespace uvw { 9 | 10 | /*! @brief Prepare event. */ 11 | struct prepare_event {}; 12 | 13 | /** 14 | * @brief The prepare handle. 15 | * 16 | * Prepare handles will emit a prepare event once per loop iteration, right 17 | * before polling for I/O. 18 | * 19 | * To create a `prepare_handle` through a `loop`, no arguments are required. 20 | */ 21 | class prepare_handle final: public handle { 22 | static void start_callback(uv_prepare_t *hndl); 23 | 24 | public: 25 | using handle::handle; 26 | 27 | /** 28 | * @brief Initializes the handle. 29 | * @return Underlying return value. 30 | */ 31 | int init(); 32 | 33 | /** 34 | * @brief Starts the handle. 35 | * 36 | * A prepare event will be emitted once per loop iteration, right before 37 | * polling for I/O. 38 | * 39 | * The handle will start emitting prepare events when needed. 40 | * 41 | * @return Underlying return value. 42 | */ 43 | int start(); 44 | 45 | /** 46 | * @brief Stops the handle. 47 | * @return Underlying return value. 48 | */ 49 | int stop(); 50 | }; 51 | 52 | } // namespace uvw 53 | 54 | #ifndef UVW_AS_LIB 55 | # include "prepare.cpp" 56 | #endif 57 | 58 | #endif // UVW_PREPARE_INCLUDE_H 59 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/request.hpp: -------------------------------------------------------------------------------- 1 | #ifndef UVW_REQUEST_INCLUDE_H 2 | #define UVW_REQUEST_INCLUDE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "config.h" 9 | #include "resource.hpp" 10 | 11 | namespace uvw { 12 | 13 | /** 14 | * @brief Request base class. 15 | * 16 | * Base type for all `uvw` request types. 17 | */ 18 | template 19 | class request: public resource { 20 | protected: 21 | static auto reserve(U *req) { 22 | auto ptr = static_cast(req->data)->shared_from_this(); 23 | ptr->self_reset(); 24 | return ptr; 25 | } 26 | 27 | public: 28 | using resource::resource; 29 | 30 | /** 31 | * @brief Cancels a pending request. 32 | * 33 | * This method fails if the request is executing or has finished 34 | * executing. 35 | * 36 | * See the official 37 | * [documentation](http://docs.libuv.org/en/v1.x/request.html#c.uv_cancel) 38 | * for further details. 39 | * 40 | * @return Underlying return value. 41 | */ 42 | int cancel() { 43 | return uv_cancel(reinterpret_cast(this->raw())); 44 | } 45 | 46 | /** 47 | * @brief Returns the size of the underlying request type. 48 | * @return The size of the underlying request type. 49 | */ 50 | std::size_t size() const noexcept { 51 | return uv_req_size(reinterpret_cast(this->raw())->type); 52 | } 53 | }; 54 | 55 | } // namespace uvw 56 | 57 | #endif // UVW_REQUEST_INCLUDE_H 58 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/signal.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "signal.h" 3 | #endif 4 | 5 | #include "config.h" 6 | 7 | namespace uvw { 8 | 9 | UVW_INLINE signal_event::signal_event(int sig) noexcept 10 | : signum{sig} {} 11 | 12 | UVW_INLINE void signal_handle::start_callback(uv_signal_t *hndl, int signum) { 13 | signal_handle &signal = *(static_cast(hndl->data)); 14 | signal.publish(signal_event{signum}); 15 | } 16 | 17 | UVW_INLINE int signal_handle::init() { 18 | return leak_if(uv_signal_init(parent().raw(), raw())); 19 | } 20 | 21 | UVW_INLINE int signal_handle::start(int signum) { 22 | return uv_signal_start(raw(), &start_callback, signum); 23 | } 24 | 25 | UVW_INLINE int signal_handle::one_shot(int signum) { 26 | return uv_signal_start_oneshot(raw(), &start_callback, signum); 27 | } 28 | 29 | UVW_INLINE int signal_handle::stop() { 30 | return uv_signal_stop(raw()); 31 | } 32 | 33 | UVW_INLINE int signal_handle::signal() const noexcept { 34 | return raw()->signum; 35 | } 36 | 37 | } // namespace uvw 38 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/stream.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "stream.h" 3 | #endif 4 | 5 | #include "config.h" 6 | 7 | namespace uvw { 8 | 9 | UVW_INLINE data_event::data_event(std::unique_ptr buf, std::size_t len) noexcept 10 | : data{std::move(buf)}, 11 | length{len} {} 12 | 13 | UVW_INLINE void details::connect_req::connect_callback(uv_connect_t *req, int status) { 14 | if(auto ptr = reserve(req); status) { 15 | ptr->publish(error_event{status}); 16 | } else { 17 | ptr->publish(connect_event{}); 18 | } 19 | } 20 | 21 | UVW_INLINE void details::shutdown_req::shoutdown_callback(uv_shutdown_t *req, int status) { 22 | if(auto ptr = reserve(req); status) { 23 | ptr->publish(error_event{status}); 24 | } else { 25 | ptr->publish(shutdown_event{}); 26 | } 27 | } 28 | 29 | UVW_INLINE int details::shutdown_req::shutdown(uv_stream_t *hndl) { 30 | return this->leak_if(uv_shutdown(raw(), hndl, &shoutdown_callback)); 31 | } 32 | 33 | } // namespace uvw 34 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/timer.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "timer.h" 3 | #endif 4 | 5 | #include "config.h" 6 | 7 | namespace uvw { 8 | 9 | UVW_INLINE void timer_handle::start_callback(uv_timer_t *hndl) { 10 | timer_handle &timer = *(static_cast(hndl->data)); 11 | timer.publish(timer_event{}); 12 | } 13 | 14 | UVW_INLINE int timer_handle::init() { 15 | return leak_if(uv_timer_init(parent().raw(), raw())); 16 | } 17 | 18 | UVW_INLINE int timer_handle::start(timer_handle::time timeout, timer_handle::time repeat) { 19 | return uv_timer_start(raw(), &start_callback, timeout.count(), repeat.count()); 20 | } 21 | 22 | UVW_INLINE int timer_handle::stop() { 23 | return uv_timer_stop(raw()); 24 | } 25 | 26 | UVW_INLINE int timer_handle::again() { 27 | return uv_timer_again(raw()); 28 | } 29 | 30 | UVW_INLINE void timer_handle::repeat(timer_handle::time repeat) { 31 | uv_timer_set_repeat(raw(), repeat.count()); 32 | } 33 | 34 | UVW_INLINE timer_handle::time timer_handle::repeat() { 35 | return time{uv_timer_get_repeat(raw())}; 36 | } 37 | 38 | UVW_INLINE timer_handle::time timer_handle::due_in() { 39 | return time{uv_timer_get_due_in(raw())}; 40 | } 41 | 42 | } // namespace uvw 43 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/work.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UVW_AS_LIB 2 | # include "work.h" 3 | #endif 4 | 5 | #include 6 | 7 | #include "config.h" 8 | 9 | namespace uvw { 10 | 11 | UVW_INLINE work_req::work_req(loop::token token, std::shared_ptr ref, task t) 12 | : request{token, std::move(ref)}, func{t} {} 13 | 14 | UVW_INLINE void work_req::work_callback(uv_work_t *req) { 15 | static_cast(req->data)->func(); 16 | } 17 | 18 | UVW_INLINE void work_req::after_work_callback(uv_work_t* req, int status) { 19 | if(auto ptr = reserve(req); status) { 20 | ptr->publish(error_event{status}); 21 | } else { 22 | ptr->publish(work_event{}); 23 | } 24 | } 25 | 26 | UVW_INLINE int work_req::queue() { 27 | return this->leak_if(uv_queue_work(parent().raw(), raw(), &work_callback, &after_work_callback)); 28 | } 29 | 30 | } // namespace uvw 31 | -------------------------------------------------------------------------------- /thirdparty/uvw/uvw/work.h: -------------------------------------------------------------------------------- 1 | #ifndef UVW_WORK_INCLUDE_H 2 | #define UVW_WORK_INCLUDE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "loop.h" 8 | #include "request.hpp" 9 | 10 | namespace uvw { 11 | 12 | /*! @brief Work event. */ 13 | struct work_event {}; 14 | 15 | /** 16 | * @brief The work request. 17 | * 18 | * It runs user code using a thread from the threadpool and gets notified in the 19 | * loop thread by means of an event. 20 | * 21 | * To create a `work_req` through a `loop`, arguments follow: 22 | * 23 | * * A valid instance of a `Task`, that is of type `std::function`. 24 | * 25 | * See the official 26 | * [documentation](http://docs.libuv.org/en/v1.x/threadpool.html) 27 | * for further details. 28 | */ 29 | class work_req final: public request { 30 | static void work_callback(uv_work_t *req); 31 | static void after_work_callback(uv_work_t *req, int status); 32 | 33 | public: 34 | using task = std::function; 35 | 36 | explicit work_req(loop::token token, std::shared_ptr ref, task t); 37 | 38 | /** 39 | * @brief Runs the given task in a separate thread. 40 | * 41 | * A work event will be emitted on the loop thread when the task is 42 | * finished.
43 | * This request can be cancelled with `cancel()`. 44 | * 45 | * @return Underlying return value. 46 | */ 47 | int queue(); 48 | 49 | private: 50 | task func{}; 51 | }; 52 | 53 | } // namespace uvw 54 | 55 | #ifndef UVW_AS_LIB 56 | # include "work.cpp" 57 | #endif 58 | 59 | #endif // UVW_WORK_INCLUDE_H 60 | --------------------------------------------------------------------------------