Skip to content

Commit

Permalink
Enhance variable usage for coin burn functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-tucci committed Nov 10, 2023
1 parent ad9a135 commit 91a035c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
15 changes: 8 additions & 7 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11622,12 +11622,13 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_burn(const std::ve
std::swap(burn_fixed, beldex_tx_params.burn_fixed);
std::swap(burn_percent, beldex_tx_params.burn_percent);
THROW_WALLET_EXCEPTION_IF(beldex_tx_params.hf_version < HF_VERSION_FEE_BURNING, error::wallet_internal_error, "cannot construct transaction: cannot burn amounts under the current hard fork");
std::vector<uint8_t> extra_plus; // Copy and modified from input if modification needed
extra_plus = extra_base;
add_burned_amount_to_tx_extra(extra_plus, 0);
fixed_fee += burn_fixed;
THROW_WALLET_EXCEPTION_IF(burn_percent > fee_percent, error::wallet_internal_error, "invalid burn fees: cannot burn more than the tx fee");

{
std::vector<uint8_t> extra_plus; // Copy and modified from input if modification needed
extra_plus = extra_base;
add_burned_amount_to_tx_extra(extra_plus, 0);
fixed_fee += burn_fixed;
THROW_WALLET_EXCEPTION_IF(burn_percent > fee_percent, error::wallet_internal_error, "invalid burn fees: cannot burn more than the tx fee");
}
LOG_PRINT_L2("Starting with " << unused_transfers_indices.size() << " non-dust outputs and " << unused_dust_indices.size() << " dust outputs");

if (unused_dust_indices.empty() && unused_transfers_indices.empty())
Expand Down Expand Up @@ -11715,7 +11716,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_burn(const std::ve
{
dt.amount = dt_amount;
}
beldex_tx_params = tools::wallet2::construct_params(*hf_version, tx_type, priority,amount_burned);
beldex_tx_params.burn_fixed = amount_burned;
transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, outs, unlock_time, needed_fee, extra_base,
test_tx, test_ptx, rct_config, beldex_tx_params);
txBlob = t_serializable_object_to_blob(test_ptx.tx);
Expand Down
18 changes: 7 additions & 11 deletions src/wallet/wallet_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,30 +1076,26 @@ namespace tools

std::vector<wallet2::pending_tx> ptx_vector;
std::vector<uint8_t> extra;
uint64_t burn_amount = req.amount;
std::cout << "burn_amount : " << burn_amount << std::endl;
std::string tx_id = req.tx_id;
std::cout << "req.txid : " << req.tx_id << std::endl;

if(burn_amount == 0 && tx_id.empty())

if(req.amount == 0 && req.tx_id.empty())
throw wallet_rpc_error{error_code::TX_NOT_POSSIBLE, "Amount/Txid is required"};
if(!burn_amount == 0 && !tx_id.empty())
if(req.amount != 0 && !req.tx_id.empty())
throw wallet_rpc_error{error_code::TX_NOT_POSSIBLE, "Only one field needed either Amount or Txid"};

LOG_PRINT_L3("on_burn_transfer starts");

if(!burn_amount == 0)
if(req.amount)
{
std::optional<uint8_t> hf_version = m_wallet->get_hard_fork_version();
if (!hf_version)
throw wallet_rpc_error{error_code::HF_QUERY_FAILED, tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED};
cryptonote::beldex_construct_tx_params tx_params = tools::wallet2::construct_params(*hf_version, cryptonote::txtype::coin_burn, req.priority, burn_amount);
cryptonote::beldex_construct_tx_params tx_params = tools::wallet2::construct_params(*hf_version, cryptonote::txtype::coin_burn, req.priority, req.amount);
ptx_vector = m_wallet->create_transactions_2({}, CRYPTONOTE_DEFAULT_TX_MIXIN, 0, req.priority, extra, req.account_index, req.subaddr_indices, tx_params);
}
else if (!tx_id.empty())
else
{
crypto::hash tx_hash;
if (!tools::hex_to_type(tx_id, tx_hash))
if (!tools::hex_to_type(req.tx_id, tx_hash))
throw wallet_rpc_error{error_code::WRONG_TXID, "failed to parse txid"};
size_t outputs = 1;
tools::wallet2::transfer_container transfers;
Expand Down

0 comments on commit 91a035c

Please sign in to comment.