Skip to content

Commit 71e3595

Browse files
committed
refactor: add chips_rpc() abstraction and poker_vdxf layer
- Add chips_rpc() abstraction in commands.c for REST/CLI switching - Update vdxf.c to use chips_rpc() for all 9 Verus RPC calls - Create poker_vdxf.c/h with poker-specific API layer - Add .rpccredentials config for RPC credentials (REST API) - Remove unused VDXF functions from public API - Add ERR_CHIPS_RPC error code Architecture: Application -> poker_vdxf.c -> vdxf.c -> chips_rpc() -> REST/CLI
1 parent 35848d3 commit 71e3595

File tree

19 files changed

+1081
-953
lines changed

19 files changed

+1081
-953
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ dist/*
5656
bet_version.h
5757
compile_commands.json
5858
.vscode/
59+
60+
# RPC credentials (contains secrets - never commit)
61+
poker/.rpccredentials
62+
.rpccredentials

poker/.rpccredentials.example

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# CHIPS RPC Credentials Template
2+
# Copy this file to .rpccredentials and fill in your values
3+
# The .rpccredentials file is in .gitignore and will not be committed
4+
5+
[rpc]
6+
# RPC endpoint URL (default CHIPS port is 22778)
7+
url = http://127.0.0.1:22778
8+
9+
# RPC username (from your chips.conf or verus chain conf)
10+
user = your_rpc_user
11+
12+
# RPC password (from your chips.conf or verus chain conf)
13+
password = your_rpc_password
14+
15+
# Set to 1 to use REST API, 0 to use CLI commands (default: 1 when file exists)
16+
use_rest_api = 1
17+

poker/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ SRCFILES := $(SRC_DIR)/cards.c $(SRC_DIR)/client.c $(SRC_DIR)/commands.c $(SR
1515
$(SRC_DIR)/host.c $(SRC_DIR)/network.c $(SRC_DIR)/oracle.c $(SRC_DIR)/payment.c \
1616
$(SRC_DIR)/states.c $(SRC_DIR)/table.c $(SRC_DIR)/poker.c $(SRC_DIR)/cashier.c \
1717
$(SRC_DIR)/storage.c $(SRC_DIR)/config.c $(SRC_DIR)/misc.c $(SRC_DIR)/heartbeat.c \
18-
$(SRC_DIR)/help.c $(SRC_DIR)/err.c $(SRC_DIR)/vdxf.c $(SRC_DIR)/player.c \
19-
$(SRC_DIR)/blinder.c $(SRC_DIR)/dealer.c $(SRC_DIR)/print.c $(SRC_DIR)/test.c \
20-
$(SRC_DIR)/deck.c $(SRC_DIR)/game.c $(SRC_DIR)/dealer_registration.c
18+
$(SRC_DIR)/help.c $(SRC_DIR)/err.c $(SRC_DIR)/vdxf.c $(SRC_DIR)/poker_vdxf.c \
19+
$(SRC_DIR)/player.c $(SRC_DIR)/blinder.c $(SRC_DIR)/dealer.c $(SRC_DIR)/print.c \
20+
$(SRC_DIR)/test.c $(SRC_DIR)/deck.c $(SRC_DIR)/game.c $(SRC_DIR)/dealer_registration.c
2121

2222
# Object files go in build directory
2323
OBJFILES := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCFILES))

poker/config/verus_ids_keys.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# Parent identity (root namespace)
77
parent_id = sg777z.chips.vrsc@
88

9+
# Test identity for development/testing ID updates
10+
test_id = test.sg777z.chips@
11+
912
# Cashier identity (holds cashier information)
1013
cashier_id = cashier.sg777z.chips.vrsc@
1114

poker/include/commands.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ int32_t chips_is_mempool_empty();
6262
struct cJSON *do_split_tx_amount(double amount, int32_t no_of_splits);
6363
int32_t run_command(int argc, char **argv);
6464
int32_t make_command(int argc, char **argv, cJSON **argjson);
65+
66+
/**
67+
* Unified CHIPS RPC interface - automatically uses REST or CLI based on config
68+
*
69+
* @param method RPC method name (e.g., "getbalance", "getblockchaininfo")
70+
* @param params cJSON array of parameters (can be NULL for no params)
71+
* @param result Output cJSON object (caller must free with cJSON_Delete)
72+
* @return OK on success, error code on failure
73+
*/
74+
int32_t chips_rpc(const char *method, cJSON *params, cJSON **result);
6575
char *ln_get_new_address();
6676
int32_t ln_block_height(int32_t *block_height);
6777
int32_t ln_listfunds();

poker/include/config.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ struct verus_ids_keys_config {
4545

4646
extern struct verus_ids_keys_config verus_config;
4747

48+
/* RPC Credentials Configuration Structure */
49+
struct rpc_credentials {
50+
char url[256];
51+
char user[128];
52+
char password[256];
53+
int use_rest_api; /* 1 = use REST API, 0 = use CLI */
54+
int initialized;
55+
};
56+
57+
extern struct rpc_credentials rpc_config;
58+
59+
/* RPC Credentials Functions */
60+
void bet_parse_rpc_credentials(void);
61+
const char *bet_get_rpc_url(void);
62+
const char *bet_get_rpc_user(void);
63+
const char *bet_get_rpc_password(void);
64+
int bet_use_rest_api(void);
65+
4866
void bet_init_config_paths(void);
4967
cJSON *bet_read_json_file(char *file_name);
5068

poker/include/err.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef enum {
4343
ERR_CHIPS_INSUFFICIENT_FUNDS = 38,
4444
ERR_CHIPS_TX_FAILED = 39,
4545
ERR_CHIPS_COMMAND = 40,
46+
ERR_CHIPS_RPC = 41,
4647

4748
// LN Errors (49-64)
4849
ERR_LN = 49,

poker/include/poker_vdxf.h

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
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

Comments
 (0)