diff --git a/dap-sdk b/dap-sdk index fb43e24152da3868bafacf5c1b41f4b1b70d3b3c..0e5303fbfc0a646d157117d451ac3e98e5a5752d 160000 --- a/dap-sdk +++ b/dap-sdk @@ -1 +1 @@ -Subproject commit fb43e24152da3868bafacf5c1b41f4b1b70d3b3c +Subproject commit 0e5303fbfc0a646d157117d451ac3e98e5a5752d diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c index 611790de845589be9857ab5be6d0027be41dedb5..c7f2dcfab8c58e966f20c2352c79929d8913642d 100644 --- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c +++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c @@ -3126,11 +3126,11 @@ static void s_print_emergency_validators(json_object *json_obj_out, dap_list_t * for (dap_list_t *it = a_validator_addrs; it; it = it->next, i++) { json_object *json_obj_validator = json_object_new_object(); dap_chain_addr_t *l_addr = it->data; - json_object_object_add(json_obj_validator,"#", json_object_new_uint64(i)); - json_object_object_add(json_obj_validator,"addr hash", json_object_new_string(dap_chain_hash_fast_to_str_static(&l_addr->data.hash_fast))); + json_object_object_add(json_obj_validator,"number", json_object_new_uint64(i)); + json_object_object_add(json_obj_validator,"addr_hash", json_object_new_string(dap_chain_hash_fast_to_str_static(&l_addr->data.hash_fast))); json_object_array_add(json_arr_validators, json_obj_validator); } - json_object_object_add(json_obj_out,"Current emergency validators list", json_arr_validators); + json_object_object_add(json_obj_out,"current_emergency_validators_list", json_arr_validators); } /** @@ -3242,7 +3242,7 @@ static int s_cli_esbocs(int a_argc, char **a_argv, void **a_str_reply) if (l_decree && (l_decree_hash_str = s_esbocs_decree_put(l_decree, l_chain_net))) { json_object * json_obj_out = json_object_new_object(); json_object_object_add(json_obj_out,"status", json_object_new_string("Minimum validators count has been set")); - json_object_object_add(json_obj_out,"decree hash", json_object_new_string(l_decree_hash_str)); + json_object_object_add(json_obj_out,"decree_hash", json_object_new_string(l_decree_hash_str)); json_object_array_add(*a_json_arr_reply, json_obj_out); DAP_DEL_MULTY(l_decree, l_decree_hash_str); } else { @@ -3252,7 +3252,7 @@ static int s_cli_esbocs(int a_argc, char **a_argv, void **a_str_reply) } } else{ json_object * json_obj_out = json_object_new_object(); - json_object_object_add(json_obj_out,"Minimum validators count", json_object_new_uint64(l_esbocs_pvt->min_validators_count)); + json_object_object_add(json_obj_out,"minimum_validators_count", json_object_new_uint64(l_esbocs_pvt->min_validators_count)); json_object_array_add(*a_json_arr_reply, json_obj_out); } } break; @@ -3263,8 +3263,8 @@ static int s_cli_esbocs(int a_argc, char **a_argv, void **a_str_reply) dap_chain_datum_decree_t *l_decree = s_esbocs_decree_set_signs_check(l_chain_net, l_chain, l_subcommand_add, l_poa_cert); char *l_decree_hash_str = NULL; if (l_decree && (l_decree_hash_str = s_esbocs_decree_put(l_decree, l_chain_net))) { - json_object_object_add(json_obj_out,"Checking signs structure has been", l_subcommand_add ? json_object_new_string("enabled") : json_object_new_string("disabled")); - json_object_object_add(json_obj_out,"Decree hash", json_object_new_string(l_decree_hash_str)); + json_object_object_add(json_obj_out,"checking_signs_status", l_subcommand_add ? json_object_new_string("enabled") : json_object_new_string("disabled")); + json_object_object_add(json_obj_out,"decree_hash", json_object_new_string(l_decree_hash_str)); json_object_array_add(*a_json_arr_reply, json_obj_out); DAP_DEL_MULTY(l_decree, l_decree_hash_str); } else { @@ -3274,7 +3274,7 @@ static int s_cli_esbocs(int a_argc, char **a_argv, void **a_str_reply) return -DAP_CHAIN_NODE_CLI_COM_ESBOCS_CHECKING_ERR; } } else{ - json_object_object_add(json_obj_out,"Checking signs structure is", l_esbocs_pvt->check_signs_structure ? json_object_new_string("enabled") : json_object_new_string("disabled")); + json_object_object_add(json_obj_out,"checking_signs_status", l_esbocs_pvt->check_signs_structure ? json_object_new_string("enabled") : json_object_new_string("disabled")); json_object_array_add(*a_json_arr_reply, json_obj_out); } } break; @@ -3300,9 +3300,9 @@ static int s_cli_esbocs(int a_argc, char **a_argv, void **a_str_reply) char *l_decree_hash_str = NULL; if (l_decree && (l_decree_hash_str = s_esbocs_decree_put(l_decree, l_chain_net))) { json_object * json_obj_out = json_object_new_object(); - json_object_object_add(json_obj_out,"Emergency validator", json_object_new_string(dap_chain_hash_fast_to_str_static(&l_pkey_hash))); + json_object_object_add(json_obj_out,"emergency_validator", json_object_new_string(dap_chain_hash_fast_to_str_static(&l_pkey_hash))); json_object_object_add(json_obj_out,"status", l_subcommand_add ? json_object_new_string("added") : json_object_new_string("deleted")); - json_object_object_add(json_obj_out,"Decree hash", json_object_new_string(l_decree_hash_str)); + json_object_object_add(json_obj_out,"decree_hash", json_object_new_string(l_decree_hash_str)); json_object_array_add(*a_json_arr_reply, json_obj_out); DAP_DEL_MULTY(l_decree, l_decree_hash_str); } else { diff --git a/modules/datum/dap_chain_datum.c b/modules/datum/dap_chain_datum.c index c72b1a8ccc668172ef8d89d03686ce85b0547032..1ad88cad189775d8ea48b82c35fc171c171de822 100644 --- a/modules/datum/dap_chain_datum.c +++ b/modules/datum/dap_chain_datum.c @@ -239,11 +239,11 @@ bool dap_chain_datum_dump_tx_json(json_object* a_json_arr_reply, json_object* json_arr_items = json_object_new_array(); dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, a_datum->header.ts_created); l_is_first ? - json_object_object_add(json_obj_out, "first transaction", json_object_new_string("emit")): - json_object_object_add(json_obj_out, "first transaction", json_object_new_string("")); + json_object_object_add(json_obj_out, "first_transaction", json_object_new_string("emit")): + json_object_object_add(json_obj_out, "first_transaction", json_object_new_string("")); json_object_object_add(json_obj_out, "hash", json_object_new_string(l_hash_str)); - json_object_object_add(json_obj_out, "tx created", json_object_new_string(l_tmp_buf)); - json_object_object_add(json_obj_out, "token ticker", a_ticker ? json_object_new_string(a_ticker) : json_object_new_string("")); + json_object_object_add(json_obj_out, "tx_created", json_object_new_string(l_tmp_buf)); + json_object_object_add(json_obj_out, "token_ticker", a_ticker ? json_object_new_string(a_ticker) : json_object_new_string("")); //json_object_array_add(json_arr_items, json_obj_tx); dap_hash_fast_t l_hash_tmp = { }; @@ -256,25 +256,25 @@ bool dap_chain_datum_dump_tx_json(json_object* a_json_arr_reply, l_hash_str = !dap_hash_fast_is_blank(&l_hash_tmp) ? dap_strcmp(a_hash_out_type, "hex") ? dap_enc_base58_encode_hash_to_str_static(&l_hash_tmp) : dap_chain_hash_fast_to_str_static(&l_hash_tmp) : "BLANK"; - json_object_object_add(json_obj_item,"item type", json_object_new_string("IN")); - json_object_object_add(json_obj_item,"Tx prev hash", json_object_new_string(l_hash_str)); - json_object_object_add(json_obj_item,"Tx out prev idx", json_object_new_uint64(((dap_chain_tx_in_t*)item)->header.tx_out_prev_idx)); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("IN")); + json_object_object_add(json_obj_item,"tx_prev_hash", json_object_new_string(l_hash_str)); + json_object_object_add(json_obj_item,"tx_out_prev_idx", json_object_new_uint64(((dap_chain_tx_in_t*)item)->header.tx_out_prev_idx)); break; case TX_ITEM_TYPE_OUT_OLD: { const char *l_value_str = dap_uint256_to_char( dap_chain_uint256_from(((dap_chain_tx_out_old_t*)item)->header.value), NULL ); - json_object_object_add(json_obj_item,"item type", json_object_new_string("OUT OLD")); - json_object_object_add(json_obj_item,"Value", json_object_new_string(l_value_str)); - json_object_object_add(json_obj_item,"Address", json_object_new_string(dap_chain_addr_to_str_static(&((dap_chain_tx_out_old_t*)item)->addr))); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("OUT OLD")); + json_object_object_add(json_obj_item,"value", json_object_new_string(l_value_str)); + json_object_object_add(json_obj_item,"address", json_object_new_string(dap_chain_addr_to_str_static(&((dap_chain_tx_out_old_t*)item)->addr))); } break; case TX_ITEM_TYPE_OUT: { // 256 const char *l_coins_str, *l_value_str = dap_uint256_to_char(((dap_chain_tx_out_t*)item)->header.value, &l_coins_str), *l_addr_str = dap_chain_addr_to_str_static(&((dap_chain_tx_out_t*)item)->addr); - json_object_object_add(json_obj_item,"item type", json_object_new_string("OUT")); - json_object_object_add(json_obj_item,"Coins", json_object_new_string(l_coins_str)); - json_object_object_add(json_obj_item,"Value", json_object_new_string(l_value_str)); - json_object_object_add(json_obj_item,"Address", json_object_new_string(l_addr_str)); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("OUT")); + json_object_object_add(json_obj_item,"coins", json_object_new_string(l_coins_str)); + json_object_object_add(json_obj_item,"value", json_object_new_string(l_value_str)); + json_object_object_add(json_obj_item,"address", json_object_new_string(l_addr_str)); } break; case TX_ITEM_TYPE_IN_EMS: { char l_tmp_buff[70]; @@ -282,7 +282,7 @@ bool dap_chain_datum_dump_tx_json(json_object* a_json_arr_reply, l_hash_str = dap_strcmp(a_hash_out_type, "hex") ? dap_enc_base58_encode_hash_to_str_static(&l_hash_tmp) : dap_chain_hash_fast_to_str_static(&l_hash_tmp); - json_object_object_add(json_obj_item,"item type", json_object_new_string("IN_EMS")); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("IN_EMS")); json_object_object_add(json_obj_item,"ticker", json_object_new_string(((dap_chain_tx_in_ems_t*)item)->header.ticker)); json_object_object_add(json_obj_item,"token_emission_hash", json_object_new_string(l_hash_str)); snprintf(l_tmp_buff, sizeof(l_tmp_buff), "0x%016"DAP_UINT64_FORMAT_x"",((dap_chain_tx_in_ems_t*)item)->header.token_emission_chain_id.uint64); @@ -294,40 +294,39 @@ bool dap_chain_datum_dump_tx_json(json_object* a_json_arr_reply, l_hash_str = dap_strcmp(a_hash_out_type, "hex") ? dap_enc_base58_encode_hash_to_str_static(&l_hash_tmp) : dap_chain_hash_fast_to_str_static(&l_hash_tmp); - json_object_object_add(json_obj_item,"item type", json_object_new_string("IN_REWARD")); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("IN_REWARD")); json_object_object_add(json_obj_item,"block_hash", json_object_new_string(l_hash_str)); } break; case TX_ITEM_TYPE_SIG: { dap_sign_t *l_sign = dap_chain_datum_tx_item_sig_get_sign((dap_chain_tx_sig_t*)item); - json_object_object_add(json_obj_item,"item type", json_object_new_string("SIG")); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("SIG")); dap_sign_get_information_json(a_json_arr_reply, l_sign, json_obj_item, a_hash_out_type); dap_chain_addr_t l_sender_addr; dap_chain_addr_fill_from_sign(&l_sender_addr, l_sign, a_net_id); - json_object_object_add(json_obj_item,"Sender addr", json_object_new_string(dap_chain_addr_to_str_static(&l_sender_addr))); + json_object_object_add(json_obj_item,"sender_addr", json_object_new_string(dap_chain_addr_to_str_static(&l_sender_addr))); } break; case TX_ITEM_TYPE_RECEIPT: { const char *l_coins_str, *l_value_str = dap_uint256_to_char(((dap_chain_datum_tx_receipt_t*)item)->receipt_info.value_datoshi, &l_coins_str); - json_object_object_add(json_obj_item,"item type", json_object_new_string("RECEIPT")); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("RECEIPT")); json_object_object_add(json_obj_item,"size", json_object_new_uint64(((dap_chain_datum_tx_receipt_t*)item)->size)); - json_object_object_add(json_obj_item,"ext size", json_object_new_uint64(((dap_chain_datum_tx_receipt_t*)item)->exts_size)); + json_object_object_add(json_obj_item,"ext_size", json_object_new_uint64(((dap_chain_datum_tx_receipt_t*)item)->exts_size)); json_object_object_add(json_obj_item,"INFO", json_object_new_string("")); json_object_object_add(json_obj_item,"units", json_object_new_uint64(((dap_chain_datum_tx_receipt_t*)item)->receipt_info.units)); json_object_object_add(json_obj_item,"uid", json_object_new_uint64(((dap_chain_datum_tx_receipt_t*)item)->receipt_info.srv_uid.uint64)); - json_object_object_add(json_obj_item,"units type", json_object_new_string(dap_chain_srv_unit_enum_to_str(((dap_chain_datum_tx_receipt_t*)item)->receipt_info.units_type.enm))); + json_object_object_add(json_obj_item,"units_type", json_object_new_string(dap_chain_srv_unit_enum_to_str(((dap_chain_datum_tx_receipt_t*)item)->receipt_info.units_type.enm))); json_object_object_add(json_obj_item,"coins", json_object_new_string(l_coins_str)); json_object_object_add(json_obj_item,"value", json_object_new_string(l_value_str)); - json_object_object_add(json_obj_item,"Exts",json_object_new_string("")); switch ( ((dap_chain_datum_tx_receipt_t*)item)->exts_size ) { case (sizeof(dap_sign_t) * 2): { dap_sign_t *l_client = (dap_sign_t*)( ((dap_chain_datum_tx_receipt_t*)item)->exts_n_signs + sizeof(dap_sign_t) ); - json_object_object_add(json_obj_item,"Client", json_object_new_string("")); + json_object_object_add(json_obj_item,"sign_inf", json_object_new_string("client")); dap_sign_get_information_json(a_json_arr_reply, l_client, json_obj_item, a_hash_out_type); } case (sizeof(dap_sign_t)): { dap_sign_t *l_provider = (dap_sign_t*)( ((dap_chain_datum_tx_receipt_t*)item)->exts_n_signs ); - json_object_object_add(json_obj_item,"Provider", json_object_new_string("")); + json_object_object_add(json_obj_item,"sign_inf", json_object_new_string("provider")); dap_sign_get_information_json(a_json_arr_reply, l_provider,json_obj_item, a_hash_out_type); break; } @@ -340,35 +339,35 @@ bool dap_chain_datum_dump_tx_json(json_object* a_json_arr_reply, l_hash_str = dap_strcmp(a_hash_out_type, "hex") ? dap_enc_base58_encode_hash_to_str_static(&l_pkey_hash) : dap_chain_hash_fast_to_str_static(&l_pkey_hash); - json_object_object_add(json_obj_item,"item type", json_object_new_string("PKey")); - json_object_object_add(json_obj_item,"PKey", json_object_new_string("")); - json_object_object_add(json_obj_item,"SIG type", json_object_new_string(dap_sign_type_to_str(((dap_chain_tx_pkey_t*)item)->header.sig_type))); - json_object_object_add(json_obj_item,"SIG size", json_object_new_uint64(((dap_chain_tx_pkey_t*)item)->header.sig_size)); - json_object_object_add(json_obj_item,"Sequence number", json_object_new_uint64(((dap_chain_tx_pkey_t*)item)->seq_no)); - json_object_object_add(json_obj_item,"Key", json_object_new_string("")); - json_object_object_add(json_obj_item,"Type", json_object_new_string(dap_pkey_type_to_str(l_pkey->header.type))); - json_object_object_add(json_obj_item,"Size", json_object_new_uint64(l_pkey->header.size)); - json_object_object_add(json_obj_item,"Hash", json_object_new_string(l_hash_str)); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("PKey")); + json_object_object_add(json_obj_item,"pkey", json_object_new_string("")); + json_object_object_add(json_obj_item,"SIG_type", json_object_new_string(dap_sign_type_to_str(((dap_chain_tx_pkey_t*)item)->header.sig_type))); + json_object_object_add(json_obj_item,"SIG_size", json_object_new_uint64(((dap_chain_tx_pkey_t*)item)->header.sig_size)); + json_object_object_add(json_obj_item,"sequence_number", json_object_new_uint64(((dap_chain_tx_pkey_t*)item)->seq_no)); + json_object_object_add(json_obj_item,"key", json_object_new_string("")); + json_object_object_add(json_obj_item,"type", json_object_new_string(dap_pkey_type_to_str(l_pkey->header.type))); + json_object_object_add(json_obj_item,"size", json_object_new_uint64(l_pkey->header.size)); + json_object_object_add(json_obj_item,"hash", json_object_new_string(l_hash_str)); } break; case TX_ITEM_TYPE_TSD: { - json_object_object_add(json_obj_item,"item type", json_object_new_string("TSD data")); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("TSD data")); json_object_object_add(json_obj_item,"type", json_object_new_uint64(((dap_chain_tx_tsd_t*)item)->header.type)); json_object_object_add(json_obj_item,"size", json_object_new_uint64(((dap_chain_tx_tsd_t*)item)->header.size)); } break; case TX_ITEM_TYPE_IN_COND: - json_object_object_add(json_obj_item,"item type", json_object_new_string("IN COND")); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("IN COND")); l_hash_tmp = ((dap_chain_tx_in_cond_t*)item)->header.tx_prev_hash; l_hash_str = dap_strcmp(a_hash_out_type, "hex") ? dap_enc_base58_encode_hash_to_str_static(&l_hash_tmp) : dap_chain_hash_fast_to_str_static(&l_hash_tmp); - json_object_object_add(json_obj_item,"Receipt_idx", json_object_new_int(((dap_chain_tx_in_cond_t*)item)->header.receipt_idx)); - json_object_object_add(json_obj_item,"Tx_prev_hash", json_object_new_string(l_hash_str)); - json_object_object_add(json_obj_item,"Tx_out_prev_idx", json_object_new_uint64(((dap_chain_tx_in_cond_t*)item)->header.tx_out_prev_idx)); + json_object_object_add(json_obj_item,"receipt_idx", json_object_new_int(((dap_chain_tx_in_cond_t*)item)->header.receipt_idx)); + json_object_object_add(json_obj_item,"tx_prev_hash", json_object_new_string(l_hash_str)); + json_object_object_add(json_obj_item,"tx_out_prev_idx", json_object_new_uint64(((dap_chain_tx_in_cond_t*)item)->header.tx_out_prev_idx)); break; case TX_ITEM_TYPE_OUT_COND: { char l_tmp_buff[70]; - json_object_object_add(json_obj_item,"item type", json_object_new_string("OUT COND")); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("OUT COND")); const char *l_coins_str, *l_value_str = dap_uint256_to_char(((dap_chain_tx_out_cond_t*)item)->header.value, &l_coins_str); dap_time_t l_ts_exp = ((dap_chain_tx_out_cond_t*)item)->header.ts_expires; dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, l_ts_exp); @@ -390,8 +389,8 @@ bool dap_chain_datum_dump_tx_json(json_object* a_json_arr_reply, snprintf(l_tmp_buff, sizeof(l_tmp_buff), "0x%08x",((dap_chain_tx_out_cond_t*)item)->subtype.srv_pay.unit.uint32); json_object_object_add(json_obj_item,"unit", json_object_new_string(l_tmp_buff)); json_object_object_add(json_obj_item,"pkey", json_object_new_string(l_hash_str)); - json_object_object_add(json_obj_item,"max price(coins)", json_object_new_string(l_coins_str)); - json_object_object_add(json_obj_item,"max price(value)", json_object_new_string(l_value_str)); + json_object_object_add(json_obj_item,"max_price_coins", json_object_new_string(l_coins_str)); + json_object_object_add(json_obj_item,"max_price_value", json_object_new_string(l_value_str)); } break; case DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_STAKE_POS_DELEGATE: { @@ -411,7 +410,7 @@ bool dap_chain_datum_dump_tx_json(json_object* a_json_arr_reply, const char *l_rate_str; dap_uint256_to_char( (((dap_chain_tx_out_cond_t*)item)->subtype.srv_xchange.rate), &l_rate_str ); snprintf(l_tmp_buff,sizeof(l_tmp_buff),"0x%016"DAP_UINT64_FORMAT_x"",((dap_chain_tx_out_cond_t*)item)->subtype.srv_xchange.buy_net_id.uint64); - json_object_object_add(json_obj_item,"net id", json_object_new_string(l_tmp_buff)); + json_object_object_add(json_obj_item,"net_id", json_object_new_string(l_tmp_buff)); json_object_object_add(json_obj_item,"buy_token", json_object_new_string(((dap_chain_tx_out_cond_t*)item)->subtype.srv_xchange.buy_token)); json_object_object_add(json_obj_item,"rate", json_object_new_string(l_rate_str)); } break; @@ -425,11 +424,11 @@ bool dap_chain_datum_dump_tx_json(json_object* a_json_arr_reply, } break; case TX_ITEM_TYPE_OUT_EXT: { const char *l_coins_str, *l_value_str = dap_uint256_to_char( ((dap_chain_tx_out_ext_t*)item)->header.value, &l_coins_str ); - json_object_object_add(json_obj_item,"item type", json_object_new_string("OUT EXT")); - json_object_object_add(json_obj_item,"Addr", json_object_new_string(dap_chain_addr_to_str_static(&((dap_chain_tx_out_ext_t*)item)->addr))); - json_object_object_add(json_obj_item,"Token", json_object_new_string(((dap_chain_tx_out_ext_t*)item)->token)); - json_object_object_add(json_obj_item,"Coins", json_object_new_string(l_coins_str)); - json_object_object_add(json_obj_item,"Value", json_object_new_string(l_value_str)); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("OUT EXT")); + json_object_object_add(json_obj_item,"addr", json_object_new_string(dap_chain_addr_to_str_static(&((dap_chain_tx_out_ext_t*)item)->addr))); + json_object_object_add(json_obj_item,"token", json_object_new_string(((dap_chain_tx_out_ext_t*)item)->token)); + json_object_object_add(json_obj_item,"coins", json_object_new_string(l_coins_str)); + json_object_object_add(json_obj_item,"value", json_object_new_string(l_value_str)); } break; case TX_ITEM_TYPE_VOTING:{ @@ -438,9 +437,9 @@ bool dap_chain_datum_dump_tx_json(json_object* a_json_arr_reply, if (!l_item || !l_tsd_size) break; dap_chain_datum_tx_voting_params_t *l_voting_params = dap_chain_datum_tx_voting_parse_tsd(a_datum); - json_object_object_add(json_obj_item,"item type", json_object_new_string("VOTING")); - json_object_object_add(json_obj_item,"Voting question", json_object_new_string(l_voting_params->question)); - json_object_object_add(json_obj_item,"Answer options", json_object_new_string("")); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("VOTING")); + json_object_object_add(json_obj_item,"voting_question", json_object_new_string(l_voting_params->question)); + json_object_object_add(json_obj_item,"answer_options", json_object_new_string("")); dap_list_t *l_temp = l_voting_params->options; uint8_t l_index = 0; @@ -451,16 +450,16 @@ bool dap_chain_datum_dump_tx_json(json_object* a_json_arr_reply, } if (l_voting_params->voting_expire) { dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, l_voting_params->voting_expire); - json_object_object_add(json_obj_item,"Voting expire", json_object_new_string(l_tmp_buf)); + json_object_object_add(json_obj_item,"voting_expire", json_object_new_string(l_tmp_buf)); } if (l_voting_params->votes_max_count) { - json_object_object_add(json_obj_item, "Votes max count", json_object_new_uint64(l_voting_params->votes_max_count)); + json_object_object_add(json_obj_item, "votes_max_count", json_object_new_uint64(l_voting_params->votes_max_count)); } - json_object_object_add(json_obj_item,"Changing vote is", l_voting_params->vote_changing_allowed ? json_object_new_string("available") : + json_object_object_add(json_obj_item,"changing_vote_is", l_voting_params->vote_changing_allowed ? json_object_new_string("available") : json_object_new_string("not available")); l_voting_params->delegate_key_required ? - json_object_object_add(json_obj_item,"Delegated key for participating in voting", json_object_new_string("required")): - json_object_object_add(json_obj_item,"Delegated key for participating in voting", json_object_new_string("not required")); + json_object_object_add(json_obj_item,"delegated_key_for_participating_in_voting", json_object_new_string("required")): + json_object_object_add(json_obj_item,"delegated_key_for_participating_in_voting", json_object_new_string("not required")); dap_list_free_full(l_voting_params->options, NULL); DAP_DELETE(l_voting_params->question); @@ -469,13 +468,13 @@ bool dap_chain_datum_dump_tx_json(json_object* a_json_arr_reply, case TX_ITEM_TYPE_VOTE:{ dap_chain_tx_vote_t *l_vote_item = (dap_chain_tx_vote_t *)item; const char *l_hash_str = dap_chain_hash_fast_to_str_static(&l_vote_item->voting_hash); - json_object_object_add(json_obj_item,"item type", json_object_new_string("VOTE")); - json_object_object_add(json_obj_item,"Voting hash", json_object_new_string(l_hash_str)); - json_object_object_add(json_obj_item,"Vote answer idx", json_object_new_uint64(l_vote_item->answer_idx)); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("VOTE")); + json_object_object_add(json_obj_item,"voting_hash", json_object_new_string(l_hash_str)); + json_object_object_add(json_obj_item,"vote_answer_idx", json_object_new_uint64(l_vote_item->answer_idx)); } break; default: - json_object_object_add(json_obj_item,"item type", json_object_new_string("This transaction have unknown item type")); + json_object_object_add(json_obj_item,"item_type", json_object_new_string("This transaction have unknown item type")); break; } json_object_array_add(json_arr_items, json_obj_item); @@ -490,8 +489,8 @@ void s_token_dump_decl_json(json_object *a_obj_out, dap_chain_datum_token_t *a_ case DAP_CHAIN_DATUM_TOKEN_SUBTYPE_PRIVATE:{ json_object_object_add(a_obj_out, "subtype",json_object_new_string("PRIVATE")); json_object_object_add(a_obj_out,"decimals",json_object_new_uint64(a_token->header_private_decl.decimals)); - json_object_object_add(a_obj_out,"auth signs valid",json_object_new_uint64(a_token->signs_valid)); - json_object_object_add(a_obj_out,"auth signs total",json_object_new_uint64(a_token->signs_total)); + json_object_object_add(a_obj_out,"auth_signs_valid",json_object_new_uint64(a_token->signs_valid)); + json_object_object_add(a_obj_out,"auth_signs_total",json_object_new_uint64(a_token->signs_total)); json_object_object_add(a_obj_out,"total_supply",json_object_new_string(dap_uint256_to_char(a_token->total_supply, NULL))); dap_chain_datum_token_flags_dump_to_json(a_obj_out, "flags",a_token->header_private_decl.flags); @@ -503,8 +502,8 @@ void s_token_dump_decl_json(json_object *a_obj_out, dap_chain_datum_token_t *a_ case DAP_CHAIN_DATUM_TOKEN_SUBTYPE_NATIVE: { json_object_object_add(a_obj_out,"subtype",json_object_new_string("CF20")); json_object_object_add(a_obj_out,"decimals",json_object_new_uint64(a_token->header_native_decl.decimals)); - json_object_object_add(a_obj_out,"auth signs valid",json_object_new_uint64(a_token->signs_valid)); - json_object_object_add(a_obj_out,"auth signs total",json_object_new_uint64(a_token->signs_total)); + json_object_object_add(a_obj_out,"auth_signs_valid",json_object_new_uint64(a_token->signs_valid)); + json_object_object_add(a_obj_out,"auth_signs_total",json_object_new_uint64(a_token->signs_total)); json_object_object_add(a_obj_out,"total_supply",json_object_new_string(dap_uint256_to_char(a_token->total_supply, NULL))); dap_chain_datum_token_flags_dump_to_json(a_obj_out, "flags", a_token->header_native_decl.flags); dap_datum_token_dump_tsd_to_json(a_obj_out, a_token, a_token_size, a_hash_out_type); @@ -612,13 +611,13 @@ void dap_chain_datum_dump_json(json_object* a_json_arr_reply, json_object *a_ob size_t l_emission_size = a_datum->header.data_size; dap_chain_datum_token_emission_t *l_emission = dap_chain_datum_emission_read(a_datum->data, &l_emission_size); const char *l_coins_str, *l_value_str = dap_uint256_to_char(l_emission->hdr.value, &l_coins_str); - json_object_object_add(json_obj_datum,"emission hash", json_object_new_string(l_hash_str)); + json_object_object_add(json_obj_datum,"emission_hash", json_object_new_string(l_hash_str)); json_object_object_add(json_obj_datum,"coins", json_object_new_string(l_coins_str)); json_object_object_add(json_obj_datum,"value", json_object_new_string(l_value_str)); json_object_object_add(json_obj_datum,"ticker", json_object_new_string(l_emission->hdr.ticker)); json_object_object_add(json_obj_datum,"type", json_object_new_string(dap_chain_datum_emission_type_str(l_emission->hdr.type))); json_object_object_add(json_obj_datum,"version", json_object_new_uint64(l_emission->hdr.version)); - json_object_object_add(json_obj_datum,"to addr", json_object_new_string(dap_chain_addr_to_str_static(&(l_emission->hdr.address)))); + json_object_object_add(json_obj_datum,"to_addr", json_object_new_string(dap_chain_addr_to_str_static(&(l_emission->hdr.address)))); switch (l_emission->hdr.type) { case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_AUTH: @@ -664,7 +663,7 @@ void dap_chain_datum_dump_json(json_object* a_json_arr_reply, json_object *a_ob case DAP_CHAIN_DATUM_DECREE:{ dap_chain_datum_decree_t *l_decree = (dap_chain_datum_decree_t *)a_datum->data; size_t l_decree_size = dap_chain_datum_decree_get_size(l_decree); - json_object_object_add(json_obj_datum,"=== Datum decree ===",json_object_new_string("empty")); + json_object_object_add(json_obj_datum,"type_datum",json_object_new_string("=== Datum decree ===")); json_object_object_add(json_obj_datum,"hash",json_object_new_string(l_hash_str)); json_object_object_add(json_obj_datum,"size",json_object_new_uint64(l_decree_size)); dap_chain_datum_decree_dump_json(json_obj_datum, l_decree, l_decree_size, a_hash_out_type); @@ -672,15 +671,15 @@ void dap_chain_datum_dump_json(json_object* a_json_arr_reply, json_object *a_ob case DAP_CHAIN_DATUM_ANCHOR:{ dap_chain_datum_anchor_t *l_anchor = (dap_chain_datum_anchor_t *)a_datum->data; size_t l_anchor_size = sizeof(dap_chain_datum_anchor_t) + l_anchor->header.data_size + l_anchor->header.signs_size; - json_object_object_add(json_obj_datum,"=== Datum anchor ===",json_object_new_string("empty")); + json_object_object_add(json_obj_datum,"type_datum",json_object_new_string("=== Datum anchor ===")); json_object_object_add(json_obj_datum,"hash",json_object_new_string(l_hash_str)); json_object_object_add(json_obj_datum,"size",json_object_new_uint64(l_anchor_size)); dap_hash_fast_t l_decree_hash = { }; dap_chain_datum_anchor_get_hash_from_data(l_anchor, &l_decree_hash); l_hash_str = dap_chain_hash_fast_to_str_static(&l_decree_hash); - json_object_object_add(json_obj_datum,"decree hash",json_object_new_string(l_hash_str)); + json_object_object_add(json_obj_datum,"decree_hash",json_object_new_string(l_hash_str)); dap_chain_datum_anchor_certs_dump_json(json_obj_datum,l_anchor->data_n_sign + l_anchor->header.data_size, l_anchor->header.signs_size, a_hash_out_type); } break; } - json_object_object_add(a_obj_out,"Datum",json_obj_datum); + json_object_object_add(a_obj_out,"datum",json_obj_datum); } diff --git a/modules/datum/dap_chain_datum_anchor.c b/modules/datum/dap_chain_datum_anchor.c index d0e934bb729133e49377c867473078605564fe87..2b7400ab14ff120e9b132e34dd48af57a033fb60 100644 --- a/modules/datum/dap_chain_datum_anchor.c +++ b/modules/datum/dap_chain_datum_anchor.c @@ -71,9 +71,8 @@ void dap_chain_datum_anchor_certs_dump(dap_string_t * a_str_out, byte_t * a_sign void dap_chain_datum_anchor_certs_dump_json(json_object * a_json_out, byte_t * a_signs, size_t a_certs_size, const char *a_hash_out_type) { - json_object_object_add(a_json_out, "signatures", json_object_new_string("")); if (!a_certs_size) { - json_object_object_add(a_json_out, "Cert status", json_object_new_string("NONE")); + json_object_object_add(a_json_out, "cert_status", json_object_new_string("NONE")); return; } json_object* json_arr_certs_out = json_object_new_array(); @@ -83,24 +82,24 @@ void dap_chain_datum_anchor_certs_dump_json(json_object * a_json_out, byte_t * a dap_sign_t *l_sign = (dap_sign_t*)(a_signs + l_offset); l_offset += dap_sign_get_size(l_sign); if (l_sign->header.sign_size == 0) { - json_object_object_add(json_obj_sign, "sign status", json_object_new_string("CORRUPTED - 0 size signature")); + json_object_object_add(json_obj_sign, "sign_status", json_object_new_string("CORRUPTED - 0 size signature")); json_object_array_add(json_arr_certs_out, json_obj_sign); continue; } dap_chain_hash_fast_t l_pkey_hash = {0}; if (dap_sign_get_pkey_hash(l_sign, &l_pkey_hash) == false) { - json_object_object_add(json_obj_sign, "sign status", json_object_new_string("CORRUPTED - can't calc hash")); + json_object_object_add(json_obj_sign, "sign_status", json_object_new_string("CORRUPTED - can't calc hash")); json_object_array_add(json_arr_certs_out, json_obj_sign); continue; } const char *l_hash_str = dap_strcmp(a_hash_out_type, "hex") ? dap_enc_base58_encode_hash_to_str_static(&l_pkey_hash) : dap_chain_hash_fast_to_str_static(&l_pkey_hash); - json_object_object_add(json_obj_sign, "sign #", json_object_new_uint64(i)); + json_object_object_add(json_obj_sign, "sign_#", json_object_new_uint64(i)); json_object_object_add(json_obj_sign, "hash", json_object_new_string(l_hash_str)); json_object_object_add(json_obj_sign, "type", json_object_new_string(dap_sign_type_to_str(l_sign->header.type))); - json_object_object_add(json_obj_sign, "sign size", json_object_new_uint64(l_sign->header.sign_size)); + json_object_object_add(json_obj_sign, "sign_size", json_object_new_uint64(l_sign->header.sign_size)); json_object_array_add(json_arr_certs_out, json_obj_sign); } json_object_object_add(a_json_out,"SIGNS",json_arr_certs_out); diff --git a/modules/datum/dap_chain_datum_decree.c b/modules/datum/dap_chain_datum_decree.c index d0ce74b3d079c8c71615a472ed9af58486c798c0..18f4d1fd54f57a80e5dc7acbb9e37981747aa465 100644 --- a/modules/datum/dap_chain_datum_decree.c +++ b/modules/datum/dap_chain_datum_decree.c @@ -228,44 +228,44 @@ void dap_chain_datum_decree_dump_json(json_object *a_json_out, dap_chain_datum_d switch(l_tsd->type) { case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_VALUE: if (l_tsd->size > sizeof(uint256_t)){ - json_object_object_add(a_json_out, "Value", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "value", json_object_new_string("WRONG SIZE")); break; } uint256_t l_value = uint256_0; _dap_tsd_get_scalar(l_tsd, &l_value); const char *l_value_str = dap_uint256_to_char(l_value, NULL); - json_object_object_add(a_json_out, "Value", json_object_new_string(l_value_str)); + json_object_object_add(a_json_out, "value", json_object_new_string(l_value_str)); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_SIGN: break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_FEE: if (l_tsd->size > sizeof(uint256_t)){ - json_object_object_add(a_json_out, "Fee", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "fee", json_object_new_string("WRONG SIZE")); break; } uint256_t l_fee_value = uint256_0; _dap_tsd_get_scalar(l_tsd, &l_fee_value); const char *l_fee_value_str = dap_uint256_to_char(l_fee_value, NULL); - json_object_object_add(a_json_out, "Fee", json_object_new_string(l_fee_value_str)); + json_object_object_add(a_json_out, "fee", json_object_new_string(l_fee_value_str)); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_OWNER: if (l_tsd->size < sizeof(dap_pkey_t)) { - json_object_object_add(a_json_out, "Owner fingerprint", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "owner_fingerprint", json_object_new_string("WRONG SIZE")); break; } dap_pkey_t *l_owner_pkey = /*DAP_NEW_STACK_SIZE(dap_pkey_t, l_tsd->size); memcpy(l_owner_pkey, l_tsd->data, l_tsd->size);*/ _dap_tsd_get_object(l_tsd, dap_pkey_t); - json_object_object_add(a_json_out, "Owner fingerprint", json_object_new_string(dap_get_data_hash_str(l_owner_pkey->pkey, l_owner_pkey->header.size).s)); + json_object_object_add(a_json_out, "owner_fingerprint", json_object_new_string(dap_get_data_hash_str(l_owner_pkey->pkey, l_owner_pkey->header.size).s)); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_MIN_OWNER: if (l_tsd->size > sizeof(uint256_t)){ - json_object_object_add(a_json_out, "Owner min", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "owner_min", json_object_new_string("WRONG SIZE")); break; } uint256_t l_owner_min = uint256_0; _dap_tsd_get_scalar(l_tsd, &l_owner_min); const char *l_owner_min_str = dap_uint256_to_char(l_owner_min, NULL); - json_object_object_add(a_json_out, "Owner min", json_object_new_string(l_owner_min_str)); + json_object_object_add(a_json_out, "owner_min", json_object_new_string(l_owner_min_str)); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_FEE_WALLET: if (l_tsd->size > sizeof(dap_chain_addr_t)) { @@ -274,10 +274,10 @@ void dap_chain_datum_decree_dump_json(json_object *a_json_out, dap_chain_datum_d } dap_chain_addr_t *l_addr_fee_wallet = /*{ }; _dap_tsd_get_scalar(l_tsd, &l_addr_fee_wallet);*/ _dap_tsd_get_object(l_tsd, dap_chain_addr_t); - json_object_object_add(a_json_out, "Wallet for fee", json_object_new_string(dap_chain_addr_to_str_static(l_addr_fee_wallet))); + json_object_object_add(a_json_out, "wallet_for_fee", json_object_new_string(dap_chain_addr_to_str_static(l_addr_fee_wallet))); case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_HASH: if (l_tsd->size > sizeof(dap_hash_fast_t)) { - json_object_object_add(a_json_out, "Stake tx", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "stake_tx", json_object_new_string("WRONG SIZE")); break; } dap_hash_fast_t *l_stake_tx = /*{ }; @@ -285,106 +285,106 @@ void dap_chain_datum_decree_dump_json(json_object *a_json_out, dap_chain_datum_d const char *l_stake_tx_hash = dap_strcmp(a_hash_out_type, "hex") ? dap_enc_base58_encode_hash_to_str_static(l_stake_tx) : dap_chain_hash_fast_to_str_static(l_stake_tx); - json_object_object_add(a_json_out, "Stake tx", json_object_new_string(l_stake_tx_hash)); + json_object_object_add(a_json_out, "stake_tx", json_object_new_string(l_stake_tx_hash)); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_VALUE: if (l_tsd->size > sizeof(uint256_t)){ - json_object_object_add(a_json_out, "Stake value", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "stake_value", json_object_new_string("WRONG SIZE")); break; } uint256_t l_stake_value = uint256_0; _dap_tsd_get_scalar(l_tsd, &l_stake_value); const char *l_stake_value_str = dap_uint256_to_char(l_stake_value, NULL); - json_object_object_add(a_json_out, "Stake value", json_object_new_string(l_stake_value_str)); + json_object_object_add(a_json_out, "stake_value", json_object_new_string(l_stake_value_str)); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_SIGNING_ADDR: if (l_tsd->size > sizeof(dap_chain_addr_t)) { - json_object_object_add(a_json_out, "Signing addr", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "signing_addr", json_object_new_string("WRONG SIZE")); break; } dap_chain_addr_t *l_stake_addr_signing = /*{ }; _dap_tsd_get_scalar(l_tsd, &l_stake_addr_signing);*/ _dap_tsd_get_object(l_tsd, dap_chain_addr_t); - json_object_object_add(a_json_out, "Signing addr", json_object_new_string(dap_chain_addr_to_str_static(l_stake_addr_signing))); + json_object_object_add(a_json_out, "signing_addr", json_object_new_string(dap_chain_addr_to_str_static(l_stake_addr_signing))); dap_chain_hash_fast_t l_pkey_signing = l_stake_addr_signing->data.hash_fast; const char *l_pkey_signing_str = dap_strcmp(a_hash_out_type, "hex") ? dap_enc_base58_encode_hash_to_str_static(&l_pkey_signing) : dap_chain_hash_fast_to_str_static(&l_pkey_signing); - json_object_object_add(a_json_out, "Signing pkey fingerprint", json_object_new_string(l_pkey_signing_str)); + json_object_object_add(a_json_out, "signing_pkey_fingerprint", json_object_new_string(l_pkey_signing_str)); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_NODE_ADDR: if(l_tsd->size > sizeof(dap_chain_node_addr_t)){ - json_object_object_add(a_json_out, "Node addr", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "node_addr", json_object_new_string("WRONG SIZE")); break; } dap_chain_node_addr_t *l_node_addr = _dap_tsd_get_object(l_tsd, dap_chain_node_addr_t); char l_buf[24]; snprintf(l_buf, sizeof(l_buf), NODE_ADDR_FP_STR, NODE_ADDR_FP_ARGS(l_node_addr)); - json_object_object_add(a_json_out, "Node addr", json_object_new_string(l_buf)); + json_object_object_add(a_json_out, "node_addr", json_object_new_string(l_buf)); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_VALUE: if (l_tsd->size > sizeof(uint256_t)) { - json_object_object_add(a_json_out, "Min value", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "min_value", json_object_new_string("WRONG SIZE")); break; } uint256_t l_min_value = uint256_0; _dap_tsd_get_scalar(l_tsd, &l_min_value); const char *l_min_value_str = dap_uint256_to_char(l_min_value, NULL); - json_object_object_add(a_json_out, "Min value", json_object_new_string(l_min_value_str)); + json_object_object_add(a_json_out, "min_value", json_object_new_string(l_min_value_str)); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_SIGNERS_COUNT: if (l_tsd->size > sizeof(uint256_t)) { - json_object_object_add(a_json_out, "Min signers count", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "min_signers_count", json_object_new_string("WRONG SIZE")); break; } uint256_t l_min_signers_count = uint256_0; _dap_tsd_get_scalar(l_tsd, &l_min_signers_count); const char *l_min_signers_count_str = dap_uint256_to_char(l_min_signers_count, NULL); - json_object_object_add(a_json_out, "Min signers count", json_object_new_string(l_min_signers_count_str)); + json_object_object_add(a_json_out, "min_signers_count", json_object_new_string(l_min_signers_count_str)); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_HOST: case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STRING: - json_object_object_add(a_json_out, "Host address", json_object_new_string(dap_tsd_get_string(l_tsd))); + json_object_object_add(a_json_out, "host_address", json_object_new_string(dap_tsd_get_string(l_tsd))); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_ACTION: if (l_tsd->size != sizeof(uint8_t)) { - json_object_object_add(a_json_out, "Action", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "action", json_object_new_string("WRONG SIZE")); break; } uint8_t l_action = 0; _dap_tsd_get_scalar(l_tsd, &l_action); - json_object_object_add(a_json_out, "tAction", l_action ? + json_object_object_add(a_json_out, "action", l_action ? json_object_new_string("add (enable)") : json_object_new_string("delete (disable)")); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_SIGNATURE_TYPE: if (l_tsd->size != sizeof(uint32_t)) { - json_object_object_add(a_json_out, "Signature type", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "signature_type", json_object_new_string("WRONG SIZE")); break; } uint32_t l_type = 0; _dap_tsd_get_scalar(l_tsd, &l_type); dap_sign_type_t l_sign_type = { .type = l_type }; - json_object_object_add(a_json_out, "Signature type", json_object_new_string(dap_sign_type_to_str(l_sign_type))); + json_object_object_add(a_json_out, "signature_type", json_object_new_string(dap_sign_type_to_str(l_sign_type))); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_PKEY: if (l_tsd->size != dap_pkey_get_size((dap_pkey_t *)(l_tsd->data))) { - json_object_object_add(a_json_out, "pkey type", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "pkey_type", json_object_new_string("WRONG SIZE")); break; } - json_object_object_add(a_json_out, "pkey type", json_object_new_string( dap_pkey_type_to_str(((dap_pkey_t *)(l_tsd->data))->header.type) )); + json_object_object_add(a_json_out, "pkey_type", json_object_new_string( dap_pkey_type_to_str(((dap_pkey_t *)(l_tsd->data))->header.type) )); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_BLOCK_NUM: if (l_tsd->size != sizeof(uint64_t)) { - json_object_object_add(a_json_out, "Signature type", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "signature_type", json_object_new_string("WRONG SIZE")); break; } uint64_t l_num = 0; _dap_tsd_get_scalar(l_tsd, &l_type); - json_object_object_add(a_json_out, "Signature type", json_object_new_uint64(l_num)); + json_object_object_add(a_json_out, "signature_type", json_object_new_uint64(l_num)); break; case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_HARDFORK_CHANGED_ADDRS: if (l_tsd->size != sizeof(uint64_t)) { - json_object_object_add(a_json_out, "Wallet_addr_pair", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "wallet_addr_pair", json_object_new_string("WRONG SIZE")); break; } json_object* l_json_obj = NULL; @@ -393,14 +393,14 @@ void dap_chain_datum_decree_dump_json(json_object *a_json_out, dap_chain_datum_d } else { l_json_obj = json_object_new_string("Can't parse json in Wallet_addr_pair"); } - json_object_object_add(a_json_out, "Wallet_addr_pair", l_json_obj); + json_object_object_add(a_json_out, "wallet_addr_pair", l_json_obj); case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_POLICY_EXECUTE: if (l_tsd->size != dap_chain_policy_get_size((dap_chain_policy_t *)(l_tsd->data))) { - json_object_object_add(a_json_out, "Policy num", json_object_new_string("WRONG SIZE")); + json_object_object_add(a_json_out, "policy_num", json_object_new_string("WRONG SIZE")); break; } - json_object_object_add(a_json_out, "Policy num", json_object_new_uint64(((dap_chain_policy_t *)(l_tsd->data))->activate.num)); + json_object_object_add(a_json_out, "policy_num", json_object_new_uint64(((dap_chain_policy_t *)(l_tsd->data))->activate.num)); break; default: @@ -414,9 +414,8 @@ void dap_chain_datum_decree_dump_json(json_object *a_json_out, dap_chain_datum_d void dap_chain_datum_decree_certs_dump_json(json_object * a_json_out, byte_t * a_signs, size_t a_certs_size, const char *a_hash_out_type) { - json_object_object_add(a_json_out, "signatures", json_object_new_string("")); if (!a_certs_size) { - json_object_object_add(a_json_out, "Cert status", json_object_new_string("NONE")); + json_object_object_add(a_json_out, "cert_status", json_object_new_string("NONE")); return; } json_object* json_arr_certs_out = json_object_new_array(); @@ -426,14 +425,14 @@ void dap_chain_datum_decree_certs_dump_json(json_object * a_json_out, byte_t * a dap_sign_t *l_sign = (dap_sign_t *) (a_signs + l_offset); l_offset += dap_sign_get_size(l_sign); if (l_sign->header.sign_size == 0) { - json_object_object_add(json_obj_sign, "sign status", json_object_new_string("CORRUPTED - 0 size signature")); + json_object_object_add(json_obj_sign, "sign_status", json_object_new_string("CORRUPTED - 0 size signature")); json_object_array_add(json_arr_certs_out, json_obj_sign); continue; } dap_chain_hash_fast_t l_pkey_hash = {0}; if (dap_sign_get_pkey_hash(l_sign, &l_pkey_hash) == false) { - json_object_object_add(json_obj_sign, "sign status", json_object_new_string("CORRUPTED - can't calc hash")); + json_object_object_add(json_obj_sign, "sign_status", json_object_new_string("CORRUPTED - can't calc hash")); json_object_array_add(json_arr_certs_out, json_obj_sign); continue; } @@ -441,10 +440,10 @@ void dap_chain_datum_decree_certs_dump_json(json_object * a_json_out, byte_t * a const char *l_hash_str = dap_strcmp(a_hash_out_type, "hex") ? dap_enc_base58_encode_hash_to_str_static(&l_pkey_hash) : dap_chain_hash_fast_to_str_static(&l_pkey_hash); - json_object_object_add(json_obj_sign, "sign #", json_object_new_uint64(i)); + json_object_object_add(json_obj_sign, "sign_#", json_object_new_uint64(i)); json_object_object_add(json_obj_sign, "hash", json_object_new_string(l_hash_str)); json_object_object_add(json_obj_sign, "type", json_object_new_string(dap_sign_type_to_str(l_sign->header.type))); - json_object_object_add(json_obj_sign, "sign size", json_object_new_uint64(l_sign->header.sign_size)); + json_object_object_add(json_obj_sign, "sign_size", json_object_new_uint64(l_sign->header.sign_size)); json_object_array_add(json_arr_certs_out, json_obj_sign); } json_object_object_add(a_json_out,"SIGNS", json_arr_certs_out); diff --git a/modules/datum/dap_chain_datum_token.c b/modules/datum/dap_chain_datum_token.c index 423e44a0ffe6d66df877c9cc63a2901364dc5e3d..391965ace431bb9af51eed51023e086ebb27054e 100644 --- a/modules/datum/dap_chain_datum_token.c +++ b/modules/datum/dap_chain_datum_token.c @@ -264,7 +264,6 @@ void dap_chain_datum_token_certs_dump(dap_string_t * a_str_out, byte_t * a_tsd_n */ void dap_chain_datum_token_certs_dump_to_json(json_object *a_json_obj_out, byte_t * a_tsd_n_signs, size_t a_certs_size, const char *a_hash_out_type) { - json_object_object_add(a_json_obj_out, "Signatures", json_object_new_string("")); if (!a_certs_size) { json_object_object_add(a_json_obj_out, "status", json_object_new_string("<NONE>")); return; diff --git a/modules/ledger/dap_chain_ledger.c b/modules/ledger/dap_chain_ledger.c index 5b5d7481e73f2d80b1250fdd26acbb99cb3f4398..fe17bfa4da8c06360b3886eacec307af5b9fec59 100644 --- a/modules/ledger/dap_chain_ledger.c +++ b/modules/ledger/dap_chain_ledger.c @@ -303,7 +303,7 @@ static void s_tx_header_print(json_object *a_json_out, dap_chain_datum_tx_t *a_t const char *l_tx_hash_str = dap_strcmp(a_hash_out_type, "hex") ? dap_enc_base58_encode_hash_to_str_static(a_tx_hash) : dap_chain_hash_fast_to_str_static(a_tx_hash); - json_object_object_add(a_json_out, "TX hash ", json_object_new_string(l_tx_hash_str)); + json_object_object_add(a_json_out, "tx_hash ", json_object_new_string(l_tx_hash_str)); json_object_object_add(a_json_out, "time ", json_object_new_string(l_time_str)); } @@ -403,7 +403,7 @@ static void s_dump_datum_tx_for_addr(dap_ledger_tx_item_t *a_item, bool a_unspen ? dap_chain_addr_to_str_static(&l_dst_addr) : dap_chain_tx_out_cond_subtype_to_str( ((dap_chain_tx_out_cond_t *)l_item)->header.subtype ); json_object_object_add(l_json_obj_datum, "send", json_object_new_string(dap_uint256_to_char(l_value, NULL))); - json_object_object_add(l_json_obj_datum, "to addr", json_object_new_string(l_dst_addr_str)); + json_object_object_add(l_json_obj_datum, "to_addr", json_object_new_string(l_dst_addr_str)); json_object_object_add(l_json_obj_datum, "token", l_src_token ? json_object_new_string(l_src_token) : json_object_new_string("UNKNOWN")); json_object_array_add(json_arr_out, l_json_obj_datum); } @@ -450,7 +450,7 @@ json_object *dap_ledger_token_tx_item_list(dap_ledger_t * a_ledger, dap_chain_ad if(!json_arr_out) { json_object * json_obj_addr = json_object_new_object(); - json_object_object_add(json_obj_addr, "status:", json_object_new_string("empty")); + json_object_object_add(json_obj_addr, "status", json_object_new_string("empty")); json_object_array_add(json_arr_out, json_obj_addr); } return json_arr_out; @@ -465,7 +465,7 @@ static bool s_pack_ledger_threshold_info_json (json_object *a_json_arr_out, dap_ char l_time[DAP_TIME_STR_SIZE] = {0}; dap_chain_hash_fast_to_str(&a_tx_item->tx_hash_fast,l_tx_prev_hash_str,sizeof(l_tx_prev_hash_str)); dap_time_to_str_rfc822(l_time, sizeof(l_time), a_tx_item->cache_data.ts_created); - json_object_object_add(json_obj_tx, "Ledger thresholded tx_hash_fast", json_object_new_string(l_tx_prev_hash_str)); + json_object_object_add(json_obj_tx, "thresholded_hash", json_object_new_string(l_tx_prev_hash_str)); json_object_object_add(json_obj_tx, "time_created", json_object_new_string(l_time)); json_object_object_add(json_obj_tx, "tx_item_size", json_object_new_int(a_tx_item->tx->header.tx_items_size)); json_object_array_add(a_json_arr_out, json_obj_tx); @@ -475,7 +475,7 @@ static bool s_pack_ledger_balance_info_json (json_object *a_json_arr_out, dap_le { json_object* json_obj_tx = json_object_new_object(); - json_object_object_add(json_obj_tx, "Ledger balance key", json_object_new_string(a_balance_item->key)); + json_object_object_add(json_obj_tx, "ledger_balance_key", json_object_new_string(a_balance_item->key)); json_object_object_add(json_obj_tx, "token_ticker", json_object_new_string(a_balance_item->token_ticker)); json_object_object_add(json_obj_tx, "balance", json_object_new_string(dap_uint256_to_char(a_balance_item->balance, NULL))); json_object_array_add(a_json_arr_out, json_obj_tx); @@ -504,10 +504,10 @@ json_object *dap_ledger_threshold_info(dap_ledger_t *a_ledger, size_t a_limit, s } HASH_FIND(hh, l_ledger_pvt->threshold_txs, a_threshold_hash, sizeof(dap_hash_t), l_tx_item); if (l_tx_item) { - json_object_object_add(json_obj_tx, "Hash was found in ledger tx threshold", json_object_new_string(dap_hash_fast_to_str_static(a_threshold_hash))); + json_object_object_add(json_obj_tx, "found_hash", json_object_new_string(dap_hash_fast_to_str_static(a_threshold_hash))); json_object_array_add(json_arr_out, json_obj_tx); } else { - json_object_object_add(json_obj_tx, "Hash wasn't found in ledger", json_object_new_string("empty")); + json_object_object_add(json_obj_tx, "found_hash", json_object_new_string("empty")); json_object_array_add(json_arr_out, json_obj_tx); } } else { @@ -585,7 +585,7 @@ json_object *dap_ledger_balance_info(dap_ledger_t *a_ledger, size_t a_limit, siz } if (!l_counter){ json_object* json_obj_tx = json_object_new_object(); - json_object_object_add(json_obj_tx, "No items in ledger balance_accounts", json_object_new_string("empty")); + json_object_object_add(json_obj_tx, "info_status", json_object_new_string("No items in ledger balance_accounts")); json_object_array_add(json_arr_out, json_obj_tx); } pthread_rwlock_unlock(&l_ledger_pvt->balance_accounts_rwlock); diff --git a/modules/ledger/dap_chain_ledger_token.c b/modules/ledger/dap_chain_ledger_token.c index 251edc83aab7b615739c7eccf7ca1191f704e552..f47346426532c3dcd4f8e36efa761c3ace504989 100644 --- a/modules/ledger/dap_chain_ledger_token.c +++ b/modules/ledger/dap_chain_ledger_token.c @@ -1707,7 +1707,7 @@ json_object *s_token_item_to_json(dap_ledger_token_item_t *a_token_item) l_type_str = "PUBLIC"; break; default: l_type_str = "UNKNOWN"; break; } - json_object_object_add(json_obj_datum, "-->Token name", json_object_new_string(a_token_item->ticker)); + json_object_object_add(json_obj_datum, "token_name", json_object_new_string(a_token_item->ticker)); json_object_object_add(json_obj_datum, "type", json_object_new_string(l_type_str)); if (a_token_item->subtype != DAP_CHAIN_DATUM_TOKEN_SUBTYPE_SIMPLE && a_token_item->subtype != DAP_CHAIN_DATUM_TOKEN_SUBTYPE_PUBLIC) { dap_chain_datum_token_flags_dump_to_json(json_obj_datum, "flags", a_token_item->flags); @@ -1715,11 +1715,11 @@ json_object *s_token_item_to_json(dap_ledger_token_item_t *a_token_item) json_object_new_string(a_token_item->description) : json_object_new_string("The token description is not set")); } - json_object_object_add(json_obj_datum, "Supply current", json_object_new_string(dap_uint256_to_char(a_token_item->current_supply, NULL))); - json_object_object_add(json_obj_datum, "Supply total", json_object_new_string(dap_uint256_to_char(a_token_item->total_supply, NULL))); - json_object_object_add(json_obj_datum, "Decimals", json_object_new_string("18")); - json_object_object_add(json_obj_datum, "Auth signs valid", json_object_new_int(a_token_item->auth_signs_valid)); - json_object_object_add(json_obj_datum, "Auth signs total", json_object_new_int(a_token_item->auth_signs_total)); + json_object_object_add(json_obj_datum, "supply_current", json_object_new_string(dap_uint256_to_char(a_token_item->current_supply, NULL))); + json_object_object_add(json_obj_datum, "supply_total", json_object_new_string(dap_uint256_to_char(a_token_item->total_supply, NULL))); + json_object_object_add(json_obj_datum, "decimals", json_object_new_string("18")); + json_object_object_add(json_obj_datum, "auth_signs_valid", json_object_new_int(a_token_item->auth_signs_valid)); + json_object_object_add(json_obj_datum, "auth_signs_total", json_object_new_int(a_token_item->auth_signs_total)); json_object *l_json_arr_pkeys = json_object_new_array(); for (uint16_t i = 0; i < a_token_item->auth_signs_total; i++) { json_object *l_json_obj_out = json_object_new_object(); @@ -1753,7 +1753,7 @@ json_object *s_token_item_to_json(dap_ledger_token_item_t *a_token_item) const char *l_addr_str = dap_chain_addr_to_str_static(&l_addr); json_object_array_add(l_json_arr_tx_send_block, json_object_new_string(l_addr_str)); } - json_object_object_add(json_obj_datum, "Signatures public keys", l_json_arr_pkeys); + json_object_object_add(json_obj_datum, "signatures_public_keys", l_json_arr_pkeys); a_token_item->tx_recv_allow_size ? json_object_object_add(json_obj_datum, "tx_recv_allow", l_json_arr_tx_recv_allow) : json_object_put(l_json_arr_tx_recv_allow); a_token_item->tx_recv_block_size ? json_object_object_add(json_obj_datum, "tx_recv_block", l_json_arr_tx_recv_block) : @@ -1762,7 +1762,7 @@ json_object *s_token_item_to_json(dap_ledger_token_item_t *a_token_item) json_object_put(l_json_arr_tx_send_allow); a_token_item->tx_send_block_size ? json_object_object_add(json_obj_datum, "tx_send_block", l_json_arr_tx_send_block) : json_object_put(l_json_arr_tx_send_block); - json_object_object_add(json_obj_datum, "Total emissions", json_object_new_int(HASH_COUNT(a_token_item->token_emissions))); + json_object_object_add(json_obj_datum, "total_emissions", json_object_new_int(HASH_COUNT(a_token_item->token_emissions))); return json_obj_datum; } diff --git a/modules/net-srv/dap_chain_net_srv.c b/modules/net-srv/dap_chain_net_srv.c index cbec211df75ecd8048a070b99a4cc98446e9d7f8..fe024885a84b396b0acae79fd0201c771198af5e 100644 --- a/modules/net-srv/dap_chain_net_srv.c +++ b/modules/net-srv/dap_chain_net_srv.c @@ -116,6 +116,7 @@ void dap_chain_net_srv_deinit(void) */ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) { + json_object **json_arr_reply = (json_object **)a_str_reply; int arg_index = 1; dap_chain_net_t * l_net = NULL; @@ -124,23 +125,25 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) if(!l_hash_out_type) l_hash_out_type = "hex"; if(dap_strcmp(l_hash_out_type, "hex") && dap_strcmp(l_hash_out_type, "base58")) { - dap_cli_server_cmd_set_reply_text(a_str_reply, "invalid parameter -H, valid values: -H <hex | base58>"); - return -1; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_HASH_ERR, "invalid parameter -H, valid values: -H <hex | base58>"); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_HASH_ERR; } int l_report = dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "report", NULL); if (l_report) { + json_object* json_obj_net_srv = json_object_new_object(); char *l_report_str = dap_chain_net_srv_ch_create_statistic_report(); - dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_report_str); + json_object_object_add(json_obj_net_srv, "report", json_object_new_string(l_report_str)); DAP_DELETE(l_report_str); - return 0; + + json_object_array_add(*json_arr_reply, json_obj_net_srv); + return DAP_CHAIN_NET_SRV_CLI_COM_ORDER_OK; } - int l_ret = dap_chain_node_cli_cmd_values_parse_net_chain( &arg_index, argc, argv, a_str_reply, NULL, &l_net, - CHAIN_TYPE_INVALID); + int l_ret = dap_chain_node_cli_cmd_values_parse_net_chain_for_json(*json_arr_reply, &arg_index, argc, argv, NULL, &l_net, CHAIN_TYPE_INVALID); + json_object* json_obj_net_srv = NULL; if ( l_net ) { - dap_string_t *l_string_ret = dap_string_new(""); const char *l_order_str = NULL; dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "order", &l_order_str); @@ -193,47 +196,44 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-units", &l_units_str); if (l_order_str){ - char *l_order_hash_hex_str = NULL; - char *l_order_hash_base58_str = NULL; + char l_order_hash_hex_str[128] = "", l_order_hash_base58_str[128] = ""; // datum hash may be in hex or base58 format if (l_order_hash_str) { if(!dap_strncmp(l_order_hash_str, "0x", 2) || !dap_strncmp(l_order_hash_str, "0X", 2)) { - l_order_hash_hex_str = dap_strdup(l_order_hash_str); - l_order_hash_base58_str = dap_enc_base58_from_hex_str_to_str(l_order_hash_str); + dap_strncpy(l_order_hash_hex_str, l_order_hash_str, sizeof(l_order_hash_hex_str)); + char *l_tmp = dap_enc_base58_from_hex_str_to_str(l_order_hash_str); + dap_strncpy(l_order_hash_base58_str, l_tmp, sizeof(l_order_hash_base58_str)); + DAP_DELETE(l_tmp); } else { - l_order_hash_hex_str = dap_enc_base58_to_hex_str_from_str(l_order_hash_str); - l_order_hash_base58_str = dap_strdup(l_order_hash_str); + char *l_tmp = dap_enc_base58_to_hex_str_from_str(l_order_hash_str); + dap_strncpy(l_order_hash_hex_str, l_tmp, sizeof(l_order_hash_hex_str)); + DAP_DELETE(l_tmp); + dap_strncpy(l_order_hash_base58_str, l_order_hash_str, sizeof(l_order_hash_base58_str)); } } if(l_continent_str && l_continent_num <= 0) { dap_string_t *l_string_err = dap_string_new("Unrecognized \"-continent\" option="); dap_string_append_printf(l_string_err, "\"%s\". Variants: ", l_continent_str); - int i = 0; - while(1) { - const char *l_continent = dap_chain_net_srv_order_continent_to_str(i); - if(!l_continent) - break; - if(!i) - dap_string_append_printf(l_string_err, "\"%s\"", l_continent); - else - dap_string_append_printf(l_string_err, ", \"%s\"", l_continent); - i++; - } - dap_string_append_printf(l_string_ret, "%s\n", l_string_err->str); + int i; + for (i = 0; i < (int)dap_chain_net_srv_order_continents_count() - 1; ++i) + dap_string_append_printf(l_string_err, "\"%s\", ", dap_chain_net_srv_order_continent_to_str(i)); + dap_string_append_printf(l_string_err, "\"%s\"", dap_chain_net_srv_order_continent_to_str(i)); + + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CONT_ERR, "%s\n", l_string_err->str); dap_string_free(l_string_err, true); - l_ret = -1; - } else if(!dap_strcmp(l_order_str, "update")) { + l_ret = -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CONT_ERR; + } else if (!dap_strcmp(l_order_str, "update")) { if (!l_order_hash_str) { - l_ret = -1; - dap_string_append(l_string_ret, "Can't find option '-hash'\n"); + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UPDATE_ERR, "Can't find option '-hash'\n"); + l_ret = -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UPDATE_ERR; } else { dap_chain_net_srv_order_t * l_order = dap_chain_net_srv_order_find_by_hash_str(l_net, l_order_hash_hex_str); if(!l_order) { l_ret = -2; if(!dap_strcmp(l_hash_out_type,"hex")) - dap_string_append_printf(l_string_ret, "Can't find order with hash %s\n", l_order_hash_hex_str); + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UPDATE_HASH_ERR, "Can't find order with hash %s\n", l_order_hash_hex_str); else - dap_string_append_printf(l_string_ret, "Can't find order with hash %s\n", l_order_hash_base58_str); + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UPDATE_HASH_ERR, "Can't find order with hash %s\n", l_order_hash_base58_str); } else { if (l_ext) { l_order->ext_size = strlen(l_ext) + 1; @@ -243,33 +243,32 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) memcpy(l_order->ext_n_sign, l_ext, l_order->ext_size); } else dap_chain_net_srv_order_set_continent_region(&l_order, l_continent_num, l_region_str); - /*if(l_region_str) { - strncpy(l_order->region, l_region_str, dap_min(sizeof(l_order->region) - 1, strlen(l_region_str) + 1)); - } - if(l_continent_num>=0) - l_order->continent = l_continent_num;*/ char *l_new_order_hash_str = dap_chain_net_srv_order_save(l_net, l_order, false); if (l_new_order_hash_str) { - const char *l_cert_str = NULL; + /*const char *l_cert_str = NULL; dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-cert", &l_cert_str); if (!l_cert_str) { - dap_cli_server_cmd_set_reply_text(a_str_reply, "Fee order creation requires parameter -cert"); - DAP_DEL_MULTY(l_new_order_hash_str, l_order_hash_hex_str, l_order_hash_base58_str, l_order); - return -7; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UPDATE_PARAM_CERT_ERR, "Fee order creation requires parameter -cert"); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UPDATE_PARAM_CERT_ERR; } dap_cert_t *l_cert = dap_cert_find_by_name(l_cert_str); if (!l_cert) { - dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't load cert %s", l_cert_str); + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UPDATE_LOAD_CERT_ERR, "Can't load cert %s", l_cert_str); DAP_DEL_MULTY(l_new_order_hash_str, l_order_hash_hex_str, l_order_hash_base58_str, l_order); - return -8; + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UPDATE_LOAD_CERT_ERR; } + */ // WTF is this? ^^^ // delete prev order if(dap_strcmp(l_new_order_hash_str, l_order_hash_hex_str)) dap_chain_net_srv_order_delete_by_hash_str_sync(l_net, l_order_hash_hex_str); DAP_DELETE(l_new_order_hash_str); - dap_string_append_printf(l_string_ret, "order updated\n"); - } else - dap_string_append_printf(l_string_ret, "Order did not updated\n"); + json_obj_net_srv = json_object_new_object(); + json_object_object_add(json_obj_net_srv, "status", json_object_new_string("updated")); + + } else { + json_obj_net_srv = json_object_new_object(); + json_object_object_add(json_obj_net_srv, "status", json_object_new_string("not updated")); + } DAP_DELETE(l_order); } } @@ -310,16 +309,16 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) else if (!strcmp(l_direction_str, "buy")) l_direction = SERV_DIR_BUY; else { - dap_string_free(l_string_ret, true); - dap_cli_server_cmd_set_reply_text(a_str_reply, "Wrong direction of the token was " - "specified, possible directions: buy, sell."); - return -18; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_FIND_PARAM_CERT_ERR, "Wrong direction of the token was " + "specified, possible directions: buy, sell."); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_FIND_PARAM_CERT_ERR; } } uint64_t l_64 = 0; if (l_srv_uid_str && dap_id_uint64_parse(l_srv_uid_str, &l_64)) { - dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't recognize '%s' string as 64-bit id, hex or dec.", l_srv_uid_str); - return -21; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_FIND_HEX_ERR, + "Can't recognize '%s' string as 64-bit id, hex or dec.", l_srv_uid_str); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_FIND_HEX_ERR; } l_srv_uid.uint64 = l_64; @@ -338,30 +337,38 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) l_price_min, l_price_max, &l_orders, &l_orders_num) ) { - dap_string_append_printf(l_string_ret, "Found %zu orders:\n", l_orders_num); + json_obj_net_srv = json_object_new_object(); + json_object_object_add(json_obj_net_srv, "count", json_object_new_uint64(l_orders_num)); + json_object* json_arr_out = json_object_new_array(); for (dap_list_t *l_temp = l_orders; l_temp; l_temp = l_temp->next){ + json_object* json_obj_order = json_object_new_object(); dap_chain_net_srv_order_t *l_order = (dap_chain_net_srv_order_t*)l_temp->data; - dap_chain_net_srv_order_dump_to_string(l_order, l_string_ret, l_hash_out_type, l_net->pub.native_ticker); - dap_string_append(l_string_ret,"\n"); + dap_chain_net_srv_order_dump_to_json(l_order, json_obj_order, l_hash_out_type, l_net->pub.native_ticker); + json_object_array_add(json_arr_out, json_obj_order); } + json_object_object_add(json_obj_net_srv, "orders", json_arr_out); l_ret = 0; dap_list_free_full(l_orders, NULL); } else { - l_ret = -5 ; - dap_string_append(l_string_ret,"Can't get orders: some internal error or wrong params\n"); + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_FIND_CANT_GET_ERR, "Can't get orders: some internal error or wrong params"); + l_ret = -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_FIND_CANT_GET_ERR ; } } else if(!dap_strcmp( l_order_str, "dump" )) { // Select with specified service uid if ( l_order_hash_str ){ - dap_chain_net_srv_order_t * l_order = dap_chain_net_srv_order_find_by_hash_str( l_net, l_order_hash_hex_str ); if (l_order) { - dap_chain_net_srv_order_dump_to_string(l_order,l_string_ret, l_hash_out_type, l_net->pub.native_ticker); + dap_chain_net_srv_order_t * l_order = dap_chain_net_srv_order_find_by_hash_str( l_net, l_order_hash_hex_str ); + json_obj_net_srv = json_object_new_object(); + if (l_order) { + dap_chain_net_srv_order_dump_to_json(l_order, json_obj_net_srv, l_hash_out_type, l_net->pub.native_ticker); l_ret = 0; - }else{ - l_ret = -7 ; + } else { if(!dap_strcmp(l_hash_out_type,"hex")) - dap_string_append_printf(l_string_ret,"Can't find order with hash %s\n", l_order_hash_hex_str ); + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_DUMP_CANT_FIND_ERR, + "Can't find order with hash %s\n", l_order_hash_hex_str ); else - dap_string_append_printf(l_string_ret,"Can't find order with hash %s\n", l_order_hash_base58_str ); + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_DUMP_CANT_FIND_ERR, + "Can't find order with hash %s\n", l_order_hash_base58_str ); + l_ret = -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_DUMP_CANT_FIND_ERR; } } else { dap_list_t * l_orders = NULL; @@ -373,38 +380,42 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) dap_chain_net_srv_order_direction_t l_direction = SERV_DIR_UNDEFINED; if( !dap_chain_net_srv_order_find_all_by( l_net,l_direction,l_srv_uid,l_price_unit, NULL, l_price_min, l_price_max,&l_orders,&l_orders_num) ){ - dap_string_append_printf(l_string_ret,"Found %zd orders:\n",l_orders_num); + json_obj_net_srv = json_object_new_object(); + json_object_object_add(json_obj_net_srv, "count", json_object_new_uint64(l_orders_num)); + json_object* json_arr_out = json_object_new_array(); for(dap_list_t *l_temp = l_orders;l_temp; l_temp = l_orders->next) { + json_object* json_obj_order = json_object_new_object(); dap_chain_net_srv_order_t *l_order =(dap_chain_net_srv_order_t *) l_temp->data; - dap_chain_net_srv_order_dump_to_string(l_order, l_string_ret, l_hash_out_type, l_net->pub.native_ticker); - dap_string_append(l_string_ret, "\n"); + dap_chain_net_srv_order_dump_to_json(l_order, json_obj_order, l_hash_out_type, l_net->pub.native_ticker); + json_object_array_add(json_arr_out, json_obj_order); } + json_object_object_add(json_obj_net_srv, "orders", json_arr_out); l_ret = 0; - }else{ - l_ret = -5 ; - dap_string_append(l_string_ret,"Can't get orders: some internal error or wrong params\n"); + } else { + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_FIND_CANT_GET_ERR,"Can't get orders: some internal error or wrong params"); + l_ret = -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_FIND_CANT_GET_ERR ; } dap_list_free_full(l_orders, NULL); } } else if (!dap_strcmp(l_order_str, "delete")) { if (l_order_hash_str) { - + + json_obj_net_srv = json_object_new_object(); l_ret = dap_chain_net_srv_order_delete_by_hash_str_sync(l_net, l_order_hash_hex_str); if (!l_ret) - dap_string_append_printf(l_string_ret, "Deleted order %s\n", l_order_hash_str); + json_object_object_add(json_obj_net_srv, "order_hash", json_object_new_string(l_order_hash_str)); else { - l_ret = -8; - dap_string_append_printf(l_string_ret, "Can't find order with hash %s\n", l_order_hash_str); + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_DEL_CANT_FIND_HASH_ERR, "Can't find order with hash %s\n", l_order_hash_str); + l_ret = -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_DEL_CANT_FIND_HASH_ERR; } } else { - l_ret = -9 ; - dap_string_append(l_string_ret,"need -hash param to obtain what the order we need to dump\n"); + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_DEL_NEED_HASH_PARAM_ERR, "need -hash param to obtain what the order we need to dump\n"); + l_ret = -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_DEL_NEED_HASH_PARAM_ERR; } - } else if(!dap_strcmp( l_order_str, "create" )) { if (dap_chain_net_get_role(l_net).enums > NODE_ROLE_MASTER) { - dap_cli_server_cmd_set_reply_text(a_str_reply, "Node role should be not lower than master\n"); - return -4; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_ROLE_ERR, "Node role should be not lower than master\n"); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_ROLE_ERR; } const char *l_order_cert_name = NULL; dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-cert", &l_order_cert_name); @@ -426,9 +437,9 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) log_it(L_DEBUG, "Created order to buy"); } else { log_it(L_WARNING, "Undefined order direction"); - dap_cli_server_cmd_set_reply_text(a_str_reply, "Wrong direction of the token was " - "specified, possible directions: buy, sell."); - return -18; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_UNDEF_ORDER_DIR_ERR, "Wrong direction of the token was " + "specified, possible directions: buy, sell."); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_UNDEF_ORDER_DIR_ERR; } } @@ -436,11 +447,12 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) l_expires = (dap_time_t ) atoll( l_expires_str); uint64_t l_64 = 0; if (l_srv_uid_str && dap_id_uint64_parse(l_srv_uid_str, &l_64)) { - dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't recognize '%s' string as 64-bit id, hex or dec.", l_srv_uid_str); - return -21; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CANT_RECOGNIZE_ERR, + "Can't recognize '%s' string as 64-bit id, hex or dec.", l_srv_uid_str); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CANT_RECOGNIZE_ERR; } else if (!l_srv_uid_str){ - dap_cli_server_cmd_set_reply_text(a_str_reply, "Parameter -srv_uid is required."); - return -22; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_REQUIRED_PARAM_UID_ERR, "Parameter -srv_uid is required."); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_REQUIRED_PARAM_UID_ERR; } l_srv_uid.uint64 = l_64; if (l_node_addr_str){ @@ -448,10 +460,10 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) dap_chain_node_addr_from_str( &l_node_addr, l_node_addr_str ); } else { log_it(L_ERROR, "Can't parse \"%s\" as node addr", l_node_addr_str); - dap_cli_server_cmd_set_reply_text(a_str_reply, "The order has not been created. " - "Failed to convert string representation of '%s' " - "to node address.", l_node_addr_str); - return -17; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CANT_PARSE_NODE_ADDR_ERR, "The order has not been created. " + "Failed to convert string representation of '%s' " + "to node address.", l_node_addr_str); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CANT_PARSE_NODE_ADDR_ERR; } } else { l_node_addr.uint64 = dap_chain_net_get_cur_addr_int(l_net); @@ -479,12 +491,13 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) l_price_unit.enm = SERV_UNIT_PCS; } else { log_it(L_ERROR, "Undefined price unit"); - dap_cli_server_cmd_set_reply_text(a_str_reply, "Wrong unit type sepcified, possible values: B, KB, MB, SEC, DAY, PCS"); - return -18; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_UNDEF_PRICE_UNIT_ERR, + "Wrong unit type sepcified, possible values: B, KB, MB, SEC, DAY, PCS"); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_UNDEF_PRICE_UNIT_ERR; } strncpy(l_price_token, l_price_token_str, DAP_CHAIN_TICKER_SIZE_MAX - 1); - size_t l_ext_len = l_ext? strlen(l_ext) + 1 : 0; + size_t l_ext_len = l_ext ? strlen(l_ext) + 1 : 0; // get cert to order sign dap_cert_t *l_cert = NULL; dap_enc_key_t *l_key = NULL; @@ -494,41 +507,46 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) l_key = l_cert->enc_key; if (!l_key->priv_key_data || !l_key->priv_key_data_size) { log_it(L_ERROR, "Certificate '%s' doesn't contain a private key", l_order_cert_name); - dap_cli_server_cmd_set_reply_text(a_str_reply, "Certificate '%s' doesn't contain a private key", l_order_cert_name); - return -25; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CERT_WITHOUT_KEY_ERR, + "Certificate '%s' doesn't contain a private key", l_order_cert_name); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CERT_WITHOUT_KEY_ERR; } } else { log_it(L_ERROR, "Can't load cert '%s' for sign order", l_order_cert_name); - dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't load cert '%s' for sign " - "order", l_order_cert_name); - return -19; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CANT_LOAD_CERT_ERR, "Can't load cert '%s' for sign " + "order", l_order_cert_name); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CANT_LOAD_CERT_ERR; } } else { - dap_cli_server_cmd_set_reply_text(a_str_reply, "The certificate name was not " - "specified. Since version 5.2 it is not possible to " - "create unsigned orders."); - return -20; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CERT_NAME_NOT_WALID_ERR, + "The certificate name was not " + "specified. Since version 5.2 it is not possible to " + "create unsigned orders."); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CERT_NAME_NOT_WALID_ERR; } // create order char * l_order_new_hash_str = dap_chain_net_srv_order_create( l_net,l_direction, l_srv_uid, l_node_addr,l_tx_cond_hash, &l_price, l_price_unit, l_price_token, l_expires, (uint8_t *)l_ext, l_ext_len, l_units, l_region_str, l_continent_num, l_key); - if (l_order_new_hash_str) - dap_string_append_printf( l_string_ret, "Created order %s\n", l_order_new_hash_str); - else { - dap_string_append_printf( l_string_ret, "Error! Can't created order\n"); - l_ret = -4; - } + if (l_order_new_hash_str) { + json_obj_net_srv = json_object_new_object(); + json_object_object_add(json_obj_net_srv, "order_hash", json_object_new_string(l_order_new_hash_str)); + DAP_DELETE(l_order_new_hash_str); + } else { + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_ORDER_ERR, + "Error! Can't created order\n"); + l_ret = -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_ORDER_ERR; + } } else { - dap_cli_server_cmd_set_reply_text(a_str_reply, "Missed some required params\n"); - return -5; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_MISSED_PARAM_ERR, + "Missed some required params\n"); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_MISSED_PARAM_ERR; } } else if (l_order_str) { - dap_cli_server_cmd_set_reply_text(a_str_reply, "Unrecognized subcommand '%s'", l_order_str); - return -14; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UNKNOWN_SUB_COM_ERR, + "Unrecognized subcommand '%s'", l_order_str); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UNKNOWN_SUB_COM_ERR; } - dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_string_ret->str); - } else if (l_get_limits_str){ const char *l_provider_pkey_hash_str = NULL; dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-provider_pkey_hash", &l_provider_pkey_hash_str); @@ -537,27 +555,28 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-client_pkey_hash", &l_client_pkey_hash_str); if (!l_provider_pkey_hash_str){ - dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'get_limits' require the parameter provider_pkey_hash"); - dap_string_free(l_string_ret, true); - return -15; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_REQUIRED_PARAM_PPKHASH_ERR, + "Command 'get_limits' require the parameter provider_pkey_hash"); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_REQUIRED_PARAM_PPKHASH_ERR; } if (!l_client_pkey_hash_str){ - dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'get_limits' require the parameter client_pkey_hash"); - dap_string_free(l_string_ret, true); - return -16; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_REQUIRED_PARAM_CPKHASH_ERR, + "Command 'get_limits' require the parameter client_pkey_hash"); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_REQUIRED_PARAM_CPKHASH_ERR; } uint64_t l_64 = 0; if (l_srv_uid_str && dap_id_uint64_parse(l_srv_uid_str, &l_64)) { - dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't recognize '%s' string as 64-bit id, hex or dec.", l_srv_uid_str); - dap_string_free(l_string_ret, true); - return -21; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_CANT_REC_UID_STR_ERR, + "Can't recognize '%s' string as 64-bit id, hex or dec.", l_srv_uid_str); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_CANT_REC_UID_STR_ERR; } else if (!l_srv_uid_str){ - dap_cli_server_cmd_set_reply_text(a_str_reply, "Parameter -srv_uid is required."); - dap_string_free(l_string_ret, true); - return -22; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_REQUIRED_PARAM_UID_ERR, + "Parameter -srv_uid is required."); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_REQUIRED_PARAM_UID_ERR; } + dap_chain_srv_uid_t l_srv_uid= { .uint64 = l_64}; dap_chain_net_srv_ch_remain_service_store_t *l_remain_service = NULL; size_t l_remain_service_size = 0; @@ -569,24 +588,25 @@ static int s_cli_net_srv( int argc, char **argv, void **a_str_reply) DAP_DELETE(l_remain_limits_gdb_group); if(!l_remain_service || !l_remain_service_size){ - dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't get remain service data"); - dap_string_free(l_string_ret, true); - return -21; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_CANT_GET_REM_SERV_DATA_ERR, + "Can't get remain service data"); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_CANT_GET_REM_SERV_DATA_ERR; } + json_obj_net_srv = json_object_new_object(); - dap_cli_server_cmd_set_reply_text(a_str_reply, "Provider %s. Client %s remain service values:\n" - "SEC: %"DAP_UINT64_FORMAT_U"\n" - "BYTES: %"DAP_UINT64_FORMAT_U"\n", l_provider_pkey_hash_str, l_client_pkey_hash_str, - (uint64_t)l_remain_service->limits_ts, (uint64_t)l_remain_service->limits_bytes); - - dap_string_free(l_string_ret, true); + json_object_object_add(json_obj_net_srv, "provider", json_object_new_string(l_provider_pkey_hash_str)); + json_object_object_add(json_obj_net_srv, "client", json_object_new_string(l_client_pkey_hash_str)); + json_object_object_add(json_obj_net_srv, "sec", json_object_new_uint64((uint64_t)l_remain_service->limits_ts)); + json_object_object_add(json_obj_net_srv, "bytes", json_object_new_uint64((uint64_t)l_remain_service->limits_bytes)); DAP_DELETE(l_remain_service); } else { - dap_cli_server_cmd_set_reply_text(a_str_reply, "Unrecognized bcommand."); - dap_string_free(l_string_ret, true); - return -17; + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UNKNOWN, + "Unrecognized command."); + return -DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UNKNOWN; } } + if (json_obj_net_srv != NULL) + json_object_array_add(*json_arr_reply, json_obj_net_srv); return l_ret; } diff --git a/modules/net-srv/dap_chain_net_srv_order.c b/modules/net-srv/dap_chain_net_srv_order.c index c60143ca73f3ec7f839f69efde74d367869b1e06..bc45709734eddfd4afc072f7ffae5c00b6a07f39 100644 --- a/modules/net-srv/dap_chain_net_srv_order.c +++ b/modules/net-srv/dap_chain_net_srv_order.c @@ -241,10 +241,7 @@ size_t dap_chain_net_srv_order_continents_count(void) */ const char* dap_chain_net_srv_order_continent_to_str(int8_t a_num) { - int8_t l_count = dap_chain_net_srv_order_continents_count(); - if(a_num >= l_count) - return NULL; - return s_server_continents[a_num]; + return a_num < (int8_t)dap_chain_net_srv_order_continents_count() ? s_server_continents[a_num] : NULL; } /** @@ -603,7 +600,7 @@ void dap_chain_net_srv_order_dump_to_json(const dap_chain_net_srv_order_t *a_ord : dap_chain_hash_fast_to_str_static(&l_hash); json_object_object_add(a_json_obj_out, "order", json_object_new_string(l_hash_str)); - json_object_object_add(a_json_obj_out, "version", json_object_new_int(a_order->version)); + json_object_object_add(a_json_obj_out, "version", json_object_new_uint64(a_order->version)); switch ( a_order->direction) { case SERV_DIR_UNDEFINED: json_object_object_add(a_json_obj_out, "direction", json_object_new_string("SERV_DIR_UNDEFINED")); break; @@ -620,16 +617,20 @@ void dap_chain_net_srv_order_dump_to_json(const dap_chain_net_srv_order_t *a_ord json_object_object_add(a_json_obj_out, "srv_uid", json_object_new_string(buf_srv_uid)); const char *l_balance_coins, *l_balance = dap_uint256_to_char(a_order->price, &l_balance_coins); + json_object_object_add(a_json_obj_out, "created", json_object_new_string(buf_time)); json_object_object_add(a_json_obj_out, "price_coins", json_object_new_string(l_balance_coins)); json_object_object_add(a_json_obj_out, "price_datoshi", json_object_new_string(l_balance)); - json_object_object_add(a_json_obj_out, "price_token", json_object_new_string((*a_order->price_ticker) ? a_order->price_ticker: a_native_ticker)); - json_object_object_add(a_json_obj_out, "units", json_object_new_int(a_order->units)); - if( a_order->price_unit.uint32 ) + json_object_object_add(a_json_obj_out, "price_token", (*a_order->price_ticker) ? + json_object_new_string(a_order->price_ticker) : + json_object_new_string(a_native_ticker)); + json_object_object_add(a_json_obj_out, "units", json_object_new_uint64(a_order->units)); + + if( a_order->price_unit.uint32) json_object_object_add(a_json_obj_out, "price_unit", json_object_new_string(dap_chain_net_srv_price_unit_uid_to_str(a_order->price_unit))); if ( a_order->node_addr.uint64) { - char buf_node_addr[64]; - snprintf(buf_node_addr, sizeof(buf_node_addr), ""NODE_ADDR_FP_STR"", NODE_ADDR_FP_ARGS_S(a_order->node_addr)); - json_object_object_add(a_json_obj_out, "node_addr", json_object_new_string(buf_node_addr)); + char *node_addr = dap_strdup_printf(""NODE_ADDR_FP_STR"", NODE_ADDR_FP_ARGS_S(a_order->node_addr)); + json_object_object_add(a_json_obj_out, "node_addr", json_object_new_string(node_addr)); + DAP_DELETE(node_addr); } char *l_region = NULL; @@ -637,9 +638,10 @@ void dap_chain_net_srv_order_dump_to_json(const dap_chain_net_srv_order_t *a_ord const char *l_continent_str = NULL; if(dap_chain_net_srv_order_get_continent_region(a_order, &l_continent_num, &l_region)) l_continent_str = dap_chain_net_srv_order_continent_to_str(l_continent_num); - char buf_location[64]; - snprintf(buf_location, sizeof(buf_location), "%s - %s", l_continent_str ? l_continent_str : "None" , l_region ? l_region : "None"); - json_object_object_add(a_json_obj_out, "node_location", json_object_new_string(buf_location)); + char *node_location = dap_strdup_printf("%s - %s", l_continent_str ? l_continent_str : "None" , l_region ? l_region : "None"); + json_object_object_add(a_json_obj_out, "node_location", json_object_new_string(node_location)); + DAP_DELETE(node_location); + DAP_DELETE(l_region); if (!dap_hash_fast_is_blank(&a_order->tx_cond_hash)){ diff --git a/modules/net-srv/include/dap_chain_net_srv.h b/modules/net-srv/include/dap_chain_net_srv.h index 96419afec90657805df3a9157c285e2df89c8dba..00d42e96a99775609f977c7906ad86e0fa92e78e 100755 --- a/modules/net-srv/include/dap_chain_net_srv.h +++ b/modules/net-srv/include/dap_chain_net_srv.h @@ -206,6 +206,49 @@ DAP_STATIC_INLINE bool dap_chain_net_srv_uid_compare_scalar(const dap_chain_srv_ return a_uid1.uint64 == a_id; } +typedef enum s_com_net_srv_err{ + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_OK = 0, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_HASH_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CONT_ERR, + + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UPDATE_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UPDATE_HASH_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UPDATE_PARAM_CERT_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UPDATE_LOAD_CERT_ERR, + + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_FIND_PARAM_CERT_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_FIND_HEX_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_FIND_CANT_GET_ERR, + + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_DUMP_CANT_FIND_ERR, + + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_DEL_CANT_FIND_HASH_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_DEL_NEED_HASH_PARAM_ERR, + + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_ROLE_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_UNDEF_ORDER_DIR_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CANT_RECOGNIZE_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_REQUIRED_PARAM_UID_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CANT_PARSE_NODE_ADDR_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_UNDEF_PRICE_UNIT_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CERT_WITHOUT_KEY_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CANT_LOAD_CERT_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_CERT_NAME_NOT_WALID_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_ORDER_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_CREATE_MISSED_PARAM_ERR, + + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_REQUIRED_PARAM_PPKHASH_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_REQUIRED_PARAM_CPKHASH_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_CANT_REC_UID_STR_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_REQUIRED_PARAM_UID_ERR, + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_GETLIM_CANT_GET_REM_SERV_DATA_ERR, + + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UNKNOWN_SUB_COM_ERR, + + DAP_CHAIN_NET_SRV_CLI_COM_ORDER_UNKNOWN + +} s_com_net_srv_err_t; + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c index 1cce569acc254d1938839639e282bd40c8ac8689..a32dfbcdbdf2b32d1237cbb62eb0c1030b432a8e 100644 --- a/modules/net/dap_chain_net.c +++ b/modules/net/dap_chain_net.c @@ -611,7 +611,7 @@ json_object *s_net_sync_status(dap_chain_net_t *a_net) json_object *l_jobj_total = json_object_new_uint64(l_chain->atom_num_last); json_object_object_add(l_jobj_chain, "status", l_jobj_chain_status); json_object_object_add(l_jobj_chain, "current", l_jobj_current); - json_object_object_add(l_jobj_chain, "in network", l_jobj_total); + json_object_object_add(l_jobj_chain, "in_network", l_jobj_total); json_object_object_add(l_jobj_chain, "percent", l_jobj_percent); json_object_object_add(l_jobj_chains_array, l_chain->name, l_jobj_chain); diff --git a/modules/net/dap_chain_net_tx.c b/modules/net/dap_chain_net_tx.c index 0c7deec0d1c81360d1088321ac458325a7411773..7561efa2602144e47e1b2dfaa161517e0fbc0cdd 100644 --- a/modules/net/dap_chain_net_tx.c +++ b/modules/net/dap_chain_net_tx.c @@ -1667,16 +1667,16 @@ int dap_chain_net_tx_to_json(dap_chain_datum_tx_t *a_tx, json_object *a_out_json } if (l_voting_params->voting_expire) { dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, l_voting_params->voting_expire); - json_object_object_add(json_obj_item,"Voting expire", json_object_new_string(l_tmp_buf)); + json_object_object_add(json_obj_item,"voting_expire", json_object_new_string(l_tmp_buf)); } if (l_voting_params->votes_max_count) { - json_object_object_add(json_obj_item, "Votes max count", json_object_new_uint64(l_voting_params->votes_max_count)); + json_object_object_add(json_obj_item, "votes_max_count", json_object_new_uint64(l_voting_params->votes_max_count)); } - json_object_object_add(json_obj_item,"Changing vote is", l_voting_params->vote_changing_allowed ? json_object_new_string("available") : + json_object_object_add(json_obj_item,"changing_vote_is", l_voting_params->vote_changing_allowed ? json_object_new_string("available") : json_object_new_string("not available")); l_voting_params->delegate_key_required ? - json_object_object_add(json_obj_item,"Delegated key for participating in voting", json_object_new_string("required")): - json_object_object_add(json_obj_item,"Delegated key for participating in voting", json_object_new_string("not required")); + json_object_object_add(json_obj_item,"delegated_key_for_participating_in_voting", json_object_new_string("required")): + json_object_object_add(json_obj_item,"delegated_key_for_participating_in_voting", json_object_new_string("not required")); dap_list_free_full(l_voting_params->options, NULL); DAP_DELETE(l_voting_params->question); diff --git a/modules/node-cli/dap_chain_node_cli_cmd.c b/modules/node-cli/dap_chain_node_cli_cmd.c index 455ac9f06db69a7f5328d2e5e628b19c9dc3a31c..bd940670a7bd985a622307f7791ab0e1f3717fc1 100644 --- a/modules/node-cli/dap_chain_node_cli_cmd.c +++ b/modules/node-cli/dap_chain_node_cli_cmd.c @@ -414,7 +414,7 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) switch (res_flush) { case 0: json_obj_flush = json_object_new_object(); - json_object_object_add(json_obj_flush, "command status", json_object_new_string("Commit data base and filesystem caches to disk completed.\n\n")); + json_object_object_add(json_obj_flush, "command_status", json_object_new_string("Commit data base and filesystem caches to disk completed.\n\n")); json_object_array_add(*a_json_arr_reply, json_obj_flush); break; case -1: @@ -496,11 +496,11 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) json_object_put(json_obj_rec); return -DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_MEMORY_ERR; } - json_object_object_add(json_obj_rec, "command status", json_object_new_string("Commit data base and filesystem caches to disk completed.")); + json_object_object_add(json_obj_rec, "command_status", json_object_new_string("Commit data base and filesystem caches to disk completed.")); dap_bin2hex(l_value_str, l_value, l_value_len); - json_object_object_add(json_obj_rec, "command status", json_object_new_string("Record found")); - json_object_object_add(json_obj_rec, "lenght(byte)", json_object_new_uint64(l_value_len)); + json_object_object_add(json_obj_rec, "command_status", json_object_new_string("Record found")); + json_object_object_add(json_obj_rec, "lenght_byte", json_object_new_uint64(l_value_len)); json_object_object_add(json_obj_rec, "hash", json_object_new_string(dap_get_data_hash_str(l_value, l_value_len).s)); json_object_object_add(json_obj_rec, "pinned", l_is_pinned ? json_object_new_string("Yes") : json_object_new_string("No") ); json_object_object_add(json_obj_rec, "value", json_object_new_string(l_value_str)); @@ -510,11 +510,11 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) case SUMCMD_PIN: // Pin record { if(l_is_pinned){ - json_object_object_add(json_obj_rec, "pinned status", json_object_new_string("record already pinned")); + json_object_object_add(json_obj_rec, "pinned_status", json_object_new_string("record already pinned")); break; } if(dap_global_db_pin_sync( l_group, l_key) ==0 ){ - json_object_object_add(json_obj_rec, "pinned status", json_object_new_string("record successfully pinned")); + json_object_object_add(json_obj_rec, "pinned_status", json_object_new_string("record successfully pinned")); } else{ dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_RECORD_NOT_PINED, @@ -526,11 +526,11 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) case SUMCMD_UNPIN: // Unpin record { if(!l_is_pinned) { - json_object_object_add(json_obj_rec, "unpinned status", json_object_new_string("record already unpinned")); + json_object_object_add(json_obj_rec, "unpinned_status", json_object_new_string("record already unpinned")); break; } if(dap_global_db_unpin_sync(l_group,l_key) == 0 ) { - json_object_object_add(json_obj_rec, "unpinned status", json_object_new_string("record successfully unpinned")); + json_object_object_add(json_obj_rec, "unpinned_status", json_object_new_string("record successfully unpinned")); } else { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_RECORD_NOT_UNPINED, @@ -577,7 +577,7 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) if (!dap_global_db_set_sync(l_group_str, l_key_str, l_value_str, strlen(l_value_str) +1 , false)) { json_object* json_obj_write = json_object_new_object(); - json_object_object_add(json_obj_write, "write status", json_object_new_string("Data has been successfully written to the database")); + json_object_object_add(json_obj_write, "write_status", json_object_new_string("Data has been successfully written to the database")); json_object_array_add(*a_json_arr_reply, json_obj_write); return DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_OK; } else { @@ -623,8 +623,8 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) json_object_object_add(json_obj_read, "group", json_object_new_string(l_group_str)); json_object_object_add(json_obj_read, "key", json_object_new_string(l_key_str)); json_object_object_add(json_obj_read, "time", json_object_new_string(l_ts_str)); - json_object_object_add(json_obj_read, "value len", json_object_new_uint64(l_out_len)); - json_object_object_add(json_obj_read, "value hex", json_object_new_string(l_value_hexdump_new)); + json_object_object_add(json_obj_read, "value_len", json_object_new_uint64(l_out_len)); + json_object_object_add(json_obj_read, "value_hex", json_object_new_string(l_value_hexdump_new)); DAP_DELETE(l_value_hexdump_new); } else { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_TIME_NO_VALUE, @@ -690,17 +690,17 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) } dap_global_db_objs_delete(l_obj, l_objs_count); json_object* json_obj_del = json_object_new_object(); - json_object_object_add(json_obj_del, "Removed records", json_object_new_uint64(j)); - json_object_object_add(json_obj_del, "of records", json_object_new_uint64(i)); - json_object_object_add(json_obj_del, "in table", json_object_new_string(l_group_str)); + json_object_object_add(json_obj_del, "removed_records", json_object_new_uint64(j)); + json_object_object_add(json_obj_del, "of_records", json_object_new_uint64(i)); + json_object_object_add(json_obj_del, "in_table", json_object_new_string(l_group_str)); json_object_array_add(*a_json_arr_reply, json_obj_del); return DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_OK; } if (!dap_global_db_del_sync_ex(l_group_str, l_key_str, DAP_GLOBAL_DB_MANUAL_DEL, strlen(DAP_GLOBAL_DB_MANUAL_DEL)+1)) { json_object* json_obj_del = json_object_new_object(); - json_object_object_add(json_obj_del, "Record key", json_object_new_string(l_key_str)); - json_object_object_add(json_obj_del, "Group name", json_object_new_string(l_group_str)); + json_object_object_add(json_obj_del, "record_key", json_object_new_string(l_key_str)); + json_object_object_add(json_obj_del, "group_name", json_object_new_string(l_group_str)); json_object_object_add(json_obj_del, "status", json_object_new_string("deleted")); json_object_array_add(*a_json_arr_reply, json_obj_del); return DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_OK; @@ -723,7 +723,7 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) if (!dap_global_db_erase_table_sync(l_group_str)) { json_object* json_obj_drop = json_object_new_object(); - json_object_object_add(json_obj_drop, "Dropped table", json_object_new_string(l_group_str)); + json_object_object_add(json_obj_drop, "dropped_table", json_object_new_string(l_group_str)); json_object_array_add(*a_json_arr_reply, json_obj_drop); return DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_OK; } else { @@ -765,8 +765,8 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) dap_store_obj_free(l_objs, l_objs_count); json_object* json_keys_list = json_object_new_object(); - json_object_object_add(json_keys_list, "group name", json_object_new_string(l_group_str)); - json_object_object_add(json_keys_list, "keys list", json_arr_keys); + json_object_object_add(json_keys_list, "group_name", json_object_new_string(l_group_str)); + json_object_object_add(json_keys_list, "keys_list", json_arr_keys); json_object_array_add(*a_json_arr_reply, json_keys_list); return DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_OK; } @@ -782,8 +782,8 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) json_object_new_uint64(dap_global_db_driver_count((char*)l_list->data, c_dap_global_db_driver_hash_blank, false))); json_object_array_add(json_arr_group, json_obj_list); } - json_object_object_add(json_group_list, "group list", json_arr_group); - json_object_object_add(json_group_list, "total count", json_object_new_uint64(l_count)); + json_object_object_add(json_group_list, "group_list", json_arr_group); + json_object_object_add(json_group_list, "total_count", json_object_new_uint64(l_count)); json_object_array_add(*a_json_arr_reply, json_group_list); dap_list_free(l_group_list); return DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_OK; @@ -1504,7 +1504,7 @@ static void s_wallet_list(const char *a_wallet_path, json_object *a_json_arr_out dap_chain_wallet_t *l_wallet = dap_chain_wallet_open(l_file_name, a_wallet_path, &res); if (l_wallet) { - json_object_object_add(json_obj_wall, "Wallet", json_object_new_string(l_file_name)); + json_object_object_add(json_obj_wall, "wallet", json_object_new_string(l_file_name)); if(l_wallet->flags & DAP_WALLET$M_FL_ACTIVE) json_object_object_add(json_obj_wall, "status", json_object_new_string("protected-active")); else @@ -1513,12 +1513,12 @@ static void s_wallet_list(const char *a_wallet_path, json_object *a_json_arr_out strlen(dap_chain_wallet_check_sign(l_wallet))!=0 ? "true" : "false")); dap_chain_wallet_close(l_wallet); } else{ - json_object_object_add(json_obj_wall, "Wallet", json_object_new_string(l_file_name)); + json_object_object_add(json_obj_wall, "wallet", json_object_new_string(l_file_name)); if(res==4)json_object_object_add(json_obj_wall, "status", json_object_new_string("protected-inactive")); else if(res != 0)json_object_object_add(json_obj_wall, "status", json_object_new_string("invalid")); } } else if ((l_file_name_len > 7) && (!strcmp(l_file_name + l_file_name_len - 7, ".backup"))) { - json_object_object_add(json_obj_wall, "Wallet", json_object_new_string(l_file_name)); + json_object_object_add(json_obj_wall, "wallet", json_object_new_string(l_file_name)); json_object_object_add(json_obj_wall, "status", json_object_new_string("Backup")); } json_object_array_add(a_json_arr_out, json_obj_wall); @@ -1846,7 +1846,7 @@ int l_arg_index = 1, l_rc, cmd_num = CMD_NONE; switch (l_rc) { case 0: - json_object_object_add(json_obj_wall, "Wallet name", json_object_new_string(l_wallet_name)); + json_object_object_add(json_obj_wall, "wallet_name", json_object_new_string(l_wallet_name)); json_object_object_add(json_obj_wall, "protection", cmd_num == CMD_WALLET_ACTIVATE ? json_object_new_string("is activated") : json_object_new_string("is deactivated")); // Notify about wallet @@ -1932,11 +1932,11 @@ int l_arg_index = 1, l_rc, cmd_num = CMD_NONE; } json_object * json_obj_wall = json_object_new_object(); log_it(L_INFO, "Wallet %s has been converted", l_wallet_name); - json_object_object_add(json_obj_wall, "Sign wallet", json_object_new_string( + json_object_object_add(json_obj_wall, "sign_wallet", json_object_new_string( strlen(dap_chain_wallet_check_sign(l_wallet))!=0 ? dap_chain_wallet_check_sign(l_wallet) : "correct")); - json_object_object_add(json_obj_wall, "Wallet name", json_object_new_string(l_wallet_name)); - json_object_object_add(json_obj_wall, "Status", json_object_new_string("successfully converted")); + json_object_object_add(json_obj_wall, "wallet_name", json_object_new_string(l_wallet_name)); + json_object_object_add(json_obj_wall, "status", json_object_new_string("successfully converted")); dap_chain_wallet_close(l_wallet); json_object_array_add(json_arr_out, json_obj_wall); break; @@ -2064,22 +2064,22 @@ int l_arg_index = 1, l_rc, cmd_num = CMD_NONE; } json_object * json_obj_wall = json_object_new_object(); - json_object_object_add(json_obj_wall, "Wallet name", json_object_new_string(l_wallet->name)); + json_object_object_add(json_obj_wall, "wallet_name", json_object_new_string(l_wallet->name)); if (l_sign_count > 1) { dap_string_t *l_signs_types_str = dap_string_new("sig_multi_chained, "); for (size_t i = 0; i < l_sign_count; i++) { dap_string_append_printf(l_signs_types_str, "%s%s", dap_sign_type_to_str(l_sign_types[i]), (i+1) == l_sign_count ? "": ", "); } - json_object_object_add(json_obj_wall, "Sign type", json_object_new_string(l_signs_types_str->str)); + json_object_object_add(json_obj_wall, "sign_type", json_object_new_string(l_signs_types_str->str)); dap_string_free(l_signs_types_str, true); } else - json_object_object_add(json_obj_wall, "Sign type", json_object_new_string(l_sign_type_str)); - json_object_object_add(json_obj_wall, "Status", json_object_new_string("successfully created")); + json_object_object_add(json_obj_wall, "sign_type", json_object_new_string(l_sign_type_str)); + json_object_object_add(json_obj_wall, "status", json_object_new_string("successfully created")); dap_chain_addr_t *l_addr = dap_chain_wallet_get_addr(l_wallet, l_net->pub.id); if (l_net && l_addr) - json_object_object_add(json_obj_wall, "new address", json_object_new_string(dap_chain_addr_to_str_static(l_addr))); + json_object_object_add(json_obj_wall, "new_address", json_object_new_string(dap_chain_addr_to_str_static(l_addr))); DAP_DEL_Z(l_addr); json_object_array_add(json_arr_out, json_obj_wall); dap_chain_wallet_close(l_wallet); @@ -4566,7 +4566,7 @@ int com_stats(int argc, char **a_argv, void **a_str_reply) } json_object* json_obj_total = json_object_new_object(); l_str_delimiter = dap_strdup_printf("%f%%", s_cpu_stats.cpu_summary.load); - json_object_object_add(json_obj_total, "Total", json_object_new_string(l_str_delimiter)); + json_object_object_add(json_obj_total, "total", json_object_new_string(l_str_delimiter)); json_object_array_add(json_arr_cpu_out, json_obj_total); DAP_DELETE(l_str_delimiter); json_object_array_add(*a_json_arr_reply, json_arr_cpu_out); @@ -6091,7 +6091,7 @@ int com_policy(int argc, char **argv, void **reply) { // if cmd none - only print preaparing result if (l_cmd == CMD_NONE) { json_object *l_answer = dap_chain_policy_json_collect(l_policy); - json_object_object_add(l_answer, "Notification", json_object_new_string("It's policy draft, check and use 'execute' command to apply")); + json_object_object_add(l_answer, "notification", json_object_new_string("It's policy draft, check and use 'execute' command to apply")); if (l_answer) { json_object_array_add(*a_json_arr_reply, l_answer); } else { diff --git a/modules/node-cli/dap_chain_node_cli_cmd_tx.c b/modules/node-cli/dap_chain_node_cli_cmd_tx.c index 9fe0571014fbd153ff241e29e3f822a73c95eddc..14a6733b942c13fbbe8380904989c7bee7c212cf 100644 --- a/modules/node-cli/dap_chain_node_cli_cmd_tx.c +++ b/modules/node-cli/dap_chain_node_cli_cmd_tx.c @@ -888,7 +888,7 @@ json_object *dap_db_history_tx_all(json_object* a_json_arr_reply, dap_chain_t *a json_object_put(json_arr_out); return NULL; } - json_object_object_add(json_tx_history, "tx number", json_object_new_uint64(l_count+1)); + json_object_object_add(json_tx_history, "tx_number", json_object_new_uint64(l_count+1)); json_object_array_add(json_arr_out, json_tx_history); ++i_tmp; l_count++; @@ -950,7 +950,7 @@ static json_object* dap_db_chain_history_token_list(json_object* a_json_arr_repl l_jobj_ticker = json_object_new_object(); dap_ledger_t *l_ledger = dap_chain_net_by_id(a_chain->net_id)->pub.ledger; json_object *l_current_state = dap_ledger_token_info_by_name(l_ledger, l_token->ticker); - json_object_object_add(l_jobj_ticker, "current state", l_current_state); + json_object_object_add(l_jobj_ticker, "current_state", l_current_state); l_jobj_decls = json_object_new_array(); l_jobj_updates = json_object_new_array(); json_object_object_add(l_jobj_ticker, "declarations", l_jobj_decls); @@ -964,7 +964,7 @@ static json_object* dap_db_chain_history_token_list(json_object* a_json_arr_repl int l_ret_code = l_datum_iter->ret_code; json_object* json_history_token = json_object_new_object(); json_object_object_add(json_history_token, "status", json_object_new_string(l_ret_code ? "DECLINED" : "ACCEPTED")); - json_object_object_add(json_history_token, "Ledger return code", json_object_new_int(l_ret_code)); + json_object_object_add(json_history_token, "ledger_return_code", json_object_new_int(l_ret_code)); switch (l_token->type) { case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE: case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PUBLIC: @@ -1581,7 +1581,8 @@ int com_tx_create(int a_argc, char **a_argv, void **a_json_arr_reply) // int cmd_num = 1; // const char *value_str = NULL; const char *addr_base58_to = NULL; - const char *str_tmp = NULL; + const char * l_fee_str = NULL; + const char * l_value_str = NULL; const char * l_from_wallet_name = NULL; const char * l_wallet_fee_name = NULL; const char * l_token_ticker = NULL; @@ -1630,14 +1631,14 @@ int com_tx_create(int a_argc, char **a_argv, void **a_json_arr_reply) l_tx_num = strtoul(l_tx_num_str, NULL, 10); // Validator's fee - if (dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-fee", &str_tmp)) { - if (!str_tmp) { + if (dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-fee", &l_fee_str)) { + if (!l_fee_str) { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_CREATE_REQUIRE_FEE, "tx_create requires parameter '-fee'"); return DAP_CHAIN_NODE_CLI_COM_TX_CREATE_REQUIRE_FEE; } - l_value_fee = dap_chain_balance_scan(str_tmp); + l_value_fee = dap_chain_balance_scan(l_fee_str); } - if (IS_ZERO_256(l_value_fee) && (!l_emission_hash_str || (str_tmp && strcmp(str_tmp, "0")))) { + if (IS_ZERO_256(l_value_fee) && (!l_emission_hash_str || (l_fee_str && strcmp(l_fee_str, "0")))) { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_CREATE_REQUIRE_FEE_IS_UINT256, "tx_create requires parameter '-fee' to be valid uint256"); return DAP_CHAIN_NODE_CLI_COM_TX_CREATE_REQUIRE_FEE_IS_UINT256; } @@ -1715,17 +1716,17 @@ int com_tx_create(int a_argc, char **a_argv, void **a_json_arr_reply) return DAP_CHAIN_NODE_CLI_COM_TX_CREATE_TOKEN_NOT_DECLARATED_IN_NET; } dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-to_addr", &addr_base58_to); - dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-value", &str_tmp); + dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-value", &l_value_str); if (!addr_base58_to) { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_CREATE_REQUIRE_PARAMETER_TO_ADDR, "tx_create requires parameter '-to_addr'"); return DAP_CHAIN_NODE_CLI_COM_TX_CREATE_REQUIRE_PARAMETER_TO_ADDR; } - if (!str_tmp) { + if (!l_value_str) { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_CREATE_REQUIRE_PARAMETER_VALUE_OR_INVALID_FORMAT_VALUE, "tx_create requires parameter '-value' to be valid uint256 value"); return DAP_CHAIN_NODE_CLI_COM_TX_CREATE_REQUIRE_PARAMETER_VALUE_OR_INVALID_FORMAT_VALUE; } l_addr_el_count = dap_str_symbol_count(addr_base58_to, ',') + 1; - l_value_el_count = dap_str_symbol_count(str_tmp, ',') + 1; + l_value_el_count = dap_str_symbol_count(l_value_str, ',') + 1; if (l_addr_el_count != l_value_el_count) { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_CREATE_REQUIRE_PARAMETER_VALUE_OR_INVALID_FORMAT_VALUE, "num of '-to_addr' and '-value' should be equal"); @@ -1737,7 +1738,7 @@ int com_tx_create(int a_argc, char **a_argv, void **a_json_arr_reply) dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_MEMORY_ERR, c_error_memory_alloc); return DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_MEMORY_ERR; } - char **l_value_array = dap_strsplit(str_tmp, ",", l_value_el_count); + char **l_value_array = dap_strsplit(l_value_str, ",", l_value_el_count); if (!l_value_array) { DAP_DELETE(l_value); dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_PARAM_ERR, "Can't read '-to_addr' arg"); @@ -2201,7 +2202,7 @@ int com_tx_history(int a_argc, char ** a_argv, void **a_str_reply) return DAP_CHAIN_NODE_CLI_COM_TX_HISTORY_OK; } else if (l_is_tx_count) { json_object * json_count_obj= json_object_new_object(); - json_object_object_add(json_count_obj, "Number of transaction", json_object_new_uint64(l_chain->callback_count_tx(l_chain))); + json_object_object_add(json_count_obj, "number_of_transaction", json_object_new_uint64(l_chain->callback_count_tx(l_chain))); json_object_array_add(*a_json_arr_reply, json_count_obj); return DAP_CHAIN_NODE_CLI_COM_TX_HISTORY_OK; } diff --git a/modules/service/stake/dap_chain_net_srv_stake_pos_delegate.c b/modules/service/stake/dap_chain_net_srv_stake_pos_delegate.c index 0ecbbd43cecd43dc58adc649b1c87472a55c654f..63a91272c32ba8d39d78815ade8cf478d8599f6f 100644 --- a/modules/service/stake/dap_chain_net_srv_stake_pos_delegate.c +++ b/modules/service/stake/dap_chain_net_srv_stake_pos_delegate.c @@ -3078,8 +3078,8 @@ static void s_srv_stake_print(dap_chain_net_srv_stake_item_t *a_stake, uint256_t json_object_object_add(l_json_obj_stake, "sovereign_tax", json_object_new_string(l_sov_tax_str)); if (s_debug_more) { json_object_object_add(l_json_obj_stake, "debug_info", NULL); - json_object_object_add(l_json_obj_stake, "\tpkey_full", json_object_new_string(a_stake->pkey ? "true" : "false")); - json_object_object_add(l_json_obj_stake, "\tdecree_hash", json_object_new_string(dap_hash_fast_to_str_static(&a_stake->decree_hash))); + json_object_object_add(l_json_obj_stake, "pkey_full", json_object_new_string(a_stake->pkey ? "true" : "false")); + json_object_object_add(l_json_obj_stake, "decree_hash", json_object_new_string(dap_hash_fast_to_str_static(&a_stake->decree_hash))); } if (dap_chain_esbocs_started(a_stake->signing_addr.net_id)) json_object_object_add(l_json_obj_stake, "active", json_object_new_string(a_stake->is_active ? "true" : "false")); @@ -4045,7 +4045,7 @@ static json_object* s_dap_chain_net_srv_stake_reward_all(json_object* a_json_arr dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(DAP_CHAIN_CS_BLOCKS(a_chain), &l_in_reward->block_hash); json_arr_sign_out = json_object_new_array(); json_block_hash = json_object_new_object(); - json_object_object_add(json_block_hash, "block hash", json_object_new_string(dap_chain_hash_fast_to_str_static(&l_in_reward->block_hash))); + json_object_object_add(json_block_hash, "block_hash", json_object_new_string(dap_chain_hash_fast_to_str_static(&l_in_reward->block_hash))); dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, 0); size_t l_sign_size = dap_sign_get_size(l_sign); dap_chain_hash_fast_t l_pkey_hash; @@ -4059,8 +4059,8 @@ static json_object* s_dap_chain_net_srv_stake_reward_all(json_object* a_json_arr DAP_DELETE(l_block_sign_pkey); const char *l_coins_str, *l_value_str = dap_uint256_to_char(l_value_reward, &l_coins_str); - json_object_object_add(json_obj_sign, "reward value", json_object_new_string(l_value_str)); - json_object_object_add(json_obj_sign, "reward coins", json_object_new_string(l_coins_str)); + json_object_object_add(json_obj_sign, "reward_value", json_object_new_string(l_value_str)); + json_object_object_add(json_obj_sign, "reward_coins", json_object_new_string(l_coins_str)); if (json_object_object_length(json_obj_sign)) json_object_array_add(json_arr_sign_out, json_obj_sign); SUM_256_256(l_value_total_calc, l_value_reward, &l_value_total_calc); @@ -4071,8 +4071,8 @@ static json_object* s_dap_chain_net_srv_stake_reward_all(json_object* a_json_arr const char *l_coins_t_out_str, *l_value_t_str; json_object* json_value_t_out = json_object_new_object(); l_value_t_str = dap_uint256_to_char(l_value_total_calc, &l_coins_t_out_str); - json_object_object_add(json_value_t_out, "Rewards value (calculated)", json_object_new_string(l_value_t_str)); - json_object_object_add(json_value_t_out, "Rewards coins (calculated)", json_object_new_string(l_coins_t_out_str)); + json_object_object_add(json_value_t_out, "rewards_value_calculated", json_object_new_string(l_value_t_str)); + json_object_object_add(json_value_t_out, "rewards_coins_calculated", json_object_new_string(l_coins_t_out_str)); json_object_array_add(json_obj_reward, json_value_t_out); } @@ -4080,8 +4080,8 @@ static json_object* s_dap_chain_net_srv_stake_reward_all(json_object* a_json_arr json_object* json_value_out = json_object_new_object(); SUM_256_256(l_value_total, l_value_out, &l_value_total); l_value_str = dap_uint256_to_char(l_value_out, &l_coins_out_str); - json_object_object_add(json_value_out, "Rewards value (tx_out)", json_object_new_string(l_value_str)); - json_object_object_add(json_value_out, "Rewards coins (tx_out)", json_object_new_string(l_coins_out_str)); + json_object_object_add(json_value_out, "rewards_value_tx_out", json_object_new_string(l_value_str)); + json_object_object_add(json_value_out, "rewards_coins_tx_out", json_object_new_string(l_coins_out_str)); json_object_array_add(json_obj_reward, json_value_out); i_tmp++; dap_list_free(l_list_in_items); @@ -4089,8 +4089,8 @@ static json_object* s_dap_chain_net_srv_stake_reward_all(json_object* a_json_arr const char *l_coins_out_str, *l_value_str; json_object* json_value_out = json_object_new_object(); l_value_str = dap_uint256_to_char(l_value_total, &l_coins_out_str); - json_object_object_add(json_value_out, "Rewards value (total)", json_object_new_string(l_value_str)); - json_object_object_add(json_value_out, "Rewards coins (total)", json_object_new_string(l_coins_out_str)); + json_object_object_add(json_value_out, "rewards_value_total", json_object_new_string(l_value_str)); + json_object_object_add(json_value_out, "rewards_coins_total", json_object_new_string(l_coins_out_str)); json_object_array_add(json_obj_reward, json_value_out); a_chain->callback_datum_iter_delete(l_datum_iter); return json_obj_reward; diff --git a/modules/service/voting/dap_chain_net_srv_voting.c b/modules/service/voting/dap_chain_net_srv_voting.c index d2c2ad09d5e861b075a654b71a473033b396536c..e4c4a55cc157dee21d9d0178e53fdf6951f473c6 100644 --- a/modules/service/voting/dap_chain_net_srv_voting.c +++ b/modules/service/voting/dap_chain_net_srv_voting.c @@ -630,7 +630,7 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) switch (res) { case DAP_CHAIN_NET_VOTE_CREATE_OK: { json_object* json_obj_inf = json_object_new_object(); - json_object_object_add(json_obj_inf, "Datum add successfully", json_object_new_string(l_hash_ret)); + json_object_object_add(json_obj_inf, "datum_add_successfully", json_object_new_string(l_hash_ret)); json_object_array_add(*json_arr_reply, json_obj_inf); DAP_DELETE(l_hash_ret); return DAP_CHAIN_NET_VOTE_CREATE_OK; @@ -768,7 +768,7 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) switch (res) { case DAP_CHAIN_NET_VOTE_VOTING_OK: { json_object* json_obj_inf = json_object_new_object(); - json_object_object_add(json_obj_inf, "Datum add successfully to mempool", json_object_new_string(l_hash_tx)); + json_object_object_add(json_obj_inf, "datum_add_successfully", json_object_new_string(l_hash_tx)); json_object_array_add(*json_arr_reply, json_obj_inf); DAP_DELETE(l_hash_tx); return DAP_CHAIN_NET_VOTE_CREATE_OK; @@ -845,7 +845,7 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) case CMD_LIST: { json_object* json_vote_out = json_object_new_object(); - json_object_object_add(json_vote_out, "List of votings in net", json_object_new_string(l_net->pub.name)); + json_object_object_add(json_vote_out, "list_of_votings", json_object_new_string(l_net->pub.name)); json_object* json_arr_voting_out = json_object_new_array(); struct voting *votings_ht = s_votings_ht_get(l_net->pub.id); for (struct voting *it = votings_ht; it; it = it->hh.next) { diff --git a/modules/service/xchange/dap_chain_net_srv_xchange.c b/modules/service/xchange/dap_chain_net_srv_xchange.c index bdaf28d69d446c1529bd5f138cfd2ae67eaca637..2cfa21a90a5bd639c82a90ee2b3d759b369f1994 100644 --- a/modules/service/xchange/dap_chain_net_srv_xchange.c +++ b/modules/service/xchange/dap_chain_net_srv_xchange.c @@ -117,7 +117,7 @@ static bool s_string_append_tx_cond_info( dap_string_t * a_reply_str, dap_chain_ dap_hash_fast_t *a_tx_hash, tx_opt_status_t a_filter_by_status, bool a_append_prev_hash, bool a_print_status,bool a_print_ts); static bool s_string_append_tx_cond_info_json( json_object * a_json_out, dap_chain_net_t * a_net, - dap_chain_addr_t *a_owner_addr, dap_chain_addr_t *a_buyer_addr, dap_chain_datum_tx_t * a_tx, + dap_chain_addr_t *a_owner_addr, dap_chain_addr_t *a_buyer_addr, dap_chain_datum_tx_t * a_tx, dap_hash_fast_t *a_tx_hash, tx_opt_status_t a_filter_by_status, bool a_print_prev_hash, bool a_print_status, bool a_print_ts); dap_chain_net_srv_xchange_price_t *s_xchange_price_from_order(dap_chain_net_t *a_net, dap_chain_datum_tx_t *a_order, @@ -1495,52 +1495,45 @@ static int s_cli_srv_xchange_order(int a_argc, char **a_argv, int a_arg_index, j HASH_FIND(hh, l_cache->cache, l_iter->cur_hash, sizeof(dap_hash_fast_t), l_item); if (!l_item) continue; - json_object* l_json_order = json_object_new_object(); - if (s_string_append_tx_cond_info_json(l_json_order, l_net, &l_item->seller_addr, + if (s_string_append_tx_cond_info_json(l_json_obj_order, l_net, &l_item->seller_addr, l_item->tx_type == TX_TYPE_EXCHANGE ? &l_item->tx_info.exchange_info.buyer_addr : NULL, - l_datum_tx, TX_STATUS_ALL, true, true, false)) { - + l_datum_tx, l_iter->cur_hash, TX_STATUS_ALL, true, true, false)) l_total++; - } else { - if (s_string_append_tx_cond_info_json(l_json_order, l_net, NULL, NULL, l_datum_tx, TX_STATUS_ALL, true, true, false)) - l_total++; - } - json_object_array_add(l_json_order_arr, l_json_order); - } + } else { + if (s_string_append_tx_cond_info_json(l_json_obj_order, l_net, NULL, NULL, l_datum_tx, l_iter->cur_hash, + TX_STATUS_ALL, true, true, false)) + l_total++; + } } dap_chain_wallet_cache_iter_delete(l_iter); - json_object_object_add(l_json_obj_order, "orders", l_json_order_arr); + if(!l_total) dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_HIST_DOES_NO_HISTORY_ERR, "No history"); else { char *l_orders = dap_strdup_printf("Found %"DAP_UINT64_FORMAT_U, l_total); - json_object_object_add(l_json_obj_order, "number of orders", json_object_new_string(l_orders)); + json_object_object_add(l_json_obj_order, "number_of_orders", json_object_new_string(l_orders)); DAP_DELETE(l_orders); } - + json_object_array_add(*a_json_arr_reply, l_json_obj_order); } else { dap_list_t *l_tx_list = dap_chain_net_get_tx_cond_all_for_addr(l_net,l_addr, c_dap_chain_net_srv_xchange_uid ); if (l_tx_list){ dap_list_t *l_tx_list_temp = l_tx_list; l_json_obj_order = json_object_new_object(); - json_object* l_json_order_arr = json_object_new_array(); - json_object_object_add(l_json_obj_order, "Wallet %s history:\n\n", json_object_new_string(l_addr_hash_str)); - + json_object_object_add(l_json_obj_order, "wallet", json_object_new_string(l_addr_hash_str)); while(l_tx_list_temp ){ dap_chain_datum_tx_t * l_tx_cur = (dap_chain_datum_tx_t*) l_tx_list_temp->data; dap_hash_fast_t l_hash = {}; dap_hash_fast(l_tx_cur, dap_chain_datum_tx_get_size(l_tx_cur), &l_hash); - json_object* l_json_order = json_object_new_object(); - if (s_string_append_tx_cond_info_json(l_json_order, l_net, NULL, NULL, l_tx_cur, TX_STATUS_ALL, true, true, false)) + if ( s_string_append_tx_cond_info_json(l_json_obj_order, l_net, NULL, NULL, l_tx_cur, &l_hash, TX_STATUS_ALL, true, true, false) ) l_total++; l_tx_list_temp = l_tx_list_temp->next; - json_object_array_add(l_json_order_arr, l_json_order); } - json_object_object_add(l_json_obj_order, "orders", l_json_order_arr); dap_list_free(l_tx_list); char *l_orders = dap_strdup_printf("Found %"DAP_UINT64_FORMAT_U, l_total); - json_object_object_add(l_json_obj_order, "number of orders", json_object_new_string(l_orders)); + json_object_object_add(l_json_obj_order, "number_of_orders", json_object_new_string(l_orders)); + json_object_array_add(*a_json_arr_reply, l_json_obj_order); DAP_DELETE(l_orders); }else{ dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_HIST_DOES_NO_HISTORY_ERR, "No history"); @@ -1559,51 +1552,47 @@ static int s_cli_srv_xchange_order(int a_argc, char **a_argv, int a_arg_index, j if( l_tx){ xchange_tx_type_t l_tx_type = dap_chain_net_srv_xchange_tx_get_type(l_net->pub.ledger, l_tx, NULL, NULL, NULL); char *l_tx_hash = dap_chain_hash_fast_to_str_new(&l_order_tx_hash); - if(l_tx_type != TX_TYPE_ORDER){ - json_object_object_add(l_json_obj_order, "datum status", json_object_new_string("is not order")); - json_object_object_add(l_json_obj_order, "datum hash", json_object_new_string(l_tx_hash)); + if (l_tx_type != TX_TYPE_ORDER){ + json_object_object_add(l_json_obj_order, "datum_status", json_object_new_string("is not order")); + json_object_object_add(l_json_obj_order, "datum_hash", json_object_new_string(l_tx_hash)); } else { dap_chain_net_srv_xchange_order_status_t l_rc = s_tx_check_for_open_close(l_net,l_tx); if(l_rc == XCHANGE_ORDER_STATUS_UNKNOWN){ - json_object_object_add(l_json_obj_order, "WRONG TX", json_object_new_string(l_tx_hash)); + json_object_object_add(l_json_obj_order, "WRONG_TX", json_object_new_string(l_tx_hash)); }else{ + json_object_object_add(l_json_obj_order, "history for order", json_object_new_string(l_order_hash_str)); dap_list_t *l_tx_list = dap_chain_net_get_tx_cond_chain(l_net, &l_order_tx_hash, c_dap_chain_net_srv_xchange_uid ); dap_list_t *l_tx_list_temp = l_tx_list; - json_object* l_json_obj_tx_arr = json_object_new_array(); while(l_tx_list_temp ){ - json_object* l_json_obj_cur_tx = json_object_new_object(); dap_chain_datum_tx_t * l_tx_cur = (dap_chain_datum_tx_t*) l_tx_list_temp->data; dap_hash_fast_t l_hash = {}; dap_hash_fast(l_tx_cur, dap_chain_datum_tx_get_size(l_tx_cur), &l_hash); - s_string_append_tx_cond_info_json(l_json_obj_cur_tx, l_net, NULL, NULL, l_tx_cur, TX_STATUS_ALL, true, true, false); - json_object_array_add(l_json_obj_tx_arr, l_json_obj_cur_tx); + s_string_append_tx_cond_info_json(l_json_obj_order, l_net, NULL, NULL, l_tx_cur, &l_hash, TX_STATUS_ALL, true, true, false); l_tx_list_temp = l_tx_list_temp->next; } - json_object_object_add(l_json_obj_order, "history for order", l_json_obj_tx_arr); dap_list_free(l_tx_list); } } - }else + DAP_DELETE(l_tx_hash); + } else { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_HIST_DOES_NO_HISTORY_ERR, "No history"); + } } else { - xchange_orders_cache_net_t* l_cache = NULL; dap_list_t *l_tx_cache_list = NULL; l_cache = s_get_xchange_cache_by_net_id(l_net->pub.id); xchange_tx_cache_t* l_item = NULL; - dap_hash_fast_t l_cur_hash = l_order_tx_hash; + dap_hash_fast_t l_cur_hash = l_order_tx_hash; + l_json_obj_order = json_object_new_object(); HASH_FIND(hh, l_cache->cache, &l_cur_hash, sizeof(dap_hash_fast_t), l_item); if (!l_item){ dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_HIST_DOES_NO_HISTORY_ERR, "No history"); return -DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_HIST_DOES_NO_HISTORY_ERR; } - json_object* l_json_obj_tx_arr = json_object_new_array(); while(l_item){ - json_object* l_json_obj_cur_tx = json_object_new_object(); - s_string_append_tx_cond_info_json(l_json_obj_cur_tx, l_net, &l_item->seller_addr, + s_string_append_tx_cond_info_json(l_json_obj_order, l_net, &l_item->seller_addr, l_item->tx_type == TX_TYPE_EXCHANGE ? &l_item->tx_info.exchange_info.buyer_addr : NULL, - l_item->tx, TX_STATUS_ALL, true, true, false); - json_object_array_add(l_json_obj_tx_arr, l_json_obj_cur_tx); + l_item->tx, &l_item->hash, TX_STATUS_ALL, true, true, false); switch(l_item->tx_type){ case TX_TYPE_ORDER:{ l_cur_hash = l_item->tx_info.order_info.next_hash; @@ -1620,7 +1609,6 @@ static int s_cli_srv_xchange_order(int a_argc, char **a_argv, int a_arg_index, j break; HASH_FIND(hh, l_cache->cache, &l_cur_hash, sizeof(dap_hash_fast_t), l_item); } - json_object_object_add(l_json_obj_order, "history for order", l_json_obj_tx_arr); } } json_object_array_add(*a_json_arr_reply, l_json_obj_order); @@ -1630,6 +1618,7 @@ static int s_cli_srv_xchange_order(int a_argc, char **a_argv, int a_arg_index, j { const char * l_order_hash_str = NULL; const char * l_fee_str = NULL; + json_object* json_obj_order = NULL; dap_cli_server_cmd_find_option_val(a_argv, l_arg_index, a_argc, "-net", &l_net_str); if (!l_net_str) { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_RMOVE_REQ_PARAM_NET_ERR, "Command 'order %s' requires parameter -net", @@ -1675,13 +1664,12 @@ static int s_cli_srv_xchange_order(int a_argc, char **a_argv, int a_arg_index, j dap_chain_hash_fast_from_str(l_order_hash_str, &l_tx_hash); char *l_tx_hash_ret = NULL; int l_ret_code = dap_chain_net_srv_xchange_remove(l_net, &l_tx_hash, l_fee, l_wallet, &l_tx_hash_ret); - json_object* json_obj_order = NULL; dap_chain_wallet_close(l_wallet); switch (l_ret_code) { case XCHANGE_REMOVE_ERROR_OK: json_obj_order = json_object_new_object(); json_object_object_add(json_obj_order, "status", json_object_new_string("Order successfully removed")); - json_object_object_add(json_obj_order, "Created inactivate tx with hash", json_object_new_string(l_tx_hash_ret)); + json_object_object_add(json_obj_order, "created_inactivate_tx_with_hash", json_object_new_string(l_tx_hash_ret)); json_object_array_add(*a_json_arr_reply, json_obj_order); DAP_DELETE(l_tx_hash_ret); break; @@ -1731,13 +1719,8 @@ static int s_cli_srv_xchange_order(int a_argc, char **a_argv, int a_arg_index, j dap_hash_fast_t l_order_tx_hash = {}; dap_chain_hash_fast_from_str(l_order_hash_str, &l_order_tx_hash); - char *l_cp_rate; - char* l_status_order = NULL; - const char *l_token_buy = NULL; - const char *l_token_sell = NULL; - const char *l_owner_addr = NULL; - const char *l_amount_coins_str = NULL, *l_amount_datoshi_str = NULL, - *l_proposed_coins_str = NULL, *l_proposed_datoshi_str = NULL; + char *l_status_order = NULL, *l_token_buy = NULL, *l_token_sell = NULL, *l_owner_addr = NULL; + const char *l_cp_rate, *l_amount_coins_str = NULL, *l_amount_datoshi_str = NULL, *l_proposed_coins_str = NULL, *l_proposed_datoshi_str = NULL; uint64_t l_percent_completed = 0; dap_chain_datum_tx_t *l_tx = NULL; uint256_t l_amount, l_rate, l_proposed; @@ -1754,6 +1737,11 @@ static int s_cli_srv_xchange_order(int a_argc, char **a_argv, int a_arg_index, j "Can't find order %s", l_order_hash_str); return -DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_STATUS_CANT_FIND_ORDER_ERR; } + if (l_item->tx_type != TX_TYPE_ORDER){ + dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_STATUS_ITS_NOT_ORDER_ERR, + "Item is not an order"); + return DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_STATUS_ITS_NOT_ORDER_ERR; + } switch (l_item->tx_info.order_info.order_status) { @@ -1775,10 +1763,13 @@ static int s_cli_srv_xchange_order(int a_argc, char **a_argv, int a_arg_index, j l_token_buy = l_item->buy_token; l_proposed = l_item->tx_info.order_info.value; - l_percent_completed = l_item->tx_info.order_info.percent_completed; + uint256_t l_completed = {}; + SUBTRACT_256_256(l_item->tx_info.order_info.value, l_item->tx_info.order_info.value_ammount, &l_completed); + DIV_256_COIN(l_completed, l_item->tx_info.order_info.value, &l_completed); + MULT_256_COIN(l_completed, dap_chain_balance_coins_scan("100.0"), &l_completed); - l_amount_datoshi_str = dap_uint256_to_char(l_item->tx_info.order_info.value_ammount, &l_amount_coins_str); - l_owner_addr = dap_chain_addr_to_str_static(&l_item->seller_addr); + l_percent_completed = dap_chain_balance_to_coins_uint64(l_completed); + l_owner_addr = dap_strdup(dap_chain_addr_to_str(&l_item->seller_addr)); } else { l_tx = dap_ledger_tx_find_by_hash(l_net->pub.ledger, &l_order_tx_hash); if (!l_tx){ @@ -1801,7 +1792,6 @@ static int s_cli_srv_xchange_order(int a_argc, char **a_argv, int a_arg_index, j return -DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_STATUS_ITS_NOT_ORDER_ERR; } - dap_chain_tx_out_cond_t *l_out_cond = dap_chain_datum_tx_out_cond_get(l_tx, DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE , NULL); if (!l_out_cond || l_out_cond->header.srv_uid.uint64 != DAP_CHAIN_NET_SRV_XCHANGE_ID){ dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_STATUS_ITS_NOT_ORDER_ERR, @@ -1857,49 +1847,42 @@ static int s_cli_srv_xchange_order(int a_argc, char **a_argv, int a_arg_index, j l_status_order = "UNKNOWN"; break; }; - l_owner_addr = dap_chain_addr_to_str_static(&l_price->creator_addr); - DAP_DEL_Z(l_price); + l_owner_addr = dap_strdup(dap_chain_addr_to_str(&l_price->creator_addr)); + DAP_DELETE(l_price); } char l_tmp_buf[DAP_TIME_STR_SIZE]; dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, l_tx->header.ts_created); - l_amount_datoshi_str = dap_uint256_uninteger_to_char(l_amount); - l_amount_coins_str = dap_uint256_decimal_to_char(l_amount); - l_proposed_coins_str = dap_uint256_decimal_to_char(l_proposed); - l_proposed_datoshi_str = dap_uint256_uninteger_to_char(l_proposed); - l_cp_rate = dap_chain_balance_coins_print(l_rate); - json_object* json_obj_order = json_object_new_object(); - - json_object_object_add(json_obj_order, "orderHash", json_object_new_string(l_order_hash_str)); + json_object_object_add(json_obj_order, "order_hash", json_object_new_string(l_order_hash_str)); json_object_object_add(json_obj_order, "ts_created", json_object_new_string(l_tmp_buf)); json_object_object_add(json_obj_order, "status", json_object_new_string(l_status_order)); - json_object_object_add(json_obj_order, "amount coins", l_amount_coins_str ? json_object_new_string(l_amount_coins_str) - : json_object_new_string("0.0")); - json_object_object_add(json_obj_order, "amount datoshi", l_amount_datoshi_str ? json_object_new_string(l_amount_datoshi_str) - : json_object_new_string("0")); - json_object_object_add(json_obj_order, "token", json_object_new_string(l_token_sell)); - char *l_filled = dap_strdup_printf("%lu%%", l_percent_completed); - json_object_object_add(json_obj_order, "filled", json_object_new_string(l_filled)); - DAP_DELETE(l_filled); - json_object_object_add(json_obj_order, "token buy", json_object_new_string(l_token_buy)); - json_object_object_add(json_obj_order, "token sell", json_object_new_string(l_token_sell)); + + l_proposed_datoshi_str = dap_uint256_to_char(l_proposed, &l_proposed_coins_str); + json_object_object_add(json_obj_order, "proposed_coins", json_object_new_string(*l_proposed_coins_str ? l_proposed_coins_str : "0.0")); + json_object_object_add(json_obj_order, "proposed_datoshi", json_object_new_string(*l_proposed_datoshi_str ? l_proposed_datoshi_str : "0")); + + l_amount_datoshi_str = dap_uint256_to_char(l_amount, &l_amount_coins_str); + json_object_object_add(json_obj_order, "amount_coins", json_object_new_string(*l_amount_coins_str ? l_amount_coins_str : "0.0")); + json_object_object_add(json_obj_order, "amount_datoshi", json_object_new_string(*l_amount_datoshi_str ? l_amount_datoshi_str : "0")); + json_object_object_add(json_obj_order, "filled_percent", json_object_new_uint64(l_percent_completed)); + json_object_object_add(json_obj_order, "token_buy", json_object_new_string(l_token_buy)); + json_object_object_add(json_obj_order, "token_sell", json_object_new_string(l_token_sell)); + + dap_uint256_to_char(l_rate, &l_cp_rate); json_object_object_add(json_obj_order, "rate", json_object_new_string(l_cp_rate)); + json_object_object_add(json_obj_order, "net", json_object_new_string(l_net->pub.name)); - json_object_object_add(json_obj_order, "owner addr", json_object_new_string(l_owner_addr ? l_owner_addr : "unknown")); json_object_array_add(*a_json_arr_reply, json_obj_order); - - DAP_DEL_Z(l_cp_rate); - DAP_DEL_Z(l_amount_coins_str); - DAP_DEL_Z(l_amount_datoshi_str); - DAP_DEL_Z(l_proposed_coins_str); - DAP_DEL_Z(l_proposed_datoshi_str); + DAP_DELETE(l_owner_addr); + if ( s_xchange_cache_state != XCHANGE_CACHE_ENABLED ) + DAP_DEL_MULTY(l_token_buy, l_token_sell); } break; default: { - dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_SUB_NOT_FOUND_ERR, - "Subcommand %s not recognized", a_argv[a_arg_index]); + dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_SUB_NOT_FOUND_ERR, + "Subcommand %s not recognized", a_argv[a_arg_index]); return -DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_SUB_NOT_FOUND_ERR; } } @@ -2037,210 +2020,6 @@ static dap_chain_net_srv_xchange_order_status_t s_tx_check_for_open_close(dap_ch return XCHANGE_ORDER_STATUS_UNKNOWN; } -/** - * @brief Append tx info to the reply string - * @param a_reply_str - * @param a_net - * @param a_tx - */ -static bool s_string_append_tx_cond_info( dap_string_t * a_reply_str, dap_chain_net_t * a_net, - dap_chain_addr_t *a_owner_addr, dap_chain_addr_t *a_buyer_addr, - dap_chain_datum_tx_t * a_tx, dap_hash_fast_t *a_tx_hash, - tx_opt_status_t a_filter_by_status, - bool a_print_prev_hash, bool a_print_status, bool a_print_ts) -{ - size_t l_tx_size = dap_chain_datum_tx_get_size(a_tx); - - const char *l_tx_hash_str = dap_chain_hash_fast_to_str_static(a_tx_hash); - // Get input token ticker - const char * l_tx_input_ticker = dap_ledger_tx_get_token_ticker_by_hash( - a_net->pub.ledger, a_tx_hash); - if(!l_tx_input_ticker){ - log_it(L_WARNING, "Can't get ticker from tx"); - return false; - } - dap_chain_tx_out_cond_t *l_out_prev_cond_item = NULL; - dap_chain_tx_out_cond_t *l_out_cond_item = NULL; - int l_cond_idx = 0; - - xchange_tx_type_t l_tx_type = dap_chain_net_srv_xchange_tx_get_type(a_net->pub.ledger, a_tx, &l_out_cond_item, &l_cond_idx, &l_out_prev_cond_item); - - bool l_is_closed = dap_ledger_tx_hash_is_used_out_item(a_net->pub.ledger, a_tx_hash, l_cond_idx, NULL); - if ((a_filter_by_status == TX_STATUS_ACTIVE && l_is_closed) || (a_filter_by_status == TX_STATUS_INACTIVE && !l_is_closed) - || (a_filter_by_status == TX_STATUS_ACTIVE && l_tx_type == TX_TYPE_INVALIDATE)) - return false; - - if(l_out_prev_cond_item && l_out_prev_cond_item->header.subtype != DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE) - return false; - - switch(l_tx_type){ - case TX_TYPE_ORDER:{ - if (!l_out_cond_item) { - log_it(L_ERROR, "Can't find conditional output"); - return false; - } - char *l_rate_str = dap_chain_balance_coins_print(l_out_cond_item->subtype.srv_xchange.rate); - const char *l_amount_str, *l_amount_datoshi_str = dap_uint256_to_char(l_out_cond_item->header.value, &l_amount_str); - - dap_string_append_printf(a_reply_str, "Hash: %s\n", l_tx_hash_str); - if(a_print_ts){ - char l_tmp_buf[DAP_TIME_STR_SIZE]; - dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, a_tx->header.ts_created); - dap_string_append_printf(a_reply_str, " ts_created: %s", l_tmp_buf); - } - if( a_print_status) - dap_string_append_printf(a_reply_str, " Status: %s,", l_is_closed ? "inactive" : "active"); - dap_string_append_printf(a_reply_str, " proposed %s (%s) %s for exchange to %s,", l_amount_str, l_amount_datoshi_str, l_tx_input_ticker, l_out_cond_item->subtype.srv_xchange.buy_token); - dap_string_append_printf(a_reply_str, " rate (%s/%s): %s, net: %s", l_out_cond_item->subtype.srv_xchange.buy_token, l_tx_input_ticker, l_rate_str, a_net->pub.name); - dap_chain_addr_t l_owner_addr = {}; - if (!a_owner_addr){ - l_owner_addr = l_out_cond_item ? l_out_cond_item->subtype.srv_xchange.seller_addr : (l_out_prev_cond_item ? l_out_prev_cond_item->subtype.srv_xchange.seller_addr : (dap_chain_addr_t){0}); - } else { - l_owner_addr = *a_owner_addr; - } - - dap_string_append_printf(a_reply_str, "\nowner addr %s \n", dap_chain_addr_to_str_static(&l_owner_addr)); - DAP_DELETE(l_rate_str); - } break; - case TX_TYPE_EXCHANGE:{ - dap_chain_tx_in_cond_t *l_in_cond - = (dap_chain_tx_in_cond_t*)dap_chain_datum_tx_item_get(a_tx, NULL, NULL, TX_ITEM_TYPE_IN_COND , NULL); - char l_tx_prev_cond_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; - dap_hash_fast_to_str(&l_in_cond->header.tx_prev_hash, l_tx_prev_cond_hash_str, sizeof(l_tx_prev_cond_hash_str)); - - if (!l_out_prev_cond_item) { - log_it(L_ERROR, "Can't find previous transaction"); - return false; - } - - uint256_t l_rate = l_out_cond_item - ? l_out_cond_item->subtype.srv_xchange.rate - : l_out_prev_cond_item->subtype.srv_xchange.rate, - l_value_from = {}, l_value_to = {}; - - if (l_out_cond_item) - SUBTRACT_256_256(l_out_prev_cond_item->header.value, l_out_cond_item->header.value, &l_value_from); - else - l_value_from = l_out_prev_cond_item->header.value; - MULT_256_COIN(l_value_from, l_rate, &l_value_to); - - char *l_buy_ticker = l_out_cond_item - ? l_out_cond_item->subtype.srv_xchange.buy_token - : l_out_prev_cond_item->subtype.srv_xchange.buy_token; - - dap_string_append_printf(a_reply_str, "Hash: %s\n", l_tx_hash_str); - if(a_print_ts){ - char l_tmp_buf[DAP_TIME_STR_SIZE]; - dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, a_tx->header.ts_created); - dap_string_append_printf(a_reply_str, " ts_created: %s", l_tmp_buf); - } - if(a_print_status) - dap_string_append_printf(a_reply_str, " Status: %s,", l_is_closed ? "inactive" : "active"); - - const char *l_value_from_str, *l_value_from_datoshi_str = dap_uint256_to_char(l_value_from, &l_value_from_str); - dap_string_append_printf(a_reply_str, " changed %s (%s) %s", l_value_from_str, l_value_from_datoshi_str, l_tx_input_ticker); - - const char *l_value_to_str, *l_value_to_datoshi_str = dap_uint256_to_char(l_value_to, &l_value_to_str); - dap_string_append_printf(a_reply_str, " for %s (%s) %s,", l_value_to_str, l_value_to_datoshi_str, l_buy_ticker); - - const char *l_rate_str; dap_uint256_to_char(l_rate, &l_rate_str); - dap_string_append_printf(a_reply_str, " rate (%s/%s): %s,", l_buy_ticker, l_tx_input_ticker, l_rate_str); - - const char *l_amount_str = NULL, - *l_amount_datoshi_str = l_out_cond_item ? dap_uint256_to_char(l_out_cond_item->header.value, &l_amount_str) : "0"; - dap_string_append_printf(a_reply_str, " remain amount %s (%s) %s, net: %s", l_amount_str ? l_amount_str : "0.0", - l_amount_datoshi_str, l_tx_input_ticker, a_net->pub.name); - if (a_print_prev_hash) - dap_string_append_printf(a_reply_str, "\n Prev cond: %s", l_tx_prev_cond_hash_str); - - dap_chain_tx_out_cond_subtype_t l_cond_type = l_out_cond_item ? l_out_cond_item->header.subtype : l_out_prev_cond_item->header.subtype; - dap_hash_fast_t l_order_hash = dap_ledger_get_first_chain_tx_hash(a_net->pub.ledger, l_cond_type, a_tx_hash); - if ( dap_hash_fast_is_blank(&l_order_hash) ) - l_order_hash = l_in_cond->header.tx_prev_hash; - char l_order_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; - dap_hash_fast_to_str(&l_order_hash, l_order_hash_str, sizeof(l_order_hash_str)); - dap_string_append_printf(a_reply_str, "\norder hash: %s\n", l_order_hash_str); - - dap_chain_addr_t l_owner_addr = {}; - if (!a_owner_addr){ - l_owner_addr = l_out_cond_item ? l_out_cond_item->subtype.srv_xchange.seller_addr : (l_out_prev_cond_item ? l_out_prev_cond_item->subtype.srv_xchange.seller_addr : (dap_chain_addr_t){0}); - } else { - l_owner_addr = *a_owner_addr; - } - dap_string_append_printf(a_reply_str, "owner addr: %s \n", dap_chain_addr_to_str_static(&l_owner_addr)); - - dap_chain_addr_t l_buyer_addr = {}; - if(!a_buyer_addr){ - dap_chain_tx_sig_t *l_tx_sig = (dap_chain_tx_sig_t *)dap_chain_datum_tx_item_get(a_tx, NULL, NULL, TX_ITEM_TYPE_SIG, NULL); - dap_sign_t *l_sign = dap_chain_datum_tx_item_sig_get_sign((dap_chain_tx_sig_t *)l_tx_sig); - dap_enc_key_t *l_key_buyer = dap_sign_to_enc_key(l_sign); - dap_chain_addr_fill_from_key(&l_buyer_addr, l_key_buyer, a_net->pub.id); - dap_enc_key_delete(l_key_buyer); - } else - l_buyer_addr = *a_buyer_addr; - dap_string_append_printf(a_reply_str, "buyer addr: %s \n", dap_chain_addr_to_str_static(&l_buyer_addr)); - - } break; - case TX_TYPE_INVALIDATE:{ - dap_chain_tx_in_cond_t * l_in_cond = (dap_chain_tx_in_cond_t *)dap_chain_datum_tx_item_get(a_tx, NULL, NULL, TX_ITEM_TYPE_IN_COND , NULL); - char l_tx_prev_cond_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; - dap_hash_fast_to_str(&l_in_cond->header.tx_prev_hash,l_tx_prev_cond_hash_str, sizeof(l_tx_prev_cond_hash_str)); - - if (!l_out_prev_cond_item) { - log_it(L_ERROR, "Can't find previous transaction"); - return false; - } - - dap_chain_datum_tx_t *l_prev_tx = dap_ledger_tx_find_by_hash(a_net->pub.ledger, &l_in_cond->header.tx_prev_hash); - if (!l_prev_tx) - return false; - - int l_out_num = l_in_cond->header.tx_out_prev_idx; - dap_chain_tx_out_cond_t *l_out_cond = dap_chain_datum_tx_out_cond_get(l_prev_tx, DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE, &l_out_num); - if (!l_out_cond) { - log_it(L_ERROR, "Can't find datum tx"); - return false; - } - dap_hash_fast_t l_order_hash = dap_ledger_get_first_chain_tx_hash(a_net->pub.ledger, DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE, &l_in_cond->header.tx_prev_hash); - if ( dap_hash_fast_is_blank(&l_order_hash) ) - l_order_hash = l_in_cond->header.tx_prev_hash; - - char *l_value_from_str = dap_chain_balance_coins_print(l_out_prev_cond_item->header.value); - char *l_value_from_datoshi_str = dap_chain_balance_datoshi_print(l_out_prev_cond_item->header.value); - - dap_string_append_printf(a_reply_str, "Hash: %s\n", l_tx_hash_str); - if(a_print_ts){ - char l_tmp_buf[DAP_TIME_STR_SIZE]; - dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, a_tx->header.ts_created); - dap_string_append_printf(a_reply_str, " ts_created: %s", l_tmp_buf); - } - if (a_print_status) - dap_string_append_printf(a_reply_str, " Status: inactive,"); - - char l_order_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; - dap_hash_fast_to_str(&l_order_hash, l_order_hash_str, sizeof(l_order_hash_str)); - dap_string_append_printf(a_reply_str, " returned %s(%s) %s to owner from order %s\n", l_value_from_str, l_value_from_datoshi_str, l_tx_input_ticker, l_order_hash_str); - if(a_print_prev_hash) - dap_string_append_printf(a_reply_str, "\n Prev cond: %s", l_tx_prev_cond_hash_str); - - dap_chain_addr_t l_owner_addr = {}; - if (!a_owner_addr){ - l_owner_addr = l_out_cond_item ? l_out_cond_item->subtype.srv_xchange.seller_addr : (l_out_prev_cond_item ? l_out_prev_cond_item->subtype.srv_xchange.seller_addr : (dap_chain_addr_t){0}); - } else { - l_owner_addr = *a_owner_addr; - } - dap_string_append_printf(a_reply_str, "owner addr %s \n", dap_chain_addr_to_str_static(&l_owner_addr)); - - DAP_DELETE(l_value_from_str); - DAP_DELETE(l_value_from_datoshi_str); - } break; - default: return false; - } - - dap_string_append_printf(a_reply_str, "\n\n"); - return true; -} - /** * @brief Append tx info to the reply string * @param a_json_out @@ -2252,19 +2031,16 @@ static bool s_string_append_tx_cond_info_json( json_object * a_json_out, dap_chain_addr_t *a_owner_addr, dap_chain_addr_t *a_buyer_addr, dap_chain_datum_tx_t * a_tx, + dap_hash_fast_t *a_tx_hash, tx_opt_status_t a_filter_by_status, bool a_print_prev_hash, bool a_print_status, bool a_print_ts) { - size_t l_tx_size = dap_chain_datum_tx_get_size(a_tx); - - dap_hash_fast_t l_tx_hash = {0}; - dap_hash_fast(a_tx, l_tx_size, &l_tx_hash); - const char *l_tx_hash_str = dap_chain_hash_fast_to_str_static(&l_tx_hash); + const char *l_tx_hash_str = dap_chain_hash_fast_to_str_static(a_tx_hash); // Get input token ticker const char * l_tx_input_ticker = dap_ledger_tx_get_token_ticker_by_hash( - a_net->pub.ledger, &l_tx_hash); + a_net->pub.ledger, a_tx_hash); if(!l_tx_input_ticker){ log_it(L_WARNING, "Can't get ticker from tx"); return false; @@ -2275,7 +2051,7 @@ static bool s_string_append_tx_cond_info_json( json_object * a_json_out, xchange_tx_type_t l_tx_type = dap_chain_net_srv_xchange_tx_get_type(a_net->pub.ledger, a_tx, &l_out_cond_item, &l_cond_idx, &l_out_prev_cond_item); - bool l_is_closed = dap_ledger_tx_hash_is_used_out_item(a_net->pub.ledger, &l_tx_hash, l_cond_idx, NULL); + bool l_is_closed = dap_ledger_tx_hash_is_used_out_item(a_net->pub.ledger, a_tx_hash, l_cond_idx, NULL); if ((a_filter_by_status == TX_STATUS_ACTIVE && l_is_closed) || (a_filter_by_status == TX_STATUS_INACTIVE && !l_is_closed) || (a_filter_by_status == TX_STATUS_ACTIVE && l_tx_type == TX_TYPE_INVALIDATE)) return false; @@ -2285,49 +2061,39 @@ static bool s_string_append_tx_cond_info_json( json_object * a_json_out, switch(l_tx_type){ case TX_TYPE_ORDER:{ - if (!l_out_cond_item) { - log_it(L_ERROR, "Can't find conditional output"); - return false; - } - char *l_rate_str = dap_chain_balance_coins_print(l_out_cond_item->subtype.srv_xchange.rate); - const char *l_amount_str, *l_amount_datoshi_str = dap_uint256_to_char(l_out_cond_item->header.value, &l_amount_str); + if (!l_out_cond_item) + return log_it(L_ERROR, "Can't find conditional output in TX %s", l_tx_hash_str), false; json_object_object_add(a_json_out, "hash", json_object_new_string(l_tx_hash_str)); - if(a_print_ts){ + if (a_print_ts){ char l_tmp_buf[DAP_TIME_STR_SIZE]; dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, a_tx->header.ts_created); json_object_object_add(a_json_out, "ts_created", json_object_new_string(l_tmp_buf)); } - if( a_print_status) - json_object_object_add(a_json_out, "status", l_is_closed ? json_object_new_string("inactive") - : json_object_new_string("active")); - json_object_object_add(a_json_out, "proposed price", json_object_new_string(l_amount_str)); - json_object_object_add(a_json_out, "proposed datoshi", json_object_new_string(l_amount_datoshi_str)); + if (a_print_status) + json_object_object_add(a_json_out, "status", json_object_new_string(l_is_closed ? "inactive" : "active")); + + const char *l_rate_str, *l_amount_str, *l_amount_datoshi_str = dap_uint256_to_char(l_out_cond_item->header.value, &l_amount_str); + json_object_object_add(a_json_out, "proposed_coins", json_object_new_string(l_amount_str)); + json_object_object_add(a_json_out, "proposed_datoshi", json_object_new_string(l_amount_datoshi_str)); json_object_object_add(a_json_out, "ticker", json_object_new_string(l_tx_input_ticker)); - json_object_object_add(a_json_out, "buy token", json_object_new_string(l_out_cond_item->subtype.srv_xchange.buy_token)); + json_object_object_add(a_json_out, "buy_token", json_object_new_string(l_out_cond_item->subtype.srv_xchange.buy_token)); + dap_uint256_to_char(l_out_cond_item->subtype.srv_xchange.rate, &l_rate_str); json_object_object_add(a_json_out, "rate", json_object_new_string(l_rate_str)); json_object_object_add(a_json_out, "net", json_object_new_string(a_net->pub.name)); - dap_chain_addr_t l_owner_addr = {}; - if (!a_owner_addr){ - l_owner_addr = l_out_cond_item ? l_out_cond_item->subtype.srv_xchange.seller_addr : (l_out_prev_cond_item ? l_out_prev_cond_item->subtype.srv_xchange.seller_addr : (dap_chain_addr_t){0}); - } else { - l_owner_addr = *a_owner_addr; - } - json_object_object_add(a_json_out, "nowner addr", json_object_new_string(dap_chain_addr_to_str_static(&l_owner_addr))); - DAP_DELETE(l_rate_str); + dap_chain_addr_t l_owner_addr = a_owner_addr ? *a_owner_addr : + l_out_cond_item ? l_out_cond_item->subtype.srv_xchange.seller_addr : + l_out_prev_cond_item ? l_out_prev_cond_item->subtype.srv_xchange.seller_addr : (dap_chain_addr_t){ }; + json_object_object_add(a_json_out, "owner_addr", json_object_new_string(dap_chain_addr_to_str_static(&l_owner_addr))); } break; case TX_TYPE_EXCHANGE:{ - dap_chain_tx_in_cond_t *l_in_cond - = (dap_chain_tx_in_cond_t*)dap_chain_datum_tx_item_get(a_tx, NULL, NULL, TX_ITEM_TYPE_IN_COND , NULL); - char l_tx_prev_cond_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; - dap_hash_fast_to_str(&l_in_cond->header.tx_prev_hash, l_tx_prev_cond_hash_str, sizeof(l_tx_prev_cond_hash_str)); + dap_chain_tx_in_cond_t *l_in_cond = (dap_chain_tx_in_cond_t*)dap_chain_datum_tx_item_get(a_tx, NULL, NULL, TX_ITEM_TYPE_IN_COND , NULL); + char *l_tx_prev_cond_hash_str = dap_hash_fast_to_str_static(&l_in_cond->header.tx_prev_hash); - if (!l_out_prev_cond_item) { - log_it(L_ERROR, "Can't find previous transaction"); - return false; - } + if (!l_out_prev_cond_item) + return log_it(L_ERROR, "Can't find previous cond item for tx %s", l_tx_hash_str), false; - uint256_t l_rate = l_out_cond_item + uint256_t l_rate = l_out_cond_item ? l_out_cond_item->subtype.srv_xchange.rate : l_out_prev_cond_item->subtype.srv_xchange.rate, l_value_from = {}, l_value_to = {}; @@ -2338,7 +2104,7 @@ static bool s_string_append_tx_cond_info_json( json_object * a_json_out, l_value_from = l_out_prev_cond_item->header.value; MULT_256_COIN(l_value_from, l_rate, &l_value_to); - char *l_buy_ticker = l_out_cond_item + char *l_buy_ticker = l_out_cond_item ? l_out_cond_item->subtype.srv_xchange.buy_token : l_out_prev_cond_item->subtype.srv_xchange.buy_token; @@ -2349,18 +2115,16 @@ static bool s_string_append_tx_cond_info_json( json_object * a_json_out, json_object_object_add(a_json_out, "ts_created", json_object_new_string(l_tmp_buf)); } if(a_print_status) - json_object_object_add(a_json_out, "status", l_is_closed ? json_object_new_string("inactive") - : json_object_new_string("active")); - + json_object_object_add(a_json_out, "status", json_object_new_string(l_is_closed ? "inactive" : "active")); + const char *l_value_from_str, *l_value_from_datoshi_str = dap_uint256_to_char(l_value_from, &l_value_from_str); - json_object_object_add(a_json_out, "changed", json_object_new_string(l_value_from_str)); - json_object_object_add(a_json_out, "changed datoshi", json_object_new_string(l_value_from_datoshi_str)); + json_object_object_add(a_json_out, "changed_coins", json_object_new_string(l_value_from_str)); + json_object_object_add(a_json_out, "changed_datoshi", json_object_new_string(l_value_from_datoshi_str)); json_object_object_add(a_json_out, "ticker", json_object_new_string(l_tx_input_ticker)); const char *l_value_to_str, *l_value_to_datoshi_str = dap_uint256_to_char(l_value_to, &l_value_to_str); - - json_object_object_add(a_json_out, "for", json_object_new_string(l_value_to_str)); - json_object_object_add(a_json_out, "for datoshi", json_object_new_string(l_value_to_datoshi_str)); + json_object_object_add(a_json_out, "for_coins", json_object_new_string(l_value_to_str)); + json_object_object_add(a_json_out, "for_datoshi", json_object_new_string(l_value_to_datoshi_str)); json_object_object_add(a_json_out, "ticker", json_object_new_string(l_buy_ticker)); const char *l_rate_str; dap_uint256_to_char(l_rate, &l_rate_str); @@ -2368,49 +2132,35 @@ static bool s_string_append_tx_cond_info_json( json_object * a_json_out, const char *l_amount_str = NULL, *l_amount_datoshi_str = l_out_cond_item ? dap_uint256_to_char(l_out_cond_item->header.value, &l_amount_str) : "0"; - json_object_object_add(a_json_out, "remain amount", l_amount_str ? json_object_new_string(l_amount_str) - : json_object_new_string("0.0")); - json_object_object_add(a_json_out, "remain amount datoshi", json_object_new_string(l_amount_datoshi_str)); + json_object_object_add(a_json_out, "remain_coins", json_object_new_string(l_amount_str ? l_amount_str : "0.0")); + json_object_object_add(a_json_out, "remain_datoshi", json_object_new_string(l_amount_datoshi_str)); json_object_object_add(a_json_out, "ticker", json_object_new_string(l_tx_input_ticker)); json_object_object_add(a_json_out, "net", json_object_new_string(a_net->pub.name)); if (a_print_prev_hash) - json_object_object_add(a_json_out, "Prev cond", json_object_new_string(l_tx_prev_cond_hash_str)); - dap_chain_tx_out_cond_subtype_t l_cond_type = l_out_cond_item ? l_out_cond_item->header.subtype : l_out_prev_cond_item->header.subtype; - dap_hash_fast_t l_order_hash = dap_ledger_get_first_chain_tx_hash(a_net->pub.ledger, l_cond_type, &l_tx_hash); - if ( dap_hash_fast_is_blank(&l_order_hash) ) - l_order_hash = l_in_cond->header.tx_prev_hash; - char l_order_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; - dap_hash_fast_to_str(&l_order_hash, l_order_hash_str, sizeof(l_order_hash_str)); - json_object_object_add(a_json_out, "norder hash", json_object_new_string(l_order_hash_str)); - - dap_chain_addr_t l_owner_addr = {}; - if (!a_owner_addr){ - l_owner_addr = l_out_cond_item ? l_out_cond_item->subtype.srv_xchange.seller_addr : (l_out_prev_cond_item ? l_out_prev_cond_item->subtype.srv_xchange.seller_addr : (dap_chain_addr_t){0}); - } else { - l_owner_addr = *a_owner_addr; - } - json_object_object_add(a_json_out, "owner addr", json_object_new_string(dap_chain_addr_to_str_static(&l_owner_addr))); - - dap_chain_addr_t l_buyer_addr = {}; - if(!a_buyer_addr){ - dap_chain_tx_sig_t *l_tx_sig = (dap_chain_tx_sig_t *)dap_chain_datum_tx_item_get(a_tx, NULL, NULL, TX_ITEM_TYPE_SIG, NULL); - dap_sign_t *l_sign = dap_chain_datum_tx_item_sig_get_sign((dap_chain_tx_sig_t *)l_tx_sig); + json_object_object_add(a_json_out, "prev_tx", json_object_new_string(l_tx_prev_cond_hash_str)); + + dap_chain_addr_t l_owner_addr = a_owner_addr ? *a_owner_addr : + l_out_cond_item ? l_out_cond_item->subtype.srv_xchange.seller_addr : + l_out_prev_cond_item ? l_out_prev_cond_item->subtype.srv_xchange.seller_addr : (dap_chain_addr_t){ }; + json_object_object_add(a_json_out, "owner_addr", json_object_new_string(dap_chain_addr_to_str_static(&l_owner_addr))); + dap_chain_addr_t l_buyer_addr; + if (a_buyer_addr) + l_buyer_addr = *a_buyer_addr; + else { + dap_sign_t *l_sign = dap_chain_datum_tx_item_sig_get_sign((dap_chain_tx_sig_t*)dap_chain_datum_tx_item_get(a_tx, NULL, NULL, TX_ITEM_TYPE_SIG, NULL)); dap_enc_key_t *l_key_buyer = dap_sign_to_enc_key(l_sign); dap_chain_addr_fill_from_key(&l_buyer_addr, l_key_buyer, a_net->pub.id); dap_enc_key_delete(l_key_buyer); - } else - l_buyer_addr = *a_buyer_addr; - json_object_object_add(a_json_out, "buyer addr", json_object_new_string(dap_chain_addr_to_str_static(&l_buyer_addr))); + } + json_object_object_add(a_json_out, "buyer_addr", json_object_new_string(dap_chain_addr_to_str_static(&l_buyer_addr))); } break; case TX_TYPE_INVALIDATE:{ dap_chain_tx_in_cond_t * l_in_cond = (dap_chain_tx_in_cond_t *)dap_chain_datum_tx_item_get(a_tx, NULL, NULL, TX_ITEM_TYPE_IN_COND , NULL); char l_tx_prev_cond_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; dap_hash_fast_to_str(&l_in_cond->header.tx_prev_hash,l_tx_prev_cond_hash_str, sizeof(l_tx_prev_cond_hash_str)); - if (!l_out_prev_cond_item) { - log_it(L_ERROR, "Can't find previous transaction"); - return false; - } + if (!l_out_prev_cond_item) + return log_it(L_ERROR, "Can't find previous cond item for tx %s", l_tx_hash_str), false; dap_chain_datum_tx_t *l_prev_tx = dap_ledger_tx_find_by_hash(a_net->pub.ledger, &l_in_cond->header.tx_prev_hash); if (!l_prev_tx) @@ -2418,17 +2168,13 @@ static bool s_string_append_tx_cond_info_json( json_object * a_json_out, int l_out_num = l_in_cond->header.tx_out_prev_idx; dap_chain_tx_out_cond_t *l_out_cond = dap_chain_datum_tx_out_cond_get(l_prev_tx, DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE, &l_out_num); - if (!l_out_cond) { - log_it(L_ERROR, "Can't find datum tx"); - return false; - } + if (!l_out_cond) + return log_it(L_ERROR, "Can't find OUT_COND in prev tx"), false; + dap_hash_fast_t l_order_hash = dap_ledger_get_first_chain_tx_hash(a_net->pub.ledger, DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE, &l_in_cond->header.tx_prev_hash); if ( dap_hash_fast_is_blank(&l_order_hash) ) l_order_hash = l_in_cond->header.tx_prev_hash; - char *l_value_from_str = dap_chain_balance_coins_print(l_out_prev_cond_item->header.value); - char *l_value_from_datoshi_str = dap_chain_balance_datoshi_print(l_out_prev_cond_item->header.value); - json_object_object_add(a_json_out, "hash", json_object_new_string(l_tx_hash_str)); if(a_print_ts){ char l_tmp_buf[DAP_TIME_STR_SIZE]; @@ -2438,25 +2184,17 @@ static bool s_string_append_tx_cond_info_json( json_object * a_json_out, if (a_print_status) json_object_object_add(a_json_out, "status", json_object_new_string("inactive")); - char l_order_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; - dap_hash_fast_to_str(&l_order_hash, l_order_hash_str, sizeof(l_order_hash_str)); - json_object_object_add(a_json_out, "returned from", json_object_new_string(l_value_from_str)); - json_object_object_add(a_json_out, "returned datoshi", json_object_new_string(l_value_from_datoshi_str)); + const char *l_value_from_str, *l_value_from_datoshi_str = dap_uint256_to_char(l_out_prev_cond_item->header.value, &l_value_from_str); + json_object_object_add(a_json_out, "returned_coins", json_object_new_string(l_value_from_str)); + json_object_object_add(a_json_out, "returned_datoshi", json_object_new_string(l_value_from_datoshi_str)); json_object_object_add(a_json_out, "ticker", json_object_new_string(l_tx_input_ticker)); - json_object_object_add(a_json_out, "order hash", json_object_new_string(l_order_hash_str)); + json_object_object_add(a_json_out, "order_hash", json_object_new_string( dap_hash_fast_to_str_static(&l_order_hash) )); if(a_print_prev_hash) json_object_object_add(a_json_out, "prev cond hash", json_object_new_string(l_tx_prev_cond_hash_str)); - - dap_chain_addr_t l_owner_addr = {}; - if (!a_owner_addr){ - l_owner_addr = l_out_cond_item ? l_out_cond_item->subtype.srv_xchange.seller_addr : (l_out_prev_cond_item ? l_out_prev_cond_item->subtype.srv_xchange.seller_addr : (dap_chain_addr_t){0}); - } else { - l_owner_addr = *a_owner_addr; - } - json_object_object_add(a_json_out, "owner addr", json_object_new_string(dap_chain_addr_to_str_static(&l_owner_addr))); - - DAP_DELETE(l_value_from_str); - DAP_DELETE(l_value_from_datoshi_str); + dap_chain_addr_t l_owner_addr = a_owner_addr ? *a_owner_addr : + l_out_cond_item ? l_out_cond_item->subtype.srv_xchange.seller_addr : + l_out_prev_cond_item ? l_out_prev_cond_item->subtype.srv_xchange.seller_addr : (dap_chain_addr_t){ }; + json_object_object_add(a_json_out, "owner_addr", json_object_new_string(dap_chain_addr_to_str_static(&l_owner_addr))); } break; default: return false; } @@ -2493,7 +2231,7 @@ static int s_cli_srv_xchange_tx_list_addr_json(dap_chain_net_t *a_net, dap_time_ continue; json_object* json_obj_tx = json_object_new_object(); - if (s_string_append_tx_cond_info_json(json_obj_tx, a_net, NULL, NULL, l_datum_tx, a_opt_status, false, true, false)) { + if (s_string_append_tx_cond_info_json(json_obj_tx, a_net, NULL, NULL, l_datum_tx, &l_hash_curr, a_opt_status, false, true, true)) { json_object_array_add(json_arr_datum_out, json_obj_tx); l_tx_count++; } @@ -2518,7 +2256,7 @@ static int s_cli_srv_xchange_tx_list_addr_json(dap_chain_net_t *a_net, dap_time_ continue; json_object* json_obj_tx = json_object_new_object(); - if (s_string_append_tx_cond_info_json(json_obj_tx, a_net, NULL, NULL, l_datum_tx, a_opt_status, false, true, false)) { + if (s_string_append_tx_cond_info_json(json_obj_tx, a_net, NULL, NULL, l_datum_tx, l_iter->cur_hash, a_opt_status, false, true, true)) { json_object_array_add(json_arr_datum_out, json_obj_tx); l_tx_count++; } @@ -2528,7 +2266,7 @@ static int s_cli_srv_xchange_tx_list_addr_json(dap_chain_net_t *a_net, dap_time_ json_object_object_add(json_obj_out, "transactions", json_arr_datum_out); char *l_transactions = dap_strdup_printf("\nFound %"DAP_UINT64_FORMAT_U" transactions", l_tx_count); - json_object_object_add(json_obj_out, "number of transactions", json_object_new_string(l_transactions)); + json_object_object_add(json_obj_out, "number_of_transactions", json_object_new_string(l_transactions)); DAP_DELETE(l_transactions); /* Free string descriptor, but keep ASCIZ buffer itself */ return 0; } @@ -2550,7 +2288,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) { json_object **json_arr_reply = (json_object **)a_str_reply; - enum {CMD_NONE = 0, CMD_ORDER, CMD_ORDERS, CMD_PURCHASE, CMD_TX_LIST, CMD_TOKEN_PAIR }; + enum {CMD_NONE = 0, CMD_ORDER, CMD_ORDERS, CMD_PURCHASE, CMD_ENABLE, CMD_DISABLE, CMD_TX_LIST, CMD_TOKEN_PAIR }; int l_arg_index = 1, l_cmd_num = CMD_NONE; if(dap_cli_server_cmd_find_option_val(a_argv, l_arg_index, dap_min(a_argc, l_arg_index + 1), "order", NULL)) { @@ -2569,7 +2307,6 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) l_cmd_num = CMD_TOKEN_PAIR; } - switch (l_cmd_num) { case CMD_ORDER:{ int res = s_cli_srv_xchange_order(a_argc, a_argv, l_arg_index + 1, json_arr_reply); @@ -2638,22 +2375,22 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) } } - dap_chain_addr_t *l_addr = NULL; - const char *l_addr_str = NULL; - dap_cli_server_cmd_find_option_val(a_argv, l_arg_index, a_argc, "-addr", &l_addr_str); - if (l_addr_str) - l_addr = dap_chain_addr_from_str(l_addr_str); - dap_cli_server_cmd_find_option_val(a_argv, l_arg_index, a_argc, "-token_to", &l_token_to_str); if(l_token_to_str){ dap_chain_datum_token_t * l_token_to_datum = dap_ledger_token_ticker_check( l_net->pub.ledger, l_token_to_str); if(!l_token_to_datum){ - dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_CANT_FIND_TOKEN_TO_ERR, + dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_CANT_FIND_TOKEN_TO_ERR, "Can't find \"%s\" token in network \"%s\" for argument '-token_to' ", l_token_to_str, l_net->pub.name); return -DAP_CHAIN_NODE_CLI_COM_NET_SRV_XCNGE_ORDRS_CANT_FIND_TOKEN_TO_ERR; } } + dap_chain_addr_t *l_addr = NULL; + const char *l_addr_str = NULL; + dap_cli_server_cmd_find_option_val(a_argv, l_arg_index, a_argc, "-addr", &l_addr_str); + if (l_addr_str) + l_addr = dap_chain_addr_from_str(l_addr_str); + uint64_t l_printed_orders_count = 0; const char *l_limit_str = NULL; const char *l_offset_str = NULL; @@ -2662,10 +2399,12 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) size_t l_limit = l_limit_str ? strtoul(l_limit_str, NULL, 10) : 1000; size_t l_offset = l_offset_str ? strtoul(l_offset_str, NULL, 10) : 0; size_t l_arr_start = 0; - size_t l_arr_end = dap_list_length(l_list); + size_t l_arr_end = 0; json_object* json_obj_order = json_object_new_object(); + json_object* json_arr_orders_limit = json_object_new_array(); json_object* json_arr_orders_out = json_object_new_array(); - dap_chain_set_offset_limit_json(json_arr_orders_out, &l_arr_start, &l_arr_end, l_limit, l_offset, dap_list_length(l_list)); + dap_chain_set_offset_limit_json(json_arr_orders_limit, &l_arr_start, &l_arr_end, l_limit, l_offset, dap_list_length(l_list)); + json_object_object_add(json_obj_order, "PAGINA", json_arr_orders_limit); size_t i_tmp = 0; // Print all txs for (dap_list_t *it = l_list; it; it = it->next) { @@ -2690,8 +2429,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) if (l_addr && dap_chain_addr_compare(&l_item->seller_addr, l_addr) == 0) continue; - l_owner_addr = dap_chain_addr_to_str_static(&l_item->seller_addr); - + l_owner_addr = dap_strdup(dap_chain_addr_to_str(&l_item->seller_addr)); l_tx = l_item->tx; l_tx_hash = l_item->hash; memcpy(l_buy_token, l_item->buy_token, strlen(l_item->buy_token)); @@ -2700,6 +2438,10 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) l_rate = l_item->rate; l_amount = l_item->tx_info.order_info.value_ammount; l_proposed = l_item->tx_info.order_info.value; + uint256_t l_completed = {}; + SUBTRACT_256_256(l_item->tx_info.order_info.value, l_item->tx_info.order_info.value_ammount, &l_completed); + DIV_256_COIN(l_completed, l_item->tx_info.order_info.value, &l_completed); + MULT_256_COIN(l_completed, dap_chain_balance_coins_scan("100.0"), &l_completed); l_percent_completed = l_item->tx_info.order_info.percent_completed; } else { @@ -2749,7 +2491,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) l_rate = l_price->rate; l_percent_completed = dap_chain_net_srv_xchange_get_order_completion_rate(l_net, l_tx_hash); l_amount = l_out_cond_last_tx ? l_out_cond_last_tx->header.value : uint256_0; - l_owner_addr = dap_chain_addr_to_str_static(&l_price->creator_addr); + l_owner_addr = dap_strdup(dap_chain_addr_to_str(&l_price->creator_addr)); l_proposed = l_price->datoshi_sell; DAP_DEL_Z(l_price); } @@ -2777,7 +2519,6 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) continue; } i_tmp++; - const char *l_tx_hash_str = dap_chain_hash_fast_to_str_static(&l_tx_hash); char l_tmp_buf[DAP_TIME_STR_SIZE]; dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, l_tx->header.ts_created); @@ -2803,7 +2544,6 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) json_object_object_add(json_obj_order, "rate", json_object_new_string(l_cp_rate)); json_object_object_add(json_obj_order, "net", json_object_new_string(l_net->pub.name)); - json_object_object_add(json_obj_order, "owner_addr", json_object_new_string(l_owner_addr)); json_object_array_add(*json_arr_reply, json_obj_order); DAP_DELETE(l_owner_addr); l_printed_orders_count++; @@ -2816,7 +2556,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) dap_list_free_full(l_list, NULL); } char *l_total = dap_strdup_printf("Total %"DAP_UINT64_FORMAT_U" orders.\n\r", i_tmp); - json_object_object_add(json_obj_order, "number of transactions", json_object_new_string(l_total)); + json_object_object_add(json_obj_order, "number_of_transactions", json_object_new_string(l_total)); DAP_DELETE(l_total); if (!json_object_array_length(json_arr_orders_out)) { @@ -2824,7 +2564,6 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) } } break; - case CMD_PURCHASE: { const char *l_net_str = NULL, *l_wallet_str = NULL, *l_order_hash_str = NULL, *l_val_buy_str = NULL, *l_val_fee_str = NULL; l_arg_index++; @@ -2902,7 +2641,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) } } break; - case CMD_TX_LIST: { + case CMD_TX_LIST: { const char *l_net_str = NULL, *l_time_begin_str = NULL, *l_time_end_str = NULL; const char *l_status_str = NULL, *l_addr_str = NULL; /* @RRL: #6294 */ int l_opt_status, l_show_tx_nr = 0; @@ -2985,15 +2724,12 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) break; json_object* json_obj_order = json_object_new_object(); if (s_string_append_tx_cond_info_json(json_obj_order, l_net, &l_item->seller_addr, - l_item->tx_type == TX_TYPE_EXCHANGE ? &l_item->tx_info.exchange_info.buyer_addr : NULL, - l_item->tx, l_opt_status, false, true, true)) { + l_item->tx_type == TX_TYPE_EXCHANGE ? &l_item->tx_info.exchange_info.buyer_addr : NULL, + l_item->tx, &l_item->hash, l_opt_status, false, true, true)){ json_object_array_add(json_arr_bl_out, json_obj_order); l_show_tx_nr++; } } - json_object* json_obj_xchange = json_object_new_object(); - json_object_object_add(json_obj_xchange, "orders", json_arr_bl_out); - json_object_array_add(*json_arr_reply, json_obj_xchange); } else { dap_list_t *l_datum_list0 = dap_chain_datum_list(l_net, NULL, s_filter_tx_list, l_time); size_t l_datum_num = dap_list_length(l_datum_list0); @@ -3010,24 +2746,21 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) json_object* json_obj_order = json_object_new_object(); dap_hash_fast_t l_hash = {}; dap_hash_fast(l_datum_tx, dap_chain_datum_tx_get_size(l_datum_tx), &l_hash); - if (s_string_append_tx_cond_info_json(json_obj_order, l_net, NULL, NULL, l_datum_tx, l_opt_status, false, true, true)) { + if (s_string_append_tx_cond_info_json(json_obj_order, l_net, NULL, NULL, l_datum_tx, &l_hash, l_opt_status, false, true, true)) { json_object_array_add(json_arr_bl_out, json_obj_order); l_show_tx_nr++; } l_datum_list = dap_list_next(l_datum_list); } - json_object* json_obj_xchange = json_object_new_object(); - json_object_object_add(json_obj_xchange, "orders", json_arr_bl_out); - json_object_array_add(*json_arr_reply, json_obj_xchange); } dap_list_free_full(l_datum_list0, NULL); } json_object* json_obj_orders = json_object_new_object(); if(l_show_tx_nr) - json_object_object_add(json_obj_orders, "number of transactions", json_object_new_int(l_show_tx_nr)); + json_object_object_add(json_obj_orders, "number_of_transactions", json_object_new_int(l_show_tx_nr)); else - json_object_object_add(json_obj_orders, "number of transactions", json_object_new_string("Transactions not found")); + json_object_object_add(json_obj_orders, "number_of_transactions", json_object_new_string("Transactions not found")); json_object_array_add(*json_arr_reply, json_obj_orders); } break; // Token pair control @@ -3193,10 +2926,10 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, l_last_rate_time); const char *l_rate_average_str; dap_uint256_to_char(l_rate_average, &l_rate_average_str); json_object* json_obj_order = json_object_new_object(); - json_object_object_add(json_obj_order, "Average rate", json_object_new_string(l_rate_average_str)); + json_object_object_add(json_obj_order, "average_rate", json_object_new_string(l_rate_average_str)); const char *l_last_rate_str; dap_uint256_to_char(l_rate, &l_last_rate_str); - json_object_object_add(json_obj_order, "Last rate", json_object_new_string(l_last_rate_str)); - json_object_object_add(json_obj_order, "Last rate time", json_object_new_string(l_tmp_buf)); + json_object_object_add(json_obj_order, "last_rate", json_object_new_string(l_last_rate_str)); + json_object_object_add(json_obj_order, "last_rate_time", json_object_new_string(l_tmp_buf)); json_object_array_add(*json_arr_reply, json_obj_order); } break; @@ -3317,7 +3050,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) i_tmp++; json_object* json_obj_out = json_object_new_object(); - if(s_string_append_tx_cond_info_json(json_obj_out, l_net, NULL, NULL, l_tx, TX_STATUS_ALL, false, false, true)){ + if(s_string_append_tx_cond_info_json(json_obj_out, l_net, NULL, NULL, l_tx, &l_tx_hash, TX_STATUS_ALL, false, false, true)){ l_total++; SUM_256_256(l_token_to_value, l_token_curr_to_value, &l_token_to_value); SUM_256_256(l_token_from_value, l_token_curr_from_value, &l_token_from_value); @@ -3326,34 +3059,17 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) l_cur = dap_list_next(l_cur); } - json_object_array_add(*json_arr_reply, json_arr_bl_cache_out); + json_object_array_add(*json_arr_reply, json_arr_bl_cache_out); dap_list_free(l_list); json_object* json_obj_order = json_object_new_object(); - char *l_total_str = dap_strdup_printf("Found %"DAP_UINT64_FORMAT_U" transactions\n", l_total); - json_object_object_add(json_obj_order, "number of transactions", json_object_new_string(l_total_str)); - DAP_DELETE(l_total_str); - - const char *l_token_from_value_coins_str = NULL, *l_token_from_value_datoshi_str = NULL, - *l_token_to_value_coins_str = NULL, *l_token_to_value_datoshi_str = NULL; - - l_token_from_value_datoshi_str = dap_chain_balance_datoshi_print(l_token_from_value); - l_token_from_value_coins_str = dap_chain_balance_coins_print(l_token_from_value); - l_token_to_value_datoshi_str = dap_chain_balance_datoshi_print(l_token_to_value); - l_token_to_value_coins_str = dap_chain_balance_coins_print(l_token_to_value); - - json_object_object_add(json_obj_order, "trading from coins", json_object_new_string(l_token_from_value_coins_str)); - json_object_object_add(json_obj_order, "trading from datoshi", json_object_new_string(l_token_from_value_datoshi_str)); - json_object_object_add(json_obj_order, "trading from token", json_object_new_string(l_token_from_str)); - - json_object_object_add(json_obj_order, "trading to coins", json_object_new_string(l_token_to_value_coins_str)); - json_object_object_add(json_obj_order, "trading to datoshi", json_object_new_string(l_token_to_value_datoshi_str)); - json_object_object_add(json_obj_order, "trading to token", json_object_new_string(l_token_to_str)); - - DAP_DEL_Z(l_token_from_value_datoshi_str); - DAP_DEL_Z(l_token_from_value_coins_str); - DAP_DEL_Z(l_token_to_value_datoshi_str); - DAP_DEL_Z(l_token_to_value_coins_str); + json_object_object_add(json_obj_order, "tx_count", json_object_new_uint64(l_total)); + const char *l_token_from_value_coins_str = NULL, *l_token_from_value_datoshi_str = dap_uint256_to_char(l_token_from_value, &l_token_from_value_coins_str); + json_object_object_add(json_obj_order, "trading_val_from_coins", json_object_new_string(l_token_from_value_coins_str)); + json_object_object_add(json_obj_order, "trading_val_from_datoshi", json_object_new_string(l_token_from_value_datoshi_str)); + const char *l_token_to_value_coins_str = NULL, *l_token_to_value_datoshi_str = dap_uint256_to_char(l_token_to_value, &l_token_to_value_coins_str); + json_object_object_add(json_obj_order, "trading_val_to_coins", json_object_new_string(l_token_to_value_coins_str)); + json_object_object_add(json_obj_order, "trading_val_to_datoshi", json_object_new_string(l_token_to_value_datoshi_str)); json_object_array_add(*json_arr_reply, json_obj_order); break; @@ -3403,7 +3119,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) } } - json_object_object_add(json_obj_out, "TICKERS PAIR", json_arr_bl_cache_out); + json_object_object_add(json_obj_out, "TICKERS_PAIR", json_arr_bl_cache_out); // Free tickers array for(size_t i = 0; i< l_tickers_count; i++){ @@ -3411,7 +3127,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) } DAP_DELETE(l_tickers); } - json_object_object_add(json_obj_out, "pair count", json_object_new_uint64(l_pairs_count)); + json_object_object_add(json_obj_out, "pair_count", json_object_new_uint64(l_pairs_count)); json_object_array_add(*json_arr_reply, json_obj_out); break; } @@ -3419,7 +3135,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void **a_str_reply) // No subcommand selected json_object* json_obj_out = json_object_new_object(); - json_object_object_add(json_obj_out, "token pair status", json_object_new_string("Command 'token pair' requires proper subcommand," + json_object_object_add(json_obj_out, "token_pair_status", json_object_new_string("Command 'token pair' requires proper subcommand," "please read its manual with command 'help srv_xchange'")); json_object_array_add(*json_arr_reply, json_obj_out); @@ -3822,4 +3538,4 @@ static void s_ledger_tx_remove_notify(dap_ledger_t *a_ledger, dap_chain_datum_tx DAP_DELETE(l_cache_found); } } -} \ No newline at end of file +} diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c index 2f87bdb0f5698541304cf44dc57aff6aef2eda13..253fb58de7b3aa3824a457a686a5ccf47e65a0c1 100644 --- a/modules/type/blocks/dap_chain_cs_blocks.c +++ b/modules/type/blocks/dap_chain_cs_blocks.c @@ -785,7 +785,8 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **a_str_reply) char l_time_buf[DAP_TIME_STR_SIZE], l_hexbuf[32] = { '\0' }; // Header json_object* json_obj_inf = json_object_new_object(); - json_object_object_add(json_obj_inf, "Block number", json_object_new_uint64(l_block_cache->block_number)); + + json_object_object_add(json_obj_inf, "block_number", json_object_new_uint64(l_block_cache->block_number)); json_object_object_add(json_obj_inf, "hash", json_object_new_string(l_hash_str)); snprintf(l_hexbuf, sizeof(l_hexbuf), "0x%04X",l_block->hdr.version); @@ -799,7 +800,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **a_str_reply) // Dump Metadata size_t l_offset = 0; - json_object_object_add(json_obj_inf, "Metadata: count", json_object_new_int(l_block->hdr.meta_count)); + json_object_object_add(json_obj_inf, "metadata_count", json_object_new_int(l_block->hdr.meta_count)); json_object* json_arr_meta_out = json_object_new_array(); json_object_array_add(*a_json_arr_reply, json_obj_inf); for (uint32_t i=0; i < l_block->hdr.meta_count; i++) { @@ -826,26 +827,26 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **a_str_reply) break; default: { snprintf(l_hexbuf, sizeof(l_hexbuf), "0x%0X", i); - json_object_object_add(json_obj_meta, "# -", json_object_new_string(l_hexbuf)); + json_object_object_add(json_obj_meta, "#", json_object_new_string(l_hexbuf)); int l_len = l_meta->hdr.data_size * 2 + 5; char *l_data_hex = DAP_NEW_STACK_SIZE(char, l_len); strcpy(l_data_hex, "0x"); dap_bin2hex(l_data_hex + 2, l_meta->data, l_meta->hdr.data_size); - json_object_object_add(json_obj_meta, "Data hex - ", json_object_new_string(l_data_hex)); } + json_object_object_add(json_obj_meta, "data_hex", json_object_new_string(l_data_hex)); } } json_object_array_add(json_arr_meta_out, json_obj_meta); l_offset += sizeof(l_meta->hdr) + l_meta->hdr.data_size; } json_object_array_add(*a_json_arr_reply, json_arr_meta_out); json_object* json_obj_datum = json_object_new_object(); - json_object_object_add(json_obj_datum, "Datums: count", json_object_new_uint64(l_block_cache->datum_count)); + json_object_object_add(json_obj_datum, "datums_count", json_object_new_uint64(l_block_cache->datum_count)); json_object_array_add(*a_json_arr_reply, json_obj_datum); json_object* json_arr_datum_out = json_object_new_array(); for (uint32_t i=0; i < l_block_cache->datum_count ; i++){ json_object* json_obj_tx = json_object_new_object(); dap_chain_datum_t * l_datum = l_block_cache->datum[i]; size_t l_datum_size = dap_chain_datum_size(l_datum); - json_object_object_add(json_obj_tx, "datum size ",json_object_new_uint64(l_datum_size)); + json_object_object_add(json_obj_tx, "datum_size",json_object_new_uint64(l_datum_size)); if (l_datum_size < sizeof (l_datum->header) ){ dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_BLOCK_DATUM_SIZE_ERR, "ERROR: datum size %zu is smaller than header size %zu \n",l_datum_size, sizeof (l_datum->header)); @@ -867,7 +868,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **a_str_reply) json_object_array_add(*a_json_arr_reply, json_arr_datum_out); // Signatures json_object* json_obj_sig = json_object_new_object(); - json_object_object_add(json_obj_sig, "signatures count", json_object_new_uint64(l_block_cache->sign_count)); + json_object_object_add(json_obj_sig, "signatures_count", json_object_new_uint64(l_block_cache->sign_count)); json_object_array_add(*a_json_arr_reply, json_obj_sig); json_object* json_arr_sign_out = json_object_new_array(); for (uint32_t i=0; i < l_block_cache->sign_count ; i++) { @@ -1050,7 +1051,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **a_str_reply) char l_buf[DAP_TIME_STR_SIZE]; dap_time_to_str_rfc822(l_buf, DAP_TIME_STR_SIZE, l_ts); json_object* json_obj_bl_cache = json_object_new_object(); - json_object_object_add(json_obj_bl_cache, "block number",json_object_new_uint64(l_block_cache->block_number)); + json_object_object_add(json_obj_bl_cache, "block_number",json_object_new_uint64(l_block_cache->block_number)); json_object_object_add(json_obj_bl_cache, "hash",json_object_new_string(l_block_cache->block_hash_str)); json_object_object_add(json_obj_bl_cache, "timestamp", json_object_new_uint64(l_ts)); json_object_object_add(json_obj_bl_cache, "ts_create",json_object_new_string(l_buf)); @@ -1086,8 +1087,8 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **a_str_reply) char l_buf[DAP_TIME_STR_SIZE]; if (l_last_block) dap_time_to_str_rfc822(l_buf, DAP_TIME_STR_SIZE, l_last_block->ts_created); - json_object_object_add(json_obj_out, "Last block num", json_object_new_uint64(l_last_block ? l_last_block->block_number : 0)); - json_object_object_add(json_obj_out, "Last block hash", json_object_new_string(l_last_block ? l_last_block->block_hash_str : "empty")); + json_object_object_add(json_obj_out, "last_block_num", json_object_new_uint64(l_last_block ? l_last_block->block_number : 0)); + json_object_object_add(json_obj_out, "last_block_hash", json_object_new_string(l_last_block ? l_last_block->block_hash_str : "empty")); json_object_object_add(json_obj_out, "ts_created", json_object_new_string(l_last_block ? l_buf : "never")); char *l_key = dap_strdup_printf("%s.%s has blocks", l_net->pub.name, l_chain->name); @@ -1120,8 +1121,8 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **a_str_reply) } } pthread_rwlock_unlock(&PVT(l_blocks)->datums_rwlock); - json_object_object_add(json_obj_out, "Blocks", json_arr_bl_cache_out); - json_object_object_add(json_obj_out, "Total",json_object_new_int(l_atoms_cnt)); + json_object_object_add(json_obj_out, "blocks", json_arr_bl_cache_out); + json_object_object_add(json_obj_out, "total",json_object_new_int(l_atoms_cnt)); json_object_array_add(*a_json_arr_reply, json_obj_out); } break; case SUBCMD_COUNT: { @@ -1422,7 +1423,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **a_str_reply) bool l_status = dap_chain_esbocs_get_autocollect_status(l_net->pub.id); char *l_val = dap_strdup_printf("for network %s is %s\n", l_net->pub.name, l_status ? "active" : "inactive cause of the network config or consensus starting problems"); - json_object_object_add(json_obj_out, "Autocollect status", json_object_new_string(l_val)); + json_object_object_add(json_obj_out, "autocollect_status", json_object_new_string(l_val)); DAP_DELETE(l_val); if (!l_status) break; @@ -2289,12 +2290,12 @@ static json_object *s_callback_atom_dump_json(json_object **a_arr_out, dap_chain break; default: { snprintf(l_hexbuf, sizeof(l_hexbuf), "0x%0X", i); - json_object_object_add(json_obj_meta, "# -", json_object_new_string(l_hexbuf)); + json_object_object_add(json_obj_meta, "#", json_object_new_string(l_hexbuf)); int l_len = l_meta->hdr.data_size * 2 + 5; char *l_data_hex = DAP_NEW_STACK_SIZE(char, l_len); strcpy(l_data_hex, "0x"); dap_bin2hex(l_data_hex + 2, l_meta->data, l_meta->hdr.data_size); - json_object_object_add(json_obj_meta, "Data hex - ", json_object_new_string(l_data_hex)); + json_object_object_add(json_obj_meta, "data_hex", json_object_new_string(l_data_hex)); } } json_object_array_add(l_jobj_metadata, json_obj_meta); @@ -2306,7 +2307,7 @@ static json_object *s_callback_atom_dump_json(json_object **a_arr_out, dap_chain dap_chain_datum_t *l_datum = (dap_chain_datum_t*)(l_block->meta_n_datum_n_sign + l_offset); json_object *l_jobj_datum = json_object_new_object(); size_t l_datum_size = dap_chain_datum_size(l_datum); - json_object_object_add(l_jobj_datum, "datum size ",json_object_new_uint64(l_datum_size)); + json_object_object_add(l_jobj_datum, "datum_size",json_object_new_uint64(l_datum_size)); if (l_datum_size < sizeof (l_datum->header) ){ dap_json_rpc_error_add(*a_arr_out, DAP_CHAIN_NODE_CLI_COM_BLOCK_DATUM_SIZE_ERR, "ERROR: datum size %zu is smaller than header size %zu",l_datum_size, sizeof (l_datum->header)); diff --git a/modules/type/dag/dap_chain_cs_dag.c b/modules/type/dag/dap_chain_cs_dag.c index 31a20b53bff53b98ef723ad4782ebcdca57e05cb..5517ee4db3f5fd8bb3a625f00e3cdc1bc5355e1a 100644 --- a/modules/type/dag/dap_chain_cs_dag.c +++ b/modules/type/dag/dap_chain_cs_dag.c @@ -1306,7 +1306,7 @@ static void s_json_dag_pack_event(json_object * a_json_out, dap_chain_cs_dag_eve char buf[DAP_TIME_STR_SIZE]; dap_time_to_str_rfc822(buf, DAP_TIME_STR_SIZE, a_event_item->event->header.ts_created); json_object_object_add(json_obj_event_i, "#", json_object_new_string(dap_itoa(i))); - json_object_object_add(json_obj_event_i, "event number", json_object_new_uint64(a_event_item->event_number)); + json_object_object_add(json_obj_event_i, "event_number", json_object_new_uint64(a_event_item->event_number)); json_object_object_add(json_obj_event_i, "hash", json_object_new_string(dap_chain_hash_fast_to_str_static(&a_event_item->hash))); json_object_object_add(json_obj_event_i, "ts_create", json_object_new_string(buf)); json_object_array_add(a_json_out, json_obj_event_i); @@ -1394,9 +1394,9 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) size_t l_objs_size = 0; dap_global_db_obj_t * l_objs = dap_global_db_get_all_sync(l_dag->gdb_group_events_round_new,&l_objs_size); if (l_objs_size) - json_object_object_add(json_obj_round,"round status", json_object_new_string("Completing round")); + json_object_object_add(json_obj_round,"round_status", json_object_new_string("Completing round")); else - json_object_object_add(json_obj_round,"round status", json_object_new_string("Completing round: no data")); + json_object_object_add(json_obj_round,"round_status", json_object_new_string("Completing round: no data")); // list for verifed and added events dap_list_t *l_list_to_del = NULL; @@ -1417,18 +1417,18 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) break; }else { snprintf(l_buf, 150, "Event %s verification passed", l_objs[i].key); - json_object_object_add(json_obj_round,"verification status", json_object_new_string(l_buf)); + json_object_object_add(json_obj_round,"verification_status", json_object_new_string(l_buf)); // If not verify only mode we add if ( ! l_verify_only ){ if (s_chain_callback_atom_add(l_chain, l_event, l_event_size, &l_event_hash, true)!= ATOM_ACCEPT) { // Add new atom in chain snprintf(l_buf, 150, "Event %s not added in chain\n", l_objs[i].key); - json_object_object_add(json_obj_round,"status add", json_object_new_string(l_buf)); + json_object_object_add(json_obj_round,"status_add", json_object_new_string(l_buf)); } else { // add event to delete l_list_to_del = dap_list_prepend(l_list_to_del, (void *)l_objs[i].key); snprintf(l_buf, 150, "Event %s added in chain successfully\n", l_objs[i].key); - json_object_object_add(json_obj_round,"status add", json_object_new_string(l_buf)); + json_object_object_add(json_obj_round,"status_add", json_object_new_string(l_buf)); } } } @@ -1476,7 +1476,7 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) size_t l_objs_size = 0; dap_global_db_obj_t * l_objs = dap_global_db_get_all_sync(l_dag->gdb_group_events_round_new, &l_objs_size); size_t l_search_events = 0; - json_object_object_add(json_obj_round,"Events", json_object_new_string("empty")); + json_object_object_add(json_obj_round,"events", json_object_new_string("empty")); for (size_t i = 0; i < l_objs_size;i++) { if (!strcmp(DAG_ROUND_CURRENT_KEY, l_objs[i].key)) continue; @@ -1488,8 +1488,8 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) dap_hash_fast(l_event, l_event_size, &ll_event_hash); char *ll_event_hash_str = dap_hash_fast_to_str_new(&ll_event_hash); l_search_events++; - json_object_object_add(json_obj_round,"events count", json_object_new_uint64(l_search_events)); - json_object_object_add(json_obj_round,"event hash", json_object_new_string(ll_event_hash_str)); + json_object_object_add(json_obj_round,"events_count", json_object_new_uint64(l_search_events)); + json_object_object_add(json_obj_round,"event_hash", json_object_new_string(ll_event_hash_str)); json_object_object_add(json_obj_round,"cell_id", json_object_new_uint64(l_event->header.cell_id.uint64)); DAP_DELETE(ll_event_hash_str); } @@ -1498,7 +1498,7 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) DAP_DELETE(l_datum_in_hash); if (!l_search_events) { snprintf(l_buf, 150, "Datum hash %s not found in round event.\n", l_datum_hash_str); - json_object_object_add(json_obj_round,"find result", json_object_new_string(l_buf)); + json_object_object_add(json_obj_round,"find_result", json_object_new_string(l_buf)); } return 0; } @@ -1605,23 +1605,23 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) } if ( l_event ) { char buf[DAP_TIME_STR_SIZE]; - json_object_object_add(json_obj_event,"Event hash", json_object_new_string(l_event_hash_str)); + json_object_object_add(json_obj_event,"event_hash", json_object_new_string(l_event_hash_str)); // Round info if ((l_from_events_str && strcmp(l_from_events_str,"round.new") == 0) && l_round_item) { - json_object_object_add(json_obj_event,"Round info", json_object_new_string(" ")); + json_object_object_add(json_obj_event,"round_info", json_object_new_string(" ")); if (l_round_item->round_info.reject_count) - json_object_object_add(json_obj_event,"signs rejects", json_object_new_uint64(l_round_item->round_info.reject_count)); + json_object_object_add(json_obj_event,"signs_rejects", json_object_new_uint64(l_round_item->round_info.reject_count)); dap_nanotime_to_str_rfc822(buf, DAP_TIME_STR_SIZE, l_round_item->round_info.ts_update); json_object_object_add(json_obj_event,"datum_hash", json_object_new_string(dap_chain_hash_fast_to_str_static(&l_round_item->round_info.datum_hash))); json_object_object_add(json_obj_event,"ts_update", json_object_new_string(buf)); } // Header - json_object_object_add(json_obj_event,"Header", json_object_new_string("empty")); + json_object_object_add(json_obj_event,"header", json_object_new_string("empty")); snprintf(l_buf, sizeof(l_buf), "%hu",l_event->header.version); json_object_object_add(json_obj_event,"version", json_object_new_string(l_buf)); - json_object_object_add(json_obj_event,"round ID", json_object_new_uint64(l_event->header.round_id)); + json_object_object_add(json_obj_event,"round_ID", json_object_new_uint64(l_event->header.round_id)); snprintf(l_buf, sizeof(l_buf), "0x%016"DAP_UINT64_FORMAT_x"",l_event->header.cell_id.uint64); json_object_object_add(json_obj_event,"cell_id", json_object_new_string(l_buf)); snprintf(l_buf, sizeof(l_buf), "0x%016"DAP_UINT64_FORMAT_x"",l_event->header.chain_id.uint64); @@ -1630,7 +1630,7 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) json_object_object_add(json_obj_event,"ts_created", json_object_new_string(l_buf)); // Hash links - json_object_object_add(json_obj_event,"hashes count", json_object_new_uint64(l_event->header.hash_count)); + json_object_object_add(json_obj_event,"hashes_count", json_object_new_uint64(l_event->header.hash_count)); for (uint16_t i=0; i < l_event->header.hash_count; i++){ dap_chain_hash_fast_t * l_hash = (dap_chain_hash_fast_t *) (l_event->hashes_n_datum_n_signs + i*sizeof (dap_chain_hash_fast_t)); @@ -1643,7 +1643,7 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) // Nested datum const char *l_datum_type = NULL; DAP_DATUM_TYPE_STR(l_datum->header.type_id, l_datum_type) - json_object_object_add(json_obj_event,"Datum", json_object_new_string("empty")); + json_object_object_add(json_obj_event,"datum", json_object_new_string("empty")); json_object_object_add(json_obj_event,"datum_size", json_object_new_uint64(l_datum_size)); snprintf(l_buf, sizeof(l_buf), "0x%02hhX",l_datum->header.version_id); json_object_object_add(json_obj_event,"version", json_object_new_string(l_buf)); @@ -1653,7 +1653,7 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) json_object_object_add(json_obj_event,"data_size", json_object_new_uint64(l_datum->header.data_size)); // Signatures - json_object_object_add(json_obj_event,"signs count", json_object_new_uint64(l_event->header.signs_count)); + json_object_object_add(json_obj_event,"signs_count", json_object_new_uint64(l_event->header.signs_count)); l_offset += l_datum_size; while (l_offset + sizeof (l_event->header) < l_event_size ){ dap_sign_t * l_sign =(dap_sign_t *) (l_event->hashes_n_datum_n_signs +l_offset); @@ -1706,9 +1706,9 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) size_t l_arr_end = 0; dap_chain_set_offset_limit_json(json_arr_obj_event, &l_arr_start, &l_arr_end, l_limit, l_offset, l_objs_count); - json_object_object_add(json_obj_event_list,"net name", json_object_new_string(l_net->pub.name)); + json_object_object_add(json_obj_event_list,"net_name", json_object_new_string(l_net->pub.name)); json_object_object_add(json_obj_event_list,"chain", json_object_new_string(l_chain->name)); - json_object_object_add(json_obj_event_list,"obj count", json_object_new_uint64(l_objs_count)); + json_object_object_add(json_obj_event_list,"obj_count", json_object_new_uint64(l_objs_count)); if (l_head) for (size_t i = l_arr_start; i < l_arr_end; i++) @@ -1759,9 +1759,9 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) size_t l_events_count = HASH_COUNT(PVT(l_dag)->events); pthread_mutex_unlock(&PVT(l_dag)->events_mutex); - json_object_object_add(json_obj_event_list,"net name", json_object_new_string(l_net->pub.name)); + json_object_object_add(json_obj_event_list,"net_name", json_object_new_string(l_net->pub.name)); json_object_object_add(json_obj_event_list,"chain", json_object_new_string(l_chain->name)); - json_object_object_add(json_obj_event_list,"total events", json_object_new_uint64(l_events_count)); + json_object_object_add(json_obj_event_list,"total_events", json_object_new_uint64(l_events_count)); json_object_array_add(*a_json_arr_reply, json_obj_event_list); }else if (l_from_events_str && (strcmp(l_from_events_str,"threshold") == 0) ){ @@ -1796,9 +1796,9 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) json_object_object_add(json_obj_event_list, "TRESHOLD", json_arr_obj_event); size_t l_events_count = HASH_COUNT(PVT(l_dag)->events_treshold); pthread_mutex_unlock(&PVT(l_dag)->events_mutex); - json_object_object_add(json_obj_event_list,"net name", json_object_new_string(l_net->pub.name)); + json_object_object_add(json_obj_event_list,"net_name", json_object_new_string(l_net->pub.name)); json_object_object_add(json_obj_event_list,"chain", json_object_new_string(l_chain->name)); - json_object_object_add(json_obj_event_list,"total events", json_object_new_uint64(l_events_count)); + json_object_object_add(json_obj_event_list,"total_events", json_object_new_uint64(l_events_count)); json_object_array_add(*a_json_arr_reply, json_obj_event_list); @@ -1811,17 +1811,17 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) case SUBCMD_EVENT_COUNT: { json_object * json_obj_event_count = json_object_new_object(); - json_object_object_add(json_obj_event_count,"net name", json_object_new_string(l_net->pub.name)); + json_object_object_add(json_obj_event_count,"net_name", json_object_new_string(l_net->pub.name)); json_object_object_add(json_obj_event_count,"chain", json_object_new_string(l_chain->name)); const char * l_gdb_group_events = DAP_CHAIN_CS_DAG(l_chain)->gdb_group_events_round_new; if (l_gdb_group_events) { size_t l_objs_count = dap_global_db_driver_count(l_gdb_group_events, c_dap_global_db_driver_hash_blank, false); - json_object_object_add(json_obj_event_count, "event count in round new", json_object_new_int(l_objs_count)); + json_object_object_add(json_obj_event_count, "event_count_in_round_new", json_object_new_int(l_objs_count)); } size_t l_event_count = HASH_COUNT(PVT(l_dag)->events); size_t l_event_treshold_count = HASH_COUNT(PVT(l_dag)->events_treshold); - json_object_object_add(json_obj_event_count,"atom in events", json_object_new_uint64(l_event_count)); - json_object_object_add(json_obj_event_count,"atom in threshold", json_object_new_uint64(l_event_treshold_count)); + json_object_object_add(json_obj_event_count,"atom_in_events", json_object_new_uint64(l_event_count)); + json_object_object_add(json_obj_event_count,"atom_in_threshold", json_object_new_uint64(l_event_treshold_count)); json_object_array_add(*a_json_arr_reply, json_obj_event_count); } break; case SUBCMD_EVENT_LAST:{ @@ -1833,8 +1833,8 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) char l_buf[DAP_TIME_STR_SIZE]; if (l_last_item) dap_time_to_str_rfc822(l_buf, DAP_TIME_STR_SIZE, l_last_item->ts_created); - json_object_object_add(json_obj_out, "Last event num", json_object_new_uint64(l_last_item ? l_last_item->event_number : 0)); - json_object_object_add(json_obj_out, "Last event hash", json_object_new_string(l_last_item ? + json_object_object_add(json_obj_out, "last_event_num", json_object_new_uint64(l_last_item ? l_last_item->event_number : 0)); + json_object_object_add(json_obj_out, "last_event_hash", json_object_new_string(l_last_item ? dap_hash_fast_to_str_static(&l_last_item->hash) : "empty")); json_object_object_add(json_obj_out, "ts_created", json_object_new_string(l_last_item ? l_buf : "never")); @@ -1864,14 +1864,14 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) HASH_ITER(hh, PVT(l_dag)->events, l_curr_event, l_temp){ if (l_curr_event && dap_hash_fast_compare(&l_datum_hash, &l_curr_event->datum_hash)){ json_obj_event = json_object_new_object(); - json_object_object_add(json_obj_event, "event hash", json_object_new_string(dap_hash_fast_to_str_static(&l_curr_event->hash))); + json_object_object_add(json_obj_event, "event_hash", json_object_new_string(dap_hash_fast_to_str_static(&l_curr_event->hash))); json_object_array_add(json_arr_bl_cache_out, json_obj_event); l_atoms_cnt++; } } pthread_mutex_unlock(&PVT(l_dag)->events_mutex); - json_object_object_add(json_obj_out, "Events", json_arr_bl_cache_out); - json_object_object_add(json_obj_out, "Total",json_object_new_int(l_atoms_cnt)); + json_object_object_add(json_obj_out, "events", json_arr_bl_cache_out); + json_object_object_add(json_obj_out, "total",json_object_new_int(l_atoms_cnt)); json_object_array_add(*a_json_arr_reply, json_obj_out); } break; case SUBCMD_EVENT_SIGN: { // Sign event command @@ -1906,7 +1906,7 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) json_object_new_string(l_event_new_hash_hex_str)); json_object_array_add(json_arr_obj_event, json_obj_sign); - json_object_object_add(json_obj_event_count,"Added new sign with cert, event placed back in round.new", json_arr_obj_event); + json_object_object_add(json_obj_event_count,"added_new_sign", json_arr_obj_event); json_object_array_add(*a_json_arr_reply, json_obj_event_count); } else { @@ -2030,7 +2030,7 @@ static json_object *s_dap_chain_callback_atom_to_json(json_object **a_arr_out, d // Header snprintf(l_buf, sizeof(l_buf), "%hu",l_event->header.version); json_object_object_add(l_jobj,"version", json_object_new_string(l_buf)); - json_object_object_add(l_jobj,"round ID", json_object_new_uint64(l_event->header.round_id)); + json_object_object_add(l_jobj,"round_ID", json_object_new_uint64(l_event->header.round_id)); snprintf(l_buf, sizeof(l_buf), "0x%016"DAP_UINT64_FORMAT_x"",l_event->header.cell_id.uint64); json_object_object_add(l_jobj,"cell_id", json_object_new_string(l_buf)); snprintf(l_buf, sizeof(l_buf), "0x%016"DAP_UINT64_FORMAT_x"",l_event->header.chain_id.uint64);