Skip to content

Commit

Permalink
Merge pull request #394 from ShowYouShowme/getaddressasset_support_ut…
Browse files Browse the repository at this point in the history
…xo_comfirm

Getaddressasset support utxo comfirm
  • Loading branch information
codrush authored May 14, 2020
2 parents aa449f9 + 0c11634 commit cc8c14b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/metaverse/explorer/extensions/base_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ void sync_fetch_asset_balance(const std::string& address, bool sum_all,
std::shared_ptr<chain::asset_balances::list> sh_asset_vec);
void sync_fetch_asset_balance(const std::string& address, bool sum_all,
bc::blockchain::block_chain_impl& blockchain,
std::shared_ptr<utxo_balance::list> sh_asset_utxo_vec);
std::shared_ptr<utxo_balance::list> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ class getaddressasset: public command_extension
value<std::string>(&option_.symbol)->default_value(""),
"Asset symbol."
)
(
"utxominimumconfirmations,x",
value<uint64_t>(&option_.utxo_min_confirm)->default_value(3),
"Create transaction with the utxo minimum confirmations. defaults to 3"
)
;

return options;
Expand Down Expand Up @@ -122,6 +127,7 @@ class getaddressasset: public command_extension
bool utxo;
colon_delimited2_item<uint64_t, uint64_t> range = {0, 0};
std::string symbol;
uint64_t utxo_min_confirm;
} option_;

};
Expand Down
12 changes: 11 additions & 1 deletion src/lib/explorer/extensions/base_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<utxo_balance::list> sh_asset_utxo_vec)
std::shared_ptr<utxo_balance::list> sh_asset_utxo_vec,
uint64_t utxo_min_confirm)
{
auto&& rows = blockchain.get_address_history(wallet::payment_address(address));

Expand Down Expand Up @@ -558,16 +559,25 @@ 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
locked_amount = asset_amount;
}
}

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});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/explorer/extensions/commands/getaddressasset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ console_result getaddressasset::invoke(Json::Value& jv_output,
+ option_.range.encode_colon_delimited());
}
auto utxo_balances = std::make_shared<utxo_balance::list>();
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)
Expand Down

0 comments on commit cc8c14b

Please sign in to comment.