Merge branch 'cake' into cryptoassets

This commit is contained in:
cryptozoidberg 2023-10-31 13:39:33 +01:00
commit b7a145e56f
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
7 changed files with 127 additions and 20 deletions

View file

@ -4,6 +4,7 @@
#pragma once
#include "../currency_core/basic_api_response_codes.h"
#define API_RETURN_CODE_OK BASIC_RESPONSE_STATUS_OK
#define API_RETURN_CODE_FAIL BASIC_RESPONSE_STATUS_FAILED

View file

@ -18,7 +18,6 @@
#include "static_helpers.h"
#include "wallet_helpers.h"
#define ANDROID_PACKAGE_NAME "com.zano_mobile"
#define LOGS_FOLDER "logs"
@ -35,19 +34,6 @@
//TODO: global objects, subject to refactoring
struct plain_wallet_instance
{
plain_wallet_instance() :initialized(false), gjobs_counter(1)
{}
wallets_manager gwm;
std::atomic<bool> initialized;
std::atomic<uint64_t> gjobs_counter;
std::map<uint64_t, std::string> gjobs;
epee::critical_section gjobs_lock;
};
std::shared_ptr<plain_wallet_instance> ginstance_ptr;
#define GET_INSTANCE_PTR(ptr_name) \
auto ptr_name = std::atomic_load(&ginstance_ptr); \
@ -72,6 +58,22 @@ void static_destroy_handler()
namespace plain_wallet
{
struct plain_wallet_instance
{
plain_wallet_instance() :initialized(false), gjobs_counter(1)
{}
wallets_manager gwm;
std::atomic<bool> initialized;
std::atomic<uint64_t> gjobs_counter;
std::map<uint64_t, std::string> gjobs;
epee::critical_section gjobs_lock;
};
std::shared_ptr<plain_wallet::plain_wallet_instance> ginstance_ptr;
typedef epee::json_rpc::response<epee::json_rpc::dummy_result, error> error_response;
@ -174,7 +176,8 @@ namespace plain_wallet
ok_response.result.return_code = API_RETURN_CODE_OK;
return epee::serialization::store_t_to_json(ok_response);
}
std::string init(const std::string& ip, const std::string& port, const std::string& working_dir, int log_level)
{
auto local_ptr = std::atomic_load(&ginstance_ptr);
@ -218,6 +221,8 @@ namespace plain_wallet
LOG_PRINT_L0("[INIT PLAIN_WALLET_INSTANCE] Ver:" << PROJECT_VERSION_LONG << "(" << BUILD_TYPE << ")");
#ifndef CAKEWALLET
std::string wallets_folder = get_wallets_folder();
boost::system::error_code ec;
boost::filesystem::create_directories(wallets_folder, ec);
@ -238,13 +243,29 @@ namespace plain_wallet
err_result.error.message = LOCATION_STR + " \nmessage:" + ec.message();
return epee::serialization::store_t_to_json(err_result);
}
#endif
std::atomic_store(&ginstance_ptr, ptr);
#ifndef CAKEWALLET
epee::json_rpc::response<view::api_responce_return_code, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response);
ok_response.result.return_code = API_RETURN_CODE_OK;
return epee::serialization::store_t_to_json(ok_response);
#else
return API_RETURN_CODE_OK;
#endif
}
std::string init(const std::string& address, const std::string& working_dir, int log_level)
{
epee::net_utils::http::url_content url_data = AUTO_VAL_INIT(url_data);
if(!epee::net_utils::parse_url(address, url_data))
{
LOG_ERROR("Failed to parse address");
return API_RETURN_CODE_BAD_ARG;
}
return init(url_data.host, std::to_string(url_data.port), working_dir, log_level);
}
std::string get_appconfig(const std::string& encryption_key)
{
std::string res_str;
@ -275,6 +296,11 @@ namespace plain_wallet
return epee::serialization::store_t_to_json(ok_response);
}
}
bool is_wallet_exist(const std::string& path)
{
boost::system::error_code ec;
return boost::filesystem::exists(path, ec);
}
std::string generate_random_key(uint64_t lenght)
{
@ -615,4 +641,35 @@ namespace plain_wallet
return res;
}
struct wallet_extended_info
{
view::wallet_info wi;
view::wallet_info_extra wi_extended;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(wi)
KV_SERIALIZE(wi_extended)
END_KV_SERIALIZE_MAP()
};
std::string get_wallet_info(hwallet h)
{
GET_INSTANCE_PTR(inst_ptr);
wallet_extended_info wei = AUTO_VAL_INIT(wei);
inst_ptr->gwm.get_wallet_info(h, wei.wi);
inst_ptr->gwm.get_wallet_info_extra(h, wei.wi_extended);
return epee::serialization::store_t_to_json(wei);
}
std::string reset_wallet_password(hwallet h, const std::string& password)
{
GET_INSTANCE_PTR(inst_ptr);
return inst_ptr->gwm.reset_wallet_password(h, password);
}
// 0 (default), 1 (unimportant), 2 (normal), 3 (elevated), 4 (priority)
uint64_t get_current_tx_fee(uint64_t priority)
{
return TX_DEFAULT_FEE;
}
}

View file

