├── .clang-format ├── .github └── workflows │ └── knuth.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── README.md ├── cfg ├── btc-mainnet.cfg └── ltc-mainnet.cfg ├── conan.lock ├── conanfile.py ├── console ├── cfg1 ├── config_test.cpp ├── demo.c ├── ds_proof.c ├── error_test.cpp ├── get_block.c ├── main copy.c ├── main.c ├── main.cpp ├── main_744727.cpp ├── main_payment_addr_cash_aware.cpp ├── node_info.c ├── organize.cpp ├── platform_test.cpp ├── print_headers.cpp ├── test_deadlock.cpp ├── test_header_hash.cpp ├── test_libconfig.cpp ├── test_wallet.c ├── test_wallet.cpp ├── test_wallet2.c └── test_wallet_manager.c ├── docs └── Doxyfile ├── helpers ├── build_debug.bat └── build_release.bat ├── history.txt ├── include └── kth │ ├── capi.h │ └── capi │ ├── binary.h │ ├── capi.h │ ├── chain │ ├── block.h │ ├── block_indexes.h │ ├── block_list.h │ ├── chain.h │ ├── chain_async.h │ ├── chain_other.h │ ├── chain_sync.h │ ├── coin_selection_algorithm.h │ ├── compact_block.h │ ├── double_spend_proof.h │ ├── double_spend_proof_spender.h │ ├── get_blocks.h │ ├── get_headers.h │ ├── header.h │ ├── history_compact.h │ ├── history_compact_list.h │ ├── input.h │ ├── input_list.h │ ├── mempool_transaction.h │ ├── mempool_transaction_list.h │ ├── merkle_block.h │ ├── opcode.h │ ├── operation.h │ ├── operation_list.h │ ├── output.h │ ├── output_list.h │ ├── output_point.h │ ├── point.h │ ├── point_list.h │ ├── rule_fork.h │ ├── script.h │ ├── script_pattern.h │ ├── script_version copy.h │ ├── script_version.h │ ├── sighash_algorithm.h │ ├── stealth_compact.h │ ├── stealth_compact_list.h │ ├── token_capability.h │ ├── token_data.h │ ├── token_kind.h │ ├── transaction.h │ ├── transaction_list.h │ ├── utxo.h │ └── utxo_list.h │ ├── config │ ├── authority.h │ ├── authority_helpers.hpp │ ├── blockchain_helpers.hpp │ ├── blockchain_settings.h │ ├── checkpoint.h │ ├── checkpoint_helpers.hpp │ ├── database_helpers.hpp │ ├── database_settings.h │ ├── endpoint.h │ ├── endpoint_helpers.hpp │ ├── helpers.hpp │ ├── network_helpers.hpp │ ├── network_settings.h │ ├── node_helpers.hpp │ ├── node_settings.h │ ├── settings.h │ └── settings_helper.hpp │ ├── conversions.hpp │ ├── double_list.h │ ├── error.h │ ├── hash.h │ ├── hash_list.h │ ├── helpers.hpp │ ├── libconfig │ └── libconfig.h │ ├── list_creator.h │ ├── node.h │ ├── node │ └── settings.h │ ├── node_info.h │ ├── p2p │ └── p2p.h │ ├── platform.h │ ├── primitives.h │ ├── string_list.h │ ├── type_conversions.h │ ├── u32_list.h │ ├── u64_list.h │ ├── version.h │ ├── visibility.h │ ├── vm │ ├── interpreter.h │ ├── metrics.h │ └── program.h │ └── wallet │ ├── conversions.hpp │ ├── ec_compressed_list.h │ ├── ec_private.h │ ├── ec_public.h │ ├── elliptic_curve.h │ ├── hd_lineage.h │ ├── hd_private.h │ ├── hd_public.h │ ├── payment_address.h │ ├── payment_address_list.h │ ├── primitives.h │ ├── raw_output.h │ ├── raw_output_list.h │ ├── transaction_functions.h │ ├── wallet.h │ ├── wallet_data.h │ └── wallet_manager.h ├── src ├── binary.cpp ├── chain │ ├── block.cpp │ ├── block_indexes.cpp │ ├── block_list.cpp │ ├── chain_async.cpp │ ├── chain_other.cpp │ ├── chain_sync.cpp │ ├── compact_block.cpp │ ├── double_spend_proof.cpp │ ├── double_spend_proof_spender.cpp │ ├── get_blocks.cpp │ ├── get_headers.cpp │ ├── header.cpp │ ├── history_compact.cpp │ ├── history_compact_list.cpp │ ├── input.cpp │ ├── input_list.cpp │ ├── mempool_transaction.cpp │ ├── mempool_transaction_list.cpp │ ├── merkle_block.cpp │ ├── opcode.cpp │ ├── operation.cpp │ ├── operation_list.cpp │ ├── output.cpp │ ├── output_list.cpp │ ├── output_point.cpp │ ├── point.cpp │ ├── point_list.cpp │ ├── script.cpp │ ├── stealth_compact.cpp │ ├── stealth_compact_list.cpp │ ├── token_data.cpp │ ├── transaction.cpp │ ├── transaction_list.cpp │ ├── utxo.cpp │ └── utxo_list.cpp ├── config │ ├── authority.cpp │ ├── blockchain_settings.cpp │ ├── checkpoint.cpp │ ├── database_settings.cpp │ ├── endpoint.cpp │ ├── network_settings.cpp │ ├── node_settings.cpp │ └── settings.cpp ├── double_list.cpp ├── hash.cpp ├── hash_list.cpp ├── libconfig │ └── libconfig.cpp ├── node.cpp ├── node │ └── settings.cpp ├── node_info.cpp ├── p2p │ └── p2p.cpp ├── platform.cpp ├── string_list.cpp ├── u32_list.cpp ├── u64_list.cpp ├── vm │ ├── interpreter.cpp │ └── program.cpp └── wallet │ ├── ec_compressed_list.cpp │ ├── ec_private.cpp │ ├── ec_public.cpp │ ├── elliptic_curve.cpp │ ├── hd_private.cpp │ ├── hd_public.cpp │ ├── payment_address.cpp │ ├── payment_address_list.cpp │ ├── raw_output.cpp │ ├── raw_output_list.cpp │ ├── transaction_functions.cpp │ ├── wallet.cpp │ ├── wallet_data.cpp │ └── wallet_manager.cpp └── test ├── doctest.h └── queries.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | cmake-build-debug/ 2 | cmake-build-release/ 3 | .idea/ 4 | build/ 5 | test_console.dir/ 6 | x64/ 7 | 8 | conanfile.pyc 9 | 10 | python_console/blockchain/ 11 | python_console/debug.log 12 | python_console/error.log 13 | python_console/archive/ 14 | python_console/hosts.cache 15 | 16 | node_console/archive/ 17 | node_console/blockchain/ 18 | node_console/hosts.cache 19 | node_console/debug.log 20 | node_console/error.log 21 | node_console/node_modules/ 22 | 23 | docs/html 24 | docs/latex 25 | 26 | .vscode/ 27 | __pycache__/ 28 | mypkg/ 29 | *.sh 30 | blockchain/ 31 | build_release/ 32 | .DS_Store 33 | CMakeUserPresets.json 34 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ci_utils"] 2 | path = ci_utils 3 | url = https://github.com/k-nuth/ci-utils.git 4 | -------------------------------------------------------------------------------- /cfg/ltc-mainnet.cfg: -------------------------------------------------------------------------------- 1 | [log] 2 | debug_file = debug.log 3 | error_file = error.log 4 | archive_directory = archive 5 | rotation_size = 10000000 6 | maximum_archive_size = 4294967296 7 | minimum_free_space = 0 8 | 9 | [network] 10 | threads = 1 11 | protocol_maximum = 70012 12 | protocol_minimum = 31402 13 | services = 1 14 | identifier = 3686187259 15 | inbound_port = 9333 16 | inbound_connections = 0 17 | outbound_connections = 1 18 | manual_attempt_limit = 0 19 | connect_batch_size = 5 20 | connect_timeout_seconds = 5 21 | channel_handshake_seconds = 30 22 | channel_heartbeat_minutes = 5 23 | channel_inactivity_minutes = 30 24 | channel_expiration_minutes = 1440 25 | channel_germination_seconds = 30 26 | host_pool_capacity = 1000 27 | relay_transactions = false 28 | hosts_file = hosts-testnet.cache 29 | self = 0.0.0.0:0 30 | seed = dnsseed.litecointools.com:9333 31 | seed = seed-a.litecoin.loshan.co.uk:9333 32 | seed = dnsseed.litecoinpool.org:9333 33 | 34 | [database] 35 | directory = litecoin-mainnet-node 36 | file_growth_rate = 50 37 | kth_block_table_buckets = 650000 38 | transaction_table_buckets = 110000000 39 | spend_table_buckets = 250000000 40 | history_table_buckets = 107000000 41 | 42 | [blockchain] 43 | threads = 1 44 | priority = true 45 | use_libconsensus = false 46 | use_testnet_rules = false 47 | flush_reorganizations = false 48 | transaction_pool_consistency = false 49 | transaction_pool_capacity = 2000 50 | block_pool_capacity = 50 51 | checkpoint = 12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2:0 52 | 53 | [node] 54 | kth_block_timeout_seconds = 5 55 | initial_connections = 8 56 | transaction_pool_refresh = true 57 | -------------------------------------------------------------------------------- /conan.lock: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.5", 3 | "requires": [ 4 | "zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1736442063.163", 5 | "tiny-aes-c/1.0.0#0f0a930c53a0d33d5a91a4c930f836ab%1743667795.615", 6 | "spdlog/1.15.1#92e99f07f134481bce4b70c1a41060e7%1738512735.307", 7 | "secp256k1/0.22.0#a10d5f434e85bf2f46aaa26f1195ded0%1744820345.023803", 8 | "openssl/3.4.1#638c4c4df8ecdef1f7aa73fc0d07fde6%1743184906.855", 9 | "node/0.57.0#ff4396e32436bcd5aa389ece2acdfc00%1747385118.527", 10 | "network/0.53.0#91ce02702d1470b22f344d26e9a78ddc%1747082418.005", 11 | "lmdb/0.9.32#062e23b9624da8798d818cf697a2d6ba%1741857861.053", 12 | "libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1%1725632951.012", 13 | "infrastructure/0.42.0#8de16c23c8ac86209f82fe8921a8c82d%1746106522.971", 14 | "gmp/6.3.0#df20ffb6d21c34d67704305bcd1dea9e%1716966936.742", 15 | "fmt/11.1.3#8364f0feb23ee32e4b870455edb552ae%1738512514.619", 16 | "expected-lite/0.8.0#f87b3ec27a4f46894950b70f8d08af24%1717770563.402", 17 | "domain/0.44.0#3726a5ca051323c5ebe2e7603c8a83c3%1746106695.3857772", 18 | "database/0.50.0#db3df3eab22448b0553fd63e15fa0235%1746106848.6596892", 19 | "ctre/3.9.0#318a83b26476a59466795daac928f3ec%1716966898.508", 20 | "consensus/0.38.0#887bf96cbdf3e1e29524c4dcf624757d%1747383110.898", 21 | "bzip2/1.0.8#00b4a4658791c1f06914e087f0e792f5%1744714891.077", 22 | "boost/1.86.0#b389df94f8fa0e15145bc66322ca0e82%1744128935.009", 23 | "blockchain/0.50.0#27722829a557e7be16035d3973df0b22%1747384416.491" 24 | ], 25 | "build_requires": [ 26 | "m4/1.4.19#b38ced39a01e31fef5435bc634461fd2%1700758725.451", 27 | "b2/5.3.2#7b5fabfe7088ae933fb3e78302343ea0%1744766677.76" 28 | ], 29 | "python_requires": [], 30 | "config_requires": [] 31 | } -------------------------------------------------------------------------------- /console/cfg1: -------------------------------------------------------------------------------- 1 | [log] 2 | archive_directory = temp/log-bch-testnet1/ 3 | debug_file = temp/log-bch-testnet1/debug.log 4 | error_file = temp/log-bch-testnet1/error.log 5 | rotation_size = 100000000 6 | minimum_free_space = 0 7 | verbose = true 8 | 9 | [network] 10 | protocol_maximum = 70015 11 | protocol_minimum = 31402 12 | identifier = 4109624820 13 | outbound_connections = 0 14 | inbound_connections = 1 15 | inbound_port = 18333 16 | channel_expiration_minutes = 1440 17 | hosts_file = temp/hosts-bch-testnet1.cache 18 | self = 0.0.0.0:0 19 | seed = testnet-seed.bitcoinabc.org:18333 20 | seed = testnet-seed-abc.bitcoinforks.org:18333 21 | seed = testnet-seed.bitcoinunlimited.info:18333 22 | seed = testnet-seed.deadalnix.me:18333 23 | seed = testnet-seeder.criptolayer.net:18333 24 | 25 | [database] 26 | directory = temp/database-bch-testnet1 27 | flush_writes = true 28 | 29 | [blockchain] 30 | # Testnet-bch 31 | checkpoint = 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206:0 32 | 33 | [fork] 34 | easy_blocks = false 35 | retarget = false 36 | bip16 = true 37 | bip30 = true 38 | bip34 = true 39 | bip66 = true 40 | bip65 = true 41 | bip90 = true 42 | 43 | [node] 44 | relay_transactions = true 45 | compact_blocks_high_bandwidth = true 46 | # RPC-CONFG 47 | zmq_publisher_port = 5556 48 | rpc_port = 18332 49 | -------------------------------------------------------------------------------- /console/config_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | 6 | // Copyright (c) 2016-2024 Knuth Project developers. 7 | // Distributed under the MIT software license, see the accompanying 8 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | int main(int argc, char* argv[]) { 30 | 31 | kth_checkpoint cp1 {kth_str_to_hash("000000000000000000eb9bc1f9557dc9e2cfe576f57a52f6be94720b338029e4"), 478557}; 32 | kth_checkpoint cp2 {kth_str_to_hash("0000000000000000011865af4122fe3b144e2cbeea86142e8ff2fb4107352d43"), 478558}; 33 | kth_checkpoint cp3 {kth_str_to_hash("000000000000000000651ef99cb9fcbe0dadde1d424bd9f15ff20136191a5eec"), 478559}; 34 | 35 | kth_blockchain_settings blk_settings = kth_config_blockchain_settings_default(kth_network_mainnet); 36 | assert(blk_settings.checkpoint_count == 57); 37 | assert(strcmp(kth_hash_to_str(blk_settings.checkpoints[28].hash), "000000000000000000651ef99cb9fcbe0dadde1d424bd9f15ff20136191a5eec") == 0); 38 | assert(blk_settings.checkpoints[28].height == 478559); 39 | 40 | kth_database_settings db_settings = kth_config_database_settings_default(kth_network_mainnet); 41 | assert(strcmp(db_settings.directory, "blockchain") == 0); 42 | 43 | kth_network_settings net_settings = kth_config_network_settings_default(kth_network_mainnet); 44 | assert(strcmp(net_settings.hosts_file, "hosts.cache") == 0); 45 | 46 | kth_node_settings node_settings = kth_config_node_settings_default(kth_network_mainnet); 47 | assert(node_settings.block_latency_seconds == 60); 48 | 49 | kth_settings settings = kth_config_settings_default(kth_network_mainnet); 50 | assert(settings.chain.checkpoint_count == 57); 51 | assert(strcmp(kth_hash_to_str(settings.chain.checkpoints[28].hash), "000000000000000000651ef99cb9fcbe0dadde1d424bd9f15ff20136191a5eec") == 0); 52 | assert(settings.chain.checkpoints[28].height == 478559); 53 | assert(strcmp(settings.database.directory, "blockchain") == 0); 54 | assert(strcmp(settings.network.hosts_file, "hosts.cache") == 0); 55 | assert(settings.node.block_latency_seconds == 60); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /console/demo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | // #include 5 | 6 | int main() { 7 | 8 | kth_settings config = kth_config_settings_default(kth_network_mainnet); 9 | 10 | auto node = kth_node_construct(&config, stdout, stderr); 11 | 12 | kth_node_destruct(node); 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /console/ds_proof.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | #include 7 | 8 | int ds_proof_handler(kth_node_t node, kth_chain_t chain, void* ctx, kth_error_code_t error, kth_double_spend_proof_t dsp) { 9 | printf("Caution: a Double-Spend Proof notification has been received."); 10 | return 1; 11 | } 12 | 13 | int main() { 14 | kth_settings* settings; 15 | char* error_message; 16 | kth_bool_t ok = kth_config_settings_get_from_file("mainnet.cfg", &settings, &error_message); 17 | 18 | if ( ! ok) { 19 | printf("error: %s", error_message); 20 | return -1; 21 | } 22 | 23 | kth_node_t node = kth_node_construct(settings, 1); 24 | kth_node_init_and_run_wait(node); 25 | kth_chain_t chain = kth_node_get_chain(node); 26 | 27 | kth_chain_subscribe_ds_proof(node, chain, NULL, ds_proof_handler); 28 | 29 | 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /console/get_block.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void handler(kth_chain_t chain, void* ctx, kth_error_code_t error, kth_block_t block, kth_size_t height) { 11 | if (error != kth_ec_success) { 12 | printf("kth_chain_async_block_by_height - error: %d\n", error); 13 | return; 14 | } 15 | printf("kth_chain_async_block_by_height - error: %d, height: %llu\n", error, height); 16 | kth_chain_block_destruct(block); 17 | } 18 | 19 | int main() { 20 | kth_settings settings = kth_config_settings_default(kth_network_mainnet); 21 | settings.database.db_max_size = 2 * 1024 * 1024; // 2MiB 22 | settings.database.directory = "blocks"; 23 | settings.database.db_mode = kth_db_mode_pruned; 24 | 25 | assert(settings.database.db_max_size == 2 * 1024 * 1024); 26 | assert(strcmp(settings.database.directory, "blockchain") == 0); 27 | assert(settings.database.db_mode == kth_db_mode_normal); 28 | 29 | 30 | // kth_db_mode_pruned = 0, 31 | // kth_db_mode_normal = 1, 32 | // kth_db_mode_full_indexed = 2 33 | 34 | kth_node_t node = kth_node_construct(&settings, 1); 35 | kth_error_code_t res = kth_node_init_run_sync(node, kth_start_modules_just_chain); 36 | printf("kth_node_init_run_sync - res: %d\n", res); 37 | kth_chain_t chain = kth_node_get_chain(node); 38 | // kth_block_t out_block; 39 | // kth_size_t out_height; 40 | // res = kth_chain_sync_block_by_height(chain, 0, &out_block, &out_height); 41 | // printf("kth_chain_sync_block_by_height - res: %d, height: %llu\n", res, out_height); 42 | 43 | 44 | kth_chain_async_block_by_height(chain, NULL, 0, handler); 45 | 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /console/main copy.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | void history_fetch_handler(int error, kth_history_compact_list_t list) { 14 | // printf("C callback (history_fetch_handler) called\n"); 15 | // printf("Calling Python callback\n"); 16 | 17 | PyObject* arglist = Py_BuildValue("(iO)", error, history_list); 18 | PyObject* result = PyObject_CallObject(global_callback, arglist); 19 | Py_DECREF(arglist); 20 | } 21 | 22 | int main(int argc, char* argv[]) { 23 | 24 | // kth_node_t exec = kth_node_construct("/home/fernando/exec/btc-mainnet.cfg", stdout, stderr); 25 | kth_node_t exec = kth_node_construct("/home/fernando/dev/kth/cs-api/tests/bch/config/invalid.cfg", stdout, stderr); 26 | 27 | int res1 = kth_node_initchain(exec); 28 | int res2 = kth_node_run(exec); 29 | 30 | // fetch_merkle_block_by_height(exec, 0, NULL); 31 | 32 | fetch_history(exec, "134HfD2fdeBTohfx8YANxEpsYXsv5UoWyz", 0, 0, history_fetch_handler); 33 | 34 | 35 | using namespace std::chrono_literals; 36 | std::cout << "Hello waiter" << std::endl; 37 | auto start = std::chrono::high_resolution_clock::now(); 38 | std::this_thread::sleep_for(2s); 39 | auto end = std::chrono::high_resolution_clock::now(); 40 | std::chrono::duration elapsed = end-start; 41 | std::cout << "Waited " << elapsed.count() << " ms\n"; 42 | 43 | 44 | kth_node_destruct(exec); 45 | 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /console/node_info.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | int main(int argc, char* argv[]) { 10 | 11 | printf("C-API version: %s\n", kth_node_capi_version()); 12 | printf("C++-API version: %s\n", kth_node_cppapi_version()); 13 | printf("Microarchitecture: %s\n", kth_node_microarchitecture()); 14 | printf("March names: %s\n", kth_node_march_names()); 15 | printf("Currency symbol: %s\n", kth_node_currency_symbol()); 16 | printf("Currency: %s\n", kth_node_currency()); 17 | printf("Build timestamp: %u\n", kth_node_cppapi_build_timestamp()); 18 | } 19 | -------------------------------------------------------------------------------- /console/platform_test.cpp: -------------------------------------------------------------------------------- 1 | // // Copyright (c) 2016-2024 Knuth Project developers. 2 | // // Distributed under the MIT software license, see the accompanying 3 | // // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | 6 | // // Copyright (c) 2016-2024 Knuth Project developers. 7 | // // Distributed under the MIT software license, see the accompanying 8 | // // file COPYING or http://www.opensource.org/licenses/mit-license.php. 9 | 10 | // #include 11 | 12 | // #include 13 | // #include 14 | // #include 15 | // #include 16 | 17 | // #include 18 | // #include 19 | 20 | // #include 21 | // #include 22 | // #include 23 | 24 | // int main(int argc, char* argv[]) { 25 | 26 | // kth_bool_t ok; 27 | // char* error_message = nullptr; 28 | // // auto settings = kth_config_settings_get_from_file("/home/fernando/dev/kth/cs-api/console/node.cfg", &ok, &error_message); 29 | // // auto settings = kth_config_settings_get_from_file("/home/fernando/dev/kth/cs-api/console/node_error.cfg", &ok, &error_message); 30 | // auto settings = kth_config_settings_get_from_file("/home/fernando/dev/kth/cs-api/console/asdasdasds.cfg", &ok, &error_message); 31 | 32 | // if ( ! ok) { 33 | // printf("%s\n", error_message); 34 | // } 35 | 36 | 37 | // // auto array = kth_platform_allocate_array_of_strings(3); 38 | 39 | // // // kth_platform_allocate_string_at(&array[0], 6); 40 | // // // strcpy(array[0], "hello"); 41 | 42 | // // // kth_platform_allocate_string_at(&array[1], 6); 43 | // // // strcpy(array[1], "world"); 44 | 45 | // // // kth_platform_allocate_string_at(&array[2], 6); 46 | // // // strcpy(array[2], "knuth"); 47 | 48 | 49 | // // auto hello = kth_platform_allocate_and_copy_string_at(array, 0, "hello"); 50 | // // auto world = kth_platform_allocate_and_copy_string_at(array, 1, "world"); 51 | // // auto knuth = kth_platform_allocate_and_copy_string_at(array, 2, "knuth"); 52 | 53 | // // printf("%s\n", hello); 54 | // // printf("%s\n", world); 55 | // // printf("%s\n", knuth); 56 | 57 | // // printf("%s\n", array[0]); 58 | // // printf("%s\n", array[1]); 59 | // // printf("%s\n", array[2]); 60 | 61 | 62 | // return 0; 63 | // } 64 | -------------------------------------------------------------------------------- /console/test_deadlock.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int main() { 12 | std::cout << "Initializing...\n"; 13 | 14 | // using (var node = new Knuth.Node("node.cfg")) { 15 | // auto node = kth_node_construct_fd("/Users/fernando/dev/kth/cs-api/console/node.cfg", 0, 0); 16 | auto node = kth_node_construct_fd("/Users/fernando/dev/kth/cs-api/console/node_throttling.cfg", 0, 0); 17 | { 18 | // var result = await node.InitAndRunAsync(); 19 | // kth_node_init_and_run(node, handlerPtr, internalRunNodeHandler_); 20 | auto result = kth_node_init_and_run_wait(node); 21 | if (result != 0) { 22 | std::cout << "kth_node_init_and_run_wait failed; error code: " << result << std::endl; 23 | std::cout << "sleeping 5 seconds" << std::endl; 24 | std::this_thread::sleep_for(std::chrono::seconds(5)); 25 | } 26 | // kth_node_close(node); 27 | 28 | std::cout << "main thread: " << std::this_thread::get_id() << std::endl; 29 | 30 | std::thread t1([&] { 31 | std::cout << "t1 thread: " << std::this_thread::get_id() << std::endl; 32 | kth_node_close(node); 33 | }); 34 | t1.join(); 35 | } 36 | } 37 | 38 | 39 | 40 | 41 | 42 | // void history_fetch_handler(int error, history_compact_list_t list) { 43 | // // printf("C callback (history_fetch_handler) called\n"); 44 | // // printf("Calling Python callback\n"); 45 | 46 | // PyObject* arglist = Py_BuildValue("(iO)", error, history_list); 47 | // PyObject* result = PyObject_CallObject(global_callback, arglist); 48 | // Py_DECREF(arglist); 49 | // } 50 | 51 | // int main(int argc, char* argv[]) { 52 | 53 | // kth_node_t exec = kth_node_construct("/home/fernando/exec/btc-mainnet.cfg", stdout, stderr); 54 | 55 | // int res1 = kth_node_initchain(exec); 56 | // int res2 = kth_node_run(exec); 57 | 58 | // // fetch_merkle_block_by_height(exec, 0, NULL); 59 | 60 | // fetch_history(exec, "134HfD2fdeBTohfx8YANxEpsYXsv5UoWyz", 0, 0, history_fetch_handler); 61 | 62 | 63 | // using namespace std::chrono_literals; 64 | // std::cout << "Hello waiter" << std::endl; 65 | // auto start = std::chrono::high_resolution_clock::now(); 66 | // std::this_thread::sleep_for(2s); 67 | // auto end = std::chrono::high_resolution_clock::now(); 68 | // std::chrono::duration elapsed = end-start; 69 | // std::cout << "Waited " << elapsed.count() << " ms\n"; 70 | 71 | 72 | // kth_node_destruct(exec); 73 | 74 | // return 0; 75 | // } 76 | 77 | -------------------------------------------------------------------------------- /console/test_libconfig.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | int main(int argc, char* argv[]) { 10 | 11 | auto config = kth_libconfig_get(); 12 | 13 | std::cout << "log_library: " << config.log_library << '\n'; 14 | std::cout << "use_libmdbx: " << config.use_libmdbx << '\n'; 15 | std::cout << "version: " << config.version << '\n'; 16 | std::cout << "microarchitecture_id: " << config.microarchitecture_id << '\n'; 17 | std::cout << "currency: " << config.currency << '\n'; 18 | std::cout << "mempool: " << config.mempool << '\n'; 19 | // std::cout << "db_mode: " << config.db_mode << '\n'; 20 | std::cout << "db_readonly: " << config.db_readonly << '\n'; 21 | std::cout << "debug_mode: " << config.debug_mode << '\n'; 22 | std::cout << "architecture: " << config.architecture << '\n'; 23 | std::cout << "os_name: " << config.os_name << '\n'; 24 | std::cout << "compiler_name: " << config.compiler_name << '\n'; 25 | std::cout << "compiler_version: " << config.compiler_version << '\n'; 26 | std::cout << "optimization_level: " << config.optimization_level << '\n'; 27 | std::cout << "build_timestamp: " << config.build_timestamp << '\n'; 28 | 29 | std::cout << "endianness: " << config.endianness << '\n'; 30 | std::cout << "size_int: " << int(config.type_sizes.size_int) << '\n'; 31 | std::cout << "size_long: " << int(config.type_sizes.size_long) << '\n'; 32 | std::cout << "size_pointer: " << int(config.type_sizes.size_pointer) << '\n'; 33 | } 34 | -------------------------------------------------------------------------------- /console/test_wallet2.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | // #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | void print_hex(uint8_t const* data, size_t n) { 32 | while (n != 0) { 33 | printf("%02x", *data); 34 | ++data; 35 | --n; 36 | } 37 | printf("\n"); 38 | } 39 | 40 | #define MAINNET_P2KH 0x00 41 | #define MAINNET_P2SH 0x05 42 | 43 | 44 | int main(int argc, char* argv[]) { 45 | // m/44'/145'/0' 46 | char const* m44h145h0h_xpub_str = "xpub..."; 47 | 48 | kth_hd_public_t m44h145h0h = kth_wallet_hd_public_construct_string(m44h145h0h_xpub_str); 49 | kth_hd_public_t m44h145h0h0 = kth_wallet_hd_public_derive_public(m44h145h0h, 0); 50 | 51 | printf("BIP44 Account Extended Public Key: %s\n", kth_wallet_hd_public_encoded(m44h145h0h)); 52 | printf("BIP32 Account Extended Public Key: %s\n", kth_wallet_hd_public_encoded(m44h145h0h0)); 53 | 54 | // print addresses 55 | for (size_t i = 0; i < 20; ++i) { 56 | kth_hd_public_t key = kth_wallet_hd_public_derive_public(m44h145h0h0, i); 57 | kth_ec_compressed_t point = kth_wallet_hd_public_point(key); 58 | kth_ec_public_t ecp = kth_wallet_ec_public_construct_from_point(&point, 1); 59 | kth_payment_address_t pa = kth_wallet_ec_public_to_payment_address(ecp, MAINNET_P2KH); 60 | printf("%s\n", kth_wallet_payment_address_encoded_cashaddr(pa, 0)); 61 | } 62 | 63 | printf("\n"); 64 | } 65 | -------------------------------------------------------------------------------- /console/test_wallet_manager.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | // #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | void print_hex(uint8_t const* data, size_t n) { 34 | while (n != 0) { 35 | printf("%02x", *data); 36 | ++data; 37 | --n; 38 | } 39 | printf("\n"); 40 | } 41 | 42 | int main(int argc, char* argv[]) { 43 | kth_wallet_data_t wallet_data; 44 | kth_error_code_t code = kth_wallet_create_wallet( 45 | "12345678", 46 | "", 47 | &wallet_data); 48 | 49 | printf("code: %d\n", code); 50 | // printf("wallet_data: %s\n", kth_wallet_wallet_data_encoded(wallet_data)); 51 | 52 | kth_string_list_t mnemonics = kth_wallet_wallet_data_mnemonics(wallet_data); 53 | 54 | kth_size_t count = kth_core_string_list_count(mnemonics); 55 | printf("count: %d\n", count); 56 | 57 | for (kth_size_t i = 0; i < count; i++) { 58 | char const* mnemonic = kth_core_string_list_nth(mnemonics, i); 59 | printf("mnemonic: %s\n", mnemonic); 60 | } 61 | 62 | kth_encrypted_seed_t seed = kth_wallet_wallet_data_encrypted_seed(wallet_data); 63 | print_hex(seed.hash, KTH_BITCOIN_ENCRYPTED_SEED_SIZE); 64 | 65 | 66 | // ------------------------------------------------------------------------- 67 | 68 | kth_longhash_t decrypted_seed; 69 | kth_error_code_t code2 = kth_wallet_decrypt_seed( 70 | "12345678", 71 | &seed, 72 | &decrypted_seed); 73 | 74 | printf("code2: %d\n", code2); 75 | print_hex(decrypted_seed.hash, KTH_BITCOIN_LONG_HASH_SIZE); 76 | } 77 | -------------------------------------------------------------------------------- /helpers/build_debug.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo %KTH_BRANCH% 4 | Set KTH_BRANCH=master 5 | echo %KTH_BRANCH% 6 | ​ 7 | if exist build mkdir build 8 | cd build 9 | conan remove --locks 10 | REM conan install .. -s build_type=Debug --build=m4 11 | conan install .. -s build_type=Debug -o db=full -s compiler.runtime=MDd --build=missing 12 | ​ 13 | cmake .. -G "Visual Studio 16 2019" -DCMAKE_VERBOSE_MAKEFILE=ON ^ 14 | -DUSE_CONAN=ON ^ 15 | -DCURRENCY=BCH ^ 16 | -DBINLOG=OFF ^ 17 | -DWITH_CONSOLE_CAPI=ON ^ 18 | -DDB_READONLY_MODE=OFF ^ 19 | -DENABLE_TESTS=OFF ^ 20 | -DWITH_TESTS=OFF ^ 21 | -DWITH_TOOLS=OFF ^ 22 | -DENABLE_ECMULT_STATIC_PRECOMPUTATION=OFF ^ 23 | -DDB_NEW=ON ^ 24 | -DDB_NEW_BLOCKS=ON ^ 25 | -DDB_NEW_FULL=ON ^ 26 | -DCMAKE_BUILD_TYPE=Debug 27 | ​ 28 | REM cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON -DWITH_CONSOLE_CAPI=OFF -DDB_READONLY_MODE=OFF -DDB_NEW=ON -DDB_NEW_BLOCKS=ON -DENABLE_TESTS=OFF -DWITH_TESTS=OFF -DWITH_TOOLS=OFF -DENABLE_ECMULT_STATIC_PRECOMPUTATION=OFF -DCMAKE_BUILD_TYPE=Debug 29 | REM ninja -j4 30 | cmake --build . -j 4 -------------------------------------------------------------------------------- /helpers/build_release.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo %KTH_BRANCH% 4 | Set KTH_BRANCH=master 5 | echo %KTH_BRANCH% 6 | ​ 7 | if exist build_release mkdir build_release 8 | cd build_release 9 | conan remove --locks 10 | REM conan install .. --build=m4 11 | conan install .. -o db=full -o c-api:march_id=4fZKi37a595hP -s build_type=Release -s compiler.runtime=MD --build=missing 12 | ​ 13 | REM cmake .. -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON^ 14 | cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON^ 15 | -DUSE_CONAN=ON^ 16 | -DCURRENCY=BCH^ 17 | -DBINLOG=OFF^ 18 | -DWITH_CONSOLE_CAPI=ON^ 19 | -DDB_READONLY_MODE=OFF^ 20 | -DENABLE_TESTS=OFF^ 21 | -DWITH_TESTS=OFF^ 22 | -DWITH_TOOLS=OFF^ 23 | -DENABLE_ECMULT_STATIC_PRECOMPUTATION=OFF^ 24 | -DDB_NEW=ON^ 25 | -DDB_NEW_BLOCKS=ON^ 26 | -DDB_NEW_FULL=ON 27 | 28 | ​ 29 | REM cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON -DWITH_CONSOLE_CAPI=OFF -DDB_READONLY_MODE=OFF -DDB_NEW=ON -DDB_NEW_BLOCKS=ON -DENABLE_TESTS=OFF -DWITH_TESTS=OFF -DWITH_TOOLS=OFF -DENABLE_ECMULT_STATIC_PRECOMPUTATION=OFF -DCMAKE_BUILD_TYPE=Release 30 | ninja -j4 31 | REM cmake --build . -j 8 32 | -------------------------------------------------------------------------------- /include/kth/capi.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | /** 6 | * API Users: Include only this header. Direct use of other headers is fragile 7 | * and unsupported as header organization is subject to change. 8 | * 9 | * Maintainers: Do not include this header internal to this library. 10 | */ 11 | 12 | #ifndef KTH_CAPI_H_ 13 | #define KTH_CAPI_H_ 14 | 15 | #include 16 | 17 | #endif // KTH_CAPI_H_ 18 | -------------------------------------------------------------------------------- /include/kth/capi/binary.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_BINARY_H 6 | #define KTH_CAPI_BINARY_H 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_binary_t kth_core_binary_construct(void); 19 | 20 | KTH_EXPORT 21 | kth_binary_t kth_core_binary_construct_string(char const* string); 22 | 23 | KTH_EXPORT 24 | kth_binary_t kth_core_binary_construct_blocks(kth_size_t bits_size, uint8_t* blocks, kth_size_t n); 25 | 26 | KTH_EXPORT 27 | void kth_core_binary_destruct(kth_binary_t binary); 28 | 29 | KTH_EXPORT 30 | uint8_t const* kth_core_binary_blocks(kth_binary_t binary, kth_size_t* out_n); 31 | 32 | KTH_EXPORT 33 | char* kth_core_binary_encoded(kth_binary_t binary); 34 | 35 | #ifdef __cplusplus 36 | } // extern "C" 37 | #endif 38 | 39 | #endif // KTH_CAPI_BINARY_H 40 | -------------------------------------------------------------------------------- /include/kth/capi/capi.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CAPI_H_ 6 | #define KTH_CAPI_CAPI_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | #include 41 | 42 | #include 43 | 44 | #include 45 | 46 | #endif /* KTH_CAPI_CAPI_H_ */ 47 | -------------------------------------------------------------------------------- /include/kth/capi/chain/block_indexes.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_BLOCK_INDEXES_H_ 6 | #define KTH_CAPI_CHAIN_BLOCK_INDEXES_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_LIST_DECLARE(chain, kth_block_indexes_t, kth_size_t, block_indexes) 19 | 20 | #ifdef __cplusplus 21 | } // extern "C" 22 | #endif 23 | 24 | #endif /* KTH_CAPI_CHAIN_BLOCK_INDEXES_H_ */ 25 | -------------------------------------------------------------------------------- /include/kth/capi/chain/block_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_BLOCK_LIST_H_ 6 | #define KTH_CAPI_CHAIN_BLOCK_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_LIST_DECLARE(chain, kth_block_list_t, kth_block_t, block_list) 19 | 20 | #ifdef __cplusplus 21 | } // extern "C" 22 | #endif 23 | 24 | #endif /* KTH_CAPI_CHAIN_BLOCK_LIST_H_ */ 25 | -------------------------------------------------------------------------------- /include/kth/capi/chain/chain.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_CHAIN_H_ 6 | #define KTH_CAPI_CHAIN_CHAIN_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #endif /* KTH_CAPI_CHAIN_CHAIN_H_ */ 13 | -------------------------------------------------------------------------------- /include/kth/capi/chain/coin_selection_algorithm.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_COIN_SELECTION_H_ 6 | #define KTH_CAPI_CHAIN_COIN_SELECTION_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef enum { 18 | kth_coin_selection_algorithm_smallest_first, // Prioriza UTXOs más pequeños 19 | kth_coin_selection_algorithm_largest_first, // Prioriza UTXOs más grandes 20 | // kth_coin_selection_algorithm_knapsack, // Algoritmo de la mochila para optimizar 21 | // kth_coin_selection_algorithm_fifo, // Primero en entrar, primero en salir 22 | // kth_coin_selection_algorithm_branch_and_bound, // Branch and Bound para optimización global 23 | kth_coin_selection_algorithm_manual, // Mantiene el orden original de los UTXOs 24 | // kth_coin_selection_algorithm_privacy, // Prioriza privacidad (mismo tamaño de UTXOs) 25 | kth_coin_selection_algorithm_send_all // Usa todos los UTXOs disponibles 26 | } kth_coin_selection_algorithm_t; 27 | 28 | #ifdef __cplusplus 29 | } // extern "C" 30 | #endif 31 | 32 | #endif // KTH_CAPI_CHAIN_COIN_SELECTION_H_ -------------------------------------------------------------------------------- /include/kth/capi/chain/compact_block.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_COMPACT_BLOCK_H_ 6 | #define KTH_CAPI_CHAIN_COMPACT_BLOCK_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | // TODO(fernando): check how to map compact_block::short_ids() 18 | 19 | KTH_EXPORT 20 | kth_header_t kth_chain_compact_block_header(kth_compact_block_t block); 21 | 22 | KTH_EXPORT 23 | kth_bool_t kth_chain_compact_block_is_valid(kth_compact_block_t block); 24 | 25 | KTH_EXPORT 26 | kth_size_t kth_chain_compact_block_serialized_size(kth_compact_block_t block, uint32_t version); 27 | 28 | KTH_EXPORT 29 | kth_size_t kth_chain_compact_block_transaction_count(kth_compact_block_t block); 30 | 31 | KTH_EXPORT 32 | kth_transaction_t kth_chain_compact_block_transaction_nth(kth_compact_block_t block, kth_size_t n); 33 | 34 | KTH_EXPORT 35 | uint64_t kth_chain_compact_block_nonce(kth_compact_block_t block); 36 | 37 | KTH_EXPORT 38 | void kth_chain_compact_block_destruct(kth_compact_block_t block); 39 | 40 | KTH_EXPORT 41 | void kth_chain_compact_block_reset(kth_compact_block_t block); 42 | 43 | #ifdef __cplusplus 44 | } // extern "C" 45 | #endif 46 | 47 | #endif /* KTH_CAPI_CHAIN_COMPACT_BLOCK_H_ */ 48 | -------------------------------------------------------------------------------- /include/kth/capi/chain/double_spend_proof.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_DOUBLE_SPEND_PROOF_H_ 6 | #define KTH_CAPI_CHAIN_DOUBLE_SPEND_PROOF_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_outputpoint_const_t kth_chain_double_spend_proof_out_point(kth_double_spend_proof_t dsp); 19 | 20 | KTH_EXPORT 21 | kth_double_spend_proof_spender_const_t kth_chain_double_spend_proof_spender1(kth_double_spend_proof_t dsp); 22 | 23 | KTH_EXPORT 24 | kth_double_spend_proof_spender_const_t kth_chain_double_spend_proof_spender2(kth_double_spend_proof_t dsp); 25 | 26 | KTH_EXPORT 27 | kth_hash_t kth_chain_double_spend_proof_hash(kth_double_spend_proof_t dsp); 28 | 29 | KTH_EXPORT 30 | void kth_chain_double_spend_proof_hash_out(kth_double_spend_proof_t dsp, kth_hash_t* out_hash); 31 | 32 | KTH_EXPORT 33 | kth_bool_t kth_chain_double_spend_proof_is_valid(kth_double_spend_proof_t dsp); 34 | 35 | KTH_EXPORT 36 | kth_size_t kth_chain_double_spend_proof_serialized_size(kth_double_spend_proof_t dsp, uint32_t version); 37 | 38 | KTH_EXPORT 39 | void kth_chain_double_spend_proof_destruct(kth_double_spend_proof_t dsp); 40 | 41 | KTH_EXPORT 42 | void kth_chain_double_spend_proof_reset(kth_double_spend_proof_t dsp); 43 | 44 | #ifdef __cplusplus 45 | } // extern "C" 46 | #endif 47 | 48 | #endif /* KTH_CAPI_CHAIN_DOUBLE_SPEND_PROOF_H_ */ 49 | -------------------------------------------------------------------------------- /include/kth/capi/chain/double_spend_proof_spender.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_DOUBLE_SPEND_PROOF_SPENDER_H_ 6 | #define KTH_CAPI_CHAIN_DOUBLE_SPEND_PROOF_SPENDER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | uint32_t kth_chain_double_spend_proof_spender_version(kth_double_spend_proof_spender_const_t spender); 19 | 20 | KTH_EXPORT 21 | uint32_t kth_chain_double_spend_proof_spender_out_sequence(kth_double_spend_proof_spender_const_t spender); 22 | 23 | KTH_EXPORT 24 | uint32_t kth_chain_double_spend_proof_spender_locktime(kth_double_spend_proof_spender_const_t spender); 25 | 26 | KTH_EXPORT 27 | kth_hash_t kth_chain_double_spend_proof_spender_prev_outs_hash(kth_double_spend_proof_spender_const_t spender); 28 | 29 | KTH_EXPORT 30 | void kth_chain_double_spend_proof_spender_prev_outs_hash_out(kth_double_spend_proof_spender_const_t dsp, kth_hash_t* out_hash); 31 | 32 | KTH_EXPORT 33 | kth_hash_t kth_chain_double_spend_proof_spender_sequence_hash(kth_double_spend_proof_spender_const_t spender); 34 | 35 | KTH_EXPORT 36 | void kth_chain_double_spend_proof_spender_sequence_hash_out(kth_double_spend_proof_spender_const_t dsp, kth_hash_t* out_hash); 37 | 38 | KTH_EXPORT 39 | kth_hash_t kth_chain_double_spend_proof_spender_outputs_hash(kth_double_spend_proof_spender_const_t spender); 40 | 41 | KTH_EXPORT 42 | void kth_chain_double_spend_proof_spender_outputs_hash_out(kth_double_spend_proof_spender_const_t dsp, kth_hash_t* out_hash); 43 | 44 | KTH_EXPORT 45 | uint8_t const* kth_chain_double_spend_proof_spender_push_data(kth_double_spend_proof_spender_const_t spender, kth_size_t* out_size); 46 | 47 | KTH_EXPORT 48 | kth_bool_t kth_chain_double_spend_proof_spender_is_valid(kth_double_spend_proof_spender_const_t spender); 49 | 50 | KTH_EXPORT 51 | kth_size_t kth_chain_double_spend_proof_spender_serialized_size(kth_double_spend_proof_spender_const_t spender); 52 | 53 | #ifdef __cplusplus 54 | } // extern "C" 55 | #endif 56 | 57 | #endif /* KTH_CAPI_CHAIN_DOUBLE_SPEND_PROOF_SPENDER_H_ */ 58 | -------------------------------------------------------------------------------- /include/kth/capi/chain/get_blocks.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_GET_BLOCKS_H_ 6 | #define KTH_CAPI_CHAIN_GET_BLOCKS_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_get_blocks_t kth_chain_get_blocks_construct_default(void); 19 | 20 | KTH_EXPORT 21 | kth_get_blocks_t kth_chain_get_blocks_construct(kth_hash_list_t start, kth_hash_t stop); 22 | 23 | KTH_EXPORT 24 | void kth_chain_get_blocks_destruct(kth_get_blocks_t get_b); 25 | 26 | KTH_EXPORT 27 | kth_hash_list_t kth_chain_get_blocks_start_hashes(kth_get_blocks_t get_b); 28 | 29 | KTH_EXPORT 30 | void kth_chain_get_blocks_set_start_hashes(kth_get_blocks_t get_b, kth_hash_list_t value); 31 | 32 | KTH_EXPORT 33 | kth_hash_t kth_chain_get_blocks_stop_hash(kth_get_blocks_t get_b); 34 | 35 | KTH_EXPORT 36 | void kth_chain_get_blocks_stop_hash_out(kth_get_blocks_t get_b, kth_hash_t* out_stop_hash); 37 | 38 | KTH_EXPORT 39 | void kth_chain_get_blocks_set_stop_hash(kth_get_blocks_t get_b, kth_hash_t value); 40 | 41 | KTH_EXPORT 42 | kth_bool_t kth_chain_get_blocks_is_valid(kth_get_blocks_t get_b); 43 | 44 | KTH_EXPORT 45 | void kth_chain_get_blocks_reset(kth_get_blocks_t get_b); 46 | 47 | KTH_EXPORT 48 | kth_size_t kth_chain_get_blocks_serialized_size(kth_get_blocks_t get_b, uint32_t version); 49 | 50 | #ifdef __cplusplus 51 | } // extern "C" 52 | #endif 53 | 54 | #endif /* KTH_CAPI_CHAIN_GET_BLOCKS_H_ */ 55 | -------------------------------------------------------------------------------- /include/kth/capi/chain/get_headers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_GET_HEADERS_H_ 6 | #define KTH_CAPI_CHAIN_GET_HEADERS_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_get_headers_t kth_chain_get_headers_construct_default(void); 19 | 20 | KTH_EXPORT 21 | kth_get_headers_t kth_chain_get_headers_construct(kth_hash_list_t start, kth_hash_t stop); 22 | 23 | KTH_EXPORT 24 | void kth_chain_get_headers_destruct(kth_get_headers_t get_b); 25 | 26 | KTH_EXPORT 27 | kth_hash_list_t kth_chain_get_headers_start_hashes(kth_get_headers_t get_b); 28 | 29 | KTH_EXPORT 30 | void kth_chain_get_headers_set_start_hashes(kth_get_headers_t get_b, kth_hash_list_t value); 31 | 32 | KTH_EXPORT 33 | kth_hash_t kth_chain_get_headers_stop_hash(kth_get_headers_t get_b); 34 | 35 | KTH_EXPORT 36 | void kth_chain_get_headers_stop_hash_out(kth_get_headers_t get_b, kth_hash_t* out_stop_hash); 37 | 38 | KTH_EXPORT 39 | void kth_chain_get_headers_set_stop_hash(kth_get_headers_t get_b, kth_hash_t value); 40 | 41 | KTH_EXPORT 42 | kth_bool_t kth_chain_get_headers_is_valid(kth_get_headers_t get_b); 43 | 44 | KTH_EXPORT 45 | void kth_chain_get_headers_reset(kth_get_headers_t get_b); 46 | 47 | KTH_EXPORT 48 | kth_size_t kth_chain_get_headers_serialized_size(kth_get_headers_t get_b, uint32_t version); 49 | 50 | #ifdef __cplusplus 51 | } // extern "C" 52 | #endif 53 | 54 | #endif /* KTH_CAPI_CHAIN_GET_HEADERS_H_ */ 55 | -------------------------------------------------------------------------------- /include/kth/capi/chain/header.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_HEADER_H_ 6 | #define KTH_CAPI_CHAIN_HEADER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_EXPORT 19 | kth_header_t kth_chain_header_factory_from_data(uint8_t* data, kth_size_t n); 20 | 21 | KTH_EXPORT 22 | kth_size_t kth_chain_header_satoshi_fixed_size(); 23 | 24 | KTH_EXPORT 25 | void kth_chain_header_reset(kth_header_t header); 26 | 27 | KTH_EXPORT 28 | kth_size_t kth_chain_header_serialized_size(kth_header_t header); 29 | 30 | KTH_EXPORT 31 | uint8_t const* kth_chain_header_to_data(kth_header_t header, kth_size_t* out_size); 32 | 33 | KTH_EXPORT 34 | kth_header_t kth_chain_header_construct_default(void); 35 | 36 | KTH_EXPORT 37 | kth_header_t kth_chain_header_construct(uint32_t version, uint8_t* previous_block_hash, uint8_t* merkle, uint32_t timestamp, uint32_t bits, uint32_t nonce); 38 | 39 | KTH_EXPORT 40 | void kth_chain_header_destruct(kth_header_t header); 41 | 42 | KTH_EXPORT 43 | kth_bool_t kth_chain_header_is_valid(kth_header_t header); 44 | 45 | KTH_EXPORT 46 | uint32_t kth_chain_header_version(kth_header_t header); 47 | 48 | KTH_EXPORT 49 | void kth_chain_header_set_version(kth_header_t header, uint32_t version); 50 | 51 | KTH_EXPORT 52 | uint32_t kth_chain_header_timestamp(kth_header_t header); 53 | 54 | KTH_EXPORT 55 | void kth_chain_header_set_timestamp(kth_header_t header, uint32_t timestamp); 56 | 57 | KTH_EXPORT 58 | uint32_t kth_chain_header_bits(kth_header_t header); 59 | 60 | KTH_EXPORT 61 | char const* kth_chain_header_proof_str(kth_header_t header); 62 | 63 | KTH_EXPORT 64 | void kth_chain_header_set_bits(kth_header_t header, uint32_t bits); 65 | 66 | KTH_EXPORT 67 | uint32_t kth_chain_header_nonce(kth_header_t header); 68 | 69 | KTH_EXPORT 70 | void kth_chain_header_set_nonce(kth_header_t header, uint32_t nonce); 71 | 72 | KTH_EXPORT 73 | kth_hash_t kth_chain_header_previous_block_hash(kth_header_t header); 74 | 75 | KTH_EXPORT 76 | void kth_chain_header_previous_block_hash_out(kth_header_t header, kth_hash_t* out_previous_block_hash); 77 | 78 | KTH_EXPORT 79 | kth_hash_t kth_chain_header_merkle(kth_header_t header); 80 | 81 | KTH_EXPORT 82 | void kth_chain_header_merkle_out(kth_header_t header, kth_hash_t* out_merkle); 83 | 84 | KTH_EXPORT 85 | kth_hash_t kth_chain_header_hash(kth_header_t header); 86 | 87 | KTH_EXPORT 88 | void kth_chain_header_hash_out(kth_header_t header, kth_hash_t* out_hash); 89 | 90 | #ifdef __cplusplus 91 | } // extern "C" 92 | #endif 93 | 94 | #endif /* KTH_CAPI_CHAIN_HEADER_H_ */ 95 | -------------------------------------------------------------------------------- /include/kth/capi/chain/history_compact.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_HISTORY_COMPACT_H 6 | #define KTH_CAPI_CHAIN_HISTORY_COMPACT_H 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_point_kind_t kth_chain_history_compact_get_point_kind(kth_history_compact_t history); 19 | 20 | KTH_EXPORT 21 | kth_point_t kth_chain_history_compact_get_point(kth_history_compact_t history); 22 | 23 | KTH_EXPORT 24 | uint32_t kth_chain_history_compact_get_height(kth_history_compact_t history); 25 | 26 | KTH_EXPORT 27 | uint64_t kth_chain_history_compact_get_value_or_previous_checksum(kth_history_compact_t history); 28 | 29 | #ifdef __cplusplus 30 | } // extern "C" 31 | #endif 32 | 33 | #endif // KTH_CAPI_CHAIN_HISTORY_COMPACT_H 34 | -------------------------------------------------------------------------------- /include/kth/capi/chain/history_compact_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_HISTORY_COMPACT_LIST_H_ 6 | #define KTH_CAPI_CHAIN_HISTORY_COMPACT_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_LIST_DECLARE(chain, kth_history_compact_list_t, kth_history_compact_t, history_compact_list) 19 | 20 | #ifdef __cplusplus 21 | } // extern "C" 22 | #endif 23 | 24 | #endif /* KTH_CAPI_CHAIN_HISTORY_COMPACT_LIST_H_ */ 25 | -------------------------------------------------------------------------------- /include/kth/capi/chain/input.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_INPUT_H_ 6 | #define KTH_CAPI_CHAIN_INPUT_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_input_t kth_chain_input_construct_default(void); 19 | 20 | KTH_EXPORT 21 | kth_input_t kth_chain_input_construct(kth_outputpoint_t previous_output, kth_script_t script, uint32_t sequence); 22 | 23 | KTH_EXPORT 24 | void kth_chain_input_destruct(kth_input_t input); 25 | 26 | KTH_EXPORT 27 | kth_input_t kth_chain_input_factory_from_data(uint8_t* data, kth_size_t n); 28 | 29 | KTH_EXPORT 30 | kth_bool_t kth_chain_input_is_valid(kth_input_t input); 31 | 32 | KTH_EXPORT 33 | kth_bool_t kth_chain_input_is_final(kth_input_t input); 34 | 35 | KTH_EXPORT 36 | kth_size_t kth_chain_input_serialized_size(kth_input_t input, kth_bool_t wire); //wire = true 37 | 38 | KTH_EXPORT 39 | uint32_t kth_chain_input_sequence(kth_input_t input); 40 | 41 | KTH_EXPORT 42 | kth_size_t kth_chain_input_signature_operations(kth_input_t input, kth_bool_t bip16_active); 43 | 44 | KTH_EXPORT 45 | kth_script_t kth_chain_input_script(kth_input_t input); 46 | 47 | KTH_EXPORT 48 | kth_outputpoint_t kth_chain_input_previous_output(kth_input_t input); 49 | 50 | KTH_EXPORT 51 | uint8_t const* kth_chain_input_to_data(kth_input_t input, kth_bool_t wire, kth_size_t* out_size); 52 | 53 | #ifdef __cplusplus 54 | } // extern "C" 55 | #endif 56 | 57 | #endif /* KTH_CAPI_CHAIN_INPUT_H_ */ 58 | -------------------------------------------------------------------------------- /include/kth/capi/chain/input_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_INPUT_LIST_H_ 6 | #define KTH_CAPI_CHAIN_INPUT_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_LIST_DECLARE(chain, kth_input_list_t, kth_input_t, input_list) 19 | 20 | #ifdef __cplusplus 21 | } // extern "C" 22 | #endif 23 | 24 | #endif /* KTH_CAPI_CHAIN_INPUT_LIST_H_ */ 25 | -------------------------------------------------------------------------------- /include/kth/capi/chain/mempool_transaction.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_MEMPOOL_TRANSACTION_H_ 6 | #define KTH_CAPI_CHAIN_MEMPOOL_TRANSACTION_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | char const* kth_chain_mempool_transaction_address(kth_mempool_transaction_t tx); 19 | 20 | KTH_EXPORT 21 | char const* kth_chain_mempool_transaction_hash(kth_mempool_transaction_t tx); 22 | 23 | KTH_EXPORT 24 | uint64_t kth_chain_mempool_transaction_index(kth_mempool_transaction_t tx); 25 | 26 | KTH_EXPORT 27 | char const* kth_chain_mempool_transaction_satoshis(kth_mempool_transaction_t tx); 28 | 29 | KTH_EXPORT 30 | uint64_t kth_chain_mempool_transaction_timestamp(kth_mempool_transaction_t tx); 31 | 32 | KTH_EXPORT 33 | char const* kth_chain_mempool_transaction_prev_output_id(kth_mempool_transaction_t tx); 34 | 35 | KTH_EXPORT 36 | char const* kth_chain_mempool_transaction_prev_output_index(kth_mempool_transaction_t tx); 37 | 38 | #ifdef __cplusplus 39 | } // extern "C" 40 | #endif 41 | 42 | #endif /* KTH_CAPI_CHAIN_MEMPOOL_TRANSACTION_H_ */ 43 | -------------------------------------------------------------------------------- /include/kth/capi/chain/mempool_transaction_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_MEMPOOL_TRANSACTION_LIST_H_ 6 | #define KTH_CAPI_CHAIN_MEMPOOL_TRANSACTION_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_LIST_DECLARE(chain, kth_mempool_transaction_list_t, kth_mempool_transaction_t, mempool_transaction_list) 19 | 20 | #ifdef __cplusplus 21 | } // extern "C" 22 | #endif 23 | 24 | #endif /* KTH_CAPI_CHAIN_MEMPOOL_TRANSACTION_LIST_H_ */ 25 | -------------------------------------------------------------------------------- /include/kth/capi/chain/merkle_block.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_MERKLE_BLOCK_H_ 6 | #define KTH_CAPI_CHAIN_MERKLE_BLOCK_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_hash_t kth_chain_merkle_block_hash_nth(kth_merkleblock_t block, kth_size_t n); 19 | 20 | KTH_EXPORT 21 | void kth_chain_merkle_block_hash_nth_out(kth_merkleblock_t block, kth_size_t n, kth_hash_t* out_hash); 22 | 23 | KTH_EXPORT 24 | kth_header_t kth_chain_merkle_block_header(kth_merkleblock_t block); 25 | 26 | KTH_EXPORT 27 | kth_bool_t kth_chain_merkle_block_is_valid(kth_merkleblock_t block); 28 | 29 | KTH_EXPORT 30 | kth_size_t kth_chain_merkle_block_hash_count(kth_merkleblock_t block); 31 | 32 | KTH_EXPORT 33 | kth_size_t kth_chain_merkle_block_serialized_size(kth_merkleblock_t block, uint32_t version); 34 | 35 | KTH_EXPORT 36 | kth_size_t kth_chain_merkle_block_total_transaction_count(kth_merkleblock_t block); 37 | 38 | KTH_EXPORT 39 | void kth_chain_merkle_block_destruct(kth_merkleblock_t block); 40 | 41 | KTH_EXPORT 42 | void kth_chain_merkle_block_reset(kth_merkleblock_t block); 43 | 44 | #ifdef __cplusplus 45 | } // extern "C" 46 | #endif 47 | 48 | #endif /* KTH_CAPI_CHAIN_MERKLE_BLOCK_H_ */ 49 | -------------------------------------------------------------------------------- /include/kth/capi/chain/operation_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_OPERATION_LIST_H_ 6 | #define KTH_CAPI_CHAIN_OPERATION_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_LIST_DECLARE(chain, kth_operation_list_t, kth_operation_t, operation_list) 19 | 20 | #ifdef __cplusplus 21 | } // extern "C" 22 | #endif 23 | 24 | #endif /* KTH_CAPI_CHAIN_OPERATION_LIST_H_ */ 25 | -------------------------------------------------------------------------------- /include/kth/capi/chain/output.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_OUTPUT_H_ 6 | #define KTH_CAPI_CHAIN_OUTPUT_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | KTH_EXPORT 20 | kth_output_t kth_chain_output_construct_default(void); 21 | 22 | KTH_EXPORT 23 | kth_output_t kth_chain_output_construct(uint64_t value, kth_script_t script); 24 | 25 | KTH_EXPORT 26 | kth_output_t kth_chain_output_construct_with_token_fungible(uint64_t value, kth_script_t script, kth_hash_t const* token_category, int64_t token_amount); 27 | 28 | KTH_EXPORT 29 | kth_output_t kth_chain_output_construct_with_token_non_fungible(uint64_t value, kth_script_t script, kth_hash_t const* token_category, kth_token_capability_t capability, uint8_t* commitment_data, kth_size_t commitment_n); 30 | 31 | KTH_EXPORT 32 | kth_output_t kth_chain_output_construct_with_token_both(uint64_t value, kth_script_t script, kth_hash_t const* token_category, int64_t token_amount, kth_token_capability_t capability, uint8_t* commitment_data, kth_size_t commitment_n); 33 | 34 | KTH_EXPORT 35 | kth_output_t kth_chain_output_construct_with_token_data(uint64_t value, kth_script_t script, kth_token_data_t token_data); 36 | 37 | KTH_EXPORT 38 | void kth_chain_output_destruct(kth_output_t output); 39 | 40 | KTH_EXPORT 41 | kth_output_t kth_chain_output_factory_from_data(uint8_t* data, kth_size_t n); 42 | 43 | KTH_EXPORT 44 | kth_bool_t kth_chain_output_is_valid(kth_output_t output); 45 | 46 | KTH_EXPORT 47 | kth_size_t kth_chain_output_serialized_size(kth_output_t output, kth_bool_t wire); //wire = true 48 | 49 | KTH_EXPORT 50 | uint64_t kth_chain_output_value(kth_output_t output); 51 | 52 | KTH_EXPORT 53 | kth_size_t kth_chain_output_signature_operations(kth_output_t output); 54 | 55 | KTH_EXPORT 56 | kth_script_t kth_chain_output_script(kth_output_t output); 57 | 58 | KTH_EXPORT 59 | kth_payment_address_t kth_chain_output_payment_address(kth_output_t output, kth_bool_t use_testnet_rules); 60 | 61 | KTH_EXPORT 62 | uint8_t const* kth_chain_output_to_data(kth_output_t output, kth_bool_t wire, kth_size_t* out_size); 63 | 64 | //uint32_t kth_chain_output_get_index(kth_output_t output); 65 | 66 | // Cash Tokens --------------------------------------------------------------- 67 | KTH_EXPORT 68 | kth_bool_t kth_chain_output_has_token_data(kth_output_t output); 69 | 70 | KTH_EXPORT 71 | kth_token_data_t kth_chain_output_token_data(kth_output_t output); 72 | 73 | #ifdef __cplusplus 74 | } // extern "C" 75 | #endif 76 | 77 | #endif /* KTH_CAPI_CHAIN_OUTPUT_H_ */ 78 | -------------------------------------------------------------------------------- /include/kth/capi/chain/output_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_OUTPUT_LIST_H_ 6 | #define KTH_CAPI_CHAIN_OUTPUT_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_LIST_DECLARE(chain, kth_output_list_t, kth_output_t, output_list) 19 | 20 | #ifdef __cplusplus 21 | } // extern "C" 22 | #endif 23 | 24 | #endif /* KTH_CAPI_CHAIN_OUTPUT_LIST_H_ */ 25 | -------------------------------------------------------------------------------- /include/kth/capi/chain/output_point.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_OUTPUT_POINT_H_ 6 | #define KTH_CAPI_CHAIN_OUTPUT_POINT_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_outputpoint_t kth_chain_output_point_construct(void); 19 | 20 | KTH_EXPORT 21 | kth_outputpoint_t kth_chain_output_point_construct_from_hash_index(kth_hash_t const* hash, uint32_t index); 22 | 23 | KTH_EXPORT 24 | void kth_chain_output_point_destruct(kth_outputpoint_t op); 25 | 26 | KTH_EXPORT 27 | kth_hash_t kth_chain_output_point_get_hash(kth_outputpoint_t op); 28 | 29 | KTH_EXPORT 30 | void kth_chain_output_point_get_hash_out(kth_outputpoint_t op, kth_hash_t* out_hash); 31 | 32 | KTH_EXPORT 33 | uint32_t kth_chain_output_point_get_index(kth_outputpoint_t op); 34 | 35 | KTH_EXPORT 36 | kth_output_t kth_chain_output_point_get_cached_output(kth_outputpoint_t op); 37 | 38 | KTH_EXPORT 39 | void kth_chain_output_point_set_hash(kth_outputpoint_t op, kth_hash_t const* hash); 40 | 41 | KTH_EXPORT 42 | void kth_chain_output_point_set_index(kth_outputpoint_t op, uint32_t index); 43 | 44 | KTH_EXPORT 45 | void kth_chain_output_point_set_cached_output(kth_outputpoint_t op, kth_output_t output); 46 | 47 | 48 | #ifdef __cplusplus 49 | } // extern "C" 50 | #endif 51 | 52 | #endif /* KTH_CAPI_CHAIN_OUTPUT_POINT_H_ */ -------------------------------------------------------------------------------- /include/kth/capi/chain/point.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_POINT_H_ 6 | #define KTH_CAPI_CHAIN_POINT_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_hash_t kth_chain_point_get_hash(kth_point_t point); 19 | 20 | KTH_EXPORT 21 | void kth_chain_point_get_hash_out(kth_point_t point, kth_hash_t* out_hash); 22 | 23 | KTH_EXPORT 24 | kth_bool_t kth_chain_point_is_valid(kth_point_t point); 25 | 26 | KTH_EXPORT 27 | uint32_t kth_chain_point_get_index(kth_point_t point); 28 | 29 | KTH_EXPORT 30 | uint64_t kth_chain_point_get_checksum(kth_point_t point); 31 | 32 | #ifdef __cplusplus 33 | } // extern "C" 34 | #endif 35 | 36 | #endif /* KTH_CAPI_CHAIN_POINT_H_ */ 37 | -------------------------------------------------------------------------------- /include/kth/capi/chain/point_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_POINT_LIST_H_ 6 | #define KTH_CAPI_CHAIN_POINT_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_LIST_DECLARE(chain, kth_point_list_t, kth_point_t, point_list) 19 | 20 | #ifdef __cplusplus 21 | } // extern "C" 22 | #endif 23 | 24 | #endif /* KTH_CAPI_CHAIN_POINT_LIST_H_ */ 25 | -------------------------------------------------------------------------------- /include/kth/capi/chain/script_pattern.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_SCRIPT_PATTERN_H_ 6 | #define KTH_CAPI_CHAIN_SCRIPT_PATTERN_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef enum { 18 | /// Null Data 19 | /// Pubkey Script: OP_RETURN <0 to 80 bytes of data> (formerly 40 bytes) 20 | /// Null data scripts cannot be spent, so there's no signature script. 21 | kth_script_pattern_null_data, 22 | 23 | /// Pay to Multisig [BIP11] 24 | /// Pubkey script: [B pubkey][C pubkey...] OP_CHECKMULTISIG 25 | /// Signature script: OP_0 [B sig][C sig...] 26 | kth_script_pattern_pay_multisig, 27 | 28 | /// Pay to Public Key (obsolete) 29 | kth_script_pattern_pay_public_key, 30 | 31 | /// Pay to Public Key Hash [P2PKH] 32 | /// Pubkey script: OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG 33 | /// Signature script: 34 | kth_script_pattern_pay_public_key_hash, 35 | 36 | /// Pay to Script Hash [P2SH/BIP16] 37 | /// The redeem script may be any pay type, but only multisig makes sense. 38 | /// Pubkey script: OP_HASH160 OP_EQUAL 39 | /// Signature script: [sig][sig...] 40 | kth_script_pattern_pay_script_hash, 41 | 42 | /// Pay to Script Hash 32 43 | /// The redeem script may be any pay type, but only multisig makes sense. 44 | /// Pubkey script: OP_HASH256 OP_EQUAL 45 | /// Signature script: [sig][sig...] 46 | kth_script_pattern_pay_script_hash_32, 47 | 48 | /// Sign Multisig script [BIP11] 49 | kth_script_pattern_sign_multisig, 50 | 51 | /// Sign Public Key (obsolete) 52 | kth_script_pattern_sign_public_key, 53 | 54 | /// Sign Public Key Hash [P2PKH] 55 | kth_script_pattern_sign_public_key_hash, 56 | 57 | /// Sign Script Hash [P2SH/BIP16] 58 | kth_script_pattern_sign_script_hash, 59 | 60 | /// Witness coinbase reserved value [BIP141]. 61 | kth_script_pattern_witness_reservation, 62 | 63 | /// The script may be valid but does not conform to the common templates. 64 | /// Such scripts are always accepted if they are mined into blocks, but 65 | /// transactions with uncommon scripts may not be forwarded by peers. 66 | kth_script_pattern_non_standard 67 | 68 | } kth_script_pattern_t; 69 | 70 | 71 | #ifdef __cplusplus 72 | } // extern "C" 73 | #endif 74 | 75 | #endif /* KTH_CAPI_CHAIN_SCRIPT_PATTERN_H_ */ 76 | -------------------------------------------------------------------------------- /include/kth/capi/chain/script_version copy.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_SCRIPT_VERSION_H_ 6 | #define KTH_CAPI_CHAIN_SCRIPT_VERSION_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef enum { 18 | /// Defined by bip141. 19 | kth_script_version_zero, 20 | 21 | /// All reserved script versions (1..16). 22 | kth_script_version_reserved, 23 | 24 | kth_script_version_unversioned 25 | } kth_script_version_t; 26 | 27 | 28 | #ifdef __cplusplus 29 | } // extern "C" 30 | #endif 31 | 32 | #endif // KTH_CAPI_CHAIN_SCRIPT_VERSION_H_ 33 | -------------------------------------------------------------------------------- /include/kth/capi/chain/script_version.h: -------------------------------------------------------------------------------- 1 | 2 | // Copyright (c) 2016-2024 Knuth Project developers. 3 | // Distributed under the MIT software license, see the accompanying 4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 | 6 | #ifndef KTH_CAPI_CHAIN_SCRIPT_VERSION_H_ 7 | #define KTH_CAPI_CHAIN_SCRIPT_VERSION_H_ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | 19 | #if ! defined(KTH_CURRENCY_BCH) 20 | typedef enum { 21 | /// Defined by bip141. 22 | kth_script_version_zero, 23 | 24 | /// All reserved script versions (1..16). 25 | kth_script_version_reserved, 26 | 27 | kth_script_version_unversioned 28 | } kth_script_version_t; 29 | 30 | #endif // ! KTH_CURRENCY_BCH 31 | 32 | 33 | #ifdef __cplusplus 34 | } // extern "C" 35 | #endif 36 | 37 | #endif // KTH_CAPI_CHAIN_SCRIPT_VERSION_H_ 38 | -------------------------------------------------------------------------------- /include/kth/capi/chain/stealth_compact.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_STEALTH_COMPACT_H_ 6 | #define KTH_CAPI_CHAIN_STEALTH_COMPACT_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_hash_t kth_chain_stealth_compact_get_ephemeral_public_key_hash(kth_stealth_compact_t stealth); 19 | 20 | KTH_EXPORT 21 | void kth_chain_stealth_compact_get_ephemeral_public_key_hash_out(kth_stealth_compact_t stealth, kth_hash_t* out_epk_hash); 22 | 23 | KTH_EXPORT 24 | kth_hash_t kth_chain_stealth_compact_get_transaction_hash(kth_stealth_compact_t stealth); 25 | 26 | KTH_EXPORT 27 | void kth_chain_stealth_compact_get_transaction_hash_out(kth_stealth_compact_t stealth, kth_hash_t* out_tx_hash); 28 | 29 | KTH_EXPORT 30 | kth_shorthash_t kth_chain_stealth_compact_get_public_key_hash(kth_stealth_compact_t stealth); 31 | 32 | KTH_EXPORT 33 | void kth_chain_stealth_compact_get_public_key_hash_out(kth_stealth_compact_t stealth, kth_shorthash_t* out_pk_hash); 34 | 35 | #ifdef __cplusplus 36 | } // extern "C" 37 | #endif 38 | 39 | #endif // KTH_CAPI_CHAIN_STEALTH_COMPACT_H_ 40 | -------------------------------------------------------------------------------- /include/kth/capi/chain/stealth_compact_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_STEALTH_COMPACT_LIST_H 6 | #define KTH_CAPI_CHAIN_STEALTH_COMPACT_LIST_H 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_LIST_DECLARE(chain, kth_stealth_compact_list_t, kth_stealth_compact_t, stealth_compact_list) 19 | 20 | #ifdef __cplusplus 21 | } // extern "C" 22 | #endif 23 | 24 | #endif // KTH_CAPI_CHAIN_STEALTH_COMPACT_LIST_H 25 | -------------------------------------------------------------------------------- /include/kth/capi/chain/token_capability.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_TOKEN_CAPABILITY_H_ 6 | #define KTH_CAPI_CHAIN_TOKEN_CAPABILITY_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef enum { 18 | kth_token_capability_none = 0x00, // The token lacks any capability or permission and is either a pure-fungible token or an immutable non-fungible token. 19 | kth_token_capability_mut = 0x01, // If the mutable capability is present, it means that the encoded token is a non-fungible token that can be altered. 20 | kth_token_capability_minting = 0x02, // If the minting capability is present, it indicates that the encoded token is a non-fungible token used for minting. 21 | } kth_token_capability_t; 22 | 23 | #ifdef __cplusplus 24 | } // extern "C" 25 | #endif 26 | 27 | #endif // KTH_CAPI_CHAIN_TOKEN_CAPABILITY_H_ 28 | -------------------------------------------------------------------------------- /include/kth/capi/chain/token_data.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_TOKEN_DATA_H_ 6 | #define KTH_CAPI_CHAIN_TOKEN_DATA_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | KTH_EXPORT 21 | kth_token_data_t kth_chain_token_data_construct_default(void); 22 | 23 | KTH_EXPORT 24 | kth_token_data_t kth_chain_token_data_construct_fungible(kth_hash_t const* token_category, int64_t token_amount); 25 | 26 | KTH_EXPORT 27 | kth_token_data_t kth_chain_token_data_construct_non_fungible(kth_hash_t const* token_category, kth_token_capability_t capability, uint8_t* commitment_data, kth_size_t commitment_n); 28 | 29 | KTH_EXPORT 30 | kth_token_data_t kth_chain_token_data_construct_both(kth_hash_t const* token_category, int64_t token_amount, kth_token_capability_t capability, uint8_t* commitment_data, kth_size_t commitment_n); 31 | 32 | KTH_EXPORT 33 | void kth_chain_token_data_destruct(kth_token_data_t token_data); 34 | 35 | KTH_EXPORT 36 | kth_bool_t kth_chain_token_data_is_valid(kth_token_data_t token_data); 37 | 38 | KTH_EXPORT 39 | kth_size_t kth_chain_token_data_serialized_size(kth_token_data_t token_data); 40 | 41 | KTH_EXPORT 42 | uint8_t const* kth_chain_token_data_to_data(kth_token_data_t token_data, kth_size_t* out_size); 43 | 44 | KTH_EXPORT 45 | kth_token_kind_t kth_chain_token_data_kind(kth_token_data_t token_data); 46 | 47 | KTH_EXPORT 48 | kth_hash_t kth_chain_token_data_category(kth_token_data_t token_data); 49 | 50 | KTH_EXPORT 51 | void kth_chain_token_data_category_out(kth_token_data_t token_data, kth_hash_t* out_category); 52 | 53 | KTH_EXPORT 54 | int64_t kth_chain_token_data_fungible_amount(kth_token_data_t token_data); 55 | 56 | KTH_EXPORT 57 | kth_token_capability_t kth_chain_token_data_non_fungible_capability(kth_token_data_t token_data); 58 | 59 | KTH_EXPORT 60 | uint8_t const* kth_chain_token_data_non_fungible_commitment(kth_token_data_t token_data, kth_size_t* out_size); 61 | 62 | #ifdef __cplusplus 63 | } // extern "C" 64 | #endif 65 | 66 | #endif /* KTH_CAPI_CHAIN_TOKEN_DATA_H_ */ 67 | -------------------------------------------------------------------------------- /include/kth/capi/chain/token_kind.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_TOKEN_KIND_H_ 6 | #define KTH_CAPI_CHAIN_TOKEN_KIND_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef enum { 18 | kth_token_kind_none = 0x00, 19 | kth_token_kind_fungible = 0x01, 20 | kth_token_kind_non_fungible = 0x02, 21 | kth_token_kind_both = 0x03, 22 | } kth_token_kind_t; 23 | 24 | #ifdef __cplusplus 25 | } // extern "C" 26 | #endif 27 | 28 | #endif // KTH_CAPI_CHAIN_TOKEN_KIND_H_ 29 | -------------------------------------------------------------------------------- /include/kth/capi/chain/transaction_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_TRANSACTION_LIST_H_ 6 | #define KTH_CAPI_CHAIN_TRANSACTION_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_LIST_DECLARE(chain, kth_transaction_list_t, kth_transaction_t, transaction_list) 19 | 20 | #ifdef __cplusplus 21 | } // extern "C" 22 | #endif 23 | 24 | #endif /* KTH_CAPI_CHAIN_TRANSACTION_LIST_H_ */ 25 | -------------------------------------------------------------------------------- /include/kth/capi/chain/utxo_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CHAIN_UTXO_LIST_H_ 6 | #define KTH_CAPI_CHAIN_UTXO_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_LIST_DECLARE(chain, kth_utxo_list_t, kth_utxo_t, utxo_list) 19 | 20 | #ifdef __cplusplus 21 | } // extern "C" 22 | #endif 23 | 24 | #endif // KTH_CAPI_CHAIN_UTXO_LIST_H_ -------------------------------------------------------------------------------- /include/kth/capi/config/authority.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_AUTHORITY_H_ 6 | #define KTH_CAPI_CONFIG_AUTHORITY_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef struct { 18 | char* ip; 19 | uint16_t port; 20 | } kth_authority; 21 | 22 | KTH_EXPORT 23 | kth_authority* kth_config_authority_allocate_n(kth_size_t n); 24 | 25 | #ifdef __cplusplus 26 | } // extern "C" 27 | #endif 28 | 29 | #endif // KTH_CAPI_CONFIG_AUTHORITY_H_ 30 | -------------------------------------------------------------------------------- /include/kth/capi/config/authority_helpers.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_AUTHORITY_HELPERS_HPP_ 6 | #define KTH_CAPI_CONFIG_AUTHORITY_HELPERS_HPP_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace kth::capi::helpers { 18 | 19 | using authority = kth::infrastructure::config::authority; 20 | 21 | inline 22 | authority authority_to_cpp(kth_authority const& x) { 23 | return {x.ip, x.port}; 24 | } 25 | 26 | inline 27 | kth_authority authority_to_c(authority const& x) { 28 | return {kth::create_c_str(x.to_hostname()), x.port()}; 29 | } 30 | 31 | inline 32 | void authority_delete(kth_authority& x) { 33 | free(x.ip); 34 | } 35 | 36 | inline 37 | std::vector authority_list_to_cpp(kth_authority const* data, size_t n) { 38 | return kth::capi::helpers::list_to_cpp(data, n, authority_to_cpp); 39 | } 40 | 41 | inline 42 | kth_authority* authority_list_to_c(std::vector const& data, size_t& out_size) { 43 | return kth::capi::helpers::list_to_c(data, out_size, authority_to_c); 44 | } 45 | 46 | inline 47 | void authority_list_delete(kth_authority* list, size_t n) { 48 | list_c_delete(list, n, authority_delete); 49 | } 50 | 51 | } 52 | 53 | #endif // KTH_CAPI_CONFIG_AUTHORITY_HELPERS_HPP_ 54 | -------------------------------------------------------------------------------- /include/kth/capi/config/checkpoint.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_CHECKPOINT_H_ 6 | #define KTH_CAPI_CONFIG_CHECKPOINT_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef struct { 18 | kth_hash_t hash; 19 | size_t height; 20 | } kth_checkpoint; 21 | 22 | KTH_EXPORT 23 | kth_checkpoint* kth_config_checkpoint_allocate_n(kth_size_t n); 24 | 25 | #ifdef __cplusplus 26 | } // extern "C" 27 | #endif 28 | 29 | #endif // KTH_CAPI_CONFIG_CHECKPOINT_H_ 30 | -------------------------------------------------------------------------------- /include/kth/capi/config/checkpoint_helpers.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_CHECKPOINT_HELPERS_HPP_ 6 | #define KTH_CAPI_CONFIG_CHECKPOINT_HELPERS_HPP_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace kth::capi::helpers { 18 | 19 | using checkpoint = kth::infrastructure::config::checkpoint; 20 | 21 | inline 22 | checkpoint checkpoint_to_cpp(kth_checkpoint const& x) { 23 | return {kth::hash_to_cpp(x.hash.hash), x.height}; 24 | } 25 | 26 | inline 27 | kth_checkpoint checkpoint_to_c(checkpoint const& x) { 28 | return {kth::to_hash_t(x.hash()), x.height()}; 29 | } 30 | 31 | inline 32 | void checkpoint_delete(kth_checkpoint&) { 33 | //do nothing 34 | } 35 | 36 | 37 | inline 38 | std::vector checkpoint_list_to_cpp(kth_checkpoint const* data, size_t n) { 39 | return kth::capi::helpers::list_to_cpp(data, n, checkpoint_to_cpp); 40 | } 41 | 42 | inline 43 | kth_checkpoint* checkpoint_list_to_c(std::vector const& data, kth_size_t& out_size) { 44 | return kth::capi::helpers::list_to_c(data, out_size, checkpoint_to_c); 45 | } 46 | 47 | inline 48 | void checkpoint_list_delete(kth_checkpoint* list, size_t n) { 49 | list_c_delete(list, n, checkpoint_delete); 50 | } 51 | 52 | } 53 | 54 | #endif // KTH_CAPI_CONFIG_CHECKPOINT_HELPERS_HPP_ 55 | -------------------------------------------------------------------------------- /include/kth/capi/config/database_helpers.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_DATABASE_HELPERS_HPP_ 6 | #define KTH_CAPI_CONFIG_DATABASE_HELPERS_HPP_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace kth::capi::helpers { 15 | 16 | inline 17 | kth::database::db_mode_type db_mode_converter(kth_db_mode_t c_mode) { 18 | return kth::database::db_mode_type(c_mode); 19 | } 20 | 21 | inline 22 | kth_db_mode_t db_mode_converter(kth::database::db_mode_type cpp_mode) { 23 | return kth_db_mode_t(cpp_mode); 24 | } 25 | 26 | namespace { 27 | 28 | template 29 | Target database_settings_to_common(Source const& x) { 30 | Target res; 31 | 32 | res.db_mode = db_mode_converter(x.db_mode); 33 | res.reorg_pool_limit = x.reorg_pool_limit; 34 | res.db_max_size = x.db_max_size; 35 | res.safe_mode = x.safe_mode; 36 | res.cache_capacity = x.cache_capacity; 37 | return res; 38 | } 39 | 40 | } 41 | 42 | inline 43 | kth::database::settings database_settings_to_cpp(kth_database_settings const& x) { 44 | auto res = database_settings_to_common(x); 45 | res.directory = x.directory; 46 | return res; 47 | } 48 | 49 | inline 50 | kth_database_settings database_settings_to_c(kth::database::settings const& x) { 51 | auto res = database_settings_to_common(x); 52 | res.directory = kth::capi::helpers::path_to_c(x.directory); 53 | return res; 54 | } 55 | 56 | inline 57 | void database_settings_delete(kth_database_settings* x) { 58 | free(x->directory); 59 | } 60 | 61 | } // namespace kth::capi::helpers 62 | 63 | #endif // KTH_CAPI_CONFIG_DATABASE_HELPERS_HPP_ 64 | -------------------------------------------------------------------------------- /include/kth/capi/config/database_settings.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_DATABASE_SETTINGS_H_ 6 | #define KTH_CAPI_CONFIG_DATABASE_SETTINGS_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | typedef struct { 17 | kth_char_t* directory; 18 | kth_db_mode_t db_mode; 19 | uint32_t reorg_pool_limit; 20 | uint64_t db_max_size; 21 | kth_bool_t safe_mode; 22 | uint32_t cache_capacity; 23 | 24 | } kth_database_settings; 25 | 26 | KTH_EXPORT 27 | kth_database_settings kth_config_database_settings_default(kth_network_t net); 28 | 29 | #ifdef __cplusplus 30 | } // extern "C" 31 | #endif 32 | 33 | #endif // KTH_CAPI_CONFIG_DATABASE_SETTINGS_H_ 34 | -------------------------------------------------------------------------------- /include/kth/capi/config/endpoint.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_ENDPOINT_H_ 6 | #define KTH_CAPI_CONFIG_ENDPOINT_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef struct { 18 | char* scheme; 19 | char* host; 20 | uint16_t port; 21 | } kth_endpoint; 22 | 23 | KTH_EXPORT 24 | kth_endpoint* kth_config_endpoint_allocate_n(kth_size_t n); 25 | 26 | #ifdef __cplusplus 27 | } // extern "C" 28 | #endif 29 | 30 | #endif // KTH_CAPI_CONFIG_ENDPOINT_H_ 31 | -------------------------------------------------------------------------------- /include/kth/capi/config/endpoint_helpers.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_ENDPOINT_HELPERS_HPP_ 6 | #define KTH_CAPI_CONFIG_ENDPOINT_HELPERS_HPP_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace kth::capi::helpers { 18 | 19 | using endpoint = kth::infrastructure::config::endpoint; 20 | 21 | inline 22 | endpoint endpoint_to_cpp(kth_endpoint const& x) { 23 | return {x.host, x.port}; 24 | } 25 | 26 | inline 27 | kth_endpoint endpoint_to_c(endpoint const& x) { 28 | return {kth::create_c_str(x.scheme()), kth::create_c_str(x.host()), x.port()}; 29 | } 30 | 31 | inline 32 | void endpoint_delete(kth_endpoint& x) { 33 | free(x.scheme); 34 | free(x.host); 35 | } 36 | 37 | inline 38 | std::vector endpoint_list_to_cpp(kth_endpoint const* data, size_t n) { 39 | return kth::capi::helpers::list_to_cpp(data, n, endpoint_to_cpp); 40 | } 41 | 42 | inline 43 | kth_endpoint* endpoint_list_to_c(std::vector const& data, size_t& out_size) { 44 | return kth::capi::helpers::list_to_c(data, out_size, endpoint_to_c); 45 | } 46 | 47 | inline 48 | void endpoint_list_delete(kth_endpoint* list, size_t n) { 49 | list_c_delete(list, n, endpoint_delete); 50 | } 51 | 52 | } 53 | 54 | #endif // KTH_CAPI_CONFIG_ENDPOINT_HELPERS_HPP_ 55 | -------------------------------------------------------------------------------- /include/kth/capi/config/helpers.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_HELPERS_HPP_ 6 | #define KTH_CAPI_CONFIG_HELPERS_HPP_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | namespace kth::capi::helpers { 16 | 17 | inline 18 | kth_char_t* path_to_c(kth::path const& x) { 19 | kth_char_t* ret = kth::mnew(x.native().size() + 1); 20 | std::copy_n(x.c_str(), x.native().size() + 1, ret); 21 | return ret; 22 | } 23 | 24 | template 25 | inline 26 | auto list_to_cpp(Source const* data, size_t n, Transformation transform) { 27 | using Target = std::invoke_result_t; 28 | // static_assert(std::is_same::value, ""); 29 | 30 | std::vector res; 31 | res.reserve(n); 32 | while (n != 0) { 33 | res.push_back(transform(*data)); 34 | ++data; 35 | --n; 36 | } 37 | return res; 38 | } 39 | 40 | template 41 | inline 42 | auto list_c_delete(Source* data, size_t n, Deleter deleter) { 43 | for (size_t i = 0; i < n; ++i) { 44 | auto xxx = data[i]; 45 | deleter(data[i]); 46 | } 47 | free(data); 48 | } 49 | 50 | template 51 | inline 52 | auto* list_to_c(std::vector const& data, UnsignedInt& out_size, Transformation transform) { 53 | using Target = std::invoke_result_t; 54 | 55 | out_size = data.size(); 56 | // if (out_size == 0) return nullptr; 57 | 58 | auto* ret = kth::mnew(out_size); 59 | auto* f = ret; 60 | for (auto&& x : data) { 61 | *f = transform(x); 62 | ++f; 63 | } 64 | return ret; 65 | } 66 | 67 | } 68 | 69 | #endif // KTH_CAPI_CONFIG_HELPERS_HPP_ 70 | -------------------------------------------------------------------------------- /include/kth/capi/config/network_settings.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_NETWORK_SETTINGS_H_ 6 | #define KTH_CAPI_CONFIG_NETWORK_SETTINGS_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | typedef struct { 21 | uint32_t threads; 22 | uint32_t protocol_maximum; 23 | uint32_t protocol_minimum; 24 | uint64_t services; 25 | uint64_t invalid_services; 26 | kth_bool_t relay_transactions; 27 | kth_bool_t validate_checksum; 28 | uint32_t identifier; 29 | uint16_t inbound_port; 30 | uint32_t inbound_connections; 31 | uint32_t outbound_connections; 32 | uint32_t manual_attempt_limit; 33 | uint32_t connect_batch_size; 34 | uint32_t connect_timeout_seconds; 35 | uint32_t channel_handshake_seconds; 36 | uint32_t channel_heartbeat_minutes; 37 | uint32_t channel_inactivity_minutes; 38 | uint32_t channel_expiration_minutes; 39 | uint32_t channel_germination_seconds; 40 | uint32_t host_pool_capacity; 41 | kth_char_t* hosts_file; 42 | kth_authority self; 43 | 44 | size_t blacklist_count; 45 | kth_authority* blacklist; 46 | 47 | size_t peer_count; 48 | kth_endpoint* peers; 49 | 50 | size_t seed_count; 51 | kth_endpoint* seeds; 52 | 53 | // [log] 54 | kth_char_t* debug_file; 55 | kth_char_t* error_file; 56 | kth_char_t* archive_directory; 57 | size_t rotation_size; 58 | size_t minimum_free_space; 59 | size_t maximum_archive_size; 60 | size_t maximum_archive_files; 61 | kth_authority statistics_server; 62 | 63 | kth_bool_t verbose; 64 | kth_bool_t use_ipv6; 65 | 66 | size_t user_agent_blacklist_count; 67 | char** user_agent_blacklist; 68 | } kth_network_settings; 69 | 70 | KTH_EXPORT 71 | kth_network_settings kth_config_network_settings_default(kth_network_t net); 72 | 73 | #ifdef __cplusplus 74 | } // extern "C" 75 | #endif 76 | 77 | #endif // KTH_CAPI_CONFIG_NETWORK_SETTINGS_H_ 78 | -------------------------------------------------------------------------------- /include/kth/capi/config/node_helpers.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_NODE_HELPERS_HPP_ 6 | #define KTH_CAPI_CONFIG_NODE_HELPERS_HPP_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace kth::capi::helpers { 15 | 16 | namespace { 17 | 18 | template 19 | inline 20 | Target node_settings_to_common(Source const& x) { 21 | Target res; 22 | res.sync_peers = x.sync_peers; 23 | res.sync_timeout_seconds = x.sync_timeout_seconds; 24 | res.block_latency_seconds = x.block_latency_seconds; 25 | res.refresh_transactions = x.refresh_transactions; 26 | res.compact_blocks_high_bandwidth = x.compact_blocks_high_bandwidth; 27 | res.ds_proofs_enabled = x.ds_proofs_enabled; 28 | return res; 29 | } 30 | 31 | } //namespace 32 | 33 | inline 34 | kth::node::settings node_settings_to_cpp(kth_node_settings const& x) { 35 | return node_settings_to_common(x); 36 | } 37 | 38 | inline 39 | kth_node_settings node_settings_to_c(kth::node::settings const& x) { 40 | return node_settings_to_common(x); 41 | } 42 | 43 | inline 44 | void node_settings_delete(kth_node_settings*) { 45 | //do nothing 46 | } 47 | 48 | } // namespace kth::capi::helpers 49 | 50 | #endif // KTH_CAPI_CONFIG_NODE_HELPERS_HPP_ 51 | -------------------------------------------------------------------------------- /include/kth/capi/config/node_settings.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_NODE_SETTINGS_H_ 6 | #define KTH_CAPI_CONFIG_NODE_SETTINGS_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | typedef struct { 17 | uint32_t sync_peers; 18 | uint32_t sync_timeout_seconds; 19 | uint32_t block_latency_seconds; 20 | kth_bool_t refresh_transactions; 21 | kth_bool_t compact_blocks_high_bandwidth; 22 | kth_bool_t ds_proofs_enabled; 23 | } kth_node_settings; 24 | 25 | KTH_EXPORT 26 | kth_node_settings kth_config_node_settings_default(kth_network_t network); 27 | 28 | #ifdef __cplusplus 29 | } // extern "C" 30 | #endif 31 | 32 | #endif // KTH_CAPI_CONFIG_NODE_SETTINGS_H_ 33 | -------------------------------------------------------------------------------- /include/kth/capi/config/settings.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_SETTINGS_H_ 6 | #define KTH_CAPI_CONFIG_SETTINGS_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef struct { 18 | kth_node_settings node; 19 | kth_blockchain_settings chain; 20 | kth_database_settings database; 21 | kth_network_settings network; 22 | } kth_settings; 23 | 24 | KTH_EXPORT 25 | kth_settings kth_config_settings_default(kth_network_t network); 26 | 27 | KTH_EXPORT 28 | kth_bool_t kth_config_settings_get_from_file(char const* path, kth_settings** out_settings, char** out_error_message); 29 | 30 | #if defined(_WIN32) 31 | KTH_EXPORT 32 | kth_bool_t kth_config_settings_get_from_fileW(wchar_t const* path, kth_settings** out_settings, char** out_error_message); 33 | #endif // defined(_WIN32) 34 | 35 | KTH_EXPORT 36 | void kth_config_settings_destruct(void* settings); 37 | 38 | #ifdef __cplusplus 39 | } // extern "C" 40 | #endif 41 | 42 | 43 | #endif // KTH_CAPI_CONFIG_SETTINGS_H_ 44 | -------------------------------------------------------------------------------- /include/kth/capi/config/settings_helper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CONFIG_SETTINGS_HELPERS_HPP_ 6 | #define KTH_CAPI_CONFIG_SETTINGS_HELPERS_HPP_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #if ! defined(__EMSCRIPTEN__) 14 | #include 15 | #endif 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace kth::capi::helpers { 23 | 24 | inline 25 | kth::node::configuration settings_to_cpp(kth_settings const& x) { 26 | kth::node::configuration config(kth::domain::config::network::mainnet); 27 | config.node = node_settings_to_cpp(x.node); 28 | config.chain = blockchain_settings_to_cpp(x.chain); 29 | config.database = database_settings_to_cpp(x.database); 30 | #if ! defined(__EMSCRIPTEN__) 31 | config.network = network_settings_to_cpp(x.network); 32 | #endif 33 | return config; 34 | } 35 | 36 | // inline 37 | // kth_node_settings settings_to_c(kth::node::settings const& x) { 38 | // return node_settings_to_common(x); 39 | // } 40 | 41 | } // namespace kth::capi::helpers 42 | 43 | #endif // KTH_CAPI_CONFIG_SETTINGS_HELPERS_HPP_ 44 | -------------------------------------------------------------------------------- /include/kth/capi/double_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_DOUBLE_LIST_H_ 6 | #define KTH_CAPI_DOUBLE_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_double_list_t kth_core_double_list_construct(void); 19 | 20 | KTH_EXPORT 21 | void kth_core_double_list_push_back(kth_double_list_t double_list, double value); 22 | 23 | KTH_EXPORT 24 | void kth_core_double_list_destruct(kth_double_list_t double_list); 25 | 26 | KTH_EXPORT 27 | double kth_core_double_list_nth(kth_double_list_t double_list, kth_size_t index); 28 | 29 | KTH_EXPORT 30 | kth_size_t kth_core_double_list_count(kth_double_list_t double_list); 31 | 32 | #ifdef __cplusplus 33 | } // extern "C" 34 | #endif 35 | 36 | #endif /* KTH_CAPI_WALLET_WORD_LIST_H_ */ -------------------------------------------------------------------------------- /include/kth/capi/hash.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_HASH_H_ 6 | #define KTH_CAPI_HASH_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | KTH_EXPORT 17 | kth_hash_t kth_sha256_hash(uint8_t const* data, kth_size_t size); 18 | 19 | KTH_EXPORT 20 | kth_hash_t kth_sha256_hash_reversed(uint8_t const* data, kth_size_t size); 21 | 22 | KTH_EXPORT 23 | char* kth_sha256_hash_reversed_str(uint8_t const* data, kth_size_t size); 24 | 25 | KTH_EXPORT 26 | kth_hash_t kth_str_to_hash(char const* str); 27 | 28 | KTH_EXPORT 29 | char* kth_hash_to_str(kth_hash_t hash); 30 | 31 | KTH_EXPORT 32 | void kth_shorthash_set(kth_shorthash_t* shorthash, uint8_t const* data); 33 | 34 | KTH_EXPORT 35 | void kth_shorthash_destruct(kth_shorthash_t* shorthash); 36 | 37 | KTH_EXPORT 38 | void kth_hash_set(kth_hash_t* hash, uint8_t const* data); 39 | 40 | KTH_EXPORT 41 | void kth_hash_destruct(kth_hash_t* hash); 42 | 43 | KTH_EXPORT 44 | void kth_longhash_set(kth_longhash_t* longhash, uint8_t const* data); 45 | 46 | KTH_EXPORT 47 | void kth_longhash_destruct(kth_longhash_t* longhash); 48 | 49 | KTH_EXPORT 50 | void kth_encrypted_seed_set(kth_encrypted_seed_t* seed, uint8_t const* data); 51 | 52 | KTH_EXPORT 53 | void kth_encrypted_seed_destruct(kth_encrypted_seed_t* seed); 54 | 55 | KTH_EXPORT 56 | void kth_ec_secret_set(kth_ec_secret_t* secret, uint8_t const* data); 57 | 58 | KTH_EXPORT 59 | void kth_ec_secret_destruct(kth_ec_secret_t* secret); 60 | 61 | #ifdef __cplusplus 62 | } // extern "C" 63 | #endif 64 | 65 | #endif /* KTH_CAPI_HASH_H_ */ 66 | -------------------------------------------------------------------------------- /include/kth/capi/hash_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_HASH_LIST_H_ 6 | #define KTH_CAPI_HASH_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_LIST_DECLARE(core, kth_hash_list_t, kth_hash_t, hash_list) 19 | 20 | KTH_EXPORT 21 | void kth_core_hash_list_nth_out(kth_hash_list_t list, kth_size_t n, kth_hash_t* out_hash); 22 | 23 | #ifdef __cplusplus 24 | } // extern "C" 25 | #endif 26 | 27 | #endif /* KTH_CAPI_HASH_LIST_H_ */ 28 | -------------------------------------------------------------------------------- /include/kth/capi/libconfig/libconfig.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_LIBCONFIG_LIBCONFIG_H_ 6 | #define KTH_CAPI_LIBCONFIG_LIBCONFIG_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef enum { 18 | kth_libconfig_log_library_boost = 0, 19 | kth_libconfig_log_library_spdlog = 1, 20 | kth_libconfig_log_library_binlog = 2, 21 | } kth_libconfig_log_library_t; 22 | 23 | typedef struct { 24 | uint8_t size_int; 25 | uint8_t size_long; 26 | uint8_t size_pointer; 27 | } kth_libconfig_type_sizes_t; 28 | 29 | typedef struct { 30 | kth_libconfig_log_library_t log_library; 31 | kth_bool_t use_libmdbx; 32 | char const* version; 33 | char const* microarchitecture_id; 34 | kth_currency_t currency; 35 | kth_bool_t mempool; 36 | kth_bool_t db_readonly; 37 | kth_bool_t debug_mode; 38 | 39 | char const* architecture; // x86_64, ARM64 40 | char const* os_name; // Linux, Windows, macOS 41 | char const* compiler_name; // GCC, Clang, MSVC 42 | char const* compiler_version; // ej. "12.2.0" 43 | char const* optimization_level; // -O2, -O3 44 | uint32_t build_timestamp; // Epoch time 45 | char const* build_git_hash; // Git hash 46 | char const* endianness; // little, big 47 | 48 | kth_libconfig_type_sizes_t type_sizes; 49 | 50 | } kth_libconfig_t; 51 | 52 | KTH_EXPORT 53 | kth_libconfig_t kth_libconfig_get(); 54 | 55 | #ifdef __cplusplus 56 | } // extern "C" 57 | #endif 58 | 59 | 60 | #endif // KTH_CAPI_LIBCONFIG_LIBCONFIG_H_ 61 | -------------------------------------------------------------------------------- /include/kth/capi/node.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_NODE_H_ 6 | #define KTH_CAPI_NODE_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | KTH_EXPORT 20 | kth_node_t kth_node_construct(kth_settings const* settings, kth_bool_t stdout_enabled); 21 | 22 | KTH_EXPORT 23 | void kth_node_destruct(kth_node_t node); 24 | 25 | #if ! defined(KTH_DB_READONLY) 26 | KTH_EXPORT 27 | int kth_node_initchain(kth_node_t node); 28 | #endif // ! defined(KTH_DB_READONLY) 29 | 30 | #if ! defined(KTH_DB_READONLY) 31 | KTH_EXPORT 32 | void kth_node_init_run_and_wait_for_signal(kth_node_t node, void* ctx, kth_start_modules_t mods, kth_run_handler_t handler); 33 | 34 | KTH_EXPORT 35 | void kth_node_init_run(kth_node_t node, void* ctx, kth_start_modules_t mods, kth_run_handler_t handler); 36 | 37 | KTH_EXPORT 38 | kth_error_code_t kth_node_init_run_sync(kth_node_t node, kth_start_modules_t mods); 39 | #endif // ! defined(KTH_DB_READONLY) 40 | 41 | KTH_EXPORT 42 | void kth_node_signal_stop(kth_node_t node); 43 | 44 | KTH_EXPORT 45 | int kth_node_close(kth_node_t node); 46 | 47 | KTH_EXPORT 48 | int kth_node_stopped(kth_node_t node); 49 | 50 | KTH_EXPORT 51 | kth_chain_t kth_node_get_chain(kth_node_t node); 52 | 53 | KTH_EXPORT 54 | kth_p2p_t kth_node_get_p2p(kth_node_t node); 55 | 56 | 57 | #ifdef __cplusplus 58 | } // extern "C" 59 | #endif 60 | 61 | #endif // KTH_CAPI_NODE_H_ 62 | -------------------------------------------------------------------------------- /include/kth/capi/node/settings.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_NODE_SETTINGS_H_ 6 | #define KTH_CAPI_NODE_SETTINGS_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_currency_t kth_node_settings_get_currency(); 19 | 20 | #if ! defined(__EMSCRIPTEN__) 21 | KTH_EXPORT 22 | kth_network_t kth_node_settings_get_network(kth_node_t exec); 23 | #endif 24 | 25 | KTH_EXPORT 26 | char const* kth_node_settings_cashaddr_prefix(); 27 | 28 | #ifdef __cplusplus 29 | } // extern "C" 30 | #endif 31 | 32 | #endif /* KTH_CAPI_NODE_SETTINGS_H_ */ 33 | -------------------------------------------------------------------------------- /include/kth/capi/node_info.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_NODE_INFO_H_ 6 | #define KTH_CAPI_NODE_INFO_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | KTH_EXPORT 20 | void kth_node_print_thread_id(); 21 | 22 | KTH_EXPORT 23 | uint64_t kth_node_get_thread_id(); 24 | 25 | KTH_EXPORT 26 | char const* kth_node_capi_version(void); 27 | 28 | KTH_EXPORT 29 | char const* kth_node_cppapi_version(void); 30 | 31 | KTH_EXPORT 32 | char const* kth_node_microarchitecture(void); 33 | 34 | KTH_EXPORT 35 | char const* kth_node_march_names(void); 36 | 37 | KTH_EXPORT 38 | char const* kth_node_currency_symbol(void); 39 | 40 | KTH_EXPORT 41 | char const* kth_node_currency(void); 42 | 43 | // #ifndef __EMSCRIPTEN__ 44 | KTH_EXPORT 45 | char const* kth_node_db_type(kth_db_mode_t mode); 46 | // #endif 47 | 48 | KTH_EXPORT 49 | uint32_t kth_node_cppapi_build_timestamp(void); 50 | 51 | #ifdef __cplusplus 52 | } // extern "C" 53 | #endif 54 | 55 | #endif // KTH_CAPI_NODE_INFO_H_ 56 | -------------------------------------------------------------------------------- /include/kth/capi/p2p/p2p.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_P2P_P2P_H_ 6 | #define KTH_CAPI_P2P_P2P_H_ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | KTH_EXPORT 16 | kth_size_t kth_p2p_address_count(kth_p2p_t p2p); 17 | 18 | KTH_EXPORT 19 | void kth_p2p_stop(kth_p2p_t p2p); 20 | 21 | KTH_EXPORT 22 | void kth_p2p_close(kth_p2p_t p2p); 23 | 24 | KTH_EXPORT 25 | kth_bool_t kth_p2p_stopped(kth_p2p_t p2p); 26 | 27 | #ifdef __cplusplus 28 | } // extern "C" 29 | #endif 30 | 31 | #endif /* KTH_CAPI_P2P_P2P_H_ */ 32 | -------------------------------------------------------------------------------- /include/kth/capi/platform.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_PLATFORM_H 6 | #define KTH_CAPI_PLATFORM_H 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | KTH_EXPORT 16 | void kth_platform_free(void* ptr); 17 | 18 | KTH_EXPORT 19 | char* kth_platform_allocate_string(kth_size_t n); 20 | 21 | KTH_EXPORT 22 | void kth_platform_allocate_string_at(char** ptr, kth_size_t n); 23 | 24 | KTH_EXPORT 25 | char** kth_platform_allocate_array_of_strings(kth_size_t n); 26 | 27 | KTH_EXPORT 28 | void kth_platform_print_string(char* str); 29 | 30 | KTH_EXPORT 31 | char* kth_platform_allocate_and_copy_string_at(char** ptr, kth_size_t offset, char const* str); 32 | 33 | #ifdef __cplusplus 34 | } // extern "C" 35 | #endif 36 | 37 | #endif //KTH_CAPI_PLATFORM_H 38 | -------------------------------------------------------------------------------- /include/kth/capi/string_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_STRING_LIST_H_ 6 | #define KTH_CAPI_STRING_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_string_list_t kth_core_string_list_construct(void); 19 | 20 | KTH_EXPORT 21 | void kth_core_string_list_push_back(kth_string_list_t string_list, char const* string); 22 | 23 | KTH_EXPORT 24 | void kth_core_string_list_destruct(kth_string_list_t string_list); 25 | 26 | KTH_EXPORT 27 | char const* kth_core_string_list_nth(kth_string_list_t string_list, kth_size_t index); 28 | 29 | KTH_EXPORT 30 | kth_size_t kth_core_string_list_count(kth_string_list_t string_list); 31 | 32 | 33 | #ifdef __cplusplus 34 | } // extern "C" 35 | #endif 36 | 37 | #endif /* KTH_CAPI_WALLET_WORD_LIST_H_ */ -------------------------------------------------------------------------------- /include/kth/capi/type_conversions.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_TYPE_CONVERSIONS_H_ 6 | #define KTH_CAPI_TYPE_CONVERSIONS_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #define KTH_CONV_DECLARE(api, type_c, type_cpp, obj_name) \ 14 | type_cpp const& kth_##api##_##obj_name##_const_cpp(type_c); \ 15 | type_cpp& kth_##api##_##obj_name##_cpp(type_c); 16 | 17 | #define KTH_CONV_DEFINE(api, type_c, type_cpp, obj_name) \ 18 | type_cpp const& kth_##api##_##obj_name##_const_cpp(type_c o) { \ 19 | return *static_cast(o); \ 20 | } \ 21 | type_cpp& kth_##api##_##obj_name##_cpp(type_c o) { \ 22 | return *static_cast(o); \ 23 | } 24 | 25 | #define KTH_CONV_DECLARE_JUST_CONST(api, type_c, type_cpp, obj_name) \ 26 | type_cpp const& kth_##api##_##obj_name##_const_cpp(type_c); 27 | 28 | #define KTH_CONV_DEFINE_JUST_CONST(api, type_c, type_cpp, obj_name) \ 29 | type_cpp const& kth_##api##_##obj_name##_const_cpp(type_c o) { \ 30 | return *static_cast(o); \ 31 | } 32 | 33 | #define KTH_CONV_DECLARE_JUST_MUTABLE(api, type_c, type_cpp, obj_name) \ 34 | type_cpp& kth_##api##_##obj_name##_cpp(type_c o); 35 | 36 | #define KTH_CONV_DEFINE_JUST_MUTABLE(api, type_c, type_cpp, obj_name) \ 37 | type_cpp& kth_##api##_##obj_name##_cpp(type_c o) { \ 38 | return *static_cast(o); \ 39 | } 40 | 41 | #endif /* KTH_CAPI_TYPE_CONVERSIONS_H_ */ 42 | -------------------------------------------------------------------------------- /include/kth/capi/u32_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CORE_U32_LIST_H_ 6 | #define KTH_CAPI_CORE_U32_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_u32_list_t kth_core_u32_list_construct(void); 19 | 20 | KTH_EXPORT 21 | void kth_core_u32_list_push_back(kth_u32_list_t u32_list, uint32_t value); 22 | 23 | KTH_EXPORT 24 | void kth_core_u32_list_destruct(kth_u32_list_t u32_list); 25 | 26 | KTH_EXPORT 27 | uint32_t kth_core_u32_list_nth(kth_u32_list_t u32_list, kth_size_t index); 28 | 29 | KTH_EXPORT 30 | kth_size_t kth_core_u32_list_count(kth_u32_list_t u32_list); 31 | 32 | #ifdef __cplusplus 33 | } // extern "C" 34 | #endif 35 | 36 | #endif // KTH_CAPI_CORE_U32_LIST_H_ -------------------------------------------------------------------------------- /include/kth/capi/u64_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_CORE_U64_LIST_H_ 6 | #define KTH_CAPI_CORE_U64_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_u64_list_t kth_core_u64_list_construct(void); 19 | 20 | KTH_EXPORT 21 | void kth_core_u64_list_push_back(kth_u64_list_t u64_list, uint64_t value); 22 | 23 | KTH_EXPORT 24 | void kth_core_u64_list_destruct(kth_u64_list_t u64_list); 25 | 26 | KTH_EXPORT 27 | uint64_t kth_core_u64_list_nth(kth_u64_list_t u64_list, kth_size_t index); 28 | 29 | KTH_EXPORT 30 | kth_size_t kth_core_u64_list_count(kth_u64_list_t u64_list); 31 | 32 | #ifdef __cplusplus 33 | } // extern "C" 34 | #endif 35 | 36 | #endif /* KTH_CAPI_CORE_U64_LIST_H_ */ -------------------------------------------------------------------------------- /include/kth/capi/version.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_VERSION_H_ 6 | #define KTH_CAPI_VERSION_H_ 7 | 8 | #define KTH_CAPI_VERSION "0.0.0-dev.1"; 9 | 10 | #endif //KTH_CAPI_VERSION_H_ 11 | -------------------------------------------------------------------------------- /include/kth/capi/visibility.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_VISIBILITY_H_ 6 | #define KTH_CAPI_VISIBILITY_H_ 7 | 8 | 9 | #if defined(KTH_LIB_STATIC) 10 | #define KTH_EXPORT 11 | #else 12 | #if defined(_WIN32) || defined(__CYGWIN__) 13 | #ifdef KTH_EXPORTS 14 | #ifdef __GNUC__ 15 | #define KTH_EXPORT __attribute__ ((dllexport)) 16 | #else 17 | #define KTH_EXPORT __declspec(dllexport) 18 | #endif 19 | #else 20 | #ifdef __GNUC__ 21 | #define KTH_EXPORT __attribute__ ((dllimport)) 22 | #else 23 | #define KTH_EXPORT __declspec(dllimport) 24 | #endif 25 | #endif 26 | #else 27 | #if __GNUC__ >= 4 28 | #define KTH_EXPORT __attribute__ ((visibility ("default"))) 29 | #else 30 | #define KTH_EXPORT 31 | #endif 32 | #endif 33 | #endif 34 | 35 | 36 | 37 | 38 | #endif /* KTH_CAPI_VISIBILITY_H_ */ 39 | -------------------------------------------------------------------------------- /include/kth/capi/vm/interpreter.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_VM_INTERPRETER_H_ 6 | #define KTH_CAPI_VM_INTERPRETER_H_ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | /// Run program script. 16 | 17 | // static 18 | // code run(program& program); 19 | 20 | // /// Run individual operations (idependent of the script). 21 | // /// For best performance use script runner for a sequence of operations. 22 | // static 23 | // code run(operation const& op, program& program); 24 | 25 | 26 | KTH_EXPORT 27 | kth_error_code_t kth_vm_interpreter_run(kth_program_t program); 28 | 29 | KTH_EXPORT 30 | kth_error_code_t kth_vm_interpreter_run_operation(kth_operation_t operation, kth_program_t program); 31 | 32 | 33 | // Debug step by step 34 | // ---------------------------------------------------------------------------- 35 | // static 36 | // std::pair debug_start(program const& program); 37 | 38 | // static 39 | // bool debug_steps_available(program const& program, size_t step); 40 | 41 | // static 42 | // std::tuple debug_step(program program, size_t step); 43 | 44 | // static 45 | // code debug_end(program const& program); 46 | 47 | KTH_EXPORT 48 | kth_error_code_t kth_vm_interpreter_debug_start(kth_program_const_t program, kth_size_t* out_step); 49 | 50 | KTH_EXPORT 51 | kth_bool_t kth_vm_interpreter_debug_steps_available(kth_program_const_t program, kth_size_t step); 52 | 53 | KTH_EXPORT 54 | kth_error_code_t kth_vm_interpreter_debug_step(kth_program_const_t program, kth_size_t step, kth_size_t* out_step, kth_program_t* out_program); 55 | 56 | KTH_EXPORT 57 | kth_error_code_t kth_vm_interpreter_debug_end(kth_program_const_t program); 58 | 59 | 60 | #ifdef __cplusplus 61 | } // extern "C" 62 | #endif 63 | 64 | 65 | #endif /* KTH_CAPI_VM_PROGRAM_H_ */ 66 | -------------------------------------------------------------------------------- /include/kth/capi/vm/metrics.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_VM_METRICS_H_ 6 | #define KTH_CAPI_VM_METRICS_H_ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | // KTH_EXPORT 16 | // kth_bool_t kth_wallet_secret_to_public(kth_ec_compressed_t* out, kth_ec_secret_t secret); 17 | 18 | 19 | #ifdef __cplusplus 20 | } // extern "C" 21 | #endif 22 | 23 | 24 | #endif // KTH_CAPI_VM_METRICS_H_ 25 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/ec_compressed_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_EC_COMPRESSED_LIST_H_ 6 | #define KTH_CAPI_WALLET_EC_COMPRESSED_LIST_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | // KTH_LIST_DECLARE(wallet, kth_ec_compressed_list_t, kth_ec_compressed_t, ec_compressed_list) 20 | 21 | KTH_EXPORT 22 | kth_ec_compressed_list_t kth_wallet_ec_compressed_list_construct_default(); 23 | 24 | KTH_EXPORT 25 | void kth_wallet_ec_compressed_list_push_back(kth_ec_compressed_list_t l, kth_ec_compressed_t e); 26 | 27 | KTH_EXPORT 28 | void kth_wallet_ec_compressed_list_destruct(kth_ec_compressed_list_t l); 29 | 30 | KTH_EXPORT 31 | kth_size_t kth_wallet_ec_compressed_list_count(kth_ec_compressed_list_t l); 32 | 33 | KTH_EXPORT 34 | kth_ec_compressed_t kth_wallet_ec_compressed_list_nth(kth_ec_compressed_list_t l, kth_size_t n); 35 | 36 | KTH_EXPORT 37 | void kth_wallet_ec_compressed_list_nth_out(kth_ec_compressed_list_t l, kth_size_t n, kth_ec_compressed_t* out_elem); 38 | 39 | #ifdef __cplusplus 40 | } // extern "C" 41 | #endif 42 | 43 | #endif /* KTH_CAPI_WALLET_EC_COMPRESSED_LIST_H_ */ 44 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/ec_private.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_EC_PRIVATE_H_ 6 | #define KTH_CAPI_WALLET_EC_PRIVATE_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_EXPORT 19 | kth_ec_private_t kth_wallet_ec_private_construct_default(void); 20 | 21 | KTH_EXPORT 22 | kth_ec_private_t kth_wallet_ec_private_construct_string(char const* wif, uint8_t version); 23 | 24 | KTH_EXPORT 25 | kth_ec_private_t kth_wallet_ec_private_construct_compressed(kth_wif_compressed_t const* wif, uint8_t version); 26 | 27 | KTH_EXPORT 28 | kth_ec_private_t kth_wallet_ec_private_construct_uncompressed(kth_wif_uncompressed_t const* wif, uint8_t version); 29 | 30 | KTH_EXPORT 31 | kth_ec_private_t kth_wallet_ec_private_construct_secret(kth_ec_secret_t const* secret, uint16_t version, kth_bool_t compress); 32 | 33 | KTH_EXPORT 34 | void kth_wallet_ec_private_destruct(kth_ec_private_t obj); 35 | 36 | KTH_EXPORT 37 | kth_bool_t kth_wallet_ec_private_is_valid(kth_ec_private_t obj); 38 | 39 | KTH_EXPORT 40 | char* kth_wallet_ec_private_encoded(kth_ec_private_t obj); 41 | 42 | KTH_EXPORT 43 | kth_ec_secret_t kth_wallet_ec_private_secret(kth_ec_private_t obj); 44 | 45 | KTH_EXPORT 46 | uint16_t kth_wallet_ec_private_version(kth_ec_private_t obj); 47 | 48 | KTH_EXPORT 49 | uint8_t kth_wallet_ec_private_payment_version(kth_ec_private_t obj); 50 | 51 | KTH_EXPORT 52 | uint8_t kth_wallet_ec_private_wif_version(kth_ec_private_t obj); 53 | 54 | KTH_EXPORT 55 | kth_bool_t kth_wallet_ec_private_compressed(kth_ec_private_t obj); 56 | 57 | KTH_EXPORT 58 | kth_ec_public_t kth_wallet_ec_private_to_public(kth_ec_private_t obj); 59 | 60 | KTH_EXPORT 61 | kth_payment_address_t kth_wallet_ec_private_to_payment_address(kth_ec_private_t obj); 62 | 63 | #ifdef __cplusplus 64 | } // extern "C" 65 | #endif 66 | 67 | #endif /* KTH_CAPI_WALLET_EC_PRIVATE_H_ */ 68 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/ec_public.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_EC_PUBLIC_H_ 6 | #define KTH_CAPI_WALLET_EC_PUBLIC_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | KTH_EXPORT 19 | kth_ec_public_t kth_wallet_ec_public_construct_default(void); 20 | 21 | KTH_EXPORT 22 | kth_ec_public_t kth_wallet_ec_public_construct(kth_ec_private_t secret); 23 | 24 | KTH_EXPORT 25 | kth_ec_public_t kth_wallet_ec_public_construct_from_decoded(uint8_t const* decoded, kth_size_t size); 26 | 27 | KTH_EXPORT 28 | kth_ec_public_t kth_wallet_ec_public_construct_from_base16(char const* base16); 29 | 30 | KTH_EXPORT 31 | kth_ec_public_t kth_wallet_ec_public_construct_from_point(kth_ec_compressed_t const* point, kth_bool_t compress); 32 | 33 | KTH_EXPORT 34 | void kth_wallet_ec_public_destruct(kth_ec_public_t obj); 35 | 36 | KTH_EXPORT 37 | kth_bool_t kth_wallet_ec_public_is_valid(kth_ec_public_t obj); 38 | 39 | KTH_EXPORT 40 | char* kth_wallet_ec_public_encoded(kth_ec_public_t obj); 41 | 42 | KTH_EXPORT 43 | kth_ec_compressed_t kth_wallet_ec_public_point(kth_ec_public_t obj); 44 | 45 | // KTH_EXPORT 46 | // uint16_t kth_wallet_ec_public_version(kth_ec_public_t obj); 47 | 48 | // KTH_EXPORT 49 | // uint8_t kth_wallet_ec_public_payment_version(kth_ec_public_t obj); 50 | 51 | // KTH_EXPORT 52 | // uint8_t kth_wallet_ec_public_wif_version(kth_ec_public_t obj); 53 | 54 | KTH_EXPORT 55 | kth_bool_t kth_wallet_ec_public_compressed(kth_ec_public_t obj); 56 | 57 | KTH_EXPORT 58 | uint8_t const* kth_wallet_ec_public_to_data(kth_ec_public_t obj, kth_size_t* out_size); 59 | 60 | KTH_EXPORT 61 | kth_bool_t kth_wallet_ec_public_to_uncompressed(kth_ec_public_t obj, kth_ec_uncompressed_t* out_data); 62 | 63 | KTH_EXPORT 64 | kth_payment_address_t kth_wallet_ec_public_to_payment_address(kth_ec_public_t obj, uint8_t version); 65 | 66 | #ifdef __cplusplus 67 | } // extern "C" 68 | #endif 69 | 70 | #endif /* KTH_CAPI_WALLET_EC_PUBLIC_H_ */ 71 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/elliptic_curve.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_ELLIPTIC_CURVE_H_ 6 | #define KTH_CAPI_WALLET_ELLIPTIC_CURVE_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | KTH_EXPORT 17 | kth_bool_t kth_wallet_secret_to_public(kth_ec_compressed_t* out, kth_ec_secret_t secret); 18 | 19 | #ifdef __cplusplus 20 | } // extern "C" 21 | #endif 22 | 23 | 24 | #endif /* KTH_CAPI_WALLET_ELLIPTIC_CURVE_H_ */ 25 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/hd_lineage.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_HD_LINEAGE_H_ 6 | #define KTH_CAPI_WALLET_HD_LINEAGE_H_ 7 | 8 | typedef struct kth_hd_lineage { 9 | uint64_t prefixes; 10 | uint8_t depth; 11 | uint32_t parent_fingerprint; 12 | uint32_t child_number; 13 | } kth_hd_lineage_t; 14 | 15 | #endif //KTH_CAPI_WALLET_HD_LINEAGE_H_ 16 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/hd_private.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_HD_PRIVATE_H_ 6 | #define KTH_CAPI_WALLET_HD_PRIVATE_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | KTH_EXPORT 22 | kth_hd_private_t kth_wallet_hd_private_construct_default(void); 23 | 24 | KTH_EXPORT 25 | kth_hd_private_t kth_wallet_hd_private_construct_key(kth_hd_key_t const* private_key); 26 | 27 | KTH_EXPORT 28 | kth_hd_private_t kth_wallet_hd_private_construct_key_prefix(kth_hd_key_t const* private_key, uint32_t prefix); 29 | 30 | KTH_EXPORT 31 | kth_hd_private_t kth_wallet_hd_private_construct_key_prefixes(kth_hd_key_t const* private_key, uint64_t prefixes); 32 | 33 | KTH_EXPORT 34 | kth_hd_private_t kth_wallet_hd_private_construct_seed(uint8_t const* seed, kth_size_t size, uint64_t prefixes); 35 | 36 | KTH_EXPORT 37 | kth_hd_private_t kth_wallet_hd_private_construct_string(char const* encoded); 38 | 39 | KTH_EXPORT 40 | kth_hd_private_t kth_wallet_hd_private_construct_string_prefix(char const* encoded, uint32_t prefix); 41 | 42 | KTH_EXPORT 43 | kth_hd_private_t kth_wallet_hd_private_construct_string_prefixes(char const* encoded, uint64_t prefixes); 44 | 45 | KTH_EXPORT 46 | void kth_wallet_hd_private_destruct(kth_hd_private_t hd_private); 47 | 48 | KTH_EXPORT 49 | kth_bool_t kth_wallet_hd_private_is_valid(kth_hd_private_t hd_private); 50 | 51 | KTH_EXPORT 52 | char* kth_wallet_hd_private_encoded(kth_hd_private_t hd_private); 53 | 54 | KTH_EXPORT 55 | kth_ec_secret_t kth_wallet_hd_private_secret(kth_hd_private_t hd_private); 56 | 57 | KTH_EXPORT 58 | kth_hd_chain_code_t kth_wallet_hd_private_chain_code(kth_hd_private_t hd_private); 59 | 60 | KTH_EXPORT 61 | kth_hd_lineage_t kth_wallet_hd_private_lineage(kth_hd_private_t hd_private); 62 | 63 | KTH_EXPORT 64 | kth_ec_compressed_t kth_wallet_hd_private_point(kth_hd_private_t hd_private); 65 | 66 | KTH_EXPORT 67 | kth_hd_key_t kth_wallet_hd_private_to_hd_key(kth_hd_private_t hd_private); 68 | 69 | KTH_EXPORT 70 | kth_hd_public_t kth_wallet_hd_private_to_public(kth_hd_private_t hd_private); 71 | 72 | KTH_EXPORT 73 | kth_hd_private_t kth_wallet_hd_private_derive_private(kth_hd_private_t hd_private, uint32_t index); 74 | 75 | KTH_EXPORT 76 | kth_hd_public_t kth_wallet_hd_private_derive_public(kth_hd_private_t hd_private, uint32_t index); 77 | 78 | #ifdef __cplusplus 79 | } // extern "C" 80 | #endif 81 | 82 | #endif /* KTH_CAPI_WALLET_HD_PRIVATE_H_ */ 83 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/hd_public.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_HD_PUBLIC_H_ 6 | #define KTH_CAPI_WALLET_HD_PUBLIC_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | KTH_EXPORT 21 | kth_hd_public_t kth_wallet_hd_public_construct_default(void); 22 | 23 | KTH_EXPORT 24 | kth_hd_public_t kth_wallet_hd_public_construct_key(kth_hd_key_t const* public_key); 25 | 26 | KTH_EXPORT 27 | kth_hd_public_t kth_wallet_hd_public_construct_key_prefix(kth_hd_key_t const* public_key, uint32_t prefix); 28 | 29 | KTH_EXPORT 30 | kth_hd_public_t kth_wallet_hd_public_construct_string(char const* encoded); 31 | 32 | KTH_EXPORT 33 | kth_hd_public_t kth_wallet_hd_public_construct_string_prefix(char const* encoded, uint32_t prefix); 34 | 35 | KTH_EXPORT 36 | void kth_wallet_hd_public_destruct(kth_hd_public_t hd_public); 37 | 38 | KTH_EXPORT 39 | kth_bool_t kth_wallet_hd_public_is_valid(kth_hd_public_t hd_public); 40 | 41 | KTH_EXPORT 42 | char* kth_wallet_hd_public_encoded(kth_hd_public_t hd_public); 43 | 44 | KTH_EXPORT 45 | kth_hd_chain_code_t kth_wallet_hd_public_chain_code(kth_hd_public_t hd_public); 46 | 47 | KTH_EXPORT 48 | kth_hd_lineage_t kth_wallet_hd_public_lineage(kth_hd_public_t hd_public); 49 | 50 | KTH_EXPORT 51 | kth_ec_compressed_t kth_wallet_hd_public_point(kth_hd_public_t hd_public); 52 | 53 | KTH_EXPORT 54 | kth_hd_key_t kth_wallet_hd_public_to_hd_key(kth_hd_public_t hd_public); 55 | 56 | KTH_EXPORT 57 | kth_hd_public_t kth_wallet_hd_public_derive_public(kth_hd_public_t hd_public, uint32_t index); 58 | 59 | #ifdef __cplusplus 60 | } // extern "C" 61 | #endif 62 | 63 | 64 | #endif /* KTH_CAPI_WALLET_HD_PUBLIC_H_ */ 65 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/payment_address.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_PAYMENT_ADDRESS_H_ 6 | #define KTH_CAPI_WALLET_PAYMENT_ADDRESS_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | KTH_EXPORT 20 | kth_payment_address_t kth_wallet_payment_address_construct_from_string(char const* address); 21 | 22 | KTH_EXPORT 23 | kth_payment_address_t kth_wallet_payment_address_construct_from_short_hash(kth_shorthash_t const* hash, uint8_t version); 24 | 25 | KTH_EXPORT 26 | kth_payment_address_t kth_wallet_payment_address_construct_from_hash(kth_hash_t const* hash, uint8_t version); 27 | 28 | KTH_EXPORT 29 | kth_payment_address_t kth_wallet_payment_address_construct_from_public(kth_ec_public_t point, uint8_t version); 30 | 31 | KTH_EXPORT 32 | kth_payment_address_t kth_wallet_payment_address_construct_from_script(kth_script_t script, uint8_t version); 33 | 34 | KTH_EXPORT 35 | kth_payment_address_t kth_wallet_payment_address_from_pay_public_key_hash_script(kth_script_t script, uint8_t version); 36 | 37 | KTH_EXPORT 38 | void kth_wallet_payment_address_destruct(kth_payment_address_t payment_address); 39 | 40 | #if defined(KTH_CURRENCY_BCH) 41 | KTH_EXPORT 42 | void kth_wallet_payment_address_set_cashaddr_prefix(char const* prefix); 43 | #endif //KTH_CURRENCY_BCH 44 | 45 | KTH_EXPORT 46 | char* kth_wallet_payment_address_encoded_legacy(kth_payment_address_t payment_address); 47 | 48 | #if defined(KTH_CURRENCY_BCH) 49 | KTH_EXPORT 50 | char* kth_wallet_payment_address_encoded_cashaddr(kth_payment_address_t payment_address, kth_bool_t token_aware); 51 | #endif //KTH_CURRENCY_BCH 52 | 53 | KTH_EXPORT 54 | kth_shorthash_t kth_wallet_payment_address_hash20(kth_payment_address_t payment_address); 55 | 56 | KTH_EXPORT 57 | kth_hash_t kth_wallet_payment_address_hash32(kth_payment_address_t payment_address); 58 | 59 | KTH_EXPORT 60 | uint8_t kth_wallet_payment_address_version(kth_payment_address_t payment_address); 61 | 62 | KTH_EXPORT 63 | kth_bool_t kth_wallet_payment_address_is_valid(kth_payment_address_t payment_address); 64 | 65 | KTH_EXPORT 66 | kth_payment_address_list_const_t kth_wallet_payment_address_extract(kth_script_t script, uint8_t p2kh_version, uint8_t p2sh_version); 67 | 68 | KTH_EXPORT 69 | kth_payment_address_list_const_t kth_wallet_payment_address_extract_input(kth_script_t script, uint8_t p2kh_version, uint8_t p2sh_version); 70 | 71 | KTH_EXPORT 72 | kth_payment_address_list_const_t kth_wallet_payment_address_extract_output(kth_script_t script, uint8_t p2kh_version, uint8_t p2sh_version); 73 | 74 | #ifdef __cplusplus 75 | } // extern "C" 76 | #endif 77 | 78 | #endif /* KTH_CAPI_WALLET_PAYMENT_ADDRESS_H_ */ 79 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/payment_address_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_PAYMENT_ADDRESS_LIST_H_ 6 | #define KTH_CAPI_WALLET_PAYMENT_ADDRESS_LIST_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | KTH_LIST_DECLARE(wallet, kth_payment_address_list_t, kth_payment_address_t, payment_address_list) 17 | 18 | #ifdef __cplusplus 19 | } // extern "C" 20 | #endif 21 | 22 | #endif /* KTH_CAPI_WALLET_PAYMENT_ADDRESS_LIST_H_ */ -------------------------------------------------------------------------------- /include/kth/capi/wallet/primitives.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_PRIMITIVES_H_ 6 | #define KTH_CAPI_WALLET_PRIMITIVES_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #define KTH_HD_CHAIN_CODE_SIZE 32 18 | #define KTH_HD_KEY_SIZE 82 19 | #define KTH_EC_COMPRESSED_SIZE 33 20 | #define KTH_BITCOIN_EC_UNCOMPRESSED_SIZE 65 21 | #define KTH_BITCOIN_EC_SECRET_SIZE 32 22 | #define KTH_HD_FIRST_HARDENED_KEY (1 << 31) 23 | #define KTH_WIF_UNCOMPRESSED_SIZE 37U 24 | #define KTH_WIF_COMPRESSED_SIZE 38U 25 | #define KTH_EC_SIGNATURE_SIZE 64 26 | typedef struct { 27 | uint8_t data[KTH_HD_CHAIN_CODE_SIZE]; 28 | } kth_hd_chain_code_t; 29 | 30 | typedef struct { 31 | uint8_t data[KTH_HD_KEY_SIZE]; 32 | } kth_hd_key_t; 33 | 34 | typedef struct { 35 | uint8_t data[KTH_EC_COMPRESSED_SIZE]; 36 | } kth_ec_compressed_t; 37 | 38 | typedef struct { 39 | uint8_t data[KTH_BITCOIN_EC_UNCOMPRESSED_SIZE]; 40 | } kth_ec_uncompressed_t; 41 | 42 | typedef struct kth_ec_secret_t { 43 | uint8_t hash[KTH_BITCOIN_EC_SECRET_SIZE]; 44 | } kth_ec_secret_t; 45 | 46 | typedef struct { 47 | uint8_t data[KTH_WIF_UNCOMPRESSED_SIZE]; 48 | } kth_wif_uncompressed_t; 49 | 50 | typedef struct { 51 | uint8_t data[KTH_WIF_COMPRESSED_SIZE]; 52 | } kth_wif_compressed_t; 53 | 54 | 55 | // Parsed ECDSA signature: 56 | typedef struct { 57 | uint8_t data[KTH_EC_SIGNATURE_SIZE]; 58 | } kth_ec_signature_t; 59 | 60 | 61 | typedef void* kth_ec_private_t; 62 | typedef void* kth_ec_public_t; 63 | typedef void* kth_hd_private_t; 64 | typedef void* kth_hd_public_t; 65 | 66 | #ifdef __cplusplus 67 | } // extern "C" 68 | #endif 69 | 70 | 71 | #endif /* KTH_CAPI_WALLET_PRIMITIVES_H_ */ 72 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/raw_output.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_RAW_OUTPUT_H_ 6 | #define KTH_CAPI_WALLET_RAW_OUTPUT_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_payment_address_t kth_wallet_raw_output_destiny(kth_raw_output_t obj); 19 | 20 | KTH_EXPORT 21 | uint64_t kth_wallet_raw_output_amount(kth_raw_output_t obj); 22 | 23 | #ifdef __cplusplus 24 | } // extern "C" 25 | #endif 26 | 27 | #endif /* KTH_CAPI_WALLET_RAW_OUTPUT_H_ */ 28 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/raw_output_list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_RAW_OUTPUT_LIST_H_ 6 | #define KTH_CAPI_WALLET_RAW_OUTPUT_LIST_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | KTH_LIST_DECLARE(wallet, kth_raw_output_list_t, kth_raw_output_t, raw_output_list) 17 | 18 | #ifdef __cplusplus 19 | } // extern "C" 20 | #endif 21 | 22 | #endif /* KTH_CAPI_WALLET_RAW_OUTPUT_LIST_H_ */ 23 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/transaction_functions.h: -------------------------------------------------------------------------------- 1 | // // Copyright (c) 2016-2024 Knuth Project developers. 2 | // // Distributed under the MIT software license, see the accompanying 3 | // // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | // #ifndef KTH_CAPI_WALLET_TRANSACTION_FUNCTIONS_H_ 6 | // #define KTH_CAPI_WALLET_TRANSACTION_FUNCTIONS_H_ 7 | 8 | // #include 9 | // #include 10 | 11 | // #ifdef __cplusplus 12 | // extern "C" { 13 | // #endif 14 | 15 | // // KTH_EXPORT 16 | // // kth_longhash_t kth_wallet_mnemonics_to_seed(kth_string_list_t mnemonics); 17 | 18 | 19 | // KTH_EXPORT 20 | // kth_error_code_t kth_wallet_tx_encode_with_extra_outputs( 21 | // kth_point_list_t outputs_to_spend, 22 | // kth_raw_output_list_t destiny_and_amount, 23 | // kth_output_list_t extra_outputs, 24 | // uint32_t locktime /*= 0*/, 25 | // uint32_t tx_version /*= 1*/, 26 | // uint8_t script_version /*= 5*/, 27 | // kth_transaction_t* out_transaction); 28 | 29 | // KTH_EXPORT 30 | // kth_error_code_t kth_wallet_tx_encode( 31 | // kth_point_list_t outputs_to_spend, 32 | // kth_raw_output_list_t destiny_and_amount, 33 | // uint32_t locktime /*= 0*/, 34 | // uint32_t tx_version /*= 1*/, 35 | // uint8_t script_version /*= 5*/, 36 | // kth_transaction_t* out_transaction); 37 | 38 | // KTH_EXPORT 39 | // kth_error_code_t input_signature_old( 40 | // kth_ec_secret_t private_key, 41 | // kth_script_t output_script, 42 | // kth_transaction_t tx, 43 | // uint32_t index, 44 | // uint8_t sign_type /*= 0x01*/, 45 | // kth_bool_t anyone_can_pay /*= false*/, 46 | // uint8_t** out_signature, 47 | // kth_size_t* out_signature_size); 48 | 49 | // KTH_EXPORT 50 | // kth_error_code_t input_signature_btc( 51 | // kth_ec_secret_t private_key, 52 | // kth_script_t output_script, 53 | // kth_transaction_t tx, 54 | // uint64_t amount, 55 | // uint32_t index, 56 | // uint8_t sign_type /*= 0x01*/, 57 | // kth_bool_t anyone_can_pay /*= false*/, 58 | // uint8_t** out_signature, 59 | // kth_size_t* out_signature_size); 60 | 61 | // KTH_EXPORT 62 | // kth_error_code_t input_signature_bch( 63 | // kth_ec_secret_t private_key, 64 | // kth_script_t output_script, 65 | // kth_transaction_t tx, 66 | // uint64_t amount, 67 | // uint32_t index, 68 | // uint8_t sign_type /*= 0x01*/, 69 | // kth_bool_t anyone_can_pay /*= false*/, 70 | // uint8_t** out_signature, 71 | // kth_size_t* out_signature_size); 72 | 73 | // KTH_EXPORT 74 | // kth_error_code_t input_set( 75 | // kth_script_t script, 76 | // kth_transaction_t tx, 77 | // uint32_t index /*= 0*/, 78 | // kth_transaction_t* out_transaction); 79 | 80 | // #ifdef __cplusplus 81 | // } // extern "C" 82 | // #endif 83 | 84 | // #endif /* KTH_CAPI_WALLET_TRANSACTION_FUNCTIONS_H_ */ 85 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/wallet.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_WALLET_H_ 6 | #define KTH_CAPI_WALLET_WALLET_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_longhash_t kth_wallet_mnemonics_to_seed(kth_string_list_t mnemonics); 19 | 20 | KTH_EXPORT 21 | void kth_wallet_mnemonics_to_seed_out(kth_string_list_t mnemonics, kth_longhash_t* out_hash); 22 | 23 | KTH_EXPORT 24 | kth_longhash_t kth_wallet_mnemonics_to_seed_normalized_passphrase(kth_string_list_t mnemonics, char const* normalized_passphrase); 25 | 26 | KTH_EXPORT 27 | void kth_wallet_mnemonics_to_seed_normalized_passphrase_out(kth_string_list_t mnemonics, char const* normalized_passphrase, kth_longhash_t* out_hash); 28 | 29 | KTH_EXPORT 30 | kth_hd_private_t kth_wallet_hd_new(kth_longhash_t seed, uint32_t version /* = 76066276*/); 31 | 32 | KTH_EXPORT 33 | kth_ec_secret_t kth_wallet_hd_private_to_ec(kth_hd_private_t key); 34 | 35 | KTH_EXPORT 36 | void kth_wallet_hd_private_to_ec_out(kth_hd_private_t key, kth_ec_secret_t* out_secret); 37 | 38 | KTH_EXPORT 39 | kth_ec_public_t kth_wallet_ec_to_public(kth_ec_secret_t secret, kth_bool_t uncompressed); 40 | 41 | KTH_EXPORT 42 | kth_payment_address_t kth_wallet_ec_to_address(kth_ec_public_t point, uint32_t version); 43 | 44 | 45 | // KTH_EXPORT 46 | // kth_longhash_t kth_wallet_mnemonics_to_seed(kth_string_list_t mnemonics); 47 | 48 | // KTH_EXPORT 49 | // kth_ec_secret_t kth_wallet_ec_new(uint8_t* seed, kth_size_t n); 50 | 51 | // KTH_EXPORT 52 | // kth_ec_public_t kth_wallet_ec_to_public(kth_ec_secret_t secret, kth_bool_t uncompressed); 53 | 54 | // KTH_EXPORT 55 | // kth_payment_address_t kth_wallet_ec_to_address(kth_ec_public_t point, uint32_t version); 56 | 57 | // KTH_EXPORT 58 | // kth_hd_private_t kth_wallet_hd_new(uint8_t* seed, kth_size_t n, uint32_t version /* = 76066276*/); 59 | 60 | // KTH_EXPORT 61 | // kth_ec_secret_t kth_wallet_hd_private_to_ec(kth_hd_private_t key); 62 | 63 | #ifdef __cplusplus 64 | } // extern "C" 65 | #endif 66 | 67 | #endif /* KTH_CAPI_WALLET_WALLET_H_ */ 68 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/wallet_data.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_WALLET_DATA_H_ 6 | #define KTH_CAPI_WALLET_WALLET_DATA_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | void kth_wallet_wallet_data_destruct(kth_wallet_data_t wallet_data); 19 | 20 | KTH_EXPORT 21 | kth_string_list_t kth_wallet_wallet_data_mnemonics(kth_wallet_data_t wallet_data); 22 | 23 | KTH_EXPORT 24 | kth_hd_public_t kth_wallet_wallet_data_xpub(kth_wallet_data_t wallet_data); 25 | 26 | KTH_EXPORT 27 | kth_encrypted_seed_t kth_wallet_wallet_data_encrypted_seed(kth_wallet_data_t wallet_data); 28 | 29 | KTH_EXPORT 30 | void kth_wallet_wallet_data_encrypted_seed_out(kth_wallet_data_t wallet_data, kth_encrypted_seed_t* out_encrypted_seed); 31 | 32 | #ifdef __cplusplus 33 | } // extern "C" 34 | #endif 35 | 36 | #endif /* KTH_CAPI_WALLET_WALLET_DATA_H_ */ 37 | -------------------------------------------------------------------------------- /include/kth/capi/wallet/wallet_manager.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef KTH_CAPI_WALLET_WALLET_MANAGER_H_ 6 | #define KTH_CAPI_WALLET_WALLET_MANAGER_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | KTH_EXPORT 18 | kth_error_code_t kth_wallet_create_wallet( 19 | char const* password, 20 | char const* normalized_passphrase, 21 | kth_wallet_data_t* out_wallet_data); 22 | 23 | KTH_EXPORT 24 | kth_error_code_t kth_wallet_decrypt_seed( 25 | char const* password, 26 | kth_encrypted_seed_t const* encrypted_seed, 27 | kth_longhash_t** out_decrypted_seed); 28 | 29 | #ifdef __cplusplus 30 | } // extern "C" 31 | #endif 32 | 33 | #endif /* KTH_CAPI_WALLET_WALLET_MANAGER_H_ */ 34 | -------------------------------------------------------------------------------- /src/binary.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | KTH_CONV_DEFINE(core, kth_binary_t, kth::binary, binary) 13 | 14 | // --------------------------------------------------------------------------- 15 | extern "C" { 16 | 17 | kth_binary_t kth_core_binary_construct() { 18 | return new kth::binary(); 19 | } 20 | 21 | kth_binary_t kth_core_binary_construct_string(char const* string) { 22 | return new kth::binary(string); 23 | } 24 | 25 | kth_binary_t kth_core_binary_construct_blocks(kth_size_t bits_size, uint8_t* blocks, kth_size_t n) { 26 | kth::data_slice blocks_cpp(blocks, blocks + n); 27 | return new kth::binary(bits_size, blocks_cpp); 28 | } 29 | 30 | void kth_core_binary_destruct(kth_binary_t binary) { 31 | delete &kth_core_binary_cpp(binary); 32 | } 33 | 34 | uint8_t const* kth_core_binary_blocks(kth_binary_t binary, kth_size_t* out_n) { 35 | *out_n = kth_core_binary_const_cpp(binary).blocks().size(); 36 | return kth_core_binary_cpp(binary).blocks().data(); 37 | } 38 | 39 | char* kth_core_binary_encoded(kth_binary_t binary) { 40 | std::string str = kth_core_binary_const_cpp(binary).encoded(); //TODO(fernando): returns a value or a reference? 41 | return kth::create_c_str(str); 42 | } 43 | 44 | } // extern "C" 45 | -------------------------------------------------------------------------------- /src/chain/block_indexes.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | KTH_LIST_DEFINE_CONVERTERS(chain, kth_block_indexes_t, kth_size_t, block_indexes) 10 | 11 | KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP(chain, kth_block_indexes_t, kth_size_t, block_indexes) 12 | 13 | extern "C" { 14 | 15 | KTH_LIST_DEFINE_VALUE(chain, kth_block_indexes_t, kth_size_t, block_indexes, kth_size_t, kth_size_t) 16 | 17 | } // extern "C" 18 | -------------------------------------------------------------------------------- /src/chain/block_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | 11 | KTH_LIST_DEFINE_CONVERTERS(chain, kth_block_list_t, kth::domain::chain::block, block_list) 12 | KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP(chain, kth_block_list_t, kth::domain::chain::block, block_list) 13 | 14 | extern "C" { 15 | 16 | KTH_LIST_DEFINE(chain, kth_block_list_t, kth_block_t, block_list, kth::domain::chain::block, kth_chain_block_const_cpp) 17 | 18 | } // extern "C" 19 | -------------------------------------------------------------------------------- /src/chain/compact_block.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | KTH_CONV_DEFINE(chain, kth_compact_block_t, kth::domain::message::compact_block, compact_block) 12 | 13 | // --------------------------------------------------------------------------- 14 | extern "C" { 15 | 16 | kth_header_t kth_chain_compact_block_header(kth_compact_block_t block) { 17 | return &kth_chain_compact_block_cpp(block).header(); 18 | } 19 | 20 | kth_bool_t kth_chain_compact_block_is_valid(kth_compact_block_t block) { 21 | return kth::bool_to_int(kth_chain_compact_block_const_cpp(block).is_valid()); 22 | } 23 | 24 | kth_size_t kth_chain_compact_block_serialized_size(kth_compact_block_t block, uint32_t version) { 25 | return kth_chain_compact_block_const_cpp(block).serialized_size(version); 26 | } 27 | 28 | kth_size_t kth_chain_compact_block_transaction_count(kth_compact_block_t block) { 29 | return kth_chain_compact_block_const_cpp(block).transactions().size(); 30 | } 31 | 32 | kth_transaction_t kth_chain_compact_block_transaction_nth(kth_compact_block_t block, kth_size_t n) { 33 | //precondition: n >=0 && n < transactions().size() 34 | 35 | auto* blk = &kth_chain_compact_block_cpp(block); 36 | auto& tx_n = blk->transactions()[n]; 37 | return &tx_n; 38 | } 39 | 40 | uint64_t kth_chain_compact_block_nonce(kth_compact_block_t block) { 41 | return kth_chain_compact_block_const_cpp(block).nonce(); 42 | } 43 | 44 | void kth_chain_compact_block_destruct(kth_compact_block_t block) { 45 | delete &kth_chain_compact_block_cpp(block); 46 | } 47 | 48 | void kth_chain_compact_block_reset(kth_compact_block_t block) { 49 | kth_chain_compact_block_cpp(block).reset(); 50 | } 51 | 52 | } // extern "C" 53 | -------------------------------------------------------------------------------- /src/chain/double_spend_proof.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | KTH_CONV_DEFINE(chain, kth_double_spend_proof_t, kth::domain::message::double_spend_proof, double_spend_proof) 13 | 14 | // --------------------------------------------------------------------------- 15 | extern "C" { 16 | 17 | kth_outputpoint_const_t kth_chain_double_spend_proof_out_point(kth_double_spend_proof_t dsp) { 18 | return &kth_chain_double_spend_proof_cpp(dsp).out_point(); 19 | } 20 | 21 | kth_double_spend_proof_spender_const_t kth_chain_double_spend_proof_spender1(kth_double_spend_proof_t dsp) { 22 | return &kth_chain_double_spend_proof_cpp(dsp).spender1(); 23 | } 24 | 25 | kth_double_spend_proof_spender_const_t kth_chain_double_spend_proof_spender2(kth_double_spend_proof_t dsp) { 26 | return &kth_chain_double_spend_proof_cpp(dsp).spender2(); 27 | } 28 | 29 | kth_hash_t kth_chain_double_spend_proof_hash(kth_double_spend_proof_t dsp) { 30 | auto const& hash_cpp = kth_chain_double_spend_proof_const_cpp(dsp).hash(); 31 | return kth::to_hash_t(hash_cpp); 32 | } 33 | 34 | void kth_chain_double_spend_proof_hash_out(kth_double_spend_proof_t dsp, kth_hash_t* out_hash) { 35 | auto const& hash_cpp = kth_chain_double_spend_proof_const_cpp(dsp).hash(); 36 | kth::copy_c_hash(hash_cpp, out_hash); 37 | } 38 | 39 | kth_bool_t kth_chain_double_spend_proof_is_valid(kth_double_spend_proof_t dsp) { 40 | return kth::bool_to_int(kth_chain_double_spend_proof_const_cpp(dsp).is_valid()); 41 | } 42 | 43 | kth_size_t kth_chain_double_spend_proof_serialized_size(kth_double_spend_proof_t dsp, uint32_t version) { 44 | return kth_chain_double_spend_proof_const_cpp(dsp).serialized_size(version); 45 | } 46 | 47 | void kth_chain_double_spend_proof_destruct(kth_double_spend_proof_t dsp) { 48 | delete &kth_chain_double_spend_proof_cpp(dsp); 49 | } 50 | 51 | void kth_chain_double_spend_proof_reset(kth_double_spend_proof_t dsp) { 52 | kth_chain_double_spend_proof_cpp(dsp).reset(); 53 | } 54 | 55 | } // extern "C" 56 | -------------------------------------------------------------------------------- /src/chain/get_blocks.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | KTH_CONV_DEFINE(chain, kth_get_blocks_t, kth::domain::message::get_blocks, get_blocks) 13 | 14 | // --------------------------------------------------------------------------- 15 | extern "C" { 16 | 17 | kth_get_blocks_t kth_chain_get_blocks_construct_default() { 18 | return new kth::domain::message::get_blocks(); 19 | } 20 | 21 | kth_get_blocks_t kth_chain_get_blocks_construct(kth_hash_list_t start, kth_hash_t stop) { 22 | auto const& start_cpp = kth_core_hash_list_const_cpp(start); 23 | auto stop_cpp = kth::to_array(stop.hash); 24 | return new kth::domain::message::get_blocks(start_cpp, stop_cpp); 25 | } 26 | 27 | void kth_chain_get_blocks_destruct(kth_get_blocks_t get_b) { 28 | delete &kth_chain_get_blocks_cpp(get_b); 29 | } 30 | 31 | kth_hash_list_t kth_chain_get_blocks_start_hashes(kth_get_blocks_t get_b) { 32 | auto& list = kth_chain_get_blocks_cpp(get_b).start_hashes(); 33 | return kth_core_hash_list_construct_from_cpp(list); 34 | } 35 | 36 | void kth_chain_get_blocks_set_start_hashes(kth_get_blocks_t get_b, kth_hash_list_t value) { 37 | auto const& value_cpp = kth_core_hash_list_const_cpp(value); 38 | kth_chain_get_blocks_cpp(get_b).set_start_hashes(value_cpp); 39 | } 40 | 41 | kth_hash_t kth_chain_get_blocks_stop_hash(kth_get_blocks_t get_b) { 42 | auto& stop = kth_chain_get_blocks_cpp(get_b).stop_hash(); 43 | return kth::to_hash_t(stop); 44 | } 45 | 46 | void kth_chain_get_blocks_stop_hash_out(kth_get_blocks_t get_b, kth_hash_t* out_stop_hash) { 47 | auto& stop = kth_chain_get_blocks_cpp(get_b).stop_hash(); 48 | kth::copy_c_hash(stop, out_stop_hash); 49 | } 50 | 51 | //TODO(fernando): pass the kth_hash_t by reference (pointer) 52 | void kth_chain_get_blocks_set_stop_hash(kth_get_blocks_t get_b, kth_hash_t value) { 53 | auto value_cpp = kth::to_array(value.hash); 54 | kth_chain_get_blocks_cpp(get_b).set_stop_hash(value_cpp); 55 | } 56 | 57 | kth_bool_t kth_chain_get_blocks_is_valid(kth_get_blocks_t get_b) { 58 | return kth::bool_to_int(kth_chain_get_blocks_cpp(get_b).is_valid()); 59 | } 60 | 61 | void kth_chain_get_blocks_reset(kth_get_blocks_t get_b) { 62 | kth_chain_get_blocks_cpp(get_b).reset(); 63 | } 64 | 65 | kth_size_t kth_chain_get_blocks_serialized_size(kth_get_blocks_t get_b, uint32_t version) { 66 | return kth_chain_get_blocks_cpp(get_b).serialized_size(version); 67 | } 68 | 69 | } // extern "C" 70 | -------------------------------------------------------------------------------- /src/chain/get_headers.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | 13 | KTH_CONV_DEFINE(chain, kth_get_headers_t, kth::domain::message::get_headers, get_headers) 14 | 15 | // --------------------------------------------------------------------------- 16 | extern "C" { 17 | 18 | kth_get_headers_t kth_chain_get_headers_construct_default() { 19 | return new kth::domain::message::get_headers(); 20 | } 21 | 22 | kth_get_headers_t kth_chain_get_headers_construct(kth_hash_list_t start, kth_hash_t stop) { 23 | auto const& start_cpp = kth_core_hash_list_const_cpp(start); 24 | auto stop_cpp = kth::to_array(stop.hash); 25 | 26 | return new kth::domain::message::get_headers(start_cpp, stop_cpp); 27 | } 28 | 29 | void kth_chain_get_headers_destruct(kth_get_headers_t get_b) { 30 | delete &kth_chain_get_headers_cpp(get_b); 31 | } 32 | 33 | kth_hash_list_t kth_chain_get_headers_start_hashes(kth_get_headers_t get_b) { 34 | auto& list = kth_chain_get_headers_cpp(get_b).start_hashes(); 35 | return kth_core_hash_list_construct_from_cpp(list); 36 | } 37 | 38 | void kth_chain_get_headers_set_start_hashes(kth_get_headers_t get_b, kth_hash_list_t value) { 39 | auto const& value_cpp = kth_core_hash_list_const_cpp(value); 40 | kth_chain_get_headers_cpp(get_b).set_start_hashes(value_cpp); 41 | } 42 | 43 | kth_hash_t kth_chain_get_headers_stop_hash(kth_get_headers_t get_b) { 44 | auto& stop = kth_chain_get_headers_cpp(get_b).stop_hash(); 45 | return kth::to_hash_t(stop); 46 | } 47 | 48 | void kth_chain_get_headers_stop_hash_out(kth_get_headers_t get_b, kth_hash_t* out_stop_hash) { 49 | auto& stop = kth_chain_get_headers_cpp(get_b).stop_hash(); 50 | kth::copy_c_hash(stop, out_stop_hash); 51 | } 52 | 53 | void kth_chain_get_headers_set_stop_hash(kth_get_headers_t get_b, kth_hash_t value) { 54 | auto value_cpp = kth::to_array(value.hash); 55 | kth_chain_get_headers_cpp(get_b).set_stop_hash(value_cpp); 56 | } 57 | 58 | kth_bool_t kth_chain_get_headers_is_valid(kth_get_headers_t get_b) { 59 | return kth::bool_to_int(kth_chain_get_headers_cpp(get_b).is_valid()); 60 | } 61 | 62 | void kth_chain_get_headers_reset(kth_get_headers_t get_b) { 63 | kth_chain_get_headers_cpp(get_b).reset(); 64 | } 65 | 66 | kth_size_t kth_chain_get_headers_serialized_size(kth_get_headers_t get_b, uint32_t version) { 67 | return kth_chain_get_headers_cpp(get_b).serialized_size(version); 68 | } 69 | 70 | } // extern "C" 71 | -------------------------------------------------------------------------------- /src/chain/history_compact.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | KTH_CONV_DEFINE(chain, kth_history_compact_t, kth::domain::chain::history_compact, history_compact) 11 | 12 | // --------------------------------------------------------------------------- 13 | extern "C" { 14 | 15 | kth_point_kind_t kth_chain_history_compact_get_point_kind(kth_history_compact_t history) { 16 | return static_cast(kth_chain_history_compact_const_cpp(history).kind); 17 | } 18 | 19 | kth_point_t kth_chain_history_compact_get_point(kth_history_compact_t history) { 20 | return &kth_chain_history_compact_cpp(history).point; 21 | } 22 | 23 | uint32_t kth_chain_history_compact_get_height(kth_history_compact_t history) { 24 | return kth_chain_history_compact_const_cpp(history).height; 25 | } 26 | 27 | uint64_t kth_chain_history_compact_get_value_or_previous_checksum(kth_history_compact_t history) { 28 | auto const& history_const_cpp = kth_chain_history_compact_const_cpp(history); 29 | return history_const_cpp.value; 30 | } 31 | 32 | } // extern "C" 33 | -------------------------------------------------------------------------------- /src/chain/history_compact_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | KTH_LIST_DEFINE_CONVERTERS(chain, kth_history_compact_list_t, kth::domain::chain::history_compact, history_compact_list) 13 | 14 | extern "C" { 15 | 16 | KTH_LIST_DEFINE(chain, kth_history_compact_list_t, kth_history_compact_t, history_compact_list, kth::domain::chain::history_compact, kth_chain_history_compact_const_cpp) 17 | 18 | } // extern "C" 19 | -------------------------------------------------------------------------------- /src/chain/input.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | KTH_CONV_DEFINE(chain, kth_input_t, kth::domain::chain::input, input) 14 | 15 | // --------------------------------------------------------------------------- 16 | extern "C" { 17 | 18 | kth_input_t kth_chain_input_construct_default() { 19 | return new kth::domain::chain::input(); 20 | } 21 | 22 | kth_input_t kth_chain_input_construct(kth_outputpoint_t previous_output, kth_script_t script, uint32_t sequence) { 23 | return new kth::domain::chain::input(kth_chain_output_point_const_cpp(previous_output), kth_chain_script_const_cpp(script), sequence); 24 | } 25 | 26 | void kth_chain_input_destruct(kth_input_t input) { 27 | delete &kth_chain_input_cpp(input); 28 | } 29 | 30 | kth_input_t kth_chain_input_factory_from_data(uint8_t* data, kth_size_t n) { 31 | kth::data_chunk data_cpp(data, std::next(data, n)); 32 | auto input = kth::domain::create_old(data_cpp, true); 33 | return kth::move_or_copy_and_leak(std::move(input)); 34 | } 35 | 36 | kth_bool_t kth_chain_input_is_valid(kth_input_t input) { 37 | return kth::bool_to_int(kth_chain_input_const_cpp(input).is_valid()); 38 | } 39 | 40 | kth_bool_t kth_chain_input_is_final(kth_input_t input) { 41 | return kth::bool_to_int(kth_chain_input_const_cpp(input).is_final()); 42 | } 43 | 44 | kth_size_t kth_chain_input_serialized_size(kth_input_t input, kth_bool_t wire /* = true*/) { 45 | return kth_chain_input_const_cpp(input).serialized_size(kth::int_to_bool(wire)); 46 | } 47 | 48 | uint32_t kth_chain_input_sequence(kth_input_t input) { 49 | return kth_chain_input_const_cpp(input).sequence(); 50 | } 51 | 52 | kth_size_t kth_chain_input_signature_operations(kth_input_t input, kth_bool_t bip16_active) { 53 | #if defined(KTH_CURRENCY_BCH) 54 | kth_bool_t bip141_active = 0; 55 | #else 56 | kth_bool_t bip141_active = 1; 57 | #endif 58 | return kth_chain_input_const_cpp(input).signature_operations(kth::int_to_bool(bip16_active), kth::int_to_bool(bip141_active)); 59 | } 60 | 61 | kth_script_t kth_chain_input_script(kth_input_t input) { 62 | return &(kth_chain_input_cpp(input).script()); 63 | } 64 | 65 | kth_outputpoint_t kth_chain_input_previous_output(kth_input_t input) { 66 | return &(kth_chain_input_cpp(input).previous_output()); 67 | } 68 | 69 | uint8_t const* kth_chain_input_to_data(kth_input_t input, kth_bool_t wire, kth_size_t* out_size) { 70 | auto input_data = kth_chain_input_const_cpp(input).to_data(kth::int_to_bool(wire)); 71 | return kth::create_c_array(input_data, *out_size); 72 | } 73 | 74 | } // extern "C" 75 | -------------------------------------------------------------------------------- /src/chain/input_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | KTH_LIST_DEFINE_CONVERTERS(chain, kth_input_list_t, kth::domain::chain::input, input_list) 13 | KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP(chain, kth_input_list_t, kth::domain::chain::input, input_list) 14 | 15 | extern "C" { 16 | 17 | KTH_LIST_DEFINE(chain, kth_input_list_t, kth_input_t, input_list, kth::domain::chain::input, kth_chain_input_const_cpp) 18 | 19 | } // extern "C" 20 | -------------------------------------------------------------------------------- /src/chain/mempool_transaction.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | KTH_CONV_DEFINE(chain, kth_mempool_transaction_t, kth::blockchain::mempool_transaction_summary, mempool_transaction) 15 | 16 | // --------------------------------------------------------------------------- 17 | extern "C" { 18 | 19 | char const* kth_chain_mempool_transaction_address(kth_mempool_transaction_t tx) { 20 | auto tx_address_str = kth_chain_mempool_transaction_const_cpp(tx).address(); 21 | return kth::create_c_str(tx_address_str); 22 | } 23 | 24 | char const* kth_chain_mempool_transaction_hash(kth_mempool_transaction_t tx) { 25 | auto tx_hash_str = kth_chain_mempool_transaction_const_cpp(tx).hash(); 26 | return kth::create_c_str(tx_hash_str); 27 | } 28 | 29 | uint64_t kth_chain_mempool_transaction_index(kth_mempool_transaction_t tx) { 30 | return kth_chain_mempool_transaction_const_cpp(tx).index(); 31 | } 32 | 33 | char const* kth_chain_mempool_transaction_satoshis(kth_mempool_transaction_t tx) { 34 | auto tx_satoshis_str = kth_chain_mempool_transaction_const_cpp(tx).satoshis(); 35 | return kth::create_c_str(tx_satoshis_str); 36 | } 37 | 38 | uint64_t kth_chain_kth_mempool_transaction_timestamp(kth_mempool_transaction_t tx) { 39 | return kth_chain_mempool_transaction_const_cpp(tx).timestamp(); 40 | } 41 | 42 | char const* kth_chain_mempool_transaction_prev_output_id(kth_mempool_transaction_t tx) { 43 | auto tx_prev_output_id_str = kth_chain_mempool_transaction_const_cpp(tx).previous_output_hash(); 44 | return kth::create_c_str(tx_prev_output_id_str); 45 | } 46 | 47 | char const* kth_chain_mempool_transaction_prev_output_index(kth_mempool_transaction_t tx) { 48 | auto tx_prev_output_index_str = kth_chain_mempool_transaction_const_cpp(tx).previous_output_index(); 49 | return kth::create_c_str(tx_prev_output_index_str); 50 | } 51 | 52 | } // extern "C" 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/chain/mempool_transaction_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | 11 | KTH_LIST_DEFINE_CONVERTERS(chain, kth_mempool_transaction_list_t, kth::blockchain::mempool_transaction_summary, mempool_transaction_list) 12 | KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP(chain, kth_mempool_transaction_list_t, kth::blockchain::mempool_transaction_summary, mempool_transaction_list) 13 | 14 | extern "C" { 15 | 16 | KTH_LIST_DEFINE(chain, kth_mempool_transaction_list_t, kth_mempool_transaction_t, mempool_transaction_list, kth::blockchain::mempool_transaction_summary, kth_chain_mempool_transaction_const_cpp) 17 | 18 | } // extern "C" 19 | -------------------------------------------------------------------------------- /src/chain/merkle_block.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | KTH_CONV_DEFINE(chain, kth_merkleblock_t, kth::domain::message::merkle_block, merkle_block) 14 | 15 | // --------------------------------------------------------------------------- 16 | extern "C" { 17 | 18 | void kth_chain_merkle_block_destruct(kth_merkleblock_t block) { 19 | delete &kth_chain_merkle_block_cpp(block); 20 | } 21 | 22 | kth_hash_t kth_chain_merkle_block_hash_nth(kth_merkleblock_t block, kth_size_t n) { 23 | //precondition: n >=0 && n < hashes().size() 24 | 25 | auto* blk = &kth_chain_merkle_block_cpp(block); 26 | auto& hash_n = blk->hashes()[n]; 27 | return kth::to_hash_t(hash_n); 28 | } 29 | 30 | void kth_chain_merkle_block_hash_nth_out(kth_merkleblock_t block, kth_size_t n, kth_hash_t* out_hash) { 31 | //precondition: n >=0 && n < hashes().size() 32 | 33 | auto* blk = &kth_chain_merkle_block_cpp(block); 34 | auto& hash_n = blk->hashes()[n]; 35 | kth::copy_c_hash(hash_n, out_hash); 36 | } 37 | 38 | kth_header_t kth_chain_merkle_block_header(kth_merkleblock_t block) { 39 | return &kth_chain_merkle_block_cpp(block).header(); 40 | } 41 | 42 | kth_bool_t kth_chain_merkle_block_is_valid(kth_merkleblock_t block) { 43 | return kth::bool_to_int(kth_chain_merkle_block_const_cpp(block).is_valid()); 44 | } 45 | 46 | kth_size_t kth_chain_merkle_block_hash_count(kth_merkleblock_t block) { 47 | return kth_chain_merkle_block_const_cpp(block).hashes().size(); 48 | } 49 | 50 | kth_size_t kth_chain_merkle_block_serialized_size(kth_merkleblock_t block, uint32_t version) { 51 | return kth_chain_merkle_block_const_cpp(block).serialized_size(version); 52 | } 53 | 54 | kth_size_t kth_chain_merkle_block_total_transaction_count(kth_merkleblock_t block) { 55 | return kth_chain_merkle_block_const_cpp(block).total_transactions(); 56 | } 57 | 58 | void kth_chain_merkle_block_reset(kth_merkleblock_t block) { 59 | kth_chain_merkle_block_cpp(block).reset(); 60 | } 61 | 62 | } // extern "C" 63 | -------------------------------------------------------------------------------- /src/chain/opcode.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | // KTH_CONV_DEFINE(chain, kth_operation_t, kth::domain::machine::operation, operation) 11 | 12 | // --------------------------------------------------------------------------- 13 | extern "C" { 14 | 15 | char const* kth_chain_opcode_to_string(kth_opcode_t value, uint32_t active_forks) { 16 | auto code_c = kth::opcode_to_cpp(value); 17 | auto str = kth::domain::machine::opcode_to_string(code_c, active_forks); 18 | return kth::create_c_str(str); 19 | } 20 | 21 | kth_bool_t kth_chain_opcode_from_string(kth_opcode_t* out_code, char const* value) { 22 | kth::domain::machine::opcode opc; 23 | auto const res = kth::domain::machine::opcode_from_string(opc, std::string(value)); 24 | if ( ! res) { 25 | return kth::bool_to_int(false); 26 | } 27 | *out_code = kth::opcode_to_c(opc); 28 | return kth::bool_to_int(true); 29 | } 30 | 31 | char const* kth_chain_opcode_to_hexadecimal(kth_opcode_t code) { 32 | auto code_c = kth::opcode_to_cpp(code); 33 | auto str = kth::domain::machine::opcode_to_hexadecimal(code_c); 34 | return kth::create_c_str(str); 35 | } 36 | 37 | kth_bool_t kth_chain_opcode_from_hexadecimal(kth_opcode_t* out_code, char const* value) { 38 | kth::domain::machine::opcode opc; 39 | auto const res = kth::domain::machine::opcode_from_hexadecimal(opc, std::string(value)); 40 | if ( ! res) { 41 | return kth::bool_to_int(false); 42 | } 43 | *out_code = kth::opcode_to_c(opc); 44 | return kth::bool_to_int(true); 45 | } 46 | 47 | } // extern "C" 48 | -------------------------------------------------------------------------------- /src/chain/operation_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | KTH_LIST_DEFINE_CONVERTERS(chain, kth_operation_list_t, kth::domain::machine::operation, operation_list) 11 | KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP_CONST(chain, kth_operation_list_t, kth::domain::machine::operation, operation_list) 12 | 13 | extern "C" { 14 | 15 | KTH_LIST_DEFINE(chain, kth_operation_list_t, kth_operation_t, operation_list, kth::domain::machine::operation, kth_chain_operation_const_cpp) 16 | 17 | } // extern "C" 18 | -------------------------------------------------------------------------------- /src/chain/output_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | KTH_LIST_DEFINE_CONVERTERS(chain, kth_output_list_t, kth::domain::chain::output, output_list) 11 | KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP(chain, kth_output_list_t, kth::domain::chain::output, output_list) 12 | 13 | extern "C" { 14 | 15 | KTH_LIST_DEFINE(chain, kth_output_list_t, kth_output_t, output_list, kth::domain::chain::output, kth_chain_output_const_cpp) 16 | 17 | } // extern "C" 18 | -------------------------------------------------------------------------------- /src/chain/output_point.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | KTH_CONV_DEFINE(chain, kth_outputpoint_t, kth::domain::chain::output_point, output_point) 11 | 12 | // --------------------------------------------------------------------------- 13 | extern "C" { 14 | 15 | kth_outputpoint_t kth_chain_output_point_construct() { 16 | // return std::make_unique().release(); 17 | return new kth::domain::chain::output_point; 18 | } 19 | 20 | 21 | kth_outputpoint_t kth_chain_output_point_construct_from_hash_index(kth_hash_t const* hash, uint32_t index) { 22 | auto hash_cpp = kth::to_array(hash->hash); 23 | auto ret = new kth::domain::chain::output_point(hash_cpp, index); 24 | return ret; 25 | } 26 | 27 | void kth_chain_output_point_destruct(kth_outputpoint_t op) { 28 | delete &kth_chain_output_point_cpp(op); 29 | } 30 | 31 | //kth_hash_t kth_chain_output_point_get_hash(kth_outputpoint_t op) { 32 | // auto const& hash_cpp = kth_chain_output_point_const_cpp(op).hash(); 33 | // return hash_cpp.data(); 34 | //} 35 | 36 | kth_hash_t kth_chain_output_point_get_hash(kth_outputpoint_t op) { 37 | auto const& hash_cpp = kth_chain_output_point_const_cpp(op).hash(); 38 | return kth::to_hash_t(hash_cpp); 39 | } 40 | 41 | void kth_chain_output_point_get_hash_out(kth_outputpoint_t op, kth_hash_t* out_hash) { 42 | auto const& hash_cpp = kth_chain_output_point_const_cpp(op).hash(); 43 | kth::copy_c_hash(hash_cpp, out_hash); 44 | } 45 | 46 | uint32_t kth_chain_output_point_get_index(kth_outputpoint_t op) { 47 | return kth_chain_output_point_const_cpp(op).index(); 48 | } 49 | 50 | kth_output_t kth_chain_output_point_get_cached_output(kth_outputpoint_t op) { 51 | auto& output = kth_chain_output_point_const_cpp(op).validation.cache; 52 | return &output; 53 | } 54 | 55 | void kth_chain_output_point_set_hash(kth_outputpoint_t op, kth_hash_t const* hash) { 56 | auto hash_cpp = kth::to_array(hash->hash); 57 | kth_chain_output_point_cpp(op).set_hash(hash_cpp); 58 | } 59 | 60 | void kth_chain_output_point_set_index(kth_outputpoint_t op, uint32_t index) { 61 | kth_chain_output_point_cpp(op).set_index(index); 62 | } 63 | 64 | void kth_chain_output_point_set_cached_output(kth_outputpoint_t op, kth_output_t output) { 65 | kth_chain_output_point_cpp(op).validation.cache = kth_chain_output_const_cpp(output); 66 | } 67 | 68 | } // extern "C" 69 | -------------------------------------------------------------------------------- /src/chain/point.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | 13 | KTH_CONV_DEFINE(chain, kth_point_t, kth::domain::chain::point, point) 14 | 15 | // --------------------------------------------------------------------------- 16 | extern "C" { 17 | 18 | kth_hash_t kth_chain_point_get_hash(kth_point_t point) { 19 | auto const& hash_cpp = kth_chain_point_const_cpp(point).hash(); 20 | return kth::to_hash_t(hash_cpp); 21 | } 22 | 23 | void kth_chain_point_get_hash_out(kth_point_t point, kth_hash_t* out_hash) { 24 | auto const& hash_cpp = kth_chain_point_const_cpp(point).hash(); 25 | kth::copy_c_hash(hash_cpp, out_hash); 26 | } 27 | 28 | kth_bool_t kth_chain_point_is_valid(kth_point_t point) { 29 | return kth::bool_to_int(kth_chain_point_const_cpp(point).is_valid()); 30 | } 31 | 32 | uint32_t kth_chain_point_get_index(kth_point_t point) { 33 | return kth_chain_point_const_cpp(point).index(); 34 | } 35 | 36 | uint64_t kth_chain_point_get_checksum(kth_point_t point) { 37 | return kth_chain_point_const_cpp(point).checksum(); 38 | } 39 | 40 | } // extern "C" 41 | 42 | -------------------------------------------------------------------------------- /src/chain/point_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | KTH_LIST_DEFINE_CONVERTERS(chain, kth_point_list_t, kth::domain::chain::point, point_list) 12 | 13 | // --------------------------------------------------------------------------- 14 | extern "C" { 15 | 16 | KTH_LIST_DEFINE(chain, kth_point_list_t, kth_point_t, point_list, kth::domain::chain::point, kth_chain_point_const_cpp) 17 | 18 | } // extern "C" -------------------------------------------------------------------------------- /src/chain/stealth_compact.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | 13 | KTH_CONV_DEFINE(chain, kth_stealth_compact_t, kth::domain::chain::stealth_compact, stealth_compact) 14 | 15 | // --------------------------------------------------------------------------- 16 | extern "C" { 17 | 18 | kth_hash_t kth_chain_stealth_compact_get_ephemeral_public_key_hash(kth_stealth_compact_t stealth) { 19 | auto const& hash_cpp = kth_chain_stealth_compact_cpp(stealth).ephemeral_public_key_hash; 20 | return kth::to_hash_t(hash_cpp); 21 | } 22 | 23 | void kth_chain_stealth_compact_get_ephemeral_public_key_hash_out(kth_stealth_compact_t stealth, kth_hash_t* out_epk_hash) { 24 | auto const& hash_cpp = kth_chain_stealth_compact_cpp(stealth).ephemeral_public_key_hash; 25 | kth::copy_c_hash(hash_cpp, out_epk_hash); 26 | } 27 | 28 | kth_hash_t kth_chain_stealth_compact_get_transaction_hash(kth_stealth_compact_t stealth) { 29 | auto const& hash_cpp = kth_chain_stealth_compact_cpp(stealth).transaction_hash; 30 | return kth::to_hash_t(hash_cpp); 31 | } 32 | 33 | void kth_chain_stealth_compact_get_transaction_hash_out(kth_stealth_compact_t stealth, kth_hash_t* out_tx_hash) { 34 | auto const& hash_cpp = kth_chain_stealth_compact_cpp(stealth).transaction_hash; 35 | kth::copy_c_hash(hash_cpp, out_tx_hash); 36 | } 37 | 38 | kth_shorthash_t kth_chain_stealth_compact_get_public_key_hash(kth_stealth_compact_t stealth) { 39 | auto const& hash_cpp = kth_chain_stealth_compact_cpp(stealth).public_key_hash; 40 | return kth::to_shorthash_t(hash_cpp); 41 | } 42 | 43 | void kth_chain_stealth_compact_get_public_key_hash_out(kth_stealth_compact_t stealth, kth_shorthash_t* out_pk_hash) { 44 | auto const& hash_cpp = kth_chain_stealth_compact_cpp(stealth).public_key_hash; 45 | kth::copy_c_hash(hash_cpp, out_pk_hash); 46 | } 47 | 48 | /* 49 | typedef std::vector list; 50 | 51 | hash_digest ephemeral_public_key_hash; 52 | short_hash public_key_hash; 53 | hash_digest transaction_hash; 54 | */ 55 | 56 | 57 | } // extern "C" 58 | -------------------------------------------------------------------------------- /src/chain/stealth_compact_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | KTH_LIST_DEFINE_CONVERTERS(chain, kth_stealth_compact_list_t, kth::domain::chain::stealth_compact, stealth_compact_list) 13 | 14 | extern "C" { 15 | 16 | KTH_LIST_DEFINE(chain, kth_stealth_compact_list_t, kth_stealth_compact_t, stealth_compact_list, kth::domain::chain::stealth_compact, kth_chain_stealth_compact_cpp) 17 | 18 | } // extern "C" 19 | 20 | -------------------------------------------------------------------------------- /src/chain/transaction_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | KTH_LIST_DEFINE_CONVERTERS(chain, kth_transaction_list_t, kth::domain::chain::transaction, transaction_list) 11 | KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP(chain, kth_transaction_list_t, kth::domain::chain::transaction, transaction_list) 12 | 13 | extern "C" { 14 | 15 | KTH_LIST_DEFINE(chain, kth_transaction_list_t, kth_transaction_t, transaction_list, kth::domain::chain::transaction, kth_chain_transaction_const_cpp) 16 | 17 | } // extern "C" 18 | 19 | 20 | // KTH_LIST_DEFINE_CONVERTERS(chain, kth_transaction_list_t, kth::domain::chain::transaction, transaction_list) 21 | // KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP(chain, kth_transaction_list_t, kth::domain::chain::transaction, transaction_list) 22 | 23 | // extern "C" { 24 | 25 | // KTH_LIST_DEFINE(chain, kth_transaction_list_t, kth_transaction_t, transaction_list, kth::domain::chain::transaction, kth_chain_transaction_const_cpp) 26 | 27 | // } // extern "C" 28 | -------------------------------------------------------------------------------- /src/chain/utxo_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | KTH_LIST_DEFINE_CONVERTERS(chain, kth_utxo_list_t, kth::domain::chain::utxo, utxo_list) 13 | KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP(chain, kth_utxo_list_t, kth::domain::chain::utxo, utxo_list) 14 | 15 | extern "C" { 16 | 17 | KTH_LIST_DEFINE(chain, kth_utxo_list_t, kth_utxo_t, utxo_list, kth::domain::chain::utxo, kth_chain_utxo_const_cpp) 18 | 19 | } // extern "C" 20 | -------------------------------------------------------------------------------- /src/config/authority.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | // #include 8 | 9 | #include 10 | 11 | // --------------------------------------------------------------------------- 12 | extern "C" { 13 | 14 | kth_authority* kth_config_authority_allocate_n(kth_size_t n) { 15 | return kth::mnew(n); 16 | } 17 | 18 | } // extern "C" 19 | -------------------------------------------------------------------------------- /src/config/blockchain_settings.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | // --------------------------------------------------------------------------- 11 | extern "C" { 12 | 13 | kth_blockchain_settings kth_config_blockchain_settings_default(kth_network_t net) { 14 | kth::blockchain::settings cpp(kth::network_to_cpp(net)); 15 | return kth::capi::helpers::blockchain_settings_to_c(cpp); 16 | } 17 | 18 | } // extern "C" 19 | -------------------------------------------------------------------------------- /src/config/checkpoint.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | #include 7 | 8 | // --------------------------------------------------------------------------- 9 | extern "C" { 10 | 11 | kth_checkpoint* kth_config_checkpoint_allocate_n(kth_size_t n) { 12 | return kth::mnew(n); 13 | } 14 | 15 | } // extern "C" 16 | -------------------------------------------------------------------------------- /src/config/database_settings.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | // --------------------------------------------------------------------------- 13 | extern "C" { 14 | 15 | kth_database_settings kth_config_database_settings_default(kth_network_t net) { 16 | kth::database::settings cpp(kth::network_to_cpp(net)); 17 | return kth::capi::helpers::database_settings_to_c(cpp); 18 | } 19 | 20 | } // extern "C" 21 | -------------------------------------------------------------------------------- /src/config/endpoint.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | kth::infrastructure::config::endpoint endpoint_to_cpp(kth_endpoint const& x) { 12 | return {x.host, x.port}; 13 | } 14 | 15 | // --------------------------------------------------------------------------- 16 | extern "C" { 17 | 18 | kth_endpoint* kth_config_endpoint_allocate_n(kth_size_t n) { 19 | return kth::mnew(n); 20 | } 21 | 22 | } // extern "C" 23 | -------------------------------------------------------------------------------- /src/config/network_settings.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | // --------------------------------------------------------------------------- 12 | extern "C" { 13 | 14 | kth_network_settings kth_config_network_settings_default(kth_network_t net) { 15 | kth::network::settings cpp(kth::network_to_cpp(net)); 16 | return kth::capi::helpers::network_settings_to_c(cpp); 17 | } 18 | 19 | } // extern "C" 20 | -------------------------------------------------------------------------------- /src/config/node_settings.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | // --------------------------------------------------------------------------- 15 | extern "C" { 16 | 17 | kth_node_settings kth_config_node_settings_default(kth_network_t net) { 18 | kth::node::settings cpp(kth::network_to_cpp(net)); 19 | return kth::capi::helpers::node_settings_to_c(cpp); 20 | } 21 | 22 | } // extern "C" 23 | -------------------------------------------------------------------------------- /src/double_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | KTH_LIST_DEFINE_CONVERTERS(core, kth_double_list_t, double, double_list) 12 | 13 | // --------------------------------------------------------------------------- 14 | extern "C" { 15 | 16 | kth_double_list_t kth_core_double_list_construct() { 17 | return new std::vector(); 18 | } 19 | 20 | void kth_core_double_list_destruct(kth_double_list_t double_list) { 21 | delete &kth_core_double_list_cpp(double_list); 22 | } 23 | 24 | void kth_core_double_list_push_back(kth_double_list_t double_list, double value) { 25 | kth_core_double_list_cpp(double_list).emplace_back(value); 26 | } 27 | 28 | double kth_core_double_list_nth(kth_double_list_t double_list, kth_size_t index) { 29 | return kth_core_double_list_cpp(double_list)[index]; 30 | } 31 | 32 | kth_size_t kth_core_double_list_count(kth_double_list_t double_list) { 33 | return kth_core_double_list_cpp(double_list).size(); 34 | } 35 | 36 | } // extern "C" -------------------------------------------------------------------------------- /src/hash_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | KTH_LIST_DEFINE_CONVERTERS(core, kth_hash_list_t, kth::hash_digest, hash_list) 11 | KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP(core, kth_hash_list_t, kth::hash_digest, hash_list) 12 | 13 | // --------------------------------------------------------------------------- 14 | 15 | extern "C" { 16 | 17 | kth_hash_list_t kth_core_hash_list_construct_default() { 18 | return new std::vector(); 19 | } 20 | 21 | void kth_core_hash_list_push_back(kth_hash_list_t list, kth_hash_t hash) { 22 | auto hash_cpp = kth::to_array(hash.hash); 23 | kth_core_hash_list_cpp(list).push_back(hash_cpp); 24 | } 25 | 26 | void kth_core_hash_list_destruct(kth_hash_list_t list) { 27 | delete &kth_core_hash_list_cpp(list); 28 | } 29 | 30 | kth_size_t kth_core_hash_list_count(kth_hash_list_t list) { 31 | return kth_core_hash_list_const_cpp(list).size(); 32 | } 33 | 34 | kth_hash_t kth_core_hash_list_nth(kth_hash_list_t list, kth_size_t n) { 35 | auto const& x = kth_core_hash_list_cpp(list)[n]; 36 | return kth::to_hash_t(x); 37 | } 38 | 39 | void kth_core_hash_list_nth_out(kth_hash_list_t list, kth_size_t n, kth_hash_t* out_hash) { 40 | auto const& x = kth_core_hash_list_cpp(list)[n]; 41 | kth::copy_c_hash(x, out_hash); 42 | } 43 | 44 | } // extern "C" 45 | -------------------------------------------------------------------------------- /src/node/settings.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #if ! defined(__EMSCRIPTEN__) 17 | #include 18 | #endif 19 | 20 | // --------------------------------------------------------------------------- 21 | extern "C" { 22 | 23 | kth_currency_t kth_node_settings_get_currency() { 24 | return static_cast(static_cast(kth::get_currency())); 25 | } 26 | 27 | #if ! defined(__EMSCRIPTEN__) 28 | kth_network_t kth_node_settings_get_network(kth_node_t exec) { 29 | 30 | kth_p2p_t p2p_node = kth_node_get_p2p(exec); 31 | auto const& node = *static_cast(p2p_node); 32 | 33 | auto const& sett = node.network_settings(); 34 | auto id = sett.identifier; 35 | bool is_chipnet = sett.inbound_port == 48333; 36 | 37 | return static_cast(static_cast(kth::get_network(id, is_chipnet))); 38 | } 39 | #endif 40 | 41 | char const* kth_node_settings_cashaddr_prefix() { 42 | #if defined(KTH_CURRENCY_BCH) 43 | auto str = kth::cashaddr_prefix(); 44 | #else 45 | std::string str; //Note: to avoid checking compilation-time feature at other languages 46 | #endif 47 | return kth::create_c_str(str); 48 | } 49 | 50 | } // extern "C" 51 | -------------------------------------------------------------------------------- /src/node_info.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | // #ifndef __EMSCRIPTEN__ 12 | #include 13 | // #endif 14 | 15 | #include 16 | #include 17 | 18 | // #ifndef __EMSCRIPTEN__ 19 | #include 20 | #include 21 | // #endif 22 | 23 | extern "C" { 24 | 25 | void kth_node_print_thread_id() { 26 | std::cout << std::this_thread::get_id() << '\n'; 27 | } 28 | 29 | uint64_t kth_node_get_thread_id() { 30 | std::hash hasher; 31 | return hasher(std::this_thread::get_id()); 32 | } 33 | 34 | char const* kth_node_capi_version() { 35 | return KTH_CAPI_VERSION; 36 | } 37 | 38 | char const* kth_node_cppapi_version() { 39 | // #ifndef __EMSCRIPTEN__ 40 | return kth::node::version(); 41 | // #else 42 | // return "0.0.0"; 43 | // #endif 44 | } 45 | 46 | char const* kth_node_microarchitecture() { 47 | // #ifndef __EMSCRIPTEN__ 48 | // I can use .data() because the string is comming from a null-terminated string 49 | return kth::node::microarchitecture().data(); 50 | // #else 51 | // return ""; 52 | // #endif 53 | } 54 | 55 | char const* kth_node_march_names() { 56 | // #ifndef __EMSCRIPTEN__ 57 | return kth::node::march_names().data(); 58 | // #else 59 | // return ""; 60 | // #endif 61 | } 62 | 63 | char const* kth_node_currency_symbol() { 64 | // #ifndef __EMSCRIPTEN__ 65 | return kth::node::currency_symbol().data(); 66 | // #else 67 | // return ""; 68 | // #endif 69 | } 70 | 71 | char const* kth_node_currency() { 72 | // #ifndef __EMSCRIPTEN__ 73 | return kth::node::currency().data(); 74 | // #else 75 | // return ""; 76 | // #endif 77 | } 78 | 79 | // #ifndef __EMSCRIPTEN__ 80 | char const* kth_node_db_type(kth_db_mode_t mode) { 81 | return kth::node::db_type(kth::capi::helpers::db_mode_converter(mode)).data(); 82 | } 83 | // #endif 84 | 85 | uint32_t kth_node_cppapi_build_timestamp() { 86 | // #ifndef __EMSCRIPTEN__ 87 | return kth::node::build_timestamp(); 88 | // #else 89 | // return 0; 90 | // #endif 91 | } 92 | 93 | } // extern "C" 94 | -------------------------------------------------------------------------------- /src/p2p/p2p.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace { 11 | 12 | inline 13 | kth::network::p2p& p2p_cast(kth_p2p_t p2p) { 14 | return *static_cast(p2p); 15 | } 16 | 17 | } /* end of anonymous namespace */ 18 | 19 | // --------------------------------------------------------------------------- 20 | extern "C" { 21 | 22 | kth_size_t kth_p2p_address_count(kth_p2p_t p2p) { 23 | return p2p_cast(p2p).address_count(); 24 | } 25 | 26 | void kth_p2p_stop(kth_p2p_t p2p) { 27 | p2p_cast(p2p).stop(); 28 | } 29 | 30 | void kth_p2p_close(kth_p2p_t p2p) { 31 | p2p_cast(p2p).close(); 32 | } 33 | 34 | kth_bool_t kth_p2p_stopped(kth_p2p_t p2p) { 35 | return kth::bool_to_int(p2p_cast(p2p).stopped()); 36 | } 37 | 38 | } // extern "C" 39 | -------------------------------------------------------------------------------- /src/platform.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | // --------------------------------------------------------------------------- 12 | extern "C" { 13 | 14 | void kth_platform_free(void* ptr) { 15 | free(ptr); 16 | } 17 | 18 | char* kth_platform_allocate_string(kth_size_t n) { 19 | return kth::mnew(n); 20 | } 21 | 22 | void kth_platform_allocate_string_at(char** ptr, kth_size_t n) { 23 | *ptr = kth::mnew(n); 24 | } 25 | 26 | char** kth_platform_allocate_array_of_strings(kth_size_t n) { 27 | return kth::mnew(n); 28 | } 29 | 30 | void kth_platform_print_string(char* str) { 31 | printf("%s\n", str); 32 | } 33 | 34 | char* kth_platform_allocate_and_copy_string_at(char** ptr, kth_size_t offset, char const* str) { 35 | auto n = strlen(str); 36 | ptr[offset] = kth::mnew(n); 37 | std::copy_n(str, n + 1, ptr[offset]); 38 | return ptr[offset]; 39 | } 40 | 41 | } //extern "C" -------------------------------------------------------------------------------- /src/string_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | KTH_LIST_DEFINE_CONVERTERS(core, kth_string_list_t, std::string, string_list) 14 | KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP(core, kth_string_list_t, std::string, string_list) 15 | 16 | // --------------------------------------------------------------------------- 17 | extern "C" { 18 | 19 | kth_string_list_t kth_core_string_list_construct() { 20 | return new std::vector(); 21 | } 22 | 23 | void kth_core_string_list_destruct(kth_string_list_t string_list) { 24 | delete &kth_core_string_list_cpp(string_list); 25 | } 26 | 27 | void kth_core_string_list_push_back(kth_string_list_t string_list, char const* string) { 28 | kth_core_string_list_cpp(string_list).emplace_back(std::string(string)); 29 | } 30 | 31 | char const* kth_core_string_list_nth(kth_string_list_t string_list, kth_size_t index) { 32 | auto str = kth_core_string_list_cpp(string_list)[index]; 33 | return kth::create_c_str(str); 34 | } 35 | 36 | kth_size_t kth_core_string_list_count(kth_string_list_t string_list) { 37 | return kth_core_string_list_cpp(string_list).size(); 38 | } 39 | 40 | } // extern "C" -------------------------------------------------------------------------------- /src/u32_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | KTH_LIST_DEFINE_CONVERTERS(core, kth_u32_list_t, uint32_t, u32_list) 12 | 13 | // --------------------------------------------------------------------------- 14 | extern "C" { 15 | 16 | kth_u32_list_t kth_core_u32_list_construct() { 17 | return new std::vector(); 18 | } 19 | 20 | void kth_core_u32_list_destruct(kth_u32_list_t u32_list) { 21 | delete &kth_core_u32_list_cpp(u32_list); 22 | } 23 | 24 | void kth_core_u32_list_push_back(kth_u32_list_t u32_list, uint32_t value) { 25 | kth_core_u32_list_cpp(u32_list).emplace_back(value); 26 | } 27 | 28 | uint32_t kth_core_u32_list_nth(kth_u32_list_t u32_list, kth_size_t index) { 29 | return kth_core_u32_list_cpp(u32_list)[index]; 30 | } 31 | 32 | kth_size_t kth_core_u32_list_count(kth_u32_list_t u32_list) { 33 | return kth_core_u32_list_cpp(u32_list).size(); 34 | } 35 | 36 | } // extern "C" -------------------------------------------------------------------------------- /src/u64_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | KTH_LIST_DEFINE_CONVERTERS(core, kth_u64_list_t, uint64_t, u64_list) 12 | 13 | // --------------------------------------------------------------------------- 14 | extern "C" { 15 | 16 | kth_u64_list_t kth_core_u64_list_construct() { 17 | return new std::vector(); 18 | } 19 | 20 | void kth_core_u64_list_destruct(kth_u64_list_t u64_list) { 21 | delete &kth_core_u64_list_cpp(u64_list); 22 | } 23 | 24 | void kth_core_u64_list_push_back(kth_u64_list_t u64_list, uint64_t value) { 25 | kth_core_u64_list_cpp(u64_list).emplace_back(value); 26 | } 27 | 28 | uint64_t kth_core_u64_list_nth(kth_u64_list_t u64_list, kth_size_t index) { 29 | return kth_core_u64_list_cpp(u64_list)[index]; 30 | } 31 | 32 | kth_size_t kth_core_u64_list_count(kth_u64_list_t u64_list) { 33 | return kth_core_u64_list_cpp(u64_list).size(); 34 | } 35 | 36 | } // extern "C" -------------------------------------------------------------------------------- /src/wallet/ec_compressed_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | KTH_LIST_DEFINE_CONVERTERS(wallet, kth_ec_compressed_list_t, ec_compressed_cpp_t, ec_compressed_list) 11 | 12 | // --------------------------------------------------------------------------- 13 | extern "C" { 14 | 15 | kth_ec_compressed_list_t kth_wallet_ec_compressed_list_construct_default() { 16 | return new std::vector(); 17 | } 18 | 19 | void kth_wallet_ec_compressed_list_push_back(kth_ec_compressed_list_t l, kth_ec_compressed_t e) { 20 | kth_wallet_ec_compressed_list_cpp(l).push_back(detail::from_ec_compressed_t(e)); 21 | } 22 | 23 | void kth_wallet_ec_compressed_list_destruct(kth_ec_compressed_list_t l) { 24 | delete &kth_wallet_ec_compressed_list_cpp(l); 25 | } 26 | 27 | kth_size_t kth_wallet_ec_compressed_list_count(kth_ec_compressed_list_t l) { 28 | return kth_wallet_ec_compressed_list_const_cpp(l).size(); 29 | } 30 | 31 | kth_ec_compressed_t kth_wallet_ec_compressed_list_nth(kth_ec_compressed_list_t l, kth_size_t n) { 32 | auto const& x = kth_wallet_ec_compressed_list_cpp(l)[n]; 33 | return detail::to_ec_compressed_t(x); 34 | } 35 | 36 | 37 | // template 38 | // inline 39 | // void copy_c_hash(HashCpp const& in, HashC* out) { 40 | // //precondition: size of out->hash is greater or equal than in.size() 41 | // std::copy_n(in.begin(), in.size(), static_cast(out->hash)); 42 | // } 43 | 44 | void kth_wallet_ec_compressed_list_nth_out(kth_ec_compressed_list_t l, kth_size_t n, kth_ec_compressed_t* out_elem) { 45 | auto const& x = kth_wallet_ec_compressed_list_cpp(l)[n]; 46 | // kth::copy_c_hash(x, out_elem); 47 | std::copy_n(x.begin(), x.size(), static_cast(out_elem->data)); 48 | } 49 | 50 | } // extern "C" 51 | -------------------------------------------------------------------------------- /src/wallet/elliptic_curve.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | extern "C" { 13 | 14 | kth_bool_t kth_wallet_secret_to_public(kth_ec_compressed_t* out, kth_ec_secret_t secret) { 15 | kth::ec_compressed out_cpp; 16 | auto secret_cpp = detail::from_ec_secret_t(secret); 17 | bool success = kth::secret_to_public(out_cpp, secret_cpp); 18 | 19 | if (success) { 20 | *out = detail::to_ec_compressed_t(out_cpp); 21 | } 22 | 23 | return kth::bool_to_int(success); 24 | } 25 | 26 | } // extern "C" 27 | -------------------------------------------------------------------------------- /src/wallet/hd_public.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | KTH_CONV_DEFINE(wallet, kth_hd_public_t, kth::infrastructure::wallet::hd_public, hd_public) 13 | 14 | extern "C" { 15 | 16 | kth_hd_public_t kth_wallet_hd_public_construct_default() { 17 | return new kth::infrastructure::wallet::hd_public(); 18 | } 19 | 20 | kth_hd_public_t kth_wallet_hd_public_construct_string(char const* encoded) { 21 | return new kth::infrastructure::wallet::hd_public(std::string(encoded)); 22 | } 23 | 24 | kth_hd_public_t kth_wallet_hd_public_construct_string_prefix(char const* encoded, uint32_t prefix) { 25 | return new kth::infrastructure::wallet::hd_public(std::string(encoded), prefix); 26 | } 27 | 28 | kth_hd_public_t kth_wallet_hd_public_construct_key(kth_hd_key_t const* public_key) { 29 | return new kth::infrastructure::wallet::hd_public(detail::from_hd_key_t(*public_key)); 30 | } 31 | 32 | kth_hd_public_t kth_wallet_hd_public_construct_key_prefix(kth_hd_key_t const* public_key, uint32_t prefix) { 33 | return new kth::infrastructure::wallet::hd_public(detail::from_hd_key_t(*public_key), prefix); 34 | } 35 | 36 | void kth_wallet_hd_public_destruct(kth_hd_public_t hd_public) { 37 | delete &kth_wallet_hd_public_cpp(hd_public); 38 | } 39 | 40 | kth_bool_t kth_wallet_hd_public_is_valid(kth_hd_public_t hd_public) { 41 | bool valid = kth_wallet_hd_public_const_cpp(hd_public); 42 | return kth::bool_to_int(valid); 43 | } 44 | 45 | // Serializer. 46 | char* kth_wallet_hd_public_encoded(kth_hd_public_t hd_public) { 47 | std::string encoded = kth_wallet_hd_public_const_cpp(hd_public).encoded(); 48 | return kth::create_c_str(encoded); 49 | } 50 | 51 | // Accessors. 52 | kth_hd_chain_code_t kth_wallet_hd_public_chain_code(kth_hd_public_t hd_public) { 53 | auto const& chain_code_cpp = kth_wallet_hd_public_const_cpp(hd_public).chain_code(); 54 | return detail::to_hd_chain_code_t(chain_code_cpp); 55 | } 56 | 57 | kth_hd_lineage_t kth_wallet_hd_public_lineage(kth_hd_public_t hd_public) { 58 | auto const& lineage_cpp = kth_wallet_hd_public_const_cpp(hd_public).lineage(); 59 | return detail::to_hd_lineage_t(lineage_cpp); 60 | } 61 | 62 | kth_ec_compressed_t kth_wallet_hd_public_point(kth_hd_public_t hd_public) { 63 | auto const& point_cpp = kth_wallet_hd_public_const_cpp(hd_public).point(); 64 | return detail::to_ec_compressed_t(point_cpp); 65 | } 66 | 67 | kth_hd_key_t kth_wallet_hd_public_to_hd_key(kth_hd_public_t hd_public) { 68 | auto const& hd_key_cpp = kth_wallet_hd_public_const_cpp(hd_public).to_hd_key(); 69 | return detail::to_hd_key_t(hd_key_cpp); 70 | } 71 | 72 | kth_hd_public_t kth_wallet_hd_public_derive_public(kth_hd_public_t hd_public, uint32_t index) { 73 | auto const& derived_public_cpp = kth_wallet_hd_public_const_cpp(hd_public).derive_public(index); 74 | return kth::move_or_copy_and_leak(std::move(derived_public_cpp)); 75 | } 76 | 77 | } // extern "C" 78 | -------------------------------------------------------------------------------- /src/wallet/payment_address_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | KTH_LIST_DEFINE_CONVERTERS(wallet, kth_payment_address_list_t, kth::domain::wallet::payment_address, payment_address_list) 15 | KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP_BOTH(wallet, kth_payment_address_list_t, kth::domain::wallet::payment_address, payment_address_list) 16 | 17 | extern "C" { 18 | KTH_LIST_DEFINE(wallet, kth_payment_address_list_t, kth_payment_address_t, payment_address_list, kth::domain::wallet::payment_address, kth_wallet_payment_address_const_cpp) 19 | } // extern "C" -------------------------------------------------------------------------------- /src/wallet/raw_output.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | KTH_CONV_DEFINE(wallet, kth_raw_output_t, kth::domain::wallet::raw_output, raw_output) 14 | 15 | // C++ class declaration 16 | // using raw_output = std::pair; 17 | 18 | extern "C" { 19 | 20 | kth_payment_address_t kth_wallet_raw_output_destiny(kth_raw_output_t obj) { 21 | return &kth_wallet_raw_output_cpp(obj).first; 22 | } 23 | 24 | uint64_t kth_wallet_raw_output_amount(kth_raw_output_t obj) { 25 | return kth_wallet_raw_output_const_cpp(obj).second; 26 | } 27 | 28 | 29 | // kth_raw_output_t kth_wallet_raw_output_construct_default() { 30 | // return new kth::domain::wallet::raw_output(); 31 | // } 32 | 33 | // kth_raw_output_t kth_wallet_raw_output_construct(uint32_t version, uint8_t* previous_block_hash, uint8_t* merkle, uint32_t timestamp, uint32_t bits, uint32_t nonce) { 34 | // //precondition: [previous_block_hash, 32) is a valid range 35 | // // && [merkle, 32) is a valid range 36 | 37 | // auto previous_block_hash_cpp = kth::hash_to_cpp(previous_block_hash); 38 | // auto merkle_cpp = kth::hash_to_cpp(merkle); 39 | // return new kth::domain::wallet::raw_output(version, previous_block_hash_cpp, merkle_cpp, timestamp, bits, nonce); 40 | // } 41 | 42 | 43 | } // extern "C" 44 | -------------------------------------------------------------------------------- /src/wallet/raw_output_list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | KTH_LIST_DEFINE_CONVERTERS(wallet, kth_raw_output_list_t, kth::domain::wallet::raw_output, raw_output_list) 15 | KTH_LIST_DEFINE_CONSTRUCT_FROM_CPP(wallet, kth_raw_output_list_t, kth::domain::wallet::raw_output, raw_output_list) 16 | 17 | extern "C" { 18 | KTH_LIST_DEFINE(wallet, kth_raw_output_list_t, kth_raw_output_t, raw_output_list, kth::domain::wallet::raw_output, kth_wallet_raw_output_const_cpp) 19 | } // extern "C" 20 | -------------------------------------------------------------------------------- /src/wallet/wallet_data.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | 15 | KTH_CONV_DEFINE(wallet, kth_wallet_data_t, kth::domain::wallet::wallet_data, wallet_data) 16 | 17 | // --------------------------------------------------------------------------- 18 | extern "C" { 19 | 20 | 21 | void kth_wallet_wallet_data_destruct(kth_wallet_data_t wallet_data) { 22 | delete &kth_wallet_wallet_data_cpp(wallet_data); 23 | } 24 | 25 | kth_string_list_t kth_wallet_wallet_data_mnemonics(kth_wallet_data_t wallet_data) { 26 | auto& mnemonics_cpp = kth_wallet_wallet_data_cpp(wallet_data).mnemonics; 27 | return kth_core_string_list_construct_from_cpp(mnemonics_cpp); 28 | } 29 | 30 | kth_hd_public_t kth_wallet_wallet_data_xpub(kth_wallet_data_t wallet_data) { 31 | auto const& xpub_cpp = kth_wallet_wallet_data_cpp(wallet_data).xpub; 32 | return kth::move_or_copy_and_leak(std::move(xpub_cpp)); 33 | } 34 | 35 | kth_encrypted_seed_t kth_wallet_wallet_data_encrypted_seed(kth_wallet_data_t wallet_data) { 36 | auto const& encrypted_seed_cpp = kth_wallet_wallet_data_cpp(wallet_data).encrypted_seed; 37 | return kth::to_encrypted_seed_t(encrypted_seed_cpp); 38 | } 39 | 40 | void kth_wallet_wallet_data_encrypted_seed_out(kth_wallet_data_t wallet_data, kth_encrypted_seed_t* out_encrypted_seed) { 41 | auto const& encrypted_seed_cpp = kth_wallet_wallet_data_cpp(wallet_data).encrypted_seed; 42 | kth::copy_c_hash(encrypted_seed_cpp, out_encrypted_seed); 43 | } 44 | 45 | } // extern "C" 46 | -------------------------------------------------------------------------------- /src/wallet/wallet_manager.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | // --------------------------------------------------------------------------- 12 | extern "C" { 13 | 14 | kth_error_code_t kth_wallet_create_wallet( 15 | char const* password, 16 | char const* normalized_passphrase, 17 | kth_wallet_data_t* out_wallet_data) { 18 | 19 | auto res = kth::domain::wallet::create_wallet( 20 | std::string(password), 21 | std::string(normalized_passphrase) 22 | // lexicon 23 | ); 24 | 25 | if ( ! res) { 26 | return kth::to_c_err(res.error()); 27 | } 28 | 29 | *out_wallet_data = kth::move_or_copy_and_leak(std::move(res.value())); 30 | return kth_ec_success; 31 | } 32 | 33 | kth_error_code_t kth_wallet_decrypt_seed( 34 | char const* password, 35 | kth_encrypted_seed_t const* encrypted_seed, 36 | kth_longhash_t** out_decrypted_seed) { 37 | 38 | auto seed_cpp = kth::to_array(encrypted_seed->hash); 39 | 40 | auto res = kth::domain::wallet::decrypt_seed( 41 | std::string(password), 42 | seed_cpp 43 | ); 44 | 45 | if ( ! res) { 46 | return kth::to_c_err(res.error()); 47 | } 48 | 49 | *out_decrypted_seed = new kth_longhash_t; 50 | kth::copy_c_hash(res.value(), *out_decrypted_seed); 51 | 52 | return kth_ec_success; 53 | } 54 | 55 | } // extern "C" 56 | -------------------------------------------------------------------------------- /test/queries.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2024 Knuth Project developers. 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 6 | #include "doctest.h" 7 | #include 8 | #include 9 | 10 | class QueriesTestsFixture { 11 | private: 12 | kth_node_t exec; 13 | public: 14 | QueriesTestsFixture() { 15 | exec = kth_node_construct("/home/fernando/exec/btc-mainnet.cfg", stdout, stderr); 16 | int res1 = kth_node_initchain(exec); 17 | std::cout << "Init chain returned: " << res1 << std::endl; 18 | //int res2 = kth_node_run(exec); 19 | } 20 | 21 | kth_node_t getExecutor() { 22 | return exec; 23 | } 24 | }; 25 | 26 | TEST_CASE_FIXTURE(QueriesTestsFixture, "Query interface tests") { 27 | REQUIRE(getExecutor() != nullptr); 28 | //REQUIRE_THROWS(conn.executeSQL("INSERT INTO employee (id, name) VALUES (?, ?)", getID(), "")); 29 | //fetch_block(exec, 0, NULL); 30 | 31 | //kth_node_destruct(exec); 32 | } 33 | --------------------------------------------------------------------------------