|
| 1 | +#ifndef __POKER_VDXF_H__ |
| 2 | +#define __POKER_VDXF_H__ |
| 3 | + |
| 4 | +#include "bet.h" |
| 5 | +#include "common.h" |
| 6 | +#include "vdxf.h" |
| 7 | + |
| 8 | +/* ============================================================================ |
| 9 | + * Poker VDXF API |
| 10 | + * ============================================================================ |
| 11 | + * This module provides poker-specific operations built on top of the generic |
| 12 | + * VDXF/Verus RPC layer (vdxf.c). These functions understand poker game keys |
| 13 | + * and structures. |
| 14 | + * |
| 15 | + * Architecture: |
| 16 | + * Application (dealer.c, player.c) |
| 17 | + * | |
| 18 | + * v |
| 19 | + * poker_vdxf.c <-- This layer (poker-specific key parsing) |
| 20 | + * | |
| 21 | + * v |
| 22 | + * vdxf.c <-- Generic VDXF operations (get_cmm, update_cmm) |
| 23 | + * | |
| 24 | + * v |
| 25 | + * chips_rpc() <-- RPC abstraction (REST or CLI) |
| 26 | + * ============================================================================ */ |
| 27 | + |
| 28 | +/* ============================================================================ |
| 29 | + * Poker Key Data Access |
| 30 | + * ============================================================================ */ |
| 31 | + |
| 32 | +/** |
| 33 | + * Get string value from a poker key stored in an identity |
| 34 | + * @param id The identity name |
| 35 | + * @param key The poker key name (e.g., T_TABLE_INFO_KEY) |
| 36 | + * @return String value or NULL |
| 37 | + */ |
| 38 | +char *poker_get_key_str(char *id, char *key); |
| 39 | + |
| 40 | +/** |
| 41 | + * Get cJSON value from a poker key stored in an identity |
| 42 | + * @param id The identity name |
| 43 | + * @param key The poker key name |
| 44 | + * @param is_full_id 1 if id is fully qualified, 0 if short name |
| 45 | + * @return cJSON object or NULL |
| 46 | + */ |
| 47 | +cJSON *poker_get_key_json(const char *id, const char *key, int32_t is_full_id); |
| 48 | + |
| 49 | +/** |
| 50 | + * Get cJSON value using a pre-computed vdxfid |
| 51 | + * @param id The identity name |
| 52 | + * @param key_vdxfid The vdxfid of the key |
| 53 | + * @return cJSON object or NULL |
| 54 | + */ |
| 55 | +cJSON *poker_get_key_json_by_vdxfid(char *id, char *key_vdxfid); |
| 56 | + |
| 57 | +/* ============================================================================ |
| 58 | + * Poker Key Data Updates |
| 59 | + * ============================================================================ */ |
| 60 | + |
| 61 | +/** |
| 62 | + * Append hex data to a key in an identity's CMM |
| 63 | + * @param id The identity name |
| 64 | + * @param key The poker key name |
| 65 | + * @param hex_data The hex-encoded data to append |
| 66 | + * @param is_key_vdxf_id true if key is already a vdxfid |
| 67 | + * @return Updated CMM or NULL on error |
| 68 | + */ |
| 69 | +cJSON *poker_append_key_hex(char *id, char *key, char *hex_data, bool is_key_vdxf_id); |
| 70 | + |
| 71 | +/** |
| 72 | + * Append cJSON data to a key in an identity's CMM |
| 73 | + * @param id The identity name |
| 74 | + * @param key The poker key name |
| 75 | + * @param data The cJSON data to append |
| 76 | + * @param is_key_vdxf_id true if key is already a vdxfid |
| 77 | + * @return Updated CMM or NULL on error |
| 78 | + */ |
| 79 | +cJSON *poker_append_key_json(char *id, char *key, cJSON *data, bool is_key_vdxf_id); |
| 80 | + |
| 81 | +/** |
| 82 | + * Update (replace) data for a key in an identity's CMM |
| 83 | + * @param id The identity name |
| 84 | + * @param key The poker key name |
| 85 | + * @param data The cJSON data to set |
| 86 | + * @param is_key_vdxf_id true if key is already a vdxfid |
| 87 | + * @return Updated CMM or NULL on error |
| 88 | + */ |
| 89 | +cJSON *poker_update_key_json(char *id, char *key, cJSON *data, bool is_key_vdxf_id); |
| 90 | + |
| 91 | +/* ============================================================================ |
| 92 | + * Table Operations |
| 93 | + * ============================================================================ */ |
| 94 | + |
| 95 | +/** |
| 96 | + * Decode table info from a string |
| 97 | + * @param str The encoded table info string |
| 98 | + * @return Decoded table structure or NULL |
| 99 | + */ |
| 100 | +struct table *poker_decode_table_info_str(char *str); |
| 101 | + |
| 102 | +/** |
| 103 | + * Decode table info from cJSON |
| 104 | + * @param dealer_cmm_data The dealer's CMM data |
| 105 | + * @return Decoded table structure or NULL |
| 106 | + */ |
| 107 | +struct table *poker_decode_table_info(cJSON *dealer_cmm_data); |
| 108 | + |
| 109 | +/** |
| 110 | + * Check if a table is full |
| 111 | + * @param table_id The table identity |
| 112 | + * @return true if table is full, false otherwise |
| 113 | + */ |
| 114 | +bool poker_is_table_full(char *table_id); |
| 115 | + |
| 116 | +/** |
| 117 | + * Check if a table is registered under a dealer |
| 118 | + * @param table_id The table identity |
| 119 | + * @param dealer_id The dealer identity |
| 120 | + * @return true if registered, false otherwise |
| 121 | + */ |
| 122 | +bool poker_is_table_registered(char *table_id, char *dealer_id); |
| 123 | + |
| 124 | +/** |
| 125 | + * Find an available table to join |
| 126 | + * @return OK on success, error code on failure |
| 127 | + */ |
| 128 | +int32_t poker_find_table(); |
| 129 | + |
| 130 | +/** |
| 131 | + * Choose a table from available options |
| 132 | + * @return OK on success, error code on failure |
| 133 | + */ |
| 134 | +int32_t poker_choose_table(); |
| 135 | + |
| 136 | +/* ============================================================================ |
| 137 | + * Player Operations |
| 138 | + * ============================================================================ */ |
| 139 | + |
| 140 | +/** |
| 141 | + * Get the player ID assigned by the dealer |
| 142 | + * @param player_id Output parameter for player ID |
| 143 | + * @return OK on success, error code on failure |
| 144 | + */ |
| 145 | +int32_t poker_get_player_id(int *player_id); |
| 146 | + |
| 147 | +/** |
| 148 | + * Join a poker table |
| 149 | + * @return OK on success, error code on failure |
| 150 | + */ |
| 151 | +int32_t poker_join_table(); |
| 152 | + |
| 153 | +/** |
| 154 | + * Check player join status |
| 155 | + * @param table_id The table identity |
| 156 | + * @param verus_pid The player's Verus ID |
| 157 | + * @return Join status code |
| 158 | + */ |
| 159 | +int32_t poker_check_player_join_status(char *table_id, char *verus_pid); |
| 160 | + |
| 161 | +/* ============================================================================ |
| 162 | + * Dealer/Cashier Registry |
| 163 | + * ============================================================================ */ |
| 164 | + |
| 165 | +/** |
| 166 | + * Update the cashiers list with a new IP |
| 167 | + * @param ip The cashier IP to add |
| 168 | + * @return Updated cashiers info or NULL |
| 169 | + */ |
| 170 | +cJSON *poker_update_cashiers(char *ip); |
| 171 | + |
| 172 | +/** |
| 173 | + * List all registered dealers |
| 174 | + * @return cJSON array of dealers or NULL |
| 175 | + */ |
| 176 | +cJSON *poker_list_dealers(); |
| 177 | + |
| 178 | +/** |
| 179 | + * List all available tables |
| 180 | + */ |
| 181 | +void poker_list_tables(); |
| 182 | + |
| 183 | +/** |
| 184 | + * Add a dealer to the dealers registry |
| 185 | + * @param dealer_id The dealer identity to add |
| 186 | + * @return OK on success, error code on failure |
| 187 | + */ |
| 188 | +int32_t poker_add_dealer(char *dealer_id); |
| 189 | + |
| 190 | +/* ============================================================================ |
| 191 | + * Transaction Processing |
| 192 | + * ============================================================================ */ |
| 193 | + |
| 194 | +/** |
| 195 | + * Process a payin transaction |
| 196 | + * @param txid The transaction ID |
| 197 | + * @param payin_tx_data The transaction data |
| 198 | + * @return OK on success, error code on failure |
| 199 | + */ |
| 200 | +int32_t poker_process_payin_tx(char *txid, cJSON *payin_tx_data); |
| 201 | + |
| 202 | +/** |
| 203 | + * Process a new block for poker-related transactions |
| 204 | + * @param blockhash The block hash to process |
| 205 | + */ |
| 206 | +void poker_process_block(char *blockhash); |
| 207 | + |
| 208 | +/* ============================================================================ |
| 209 | + * Setup Verification |
| 210 | + * ============================================================================ */ |
| 211 | + |
| 212 | +/** |
| 213 | + * Verify the poker environment is properly configured |
| 214 | + * @return OK if setup is valid, error code otherwise |
| 215 | + */ |
| 216 | +int32_t poker_verify_setup(); |
| 217 | + |
| 218 | +#endif /* __POKER_VDXF_H__ */ |
| 219 | + |
0 commit comments