diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index d5693b67..d7c5b538 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -749,7 +749,7 @@ namespace currency crypto::public_key owner = currency::null_pkey; // consider premultipling by 1/8 bool hidden_supply = false; - BEGIN_VERSIONED_SERIALIZE() + BEGIN_VERSIONED_SERIALIZE(0) FIELD(total_max_supply) FIELD(current_supply) FIELD(decimal_point) @@ -816,8 +816,7 @@ namespace currency boost::optional opt_proof; // operation proof - for update/emit boost::optional opt_asset_id; // target asset_id - for update/emit - BEGIN_VERSIONED_SERIALIZE() - CURRENT_VERSION(1) + BEGIN_VERSIONED_SERIALIZE(1) FIELD(operation_type) FIELD(descriptor) FIELD(opt_amount_commitment) @@ -842,7 +841,7 @@ namespace currency boost::optional opt_amount_commitment_composition_proof; // for hidden supply boost::optional opt_amount_commitment_g_proof; // for non-hidden supply, proofs that amount_commitment - supply * asset_id = lin(G) - BEGIN_VERSIONED_SERIALIZE() + BEGIN_VERSIONED_SERIALIZE(0) FIELD(opt_amount_commitment_composition_proof) FIELD(opt_amount_commitment_g_proof) END_SERIALIZE() diff --git a/src/currency_core/currency_format_utils_transactions.h b/src/currency_core/currency_format_utils_transactions.h index c5c9cfb0..ec5e0249 100644 --- a/src/currency_core/currency_format_utils_transactions.h +++ b/src/currency_core/currency_format_utils_transactions.h @@ -299,8 +299,7 @@ namespace currency // solely for consolidated txs, asset opration fields are not serialized BEGIN_SERIALIZE_OBJECT() - VERSION() - CURRENT_VERSION(0) + VERSION(0) FIELD(asset_ids) FIELD(blinded_asset_ids) FIELD(amount_commitments) diff --git a/src/serialization/serialization.h b/src/serialization/serialization.h index 407f4576..df2ab1f7 100644 --- a/src/serialization/serialization.h +++ b/src/serialization/serialization.h @@ -98,28 +98,31 @@ do { \ if (!_ser_ar.stream().good()) return false; \ } while (0); -#define VERSION() \ +#define VERSION(ver) \ do { \ _ser_ar.tag("VERSION"); \ if (!_ser_ar.stream().good()){break;} \ + s_version = s_current_version = ver; \ _ser_ar.serialize_varint(s_version); \ if (!_ser_ar.stream().good()) return false; \ if(s_version > s_current_version) return false; \ } while (0); +/* #define CURRENT_VERSION(v) \ do { \ s_current_version = v; \ if (_ser_ar.is_saving_arch()) { s_version = v; } \ } while (0); +*/ #define END_VERSION_UNDER(x) \ if(s_version < x ) {return true;} -#define BEGIN_VERSIONED_SERIALIZE() \ +#define BEGIN_VERSIONED_SERIALIZE(ver) \ BEGIN_SERIALIZE() \ - VERSION() + VERSION(ver) #define DEFINE_SERIALIZATION_VERSION(v) inline static uint32_t get_serialization_version() { return v; } diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index cad805c9..75e05230 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3335,6 +3335,20 @@ uint64_t wallet2::balance(uint64_t& unlocked, uint64_t& awaiting_in, uint64_t& a return total; } //---------------------------------------------------------------------------------------------------- +uint64_t wallet2::balance(crypto::public_key asset_id, uint64_t& unlocked) const +{ + std::unordered_map balances; + uint64_t dummy; + balance(balances, dummy); + auto it = balances.find(asset_id); + if (it == balances.end()) + { + return 0; + } + unlocked = it->second.unlocked; + return it->second.total; +} +//---------------------------------------------------------------------------------------------------- bool wallet2::balance(std::unordered_map& balances, uint64_t& mined) const { mined = 0; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 08c01e06..dfcc2f85 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -703,6 +703,7 @@ namespace tools uint64_t balance(uint64_t& unloked, uint64_t& awaiting_in, uint64_t& awaiting_out, uint64_t& mined, const crypto::public_key& asset_id = currency::native_coin_asset_id) const; bool balance(std::unordered_map& balances, uint64_t& mined) const; bool balance(std::list& balances, uint64_t& mined) const; + uint64_t balance(crypto::public_key asset_id, uint64_t& unloked) const; uint64_t balance(uint64_t& unloked) const; diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 5ca0502e..c5ec61cd 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -1347,8 +1347,7 @@ namespace wallet_public crypto::secret_key one_time_skey; BEGIN_SERIALIZE_OBJECT() - VERSION() - CURRENT_VERSION(0) + VERSION(0) FIELD(gen_context) FIELD(one_time_skey) END_SERIALIZE() @@ -1361,8 +1360,7 @@ namespace wallet_public BEGIN_SERIALIZE_OBJECT() - VERSION() - CURRENT_VERSION(0) + VERSION(0) FIELD(tx_template) FIELD(encrypted_context) END_SERIALIZE() diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 3747ce39..e269dbd5 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -115,23 +115,27 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); alice_wlt->refresh(); - balances.clear(); - alice_wlt->balance(balances, mined); + uint64_t last_alice_balances = alice_wlt->balance(asset_id, mined); + CHECK_AND_ASSERT_MES(last_alice_balances == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC + AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC/2, false, "Failed to find needed asset in result balances"); - it_asset = balances.find(asset_id); + - CHECK_AND_ASSERT_MES(it_asset != balances.end(), false, "Failed to find needed asset in result balances"); - CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC + AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC/2, false, "Failed to find needed asset in result balances"); + miner_wlt->refresh(); + uint64_t last_miner_balance = miner_wlt->balance(asset_id, mined); - try { - miner_wlt->transfer(AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC / 2, alice_wlt->get_account().get_public_address(), asset_id); - //pass over hardfork - CHECK_AND_ASSERT_MES(false, false, "Transfer with 0 Zano worked(fail)"); - } - catch (...) { - return true; + try { + + miner_wlt->transfer(AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC / 2, alice_wlt->get_account().get_public_address(), asset_id); + //pass over hardfork + CHECK_AND_ASSERT_MES(false, false, "Transfer with 0 Zano worked(fail)"); + } + catch (...) + { + LOG_PRINT_L0("Transfer failed as planned"); + //return true; + } } asset_descriptor_base asset_info = AUTO_VAL_INIT(asset_info); @@ -141,10 +145,39 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v adb.ticker = "TCT"; adb.decimal_point = 12 */ - bool r = c.get_blockchain_storage().get_asset_info(asset_id); + r = c.get_blockchain_storage().get_asset_info(asset_id, asset_info); CHECK_AND_ASSERT_MES(r, false, "Failed to get_asset_info"); - CHECK_AND_ASSERT_MES(asset_info.current_supply = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC*2, false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(asset_info.current_supply == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC*2, false, "Failed to find needed asset in result balances"); + + //test update function + asset_info.meta_info = "{\"some\": \"info\"}"; + miner_wlt->update_asset(asset_id, asset_info, tx); + r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, 2); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); + + asset_descriptor_base asset_info2 = AUTO_VAL_INIT(asset_info2); + r = c.get_blockchain_storage().get_asset_info(asset_id, asset_info2); + CHECK_AND_ASSERT_MES(r, false, "Failed to get_asset_info"); + + CHECK_AND_ASSERT_MES(asset_info2.meta_info == asset_info.meta_info, false, "Failed to find needed asset in result balances"); + + //test emmit function + //use same destinations as we used before + miner_wlt->emmit_asset(asset_id, destinations, tx); + r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); + + miner_wlt->refresh(); + alice_wlt->refresh(); + CHECK_AND_ASSERT_MES(miner_wlt->balance(asset_id, mined) == last_miner_balance + destinations[0].amount, false, "Miner balance wrong"); + CHECK_AND_ASSERT_MES(alice_wlt->balance(asset_id, mined) == last_alice_balances + destinations[1].amount, false, "Alice balance wrong"); + + asset_descriptor_base asset_info3 = AUTO_VAL_INIT(asset_info3); + r = c.get_blockchain_storage().get_asset_info(asset_id, asset_info3); + CHECK_AND_ASSERT_MES(r, false, "Failed to get_asset_info"); + CHECK_AND_ASSERT_MES(asset_info3.current_supply == asset_info2.current_supply + destinations[1].amount + destinations[0].amount, false, "Failed to find needed asset in result balances"); + return true; } diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp index 43df9c0e..47e0d4c4 100644 --- a/tests/unit_tests/serialization.cpp +++ b/tests/unit_tests/serialization.cpp @@ -760,11 +760,10 @@ struct A_v1 : public A BEGIN_SERIALIZE() - CURRENT_VERSION(1) FIELD(one) FIELD(two) FIELD(vector_one) - VERSION() + VERSION(1) if (s_version < 1) return true; FIELD(vector_two) END_SERIALIZE() @@ -777,11 +776,11 @@ struct A_v2 : public A_v1 BEGIN_SERIALIZE() - CURRENT_VERSION(2) + //CURRENT_VERSION(2) FIELD(one) FIELD(two) FIELD(vector_one) - VERSION() + VERSION(2) if (s_version < 1) return true; FIELD(vector_two) if (s_version < 2) return true; @@ -795,11 +794,11 @@ struct A_v3 : public A_v2 std::vector vector_5; BEGIN_SERIALIZE() - CURRENT_VERSION(3) + //CURRENT_VERSION(3) FIELD(one) FIELD(two) FIELD(vector_one) - VERSION() + VERSION(3) if (s_version < 1) return true; FIELD(vector_two) if (s_version < 2) return true;