forked from lthn/blockchain
fixed mw_get_wallets for simplewallet, fail-resistant whitelisti loading
This commit is contained in:
parent
7a6883457b
commit
c03438ba23
5 changed files with 42 additions and 55 deletions
|
|
@ -2816,6 +2816,22 @@ int main(int argc, char* argv[])
|
|||
break;
|
||||
}
|
||||
//try to sync it
|
||||
struct wallet_rpc_local_callback : public tools::i_wallet2_callback
|
||||
{
|
||||
std::shared_ptr<tools::wallet2> m_wlt_ptr;
|
||||
wallet_rpc_local_callback(std::shared_ptr<tools::wallet2> ptr): m_wlt_ptr(ptr)
|
||||
{}
|
||||
virtual void on_mw_get_wallets(std::vector<tools::wallet_public::wallet_entry_info>& wallets)
|
||||
{
|
||||
wallets.push_back(tools::wallet_public::wallet_entry_info());
|
||||
wallets.back().wallet_id = 0;
|
||||
tools::get_wallet_info(*m_wlt_ptr, wallets.back().wi);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
std::shared_ptr<tools::i_wallet2_callback> callback(new wallet_rpc_local_callback(wallet_ptr));
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
|
|
@ -2828,6 +2844,7 @@ int main(int argc, char* argv[])
|
|||
return EXIT_FAILURE;
|
||||
|
||||
wal.set_use_assets_whitelisting(true);
|
||||
wal.callback(callback);
|
||||
|
||||
if (!offline_mode)
|
||||
wal.refresh();
|
||||
|
|
|
|||
|
|
@ -3617,9 +3617,10 @@ bool wallet2::load_whitelisted_tokens() const
|
|||
for (auto it = aw.assets.begin(); it != aw.assets.end(); it++)
|
||||
{
|
||||
m_whitelisted_assets[it->asset_id] = static_cast<currency::asset_descriptor_base>(*it);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool wallet2::load_whitelisted_tokens_if_not_loaded() const
|
||||
|
|
|
|||
|
|
@ -17,7 +17,10 @@ using namespace epee;
|
|||
#include "wallet_rpc_server_error_codes.h"
|
||||
#include "wallet_helpers.h"
|
||||
#include "wrap_service.h"
|
||||
PUSH_VS_WARNINGS
|
||||
DISABLE_VS_WARNINGS(4244)
|
||||
#include "jwt-cpp/jwt.h"
|
||||
POP_VS_WARNINGS
|
||||
#include "crypto/bitcoin/sha256_helper.h"
|
||||
|
||||
#define JWT_TOKEN_EXPIRATION_MAXIMUM (60 * 60)
|
||||
|
|
|
|||
|
|
@ -1043,7 +1043,6 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st
|
|||
|
||||
std::shared_ptr<tools::wallet2> w(new tools::wallet2());
|
||||
w->set_use_deffered_global_outputs(m_use_deffered_global_outputs);
|
||||
w->set_use_assets_whitelisting(true);
|
||||
owr.wallet_id = m_wallet_id_counter++;
|
||||
|
||||
w->callback(std::shared_ptr<tools::i_wallet2_callback>(new i_wallet_to_i_backend_adapter(this, owr.wallet_id)));
|
||||
|
|
@ -1075,6 +1074,7 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st
|
|||
w->get_recent_transfers_history(owr.recent_history.history, 0, txs_to_return, owr.recent_history.total_history_items, owr.recent_history.last_item_index, exclude_mining_txs);
|
||||
//w->get_unconfirmed_transfers(owr.recent_history.unconfirmed);
|
||||
w->get_unconfirmed_transfers(owr.recent_history.history, exclude_mining_txs);
|
||||
w->set_use_assets_whitelisting(true);
|
||||
owr.wallet_local_bc_size = w->get_blockchain_current_size();
|
||||
|
||||
//workaround for missed fee
|
||||
|
|
|
|||
|
|
@ -26,61 +26,19 @@
|
|||
#include "threads_pool_tests.h"
|
||||
#include "wallet/plain_wallet_api.h"
|
||||
#include "wallet/view_iface.h"
|
||||
#include <jwt-cpp/jwt.h>
|
||||
|
||||
PUSH_VS_WARNINGS
|
||||
DISABLE_VS_WARNINGS(4244)
|
||||
#include "jwt-cpp/jwt.h"
|
||||
POP_VS_WARNINGS
|
||||
|
||||
void test_plain_wallet()
|
||||
{
|
||||
|
||||
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiemFub19leHRlbnNpb24iLCJzYWx0IjoiYTUyMTk5MzQyNmYxN2Y2MDQyMzkzYTI4YzJhMzk1NjFiYTgxYmVkZDkxODJlY2E5NTY3ZDBlNjQ3YjIwZTE2NSIsImV4cCI6MTcxMDM2MzA1MH0.CwqvPBtgE8ZUFZ4cYy1ZJLWdYCnhfEiCzEhqDYCK4CQ";
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
std::string sharedSecret = "DFDvfedceEDCECECecedcyhtyh";
|
||||
|
||||
try
|
||||
{
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
auto verifier = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::hs256 { sharedSecret });
|
||||
|
||||
verifier.verify(decoded);
|
||||
|
||||
std::cout << "Token is valid. Claims:" << std::endl;
|
||||
for(auto& e : decoded.get_payload_json())
|
||||
std::cout << e.first << " = " << e.second << std::endl;
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
std::cerr << "Invalid token: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
auto verifier = jwt::verify()
|
||||
.with_issuer("auth0")
|
||||
.with_claim("sample", jwt::claim(std::string("test")))
|
||||
.allow_algorithm(jwt::algorithm::hs256 { "secret" });
|
||||
|
||||
verifier.verify(decoded_token);
|
||||
|
||||
auto token = jwt::create()
|
||||
.set_type("JWS")
|
||||
.set_issuer("auth0")
|
||||
.set_payload_claim("sample", jwt::claim(std::string("test")))
|
||||
.sign(jwt::algorithm::hs256 { "secret" });
|
||||
|
||||
*/
|
||||
return;
|
||||
|
||||
|
||||
|
||||
|
||||
std::string res = plain_wallet::init("195.201.107.230", "33336", "E:\\tmp\\", 0);
|
||||
std::string res = plain_wallet::init("195.201.107.230", "33336", "C:\\Users\\roky\\home\\", 0);
|
||||
|
||||
uint64_t instance_id = 0;
|
||||
res = plain_wallet::open("test.zan", "111");
|
||||
res = plain_wallet::open("SEGA_2", "Test2");
|
||||
while(true)
|
||||
{
|
||||
epee::misc_utils::sleep_no_w(2000);
|
||||
|
|
@ -95,6 +53,14 @@ void test_plain_wallet()
|
|||
std::string invoke_body = "{\"method\":\"get_recent_txs_and_info\",\"params\":{\"offset\":0,\"count\":30,\"update_provision_info\":true}}";
|
||||
|
||||
res = plain_wallet::sync_call("invoke", instance_id, invoke_body);
|
||||
|
||||
invoke_body = "{\"method\":\"assets_whitelist_get\",\"params\":{}}";
|
||||
|
||||
res = plain_wallet::sync_call("invoke", instance_id, invoke_body);
|
||||
|
||||
|
||||
res = plain_wallet::close_wallet(instance_id);
|
||||
|
||||
LOG_PRINT_L0(res);
|
||||
|
||||
}
|
||||
|
|
@ -104,10 +70,10 @@ int main(int argc, char** argv)
|
|||
{
|
||||
epee::string_tools::set_module_name_and_folder(argv[0]);
|
||||
epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2);
|
||||
epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2);
|
||||
epee::log_space::log_singletone::add_logger(LOGGER_FILE,
|
||||
epee::log_space::log_singletone::get_default_log_file().c_str(),
|
||||
epee::log_space::log_singletone::get_default_log_folder().c_str());
|
||||
//epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2);
|
||||
//epee::log_space::log_singletone::add_logger(LOGGER_FILE,
|
||||
// epee::log_space::log_singletone::get_default_log_file().c_str(),
|
||||
// epee::log_space::log_singletone::get_default_log_folder().c_str());
|
||||
|
||||
test_plain_wallet();
|
||||
//parse_weird_tx();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue