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(); 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/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/config.c b/privatebet/config.c index 90eb512c..efd9050c 100644 --- a/privatebet/config.c +++ b/privatebet/config.c @@ -358,10 +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 (NULL != iniparser_getstring(ini, "verus:primaryaddress", NULL)) { - strncpy(player_config.primaryaddress, iniparser_getstring(ini, "verus:primaryaddress", NULL), - sizeof(player_config.primaryaddress)); - } 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/dealer.c b/privatebet/dealer.c index e466ecf6..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 }; @@ -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/err.c b/privatebet/err.c index 117fb8da..69a63c40 100644 --- a/privatebet/err.c +++ b/privatebet/err.c @@ -186,6 +186,10 @@ 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"; + 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 da35edd0..5112183f 100644 --- a/privatebet/err.h +++ b/privatebet/err.h @@ -127,6 +127,8 @@ 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 +#define ERR_PLAYER_NOT_ADDED 144 // clang-format on const char *bet_err_str(int32_t err_no); 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 8cd10119..4663a528 100644 --- a/privatebet/player.c +++ b/privatebet/player.c @@ -40,14 +40,14 @@ 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("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))); - - 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], - bits256_str(str, p_deck_info.game_id)), - player_deck, true); + + 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("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); dlg_info("%s", cJSON_Print(out)); return retval; @@ -142,10 +142,6 @@ int32_t handle_verus_player() return retval; } - if (!chips_ismine(player_config.primaryaddress)) { - return ERR_ADDR_AUTH; - } - 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/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/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/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 bad69fc3..85cf2c3a 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); @@ -436,7 +432,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, "_")); @@ -455,8 +451,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) @@ -475,9 +470,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; } } @@ -507,7 +505,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 +528,7 @@ int32_t chose_table() } return ERR_NO_TABLES_FOUND; } + int32_t find_table() { int32_t retval = OK; @@ -542,11 +541,12 @@ int32_t find_table() return retval; } /* - * Check if the player wallet has suffiecient funds to join the table + * 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; } @@ -573,19 +573,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); @@ -732,7 +734,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,7 +764,28 @@ bool is_table_full(char *table_id) return false; } -int32_t check_if_pa_exists(char *table_id) +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, char *pa) { int32_t retval = OK; cJSON *pa_arr = NULL; @@ -771,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; } } @@ -817,9 +840,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 @@ -978,23 +1001,16 @@ 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; + int32_t game_state; + char *game_id_str = NULL; + cJSON *t_player_info = 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); - } + 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; } @@ -1002,7 +1018,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 *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 +1027,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,8 +1056,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; } - - // 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) { @@ -1049,19 +1065,19 @@ 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; } } 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 +1095,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(); @@ -1112,7 +1130,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; } @@ -1135,10 +1153,6 @@ int32_t process_payin_tx_data(char *txid, cJSON *payin_tx_data) updated_t_player_info, true); dlg_info("%s", cJSON_Print(out)); - //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)); - return retval; } @@ -1172,6 +1186,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..7d6409b7 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" @@ -68,6 +74,15 @@ 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" + /* Datatypes used -------------- @@ -108,7 +123,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 @@ -156,7 +174,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); @@ -178,4 +196,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