1
0
Fork 0
forked from lthn/blockchain

Implemented basics for building ionic_swap template

This commit is contained in:
cryptozoidberg 2023-02-23 19:10:22 +01:00
parent 8f483db05e
commit 2328a2cced
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
6 changed files with 116 additions and 7 deletions

View file

@ -2162,7 +2162,26 @@ QString MainWindow::get_wallet_info(const QString& param)
return MAKE_RESPONSE(ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
}
QString create_ionic_swap_proposal(const QString& param)
{
TRY_ENTRY();
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);
return MAKE_RESPONSE(ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
}
QString get_ionic_swap_proposal_info(const QString& param)
{
}
QString accept_ionic_swap_proposal(const QString& param)
{
}
QString MainWindow::backup_wallet_keys(const QString& param)
{
TRY_ENTRY();

View file

@ -686,14 +686,11 @@ public:
};
struct wallet_and_contract_id_param
{
uint64_t wallet_id;
crypto::hash contract_id;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(wallet_id)
KV_SERIALIZE_POD_AS_HEX_STRING(contract_id)
@ -742,6 +739,50 @@ public:
END_KV_SERIALIZE_MAP()
};
struct asset_funds
{
crypto::hash token_id;
uint64_t amount;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(token_id)
KV_SERIALIZE(amount)
END_KV_SERIALIZE_MAP()
};
struct ionic_swap_proposal_info
{
std::vector<asset_funds> from;
std::vector<asset_funds> to;
uint64_t mixins;
uint64_t fee;
uint64_t expiration_time;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(from)
KV_SERIALIZE(to)
KV_SERIALIZE(mixins)
KV_SERIALIZE(fee)
KV_SERIALIZE(expiration_time)
END_KV_SERIALIZE_MAP()
};
struct create_ionic_swap_proposal_request
{
uint64_t wallet_id;
ionic_swap_proposal_info proposal;
std::string destination_add;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(wallet_id)
KV_SERIALIZE(proposal)
KV_SERIALIZE(destination_add)
END_KV_SERIALIZE_MAP()
};
struct address_validation_response
{
std::string error_code;

View file

@ -4877,6 +4877,46 @@ bool wallet2::check_htlc_redeemed(const crypto::hash& htlc_tx_id, std::string& o
}
return false;
}
bool wallet2::create_ionic_swap_proposal(uint64_t wallet_id, const view::ionic_swap_proposal_info& proposal_details, const currency::account_public_address& destination_addr)
{
crypto::secret_key one_time_key = AUTO_VAL_INIT(one_time_key);
std::vector<uint64_t> selected_transfers_for_template;
transaction tx_template;
build_ionic_swap_template(proposal_details, destination_addr, tx_template, selected_transfers_for_template, one_time_key);
const uint32_t mask_to_mark_escrow_template_locked_transfers = WALLET_TRANSFER_DETAIL_FLAG_BLOCKED | WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION;
mark_transfers_with_flag(selected_transfers_for_template, mask_to_mark_escrow_template_locked_transfers, "preparing escrow template tx, contract: " + epee::string_tools::pod_to_hex(ms_id));
}
//----------------------------------------------------------------------------------------------------
bool wallet2::build_ionic_swap_template(const view::ionic_swap_proposal_info& proposal_detais, const currency::account_public_address& destination_addr,
currency::transaction& template_tx,
std::vector<uint64_t>& selected_transfers_for_template,
crypto::secret_key& one_time_key)
{
construct_tx_param ctp = get_default_construct_tx_param();
ctp.fake_outputs_count = proposal_detais.mixins;
ctp.fee = 0;
ctp.flags = TX_FLAG_SIGNATURE_MODE_SEPARATE;
ctp.mark_tx_as_complete = false;
etc_tx_details_expiration_time t = AUTO_VAL_INIT(t);
t.v = proposal_detais.expiration_time;
ctp.extra.push_back(t);
//TODO:
currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp);
ftp.tx_version = this->get_current_tx_version();
prepare_transaction(ctp, ftp, tx);
selected_transfers = ftp.selected_transfers;
finalize_transaction(ftp, tx, one_time_key, false);
}
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
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

@ -916,7 +916,11 @@ namespace tools
bool check_htlc_redeemed(const crypto::hash& htlc_tx_id, std::string& origin, crypto::hash& redeem_tx_id);
// ionic swaps:
bool create_ionic_swap_proposal(uint64_t wallet_id, const view::ionic_swap_proposal_info& proposal);
bool create_ionic_swap_proposal(uint64_t wallet_id, const view::ionic_swap_proposal_info& proposal, const currency::account_public_address& destination_addr);
bool build_ionic_swap_template(const view::ionic_swap_proposal_info& proposal_detais, const currency::account_public_address& destination_addr,
currency::transaction& template_tx,
std::vector<uint64_t>& selected_transfers_for_template,
crypto::secret_key& one_time_key);
private:
// -------- t_transport_state_notifier ------------------------------------------------

View file

@ -854,12 +854,17 @@ std::string wallets_manager::get_fav_offers(const std::list<bc_services::offer_i
#endif
}
std::string wallets_manager::create_ionic_swap_proposal(uint64_t wallet_id, const view::ionic_swap_proposal_info& proposal)
std::string wallets_manager::create_ionic_swap_proposal(uint64_t wallet_id, const view::create_ionic_swap_proposal_request& proposal, std::string& result_proposal_hex)
{
GET_WALLET_OPT_BY_ID(wallet_id, wo);
try {
bool r = wo.w->get()->create_ionic_swap_proposal(proposal);
currency::account_public_address dest_account = AUTO_VAL_INIT(dest_account);
if (!currency::get_account_address_from_str(proposal.destination_add))
{
return API_RETURN_CODE_BAD_ARG;
}
bool r = wo.w->get()->create_ionic_swap_proposal(proposal, dest_account);
}
catch (...)
{

View file

@ -136,7 +136,7 @@ public:
std::string backup_wallet(uint64_t wallet_id, const std::wstring& path);
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::ionic_swap_proposal_info& proposal);
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_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);