1
0
Fork 0
forked from lthn/blockchain

Implemented basic code for validatiing ionic_swap

This commit is contained in:
cryptozoidberg 2023-03-03 18:17:16 +01:00
parent ae6feef3e5
commit 0030f7fbf6
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
4 changed files with 58 additions and 2 deletions

View file

@ -2168,14 +2168,20 @@ QString create_ionic_swap_proposal(const QString& param)
LOG_API_TIMING();
PREPARE_ARG_FROM_JSON(view::create_ionic_swap_proposal_request, cispr);
PREPARE_RESPONSE(view::api_response_t<std::string>, ar);
ar.error_code = m_backend.create_ionic_swap_proposal(waid.wallet_id, cispr, ar.response_data);
ar.error_code = m_backend.create_ionic_swap_proposal(cispr.wallet_id, cispr, ar.response_data);
return MAKE_RESPONSE(ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
}
QString get_ionic_swap_proposal_info(const QString& param)
{
TRY_ENTRY();
LOG_API_TIMING();
PREPARE_ARG_FROM_JSON(view::api_request_t<std::string>, tx_raw_hex);
PREPARE_RESPONSE(view::api_response_t<std::string>, ar);
ar.error_code = m_backend.get_ionic_swap_proposal_info(tx_raw_hex.wallet_id, tx_raw_hex.req_data, ar.response_data);
return MAKE_RESPONSE(ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
}

View file

@ -4927,6 +4927,25 @@ bool wallet2::build_ionic_swap_template(const view::ionic_swap_proposal_info& pr
return true;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::get_ionic_swap_proposal_info(std::string&raw_tx_template, ionic_swap_proposal_info& proposal)
{
currency::transaction tx;
bool r = parse_and_validate_tx_from_blob(tx_blob, tx);
THROW_IF_TRUE_WALLET_EX(!r, error::tx_parse_error, tx_blob);
crypto::key_derivation derivation = AUTO_VAL_INIT(derivation);
std::vector<wallet_out_info> outs;
uint64_t tx_money_got_in_outs = 0;
r = lookup_acc_outs(m_account.get_keys(), tx, outs, tx_money_got_in_outs, derivation);
THROW_IF_FALSE_WALLET_INT_ERR_EX(r, "Failed to lookup_acc_outs for tx: " << get_transaction_hash(tx));
for (const auto& o : outs)
{
}
}
//----------------------------------------------------------------------------------------------------
bool wallet2::prepare_tx_sources_for_packing(uint64_t items_to_pack, size_t fake_outputs_count, std::vector<currency::tx_source_entry>& sources, std::vector<uint64_t>& selected_indicies, uint64_t& found_money)
{

View file

@ -865,6 +865,14 @@ std::string wallets_manager::create_ionic_swap_proposal(uint64_t wallet_id, cons
}
bool r = wo.w->get()->create_ionic_swap_proposal(proposal, dest_account);
if (!r)
{
return API_RETURN_CODE_FAIL;
}
else
{
return API_RETURN_CODE_OK;
}
}
catch (...)
{
@ -875,6 +883,28 @@ std::string wallets_manager::create_ionic_swap_proposal(uint64_t wallet_id, cons
return true;
}
std::string get_ionic_swap_proposal_info(uint64_t wallet_id, std::string&raw_tx_template_hex, ionic_swap_proposal_info& proposal)
{
GET_WALLET_OPT_BY_ID(wallet_id, wo);
try {
std::string raw_tx_template;
bool r = epee::string_tools::parse_hexstr_to_binbuff(raw_tx_template_hex, raw_tx_template);
if (!r)
{
return API_RETURN_CODE_BAD_ARG;
}
if (!wo.w->get()->get_ionic_swap_proposal_info(raw_tx_template, proposal))
{
return API_RETURN_CODE_FAIL;
}
}
catch (...)
{
return API_RETURN_CODE_FAIL;
}
return API_RETURN_CODE_OK;
}
std::string wallets_manager::get_my_offers(const bc_services::core_offers_filter& filter, std::list<bc_services::offer_details_ex>& offers)
{

View file

@ -137,6 +137,7 @@ public:
std::string reset_wallet_password(uint64_t wallet_id, const std::string& pass);
std::string is_wallet_password_valid(uint64_t wallet_id, const std::string& pass);
std::string create_ionic_swap_proposal(uint64_t wallet_id, const view::create_ionic_swap_proposal_request& proposal, std::string& result_proposal_hex);
std::string get_ionic_swap_proposal_info(uint64_t wallet_id, std::string&raw_tx_template, ionic_swap_proposal_info& proposal);
std::string get_my_offers(const bc_services::core_offers_filter& filter, std::list<bc_services::offer_details_ex>& offers);
std::string get_fav_offers(const std::list<bc_services::offer_id>& hashes, const bc_services::core_offers_filter& filter, std::list<bc_services::offer_details_ex>& offers);
std::string get_tx_pool_info(currency::COMMAND_RPC_GET_POOL_INFO::response& res);