From be8e0f73278907a4deb6bb976f6f3e1841c66c37 Mon Sep 17 00:00:00 2001 From: Some Random Crypto Guy Date: Wed, 22 Nov 2023 06:25:25 +0000 Subject: [PATCH] Fixed the key definition for circ_supply to allow duplicate tx_ids Updated the CLI wallet to remove the "address" parameter from CONVERT. Reordered processing of CONVERT vs PROTOCOL TXs, so that the PROTOCOL TXs have the necessary data to decode the destination address. --- src/blockchain_db/lmdb/db_lmdb.cpp | 2 +- src/simplewallet/simplewallet.cpp | 120 +++++++++++++++-------------- src/wallet/wallet2.cpp | 10 ++- 3 files changed, 71 insertions(+), 61 deletions(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 583d04786..0f5bf4610 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -1794,7 +1794,7 @@ void BlockchainLMDB::open(const std::string& filename, const int db_flags) lmdb_db_open(txn, LMDB_PROPERTIES, MDB_CREATE, m_properties, "Failed to open db handle for m_properties"); - lmdb_db_open(txn, LMDB_CIRC_SUPPLY, MDB_INTEGERKEY | MDB_CREATE, m_circ_supply, "Failed to open db handle for m_circ_supply"); + lmdb_db_open(txn, LMDB_CIRC_SUPPLY, MDB_INTEGERKEY | MDB_DUPSORT | MDB_DUPFIXED | MDB_CREATE, m_circ_supply, "Failed to open db handle for m_circ_supply"); lmdb_db_open(txn, LMDB_CIRC_SUPPLY_TALLY, MDB_CREATE, m_circ_supply_tally, "Failed to open db handle for m_circ_supply_tally"); lmdb_db_open(txn, LMDB_YIELD_TXS, MDB_INTEGERKEY | MDB_DUPSORT | MDB_DUPFIXED | MDB_CREATE, m_yield_txs, "Failed to open db handle for m_yield_txs"); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 570c653d4..86a1a574f 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -208,7 +208,7 @@ namespace const char* USAGE_SWEEP_BELOW("sweep_below [index=[,,...]] [] []
[]"); const char* USAGE_SWEEP_SINGLE("sweep_single [] [] [outputs=]
[]"); const char* USAGE_BURN("burn "); - const char* USAGE_CONVERT("convert [index=[,,...]] [] [] ( |
) []"); + const char* USAGE_CONVERT("convert "); const char* USAGE_LOCK_FOR_YIELD("lock_for_yield "); const char* USAGE_PRICE_INFO("price_info"); const char* USAGE_SUPPLY_INFO("supply_info"); @@ -3153,7 +3153,7 @@ bool simple_wallet::help(const std::vector &args/* = std::vector []\" - Send FULM or F$ to an address."); message_writer() << tr("\"burn \" - destroy coins forever."); - message_writer() << tr("\"convert
\" - convert between coin types and send to address."); + message_writer() << tr("\"convert \" - convert between coin types."); message_writer() << tr("\"lock_for_tield \" - lock FULM in order to earn yield."); message_writer() << tr("\"price_info\" - Display current pricing information for supported assets."); message_writer() << tr("\"supply_info\" - Display circulating supply information."); @@ -3338,7 +3338,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("convert", boost::bind(&simple_wallet::convert, this, _1), tr(USAGE_CONVERT), - tr("Converts into , with optional [0-5]")); + tr("Converts into ")); m_cmd_binder.set_handler("lock_for_yield", boost::bind(&simple_wallet::lock_for_yield, this, _1), tr(USAGE_LOCK_FOR_YIELD), @@ -6593,37 +6593,41 @@ bool simple_wallet::transfer_main( std::vector local_args = args_; std::set subaddr_indices; - if (local_args.size() > 0 && local_args[0].substr(0, 6) == "index=") - { - if (!parse_subaddress_indices(local_args[0], subaddr_indices)) - return false; - local_args.erase(local_args.begin()); - } + if (transfer_type == TransferLocked) + if (local_args.size() > 0 && local_args[0].substr(0, 6) == "index=") + { + if (!parse_subaddress_indices(local_args[0], subaddr_indices)) + return false; + local_args.erase(local_args.begin()); + } uint32_t priority = 0; - if (local_args.size() > 0 && parse_priority(local_args[0], priority)) - local_args.erase(local_args.begin()); + if (transfer_type == TransferLocked) + if (local_args.size() > 0 && parse_priority(local_args[0], priority)) + local_args.erase(local_args.begin()); priority = m_wallet->adjust_priority(priority); const size_t min_ring_size = m_wallet->get_min_ring_size(); size_t fake_outs_count = min_ring_size - 1; - if(local_args.size() > 0) { - size_t ring_size; - if(!epee::string_tools::get_xtype_from_string(ring_size, local_args[0])) - { + if (transfer_type == TransferLocked) + if(local_args.size() > 0) { + size_t ring_size; + if(!epee::string_tools::get_xtype_from_string(ring_size, local_args[0])) + { + } + else if (ring_size == 0) + { + fail_msg_writer() << tr("Ring size must not be 0"); + return false; + } + else + { + fake_outs_count = ring_size - 1; + local_args.erase(local_args.begin()); + } } - else if (ring_size == 0) - { - fail_msg_writer() << tr("Ring size must not be 0"); - return false; - } - else - { - fake_outs_count = ring_size - 1; - local_args.erase(local_args.begin()); - } - } + uint64_t adjusted_fake_outs_count = m_wallet->adjust_mixin(fake_outs_count); if (adjusted_fake_outs_count > fake_outs_count) { @@ -6645,21 +6649,22 @@ bool simple_wallet::transfer_main( std::vector extra; bool payment_id_seen = false; - if (!local_args.empty()) - { - std::string payment_id_str = local_args.back(); - crypto::hash payment_id; - bool r = true; - if (tools::wallet2::parse_long_payment_id(payment_id_str, payment_id)) + if (transfer_type == TransferLocked) + if (!local_args.empty()) { - LONG_PAYMENT_ID_SUPPORT_CHECK(); + std::string payment_id_str = local_args.back(); + crypto::hash payment_id; + bool r = true; + if (tools::wallet2::parse_long_payment_id(payment_id_str, payment_id)) + { + LONG_PAYMENT_ID_SUPPORT_CHECK(); + } + if(!r) + { + fail_msg_writer() << tr("payment id failed to encode"); + return false; + } } - if(!r) - { - fail_msg_writer() << tr("payment id failed to encode"); - return false; - } - } uint64_t locked_blocks = 0; if (transfer_type == TransferLocked) @@ -6734,11 +6739,23 @@ bool simple_wallet::transfer_main( } else { - if (boost::starts_with(local_args[i], "fulmo:")) - fail_msg_writer() << tr("Invalid last argument: ") << local_args.back() << ": " << error; - else - fail_msg_writer() << tr("Invalid last argument: ") << local_args.back(); - return false; + if (transfer_type == Convert) { + bool ok = cryptonote::parse_amount(de.amount, local_args[i]); + if(!ok || 0 == de.amount) + { + fail_msg_writer() << tr("amount is wrong: ") << local_args[i] << + ", " << tr("expected number from 0 to ") << print_money(std::numeric_limits::max()); + return false; + } + de.asset_type = source_asset; + ++i; + } else { + if (boost::starts_with(local_args[i], "fulmo:")) + fail_msg_writer() << tr("Invalid last argument: ") << local_args.back() << ": " << error; + else + fail_msg_writer() << tr("Invalid last argument: ") << local_args.back(); + return false; + } } if (!r) @@ -7870,26 +7887,15 @@ bool simple_wallet::burn(const std::vector &args_) bool simple_wallet::convert(const std::vector &args_) { // TODO: add locked versions - if (args_.size() < 4) + if (args_.size() != 3) { - fail_msg_writer() << tr("missing argument(s)"); + fail_msg_writer() << tr("missing / extraneous argument(s)"); PRINT_USAGE(USAGE_CONVERT); return true; } std::vector local_args = args_; - // get payment id and pop - std::string payment_id_str; - crypto::hash payment_id; - crypto::hash8 payment_id8; - if (tools::wallet2::parse_long_payment_id (local_args.back(), payment_id ) or - tools::wallet2::parse_short_payment_id(local_args.back(), payment_id8)) - { - payment_id_str = local_args.back(); - local_args.pop_back(); - } - // Get the destination asset type std::string source_asset, dest_asset; std::string strLastArg = local_args.back(); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 8fc95bce9..7162eeb9b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2716,10 +2716,9 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cry ++tx_cache_data_offset; TIME_MEASURE_FINISH(miner_tx_handle_time); - TIME_MEASURE_START(protocol_tx_handle_time); - process_new_transaction(get_transaction_hash(b.protocol_tx), b.protocol_tx, parsed_block.o_indices.indices[1].indices, parsed_block.asset_type_output_indices.indices[1].indices, height, b.major_version, b.timestamp, true, false, false, tx_cache_data[tx_cache_data_offset], output_tracker_cache); + // Store the current cache offset for later use + size_t protocol_tx_cache_data_offset = tx_cache_data_offset; ++tx_cache_data_offset; - TIME_MEASURE_FINISH(protocol_tx_handle_time); TIME_MEASURE_START(txs_handle_time); THROW_WALLET_EXCEPTION_IF(bche.txs.size() != b.tx_hashes.size(), error::wallet_internal_error, "Wrong amount of transactions for block"); @@ -2729,6 +2728,11 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cry process_new_transaction(b.tx_hashes[idx], parsed_block.txes[idx], parsed_block.o_indices.indices[idx+2].indices, parsed_block.asset_type_output_indices.indices[idx+2].indices, height, b.major_version, b.timestamp, false, false, false, tx_cache_data[tx_cache_data_offset++], output_tracker_cache); } TIME_MEASURE_FINISH(txs_handle_time); + + TIME_MEASURE_START(protocol_tx_handle_time); + process_new_transaction(get_transaction_hash(b.protocol_tx), b.protocol_tx, parsed_block.o_indices.indices[1].indices, parsed_block.asset_type_output_indices.indices[1].indices, height, b.major_version, b.timestamp, true, false, false, tx_cache_data[tx_cache_data_offset], output_tracker_cache); + TIME_MEASURE_FINISH(protocol_tx_handle_time); + m_last_block_reward = cryptonote::get_outs_money_amount(b.miner_tx); LOG_PRINT_L2("Processed block: " << bl_id << ", height " << height << ", " << miner_tx_handle_time + txs_handle_time << "(" << miner_tx_handle_time << "/" << txs_handle_time <<")ms"); }else