1
0
Fork 0
forked from lthn/blockchain

added api for adding/removing assets via UI

This commit is contained in:
cryptozoidberg 2022-12-02 22:29:23 +01:00
parent 3a46bf3a44
commit 464818fb7f
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
8 changed files with 80 additions and 18 deletions

View file

@ -2127,6 +2127,27 @@ QString MainWindow::get_mining_estimate(const QString& param)
return MAKE_RESPONSE(ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
}
QString MainWindow::add_custom_asset_id(const QString& param)
{
TRY_ENTRY();
LOG_API_TIMING();
PREPARE_ARG_FROM_JSON(view::wallet_and_asset_id, waid);
PREPARE_RESPONSE(currency::COMMAND_RPC_GET_ASSET_INFO::response, ar);
ar.error_code = m_backend.add_custom_asset_id(waid.wallet_id, waid.asset_id, ar.response_data.asset_descriptor);
ar.response_data.status = ar.error_code;
return MAKE_RESPONSE(ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
}
QString MainWindow::remove_custom_asset_id(const QString& param)
{
TRY_ENTRY();
LOG_API_TIMING();
PREPARE_ARG_FROM_JSON(view::wallet_and_asset_id, waid);
default_ar.error_code = m_backend.delete_custom_asset_id(waid.wallet_id, waid.asset_id);
return MAKE_RESPONSE(default_ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
}
QString MainWindow::backup_wallet_keys(const QString& param)
{
TRY_ENTRY();

View file

@ -168,7 +168,10 @@ public:
QString get_default_fee();
QString get_options();
void bool_toggle_icon(const QString& param);
QString add_custom_asset_id(const QString& param);
QString remove_custom_asset_id(const QString& param);
bool get_is_disabled_notifications();
bool set_is_disabled_notifications(const bool& param);
QString export_wallet_history(const QString& param);

View file

@ -82,16 +82,19 @@ namespace currency
};
};
struct asset_id_kv
{
crypto::hash asset_id;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_POD_AS_HEX_STRING(asset_id)
END_KV_SERIALIZE_MAP()
};
struct COMMAND_RPC_GET_ASSET_INFO
{
struct request
{
crypto::hash asset_id;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_POD_AS_HEX_STRING(asset_id)
END_KV_SERIALIZE_MAP()
};
typedef asset_id_kv request;
struct response
{

View file

@ -766,7 +766,7 @@ bool simple_wallet::show_balance(const std::vector<std::string>& args/* = std::v
std::stringstream ss;
for (const tools::wallet_public::asset_balance_entry& b : balances)
{
ss << std::setw(21) << print_fixed_decimal_point(b.total, b.asset_info.decimal_point) << "\t" << b.asset_info.ticker << ENDL;
ss << std::setw(21) << print_fixed_decimal_point(b.total, b.asset_info.decimal_point) << "\t" << b.asset_info.ticker << "\t" << b.asset_info.asset_id << ENDL;
}
success_msg_writer() << "Balance: " << ENDL << ss.str();
return true;

View file

@ -426,10 +426,10 @@ public:
struct get_recent_transfers_request
{
uint64_t wallet_id;
uint64_t offset;
uint64_t count;
bool exclude_mining_txs;
uint64_t wallet_id = 0;
uint64_t offset = 0;
uint64_t count = 0;
bool exclude_mining_txs = false;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(wallet_id)
@ -439,9 +439,20 @@ public:
END_KV_SERIALIZE_MAP()
};
struct wallet_and_asset_id
{
uint64_t wallet_id = 0;
crypto::hash asset_id = currency::null_hash;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(wallet_id)
KV_SERIALIZE_POD_AS_HEX_STRING(asset_id)
END_KV_SERIALIZE_MAP()
};
struct reset_pass_request
{
uint64_t wallet_id;
uint64_t wallet_id = 0;
std::string pass;
BEGIN_KV_SERIALIZE_MAP()

View file

@ -3152,7 +3152,10 @@ bool wallet2::balance(std::list<wallet_public::asset_balance_entry>& balances, u
for (auto& own_asset : m_own_asset_descriptors)
{
custom_assets_local[own_asset.first] = own_asset.second.asset_descriptor;
if (m_whitelisted_assets.find(own_asset.first) == m_whitelisted_assets.end())
{
custom_assets_local[own_asset.first] = own_asset.second.asset_descriptor;
}
}
asset_descriptor_base native_asset_info = AUTO_VAL_INIT(native_asset_info);
@ -3218,6 +3221,7 @@ bool wallet2::add_custom_asset_id(const crypto::hash& asset_id, asset_descriptor
{
currency::COMMAND_RPC_GET_ASSET_INFO::request req = AUTO_VAL_INIT(req);
currency::COMMAND_RPC_GET_ASSET_INFO::response resp = AUTO_VAL_INIT(resp);
req.asset_id = asset_id;
bool r = m_core_proxy->call_COMMAND_RPC_GET_ASSET_INFO(req, resp);
if (resp.status == API_RETURN_CODE_OK)

View file

@ -1361,7 +1361,7 @@ std::string wallets_manager::request_alias_update(const currency::alias_rpc_deta
}
std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx)
std::string wallets_manager::transfer(uint64_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx)
{
std::vector<currency::tx_destination_entry> dsts;
@ -1675,6 +1675,23 @@ std::string wallets_manager::reset_wallet_password(uint64_t wallet_id, const std
else
return API_RETURN_CODE_FAIL;
}
std::string wallets_manager::add_custom_asset_id(uint64_t wallet_id, const crypto::hash& asset_id, currency::asset_descriptor_base& asset_descriptor)
{
GET_WALLET_OPT_BY_ID(wallet_id, w);
if(w.w->get()->add_custom_asset_id(asset_id, asset_descriptor))
return API_RETURN_CODE_OK;
else
return API_RETURN_CODE_FAIL;
}
std::string wallets_manager::delete_custom_asset_id(uint64_t wallet_id, const crypto::hash& asset_id)
{
GET_WALLET_OPT_BY_ID(wallet_id, w);
if (w.w->get()->delete_custom_asset_id(asset_id))
return API_RETURN_CODE_OK;
else
return API_RETURN_CODE_FAIL;
}
std::string wallets_manager::is_wallet_password_valid(uint64_t wallet_id, const std::string& pass)
{
GET_WALLET_OPT_BY_ID(wallet_id, w);

View file

@ -148,7 +148,7 @@ public:
std::vector<uint64_t>& days);
std::string is_pos_allowed();
void toggle_pos_mining();
std::string transfer(size_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx);
std::string transfer(uint64_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx);
std::string get_config_folder();
std::string is_valid_brain_restore_data(const std::string& seed_phrase, const std::string& seed_password);
std::string get_seed_phrase_info(const std::string& seed_phrase, const std::string& seed_password, view::seed_phrase_info& result);
@ -162,6 +162,9 @@ public:
std::string get_qt_dev_tools_option() const { return m_qt_dev_tools; }
void set_use_deffered_global_outputs(bool use) { m_use_deffered_global_outputs = use; }
bool set_use_tor(bool use_tor);
std::string add_custom_asset_id(uint64_t wallet_id, const crypto::hash& asset_id, currency::asset_descriptor_base& asset_descriptor);
std::string delete_custom_asset_id(uint64_t wallet_id, const crypto::hash& asset_id);
private:
void main_worker(const po::variables_map& vm);
bool init_local_daemon();