### Setup Development Environment Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/contrib/scripts/README-scripts.md Initializes the development environment by installing necessary system packages or dependencies for a specific host architecture. ```bash ./contrib/scripts/setup.sh --host x86_64-pc-linux-gnu ./contrib/scripts/setup.sh --host x86_64-pc-linux-gnu --depends ``` -------------------------------- ### Compile Example with GCC Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/README.md This command demonstrates how to compile an example C file using GCC, linking against the built libdogecoin library. It specifies include paths and library paths. ```bash gcc ./contrib/examples/example.c ./.libs/libdogecoin.a -I./include/dogecoin -L./.libs -ldogecoin -o example ``` -------------------------------- ### Install Docker and Clone Libdogecoin Repository (Shell) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/enclaves.md Installs Docker on Ubuntu and clones the libdogecoin repository into a specified directory. This is a prerequisite for building the OP-TEE SDK and client. ```shell sudo apt-get install docker.io mkdir -p /doge cd /doge git clone https://github.com/dogecoinfoundation/libdogecoin.git cd libdogecoin ``` -------------------------------- ### Install Dependencies (Debian/Ubuntu) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/README.md Installs necessary dependencies for building libdogecoin on Debian/Ubuntu systems. This includes autoconf, automake, libtool, build-essential, and libevent-dev. ```bash sudo apt-get install autoconf automake libtool build-essential libevent-dev ``` -------------------------------- ### Basic Libdogecoin Project Setup Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/getting_started.md Shows the standard include structure for a C project using the Libdogecoin library. ```c #include #include "libdogecoin.h" int main() { // your code here... } ``` -------------------------------- ### Initialize Libdogecoin Repository Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/enclaves.md Commands to install Docker and clone the Libdogecoin repository to a local directory for building. ```bash sudo apt-get install docker.io mkdir -p /doge cd /doge git clone https://github.com/dogecoinfoundation/libdogecoin.git cd libdogecoin ``` -------------------------------- ### Library and Installation Configuration Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/CMakeLists.txt This section configures the main libdogecoin library, adding source files and installing the library and header files to their respective destinations. It ensures that the compiled library and its headers are correctly placed for use by other projects. ```cmake FILE(TOUCH config/libdogecoin-config.h) ADD_LIBRARY(${LIBDOGECOIN_NAME} ${ASM_SOURCES}) INSTALL(TARGETS ${LIBDOGECOIN_NAME} LIBRARY DESTINATION lib ) INSTALL(FILES include/dogecoin/constants.h include/dogecoin/dogecoin.h include/dogecoin/libdogecoin.h include/dogecoin/uthash.h config/libdogecoin-config.h DESTINATION include/dogecoin ) TARGET_SOURCES(${LIBDOGECOIN_NAME} PRIVATE src/address.c src/aes.c src/arith_uint256.c src/auxpow.c src/base58.c src/bip32.c src/bip39.c src/bip44.c src/block.c src/buffer.c src/chacha20.c ) ``` -------------------------------- ### Install Libevent Headers and Config Files (CMake) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/libevent/CMakeLists.txt This CMake code block handles the installation of libevent headers and CMake configuration files. It installs compat and public headers into the include directories and the generated Config.cmake and ConfigVersion.cmake files into the CMake config directory, making the library easily discoverable by other projects. ```cmake # Install compat headers install(FILES ${HDR_COMPAT} DESTINATION "include" COMPONENT dev) # Install public headers install(FILES ${HDR_PUBLIC} DESTINATION "include/event2" COMPONENT dev) # Install the configs. install(FILES ${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/LibeventConfig.cmake ${PROJECT_BINARY_DIR}/LibeventConfigVersion.cmake DESTINATION "${EVENT_INSTALL_CMAKE_DIR}" COMPONENT dev) ``` -------------------------------- ### SMPV Client Usage Example Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/smpv.md Demonstrates how to initialize an SPV client, add addresses to watch, process transactions, and retrieve statistics. ```APIDOC ## SMPV Client Usage Example ### Description This example illustrates the basic workflow of using the libdogecoin SPV client to monitor Dogecoin addresses and process transactions. ### Method C ### Endpoint N/A (This is a library usage example) ### Parameters N/A ### Request Example ```c #include #include #include /* Callback function for transaction notifications */ static void tx_callback(const dogecoin_smpv_tx* tx, const char* address, void* user_data) { (void)user_data; printf("New transaction for %s: %s\n", address, tx->txid); printf("Size: %llu bytes\n", (unsigned long long)tx->size); } int main(void) { /* Create SMPV client */ dogecoin_smpv_client* client = dogecoin_smpv_client_new(&dogecoin_chainparams_main); if (!client) { printf("Failed to create SMPV client\n"); return 1; } /* Add addresses to watch */ dogecoin_smpv_add_watcher(client, "D7Y55vD8nNtW7VnT9Xr6Qc4vB8hN3jK2mP"); dogecoin_smpv_add_watcher(client, "D8Y66wE9nOtW8WnU0Xs7Rd5cC9i4kL3nQ"); /* Start monitoring */ if (!dogecoin_smpv_start(client)) { printf("Failed to start SMPV\n"); dogecoin_smpv_client_free(client); return 1; } /* * Process a transaction. * In a real integration, raw_tx_hex would typically come from a mempool feed * (e.g. inv/tx messages from a peer connection). */ const char* raw_tx_hex = "0100000001..."; /* Raw transaction hex */ dogecoin_smpv_process_tx(client, raw_tx_hex, tx_callback, NULL); /* Get statistics */ uint32_t total_txs = 0; uint32_t watched_addresses = 0; dogecoin_smpv_get_stats(client, &total_txs, &watched_addresses); printf("Watched addresses: %u\n", watched_addresses); printf("Mempool transactions: %u\n", total_txs); /* Clean up */ dogecoin_smpv_stop(client); dogecoin_smpv_client_free(client); return 0; } ``` ### Response N/A (This is a library usage example) ### Response Example N/A ``` -------------------------------- ### Compiling with Libdogecoin Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/getting_started.md Example command line instruction for compiling a C project while linking the libdogecoin and libevent_core libraries. ```bash gcc main.c -L./path/to/library/file -I./path/to/header/file -ldogecoin -levent_core -o myprojectname ``` -------------------------------- ### Install YubiKey Dependencies on Linux Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/yubikey.md Installs the necessary libraries and daemons for YubiKey integration on Debian-based Linux systems. This includes libykpiv for YubiKey communication and pcscd for smart card management. ```bash sudo apt-get update sudo apt-get install libykpiv libykpiv-dev pcscd libpcsclite-dev ``` -------------------------------- ### Wallet Module Configuration Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/CMakeLists.txt Installs the wallet.h header file and adds wallet.c to the libdogecoin sources if WITH_WALLET is enabled. If USE_TESTS is also enabled, it includes wallet_tests.c. ```cmake IF(WITH_WALLET) INSTALL(FILES include/dogecoin/wallet.h DESTINATION include/dogecoin ) TARGET_SOURCES(${LIBDOGECOIN_NAME} ${visibility} src/wallet.c ) IF(USE_TESTS) TARGET_SOURCES(tests ${visibility} test/wallet_tests.c ) ENDIF() ENDIF() ``` -------------------------------- ### Use 'such' CLI for Address and Transaction Operations Source: https://context7.com/dogecoinfoundation/libdogecoin/llms.txt Examples of using the 'such' interactive tool for key generation, address derivation, mnemonic handling, and message signing. ```bash ./such -c generate_private_key ./such -c generate_public_key -p QSPDnjzvrSPAeiM7N2jCkzv2dqsi7fxoHipgpPfz2zdE3ZpYp74j ./such -c bip32_extended_master_key ./such -c derive_child_keys -m m/44h/3h/0h/0/0 -p dgpv51eADS3spNJh9qLpW8S7B7uZmusTpNE85NgXsYD7eGuVhebMDfEsj6fNR6DHgpSBCmYdAvw9YRSqRWnFxtYn1bM8AdNipwdi9dDXFCY8vkY ./such -c generate_mnemonic ./such -c mnemonic_to_addresses -n "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote" ./such -c signmessage -x "Hello Dogecoin" -p QWCcckTzUBiY1g3GFixihAscwHAKXeXY76v7Gcxhp3HUEAcBv33i ./such -c verifymessage -x "Hello Dogecoin" -s -k D8mQ2sKYpLbFCQLhGeHCPBmkLJRi6kRoSg ./such -c transaction ``` -------------------------------- ### Control SMPV Monitoring (C) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/smpv.md Functions to start and stop the SMPV monitoring service. `dogecoin_smpv_start` initiates the monitoring process, and `dogecoin_smpv_stop` halts it. ```c dogecoin_bool dogecoin_smpv_start(dogecoin_smpv_client* client); void dogecoin_smpv_stop(dogecoin_smpv_client* client); ``` -------------------------------- ### Dogecoin Standard ScriptPubKey and ScriptSig Examples Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/transaction_extended.md Illustrates the common format for a standard pay-to-public-key-hash (P2PKH) scriptPubKey and its corresponding scriptSig. This is essential for understanding how Dogecoin transactions are authorized and validated. ```plaintext scriptPubKey: OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG scriptSig: ``` ```plaintext 76 A9 14 OP_DUP OP_HASH160 Bytes to push 89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC Data to push OP_EQUALVERIFY OP_CHECKSIG ``` -------------------------------- ### Standard Autotools Staging Command Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/depends/packages.md A common pattern for staging autotools-based projects using the standard make install command with a custom DESTDIR. ```makefile $(MAKE) DESTDIR=$($(package)_staging_dir) install ``` -------------------------------- ### Start and Register New Key Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/eckey.md Convenience function that creates a new eckey, adds it to the hash table, and returns its unique index. ```c int start_key(dogecoin_bool is_testnet) { eckey* key = new_eckey(is_testnet); int index = key->idx; add_eckey(key); return index; } ``` -------------------------------- ### Build libsecp256k1 using Autotools Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/secp256k1/README.md Standard build process for libsecp256k1 using autotools. This involves generating build scripts, configuring the build, compiling the library, and optionally installing it. ```bash ./autogen.sh ./configure make make check sudo make install ``` -------------------------------- ### CMake: Project and Open Enclave Setup Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/openenclave/CMakeLists.txt Defines the project name and languages, then finds the OpenEnclave configuration package. Sets the C++ standard to 11 and specifies the crypto library to be used by enclaves. ```cmake project("Libdogecoin Sample" LANGUAGES C CXX) # Currently the `OpenEnclave` package depends on `project()`. find_package(OpenEnclave CONFIG REQUIRED) set(CMAKE_CXX_STANDARD 11) set(OE_CRYPTO_LIB mbedtls CACHE STRING "Crypto library used by enclaves.") add_subdirectory(enclave) add_subdirectory(host) ``` -------------------------------- ### Install RPC Generation Script (CMake) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/libevent/CMakeLists.txt This CMake command installs the 'event_rpcgen.py' Python script to the 'bin' directory of the installation. This script is likely used for generating Remote Procedure Call (RPC) interfaces and is installed as a runtime component. ```cmake # Install the scripts. install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/event_rpcgen.py DESTINATION "bin" COMPONENT runtime) ``` -------------------------------- ### Implement SMPV Client Usage Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/smpv.md Demonstrates how to initialize an SMPV client, register addresses for monitoring, and process raw transaction data using a callback mechanism. This example highlights the lifecycle of an SMPV client from creation to cleanup. ```c #include #include #include static void tx_callback(const dogecoin_smpv_tx* tx, const char* address, void* user_data) { (void)user_data; printf("New transaction for %s: %s\n", address, tx->txid); printf("Size: %llu bytes\n", (unsigned long long)tx->size); } int main(void) { dogecoin_smpv_client* client = dogecoin_smpv_client_new(&dogecoin_chainparams_main); if (!client) return 1; dogecoin_smpv_add_watcher(client, "D7Y55vD8nNtW7VnT9Xr6Qc4vB8hN3jK2mP"); dogecoin_smpv_add_watcher(client, "D8Y66wE9nOtW8WnU0Xs7Rd5cC9i4kL3nQ"); if (!dogecoin_smpv_start(client)) { dogecoin_smpv_client_free(client); return 1; } const char* raw_tx_hex = "0100000001..."; dogecoin_smpv_process_tx(client, raw_tx_hex, tx_callback, NULL); dogecoin_smpv_stop(client); dogecoin_smpv_client_free(client); return 0; } ``` -------------------------------- ### Get Current Timestamp (GET /getTimestamp) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves the current timestamp of the SPV node. The response is plain text indicating the date and local time. ```bash curl http://localhost:/getTimestamp ``` -------------------------------- ### Install Export Definitions (CMake) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/libevent/CMakeLists.txt This CMake macro, 'install_export', is used to install the export definitions for libevent targets. It allows for proper integration with CMake's module system, enabling other projects to import targets like 'libevent::event' when libevent is used as a dependency. It supports installing exports for both static and shared library configurations. ```cmake # Install exports for the install-tree. macro(install_export type) install(EXPORT LibeventTargets-${type} NAMESPACE ${PROJECT_NAME}:: DESTINATION "${EVENT_INSTALL_CMAKE_DIR}" COMPONENT dev) endmacro() if (${EVENT_LIBRARY_STATIC}) install_export(static) endif() if (${EVENT_LIBRARY_SHARED}) install_export(shared) endif() ``` -------------------------------- ### Build OP-TEE SDK and Client in Docker Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/enclaves.md This script automates the entire process of setting up the build environment, cloning the OP-TEE repository, applying patches, generating RSA keys, signing subkeys, and compiling the OS and client. It requires a Docker environment and targets the ARMv8 QEMU platform. ```bash docker pull jforissier/optee_os_ci:qemu_check docker run -v "$(pwd):/src" -w /src jforissier/optee_os_ci:qemu_check /bin/bash -c "\ set -e && \ apt update && \ apt -y upgrade && \ apt -y install libusb-1.0-0-dev swig python3-dev python3-setuptools e2tools && \ curl https://storage.googleapis.com/git-repo-downloads/repo > /bin/repo && chmod a+x /bin/repo && \ mkdir -p optee && \ cd optee && \ repo init -u https://github.com/OP-TEE/manifest.git -m qemu_v8.xml -b 4.0.0 && \ export FORCE_UNSAFE_CONFIGURE=1 && \ repo sync -j 4 --force-sync && \ patch -N -F 4 /src/optee/build/common.mk < /src/src/optee/common.mk.patch && \ cd build && \ make toolchains -j 4 && \ export CFG_TEE_CORE_LOG_LEVEL=0 && \ export CFG_ATTESTATION_PTA=y && \ export CFG_ATTESTATION_PTA_KEY_SIZE=1024 && \ export CFG_WITH_USER_TA=y && \ openssl genpkey -algorithm RSA -out rsa_private.pem -pkeyopt rsa_keygen_bits:2048 && \ mv rsa_private.pem /src/optee/optee_os/keys/default_ta.pem && \ openssl genrsa -out /src/optee/optee_test/ta/top_level_subkey.pem && \ openssl genrsa -out /src/optee/optee_test/ta/mid_level_subkey.pem && \ openssl genrsa -out /src/optee/optee_test/ta/identity_subkey2.pem && \ /src/optee/optee_os/scripts/sign_encrypt.py sign-subkey --uuid f04fa996-148a-453c-b037-1dcfbad120a6 --key /src/optee/optee_os/keys/default_ta.pem --in /src/optee/optee_test/ta/top_level_subkey.pem --out /src/optee/optee_test/ta/top_level_subkey.bin --max-depth 4 --name-size 64 --subkey-version 1 && \ /src/optee/optee_os/scripts/sign_encrypt.py subkey-uuid --in /src/optee/optee_test/ta/top_level_subkey.bin --name mid_level_subkey && \ /src/optee/optee_os/scripts/sign_encrypt.py sign-subkey --uuid 1a5948c5-1aa0-518c-86f4-be6f6a057b16 --key /src/optee/optee_test/ta/top_level_subkey.pem --subkey /src/optee/optee_test/ta/top_level_subkey.bin --name-size 64 --subkey-version 1 --name mid_level_subkey --in /src/optee/optee_test/ta/mid_level_subkey.pem --out /src/optee/optee_test/ta/mid_level_subkey.bin && \ /src/optee/optee_os/scripts/sign_encrypt.py subkey-uuid --in /src/optee/optee_test/ta/mid_level_subkey.bin --name subkey1_ta && \ /src/optee/optee_os/scripts/sign_encrypt.py sign-subkey --uuid a720ccbb-51da-417d-b82e-e5445d474a7a --key /src/optee/optee_os/keys/default_ta.pem --in /src/optee/optee_test/ta/identity_subkey2.pem --out /src/optee/optee_test/ta/identity_subkey2.bin --max-depth 0 --name-size 0 --subkey-version 1 && \ make -j 4 check && \ cd /src && \ [ ! -d optee_client ] && git clone https://github.com/OP-TEE/optee_client.git && \ cd optee_client && \ mkdir -p build && \ cd build && \ export PATH=/src/optee/toolchains/aarch64/bin:$PATH && \ export CC=aarch64-linux-gnu-gcc && \ cmake .. -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_INSTALL_PREFIX=/src/optee/toolchains/aarch64 && \ make -j 4 VERBOSE=1 && \ make install" ``` -------------------------------- ### Start and Manage Dogecoin Transaction (C) Source: https://context7.com/dogecoinfoundation/libdogecoin/llms.txt Demonstrates how to initiate a new Dogecoin transaction, retrieve its raw hexadecimal representation, and importantly, how to free the associated memory to prevent leaks. Requires libdogecoin. ```c #include "libdogecoin.h" #include int main() { // Start a new transaction - returns index for reference int txIndex = start_transaction(); printf("New transaction created at index: %d\n", txIndex); // Get the initial empty transaction hex char* emptyHex = get_raw_transaction(txIndex); printf("Empty transaction hex: %s\n", emptyHex); // Output: 01000000000000000000 // Always clean up when done clear_transaction(txIndex); return 0; } ``` -------------------------------- ### Get Last Block Information (GET /getLastBlockInfo) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves information about the last block processed by the SPV node, including block size, transaction count, and total transaction size. ```bash curl http://localhost:/getLastBlockInfo ``` -------------------------------- ### Implement Open Enclave Host Application Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/openenclave/README.md A complete C implementation of an Open Enclave host application. It demonstrates how to initialize an enclave, execute enclave functions, and handle callbacks from the enclave to the host. ```c #include #include #include "libdogecoin_u.h" void host_libdogecoin() { fprintf(stdout, "Enclave called into host to print: Libdogecoin!\n"); } int main(int argc, const char* argv[]) { oe_result_t result; int ret = 1; oe_enclave_t* enclave = NULL; if (argc != 2) { fprintf(stderr, "Usage: %s enclave_image_path\n", argv[0]); goto exit; } result = oe_create_libdogecoin_enclave( argv[1], OE_ENCLAVE_TYPE_AUTO, OE_ENCLAVE_FLAG_DEBUG, NULL, 0, &enclave); if (result != OE_OK) { fprintf(stderr, "oe_create_libdogecoin_enclave(): result=%u (%s)\n", result, oe_result_str(result)); goto exit; } result = enclave_libdogecoin(enclave); if (result != OE_OK) { fprintf(stderr, "calling into enclave_libdogecoin failed: result=%u (%s)\n", result, oe_result_str(result)); goto exit; } ret = 0; exit: if (enclave) oe_terminate_enclave(enclave); return ret; } ``` -------------------------------- ### Get Current Chain Tip (GET /getChaintip) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves the current chain tip, which is the latest known block height of the node. The response is plain text indicating the block height. ```bash curl http://localhost:/getChaintip ``` -------------------------------- ### start_key Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/eckey.md Creates a new eckey, adds it to the hash table, and returns its index. ```APIDOC ## start_key ### Description This convenience function creates a new `eckey`, adds it to the internal hash table using `add_eckey`, and returns the index of the newly added key. The index is guaranteed to be unique and increments with each call. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Function Signature ```c int start_key(dogecoin_bool is_testnet) ``` ### Parameters - **is_testnet** (dogecoin_bool) - Required - A boolean indicating whether to generate keys for the testnet (true) or mainnet (false). ### Request Example ```c int key_id = start_key(false); // Generates a mainnet key and returns its ID ``` ### Response #### Success Response (200) - **int** - The index of the newly created and added `eckey`. #### Response Example ``` 1 ``` ### Error Handling None ``` -------------------------------- ### Get Session Chain Statistics (GET /chainStats) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves session totals and on-disk sizes observed by the SPV node for the current run. This endpoint provides insights into the node's operational data. ```bash curl http://localhost:/chainStats ``` -------------------------------- ### Get On-Chain Activity Stats (GET /stats) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Aggregates recent on-chain activity within a specified time window or block count. Provides metrics like blocks, transactions, TPS, volume, and fees. ```bash curl "http://localhost:/stats?blocks=11&secs=86400" ``` -------------------------------- ### Get Raw Transaction (GET /getRawTx) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Returns the raw transaction in hexadecimal format for a given transaction ID. Requires a valid 64-hex character txid. Returns 400 for invalid txid or 404 if not found. ```bash curl "http://localhost:/getRawTx?txid=7c6728205d56b2b625463a10ade9c9a7ab2bf19ae2e05328f1f39e6f943c397b" ``` -------------------------------- ### Complete Dogecoin Transaction Workflow (C) Source: https://context7.com/dogecoinfoundation/libdogecoin/llms.txt Demonstrates the complete workflow of building, signing, and preparing a Dogecoin transaction for broadcast using libdogecoin. It covers key generation, UTXO definition, transaction construction, fee calculation, signing with a private key, and retrieving the raw transaction hex. Dependencies include libdogecoin headers and standard C libraries. ```c #include "libdogecoin.h" #include #include int main() { dogecoin_ecc_start(); // === STEP 1: Generate or use existing keys === char privKey[PRIVKEYWIFLEN] = "ci5prbqz7jXyFPVWKkHhPq4a9N8Dag3TpeRfuqqC2Nfr7gSqx1fy"; char myAddress[P2PKHLEN] = "noxKJyGPugPRN4wqvrwsrtYXuQCk7yQEsy"; char scriptPubKey[PUBKEYHASHLEN]; // Convert address to script pubkey hash dogecoin_p2pkh_address_to_pubkey_hash(myAddress, scriptPubKey); // === STEP 2: Define UTXOs (from blockchain/wallet) === char* utxo1_txid = "b4455e7b7b7acb51fb6feba7a2702c42a5100f61f61abafa31851ed6ae076074"; int utxo1_vout = 1; char* utxo1_amount = "2.0"; // 2 DOGE char* utxo2_txid = "42113bdc65fc2943cf0359ea1a24ced0b6b0b5290db4c63a3329c6601c4616e2"; int utxo2_vout = 1; char* utxo2_amount = "10.0"; // 10 DOGE // === STEP 3: Build the transaction === int txIndex = start_transaction(); printf("Created new transaction at index %d\n", txIndex); // Add all UTXOs as inputs add_utxo(txIndex, utxo1_txid, utxo1_vout); add_utxo(txIndex, utxo2_txid, utxo2_vout); printf("Added 2 inputs totaling 12 DOGE\n"); // Add recipient output char* recipient = "nbGfXLskPh7eM1iG5zz5EfDkkNTo9TRmde"; char* sendAmount = "5.0"; add_output(txIndex, recipient, sendAmount); printf("Added output: %s DOGE to %s\n", sendAmount, recipient); // === STEP 4: Finalize with fee and change === char* totalInput = "12.0"; char* fee = "0.00226"; // Standard minimum fee char* rawHex = finalize_transaction(txIndex, recipient, fee, totalInput, myAddress); if (rawHex) { printf("\nUnsigned Transaction:\n%s\n", rawHex); printf("Length: %lu characters\n\n", strlen(rawHex)); } // === STEP 5: Sign the transaction === if (sign_transaction(txIndex, scriptPubKey, privKey)) { char* signedHex = get_raw_transaction(txIndex); printf("=== SIGNED TRANSACTION ===\n"); printf("%s\n", signedHex); printf("Length: %lu characters\n\n", strlen(signedHex)); printf("Ready to broadcast via sendtx or API\n"); } // === STEP 6: Cleanup === clear_transaction(txIndex); dogecoin_ecc_stop(); return 0; } ``` -------------------------------- ### GET /getAddresses Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves all addresses associated with the wallet. ```APIDOC ## GET /getAddresses ### Description Retrieves all addresses associated with the wallet. ### Method GET ### Endpoint /getAddresses ### Response #### Success Response (200) - **Body** (text/plain) - List of addresses, one per line. #### Response Example address: DH5yaieqoZN36fDVciNyRueRGvGLR3mr7L address: DQe1QeG4FxhEgvfuvGfC7oL5G2G87huuxU ``` -------------------------------- ### Build Libdogecoin (Debian/Ubuntu) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/README.md Builds the full libdogecoin library, including the 'such' and 'sendtx' CLI tools, using autoconf and make. This process involves running autogen.sh, configure, and make. ```bash ./autogen.sh ./configure make ``` -------------------------------- ### Generate Package Configuration Files (CMake) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/libevent/CMakeLists.txt This CMake function, 'gen_package_config', is responsible for generating the LibeventConfig.cmake and LibeventConfigVersion.cmake files. These files are crucial for allowing other projects to find and use the installed libevent library. It supports generating files for both the build tree and the installation tree. ```cmake function(gen_package_config forinstall) if(${forinstall}) set(CONFIG_FOR_INSTALL_TREE 1) set(dir "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}") else() set(CONFIG_FOR_INSTALL_TREE 0) set(dir "${PROJECT_BINARY_DIR}") endif() configure_file(${PROJECT_SOURCE_DIR}/cmake/LibeventConfig.cmake.in "${dir}/LibeventConfig.cmake" @ONLY) endfunction() # Generate the config file for the build-tree. set(EVENT__INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include") set(LIBEVENT_INCLUDE_DIRS ${EVENT__INCLUDE_DIRS} CACHE PATH "Libevent include directories") gen_package_config(0) # Generate the config file for the installation tree. gen_package_config(1) # Generate version info for both build-tree and install-tree. configure_file(${PROJECT_SOURCE_DIR}/cmake/LibeventConfigVersion.cmake.in ${PROJECT_BINARY_DIR}/LibeventConfigVersion.cmake @ONLY) ``` -------------------------------- ### GET /stats Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Aggregates recent on-chain activity statistics. ```APIDOC ## GET /stats ### Description Aggregates recent on-chain activity seen by the SPV session within a specific time window or block count. ### Method GET ### Endpoint /stats ### Parameters #### Query Parameters - **secs** (integer) - Optional - Time window in seconds (default 86400). - **blocks** (integer) - Optional - Use last M blocks instead of time window. ### Response #### Success Response (200) - **Body** (text) - Key-value pairs representing blockchain statistics including blocks, transactions, volume, and fees. ``` -------------------------------- ### Create and Free SMPV Client (C) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/smpv.md Functions for creating and freeing an SMPV client. `dogecoin_smpv_client_new` initializes a client for specified chain parameters, while `dogecoin_smpv_client_free` releases its resources. ```c dogecoin_smpv_client* dogecoin_smpv_client_new(const dogecoin_chainparams* chain_params); void dogecoin_smpv_client_free(dogecoin_smpv_client* client); ``` -------------------------------- ### GET /getRawTx Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves the raw hex representation of a transaction. ```APIDOC ## GET /getRawTx ### Description Returns the raw transaction (hex) for a given transaction ID present in the wallet DB. ### Method GET ### Endpoint /getRawTx ### Parameters #### Query Parameters - **txid** (string) - Required - The 64-character hex transaction ID. ### Response #### Success Response (200) - **Body** (string) - Raw transaction hex string. #### Error Response - **400** - Missing or invalid txid. - **404** - Transaction not found in wallet DB. ``` -------------------------------- ### Constructing and Signing a Dogecoin Transaction Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/getting_started.md Demonstrates the workflow for initializing the ECC context, generating a key pair, building a transaction with UTXOs, signing it, and outputting the raw hex. ```c #include "libdogecoin.h" #include int main() { dogecoin_ecc_start(); char *oldPrivKey = "ci5prbqz7jXyFPVWKkHhPq4a9N8Dag3TpeRfuqqC2Nfr7gSqx1fy"; char *oldPubKey = "031dc1e49cfa6ae15edd6fa871a91b1f768e6f6cab06bf7a87ac0d8beb9229075b"; char *oldScriptPubKey = "76a914d8c43e6f68ca4ea1e9b93da2d1e3a95118fa4a7c88ac"; char* utxo_id = "b4455e7b7b7acb51fb6feba7a2702c42a5100f61f61abafa31851ed6ae076074"; int utxo_vout = 1; char* amt_total = "2.0"; char newPrivKey[PRIVKEYWIFLEN]; char newPubKey[P2PKHLEN]; generatePrivPubKeypair(newPrivKey, newPubKey, false); int idx = start_transaction(); add_utxo(idx, utxo_id, utxo_vout); add_output(idx, newPubKey, "0.69"); finalize_transaction(idx, newPubKey, "0.00226", amt_total, oldPubKey); sign_transaction(idx, oldScriptPubKey, oldPrivKey); printf("\nFinal signed transaction hex: %s\n\n", get_raw_transaction(idx)); dogecoin_ecc_stop(); } ``` -------------------------------- ### Compile C Project with Libdogecoin and Libevent Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/README.md This compilation command shows how to link a C source file (`main.c`) with the libdogecoin library and the `libevent` library. It's a common setup for projects requiring both. ```bash gcc main.c -ldogecoin -levent -o myprojectname ``` -------------------------------- ### GET /getWallet Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Downloads the wallet file associated with the node. ```APIDOC ## GET /getWallet ### Description Downloads the binary wallet file. Note: This contains sensitive information. ### Method GET ### Endpoint /getWallet ### Response #### Success Response (200) - **Content-Type** (application/octet-stream) - Binary data of the wallet file. ``` -------------------------------- ### GET /getBalance Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves the total balance of the wallet in Dogecoin. ```APIDOC ## GET /getBalance ### Description Retrieves the total balance of the wallet. ### Method GET ### Endpoint /getBalance ### Response #### Success Response (200) - **Body** (text/plain) - Wallet balance: #### Response Example Wallet balance: 123.45678900 ``` -------------------------------- ### GET /getHeaders Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves the binary blockchain headers file from the node. ```APIDOC ## GET /getHeaders ### Description Downloads the binary headers file for the blockchain, useful for debugging or analysis. ### Method GET ### Endpoint /getHeaders ### Response #### Success Response (200) - **Body** (binary) - Binary data of the headers file. ``` -------------------------------- ### GET /getTransactions Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves all spent (non-spendable) transactions associated with the wallet. ```APIDOC ## GET /getTransactions ### Description Retrieves all spent (non-spendable) transactions associated with the wallet. ### Method GET ### Endpoint /getTransactions ### Response #### Success Response (200) - **Body** (text/plain) - Detailed list of spent transactions and total spent balance. #### Response Example ---------------------- txid: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 vout: 0 address: DH5yaieqoZN36fDVciNyRueRGvGLR3mr7L Spent Balance: 50.00000000 ``` -------------------------------- ### Add Output to Dogecoin Transaction (C) Source: https://context7.com/dogecoinfoundation/libdogecoin/llms.txt Illustrates how to add outputs to a Dogecoin transaction, specifying recipient addresses and amounts in Dogecoin. This example first adds a UTXO as an input and then adds two separate outputs to demonstrate sending funds to multiple recipients. Requires libdogecoin. ```c #include "libdogecoin.h" #include int main() { char* utxo_txid = "b4455e7b7b7acb51fb6feba7a2702c42a5100f61f61abafa31851ed6ae076074"; char* recipient1 = "nbGfXLskPh7eM1iG5zz5EfDkkNTo9TRmde"; char* recipient2 = "noxKJyGPugPRN4wqvrwsrtYXuQCk7yQEsy"; int txIndex = start_transaction(); // Add input UTXO worth 10 DOGE add_utxo(txIndex, utxo_txid, 1); // Add outputs - sending to multiple recipients if (add_output(txIndex, recipient1, "5.0")) { printf("Added output: 5 DOGE to %s\n", recipient1); } if (add_output(txIndex, recipient2, "2.5")) { printf("Added output: 2.5 DOGE to %s\n", recipient2); } printf("Transaction hex: %s\n", get_raw_transaction(txIndex)); clear_transaction(txIndex); return 0; } ``` -------------------------------- ### Network Module Configuration Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/CMakeLists.txt Installs the rest.h header and adds network-related source files (headersdb_file.c, net.c, protocol.c, rest.c, spv.c) to the libdogecoin target if WITH_NET is enabled. It also includes conditional linking for Windows with TPM2 support. ```cmake IF(WITH_NET) INSTALL(FILES include/dogecoin/rest.h DESTINATION include/dogecoin ) TARGET_SOURCES(${LIBDOGECOIN_NAME} ${visibility} src/headersdb_file.c src/net.c src/protocol.c src/rest.c src/spv.c ) IF(WIN32 AND USE_TPM2) TARGET_LINK_LIBRARIES(${LIBS} ${LIBEVENT} ${LIBEVENT_PTHREADS} tbs ncrypt crypt32) ELSE() ``` -------------------------------- ### GET /smpvTx Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves details for a specific transaction tracked by the SMPV system. ```APIDOC ## GET /smpvTx ### Description Returns a single mempool transaction as a JSON object by its transaction ID. ### Method GET ### Endpoint /smpvTx?id= ### Parameters #### Query Parameters - **id** (string) - Required - The transaction ID (txid) to retrieve ### Response #### Success Response (200) - **txid** (string) - Transaction ID - **size** (int) - Transaction size in bytes - **outval** (int) - Total output value #### Response Example { "txid": "a65792df3f399a3436fc7c088ae9ef5fc81530010dc02a216731c971ac25dead", "size": 1677, "outval": 123328000 } ``` -------------------------------- ### GET /getChaintip Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves the current block height known to the SPV node. ```APIDOC ## GET /getChaintip ### Description Returns the height of the latest block known to the SPV node. ### Method GET ### Endpoint /getChaintip ### Response #### Success Response (200) - **Body** (string) - "Chain tip: " ``` -------------------------------- ### GET /getUTXOs Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves all unspent transaction outputs (UTXOs) associated with the wallet. ```APIDOC ## GET /getUTXOs ### Description Retrieves all unspent transaction outputs (UTXOs) associated with the wallet. ### Method GET ### Endpoint /getUTXOs ### Response #### Success Response (200) - **Body** (text/plain) - Detailed list of unspent transaction outputs and total unspent balance. #### Response Example ---------------------- Unspent UTXO: txid: b1fea5241c4a1d7d1e6c6d619fbf3bb8b1ec3f1f1d2f4c5b6a7c8d9e0f1a2b3c Total Unspent: 75.00000000 ```