diff --git a/modules/common/dap_chain_datum.c b/modules/common/dap_chain_datum.c index 888527d614a1cf45bd29914f9fa2054432188613..2c35206c6a7fd1568bae7143257b4b008ee3a0d9 100644 --- a/modules/common/dap_chain_datum.c +++ b/modules/common/dap_chain_datum.c @@ -731,36 +731,7 @@ 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, "type: %s\n", l_type_str); - char *l_subtype_str = ""; - switch(l_decree->header.sub_type) - { - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_FEE: - l_subtype_str = "DECREE_COMMON_SUBTYPE_FEE"; - break; - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_OWNERS: - l_subtype_str = "DECREE_COMMON_SUBTYPE_OWNERS"; - break; - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_OWNERS_MIN: - l_subtype_str = "DECREE_COMMON_SUBTYPE_OWNERS_MIN"; - break; - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_TON_SIGNERS_MIN: - l_subtype_str = "DECREE_COMMON_SUBTYPE_TON_SIGNERS_MIN"; - break; - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_APPROVE: - l_subtype_str = "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_APPROVE"; - break; - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_INVALIDATE: - l_subtype_str = "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_INVALIDATE"; - break; - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALUE: - l_subtype_str = "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALUE"; - break; - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALIDATORS_COUNT: - l_subtype_str = "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALIDATORS_COUNT"; - break; - default: - l_subtype_str = "DECREE_TYPE_UNKNOWN"; - } + 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); diff --git a/modules/common/include/dap_chain_datum_decree.h b/modules/common/include/dap_chain_datum_decree.h index a2e9ab414eacb02fde712dfff0fe0e1ed9419e0f..4c69d55e7cc227313e8fd5fcd7d067c528014cd9 100644 --- a/modules/common/include/dap_chain_datum_decree.h +++ b/modules/common/include/dap_chain_datum_decree.h @@ -65,7 +65,6 @@ DAP_STATIC_INLINE size_t dap_chain_datum_decree_get_size(dap_chain_datum_decree_ #define DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_FEE 0x0001 #define DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_OWNERS 0x0002 #define DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_OWNERS_MIN 0x0003 -#define DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_TON_SIGNERS_MIN 0x0004 #define DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_APPROVE 0x0005 #define DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_INVALIDATE 0x0006 #define DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALUE 0x0007 @@ -84,6 +83,29 @@ DAP_STATIC_INLINE size_t dap_chain_datum_decree_get_size(dap_chain_datum_decree_ #define DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_VALUE 0x0111 #define DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_SIGNERS_COUNT 0x0112 +DAP_STATIC_INLINE const char *dap_chain_datum_decree_subtype_to_str(uint16_t a_decree_subtype) +{ + switch(a_decree_subtype) { + case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_FEE: + return "DECREE_COMMON_SUBTYPE_FEE"; + case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_OWNERS: + return "DECREE_COMMON_SUBTYPE_OWNERS"; + case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_OWNERS_MIN: + return "DECREE_COMMON_SUBTYPE_OWNERS_MIN"; + case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_APPROVE: + return "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_APPROVE"; + case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_INVALIDATE: + return "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_INVALIDATE"; + case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALUE: + return "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALUE"; + case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALIDATORS_COUNT: + return"DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALIDATORS_COUNT"; + default: + return "DECREE_SUBTYPE_UNKNOWN"; + } +} + + /** * @brief dap_chain_datum_decree_get_signs * @param decree pointer to decree diff --git a/modules/net/dap_chain_net_anchor.c b/modules/net/dap_chain_net_anchor.c index 9812fbdbc7db586ef18df764a2f6f3ba004db1af..7480663f78e016f3e60585ea0408f2a44daaeff0 100644 --- a/modules/net/dap_chain_net_anchor.c +++ b/modules/net/dap_chain_net_anchor.c @@ -92,7 +92,7 @@ int dap_chain_net_anchor_verify(dap_chain_datum_anchor_t * a_anchor, size_t a_da } bool l_is_applied = false; - l_decree = dap_chain_net_decree_get_by_hash(l_decree_hash, &l_is_applied); + l_decree = dap_chain_net_decree_get_by_hash(&l_decree_hash, &l_is_applied); if (!l_decree) { DAP_DELETE(l_signs_arr); diff --git a/modules/net/dap_chain_net_decree.c b/modules/net/dap_chain_net_decree.c index 7ed6a3e767371c3a1801a7d890f0b91877b876e1..190fffd2d7e8f37966a9dba54f882ed5ab725381 100644 --- a/modules/net/dap_chain_net_decree.c +++ b/modules/net/dap_chain_net_decree.c @@ -346,11 +346,10 @@ int dap_chain_net_decree_load(dap_chain_datum_decree_t * a_decree, dap_chain_t * return ret_val; } -dap_chain_datum_decree_t * dap_chain_net_decree_get_by_hash(dap_hash_fast_t a_hash, bool *is_applied) +dap_chain_datum_decree_t *dap_chain_net_decree_get_by_hash(dap_hash_fast_t *a_hash, bool *is_applied) { struct decree_hh* l_decree_hh = NULL; - - HASH_FIND(hh, s_decree_hh, &a_hash, sizeof(dap_hash_fast_t), l_decree_hh); + HASH_FIND(hh, s_decree_hh, a_hash, sizeof(dap_hash_fast_t), l_decree_hh); if (!l_decree_hh) return NULL; @@ -449,10 +448,6 @@ static int s_common_decree_handler(dap_chain_datum_decree_t * a_decree, dap_chai break; l_net->pub.decree->min_num_of_owners = l_uint16_buffer; break; - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_TON_SIGNERS_MIN: - if (!a_apply) - break; - break; case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_APPROVE: if (dap_chain_datum_decree_get_stake_tx_hash(a_decree, &l_hash)){ log_it(L_WARNING,"Can't get tx hash from decree."); diff --git a/modules/net/dap_chain_node_cli_cmd_tx.c b/modules/net/dap_chain_node_cli_cmd_tx.c index 74c5b6c00bf689b27ed89e8e4529457a283e06ce..e9ffbdef9708632a346c09b2f981c72303fcd360 100644 --- a/modules/net/dap_chain_node_cli_cmd_tx.c +++ b/modules/net/dap_chain_node_cli_cmd_tx.c @@ -1389,46 +1389,6 @@ static dap_chain_datum_anchor_t * s_sign_anchor_in_cycle(dap_cert_t ** a_certs, return a_datum_anchor; } -char *s_decree_subtype_to_str(int a_subtype) -{ - switch (a_subtype) - { - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_FEE: - { - return "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_FEE"; - } - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_OWNERS: - { - return "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_OWNERS"; - } - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_OWNERS_MIN: - { - return "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_OWNERS_MIN"; - } - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_TON_SIGNERS_MIN: - { - return "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_TON_SIGNERS_MIN"; - } - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_APPROVE: - { - return "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_APPROVE"; - } - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_INVALIDATE: - { - return "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_INVALIDATE"; - } - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALUE: - { - return "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALUE"; - } - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALIDATORS_COUNT: - { - return "DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALIDATORS_COUNT"; - } - default: return "(UNKNOWN)"; - } -} - // Decree commands handlers int cmd_decree(int a_argc, char **a_argv, char ** a_str_reply) { @@ -1650,11 +1610,13 @@ int cmd_decree(int a_argc, char **a_argv, char ** a_str_reply) l_subtype == DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_OWNERS_MIN) { if (l_decree_chain->id.uint64 != l_chain->id.uint64){ - dap_cli_server_cmd_set_reply_text(a_str_reply, "Decree subtype %s not suppurted by chain %s", s_decree_subtype_to_str(l_subtype), l_decree_chain_str); + dap_cli_server_cmd_set_reply_text(a_str_reply, "Decree subtype %s not suppurted by chain %s", + dap_chain_datum_decree_subtype_to_str(l_subtype), l_decree_chain_str); return -107; } } else if (l_decree_chain->id.uint64 == l_chain->id.uint64){ - dap_cli_server_cmd_set_reply_text(a_str_reply, "Decree subtype %s not suppurted by chain %s", s_decree_subtype_to_str(l_subtype), l_decree_chain_str); + dap_cli_server_cmd_set_reply_text(a_str_reply, "Decree subtype %s not suppurted by chain %s", + dap_chain_datum_decree_subtype_to_str(l_subtype), l_decree_chain_str); return -107; } diff --git a/modules/net/include/dap_chain_net_decree.h b/modules/net/include/dap_chain_net_decree.h index a62ca0d07ae70f7cff4efdc2066d1e5b918879c5..b4223a6181e33b9b1edbfa813c5b8f743e6e087f 100644 --- a/modules/net/include/dap_chain_net_decree.h +++ b/modules/net/include/dap_chain_net_decree.h @@ -41,4 +41,4 @@ int dap_chain_net_decree_apply(dap_hash_fast_t *a_decree_hash, dap_chain_datum_d int dap_chain_net_decree_verify(dap_chain_datum_decree_t *a_decree, dap_chain_net_t *a_net, size_t a_data_size, dap_hash_fast_t *a_decree_hash); int dap_chain_net_decree_load(dap_chain_datum_decree_t * a_decree, dap_chain_t *a_chain); -dap_chain_datum_decree_t *dap_chain_net_decree_get_by_hash(dap_hash_fast_t a_hash, bool *is_applied); +dap_chain_datum_decree_t *dap_chain_net_decree_get_by_hash(dap_hash_fast_t *a_hash, bool *is_applied);