diff --git a/include/metaverse/explorer/extensions/base_helper.hpp b/include/metaverse/explorer/extensions/base_helper.hpp index ecb2945d3..404722d0a 100644 --- a/include/metaverse/explorer/extensions/base_helper.hpp +++ b/include/metaverse/explorer/extensions/base_helper.hpp @@ -235,7 +235,8 @@ void sync_fetch_asset_balance(const std::string& address, bool sum_all, std::shared_ptr sh_asset_vec); void sync_fetch_asset_balance(const std::string& address, bool sum_all, bc::blockchain::block_chain_impl& blockchain, - std::shared_ptr sh_asset_utxo_vec); + std::shared_ptr sh_asset_utxo_vec, + uint64_t utxo_min_confirm); void sync_fetch_asset_deposited_balance(const std::string& address, bc::blockchain::block_chain_impl& blockchain, diff --git a/include/metaverse/explorer/extensions/commands/getaddressasset.hpp b/include/metaverse/explorer/extensions/commands/getaddressasset.hpp index df827abeb..241a47cc4 100644 --- a/include/metaverse/explorer/extensions/commands/getaddressasset.hpp +++ b/include/metaverse/explorer/extensions/commands/getaddressasset.hpp @@ -93,6 +93,11 @@ class getaddressasset: public command_extension value(&option_.symbol)->default_value(""), "Asset symbol." ) + ( + "utxominimumconfirmations,x", + value(&option_.utxo_min_confirm)->default_value(3), + "Create transaction with the utxo minimum confirmations. defaults to 3" + ) ; return options; @@ -122,6 +127,7 @@ class getaddressasset: public command_extension bool utxo; colon_delimited2_item range = {0, 0}; std::string symbol; + uint64_t utxo_min_confirm; } option_; }; diff --git a/src/lib/explorer/extensions/base_helper.cpp b/src/lib/explorer/extensions/base_helper.cpp index 5c3fc4895..adb9c309c 100644 --- a/src/lib/explorer/extensions/base_helper.cpp +++ b/src/lib/explorer/extensions/base_helper.cpp @@ -510,7 +510,8 @@ void sync_fetch_asset_balance(const std::string& address, bool sum_all, void sync_fetch_asset_balance(const std::string& address, bool sum_all, bc::blockchain::block_chain_impl& blockchain, - std::shared_ptr sh_asset_utxo_vec) + std::shared_ptr sh_asset_utxo_vec, + uint64_t utxo_min_confirm) { auto&& rows = blockchain.get_address_history(wallet::payment_address(address)); @@ -558,9 +559,15 @@ void sync_fetch_asset_balance(const std::string& address, bool sum_all, auto available_amount = attenuation_model::get_available_asset_amount( asset_amount, diff_height, attenuation_model_param); locked_amount = asset_amount - available_amount; + if (utxo_min_confirm > diff_height){ + continue; + } } else if (asset_amount && chain::operation::is_pay_key_hash_with_sequence_lock_pattern(output.script.operations)) { + if (utxo_min_confirm > blockchain.calc_number_of_blocks(tx_height, height)){ + continue; + } auto is_spendable = blockchain.is_utxo_spendable(tx_temp, row.output.index, tx_height, height); if (!is_spendable) { // utxo already in block but is locked with sequence and not mature @@ -568,6 +575,9 @@ void sync_fetch_asset_balance(const std::string& address, bool sum_all, } } + if (utxo_min_confirm > blockchain.calc_number_of_blocks(tx_height, height)){ + continue; + } sh_asset_utxo_vec->emplace_back(utxo_balance{ encode_hash(row.output.hash), row.output.index, row.output_height, asset_amount, locked_amount, symbol}); diff --git a/src/lib/explorer/extensions/commands/getaddressasset.cpp b/src/lib/explorer/extensions/commands/getaddressasset.cpp index 564956aaa..4f47a27a4 100644 --- a/src/lib/explorer/extensions/commands/getaddressasset.cpp +++ b/src/lib/explorer/extensions/commands/getaddressasset.cpp @@ -125,7 +125,7 @@ console_result getaddressasset::invoke(Json::Value& jv_output, + option_.range.encode_colon_delimited()); } auto utxo_balances = std::make_shared(); - sync_fetch_asset_balance(address, true, blockchain, utxo_balances); + sync_fetch_asset_balance(address, true, blockchain, utxo_balances, option_.utxo_min_confirm); for (const auto& balance : *utxo_balances) { if (option_.range.is_in_range(balance.unspent_balance)) { if (!option_.symbol.empty() && option_.symbol != balance.symbol)