@ -6,10 +6,12 @@
#pragma once
#include <string>
#include "../common/error_codes.h"
namespace plain_wallet
{
typedef int64_t hwallet;
std::string init(const std::string& address, const std::string& working_dir, int log_level);
std::string init(const std::string& ip, const std::string& port, const std::string& working_dir, int log_level);
std::string reset();
std::string set_log_level(int log_level);
@ -31,6 +33,7 @@ namespace plain_wallet
std::string generate(const std::string& path, const std::string& password);
std::string get_opened_wallets();
std::string get_wallet_status(hwallet h);
std::string close_wallet(hwallet h);
std::string invoke(hwallet h, const std::string& params);
@ -39,4 +42,12 @@ namespace plain_wallet
std::string async_call(const std::string& method_name, uint64_t instance_id, const std::string& params);
std::string try_pull_result(uint64_t);
std::string sync_call(const std::string& method_name, uint64_t instance_id, const std::string& params);
}
//cake wallet api extension
bool is_wallet_exist(const std::string& path);
std::string get_wallet_info(hwallet h);
std::string reset_wallet_password(hwallet h, const std::string& password);
uint64_t get_current_tx_fee(uint64_t priority); // 0 (default), 1 (unimportant), 2 (normal), 3 (elevated), 4 (priority)
}

View file

@ -210,7 +210,7 @@ public:
};
typedef tools::wallet_public::wallet_info wallet_info;
typedef tools::wallet_public::wallet_info_extra wallet_info_extra;
typedef tools::wallet_public::wallet_entry_info wallet_entry_info;
@ -591,6 +591,7 @@ public:
bool is_in_long_refresh;
uint64_t progress;
uint64_t current_daemon_height;
uint64_t current_wallet_height;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(is_daemon_connected)
@ -598,6 +599,7 @@ public:
KV_SERIALIZE(is_in_long_refresh)
KV_SERIALIZE(progress)
KV_SERIALIZE(current_daemon_height)
KV_SERIALIZE(current_wallet_height)
END_KV_SERIALIZE_MAP()
};

View file

@ -1463,11 +1463,27 @@ namespace wallet_public
KV_SERIALIZE(address)
KV_SERIALIZE(view_sec_key)
KV_SERIALIZE(path)
KV_SERIALIZE(is_auditable);
KV_SERIALIZE(is_watch_only);
KV_SERIALIZE(is_auditable)
KV_SERIALIZE(is_watch_only)
END_KV_SERIALIZE_MAP()
};
struct wallet_info_extra
{
std::string view_private_key;
std::string view_public_key;
std::string spend_private_key;
std::string spend_public_key;
std::string seed;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(view_private_key)
KV_SERIALIZE(view_public_key)
KV_SERIALIZE(spend_private_key)
KV_SERIALIZE(spend_public_key)
KV_SERIALIZE(seed)
END_KV_SERIALIZE_MAP()
};
struct wallet_entry_info

View file

@ -1613,6 +1613,7 @@ std::string wallets_manager::get_wallet_status(uint64_t wallet_id)
wsi.progress = wo.w.unlocked_get().get()->get_sync_progress();
wsi.wallet_state = wo.wallet_state;
wsi.current_daemon_height = m_last_daemon_height;
wsi.current_wallet_height = wo.w.unlocked_get().get()->get_top_block_height();
return epee::serialization::store_t_to_json(wsi);
}
@ -1648,6 +1649,24 @@ std::string wallets_manager::get_wallet_info(uint64_t wallet_id, view::wallet_in
GET_WALLET_OPT_BY_ID(wallet_id, w);
return get_wallet_info(w, wi);
}
std::string wallets_manager::get_wallet_info_extra(uint64_t wallet_id, view::wallet_info_extra& wi)
{
GET_WALLET_OPT_BY_ID(wallet_id, wo);
auto locker_object = wo.w.lock();
tools::wallet2& rw = *(*(*locker_object)); //this looks a bit crazy, i know
auto& keys = rw.get_account().get_keys();
wi.view_private_key = epee::string_tools::pod_to_hex(keys.view_secret_key);
wi.view_public_key = epee::string_tools::pod_to_hex(keys.account_address.view_public_key);
wi.spend_private_key = epee::string_tools::pod_to_hex(keys.spend_secret_key);
wi.spend_public_key = epee::string_tools::pod_to_hex(keys.account_address.spend_public_key);
wi.seed = rw.get_account().get_seed_phrase("");
return API_RETURN_CODE_OK;
}
std::string wallets_manager::get_contracts(size_t wallet_id, std::vector<tools::wallet_public::escrow_contract_details>& contracts)
{
tools::wallet2::escrow_contracts_container cc;

View file

@ -106,6 +106,7 @@ public:
std::string run_wallet(uint64_t wallet_id);
std::string get_recent_transfers(size_t wallet_id, uint64_t offset, uint64_t count, view::transfers_array& tr_hist, bool exclude_mining_txs = false);
std::string get_wallet_info(uint64_t wallet_id, view::wallet_info& wi);
std::string get_wallet_info_extra(uint64_t wallet_id, view::wallet_info_extra& wi);
std::string get_contracts(size_t wallet_id, std::vector<tools::wallet_public::escrow_contract_details>& contracts);
std::string create_proposal(const view::create_proposal_param_gui& cpp);
std::string accept_proposal(size_t wallet_id, const crypto::hash& contract_id);