diff --git a/modules/chain/dap_chain_ledger.c b/modules/chain/dap_chain_ledger.c index 586937572e2c12feba35d10bec1f78c0c6cc5b25..59e87cd51ae436d280838d24c0b8420317552293 100644 --- a/modules/chain/dap_chain_ledger.c +++ b/modules/chain/dap_chain_ledger.c @@ -128,7 +128,7 @@ typedef struct dap_chain_ledger_tx_item { } dap_chain_ledger_tx_item_t; typedef struct dap_chain_ledger_tokenizer { - bool type_256; + // bool type_256; char token_ticker[10]; uint64_t sum; UT_hash_handle hh; @@ -395,7 +395,7 @@ int dap_chain_ledger_token_add(dap_ledger_t * a_ledger, dap_chain_datum_token_t DAP_DELETE(l_gdb_group); l_token_item->type = a_token->type; switch(a_token->type){ - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_SIMPLE: {// 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE: {// 256 l_token_item->total_supply = a_token->header_private.total_supply_256; l_token_item->auth_signs= dap_chain_datum_token_simple_signs_parse(a_token,a_token_size, &l_token_item->auth_signs_total, @@ -406,13 +406,13 @@ int dap_chain_ledger_token_add(dap_ledger_t * a_ledger, dap_chain_datum_token_t dap_sign_get_pkey_hash(l_token_item->auth_signs[k],&l_token_item->auth_signs_pkey_hash[k]); } if(s_debug_more) - log_it(L_NOTICE, "Simple token %s added (total_supply = %s total_signs_valid=%hu signs_total=%hu type=DAP_CHAIN_DATUM_TOKEN_TYPE_256_SIMPLE )", + log_it(L_NOTICE, "Simple token %s added (total_supply = %s total_signs_valid=%hu signs_total=%hu type=DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE )", a_token->ticker, dap_chain_balance_to_coins(dap_chain_uint128_from_uint256(a_token->header_private.total_supply_256)), a_token->header_private.signs_valid, a_token->header_private.signs_total); } break; } - case DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE: { + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE: { l_token_item->total_supply = GET_256_FROM_64(a_token->header_private.total_supply); l_token_item->auth_signs= dap_chain_datum_token_simple_signs_parse(a_token,a_token_size, &l_token_item->auth_signs_total, @@ -423,30 +423,30 @@ int dap_chain_ledger_token_add(dap_ledger_t * a_ledger, dap_chain_datum_token_t dap_sign_get_pkey_hash(l_token_item->auth_signs[k],&l_token_item->auth_signs_pkey_hash[k]); } if(s_debug_more) - log_it(L_NOTICE, "Simple token %s added (total_supply = %.1Lf total_signs_valid=%hu signs_total=%hu type=DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE )", + log_it(L_NOTICE, "Simple token %s added (total_supply = %.1Lf total_signs_valid=%hu signs_total=%hu type=DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE )", a_token->ticker, dap_chain_datoshi_to_coins(a_token->header_private.total_supply), a_token->header_private.signs_valid, a_token->header_private.signs_total); } break; } - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_DECL: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: // 256 if(s_debug_more) - log_it( L_NOTICE, "Private token %s type=DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_DECL ", a_token->ticker); + log_it( L_NOTICE, "Private token %s type=DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL ", a_token->ticker); s_token_tsd_parse(a_ledger,l_token_item, a_token, a_token_size); break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: { + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL: { if(s_debug_more) - log_it( L_NOTICE, "Private token %s type=DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL ", a_token->ticker); + log_it( L_NOTICE, "Private token %s type=DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL ", a_token->ticker); s_token_tsd_parse(a_ledger,l_token_item, a_token, a_token_size); break; } - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_UPDATE: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE: // 256 if(s_debug_more) - log_it( L_WARNING, "Private token %s type=DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_UPDATE. Not processed, wait for software update", a_token->ticker); + log_it( L_WARNING, "Private token %s type=DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE. Not processed, wait for software update", a_token->ticker); break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE: + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_UPDATE: if(s_debug_more) - log_it( L_WARNING, "Private token %s type=DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE. Not processed, wait for software update", a_token->ticker); + log_it( L_WARNING, "Private token %s type=DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_UPDATE. Not processed, wait for software update", a_token->ticker); // TODO: Check authorithy //s_token_tsd_parse(a_ledger,l_token_item, a_token, a_token_size); break; @@ -501,7 +501,7 @@ static int s_token_tsd_parse(dap_ledger_t * a_ledger, dap_chain_ledger_token_ite // set total supply case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY:{ - a_token_item->total_supply = dap_chain_datum_token_is_type_256(a_token->type) + a_token_item->total_supply = dap_chain_datum_token_is_old(a_token->type) ? GET_256_FROM_128(dap_tsd_get_scalar(l_tsd,uint64_t)) : dap_tsd_get_scalar(l_tsd,uint256_t); // 256 // a_token_item->total_supply = GET_256_FROM_128(dap_tsd_get_scalar(l_tsd,uint64_t)); @@ -929,17 +929,17 @@ dap_list_t *dap_chain_ledger_token_info(dap_ledger_t *a_ledger) HASH_ITER(hh, PVT(a_ledger)->tokens, l_token_item, l_tmp_item) { const char *l_type_str; switch (l_token_item->type) { - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_SIMPLE: // 256 - case DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE: + case DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE: l_type_str = "SIMPLE"; break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_DECL: // 256 - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: + case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL: l_type_str = "PRIVATE_DECL"; break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_UPDATE: // 256 - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE: + case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_UPDATE: l_type_str = "PRIVATE_UPDATE"; break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PUBLIC: // 256 - case DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC: + case DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PUBLIC: l_type_str = "PUBLIC"; default: l_type_str = "UNKNOWN"; break; @@ -1031,12 +1031,20 @@ void dap_chain_ledger_load_cache(dap_ledger_t *a_ledger) dap_chain_ledger_token_item_t *l_token_item = DAP_NEW_Z(dap_chain_ledger_token_item_t); strncpy(l_token_item->ticker, l_objs[i].key, sizeof(l_token_item->ticker) - 1); l_token_item->ticker[sizeof(l_token_item->ticker) - 1] = '\0'; - l_token_item->datum_token = DAP_NEW_Z_SIZE(dap_chain_datum_token_t, l_objs[i].value_len); - memcpy(l_token_item->datum_token, l_objs[i].value, l_objs[i].value_len); + // l_token_item->datum_token = DAP_NEW_Z_SIZE(dap_chain_datum_token_t, l_objs[i].value_len); + // memcpy(l_token_item->datum_token, l_objs[i].value, l_objs[i].value_len); + size_t l_token_size = l_objs[i].value_len; + l_token_item->datum_token = dap_chain_datum_token_read(l_objs[i].value, &l_token_size); pthread_rwlock_init(&l_token_item->token_emissions_rwlock, NULL); - if (l_token_item->datum_token->type == DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE) { + + // test tsd + // size_t signs_total = 0, signs_valid = 0, l_token_size_test = l_token_size - sizeof(dap_chain_datum_token_t) + sizeof(dap_chain_datum_token_old_t); + // dap_sign_t **sign = dap_chain_datum_token_simple_signs_parse( l_token_item->datum_token, l_token_size_test, &signs_total, &signs_valid); + // printf("---!!! dap_chain_ledger_load_cache() sign_type %d \n", ( (dap_sign_t *)sign[0])->header.type.type ); + + if (l_token_item->datum_token->type == DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE) { l_token_item->total_supply = GET_256_FROM_64(l_token_item->datum_token->header_private.total_supply); - } else if (l_token_item->datum_token->type == DAP_CHAIN_DATUM_TOKEN_TYPE_256_SIMPLE) { + } else if (l_token_item->datum_token->type == DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE) { l_token_item->total_supply = l_token_item->datum_token->header_private.total_supply_256; } HASH_ADD_STR(l_ledger_pvt->tokens, ticker, l_token_item); @@ -1062,9 +1070,10 @@ void dap_chain_ledger_load_cache(dap_ledger_t *a_ledger) const char *c_token_ticker = ((dap_chain_datum_token_emission_t *)l_objs[i].value)->hdr.ticker; dap_chain_ledger_token_item_t *l_token_item = NULL; HASH_FIND_STR(l_ledger_pvt->tokens, c_token_ticker, l_token_item); - l_emission_item->datum_token_emission = l_token_item - ? dap_chain_datum_emission_read(l_objs[i].value, &l_emission_size) - : DAP_DUP_SIZE(l_objs[i].value, l_objs[i].value_len); + // l_emission_item->datum_token_emission = l_token_item + // ? dap_chain_datum_emission_read(l_objs[i].value, &l_emission_size) + // : DAP_DUP_SIZE(l_objs[i].value, l_objs[i].value_len); + l_emission_item->datum_token_emission = dap_chain_datum_emission_read(l_objs[i].value, &l_emission_size); l_emission_item->datum_token_emission_size = l_emission_size; if (l_token_item) { HASH_ADD(hh, l_token_item->token_emissions, datum_token_emission_hash, @@ -1127,14 +1136,20 @@ void dap_chain_ledger_load_cache(dap_ledger_t *a_ledger) l_objs = dap_chain_global_db_gr_load(l_gdb_group, &l_objs_count); for (size_t i = 0; i < l_objs_count; i++) { dap_ledger_wallet_balance_t *l_balance_item = DAP_NEW_Z(dap_ledger_wallet_balance_t); + size_t l_v0_size = sizeof(uint128_t); // for old data + l_balance_item->key = DAP_NEW_Z_SIZE(char, strlen(l_objs[i].key) + 1); strcpy(l_balance_item->key, l_objs[i].key); char *l_ptr = strchr(l_balance_item->key, ' '); if (l_ptr++) { strcpy(l_balance_item->token_ticker, l_ptr); } - //l_balance_item->balance = *(uint128_t *)l_objs[i].value; - l_balance_item->balance = *(uint256_t *)l_objs[i].value; + if ( l_v0_size == l_objs[i].value_len ) { // old data + l_balance_item->balance = uint256_0; + l_balance_item->balance.lo = *(uint128_t *)l_objs[i].value; + } else { + l_balance_item->balance = *(uint256_t *)l_objs[i].value; + } HASH_ADD_KEYPTR(hh, l_ledger_pvt->balance_accounts, l_balance_item->key, strlen(l_balance_item->key), l_balance_item); } @@ -1197,8 +1212,7 @@ int dap_chain_ledger_token_emission_add_check(dap_ledger_t *a_ledger, byte_t *a_ : &l_ledger_priv->treshold_emissions_rwlock); if(l_token_emission_item ) { if(s_debug_more) - // if ( dap_chain_datum_token_emission_is_type_256(l_token_emission_item->datum_token_emission->hdr.type) ) - if ( l_token_emission_item->datum_token_emission->hdr.version == 1 ) + if ( l_token_emission_item->datum_token_emission->hdr.version == 1 ) //&& l_token_emission_item->datum_token_emission->hdr.type_256 ) log_it(L_ERROR, "Can't add token emission datum of %s %s ( %s ): already present in cache", dap_chain_u256tostr(l_token_emission_item->datum_token_emission->hdr.value_256), c_token_ticker, l_hash_str); else @@ -1253,7 +1267,7 @@ int dap_chain_ledger_token_emission_add_check(dap_ledger_t *a_ledger, byte_t *a_ if (l_aproves < l_aproves_valid ){ if(s_debug_more) - if ( l_emission->hdr.version == 1 ) // 256 + if ( l_emission->hdr.version == 1 ) // && l_emission->hdr.type_256 ) // 256 log_it(L_WARNING, "Emission of %s datoshi of %s:%s is wrong: only %u valid aproves when %u need", dap_chain_u256tostr(l_emission->hdr.value_256), a_ledger->net_name, l_emission->hdr.ticker, l_aproves, l_aproves_valid ); else @@ -1337,8 +1351,7 @@ int dap_chain_ledger_token_emission_add(dap_ledger_t *a_ledger, byte_t *a_token_ DAP_DELETE(l_gdb_group); char * l_token_emission_address_str = dap_chain_addr_to_str(&(l_token_emission_item->datum_token_emission->hdr.address) ); if(s_debug_more) - // if ( dap_chain_datum_token_emission_is_type_256(l_token_emission_item->datum_token_emission->hdr.type) ) // 256 - if ( l_token_emission_item->datum_token_emission->hdr.version == 1 ) + if ( l_token_emission_item->datum_token_emission->hdr.version == 1 ) // && l_token_emission_item->datum_token_emission->hdr.type_256 ) log_it(L_NOTICE, "Added token emission datum to %s: type=%s value=%s token=%s to_addr=%s ", l_token_item?"emissions cache":"emissions treshold", c_dap_chain_datum_token_emission_type_str[ l_token_emission_item->datum_token_emission->hdr.type ] , @@ -1362,8 +1375,7 @@ int dap_chain_ledger_token_emission_add(dap_ledger_t *a_ledger, byte_t *a_token_ } else { if (l_token_item) { if(s_debug_more) - // if ( dap_chain_datum_token_emission_is_type_256(((dap_chain_datum_token_emission_t *)a_token_emission)->hdr.type) ) // 256 - if ( ((dap_chain_datum_token_emission_t *)a_token_emission)->hdr.version == 1 ) // 256 + if ( ((dap_chain_datum_token_emission_t *)a_token_emission)->hdr.version == 1 ) // && ((dap_chain_datum_token_emission_t *)a_token_emission)->hdr.type_256 ) // 256 log_it(L_ERROR, "Duplicate token emission datum of %s %s ( %s )", dap_chain_u256tostr(((dap_chain_datum_token_emission_t *)a_token_emission)->hdr.value_256), c_token_ticker, l_hash_str); else diff --git a/modules/common/dap_chain_datum_token.c b/modules/common/dap_chain_datum_token.c index ebcd44d1c3593f02d93f896cbda9b0f4889c228a..dd1da5ab30a840b70b5420351882fb55520b175d 100644 --- a/modules/common/dap_chain_datum_token.c +++ b/modules/common/dap_chain_datum_token.c @@ -34,13 +34,13 @@ const char *c_dap_chain_datum_token_emission_type_str[]={ [DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_AUTH] = "AUTH", [DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_ALGO] = "ALGO", [DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_ATOM_OWNER] = "OWNER", - [DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_SMART_CONTRACT] = "SMART_CONTRACT", + [DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_SMART_CONTRACT] = "SMART_CONTRACT" // 256 types // [DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_UNDEFINED] = "UNDEFINED", // [DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_AUTH] = "AUTH", // [DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_ALGO] = "ALGO", // [DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_ATOM_OWNER] = "OWNER", - // [DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_SMART_CONTRACT] = "SMART_CONTRACT", + // [DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_SMART_CONTRACT] = "SMART_CONTRACT" }; const char *c_dap_chain_datum_token_flag_str[] = { @@ -73,12 +73,12 @@ dap_tsd_t* dap_chain_datum_token_tsd_get(dap_chain_datum_token_t * a_token, size } switch( a_token->type){ - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_DECL: - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: + case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL: l_tsd_size = a_token->header_private_decl.tsd_total_size; break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_UPDATE: - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE: + case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_UPDATE: l_tsd_size = a_token->header_private_update.tsd_total_size; break; default: return NULL; @@ -109,6 +109,56 @@ dap_tsd_t* dap_chain_datum_token_tsd_get(dap_chain_datum_token_t * a_token, size } } +dap_chain_datum_token_t *dap_chain_datum_token_read(byte_t *a_token_serial, size_t *a_token_size) { + + uint16_t l_token_type = ((dap_chain_datum_token_t *)a_token_serial)->type; + if ( dap_chain_datum_token_is_old(l_token_type) ) { + dap_chain_datum_token_old_t * l_token_old = DAP_NEW_Z_SIZE(dap_chain_datum_token_old_t, (*a_token_size)); + memcpy(l_token_old, a_token_serial, (*a_token_size)); + size_t l_token_size = (*a_token_size) - sizeof(*l_token_old) + sizeof(dap_chain_datum_token_t); + dap_chain_datum_token_t * l_token = DAP_NEW_Z_SIZE(dap_chain_datum_token_t, l_token_size); + strncpy(l_token->ticker, l_token_old->ticker, sizeof(l_token_old->ticker) ); + size_t l_token_tsd_size = (*a_token_size) - sizeof(*l_token_old); + memcpy(l_token->data_n_tsd, l_token_old->data_n_tsd, l_token_tsd_size); + + switch( l_token_type ){ + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE: { + l_token->type = DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE; // 256 + l_token->header_private.total_supply_256 = GET_256_FROM_64(l_token_old->header_private.total_supply); + l_token->header_private.signs_valid = l_token_old->header_private.signs_valid; + l_token->header_private.signs_total = l_token_old->header_private.signs_total; + break; + } + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL: + l_token->type = DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL; // 256 + l_token->header_private_decl.flags = l_token_old->header_private_decl.flags; + l_token->header_private_decl.tsd_total_size = l_token_old->header_private_decl.tsd_total_size; + break; + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_UPDATE: + l_token->type = DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE; // 256 + l_token->header_private_update.padding = l_token_old->header_private_update.padding; + l_token->header_private_update.tsd_total_size = l_token_old->header_private_update.tsd_total_size; + break; + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PUBLIC: + l_token->type = DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC; // 256 + l_token->header_public.total_supply_256 = GET_256_FROM_128(l_token_old->header_public.total_supply); + l_token->header_public.premine_supply_256 = GET_256_FROM_128(l_token_old->header_public.premine_supply); + memcpy(&l_token->header_public.premine_address, &l_token_old->header_public.premine_address, sizeof(l_token_old->header_public.premine_address)); + break; + default: + DAP_DELETE(l_token_old); + return NULL; + } + DAP_DELETE(l_token_old); + return l_token; + } else { + dap_chain_datum_token_t * l_token = DAP_NEW_Z_SIZE(dap_chain_datum_token_t, (*a_token_size)); + memcpy(l_token, a_token_serial, (*a_token_size)); + return l_token; + } + return NULL; +} + /** * @brief dap_chain_datum_token_flags_dump * @param a_str_out @@ -185,6 +235,7 @@ dap_sign_t ** dap_chain_datum_token_simple_signs_parse(dap_chain_datum_token_t * *a_signs_valid = a_datum_token->header_private.signs_valid; size_t l_offset = 0; uint16_t n = 0; + while( l_offset < (a_datum_token_size-sizeof (a_datum_token) ) && n < a_datum_token->header_private.signs_total ) { dap_sign_t *l_sign = (dap_sign_t *) ( a_datum_token->data_n_tsd + l_offset); size_t l_sign_size = dap_sign_get_size(l_sign); @@ -233,15 +284,15 @@ size_t dap_chain_datum_emission_get_size(uint8_t *a_emission_serial) case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_ALGO: l_ret += sizeof(l_emission->data.type_algo); break; - // case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_ATOM_OWNER: // 256 + // case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_ATOM_OWNER: case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_ATOM_OWNER: l_ret += sizeof(l_emission->data.type_atom_owner); break; - // case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_SMART_CONTRACT: // 256 + // case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_SMART_CONTRACT: case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_SMART_CONTRACT: l_ret += sizeof(l_emission->data.type_presale); break; - // case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_UNDEFINED: // 256 + // case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_UNDEFINED: case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_UNDEFINED: default: break; @@ -260,6 +311,7 @@ dap_chain_datum_token_emission_t *dap_chain_datum_emission_read(byte_t *a_emissi size_t l_add_size = sizeof(l_emission->hdr) - l_old_hdr_size; l_emission = DAP_NEW_Z_SIZE(dap_chain_datum_token_emission_t, l_emission_size + l_add_size); l_emission->hdr.version = 1; + // l_emission->hdr.type_256 = false; memcpy(l_emission, a_emission_serial, l_old_hdr_size); memcpy((byte_t *)l_emission + sizeof(l_emission->hdr), a_emission_serial + l_old_hdr_size, @@ -272,25 +324,24 @@ dap_chain_datum_token_emission_t *dap_chain_datum_emission_read(byte_t *a_emissi return l_emission; } -#define DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE 0x0001 +// #define DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE 0x0001 // Extended declaration of privatetoken with in-time control -#define DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL 0x0002 +// #define DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL 0x0002 // Token update -#define DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE 0x0003 +// #define DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_UPDATE 0x0003 // Open token with now ownership -#define DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC 0x0004 - +// #define DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PUBLIC 0x0004 // 256 TYPE -bool dap_chain_datum_token_is_type_256(uint8_t a_type) { +bool dap_chain_datum_token_is_old(uint8_t a_type) { switch(a_type) { - case DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE: - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE: - case DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC: - return false; - default: + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE: + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL: + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_UPDATE: + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PUBLIC: return true; + default: + return false; } } diff --git a/modules/common/include/dap_chain_datum_token.h b/modules/common/include/dap_chain_datum_token.h index 9c53b76b4336964519d590e0af5ae28f619c3f48..8a6ef75ec5252f5d8c0811d59b28658331f59aa6 100644 --- a/modules/common/include/dap_chain_datum_token.h +++ b/modules/common/include/dap_chain_datum_token.h @@ -31,6 +31,36 @@ #include "dap_tsd.h" #include "dap_strfuncs.h" + +// Token declaration +typedef struct dap_chain_datum_token_old { + uint16_t type; + char ticker[DAP_CHAIN_TICKER_SIZE_MAX]; + union { + struct { + uint64_t total_supply; + uint16_t signs_valid; + uint16_t signs_total; + } DAP_ALIGN_PACKED header_private; + struct { + uint16_t flags; + size_t tsd_total_size; + } DAP_ALIGN_PACKED header_private_decl; + struct { + uint16_t padding; + size_t tsd_total_size; + } DAP_ALIGN_PACKED header_private_update; + struct { + uint128_t total_supply; + uint128_t premine_supply; + dap_chain_addr_t premine_address; + uint32_t flags; + } DAP_ALIGN_PACKED header_public; + }; + byte_t data_n_tsd[]; +} DAP_ALIGN_PACKED dap_chain_datum_token_old_t; + + // Token declaration typedef struct dap_chain_datum_token{ uint16_t type; @@ -74,23 +104,23 @@ typedef struct dap_chain_datum_token{ // Token declaration type // Simple private token decl -#define DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE 0x0001 +#define DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE 0x0001 // Extended declaration of privatetoken with in-time control -#define DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL 0x0002 +#define DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL 0x0002 // Token update -#define DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE 0x0003 +#define DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_UPDATE 0x0003 // Open token with now ownership -#define DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC 0x0004 +#define DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PUBLIC 0x0004 // 256 // Simple private token decl -#define DAP_CHAIN_DATUM_TOKEN_TYPE_256_SIMPLE 0x0005 +#define DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE 0x0005 // Extended declaration of privatetoken with in-time control -#define DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_DECL 0x0006 +#define DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL 0x0006 // Token update -#define DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_UPDATE 0x0007 +#define DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE 0x0007 // Open token with now ownership -#define DAP_CHAIN_DATUM_TOKEN_TYPE_256_PUBLIC 0x0008 +#define DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC 0x0008 // Macros for token flags @@ -236,6 +266,7 @@ typedef struct dap_chain_datum_token_emission{ uint256_t value_256; }; uint8_t nonce[DAP_CHAIN_DATUM_NONCE_SIZE]; + // bool type_256; // emission 256 } DAP_ALIGN_PACKED hdr; union { struct { @@ -279,8 +310,9 @@ dap_tsd_t* dap_chain_datum_token_tsd_get(dap_chain_datum_token_t * a_token, siz void dap_chain_datum_token_flags_dump(dap_string_t * a_str_out, uint16_t a_flags); void dap_chain_datum_token_certs_dump(dap_string_t * a_str_out, byte_t * a_data_n_tsd, size_t a_certs_size); dap_sign_t ** dap_chain_datum_token_simple_signs_parse(dap_chain_datum_token_t * a_datum_token, size_t a_datum_token_size, size_t *a_signs_count, size_t * a_signs_valid); +dap_chain_datum_token_t *dap_chain_datum_token_read(byte_t *a_token_serial, size_t *a_token_size); dap_chain_datum_token_emission_t *dap_chain_datum_emission_read(byte_t *a_emission_serial, size_t *a_emission_size); size_t dap_chain_datum_emission_get_size(uint8_t *a_emission_serial); // 256 TYPE -bool dap_chain_datum_token_is_type_256(uint8_t a_type); +bool dap_chain_datum_token_is_old(uint8_t a_type); diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c index 3d28d9519224fa0c183f74e5a2cf207cde57e674..927f51bb816ebe988d8ad7c905e9b382f2b05414 100644 --- a/modules/net/dap_chain_net.c +++ b/modules/net/dap_chain_net.c @@ -2581,6 +2581,7 @@ void dap_chain_net_dump_datum(dap_string_t * a_str_out, dap_chain_datum_t * a_da return; } switch (a_datum->header.type_id){ + case DAP_CHAIN_DATUM_256_TOKEN_DECL: case DAP_CHAIN_DATUM_TOKEN_DECL:{ dap_chain_datum_token_t * l_token = (dap_chain_datum_token_t*) a_datum->data; size_t l_token_size = a_datum->header.data_size; @@ -2593,12 +2594,18 @@ void dap_chain_net_dump_datum(dap_string_t * a_str_out, dap_chain_datum_t * a_da dap_string_append_printf(a_str_out, "ticker: %s\n", l_token->ticker); dap_string_append_printf(a_str_out, "size: %zd\n", l_token_size); switch (l_token->type) { + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE: case DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE:{ dap_string_append_printf(a_str_out, "type: SIMPLE\n"); dap_string_append_printf(a_str_out, "sign_total: %hu\n", l_token->header_private.signs_total ); dap_string_append_printf(a_str_out, "sign_valid: %hu\n", l_token->header_private.signs_valid ); - dap_string_append_printf(a_str_out, "total_supply: %"DAP_UINT64_FORMAT_U"\n", l_token->header_private.total_supply ); + if ( dap_chain_datum_token_is_old(l_token->type) ) + dap_string_append_printf(a_str_out, "total_supply: %"DAP_UINT64_FORMAT_U"\n", l_token->header_private.total_supply ); + else + dap_string_append_printf(a_str_out, "total_supply: %s\n", + dap_chain_u256tostr(l_token->header_private.total_supply_256)); }break; + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_UPDATE: case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE:{ dap_string_append_printf(a_str_out,"type: PRIVATE_UPDATE\n"); dap_tsd_t * l_tsd = dap_chain_datum_token_tsd_get(l_token, l_token_size); @@ -2625,8 +2632,14 @@ void dap_chain_net_dump_datum(dap_string_t * a_str_out, dap_chain_datum_t * a_da dap_tsd_get_scalar(l_tsd, uint16_t)); break; case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY: - dap_string_append_printf(a_str_out,"total_supply: %s\n", - dap_chain_balance_print(dap_tsd_get_scalar(l_tsd, uint128_t))); + if ( dap_chain_datum_token_is_old(l_token->type) ) + dap_string_append_printf(a_str_out,"total_supply: %s\n", + dap_chain_balance_print( + dap_tsd_get_scalar(l_tsd, uint128_t))); + else // 256 + dap_string_append_printf(a_str_out,"total_supply: %s\n", + dap_chain_u256tostr( + dap_tsd_get_scalar(l_tsd, uint256_t))); break; case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SIGNS_VALID : dap_string_append_printf(a_str_out,"total_signs_valid: %u\n", @@ -2711,6 +2724,7 @@ void dap_chain_net_dump_datum(dap_string_t * a_str_out, dap_chain_datum_t * a_da } } }break; + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL: case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL:{ dap_string_append_printf(a_str_out,"type: PRIVATE_DECL\n"); dap_string_append_printf(a_str_out,"flags: "); @@ -2730,8 +2744,14 @@ void dap_chain_net_dump_datum(dap_string_t * a_str_out, dap_chain_datum_t * a_da } switch( l_tsd->type){ case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY: - dap_string_append_printf(a_str_out,"total_supply: %s\n", - dap_chain_balance_print(dap_tsd_get_scalar(l_tsd, uint128_t))); + if ( dap_chain_datum_token_is_old(l_token->type) ) + dap_string_append_printf(a_str_out,"total_supply: %s\n", + dap_chain_balance_print( + dap_tsd_get_scalar(l_tsd, uint128_t))); + else // 256 + dap_string_append_printf(a_str_out,"total_supply: %s\n", + dap_chain_u256tostr( + dap_tsd_get_scalar(l_tsd, uint256_t))); break; case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SIGNS_VALID : dap_string_append_printf(a_str_out,"total_signs_valid: %u\n", @@ -2771,6 +2791,7 @@ void dap_chain_net_dump_datum(dap_string_t * a_str_out, dap_chain_datum_t * a_da size_t l_certs_field_size = l_token_size - sizeof(*l_token) - l_token->header_private_decl.tsd_total_size; dap_chain_datum_token_certs_dump(a_str_out, l_token->data_n_tsd, l_certs_field_size); }break; + case DAP_CHAIN_DATUM_256_TX: case DAP_CHAIN_DATUM_TX:{ dap_chain_datum_tx_t * l_tx =(dap_chain_datum_tx_t *) a_datum->data; char buf[50]; diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c index 7de498427f4361a133ab5c1fbad61c19f5416769..c85e049e4a896575389d52e8db520cce6187b28d 100644 --- a/modules/net/dap_chain_node_cli_cmd.c +++ b/modules/net/dap_chain_node_cli_cmd.c @@ -1798,6 +1798,7 @@ int com_tx_wallet(int argc, char ** argv, char **str_reply) dap_string_append_printf(l_string_ret, "balance:\n"); else dap_string_append_printf(l_string_ret, "balance: 0"); + for(size_t i = 0; i < l_addr_tokens_size; i++) { if(l_addr_tokens[i]) { // uint128_t l_balance = dap_chain_ledger_calc_balance(l_ledger, l_addr, l_addr_tokens[i]); @@ -2457,7 +2458,7 @@ int com_token_update(int a_argc, char ** a_argv, char ** a_str_reply) int l_arg_index = 1; const char * l_type_str = NULL; - uint16_t l_type = DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE; + uint16_t l_type = DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE; // 256 const char * l_ticker = NULL; @@ -2502,7 +2503,8 @@ int com_token_update(int a_argc, char ** a_argv, char ** a_str_reply) size_t l_datum_data_offset = 0; switch(l_type){ - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE:{ + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_UPDATE: + case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE:{ // 256 dap_list_t *l_tsd_list = dap_list_alloc(); size_t l_tsd_total_size = 0; l_arg_index++; @@ -2523,7 +2525,7 @@ int com_token_update(int a_argc, char ** a_argv, char ** a_str_reply) } // Add flags as set_flags TDS section dap_tsd_t * l_tsd = dap_tsd_create_scalar( - DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_SET_FLAGS, l_flags); + DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_SET_FLAGS, l_flags); dap_list_append( l_tsd_list, l_tsd); l_tsd_total_size+= dap_tsd_size( l_tsd); @@ -2554,9 +2556,20 @@ int com_token_update(int a_argc, char ** a_argv, char ** a_str_reply) return -10; } } else if ( strcmp( a_argv[l_arg_index],"-total_supply" )==0){ // Total supply - uint128_t l_param_value = dap_chain_balance_scan(l_arg_param); - dap_tsd_t * l_tsd = dap_tsd_create_scalar( - DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY, l_param_value); + // uint128_t l_param_value = dap_chain_balance_scan(l_arg_param); + // uint256_t l_param_value = GET_256_FROM_128(dap_chain_balance_scan(l_arg_param)); // 256 + // dap_tsd_t * l_tsd = dap_tsd_create_scalar( + // DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY, l_param_value); + dap_tsd_t * l_tsd; + if ( dap_chain_datum_token_is_old(l_type) ) { + uint128_t l_param_value = dap_chain_balance_scan(l_arg_param); + l_tsd = dap_tsd_create_scalar( + DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY, l_param_value); + } else { // 256 + uint256_t l_param_value = GET_256_FROM_128(dap_chain_balance_scan(l_arg_param)); // 256 + l_tsd = dap_tsd_create_scalar( + DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY, l_param_value); + } dap_list_append( l_tsd_list, l_tsd); l_tsd_total_size+= dap_tsd_size( l_tsd); }else if ( strcmp( a_argv[l_arg_index],"-total_signs_valid" )==0){ // Signs valid @@ -2794,11 +2807,11 @@ int com_token_decl(int a_argc, char ** a_argv, char ** a_str_reply) dap_chain_net_t * l_net = NULL; // 256 - bool l_type_256 = dap_chain_node_cli_check_option(a_argv, l_arg_index, a_argc, "-256") == -1 ? false : true; + bool l_type_256 = true; //dap_chain_node_cli_check_option(a_argv, l_arg_index, a_argc, "-256") == -1 ? false : true; uint16_t l_type = l_type_256 - ? DAP_CHAIN_DATUM_TOKEN_TYPE_256_SIMPLE // 256 - : DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE; + ? DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE // 256 + : DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE; const char * l_hash_out_type = NULL; dap_chain_node_cli_find_option_val(a_argv, l_arg_index, a_argc, "-H", &l_hash_out_type); @@ -2831,14 +2844,14 @@ int com_token_decl(int a_argc, char ** a_argv, char ** a_str_reply) if (l_type_str) { if (strcmp( l_type_str, "private") == 0){ - l_type = l_type_256 ? DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_DECL // 256 - : DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL; + l_type = l_type_256 ? DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL // 256 + : DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL; }else if (strcmp( l_type_str, "private_simple") == 0){ - l_type = l_type_256 ? DAP_CHAIN_DATUM_TOKEN_TYPE_256_SIMPLE // 256 - : DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE; + l_type = l_type_256 ? DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE // 256 + : DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE; }else if (strcmp( l_type_str, "public_simple") == 0){ - l_type = l_type_256 ? DAP_CHAIN_DATUM_TOKEN_TYPE_256_PUBLIC // 256 - : DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC; + l_type = l_type_256 ? DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC // 256 + : DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PUBLIC; } } @@ -2846,8 +2859,8 @@ int com_token_decl(int a_argc, char ** a_argv, char ** a_str_reply) size_t l_datum_data_offset = 0; switch(l_type){ - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_DECL: // 256 - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: { + case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL: { dap_list_t *l_tsd_list = dap_list_alloc(); size_t l_tsd_total_size = 0; uint16_t l_flags = 0; @@ -2869,7 +2882,7 @@ int com_token_decl(int a_argc, char ** a_argv, char ** a_str_reply) } else if ( strcmp( a_argv[l_arg_index],"-total_supply" )==0){ // Total supply // uint128_t l_param_value = dap_chain_balance_scan(l_arg_param); dap_tsd_t * l_tsd; - if ( l_type == DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_DECL ) { + if ( l_type == DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL ) { // 256 uint256_t l_param_value = GET_256_FROM_128(dap_chain_balance_scan(l_arg_param)); l_tsd = dap_tsd_create_scalar(DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY, l_param_value); } else { @@ -2937,7 +2950,9 @@ int com_token_decl(int a_argc, char ** a_argv, char ** a_str_reply) log_it(L_DEBUG,"Prepeared TSD sections on %zd total size", l_tsd_total_size); // Create new datum token l_datum_token = DAP_NEW_Z_SIZE(dap_chain_datum_token_t, sizeof(dap_chain_datum_token_t)+l_tsd_total_size ) ; - l_datum_token->type = DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL; + + l_datum_token->type = l_type; //DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL; + dap_snprintf(l_datum_token->ticker, sizeof(l_datum_token->ticker), "%s", l_ticker); l_datum_token->header_private_decl.flags = l_flags; log_it(L_DEBUG,"Token declaration '%s' initialized", l_datum_token->ticker); @@ -2967,10 +2982,8 @@ int com_token_decl(int a_argc, char ** a_argv, char ** a_str_reply) switch (l_tsd->type){ case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY: { char *l_balance; - l_balance = l_type == DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_DECL - ? dap_chain_balance_print( - dap_chain_uint128_from_uint256(dap_tsd_get_scalar(l_tsd, uint256_t)) - ) + l_balance = l_type == DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL + ? dap_chain_u256tostr(dap_tsd_get_scalar(l_tsd, uint256_t)) : dap_chain_balance_print(dap_tsd_get_scalar(l_tsd, uint128_t)); log_it(L_DEBUG,"== TOTAL_SUPPLY: %s", l_balance); DAP_DELETE(l_balance); @@ -3010,8 +3023,8 @@ int com_token_decl(int a_argc, char ** a_argv, char ** a_str_reply) }break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_SIMPLE: // 256 - case DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE: { + case DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE: { // Total supply value dap_chain_node_cli_find_option_val(a_argv, l_arg_index, a_argc, "-total_supply", &l_total_supply_str); @@ -3089,8 +3102,8 @@ int com_token_decl(int a_argc, char ** a_argv, char ** a_str_reply) // Create new datum token l_datum_token = DAP_NEW_Z_SIZE(dap_chain_datum_token_t, sizeof(dap_chain_datum_token_t)); l_datum_token->type = l_type_256 - ? DAP_CHAIN_DATUM_TOKEN_TYPE_256_SIMPLE // 256 - : DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE; + ? DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE // 256 + : DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE; dap_snprintf(l_datum_token->ticker, sizeof(l_datum_token->ticker), "%s", l_ticker); if ( l_type_256 ) l_datum_token->header_private.total_supply_256 = l_total_supply; @@ -3181,7 +3194,7 @@ int com_token_emit(int a_argc, char ** a_argv, char ** a_str_reply) const char * l_addr_str = NULL; const char * l_emission_hash_str = NULL; - bool l_type_256 = false; + bool l_type_256 = true; // false; char * l_emission_hash_str_new = NULL; dap_chain_hash_fast_t l_emission_hash={0}; @@ -3226,7 +3239,7 @@ int com_token_emit(int a_argc, char ** a_argv, char ** a_str_reply) // 256 // dap_chain_node_cli_find_option_val(a_argv, arg_index, a_argc, "-256", &l_type_256); - l_type_256 = dap_chain_node_cli_check_option(a_argv, arg_index, a_argc, "-256") == -1 ? false : true; + //l_type_256 = dap_chain_node_cli_check_option(a_argv, arg_index, a_argc, "-256") == -1 ? false : true; // Emission certs dap_chain_node_cli_find_option_val(a_argv, arg_index, a_argc, "-certs", &l_certs_str); @@ -3343,14 +3356,15 @@ int com_token_emit(int a_argc, char ** a_argv, char ** a_str_reply) l_emission = DAP_NEW_Z_SIZE(dap_chain_datum_token_emission_t, l_emission_size); - if ( !l_type_256 ) + if ( !l_type_256 ) { // l_emission->hdr.type = DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_AUTH; - //l_emission->hdr.type_value_256 = false; + // l_emission->hdr.type_256 = false; l_emission->hdr.value = dap_chain_uint256_to(l_emission_value); - else // 256 + } else { // 256 // l_emission->hdr.type = DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_AUTH; - // l_emission->hdr.type_value_256 = true; + // l_emission->hdr.type_256 = true; l_emission->hdr.value_256 = l_emission_value; + } l_emission->hdr.type = DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_AUTH; l_emission->hdr.version = 1; diff --git a/modules/net/dap_chain_node_cli_cmd_tx.c b/modules/net/dap_chain_node_cli_cmd_tx.c index 911048d894403226f29d0f6b16719b4849bf826d..a910f232d0b3e19084e0a30cf8dec5588e492fde 100644 --- a/modules/net/dap_chain_node_cli_cmd_tx.c +++ b/modules/net/dap_chain_node_cli_cmd_tx.c @@ -1196,36 +1196,36 @@ static char* dap_db_history_token_list(dap_chain_t * a_chain, const char *a_toke dap_string_append(l_str_out, "\n"); dap_string_append_printf(l_str_out, "token %s %s, created: %s\n", l_token->ticker, - dap_chain_datum_token_is_type_256(l_token->type) ? " 256_t " : "", + dap_chain_datum_token_is_old(l_token->type) ? "" : " 256_t ", l_time_str ); switch (l_token->type) { // Simple private token decl - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_SIMPLE: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE: // 256 dap_string_append_printf(l_str_out, " total_supply: %s(%s), signs: valid/total %02d/%02d \n", dap_chain_balance_to_coins(dap_chain_uint128_from_uint256(l_token->header_private.total_supply_256)), dap_chain_u256tostr(l_token->header_private.total_supply_256), l_token->header_private.signs_valid, l_token->header_private.signs_total); break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE: + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE: dap_string_append_printf(l_str_out, " total_supply: %.0Lf(%"DAP_UINT64_FORMAT_U"), signs: valid/total %02d/%02d \n", dap_chain_datoshi_to_coins(l_token->header_private.total_supply), l_token->header_private.total_supply, l_token->header_private.signs_valid, l_token->header_private.signs_total); break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_DECL: // 256 - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: + case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL: dap_string_append_printf(l_str_out, " tsd_total_size: %"DAP_UINT64_FORMAT_U", flags: 0x%x \n", l_token->header_private_decl.tsd_total_size, l_token->header_private_decl.flags); break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_UPDATE: // 256 - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE: + case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_UPDATE: dap_string_append_printf(l_str_out, " tsd_total_size: %"DAP_UINT64_FORMAT_U", padding: 0x%x \n", l_token->header_private_update.tsd_total_size, l_token->header_private_update.padding); break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PUBLIC: { // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC: { // 256 char *l_addr = dap_chain_addr_to_str(&l_token->header_public.premine_address); char * l_balance = dap_chain_balance_to_coins(dap_chain_uint128_from_uint256(l_token->header_public.total_supply_256)); dap_string_append_printf(l_str_out, @@ -1238,7 +1238,7 @@ static char* dap_db_history_token_list(dap_chain_t * a_chain, const char *a_toke DAP_DELETE(l_addr); DAP_DELETE(l_balance); }break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC: { + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PUBLIC: { char *l_addr = dap_chain_addr_to_str(&l_token->header_public.premine_address); char * l_balance = dap_chain_balance_to_coins(l_token->header_public.total_supply); dap_string_append_printf(l_str_out, @@ -1355,39 +1355,39 @@ static char* dap_db_history_filter(dap_chain_t * a_chain, dap_ledger_t *a_ledger dap_string_append_printf(l_str_out, "token %s, created: %s\n", l_token->ticker, l_time_str); switch (l_token->type) { // Simple private token decl - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_SIMPLE: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE: // 256 dap_string_append_printf(l_str_out, " 256_t total_supply: %s(%s), signs: valid/total %02d/%02d \n", dap_chain_balance_to_coins(dap_chain_uint128_from_uint256(l_token->header_private.total_supply_256)), dap_chain_u256tostr(l_token->header_private.total_supply_256), l_token->header_private.signs_valid, l_token->header_private.signs_total); break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_SIMPLE: + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_SIMPLE: dap_string_append_printf(l_str_out, " total_supply: %.0Lf(%"DAP_UINT64_FORMAT_U"), signs: valid/total %02d/%02d \n", dap_chain_datoshi_to_coins(l_token->header_private.total_supply), l_token->header_private.total_supply, l_token->header_private.signs_valid, l_token->header_private.signs_total); break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_DECL: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: // 256 dap_string_append_printf(l_str_out, "256_t tsd_total_size: %"DAP_UINT64_FORMAT_U", flags: 0x%x \n", l_token->header_private_decl.tsd_total_size, l_token->header_private_decl.flags); break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_DECL: + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_DECL: dap_string_append_printf(l_str_out, " tsd_total_size: %"DAP_UINT64_FORMAT_U", flags: 0x%x \n", l_token->header_private_decl.tsd_total_size, l_token->header_private_decl.flags); break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PRIVATE_UPDATE: // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE: // 256 dap_string_append_printf(l_str_out, "256_t tsd_total_size: %"DAP_UINT64_FORMAT_U", padding: 0x%x \n", l_token->header_private_update.tsd_total_size, l_token->header_private_update.padding); break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_PRIVATE_UPDATE: + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PRIVATE_UPDATE: dap_string_append_printf(l_str_out, " tsd_total_size: %"DAP_UINT64_FORMAT_U", padding: 0x%x \n", l_token->header_private_update.tsd_total_size, l_token->header_private_update.padding); break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_256_PUBLIC: { // 256 + case DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC: { // 256 char *l_addr = dap_chain_addr_to_str(&l_token->header_public.premine_address); char * l_balance = dap_chain_balance_to_coins(l_token->header_public.total_supply); dap_string_append_printf(l_str_out, @@ -1400,7 +1400,7 @@ static char* dap_db_history_filter(dap_chain_t * a_chain, dap_ledger_t *a_ledger DAP_DELETE(l_addr); DAP_DELETE(l_balance); } break; - case DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC: { + case DAP_CHAIN_DATUM_TOKEN_TYPE_OLD_PUBLIC: { char *l_addr = dap_chain_addr_to_str(&l_token->header_public.premine_address); char * l_balance = dap_chain_balance_to_coins(l_token->header_public.total_supply); dap_string_append_printf(l_str_out, @@ -1441,8 +1441,7 @@ static char* dap_db_history_filter(dap_chain_t * a_chain, dap_ledger_t *a_ledger break; } - // if ( dap_chain_datum_token_emission_is_type_256(l_token_em->hdr.type) ) { // 256 - if ( l_token_em->hdr.version == 1 ) { // 256 + if ( l_token_em->hdr.version == 1 ) { // && l_token_em->hdr.type_256 ) { // 256 dap_string_append_printf(l_str_out, "emission 256: %s(%s) %s, type: %s, version: %d\n", dap_chain_balance_to_coins(dap_chain_uint128_from_uint256(l_token_em->hdr.value_256)), dap_chain_u256tostr(l_token_em->hdr.value_256), @@ -1474,8 +1473,7 @@ static char* dap_db_history_filter(dap_chain_t * a_chain, dap_ledger_t *a_ledger break; // case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_256_ATOM_OWNER: // 256 case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_ATOM_OWNER: - // if ( dap_chain_datum_token_emission_is_type_256(l_token_em->hdr.type) ) { // 256 - if ( l_token_em->hdr.version == 1 ) { // 256 + if ( l_token_em->hdr.version == 1 ) { // && l_token_em->hdr.type_256 ) { // 256 dap_string_append_printf(l_str_out, " value_start: %s(%s), codename: %s\n", dap_chain_balance_to_coins(dap_chain_uint128_from_uint256(l_token_em->data.type_atom_owner.value_start_256)), dap_chain_u256tostr(l_token_em->data.type_atom_owner.value_start_256),