diff --git a/modules/common/dap_chain_datum.c b/modules/common/dap_chain_datum.c index 2c35206c6a7fd1568bae7143257b4b008ee3a0d9..16132d7a8aac340c8ae8a3cfcf1a76a08703f857 100644 --- a/modules/common/dap_chain_datum.c +++ b/modules/common/dap_chain_datum.c @@ -716,26 +716,8 @@ void dap_chain_datum_dump(dap_string_t *a_str_out, dap_chain_datum_t *a_datum, c dap_string_append_printf(a_str_out,"=== Datum decree ===\n"); dap_string_append_printf(a_str_out, "hash: %s\n", l_hash_str); dap_string_append_printf(a_str_out, "size: %zd\n", l_decree_size); - char *l_type_str = ""; - switch(l_decree->header.type) - { - case DAP_CHAIN_DATUM_DECREE_TYPE_COMMON: - l_type_str = "DECREE_TYPE_COMMON"; - break; - case DAP_CHAIN_DATUM_DECREE_TYPE_SERVICE: - l_type_str = "DECREE_TYPE_SERVICE"; - break; - default: - l_type_str = "DECREE_TYPE_UNKNOWN"; - } - - dap_string_append_printf(a_str_out, "type: %s\n", l_type_str); - - const char *l_subtype_str = dap_chain_datum_decree_subtype_to_str(l_decree->header.sub_type); - - dap_string_append_printf(a_str_out, "subtype: %s\n", l_subtype_str); - dap_chain_datum_decree_certs_dump(a_str_out, l_decree->data_n_signs + l_decree->header.data_size, l_decree->header.signs_size, a_hash_out_type); + dap_chain_datum_decree_dump(a_str_out, l_decree, l_decree_size, a_hash_out_type); } break; case DAP_CHAIN_DATUM_ANCHOR:{ dap_chain_datum_anchor_t *l_anchor = (dap_chain_datum_anchor_t *)a_datum->data; diff --git a/modules/common/dap_chain_datum_decree.c b/modules/common/dap_chain_datum_decree.c index e3af6de341b1d54203474a8b850abf4c0d41a098..9826bcbf9264ccf4edef107679eb5c30e66a2272 100644 --- a/modules/common/dap_chain_datum_decree.c +++ b/modules/common/dap_chain_datum_decree.c @@ -350,6 +350,159 @@ int dap_chain_datum_decree_get_stake_min_signers_count(dap_chain_datum_decree_t return 1; } +void dap_chain_datum_decree_dump(dap_string_t *a_str_out, dap_chain_datum_decree_t *a_decree, size_t a_decree_size, const char *a_hash_out_type) { + char *l_type_str = ""; + switch(a_decree->header.type) + { + case DAP_CHAIN_DATUM_DECREE_TYPE_COMMON: + l_type_str = "DECREE_TYPE_COMMON"; + break; + case DAP_CHAIN_DATUM_DECREE_TYPE_SERVICE: + l_type_str = "DECREE_TYPE_SERVICE"; + break; + default: + l_type_str = "DECREE_TYPE_UNKNOWN"; + } + dap_string_append_printf(a_str_out, "type: %s\n", l_type_str); + const char *l_subtype_str = dap_chain_datum_decree_subtype_to_str(a_decree->header.sub_type); + dap_string_append_printf(a_str_out, "subtype: %s\n", l_subtype_str); + dap_string_append_printf(a_str_out, "TSD:\n"); + for (size_t l_offset = 0; l_offset < a_decree->header.data_size;) { + dap_tsd_t *l_tsd = (dap_tsd_t *)((byte_t*)a_decree->data_n_signs + l_offset); + l_offset += dap_tsd_size(l_tsd); + switch(l_tsd->type) { + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_SIGN: +// return "DAP_CHAIN_DATUM_DECREE_TSD_TYPE_SIGN"; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_FEE: + if (l_tsd->size > sizeof(uint256_t)){ + dap_string_append_printf(a_str_out, "\tFee: <WRONG SIZE>\n"); + break; + } + uint256_t l_fee_value = dap_tsd_get_scalar(l_tsd, uint256_t); + char *l_fee_value_str = dap_chain_balance_print(l_fee_value); + dap_string_append_printf(a_str_out, "\tFee: %s\n", l_fee_value_str); + DAP_DELETE(l_fee_value_str); + break; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_OWNER: + if (l_tsd->size < sizeof(dap_pkey_t)) { + dap_string_append_printf(a_str_out, "\tOwner fingerprint: <WRONG SIZE>\n"); + break; + } + dap_pkey_t *l_owner_pkey = DAP_NEW_Z_SIZE(dap_pkey_t, l_tsd->size); + memcpy(l_owner_pkey, l_tsd->data, l_tsd->size); + dap_hash_fast_t l_owner_pkey_hash = {0}; + dap_hash_fast(l_owner_pkey->pkey, l_owner_pkey->header.size, &l_owner_pkey_hash); + char *l_owner_pkey_str = dap_chain_hash_fast_to_str_new(&l_owner_pkey_hash); + dap_string_append_printf(a_str_out, "\tOwner fingerprint: %s\n", l_owner_pkey_str); + DAP_DELETE(l_owner_pkey_str); + break; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_MIN_OWNER: + if (l_tsd->size > sizeof(uint256_t)){ + dap_string_append_printf(a_str_out, "\tOwner min: <WRONG SIZE>\n"); + break; + } + uint256_t l_owner_min = dap_tsd_get_scalar(l_tsd, uint256_t); + char *l_owner_min_str = dap_chain_balance_print(l_owner_min); + dap_string_append_printf(a_str_out, "\tOwner min: %s\n", l_owner_min_str); + DAP_DELETE(l_owner_min_str); + break; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_FEE_WALLET: + if (l_tsd->size > sizeof(dap_chain_addr_t)) { + dap_string_append_printf(a_str_out, "\tWallet for fee: <WRONG SIZE>\n"); + break; + } + dap_chain_addr_t l_addr_fee_wallet = {0}; + l_addr_fee_wallet = dap_tsd_get_scalar(l_tsd, dap_chain_addr_t); + char *l_addr_fee_wallet_str = dap_chain_addr_to_str(&l_addr_fee_wallet); + dap_string_append_printf(a_str_out, "\tWallet for fee: %s\n", l_addr_fee_wallet_str); + DAP_DELETE(l_addr_fee_wallet_str); + break; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_TX_HASH: + if (l_tsd->size > sizeof(dap_hash_fast_t)) { + dap_string_append_printf(a_str_out, "\tStake tx: <WRONG SIZE>\n"); + break; + } + dap_hash_fast_t l_stake_tx = {0}; + l_stake_tx = dap_tsd_get_scalar(l_tsd, dap_hash_fast_t); + char *l_stake_tx_hash = ""; + if (strcmp(a_hash_out_type, "hex") == 0) { + l_stake_tx_hash = dap_hash_fast_to_str_new(&l_stake_tx); + } else { + l_stake_tx_hash = dap_enc_base58_encode_hash_to_str(&l_stake_tx); + } + dap_string_append_printf(a_str_out, "\tStake tx: %s\n", l_stake_tx_hash); + DAP_DELETE(l_stake_tx_hash); + break; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_VALUE: + if (l_tsd->size > sizeof(uint256_t)){ + dap_string_append_printf(a_str_out, "\tStake value: <WRONG SIZE>\n"); + break; + } + uint256_t l_stake_value = dap_tsd_get_scalar(l_tsd, uint256_t); + char *l_stake_value_str = dap_chain_balance_print(l_stake_value); + dap_string_append_printf(a_str_out, "\tStake value: %s\n", l_stake_value_str); + DAP_DELETE(l_stake_value_str); + break; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_SIGNING_ADDR: + if (l_tsd->size > sizeof(dap_chain_addr_t)) { + dap_string_append_printf(a_str_out, "\tSigning addr: <WRONG SIZE>\n"); + break; + } + dap_chain_addr_t l_stake_addr_signing = {0}; + l_stake_addr_signing = dap_tsd_get_scalar(l_tsd, dap_chain_addr_t); + char *l_stake_addr_signing_str = dap_chain_addr_to_str(&l_stake_addr_signing); + dap_string_append_printf(a_str_out, "\tSigning addr: %s\n", l_stake_addr_signing_str); + dap_chain_hash_fast_t *l_pkey_signing = DAP_NEW(dap_chain_hash_fast_t); + memcpy(l_pkey_signing, l_stake_addr_signing.data.key, sizeof(dap_chain_hash_fast_t)); + char *l_pkey_signing_str = NULL; + if (strcmp(a_hash_out_type, "hex") == 0) { + l_pkey_signing_str = dap_hash_fast_to_str_new(l_pkey_signing); + } else { + l_pkey_signing_str = dap_enc_base58_encode_hash_to_str(l_pkey_signing); + } + dap_string_append_printf(a_str_out, "\tSigning pkey fingerprint: %s\n", l_pkey_signing_str); + DAP_DELETE(l_stake_addr_signing_str); + DAP_DELETE(l_pkey_signing_str); + DAP_DELETE(l_pkey_signing); + break; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_SIGNER_NODE_ADDR: + if(l_tsd->size > sizeof(dap_chain_node_addr_t)){ + dap_string_append_printf(a_str_out, "\tNode addr: <WRONG SIZE>\n"); + break; + } + dap_chain_node_addr_t l_node_addr = dap_tsd_get_scalar(l_tsd, dap_chain_node_addr_t); + dap_string_append_printf(a_str_out, "\tNode addr: "NODE_ADDR_FP_STR"\n", + NODE_ADDR_FP_ARGS_S(l_node_addr)); + break; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_VALUE: + if (l_tsd->size > sizeof(uint256_t)) { + dap_string_append_printf(a_str_out, "\tMin value: <WRONG SIZE>\n"); + break; + } + uint256_t l_min_value = dap_tsd_get_scalar(l_tsd, uint256_t); + char *l_min_value_str = dap_chain_balance_print(l_min_value); + dap_string_append_printf(a_str_out, "\tMin value: %s\n", l_min_value_str); + DAP_DELETE(l_min_value_str); + break; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_SIGNERS_COUNT: + if (l_tsd->size > sizeof(uint256_t)) { + dap_string_append_printf(a_str_out, "\tMin signers count: <WRONG SIZE>\n"); + break; + } + uint256_t l_min_signers_count = dap_tsd_get_scalar(l_tsd, uint256_t); + char *l_min_signers_count_str = dap_chain_balance_print(l_min_signers_count); + dap_string_append_printf(a_str_out, "\tMin signers count: %s\n", l_min_signers_count_str); + DAP_DELETE(l_min_signers_count_str); + break; + default: + dap_string_append_printf(a_str_out, "\t<UNKNOWN_TYPE_TSD_SECTION>\n"); + break; + } + } + dap_chain_datum_decree_certs_dump(a_str_out, a_decree->data_n_signs + a_decree->header.data_size, + a_decree->header.signs_size, a_hash_out_type); +} + void dap_chain_datum_decree_certs_dump(dap_string_t * a_str_out, byte_t * a_signs, size_t a_certs_size, const char *a_hash_out_type) { dap_string_append_printf(a_str_out, "signatures: "); diff --git a/modules/common/include/dap_chain_datum_decree.h b/modules/common/include/dap_chain_datum_decree.h index 4c69d55e7cc227313e8fd5fcd7d067c528014cd9..d4a02a201953cea40051b83a46bdd1430a497146 100644 --- a/modules/common/include/dap_chain_datum_decree.h +++ b/modules/common/include/dap_chain_datum_decree.h @@ -105,6 +105,34 @@ DAP_STATIC_INLINE const char *dap_chain_datum_decree_subtype_to_str(uint16_t a_d } } +DAP_STATIC_INLINE const char *dap_chain_datum_decree_tsd_type_to_str(uint16_t a_decree_tsd_type) { + switch (a_decree_tsd_type) { + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_SIGN: + return "DAP_CHAIN_DATUM_DECREE_TSD_TYPE_SIGN"; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_FEE: + return "DAP_CHAIN_DATUM_DECREE_TSD_TYPE_FEE"; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_OWNER: + return "DAP_CHAIN_DATUM_DECREE_TSD_TYPE_OWNER"; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_MIN_OWNER: + return "DAP_CHAIN_DATUM_DECREE_TSD_TYPE_MIN_OWNER"; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_FEE_WALLET: + return "DAP_CHAIN_DATUM_DECREE_TSD_TYPE_FEE_WALLET"; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_TX_HASH: + return "DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_TX_HASH"; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_VALUE: + return "DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_VALUE"; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_SIGNING_ADDR: + return "DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_SIGNING_ADDR"; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_SIGNER_NODE_ADDR: + return "DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_SIGNER_NODE_ADDR"; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_VALUE: + return "DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_VALUE"; + case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_SIGNERS_COUNT: + return "DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_SIGNERS_COUNT"; + default: + return "DECREE_TSD_TYPE_UNKNOWN"; + } +} /** * @brief dap_chain_datum_decree_get_signs @@ -195,6 +223,15 @@ int dap_chain_datum_decree_get_stake_min_value(dap_chain_datum_decree_t *a_decre */ int dap_chain_datum_decree_get_stake_min_signers_count(dap_chain_datum_decree_t *a_decree, uint256_t *a_min_signers_count); +/** + * @breif dap_chain_datum_decree_dump Dump information about decree + * @param a_str_out pointer to output text buffer + * @param a_decree pointer to decree + * @param a_decree_size size data + * @param a_hash_out_type + */ +void dap_chain_datum_decree_dump(dap_string_t *a_str_out, dap_chain_datum_decree_t *a_decree, size_t a_decree_size, const char *a_hash_out_type); + /** * @brief dap_chain_datum_decree_certs_dump compose decree signatures output string * @param a_str_out pointer to output text buffer diff --git a/modules/service/stake_pos_delegate/dap_chain_net_srv_stake_pos_delegate.c b/modules/service/stake_pos_delegate/dap_chain_net_srv_stake_pos_delegate.c index 077026777b6b416a20235c49ae20ba6e31bb7a20..94271138630f113b3b7db16f5be688606b752990 100644 --- a/modules/service/stake_pos_delegate/dap_chain_net_srv_stake_pos_delegate.c +++ b/modules/service/stake_pos_delegate/dap_chain_net_srv_stake_pos_delegate.c @@ -1225,12 +1225,15 @@ static int s_cli_srv_stake(int a_argc, char **a_argv, char **a_str_reply) return -14; } dap_chain_datum_decree_t *l_decree = s_stake_decree_approve(l_net, &l_tx_hash, l_cert); - if (!l_decree || !s_stake_decree_put(l_decree, l_net)) { + char *l_decree_hash_str = NULL; + if (!l_decree || !(l_decree_hash_str = s_stake_decree_put(l_decree, l_net))) { dap_cli_server_cmd_set_reply_text(a_str_reply, "Approve decree error"); return -12; } DAP_DELETE(l_decree); - dap_cli_server_cmd_set_reply_text(a_str_reply, "Approve decree successfully created"); + dap_cli_server_cmd_set_reply_text(a_str_reply, "Approve decree %s successfully created", + l_decree_hash_str); + DAP_DELETE(l_decree_hash_str); } break; case CMD_KEY_LIST: { const char *l_net_str = NULL, @@ -1387,8 +1390,11 @@ static int s_cli_srv_stake(int a_argc, char **a_argv, char **a_str_reply) } dap_chain_datum_tx_t *l_tx = s_stake_tx_invalidate(l_net, l_final_tx_hash, l_fee, dap_chain_wallet_get_key(l_wallet, 0)); dap_chain_wallet_close(l_wallet); - if (l_tx && s_stake_tx_put(l_tx, l_net)) { - dap_cli_server_cmd_set_reply_text(a_str_reply, "All m-tokens successfully returned to owner"); + char *l_decree_hash_str = NULL; + if (l_tx && (l_decree_hash_str = s_stake_tx_put(l_tx, l_net))) { + dap_cli_server_cmd_set_reply_text(a_str_reply, "All m-tokens successfully returned to " + "owner. Returning tx hash %s.", l_decree_hash_str); + DAP_DELETE(l_decree_hash_str); DAP_DELETE(l_tx); } else { char *l_final_tx_hash_str = dap_chain_hash_fast_to_str_new(l_final_tx_hash); @@ -1408,10 +1414,13 @@ static int s_cli_srv_stake(int a_argc, char **a_argv, char **a_str_reply) return -26; } dap_chain_datum_decree_t *l_decree = s_stake_decree_invalidate(l_net, l_final_tx_hash, l_poa_cert); - if (l_decree && s_stake_decree_put(l_decree, l_net)) { + char *l_decree_hash_str = NULL; + if (l_decree && (l_decree_hash_str = s_stake_decree_put(l_decree, l_net))) { dap_cli_server_cmd_set_reply_text(a_str_reply, "Specified delageted key invalidated. " - "Try to execute this command with -wallet to return m-tokens to owner"); + "Created key invalidation decree %s." + "Try to execute this command with -wallet to return m-tokens to owner", l_decree_hash_str); DAP_DELETE(l_decree); + DAP_DELETE(l_decree_hash_str); } else { char *l_final_tx_hash_str = dap_chain_hash_fast_to_str_new(l_final_tx_hash); dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't invalidate transaction %s, examine log files for details", l_final_tx_hash_str);