# Module Service - Exchange ## Overview The Exchange Service implements a decentralized trading platform for token pairs within the Cellframe SDK. This service provides comprehensive functionality for creating, managing, and executing token exchange orders with automated matching, fee distribution, and order book management. *Based on: `dap_chain_net_srv_xchange.h`, `dap_chain_net_srv_xchange.c`* **Service UID:** `DAP_CHAIN_NET_SRV_XCHANGE_ID` (0x2) **Group:** `GROUP_LOCAL_XCHANGE` ("local.xchange") ## Document Structure - [[#Overview|Overview]] - [[#Exchange Structures|Exchange Structures]] - [[#dap_chain_net_srv_xchange_price_t|dap_chain_net_srv_xchange_price_t - Order price structure]] - [[#dap_srv_xchange_order_ext_t|dap_srv_xchange_order_ext_t - Extended order information]] - [[#dap_chain_net_srv_xchange_t|dap_chain_net_srv_xchange_t - Main exchange service structure]] - [[#s_com_net_srv_xchange_err_t|s_com_net_srv_xchange_err_t - CLI error codes]] - [[#dap_chain_net_srv_xchange_order_status_t|dap_chain_net_srv_xchange_order_status_t - Order status enumeration]] - [[#xchange_tx_type_t|xchange_tx_type_t - Transaction type classification]] - [[#Exchange Functions|Exchange Functions]] - [[#Order Management|Order Management Functions]] - [[#Trading Operations|Trading Operations Functions]] - [[#Information Retrieval|Information Retrieval Functions]] - [[#Error Codes|Error Codes]] - [[#Typical Examples|Typical Examples]] ## Exchange Structures ### dap_chain_net_srv_xchange_price_t Core price and order information structure containing all essential data for exchange orders. ```c typedef struct dap_chain_net_srv_xchange_price { char token_sell[DAP_CHAIN_TICKER_SIZE_MAX]; // Token being sold (ticker) uint256_t datoshi_sell; // Amount to sell in datoshi dap_chain_net_t *net; // Network context char token_buy[DAP_CHAIN_TICKER_SIZE_MAX]; // Token to buy (ticker) uint256_t rate; // Exchange rate (buy/sell ratio) uint256_t fee; // Transaction fee amount dap_chain_hash_fast_t tx_hash; // Transaction hash dap_chain_hash_fast_t order_hash; // Unique order hash dap_chain_addr_t creator_addr; // Order creator address dap_time_t creation_date; // Order creation timestamp } dap_chain_net_srv_xchange_price_t; ``` **Fields:** - `token_sell` - Ticker of the token being sold (e.g., "CELL") - `datoshi_sell` - Amount to sell in smallest units (datoshi) - `net` - Pointer to the network where the exchange operates - `token_buy` - Ticker of the token to purchase (e.g., "ETH") - `rate` - Exchange rate representing how much of token_buy per unit of token_sell - `fee` - Transaction fee charged for the exchange operation - `tx_hash` - Hash of the transaction that created this order - `order_hash` - Unique identifier for this specific order - `creator_addr` - Address of the user who created the order - `creation_date` - Unix timestamp when the order was created ### dap_srv_xchange_order_ext_t Extended order information structure for additional order details. ```c typedef struct dap_srv_xchange_order_ext { uint64_t padding; // Padding for alignment uint256_t datoshi_buy; // Amount to buy in datoshi char token_buy[DAP_CHAIN_TICKER_SIZE_MAX]; // Token to buy ticker } DAP_ALIGN_PACKED dap_srv_xchange_order_ext_t; ``` **Fields:** - `padding` - Memory alignment padding - `datoshi_buy` - Specific amount to purchase in smallest units - `token_buy` - Ticker symbol of the token to purchase ### dap_chain_net_srv_xchange_t Main exchange service structure. ```c typedef struct dap_chain_net_srv_xchange { dap_chain_net_srv_t *parent; // Base service reference bool enabled; // Service activation status } dap_chain_net_srv_xchange_t; ``` ### s_com_net_srv_xchange_err_t Comprehensive CLI error codes for exchange operations. ```c typedef enum s_com_net_srv_xchange_err { DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_OK = 0, // Success // Order parameter errors DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_REQ_PARAM_NET_ERR, // Network parameter error DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_NET_NOT_FOUND_ERR, // Network not found DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_UNREC_STATUS_ERR, // Unrecognized status DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_CANT_FIND_TOKEN_TO_ERR, // Token to not found DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_CANT_FIND_TOKEN_FROM_ERR, // Token from not found DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_PARAM_TOKEN_SELL_ERR, // Token sell parameter error DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_PARAM_TOKEN_BUY_ERR, // Token buy parameter error DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_PARAM_TICKR_NOTF_ERR, // Ticker not found DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_TOKEN_EQUAL_ERR, // Tokens are equal // Order creation errors DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_CRTE_REQ_PARAM_VALUE_ERR, // Value parameter error DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_CRTE_REQ_PARAM_RATE_ERR, // Rate parameter error DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_CRTE_REQ_PARAM_FEE_ERR, // Fee parameter error DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_CRTE_REQ_PARAM_W_ERR, // Wallet parameter error DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_CRTE_WALLET_NOT_FOUND_ERR, // Wallet not found // Additional CLI error codes (truncated for brevity) DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_UNKNOWN_COMMAND_ERR // Unknown command error } s_com_net_srv_xchange_err_t; ``` ### dap_chain_net_srv_xchange_order_status_t Order status enumeration for tracking order lifecycle. ```c typedef enum dap_chain_net_srv_xchange_order_status { XCHANGE_ORDER_STATUS_OPENED = 0, // Order is open and active XCHANGE_ORDER_STATUS_CLOSED, // Order is closed/completed XCHANGE_ORDER_STATUS_UNKNOWN // Order status unknown } dap_chain_net_srv_xchange_order_status_t; ``` ### xchange_tx_type_t Transaction type classification for exchange operations. ```c typedef enum xchange_tx_type { TX_TYPE_UNDEFINED = 0, // Undefined transaction type TX_TYPE_ORDER, // Order creation transaction TX_TYPE_EXCHANGE, // Exchange execution transaction TX_TYPE_INVALIDATE // Order invalidation transaction } xchange_tx_type_t; ``` ## Exchange Functions ### Order Management #### `dap_chain_net_srv_xchange_create()` Creates a new exchange order in the system. ```c dap_chain_net_srv_xchange_create_error_t dap_chain_net_srv_xchange_create( dap_chain_net_t *a_net, const char *a_token_buy, const char *a_token_sell, uint256_t a_datoshi_sell, uint256_t a_rate, uint256_t a_fee, dap_chain_wallet_t *a_wallet, char **a_out_tx_hash ); ``` **Parameters:** - `a_net` (dap_chain_net_t *) - Target network for the exchange - `a_token_buy` (const char *) - Ticker of token to purchase - `a_token_sell` (const char *) - Ticker of token to sell - `a_datoshi_sell` (uint256_t) - Amount to sell in datoshi - `a_rate` (uint256_t) - Exchange rate (buy tokens per sell token) - `a_fee` (uint256_t) - Transaction fee amount - `a_wallet` (dap_chain_wallet_t *) - Wallet for transaction signing - `a_out_tx_hash` (char **) - Output transaction hash **Returns:** - `XCHANGE_CREATE_ERROR_OK` - Order created successfully - `XCHANGE_CREATE_ERROR_INVALID_ARGUMENT` - Invalid input parameters - `XCHANGE_CREATE_ERROR_TOKEN_TICKER_SELL_IS_NOT_FOUND_LEDGER` - Sell token not found - `XCHANGE_CREATE_ERROR_TOKEN_TICKER_BUY_IS_NOT_FOUND_LEDGER` - Buy token not found - `XCHANGE_CREATE_ERROR_NOT_ENOUGH_CASH_IN_SPECIFIED_WALLET` - Insufficient funds **Error Conditions:** - Returns error if either token ticker is not found in the ledger - Returns error if wallet has insufficient balance for sell amount plus fees - Returns error if exchange rate is zero - Returns error if transaction cannot be added to mempool #### `dap_chain_net_srv_xchange_remove()` Removes an existing exchange order from the system. ```c dap_chain_net_srv_xchange_remove_error_t dap_chain_net_srv_xchange_remove( dap_chain_net_t *a_net, dap_hash_fast_t *a_hash_tx, uint256_t a_fee, dap_chain_wallet_t *a_wallet, char **a_out_hash_tx ); ``` **Parameters:** - `a_net` (dap_chain_net_t *) - Network containing the order - `a_hash_tx` (dap_hash_fast_t *) - Hash of the order to remove - `a_fee` (uint256_t) - Fee for the removal transaction - `a_wallet` (dap_chain_wallet_t *) - Wallet for transaction signing - `a_out_hash_tx` (char **) - Output transaction hash **Returns:** - `XCHANGE_REMOVE_ERROR_OK` - Order removed successfully - `XCHANGE_REMOVE_ERROR_INVALID_ARGUMENT` - Invalid parameters - `XCHANGE_REMOVE_ERROR_CAN_NOT_FIND_TX` - Order transaction not found - `XCHANGE_REMOVE_ERROR_CAN_NOT_INVALIDATE_TX` - Failed to invalidate order ### Trading Operations #### `dap_chain_net_srv_xchange_purchase()` Executes a purchase against an existing exchange order. ```c dap_chain_net_srv_xchange_purchase_error_t dap_chain_net_srv_xchange_purchase( dap_chain_net_t *a_net, dap_hash_fast_t *a_order_hash, uint256_t a_value, uint256_t a_fee, dap_chain_wallet_t *a_wallet, char **a_hash_out ); ``` **Parameters:** - `a_net` (dap_chain_net_t *) - Network containing the order - `a_order_hash` (dap_hash_fast_t *) - Hash of the order to purchase from - `a_value` (uint256_t) - Amount to purchase - `a_fee` (uint256_t) - Transaction fee - `a_wallet` (dap_chain_wallet_t *) - Buyer's wallet - `a_hash_out` (char **) - Output transaction hash **Returns:** - `XCHANGE_PURCHASE_ERROR_OK` - Purchase completed successfully - `XCHANGE_PURCHASE_ERROR_INVALID_ARGUMENT` - Invalid parameters - `XCHANGE_PURCHASE_ERROR_SPECIFIED_ORDER_NOT_FOUND` - Order not found - `XCHANGE_PURCHASE_ERROR_CAN_NOT_CREATE_EXCHANGE_TX` - Failed to create transaction ### Information Retrieval #### `dap_chain_net_srv_xchange_get_prices()` Retrieves list of all active exchange prices. ```c dap_list_t *dap_chain_net_srv_xchange_get_prices(dap_chain_net_t *a_net); ``` **Parameters:** - `a_net` (dap_chain_net_t *) - Target network **Returns:** - List of `dap_chain_net_srv_xchange_price_t` structures - `NULL` if no prices available or error occurred #### `dap_chain_net_srv_xchange_get_order_status()` Gets the current status of a specific order. ```c dap_chain_net_srv_xchange_order_status_t dap_chain_net_srv_xchange_get_order_status( dap_chain_net_t *a_net, dap_chain_hash_fast_t a_order_tx_hash ); ``` **Returns:** - `XCHANGE_ORDER_STATUS_OPENED` - Order is active and accepting purchases - `XCHANGE_ORDER_STATUS_CLOSED` - Order has been completed or cancelled - `XCHANGE_ORDER_STATUS_UNKNOWN` - Order status cannot be determined #### `dap_chain_net_srv_xchange_get_order_completion_rate()` Gets completion percentage of a specific order. ```c uint64_t dap_chain_net_srv_xchange_get_order_completion_rate( dap_chain_net_t *a_net, dap_chain_hash_fast_t a_order_tx_hash ); ``` **Returns:** - Completion rate as percentage (0-100) - 0 if order not found or no progress ## Error Codes ### Exchange Creation Error Codes ```c typedef enum dap_chain_net_srv_xchange_create_error_list { XCHANGE_CREATE_ERROR_OK = 0, // Success XCHANGE_CREATE_ERROR_INVALID_ARGUMENT, // Invalid parameters XCHANGE_CREATE_ERROR_TOKEN_TICKER_SELL_IS_NOT_FOUND_LEDGER, // Sell token not found XCHANGE_CREATE_ERROR_TOKEN_TICKER_BUY_IS_NOT_FOUND_LEDGER, // Buy token not found XCHANGE_CREATE_ERROR_RATE_IS_ZERO, // Zero exchange rate XCHANGE_CREATE_ERROR_FEE_IS_ZERO, // Zero fee specified XCHANGE_CREATE_ERROR_VALUE_SELL_IS_ZERO, // Zero sell value XCHANGE_CREATE_ERROR_INTEGER_OVERFLOW_WITH_SUM_OF_VALUE_AND_FEE, // Overflow error XCHANGE_CREATE_ERROR_NOT_ENOUGH_CASH_FOR_FEE_IN_SPECIFIED_WALLET, // Insufficient fee funds XCHANGE_CREATE_ERROR_NOT_ENOUGH_CASH_IN_SPECIFIED_WALLET, // Insufficient funds XCHANGE_CREATE_ERROR_MEMORY_ALLOCATED, // Memory allocation error XCHANGE_CREATE_ERROR_CAN_NOT_COMPOSE_THE_CONDITIONAL_TRANSACTION, // TX composition error XCHANGE_CREATE_ERROR_CAN_NOT_PUT_TRANSACTION_TO_MEMPOOL // Mempool error } dap_chain_net_srv_xchange_create_error_t; ``` ### Exchange Removal Error Codes ```c typedef enum dap_chain_net_srv_xchange_remove_error_list { XCHANGE_REMOVE_ERROR_OK = 0, // Success XCHANGE_REMOVE_ERROR_INVALID_ARGUMENT, // Invalid parameters XCHANGE_REMOVE_ERROR_FEE_IS_ZERO, // Zero fee XCHANGE_REMOVE_ERROR_CAN_NOT_FIND_TX, // Transaction not found XCHANGE_REMOVE_ERROR_CAN_NOT_CREATE_PRICE, // Price creation failed XCHANGE_REMOVE_ERROR_CAN_NOT_INVALIDATE_TX // Transaction invalidation failed } dap_chain_net_srv_xchange_remove_error_t; ``` ### Exchange Purchase Error Codes ```c typedef enum dap_chain_net_srv_xchange_purchase_error_list { XCHANGE_PURCHASE_ERROR_OK = 0, // Success XCHANGE_PURCHASE_ERROR_INVALID_ARGUMENT, // Invalid parameters XCHANGE_PURCHASE_ERROR_SPECIFIED_ORDER_NOT_FOUND, // Order not found XCHANGE_PURCHASE_ERROR_CAN_NOT_CREATE_PRICE, // Price creation failed XCHANGE_PURCHASE_ERROR_CAN_NOT_CREATE_EXCHANGE_TX // Exchange transaction failed } dap_chain_net_srv_xchange_purchase_error_t; ``` ## Typical Examples ### Exchange Order Creation Example ```c #include <dap_chain_net_srv_xchange.h> void exchange_order_creation_example() { log_it_info("=== Exchange Order Creation Example ==="); // Step 1: Setup network and wallet dap_chain_net_t *net = dap_chain_net_by_name("backbone"); if (!net) { log_it_error("✗ Network 'backbone' not found"); return; } dap_chain_wallet_t *wallet = dap_chain_wallet_open("trader_wallet", NULL, NULL); if (!wallet) { log_it_error("✗ Failed to open wallet 'trader_wallet'"); return; } // Step 2: Define order parameters const char *token_sell = "CELL"; const char *token_buy = "ETH"; uint256_t datoshi_sell = dap_chain_balance_scan("1000.0"); // Sell 1000 CELL uint256_t rate = dap_chain_balance_scan("0.05"); // 1 CELL = 0.05 ETH uint256_t fee = dap_chain_balance_scan("1.0"); // 1 CELL fee log_it_info("Creating exchange order:"); log_it_info(" Selling: %s CELL", dap_chain_balance_to_coins(datoshi_sell)); log_it_info(" Buying: %s", token_buy); log_it_info(" Rate: %s %s per %s", dap_chain_balance_to_coins(rate), token_buy, token_sell); log_it_info(" Fee: %s %s", dap_chain_balance_to_coins(fee), token_sell); // Step 3: Create exchange order char *tx_hash_out = NULL; dap_chain_net_srv_xchange_create_error_t result = dap_chain_net_srv_xchange_create( net, token_buy, token_sell, datoshi_sell, rate, fee, wallet, &tx_hash_out ); // Step 4: Handle result switch (result) { case XCHANGE_CREATE_ERROR_OK: log_it_info("✓ Exchange order created successfully"); log_it_info(" Transaction hash: %s", tx_hash_out ? tx_hash_out : "N/A"); break; case XCHANGE_CREATE_ERROR_TOKEN_TICKER_SELL_IS_NOT_FOUND_LEDGER: log_it_error("✗ Sell token '%s' not found in ledger", token_sell); break; case XCHANGE_CREATE_ERROR_TOKEN_TICKER_BUY_IS_NOT_FOUND_LEDGER: log_it_error("✗ Buy token '%s' not found in ledger", token_buy); break; case XCHANGE_CREATE_ERROR_NOT_ENOUGH_CASH_IN_SPECIFIED_WALLET: log_it_error("✗ Insufficient funds in wallet"); log_it_error(" Required: %s %s + %s fee", dap_chain_balance_to_coins(datoshi_sell), token_sell, dap_chain_balance_to_coins(fee)); break; case XCHANGE_CREATE_ERROR_RATE_IS_ZERO: log_it_error("✗ Exchange rate cannot be zero"); break; case XCHANGE_CREATE_ERROR_INVALID_ARGUMENT: log_it_error("✗ Invalid order parameters"); break; default: log_it_error("✗ Order creation failed with error: %d", result); break; } // Step 5: Cleanup if (tx_hash_out) { DAP_DELETE(tx_hash_out); } dap_chain_wallet_close(wallet); log_it_info("Exchange order creation example completed"); } ``` ### Exchange Purchase Example ```c #include <dap_chain_net_srv_xchange.h> void exchange_purchase_example() { log_it_info("=== Exchange Purchase Example ==="); // Step 1: Setup network and buyer wallet dap_chain_net_t *net = dap_chain_net_by_name("backbone"); if (!net) { log_it_error("✗ Network not found"); return; } dap_chain_wallet_t *buyer_wallet = dap_chain_wallet_open("buyer_wallet", NULL, NULL); if (!buyer_wallet) { log_it_error("✗ Failed to open buyer wallet"); return; } // Step 2: Get available orders dap_list_t *prices = dap_chain_net_srv_xchange_get_prices(net); if (!prices) { log_it_error("✗ No exchange orders available"); dap_chain_wallet_close(buyer_wallet); return; } log_it_info("✓ Found active exchange orders"); // Step 3: Select first available order (in real app, user would choose) dap_chain_net_srv_xchange_price_t *selected_order = (dap_chain_net_srv_xchange_price_t *)prices->data; log_it_info("Selected order details:"); log_it_info(" Selling: %s %s", dap_chain_balance_to_coins(selected_order->datoshi_sell), selected_order->token_sell); log_it_info(" Buying: %s", selected_order->token_buy); log_it_info(" Rate: %s", dap_chain_balance_to_coins(selected_order->rate)); log_it_info(" Creator: %s", dap_chain_addr_to_str(&selected_order->creator_addr)); // Step 4: Execute purchase uint256_t purchase_amount = dap_chain_balance_scan("100.0"); // Buy 100 tokens uint256_t purchase_fee = dap_chain_balance_scan("0.5"); // 0.5 token fee char *purchase_tx_hash = NULL; dap_chain_net_srv_xchange_purchase_error_t purchase_result = dap_chain_net_srv_xchange_purchase( net, &selected_order->order_hash, purchase_amount, purchase_fee, buyer_wallet, &purchase_tx_hash ); // Step 5: Handle purchase result switch (purchase_result) { case XCHANGE_PURCHASE_ERROR_OK: log_it_info("✓ Purchase completed successfully"); log_it_info(" Purchase hash: %s", purchase_tx_hash ? purchase_tx_hash : "N/A"); log_it_info(" Amount purchased: %s tokens", dap_chain_balance_to_coins(purchase_amount)); break; case XCHANGE_PURCHASE_ERROR_SPECIFIED_ORDER_NOT_FOUND: log_it_error("✗ Selected order no longer available"); break; case XCHANGE_PURCHASE_ERROR_INVALID_ARGUMENT: log_it_error("✗ Invalid purchase parameters"); break; case XCHANGE_PURCHASE_ERROR_CAN_NOT_CREATE_EXCHANGE_TX: log_it_error("✗ Failed to create exchange transaction"); break; default: log_it_error("✗ Purchase failed with error: %d", purchase_result); break; } // Step 6: Cleanup if (purchase_tx_hash) { DAP_DELETE(purchase_tx_hash); } dap_list_free(prices); dap_chain_wallet_close(buyer_wallet); log_it_info("Exchange purchase example completed"); } ``` ### Exchange Order Management Example ```c #include <dap_chain_net_srv_xchange.h> void exchange_order_management_example() { log_it_info("=== Exchange Order Management Example ==="); // Step 1: Setup network dap_chain_net_t *net = dap_chain_net_by_name("backbone"); if (!net) { log_it_error("✗ Network not found"); return; } // Step 2: Get all active orders dap_list_t *prices = dap_chain_net_srv_xchange_get_prices(net); if (!prices) { log_it_info("No active exchange orders found"); return; } // Step 3: Display order information log_it_info("Active Exchange Orders:"); log_it_info("╭─────────────────────────────────────────────────────────────────────╮"); log_it_info("│ Token Pair │ Amount │ Rate │ Status │ Progress │"); log_it_info("├─────────────────────────────────────────────────────────────────────┤"); dap_list_t *current = prices; int order_count = 0; while (current) { dap_chain_net_srv_xchange_price_t *price = (dap_chain_net_srv_xchange_price_t *)current->data; // Get order status dap_chain_hash_fast_t order_hash = price->order_hash; dap_chain_net_srv_xchange_order_status_t status = dap_chain_net_srv_xchange_get_order_status(net, order_hash); uint64_t completion = dap_chain_net_srv_xchange_get_order_completion_rate(net, order_hash); const char *status_str = "Unknown"; switch (status) { case XCHANGE_ORDER_STATUS_OPENED: status_str = "Open"; break; case XCHANGE_ORDER_STATUS_CLOSED: status_str = "Closed"; break; case XCHANGE_ORDER_STATUS_UNKNOWN: status_str = "Unknown"; break; } char pair[32]; snprintf(pair, sizeof(pair), "%s/%s", price->token_sell, price->token_buy); log_it_info("│ %-13s │ %-12s │ %-12s │ %-9s │ %3" PRIu64 "%% │", pair, dap_chain_balance_to_coins(price->datoshi_sell), dap_chain_balance_to_coins(price->rate), status_str, completion); current = current->next; order_count++; } log_it_info("╰─────────────────────────────────────────────────────────────────────╯"); log_it_info("Total active orders: %d", order_count); // Step 4: Demonstrate order removal (if any open orders exist) if (order_count > 0) { dap_chain_net_srv_xchange_price_t *first_order = (dap_chain_net_srv_xchange_price_t *)prices->data; log_it_info("--- Order Removal Example ---"); log_it_info("Attempting to remove order: %s/%s", first_order->token_sell, first_order->token_buy); // Note: In real scenario, only order creator can remove their orders dap_chain_wallet_t *creator_wallet = dap_chain_wallet_open("creator_wallet", NULL, NULL); if (creator_wallet) { char *removal_tx_hash = NULL; uint256_t removal_fee = dap_chain_balance_scan("0.1"); dap_chain_net_srv_xchange_remove_error_t removal_result = dap_chain_net_srv_xchange_remove( net, &first_order->tx_hash, removal_fee, creator_wallet, &removal_tx_hash ); switch (removal_result) { case XCHANGE_REMOVE_ERROR_OK: log_it_info("✓ Order removed successfully"); log_it_info(" Removal hash: %s", removal_tx_hash ? removal_tx_hash : "N/A"); break; case XCHANGE_REMOVE_ERROR_CAN_NOT_FIND_TX: log_it_error("✗ Order transaction not found"); break; case XCHANGE_REMOVE_ERROR_FEE_IS_ZERO: log_it_error("✗ Removal fee cannot be zero"); break; default: log_it_error("✗ Order removal failed: %d", removal_result); break; } if (removal_tx_hash) { DAP_DELETE(removal_tx_hash); } dap_chain_wallet_close(creator_wallet); } } // Step 5: Cleanup dap_list_free(prices); log_it_info("Exchange order management example completed"); } ``` --- *See also: [[Modules/Module Service|Module Service]], [[Modules/Module Wallet|Module Wallet]], [[ETC/Services Overview|Services Overview]]*