From 44e22b611d4969fde10a70d6514ec74574e708b1 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 18 Apr 2023 16:55:00 +0200 Subject: [PATCH] Multiple fixes here and there, mostly fixing compilation problems --- src/currency_core/currency_basic.h | 4 +-- src/currency_core/currency_format_utils.cpp | 2 +- src/simplewallet/simplewallet.cpp | 2 +- src/wallet/wallet2.cpp | 4 +-- src/wallet/wallet_public_structs_defs.h | 9 +++-- src/wallet/wallet_rpc_server.cpp | 6 ++-- src/wallet/wallets_manager.cpp | 8 ++--- tests/core_tests/hard_fork_2.cpp | 6 ++-- tests/core_tests/ionic_swap_tests.cpp | 36 +++++++++---------- .../isolate_auditable_and_proof.cpp | 2 +- tests/core_tests/multiassets_test.cpp | 6 ++-- tests/core_tests/multisig_wallet_tests.cpp | 5 +-- tests/core_tests/wallet_rpc_tests.cpp | 6 ++-- 13 files changed, 51 insertions(+), 45 deletions(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index e64155c0..b86d5e70 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -56,8 +56,8 @@ namespace currency const static crypto::key_derivation null_derivation = AUTO_VAL_INIT(null_derivation); const static crypto::hash gdefault_genesis = epee::string_tools::hex_to_pod("CC608F59F8080E2FBFE3C8C80EB6E6A953D47CF2D6AEBD345BADA3A1CAB99852"); - const static crypto::hash ffff_hash = epee::string_tools::hex_to_pod("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - const static crypto::public_key ffff_pkey = epee::string_tools::hex_to_pod("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // TODO @#@# consider getting rid of this + //const static crypto::hash ffff_hash = epee::string_tools::hex_to_pod("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + //const static crypto::public_key ffff_pkey = epee::string_tools::hex_to_pod("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // TODO @#@# consider getting rid of this // TODO: rewtire the following to a normal aggregate initialization once we move to C++17 -- sowle const static crypto::public_key native_coin_asset_id = reinterpret_cast(static_cast(crypto::ec_scalar{'\xd6', '\x32', '\x9b', '\x5b', '\x1f', '\x7c', '\x08', '\x05', '\xb5', '\xc3', '\x45', '\xf4', '\x95', '\x75', '\x54', '\x00', '\x2a', '\x2f', '\x55', '\x78', '\x45', '\xf6', '\x4d', '\x76', '\x45', '\xda', '\xe0', '\xe0', '\x51', '\xa6', '\x49', '\x8a'})); // == crypto::c_point_H, checked in crypto_constants diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 98dcf722..cfe34b18 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -2241,7 +2241,7 @@ namespace currency uint64_t amount_of_emitted_asset = 0; for (auto& item : shuffled_dsts) { - if (item.asset_id == currency::ffff_pkey) + if (item.asset_id == currency::null_pkey) { item.asset_id = gen_context.ao_asset_id; // set calculated asset_id to the asset's outputs, if this asset is being emitted within this tx amount_of_emitted_asset += item.amount; diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index de38d89a..d23a3ea1 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1819,7 +1819,7 @@ bool simple_wallet::deploy_new_asset(const std::vector &args) tx_destination_entry td = AUTO_VAL_INIT(td); td.addr.push_back(m_wallet->get_account().get_public_address()); td.amount = adb.current_supply; - td.asset_id = currency::ffff_pkey; + td.asset_id = currency::null_pkey; std::vector destinations; destinations.push_back(td); currency::transaction result_tx = AUTO_VAL_INIT(result_tx); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 58db3195..ac4838f6 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5535,7 +5535,7 @@ assets_selection_context wallet2::get_needed_money(uint64_t fee, const std::vect amounts_map[currency::native_coin_asset_id].needed_amount = fee; for(auto& dt : dsts) { - if(dt.asset_id == currency::ffff_pkey) + if(dt.asset_id == currency::null_pkey) continue; //this destination for emmition only THROW_IF_TRUE_WALLET_EX(0 == dt.amount, error::zero_destination); @@ -6181,7 +6181,7 @@ void wallet2::prepare_tx_destinations(const assets_selection_context& needed_mon { // special case for asset minting destinations for (auto& dst : dsts) - if (dst.asset_id == currency::ffff_pkey) + if (dst.asset_id == currency::null_pkey) final_destinations.emplace_back(dst.amount, dst.addr, dst.asset_id); // if there's not ehough destinations items (i.e. outputs), split the last one diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 06dd7832..bdba4ff4 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -1192,6 +1192,7 @@ namespace wallet_public END_KV_SERIALIZE_MAP() }; + struct ionic_swap_proposal_info { std::vector from; @@ -1242,12 +1243,12 @@ namespace wallet_public struct create_ionic_swap_proposal_request { uint64_t wallet_id; - ionic_swap_proposal_info proposal; + ionic_swap_proposal_info proposal_info; std::string destination_add; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(wallet_id) - KV_SERIALIZE(proposal) + KV_SERIALIZE(proposal_info) KV_SERIALIZE(destination_add) END_KV_SERIALIZE_MAP() }; @@ -1515,6 +1516,10 @@ namespace wallet_public } } + bool operator==(const asset_funds& lhs, const asset_funds& rhs) + { + return lhs.amount == rhs.amount && lhs.asset_id == rhs.asset_id; + } } // namespace wallet_rpc } // namespace tools diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index b151972e..e9b156cd 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -948,15 +948,15 @@ namespace tools return false; } - currency::transaction tx_template = AUTO_VAL_INIT(tx_template); - bool r = get_wallet()->create_ionic_swap_proposal(req.proposal, destination_addr, tx_template); + wallet_public::ionic_swap_proposal proposal = AUTO_VAL_INIT(proposal); + bool r = get_wallet()->create_ionic_swap_proposal(req.proposal, destination_addr, proposal); if (!r) { er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT; er.message = "WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT - Error creating proposal"; return false; } - res.hex_raw_proposal = epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(tx_template)); + res.hex_raw_proposal = epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(proposal)); return true; } //------------------------------------------------------------------------------------------------------------------------------ diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 72e2e663..d8159122 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -876,17 +876,17 @@ std::string wallets_manager::get_fav_offers(const std::listget()->create_ionic_swap_proposal(proposal.proposal, dest_account, proposal); + tools::wallet_public::ionic_swap_proposal proposal = AUTO_VAL_INIT(proposal); + bool r = wo.w->get()->create_ionic_swap_proposal(proposal_req.proposal_info, dest_account, proposal); if (!r) { return API_RETURN_CODE_FAIL; diff --git a/tests/core_tests/hard_fork_2.cpp b/tests/core_tests/hard_fork_2.cpp index fc6a96cd..72b21bea 100644 --- a/tests/core_tests/hard_fork_2.cpp +++ b/tests/core_tests/hard_fork_2.cpp @@ -81,7 +81,7 @@ bool hard_fork_2_tx_payer_in_wallet::c1(currency::core& c, size_t ev_index, cons CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Bob", bob_wlt, MK_TEST_COINS(12)), false, ""); // wallet RPC server - tools::wallet_rpc_server miner_wlt_rpc(*miner_wlt); + tools::wallet_rpc_server miner_wlt_rpc(miner_wlt); epee::json_rpc::error je; tools::wallet_rpc_server::connection_context ctx; @@ -161,7 +161,7 @@ bool hard_fork_2_tx_payer_in_wallet::c1(currency::core& c, size_t ev_index, cons bob_wlt->callback(std::make_shared()); // clear callback // Before HF2: Bob (auditable address) -> Alice with payer info requested (should NOT put tx_payer or tx_payer_old) - tools::wallet_rpc_server bob_wlt_rpc(*bob_wlt); + tools::wallet_rpc_server bob_wlt_rpc(bob_wlt); tools::wallet_public::COMMAND_RPC_TRANSFER::request req_c = AUTO_VAL_INIT(req_c); req_c.destinations.push_back(tools::wallet_public::transfer_destination{ MK_TEST_COINS(1), m_accounts[ALICE_ACC_IDX].get_public_address_str() }); req_c.fee = TESTS_DEFAULT_FEE; @@ -328,7 +328,7 @@ bool hard_fork_2_tx_receiver_in_wallet::c1(currency::core& c, size_t ev_index, c CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Bob", bob_wlt, 0), false, ""); // wallet RPC server - tools::wallet_rpc_server alice_wlt_rpc(*alice_wlt); + tools::wallet_rpc_server alice_wlt_rpc(alice_wlt); epee::json_rpc::error je; tools::wallet_rpc_server::connection_context ctx; diff --git a/tests/core_tests/ionic_swap_tests.cpp b/tests/core_tests/ionic_swap_tests.cpp index c0206de7..17361503 100644 --- a/tests/core_tests/ionic_swap_tests.cpp +++ b/tests/core_tests/ionic_swap_tests.cpp @@ -31,9 +31,9 @@ bool ionic_swap_basic_test::generate(std::vector& events) cons { uint64_t ts = test_core_time::get_time(); m_accounts.resize(TOTAL_ACCS_COUNT); - account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts); - account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts); - account_base& bob_acc = m_accounts[BOB_ACC_IDX]; bob_acc.generate(); bob_acc.set_createtime(ts); + currency::account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts); + currency::account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts); + currency::account_base& bob_acc = m_accounts[BOB_ACC_IDX]; bob_acc.generate(); bob_acc.set_createtime(ts); //account_base& carol_acc = m_accounts[CAROL_ACC_IDX]; carol_acc.generate(); carol_acc.set_createtime(ts); MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, ts); @@ -45,7 +45,7 @@ bool ionic_swap_basic_test::generate(std::vector& events) cons return true; } -bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vector& events) +bool ionic_swap_basic_test::c1(currency::core& c, size_t ev_index, const std::vector& events) { bool r = false; std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, MINER_ACC_IDX); @@ -58,13 +58,13 @@ bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vect CHECK_AND_ASSERT_MES(!c.get_blockchain_storage().is_hardfork_active(ZANO_HARDFORK_04_ZARCANUM), false, "ZANO_HARDFORK_04_ZARCANUM is active"); - account_base alice_acc; + currency::account_base alice_acc; alice_acc.generate(); std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, alice_acc); alice_wlt->get_account().set_createtime(0); miner_wlt->refresh(); - asset_descriptor_base adb = AUTO_VAL_INIT(adb); + currency::asset_descriptor_base adb = AUTO_VAL_INIT(adb); adb.total_max_supply = 1000000000000000000; //1M coins adb.full_name = "Test coins"; adb.ticker = "TCT"; @@ -73,17 +73,17 @@ bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vect std::vector destinations(2); destinations[0].addr.push_back(miner_wlt->get_account().get_public_address()); destinations[0].amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC; - destinations[0].asset_id = currency::ffff_hash; + destinations[0].asset_id = currency::null_pkey; destinations[1].addr.push_back(alice_wlt->get_account().get_public_address()); destinations[1].amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC; - destinations[1].asset_id = currency::ffff_hash; + destinations[1].asset_id = currency::null_pkey; LOG_PRINT_MAGENTA("destinations[0].asset_id:" << destinations[0].asset_id, LOG_LEVEL_0); LOG_PRINT_MAGENTA("destinations[1].asset_id:" << destinations[1].asset_id, LOG_LEVEL_0); - LOG_PRINT_MAGENTA("currency::ffff_hash:" << currency::ffff_hash, LOG_LEVEL_0); + LOG_PRINT_MAGENTA("currency::null_pkey:" << currency::null_pkey, LOG_LEVEL_0); currency::transaction tx = AUTO_VAL_INIT(tx); - crypto::hash asset_id = currency::null_hash; + crypto::public_key asset_id = currency::null_pkey; miner_wlt->publish_new_asset(adb, destinations, tx, asset_id); LOG_PRINT_L0("Published new asset: " << asset_id << ", tx_id: " << currency::get_transaction_hash(tx)); @@ -94,11 +94,11 @@ bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vect miner_wlt->refresh(); alice_wlt->refresh(); uint64_t mined = 0; - std::unordered_map balances; + std::unordered_map balances; miner_wlt->balance(balances, mined); auto it_asset = balances.find(asset_id); - auto it_native = balances.find(currency::null_hash); + auto it_native = balances.find(currency::native_coin_asset_id); CHECK_AND_ASSERT_MES(it_asset != balances.end() && it_native != balances.end(), false, "Failed to find needed asset in result balances"); @@ -111,7 +111,7 @@ bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vect alice_wlt->balance(balances, mined); it_asset = balances.find(asset_id); - it_native = balances.find(currency::null_hash); + it_native = balances.find(currency::native_coin_asset_id); CHECK_AND_ASSERT_MES(it_asset != balances.end(), false, "Failed to find needed asset in result balances"); CHECK_AND_ASSERT_MES(it_native == balances.end(), false, "Failed to find needed asset in result balances"); @@ -128,11 +128,11 @@ bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vect proposal_details.from.push_back(view::asset_funds{ asset_id , assets_to_exchange }); proposal_details.to.push_back(view::asset_funds{ currency::null_pkey , native_tokens_to_exchange }); - currency::transaction tx_template = AUTO_VAL_INIT(tx_template); - alice_wlt->create_ionic_swap_proposal(proposal_details, miner_wlt->get_account().get_public_address(), tx_template); + tools::wallet_public::ionic_swap_proposal proposal = AUTO_VAL_INIT(proposal); + alice_wlt->create_ionic_swap_proposal(proposal_details, miner_wlt->get_account().get_public_address(), proposal); view::ionic_swap_proposal_info proposal_decoded_info; - miner_wlt->get_ionic_swap_proposal_info(tx_template, proposal_decoded_info); + miner_wlt->get_ionic_swap_proposal_info(proposal, proposal_decoded_info); //Validate proposal if (proposal_decoded_info.from != proposal_details.from || proposal_decoded_info.to != proposal_details.to) @@ -141,7 +141,7 @@ bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vect } currency::transaction res_tx = AUTO_VAL_INIT(res_tx); - r = miner_wlt->accept_ionic_swap_proposal(tx_template, res_tx); + r = miner_wlt->accept_ionic_swap_proposal(proposal, res_tx); CHECK_AND_ASSERT_MES(r, false, "Failed to accept ionic proposal"); r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); @@ -155,7 +155,7 @@ bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vect alice_wlt->balance(balances, mined); it_asset = balances.find(asset_id); - it_native = balances.find(currency::null_hash); + it_native = balances.find(currency::native_coin_asset_id); CHECK_AND_ASSERT_MES(it_asset != balances.end(), false, "Failed to find needed asset in result balances"); CHECK_AND_ASSERT_MES(it_native->second.total == native_tokens_to_exchange, false, "Failed to find needed asset in result balances"); diff --git a/tests/core_tests/isolate_auditable_and_proof.cpp b/tests/core_tests/isolate_auditable_and_proof.cpp index 2bf086f5..d079a022 100644 --- a/tests/core_tests/isolate_auditable_and_proof.cpp +++ b/tests/core_tests/isolate_auditable_and_proof.cpp @@ -111,7 +111,7 @@ bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const s epee::json_rpc::error je; tools::wallet_rpc_server::connection_context ctx; - tools::wallet_rpc_server miner_wlt_rpc(*auditable_test_instance); + tools::wallet_rpc_server miner_wlt_rpc(auditable_test_instance); tools::wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request req = AUTO_VAL_INIT(req); tools::wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::response res = AUTO_VAL_INIT(res); req.count = 100; diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 06beb95a..64b861d0 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -70,14 +70,14 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v std::vector destinations(2); destinations[0].addr.push_back(miner_wlt->get_account().get_public_address()); destinations[0].amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC; - destinations[0].asset_id = currency::ffff_pkey; + destinations[0].asset_id = currency::null_pkey; destinations[1].addr.push_back(alice_wlt->get_account().get_public_address()); destinations[1].amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC; - destinations[1].asset_id = currency::ffff_pkey; + destinations[1].asset_id = currency::null_pkey; LOG_PRINT_MAGENTA("destinations[0].asset_id:" << destinations[0].asset_id, LOG_LEVEL_0); LOG_PRINT_MAGENTA("destinations[1].asset_id:" << destinations[1].asset_id, LOG_LEVEL_0); - LOG_PRINT_MAGENTA("currency::ffff_pkey: " << currency::ffff_pkey, LOG_LEVEL_0); + LOG_PRINT_MAGENTA("currency::null_pkey: " << currency::null_pkey, LOG_LEVEL_0); currency::transaction tx = AUTO_VAL_INIT(tx); crypto::public_key asset_id = currency::null_pkey; diff --git a/tests/core_tests/multisig_wallet_tests.cpp b/tests/core_tests/multisig_wallet_tests.cpp index ec2abfaa..acf4d959 100644 --- a/tests/core_tests/multisig_wallet_tests.cpp +++ b/tests/core_tests/multisig_wallet_tests.cpp @@ -66,8 +66,9 @@ void transfer_multisig(tools::wallet2& w, ftp.tx_version = tx_version; - - w.prepare_transaction(ctp, ftp, tx); + tools::mode_separate_context emode_separate = AUTO_VAL_INIT(emode_separate); + emode_separate.tx_for_mode_separate = tx; + w.prepare_transaction(ctp, ftp, emode_separate); crypto::secret_key sk = AUTO_VAL_INIT(sk); w.finalize_transaction(ftp, tx, sk, false); diff --git a/tests/core_tests/wallet_rpc_tests.cpp b/tests/core_tests/wallet_rpc_tests.cpp index ec867687..4db60da5 100644 --- a/tests/core_tests/wallet_rpc_tests.cpp +++ b/tests/core_tests/wallet_rpc_tests.cpp @@ -28,7 +28,7 @@ bool wallet_rpc_integrated_address::generate(std::vector& even CREATE_TEST_WALLET(miner_wlt, miner_acc, blk_0); // wallet RPC server - tools::wallet_rpc_server miner_wlt_rpc(*miner_wlt); + tools::wallet_rpc_server miner_wlt_rpc(miner_wlt); epee::json_rpc::error je; tools::wallet_rpc_server::connection_context ctx; @@ -110,7 +110,7 @@ bool wallet_rpc_integrated_address_transfer::c1(currency::core& c, size_t ev_ind std::string alice_integrated_address = get_account_address_and_payment_id_as_str(m_accounts[ALICE_ACC_IDX].get_public_address(), payment_id); // wallet RPC server - tools::wallet_rpc_server miner_wlt_rpc(*miner_wlt); + tools::wallet_rpc_server miner_wlt_rpc(miner_wlt); epee::json_rpc::error je; tools::wallet_rpc_server::connection_context ctx; @@ -226,7 +226,7 @@ bool wallet_rpc_transfer::c1(currency::core& c, size_t ev_index, const std::vect miner_wlt->refresh(); // wallet RPC server - tools::wallet_rpc_server miner_wlt_rpc(*miner_wlt); + tools::wallet_rpc_server miner_wlt_rpc(miner_wlt); epee::json_rpc::error je; tools::wallet_rpc_server::connection_context ctx;