Use default null string to get first vout

This commit is contained in:
satyakoneru 2020-04-20 12:01:04 +00:00
parent 85055d7876
commit c204020ca5
3 changed files with 7 additions and 3 deletions

View file

@ -119,7 +119,8 @@ std::vector<prev_out> get_outputs_from_transaction_by_address(const std::string
to_addresses.push_back(address.second.data());
}
if (std::find(to_addresses.begin(), to_addresses.end(), to_address) != to_addresses.end()) {
if ((to_address == "") ||
(std::find(to_addresses.begin(), to_addresses.end(), to_address) != to_addresses.end())) {
std::string tx_amount_s = vout.second.get<std::string>("value");
tx_amount_s.erase(std::remove(tx_amount_s.begin(), tx_amount_s.end(), '.'), tx_amount_s.end());
uint64_t tx_amount = std::stoll(tx_amount_s);
@ -132,6 +133,9 @@ std::vector<prev_out> get_outputs_from_transaction_by_address(const std::string
pout.n_vout = tx_vout;
pout.amount = tx_amount;
result.push_back(pout);
if (to_address == "") {
return result;
}
}
}
return result;

View file

@ -23,6 +23,6 @@ void read_transaction_data(const std::string &string_buf, std::string &tx_hex, s
std::string write_transaction_data(const std::string &tx, const std::vector<uint64_t> &in_amounts, const std::string &redeem_script);
std::vector<prev_out> get_outputs_from_transaction_by_address(const std::string &tx_json, const std::string &to_address);
std::vector<prev_out> get_outputs_from_transaction_by_address(const std::string &tx_json, const std::string &to_address = "");
}}} // namespace graphene::peerplays_sidechain::bitcoin

View file

@ -1406,7 +1406,7 @@ int64_t sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidech
if (sto.object_id.is<son_wallet_deposit_id_type>()) {
std::string tx_hex = tx_json.get<std::string>("result.hex");
std::string tx_hex_json = bitcoin_client->decoderawtransaction(tx_hex);
std::vector<bitcoin::prev_out> pouts = bitcoin::get_outputs_from_transaction_by_address(tx_hex_json, get_current_primary_wallet_address());
std::vector<bitcoin::prev_out> pouts = bitcoin::get_outputs_from_transaction_by_address(tx_hex_json);
if (pouts.size() > 0) {
settle_amount = pouts[0].amount;
}