From fd70022568e113d635b821ca540c350b0082fd70 Mon Sep 17 00:00:00 2001 From: sg777 Date: Tue, 14 May 2024 07:43:42 +0530 Subject: [PATCH 01/13] Updating verus_pid to t_player_info key instead of primaryaddress --- privatebet/dealer.c | 9 ++------- privatebet/vdxf.c | 39 +++++++++++++++++++++++++++------------ privatebet/vdxf.h | 11 ++++++++++- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/privatebet/dealer.c b/privatebet/dealer.c index e466ecf6..77bda629 100644 --- a/privatebet/dealer.c +++ b/privatebet/dealer.c @@ -23,11 +23,6 @@ char all_game_keys[all_game_keys_no][128] = { T_GAME_INFO_KEY }; char all_game_key_names[all_game_keys_no][128] = { "t_game_info" }; -/* Dealer should hold atleast 1 CHIPS, atm 1 CHIP can last to make 1000 updates to the ID which is -* sufficient to accomodate all gaming updates in poker -*/ -double dealer_min_funds = 1; - int32_t add_dealer(char *dealer_id) { int32_t retval = OK; @@ -293,8 +288,8 @@ int32_t dealer_init(struct table t) double balance = 0; balance = chips_get_balance(); - if (balance < dealer_min_funds) { - dlg_info("Wallet balance ::%f, Minimum funds needed to host a table :: %f", balance, dealer_min_funds); + if (balance < RESERVE_AMOUNT) { + dlg_info("Wallet balance ::%f, Minimum funds needed to host a table :: %f", balance, RESERVE_AMOUNT); return ERR_CHIPS_INSUFFICIENT_FUNDS; } if ((!id_cansignfor(t.dealer_id, 0, &retval)) || (!id_cansignfor(t.table_id, 0, &retval))) { diff --git a/privatebet/vdxf.c b/privatebet/vdxf.c index bad69fc3..3af123e2 100644 --- a/privatebet/vdxf.c +++ b/privatebet/vdxf.c @@ -535,18 +535,18 @@ int32_t find_table() int32_t retval = OK; cJSON *t_table_info = NULL, *dealer_ids = NULL; - /* - * Check if the configured table meets the preconditions for the player to join the table - */ - if ((retval = chose_table()) != OK) { - return retval; - } /* * Check if the player wallet has suffiecient funds to join the table */ if (!check_if_enough_funds_avail(player_t.table_id)) { return ERR_CHIPS_INSUFFICIENT_FUNDS; } + /* + * Check if the configured table meets the preconditions for the player to join the table + */ + if ((retval = chose_table()) != OK) { + return retval; + } return retval; } @@ -1002,7 +1002,7 @@ int32_t do_payin_tx_checks(char *txid, cJSON *payin_tx_data) { int32_t retval = OK, game_state; double amount = 0; - char pa[128] = { 0 }, *game_id_str = NULL, *table_id = NULL, *dealer_id = NULL; + char pa[128] = { 0 }, *game_id_str = NULL, *table_id = NULL, *dealer_id = NULL, *verus_pid = NULL; cJSON *t_player_info = NULL, *player_info = NULL, *t_table_info = NULL; if ((!txid) || (!payin_tx_data)) @@ -1011,9 +1011,10 @@ int32_t do_payin_tx_checks(char *txid, cJSON *payin_tx_data) dlg_info("Payin TX Data ::%s", cJSON_Print(payin_tx_data)); table_id = jstr(payin_tx_data, "table_id"); dealer_id = jstr(payin_tx_data, "dealer_id"); + verus_pid = jstr(payin_tx_data, "verus_pid"); //Check the table ID and dealer ID mentioned in Payin TX are valid. - if (!is_id_exists(table_id, 0) || !is_id_exists(dealer_id, 0)) { + if (!is_id_exists(table_id, 0) || !is_id_exists(dealer_id, 0) || !is_id_exists(verus_pid, 0)) { return ERR_ID_NOT_FOUND; } @@ -1039,7 +1040,8 @@ int32_t do_payin_tx_checks(char *txid, cJSON *payin_tx_data) jdouble(t_table_info, "min_stake"), jdouble(t_table_info, "max_stake")); return ERR_PAYIN_TX_INVALID_FUNDS; } - + // TODO:: Check for duplicate request based on ID + #if 0 // Check for a duplicate join request and duplicate PA, PA should be unique so that ensures a player can occupy atmost one position on the table. t_player_info = cJSON_CreateObject(); t_player_info = get_cJSON_from_id_key_vdxfid(table_id, get_key_data_vdxf_id(T_PLAYER_INFO_KEY, game_id_str)); @@ -1057,11 +1059,13 @@ int32_t do_payin_tx_checks(char *txid, cJSON *payin_tx_data) return ERR_PA_EXISTS; } } + #endif return retval; } /* - The player info is stored in the form of PA_TXID_PLAYERID +* Reads the key T_PLAYER_INFO_KEY +* Increment num_players and append player data to player_info array. */ static cJSON *compute_updated_t_player_info(char *txid, cJSON *payin_tx_data) { @@ -1079,11 +1083,13 @@ static cJSON *compute_updated_t_player_info(char *txid, cJSON *payin_tx_data) if (t_player_info) { num_players = jint(t_player_info, "num_players"); player_info = cJSON_GetObjectItem(t_player_info, "player_info"); - if (!player_info) + if (!player_info) { + dlg_error("Error with data on Key :: %s", T_PLAYER_INFO_KEY); return NULL; + } } num_players++; - sprintf(pa_tx_id, "%s_%s_%d", jstr(payin_tx_data, "primaryaddress"), txid, num_players); + sprintf(pa_tx_id, "%s_%s_%d", jstr(payin_tx_data, "verus_pid"), txid, num_players); jaddistr(player_info, pa_tx_id); updated_t_player_info = cJSON_CreateObject(); @@ -1135,9 +1141,11 @@ int32_t process_payin_tx_data(char *txid, cJSON *payin_tx_data) updated_t_player_info, true); dlg_info("%s", cJSON_Print(out)); + #if 0 //Add the players primary address to the list of the primary addresses of the table id so that player can able to perform the updates to the table ID. out = append_pa_to_cmm(jstr(payin_tx_data, "table_id"), jstr(payin_tx_data, "primaryaddress")); dlg_info("%s", cJSON_Print(out)); + #endif return retval; } @@ -1172,6 +1180,13 @@ void process_block(char *blockhash) return; } + /* + * List all the utxos attached to the registered cashiers, like cashiers.poker.chips10sec@ + * Look for the utxos that matches to the current processing block height + * Extract the tx data + * Process the tx data to see if this tx is intended and related to poker + * If the tx is related to poker, do all checks and add the players info to the table + */ cJSON *argjson = cJSON_CreateObject(); argjson = getaddressutxos(verus_addr, 1); for (int32_t i = 0; i < cJSON_GetArraySize(argjson); i++) { diff --git a/privatebet/vdxf.h b/privatebet/vdxf.h index 7def7309..9873734b 100644 --- a/privatebet/vdxf.h +++ b/privatebet/vdxf.h @@ -27,6 +27,12 @@ key is represented as chips.vrsc::poker.cashiers. #define T_GAME_ID_KEY "chips.vrsc::poker.t_game_ids" #define T_TABLE_INFO_KEY "chips.vrsc::poker.t_table_info" +/* +* t_player_info { +* num_players : +* player_info : [veruspid_txid_playerid] +* } +*/ #define T_PLAYER_INFO_KEY "chips.vrsc::poker.t_player_info" #define T_PLAYER1_KEY "chips.vrsc::poker.t_player1" #define T_PLAYER2_KEY "chips.vrsc::poker.t_player2" @@ -108,7 +114,10 @@ Bet supports various tokens that launch on Verus and CHIPS is the token which we */ #define CHIPS "chips10sec" -#define ID_UPDATE_ESTIMATE_NO 50 +/* Every node that is part of the poker make updates to the IDs, so to pay tx_fee for the ID updates we keeping this reserve +* amount to be 1 CHIP which is sufficient to accomodate all gaming updates in poker. +*/ +#define ID_UPDATE_ESTIMATE_NO 1000 #define RESERVE_AMOUNT ID_UPDATE_ESTIMATE_NO *chips_tx_fee #define all_t_d_p_keys_no 10 From ee41b18ebff908bfd8a6e6f383e3f801638f82fe Mon Sep 17 00:00:00 2001 From: sg777 Date: Tue, 14 May 2024 08:11:35 +0530 Subject: [PATCH 02/13] Made changes to use verus player id to check the status of the player on the table --- privatebet/config.c | 2 ++ privatebet/err.c | 2 ++ privatebet/err.h | 1 + privatebet/player.c | 3 ++- privatebet/vdxf.c | 36 +++++++++++++++++++++++++++++------- privatebet/vdxf.h | 2 ++ 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/privatebet/config.c b/privatebet/config.c index 90eb512c..141940df 100644 --- a/privatebet/config.c +++ b/privatebet/config.c @@ -358,10 +358,12 @@ int32_t bet_parse_verus_player() strncpy(player_config.table_id, iniparser_getstring(ini, "verus:table_id", NULL), sizeof(player_config.table_id)); } + #if 0 if (NULL != iniparser_getstring(ini, "verus:primaryaddress", NULL)) { strncpy(player_config.primaryaddress, iniparser_getstring(ini, "verus:primaryaddress", NULL), sizeof(player_config.primaryaddress)); } + #endif if (NULL != iniparser_getstring(ini, "verus:wallet_addr", NULL)) { strncpy(player_config.wallet_addr, iniparser_getstring(ini, "verus:wallet_addr", NULL), sizeof(player_config.wallet_addr)); diff --git a/privatebet/err.c b/privatebet/err.c index 117fb8da..4116bddb 100644 --- a/privatebet/err.c +++ b/privatebet/err.c @@ -186,6 +186,8 @@ const char *bet_err_str(int32_t err_no) return "ID name is NULL"; case ERR_TABLE_UNREGISTERED: return "Table is unregistered with the Dealer"; + case ERR_DUPLICATE_PLAYERID: + return "Player ID has already been added to the table"; default: return "This error is not handled yet..."; } diff --git a/privatebet/err.h b/privatebet/err.h index da35edd0..34a1bb93 100644 --- a/privatebet/err.h +++ b/privatebet/err.h @@ -127,6 +127,7 @@ All the errors that come across in bet are defined here. The error numbers are a #define ERR_NULL_KEY 140 #define ERR_NULL_ID 141 #define ERR_TABLE_UNREGISTERED 142 +#define ERR_DUPLICATE_PLAYERID 143 // clang-format on const char *bet_err_str(int32_t err_no); diff --git a/privatebet/player.c b/privatebet/player.c index 8cd10119..81b5488a 100644 --- a/privatebet/player.c +++ b/privatebet/player.c @@ -142,10 +142,11 @@ int32_t handle_verus_player() return retval; } + #if 0 if (!chips_ismine(player_config.primaryaddress)) { return ERR_ADDR_AUTH; } - + #endif if ((retval = find_table()) != OK) { // TODO:: If retval is ERR_PA_EXISTS, i.e PA exists in the table and the player can rejoin. return retval; diff --git a/privatebet/vdxf.c b/privatebet/vdxf.c index 3af123e2..d2fc139b 100644 --- a/privatebet/vdxf.c +++ b/privatebet/vdxf.c @@ -436,7 +436,7 @@ int32_t get_player_id(int *player_id) dlg_info("%s", cJSON_Print(player_info)); for (int32_t i = 0; i < cJSON_GetArraySize(player_info); i++) { - if (strstr(jstri(player_info, i), player_config.primaryaddress)) { + if (strstr(jstri(player_info, i), player_config.verus_pid)) { strtok(jstri(player_info, i), "_"); strtok(NULL, "_"); *player_id = atoi(strtok(NULL, "_")); @@ -507,7 +507,7 @@ int32_t chose_table() return retval; } - if (retval == ERR_PA_EXISTS) + if (retval == ERR_DUPLICATE_PLAYERID) return retval; dlg_info("Unable to join preconfigured table ::%s, checking for any other available tables...", @@ -530,6 +530,7 @@ int32_t chose_table() } return ERR_NO_TABLES_FOUND; } + int32_t find_table() { int32_t retval = OK; @@ -732,7 +733,7 @@ cJSON *get_available_t_of_d(char *dealer_id) game_state = get_game_state(jstr(t_table_info, "table_id")); if ((game_state == G_TABLE_STARTED) && (!is_table_full(jstr(t_table_info, "table_id"))) && - (!check_if_pa_exists(jstr(t_table_info, "table_id")))) { + (!is_playerid_added(jstr(t_table_info, "table_id")))) { return t_table_info; } return NULL; @@ -762,6 +763,27 @@ bool is_table_full(char *table_id) return false; } +bool is_playerid_added(char *table_id) +{ + int32_t game_state, retval = OK; + char *game_id_str = NULL; + cJSON *t_player_info = NULL, *player_info = NULL; + + game_state = get_game_state(table_id); + if (game_state == G_TABLE_STARTED) { + game_id_str = get_str_from_id_key(table_id, T_GAME_ID_KEY); + + t_player_info = + get_cJSON_from_id_key_vdxfid(table_id, get_key_data_vdxf_id(T_PLAYER_INFO_KEY, game_id_str)); + player_info = jobj(t_player_info, "player_info"); + for (int32_t i = 0; i < cJSON_GetArraySize(player_info); i++) { + if (strstr(jstri(player_info, i), player_config.verus_pid)) + return true; + } + } + return false; +} + int32_t check_if_pa_exists(char *table_id) { int32_t retval = OK; @@ -817,9 +839,9 @@ int32_t check_if_d_t_available(char *dealer_id, char *table_id, cJSON **t_table_ } if ((0 == strcmp(jstr(*t_table_info, "table_id"), table_id))) { - // Check is the Primary Address of the player join request is already been added to the table - if (check_if_pa_exists(table_id)) { - return ERR_PA_EXISTS; + // Check is the verus id of the player in the join request is already been added to the table + if (is_playerid_added(table_id)) { + return ERR_DUPLICATE_PLAYERID; } // Check if the table is started @@ -1118,7 +1140,7 @@ int32_t process_payin_tx_data(char *txid, cJSON *payin_tx_data) */ dlg_error("Reversing the Payin TX due to :: %s", bet_err_str(retval)); double amount = chips_get_balance_on_address_from_tx(get_vdxf_id(CASHIERS_ID_FQN), txid); - cJSON *tx = chips_transfer_funds(amount, jstr(payin_tx_data, "primaryaddress")); + cJSON *tx = chips_transfer_funds(amount, jstr(payin_tx_data, "verus_pid")); dlg_info("Payback TX::%s", cJSON_Print(tx)); return retval; } diff --git a/privatebet/vdxf.h b/privatebet/vdxf.h index 9873734b..6e2ad19f 100644 --- a/privatebet/vdxf.h +++ b/privatebet/vdxf.h @@ -187,4 +187,6 @@ int32_t add_dealer_to_dealers(char *dealer_id); int32_t id_canspendfor(char *id, int32_t full_id, int32_t *err_no); int32_t id_cansignfor(char *id, int32_t full_id, int32_t *err_no); bool is_table_registered(char *table_id, char *dealer_id); +bool is_playerid_added(char *table_id); + #endif From 6e6cafd2654e715158802c6697e25e76aff0393f Mon Sep 17 00:00:00 2001 From: sg777 Date: Tue, 14 May 2024 09:46:47 +0530 Subject: [PATCH 03/13] Check if the node is authorized to reset the ID --- privatebet/bet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/privatebet/bet.c b/privatebet/bet.c index dc31d48e..4df7a071 100644 --- a/privatebet/bet.c +++ b/privatebet/bet.c @@ -554,7 +554,7 @@ static void bet_start(int argc, char **argv) } else if (strcmp(argv[1], "list_tables") == 0) { list_tables(); } else if ((strcmp(argv[1], "reset_id") == 0) && (argc == 3)) { - if (is_id_exists(argv[2], 0)) + if (id_cansignfor(argv[2], 0, &retval)) update_cmm(argv[2], NULL); } else { bet_command_info(); From 4e1941f4836fd00a23a2ab71d5e30d9a7aaf917a Mon Sep 17 00:00:00 2001 From: sg777 Date: Tue, 14 May 2024 10:03:16 +0530 Subject: [PATCH 04/13] Minor bug fix --- privatebet/vdxf.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/privatebet/vdxf.c b/privatebet/vdxf.c index d2fc139b..8c72465f 100644 --- a/privatebet/vdxf.c +++ b/privatebet/vdxf.c @@ -536,18 +536,19 @@ int32_t find_table() int32_t retval = OK; cJSON *t_table_info = NULL, *dealer_ids = NULL; - /* - * Check if the player wallet has suffiecient funds to join the table - */ - if (!check_if_enough_funds_avail(player_t.table_id)) { - return ERR_CHIPS_INSUFFICIENT_FUNDS; - } /* * Check if the configured table meets the preconditions for the player to join the table */ if ((retval = chose_table()) != OK) { return retval; } + /* + * Check if the player wallet has suffiecient funds to join the table chosen + */ + if (!check_if_enough_funds_avail(player_t.table_id)) { + return ERR_CHIPS_INSUFFICIENT_FUNDS; + } + return retval; } From 0276079698d60670389471c512eddbea28696ee6 Mon Sep 17 00:00:00 2001 From: sg777 Date: Tue, 14 May 2024 10:25:05 +0530 Subject: [PATCH 05/13] Minor crash fix --- privatebet/vdxf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/privatebet/vdxf.c b/privatebet/vdxf.c index 8c72465f..049cff19 100644 --- a/privatebet/vdxf.c +++ b/privatebet/vdxf.c @@ -455,8 +455,7 @@ int32_t join_table() data = cJSON_CreateObject(); jaddstr(data, "dealer_id", player_config.dealer_id); jaddstr(data, "table_id", player_config.table_id); - jaddstr(data, "primaryaddress", player_config.primaryaddress); - jaddstr(data, "player_id", player_config.verus_pid); + jaddstr(data, "verus_pid", player_config.verus_pid); op_id = verus_sendcurrency_data(data); if (op_id == NULL) From 8d7b66bd38352fabbd83604cf419498afd3ea8eb Mon Sep 17 00:00:00 2001 From: sg777 Date: Tue, 14 May 2024 10:45:03 +0530 Subject: [PATCH 06/13] Check for duplicate request based on ID --- privatebet/vdxf.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/privatebet/vdxf.c b/privatebet/vdxf.c index 049cff19..37f0a9f6 100644 --- a/privatebet/vdxf.c +++ b/privatebet/vdxf.c @@ -1024,7 +1024,7 @@ int32_t do_payin_tx_checks(char *txid, cJSON *payin_tx_data) { int32_t retval = OK, game_state; double amount = 0; - char pa[128] = { 0 }, *game_id_str = NULL, *table_id = NULL, *dealer_id = NULL, *verus_pid = NULL; + char *game_id_str = NULL, *table_id = NULL, *dealer_id = NULL, *verus_pid = NULL; cJSON *t_player_info = NULL, *player_info = NULL, *t_table_info = NULL; if ((!txid) || (!payin_tx_data)) @@ -1062,9 +1062,7 @@ int32_t do_payin_tx_checks(char *txid, cJSON *payin_tx_data) jdouble(t_table_info, "min_stake"), jdouble(t_table_info, "max_stake")); return ERR_PAYIN_TX_INVALID_FUNDS; } - // TODO:: Check for duplicate request based on ID - #if 0 - // Check for a duplicate join request and duplicate PA, PA should be unique so that ensures a player can occupy atmost one position on the table. + // Check for a duplicate join request and duplicate verus_pid, verus player ID should be unique so that ensures a player can occupy atmost one position on the table. t_player_info = cJSON_CreateObject(); t_player_info = get_cJSON_from_id_key_vdxfid(table_id, get_key_data_vdxf_id(T_PLAYER_INFO_KEY, game_id_str)); if (!t_player_info) { @@ -1073,15 +1071,13 @@ int32_t do_payin_tx_checks(char *txid, cJSON *payin_tx_data) player_info = cJSON_CreateArray(); player_info = cJSON_GetObjectItem(t_player_info, "player_info"); - strncpy(pa, jstr(payin_tx_data, "primaryaddress"), sizeof(pa)); for (int32_t i = 0; i < cJSON_GetArraySize(player_info); i++) { - if ((strstr(jstri(player_info, i), pa)) && (strstr(jstri(player_info, i), txid))) { + if ((strstr(jstri(player_info, i), verus_pid)) && (strstr(jstri(player_info, i), txid))) { return ERR_DUP_PAYIN_UPDATE_REQ; - } else if (strstr(jstri(player_info, i), pa)) { - return ERR_PA_EXISTS; + } else if (strstr(jstri(player_info, i), verus_pid)) { + return ERR_DUPLICATE_PLAYERID; } } - #endif return retval; } From 1e379ff5251c2da8aeedbe2a5f9c3a8ce7969b58 Mon Sep 17 00:00:00 2001 From: sg777 Date: Tue, 14 May 2024 11:09:12 +0530 Subject: [PATCH 07/13] Minor bug fix --- privatebet/vdxf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/privatebet/vdxf.c b/privatebet/vdxf.c index 37f0a9f6..46b0cd51 100644 --- a/privatebet/vdxf.c +++ b/privatebet/vdxf.c @@ -474,9 +474,12 @@ int32_t join_table() char *txid = jstr(jobj(jitem(op_id_info, 0), "result"), "txid"); strcpy(player_config.txid, txid); dlg_info("payin_tx::%s", txid); - retval = check_player_join_status(player_config.table_id, player_config.primaryaddress); + retval = check_player_join_status(player_config.table_id, player_config.verus_pid); if (retval) { - // TODO::This is where TX is success but PA is not added to the table, ideally in these scenarios TX needs to be reversed. + /* + TODO::This is where TX is success verus_pid is not added to the table, in such scenarios if the tx is not reversed, + then using dispute resolution protocol the player need to get the funds back. + */ return retval; } } From 6d592cae49315a468bc3c4a1fc49b7953980a19b Mon Sep 17 00:00:00 2001 From: sg777 Date: Tue, 14 May 2024 17:15:38 +0530 Subject: [PATCH 08/13] Checking player join status based on using player verus ID --- privatebet/err.c | 2 ++ privatebet/err.h | 1 + privatebet/vdxf.c | 40 ++++++++++++++++++---------------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/privatebet/err.c b/privatebet/err.c index 4116bddb..69a63c40 100644 --- a/privatebet/err.c +++ b/privatebet/err.c @@ -188,6 +188,8 @@ const char *bet_err_str(int32_t err_no) return "Table is unregistered with the Dealer"; case ERR_DUPLICATE_PLAYERID: return "Player ID has already been added to the table"; + case ERR_PLAYER_NOT_ADDED: + return "Player ID hasn't added to the table"; default: return "This error is not handled yet..."; } diff --git a/privatebet/err.h b/privatebet/err.h index 34a1bb93..5112183f 100644 --- a/privatebet/err.h +++ b/privatebet/err.h @@ -128,6 +128,7 @@ All the errors that come across in bet are defined here. The error numbers are a #define ERR_NULL_ID 141 #define ERR_TABLE_UNREGISTERED 142 #define ERR_DUPLICATE_PLAYERID 143 +#define ERR_PLAYER_NOT_ADDED 144 // clang-format on const char *bet_err_str(int32_t err_no); diff --git a/privatebet/vdxf.c b/privatebet/vdxf.c index 46b0cd51..35987a87 100644 --- a/privatebet/vdxf.c +++ b/privatebet/vdxf.c @@ -577,19 +577,21 @@ bool is_id_exists(char *id, int16_t full_id) return id_exists; } -int32_t check_player_join_status(char *table_id, char *pa) +int32_t check_player_join_status(char *table_id, char *verus_pid) { - int32_t block_count = 0, retval = ERR_PA_NOT_ADDED_TO_TABLE; + int32_t block_count = 0, retval = ERR_PLAYER_NOT_ADDED; int32_t block_wait_time = 5; //This is the wait time in number of blocks upto which player can look for its table joining update block_count = chips_get_block_count() + block_wait_time; do { - cJSON *pa_arr = cJSON_CreateArray(); - pa_arr = get_primaryaddresses(table_id, 0); - for (int32_t i = 0; i < cJSON_GetArraySize(pa_arr); i++) { - if (0 == strcmp(jstri(pa_arr, i), pa)) + cJSON *t_player_info = get_t_player_info(table_id); + cJSON *player_info = jobj(t_player_info, "player_info"); + dlg_info("t_player_info :: %s", cJSON_Print(t_player_info)); + for (int32_t i = 0; (player_info) && (i < cJSON_GetArraySize(player_info)); i++) { + if (strstr(jstri(player_info, i), player_config.verus_pid)) { return OK; + } } sleep(2); } while (chips_get_block_count() <= block_count); @@ -1003,23 +1005,17 @@ cJSON *update_cmm_from_id_key_data_cJSON(char *id, char *key, cJSON *data, bool cJSON *get_t_player_info(char *table_id) { - cJSON *cmm_t_player_info = NULL, *t_player_info = NULL, *cmm = NULL; - char *hexstr = NULL, *t_player_info_str = NULL; - - cmm = cJSON_CreateObject(); - cmm = get_cmm(table_id, 0); - if (cmm) { - cmm_t_player_info = cJSON_CreateObject(); - cmm_t_player_info = cJSON_GetObjectItem(cmm, get_vdxf_id(T_PLAYER_INFO_KEY)); - if (cmm_t_player_info) { - hexstr = jstr(cJSON_GetArrayItem(cmm_t_player_info, 0), get_vdxf_id(STRING_VDXF_ID)); - t_player_info_str = calloc(1, strlen(hexstr)); - hexstr_to_str(hexstr, t_player_info_str); - t_player_info = cJSON_CreateObject(); - t_player_info = cJSON_Parse(t_player_info_str); - } + + int32_t game_state; + char *game_id_str = NULL; + cJSON *t_player_info = NULL; + + game_state = get_game_state(table_id); + if (game_state == G_TABLE_STARTED) { + game_id_str = get_str_from_id_key(table_id, T_GAME_ID_KEY); + t_player_info = + get_cJSON_from_id_key_vdxfid(table_id, get_key_data_vdxf_id(T_PLAYER_INFO_KEY, game_id_str)); } - free(t_player_info_str); return t_player_info; } From e8e272b80f423708c1617a20e94cd05166e67b5b Mon Sep 17 00:00:00 2001 From: sg777 Date: Wed, 15 May 2024 05:18:26 +0530 Subject: [PATCH 09/13] Removing the dead code snippets relate to primaryaddress --- privatebet/bet.h | 1 - privatebet/config.c | 6 ------ privatebet/config/verus_player.ini | 1 - privatebet/player.c | 5 ----- privatebet/vdxf.c | 14 ++------------ privatebet/vdxf.h | 2 +- 6 files changed, 3 insertions(+), 26 deletions(-) diff --git a/privatebet/bet.h b/privatebet/bet.h index 9ce8c50d..ef6e02a5 100644 --- a/privatebet/bet.h +++ b/privatebet/bet.h @@ -249,7 +249,6 @@ struct verus_player_config { int32_t player_id; char dealer_id[16]; char table_id[16]; - char primaryaddress[128]; char wallet_addr[64]; char txid[128]; char verus_pid[128]; diff --git a/privatebet/config.c b/privatebet/config.c index 141940df..efd9050c 100644 --- a/privatebet/config.c +++ b/privatebet/config.c @@ -358,12 +358,6 @@ int32_t bet_parse_verus_player() strncpy(player_config.table_id, iniparser_getstring(ini, "verus:table_id", NULL), sizeof(player_config.table_id)); } - #if 0 - if (NULL != iniparser_getstring(ini, "verus:primaryaddress", NULL)) { - strncpy(player_config.primaryaddress, iniparser_getstring(ini, "verus:primaryaddress", NULL), - sizeof(player_config.primaryaddress)); - } - #endif if (NULL != iniparser_getstring(ini, "verus:wallet_addr", NULL)) { strncpy(player_config.wallet_addr, iniparser_getstring(ini, "verus:wallet_addr", NULL), sizeof(player_config.wallet_addr)); diff --git a/privatebet/config/verus_player.ini b/privatebet/config/verus_player.ini index b98e9108..4a5e1e03 100644 --- a/privatebet/config/verus_player.ini +++ b/privatebet/config/verus_player.ini @@ -1,6 +1,5 @@ [verus] dealer_id = "sg777_d" #The player specifically looks if any dealers with this name exists in the available dealer names and prefers that to join, else atm the player picks any one dealer that is available. table_id = "sg777_t" #If this set, then player looks to join the table with this specific name which is hosted by the dealer it is set in dealer_id and if no dealer_id is set then the player scan through all the dealers and tables available and joins if any table with this name exists, else the player just picks any one table and joins. -primaryaddress = "RUDCNptNJZrzFErgRXgPcfEcWXdY7Rn7x2" #This is the address owned by the player, the cashiers adds this address as the primaryaddress to the corresponding table_id. wallet_addr = "*" #This is the player registered address from which the player can spend funds from, the default value is *. player_id = "p1" #This is the verus player ID, to which player updates the game info, so this ID must be signable and spendable from the node in which bet player node is running. diff --git a/privatebet/player.c b/privatebet/player.c index 81b5488a..bae23ffa 100644 --- a/privatebet/player.c +++ b/privatebet/player.c @@ -142,11 +142,6 @@ int32_t handle_verus_player() return retval; } - #if 0 - if (!chips_ismine(player_config.primaryaddress)) { - return ERR_ADDR_AUTH; - } - #endif if ((retval = find_table()) != OK) { // TODO:: If retval is ERR_PA_EXISTS, i.e PA exists in the table and the player can rejoin. return retval; diff --git a/privatebet/vdxf.c b/privatebet/vdxf.c index 35987a87..c85f133b 100644 --- a/privatebet/vdxf.c +++ b/privatebet/vdxf.c @@ -224,10 +224,6 @@ cJSON *update_primaryaddresses(char *id, cJSON *primaryaddress) argv = bet_copy_args(argc, verus_chips_cli, "updateidentity", params); argjson = update_with_retry(argc, argv); -#if 0 - argjson = cJSON_CreateObject(); - make_command(argc, argv, &argjson); -#endif end: bet_dealloc_args(argc, &argv); @@ -789,7 +785,7 @@ bool is_playerid_added(char *table_id) return false; } -int32_t check_if_pa_exists(char *table_id) +int32_t check_if_pa_exists(char *table_id, char *pa) { int32_t retval = OK; cJSON *pa_arr = NULL; @@ -798,7 +794,7 @@ int32_t check_if_pa_exists(char *table_id) pa_arr = get_primaryaddresses(table_id, 0); if (pa_arr) { for (int32_t i = 0; i < cJSON_GetArraySize(pa_arr); i++) { - if (0 == strcmp(jstri(pa_arr, i), player_config.primaryaddress)) { + if (0 == strcmp(jstri(pa_arr, i), pa)) { return !retval; } } @@ -1158,12 +1154,6 @@ int32_t process_payin_tx_data(char *txid, cJSON *payin_tx_data) updated_t_player_info, true); dlg_info("%s", cJSON_Print(out)); - #if 0 - //Add the players primary address to the list of the primary addresses of the table id so that player can able to perform the updates to the table ID. - out = append_pa_to_cmm(jstr(payin_tx_data, "table_id"), jstr(payin_tx_data, "primaryaddress")); - dlg_info("%s", cJSON_Print(out)); - #endif - return retval; } diff --git a/privatebet/vdxf.h b/privatebet/vdxf.h index 6e2ad19f..6f46affe 100644 --- a/privatebet/vdxf.h +++ b/privatebet/vdxf.h @@ -165,7 +165,7 @@ struct table *decode_table_info_from_str(char *str); struct table *decode_table_info(cJSON *dealer_cmm_data); cJSON *get_available_t_of_d(char *dealer_id); bool is_table_full(char *table_id); -int32_t check_if_pa_exists(char *table_id); +int32_t check_if_pa_exists(char *table_id, char *pa); bool check_if_enough_funds_avail(char *table_id); int32_t check_if_d_t_available(char *dealer_id, char *table_id, cJSON **t_table_info); char *get_str_from_id_key(char *id, char *key); From c7b7552de738fe618fa170d5be00c9608438de6a Mon Sep 17 00:00:00 2001 From: sg777 Date: Wed, 15 May 2024 05:42:39 +0530 Subject: [PATCH 10/13] Updating players deck info at PLAYER_DECK_KEY on players ID --- privatebet/player.c | 6 +++--- privatebet/vdxf.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/privatebet/player.c b/privatebet/player.c index bae23ffa..13e79388 100644 --- a/privatebet/player.c +++ b/privatebet/player.c @@ -42,10 +42,10 @@ int32_t player_init_deck() } dlg_info("player_key::%s", - get_key_data_vdxf_id(all_t_p_keys[p_deck_info.player_id - 1], bits256_str(str, p_deck_info.game_id))); + get_key_data_vdxf_id(PLAYER_DECK_KEY, bits256_str(str, p_deck_info.game_id))); - cJSON *out = append_cmm_from_id_key_data_cJSON(player_config.table_id, - get_key_data_vdxf_id(all_t_p_keys[p_deck_info.player_id - 1], + cJSON *out = append_cmm_from_id_key_data_cJSON(player_config.verus_pid, + get_key_data_vdxf_id(PLAYER_DECK_KEY, bits256_str(str, p_deck_info.game_id)), player_deck, true); dlg_info("%s", cJSON_Print(out)); diff --git a/privatebet/vdxf.h b/privatebet/vdxf.h index 6f46affe..1d635bae 100644 --- a/privatebet/vdxf.h +++ b/privatebet/vdxf.h @@ -74,6 +74,8 @@ key is represented as chips.vrsc::poker.cashiers. #define T_B_DECK_BV_KEY_NAME "t_b_deck_bv" #define T_GAME_INFO_KEY_NAME "t_game_info" +#define PLAYER_DECK_KEY "chips.vrsc::poker.player_deck" + /* Datatypes used -------------- From bc8951c38fbe1bcb9e034157c3a12e8a28c624a5 Mon Sep 17 00:00:00 2001 From: sg777 Date: Wed, 15 May 2024 02:24:17 +0200 Subject: [PATCH 11/13] Running clang --- privatebet/client.c | 4 ++-- privatebet/dealer.c | 2 +- privatebet/host.c | 4 ++-- privatebet/player.c | 10 ++++------ privatebet/poker.c | 4 ++-- privatebet/storage.c | 8 ++++---- privatebet/vdxf.c | 11 +++++------ 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/privatebet/client.c b/privatebet/client.c index e31cfa1e..274ca5ce 100644 --- a/privatebet/client.c +++ b/privatebet/client.c @@ -1947,8 +1947,8 @@ void rest_push_cards(struct lws *wsi, cJSON *argjson, int32_t this_playerID) void rest_display_cards(cJSON *argjson, int32_t this_playerID) { char *suit[NSUITS] = { "clubs", "diamonds", "hearts", "spades" }; - char *face[NFACES] = { "two", "three", "four", "five", "six", "seven", "eight", - "nine", "ten", "jack", "queen", "king", "ace" }; + char *face[NFACES] = { "two", "three", "four", "five", "six", "seven", "eight", + "nine", "ten", "jack", "queen", "king", "ace" }; char action_str[8][100] = { "", "small_blind", "big_blind", "check", "raise", "call", "allin", "fold" }; cJSON *actions = NULL; diff --git a/privatebet/dealer.c b/privatebet/dealer.c index 77bda629..2d6032a5 100644 --- a/privatebet/dealer.c +++ b/privatebet/dealer.c @@ -11,7 +11,7 @@ struct d_deck_info_struct d_deck_info; struct game_meta_info_struct game_meta_info; -char all_t_d_p_keys[all_t_d_p_keys_no][128] = { T_D_DECK_KEY, T_D_P1_DECK_KEY, T_D_P2_DECK_KEY, T_D_P3_DECK_KEY, +char all_t_d_p_keys[all_t_d_p_keys_no][128] = { T_D_DECK_KEY, T_D_P1_DECK_KEY, T_D_P2_DECK_KEY, T_D_P3_DECK_KEY, T_D_P4_DECK_KEY, T_D_P5_DECK_KEY, T_D_P6_DECK_KEY, T_D_P7_DECK_KEY, T_D_P8_DECK_KEY, T_D_P9_DECK_KEY }; diff --git a/privatebet/host.c b/privatebet/host.c index 190812c7..b6996e86 100644 --- a/privatebet/host.c +++ b/privatebet/host.c @@ -63,8 +63,8 @@ int no_of_rand_str = 0; int32_t invoiceID; char *suit[NSUITS] = { "clubs", "diamonds", "hearts", "spades" }; -char *face[NFACES] = { "two", "three", "four", "five", "six", "seven", "eight", - "nine", "ten", "jack", "queen", "king", "ace" }; +char *face[NFACES] = { "two", "three", "four", "five", "six", "seven", "eight", + "nine", "ten", "jack", "queen", "king", "ace" }; struct privatebet_info *bet_dcv = NULL; struct privatebet_vars *dcv_vars = NULL; diff --git a/privatebet/player.c b/privatebet/player.c index 13e79388..4c9ecd64 100644 --- a/privatebet/player.c +++ b/privatebet/player.c @@ -41,13 +41,11 @@ int32_t player_init_deck() jaddistr(cjson_player_cards, bits256_str(str, p_deck_info.player_r[i].prod)); } - dlg_info("player_key::%s", - get_key_data_vdxf_id(PLAYER_DECK_KEY, bits256_str(str, p_deck_info.game_id))); + dlg_info("player_key::%s", get_key_data_vdxf_id(PLAYER_DECK_KEY, bits256_str(str, p_deck_info.game_id))); - cJSON *out = append_cmm_from_id_key_data_cJSON(player_config.verus_pid, - get_key_data_vdxf_id(PLAYER_DECK_KEY, - bits256_str(str, p_deck_info.game_id)), - player_deck, true); + cJSON *out = append_cmm_from_id_key_data_cJSON( + player_config.verus_pid, get_key_data_vdxf_id(PLAYER_DECK_KEY, bits256_str(str, p_deck_info.game_id)), + player_deck, true); dlg_info("%s", cJSON_Print(out)); return retval; diff --git a/privatebet/poker.c b/privatebet/poker.c index 687ca40f..80e9ac18 100644 --- a/privatebet/poker.c +++ b/privatebet/poker.c @@ -54,8 +54,8 @@ static char *handstrs[16] = { "high card", "err", "err", "err" }; -static char *kickerstrs[16] = { "", "kickers", "kicker", "kickers", "high", "high", "full of", "kicker", - "high", "err", "err", "err", "err", "err", "err", "err" }; +static char *kickerstrs[16] = { "", "kickers", "kicker", "kickers", "high", "high", "full of", "kicker", + "high", "err", "err", "err", "err", "err", "err", "err" }; static u32 CardValue[52] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; diff --git a/privatebet/storage.c b/privatebet/storage.c index 2c7b380c..f4a2d753 100644 --- a/privatebet/storage.c +++ b/privatebet/storage.c @@ -14,10 +14,10 @@ char *db_name = NULL; -const char *table_names[no_of_tables] = { "dcv_tx_mapping", "player_tx_mapping", "cashier_tx_mapping", - "c_tx_addr_mapping", "dcv_game_state", "player_game_state", - "cashier_game_state", "dealers_info", "game_info", - "sc_games_info", "player_deck_info", "dealer_deck_info", +const char *table_names[no_of_tables] = { "dcv_tx_mapping", "player_tx_mapping", "cashier_tx_mapping", + "c_tx_addr_mapping", "dcv_game_state", "player_game_state", + "cashier_game_state", "dealers_info", "game_info", + "sc_games_info", "player_deck_info", "dealer_deck_info", "cashier_deck_info" }; const char *schemas[no_of_tables] = { diff --git a/privatebet/vdxf.c b/privatebet/vdxf.c index c85f133b..85cf2c3a 100644 --- a/privatebet/vdxf.c +++ b/privatebet/vdxf.c @@ -546,7 +546,7 @@ int32_t find_table() if (!check_if_enough_funds_avail(player_t.table_id)) { return ERR_CHIPS_INSUFFICIENT_FUNDS; } - + return retval; } @@ -769,7 +769,7 @@ bool is_playerid_added(char *table_id) int32_t game_state, retval = OK; char *game_id_str = NULL; cJSON *t_player_info = NULL, *player_info = NULL; - + game_state = get_game_state(table_id); if (game_state == G_TABLE_STARTED) { game_id_str = get_str_from_id_key(table_id, T_GAME_ID_KEY); @@ -778,7 +778,7 @@ bool is_playerid_added(char *table_id) get_cJSON_from_id_key_vdxfid(table_id, get_key_data_vdxf_id(T_PLAYER_INFO_KEY, game_id_str)); player_info = jobj(t_player_info, "player_info"); for (int32_t i = 0; i < cJSON_GetArraySize(player_info); i++) { - if (strstr(jstri(player_info, i), player_config.verus_pid)) + if (strstr(jstri(player_info, i), player_config.verus_pid)) return true; } } @@ -1001,11 +1001,10 @@ cJSON *update_cmm_from_id_key_data_cJSON(char *id, char *key, cJSON *data, bool cJSON *get_t_player_info(char *table_id) { - int32_t game_state; char *game_id_str = NULL; cJSON *t_player_info = NULL; - + game_state = get_game_state(table_id); if (game_state == G_TABLE_STARTED) { game_id_str = get_str_from_id_key(table_id, T_GAME_ID_KEY); @@ -1099,7 +1098,7 @@ static cJSON *compute_updated_t_player_info(char *txid, cJSON *payin_tx_data) if (!player_info) { dlg_error("Error with data on Key :: %s", T_PLAYER_INFO_KEY); return NULL; - } + } } num_players++; sprintf(pa_tx_id, "%s_%s_%d", jstr(payin_tx_data, "verus_pid"), txid, num_players); From 5a928947b2f348d22092aea3eb9a902a5d16701b Mon Sep 17 00:00:00 2001 From: sg777 Date: Wed, 15 May 2024 08:06:28 +0530 Subject: [PATCH 12/13] Updating game id at T_GAME_ID_KEY on player verus ID --- privatebet/player.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/privatebet/player.c b/privatebet/player.c index 4c9ecd64..d28b0f86 100644 --- a/privatebet/player.c +++ b/privatebet/player.c @@ -40,10 +40,12 @@ int32_t player_init_deck() for (int32_t i = 0; i < CARDS777_MAXCARDS; i++) { jaddistr(cjson_player_cards, bits256_str(str, p_deck_info.player_r[i].prod)); } + + dlg_info("Updating %s key...", T_GAME_ID_KEY); + cJSON *out = append_cmm_from_id_key_data_hex(player_config.verus_pid, T_GAME_ID_KEY, bits256_str(str, p_deck_info.game_id), false); dlg_info("player_key::%s", get_key_data_vdxf_id(PLAYER_DECK_KEY, bits256_str(str, p_deck_info.game_id))); - - cJSON *out = append_cmm_from_id_key_data_cJSON( + out = append_cmm_from_id_key_data_cJSON( player_config.verus_pid, get_key_data_vdxf_id(PLAYER_DECK_KEY, bits256_str(str, p_deck_info.game_id)), player_deck, true); dlg_info("%s", cJSON_Print(out)); From d762ca896fd5040bd0aceaee3e39a1bbf7a19bfc Mon Sep 17 00:00:00 2001 From: sg777 Date: Wed, 15 May 2024 20:03:23 +0530 Subject: [PATCH 13/13] Adding support to parse player_id --- privatebet/player.c | 2 +- privatebet/print.c | 15 +++++++++++++++ privatebet/print.h | 1 + privatebet/vdxf.h | 7 +++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/privatebet/player.c b/privatebet/player.c index d28b0f86..4663a528 100644 --- a/privatebet/player.c +++ b/privatebet/player.c @@ -44,7 +44,7 @@ int32_t player_init_deck() dlg_info("Updating %s key...", T_GAME_ID_KEY); cJSON *out = append_cmm_from_id_key_data_hex(player_config.verus_pid, T_GAME_ID_KEY, bits256_str(str, p_deck_info.game_id), false); - dlg_info("player_key::%s", get_key_data_vdxf_id(PLAYER_DECK_KEY, bits256_str(str, p_deck_info.game_id))); + dlg_info("Updating %s key...", PLAYER_DECK_KEY); out = append_cmm_from_id_key_data_cJSON( player_config.verus_pid, get_key_data_vdxf_id(PLAYER_DECK_KEY, bits256_str(str, p_deck_info.game_id)), player_deck, true); diff --git a/privatebet/print.c b/privatebet/print.c index 88481c1c..7b0e378a 100644 --- a/privatebet/print.c +++ b/privatebet/print.c @@ -120,6 +120,19 @@ void print_table_id(char *id) } } +void print_player_id(char *id) +{ + char *game_id = NULL; + + game_id = get_str_from_id_key(id, get_vdxf_id(T_GAME_ID_KEY)); + if (game_id) { + cJSON *player_deck = NULL; + player_deck = get_cJSON_from_id_key_vdxfid(id, get_key_data_vdxf_id(PLAYER_DECK_KEY, game_id)); + if(player_deck) + dlg_info("%s :: %s", PLAYER_DECK_KEY, cJSON_Print(player_deck)); + } +} + void print_table_key_info(int argc, char **argv) { char *game_id_str = NULL, *key_name = NULL; @@ -145,6 +158,8 @@ void print_id_info(int argc, char **argv) print_table_id(argv[2]); } else if ((strcmp(argv[3], "d") == 0) || (strcmp(argv[3], "dealer") == 0)) { print_dealer_id(argv[2]); + } else if ((strcmp(argv[3], "p") == 0) || (strcmp(argv[3], "player") == 0)) { + print_player_id(argv[2]); } else if (strcmp(argv[3], "dealers") == 0) { print_dealers_id(argv[2]); } else if (strcmp(argv[3], "cashiers") == 0) { diff --git a/privatebet/print.h b/privatebet/print.h index 049f8f70..8923f7f0 100644 --- a/privatebet/print.h +++ b/privatebet/print.h @@ -5,6 +5,7 @@ void print_cashiers_id(char *id); void print_dealers_id(char *id); void print_dealer_id(char *id); void print_table_id(char *id); +void print_player_id(char *id); void print_table_key_info(int argc, char **argv); void print_id_info(int argc, char **argv); void print_vdxf_info(int argc, char **argv); diff --git a/privatebet/vdxf.h b/privatebet/vdxf.h index 1d635bae..7d6409b7 100644 --- a/privatebet/vdxf.h +++ b/privatebet/vdxf.h @@ -74,6 +74,13 @@ key is represented as chips.vrsc::poker.cashiers. #define T_B_DECK_BV_KEY_NAME "t_b_deck_bv" #define T_GAME_INFO_KEY_NAME "t_game_info" +/* +* player_deck { +* id: Players ID assigned by dealer, this is fecthed using get_playerid after player join. +* pubkey: This is players pubkey pG +* cardinfo:Array of card pubkeys r1G, r2G, ..., r52G +* } +*/ #define PLAYER_DECK_KEY "chips.vrsc::poker.player_deck" /*