1
0
Fork 0
forked from lthn/blockchain

tested plain wallet interface, and fixed errors

This commit is contained in:
cryptozoidberg 2020-01-27 20:57:12 +01:00
parent 03f04c9dd9
commit cfe9837ba8
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
5 changed files with 87 additions and 9 deletions

View file

@ -8,9 +8,9 @@
namespace plain_wallet
{
hwallet create_instance(const std::string port, const std::string ip)
hwallet create_instance(const std::string ip, const std::string port)
{
return new plain_wallet_api_impl(port, ip);
return new plain_wallet_api_impl(ip, port);
}
void destroy_instance(hwallet h)
{

View file

@ -10,7 +10,7 @@
namespace plain_wallet
{
typedef void* hwallet;
hwallet create_instance(const std::string port, const std::string ip);
hwallet create_instance(const std::string ip, const std::string port);
void destroy_instance(hwallet h);
std::string open(hwallet h, const std::string& path, const std::string password);

View file

@ -9,7 +9,9 @@ namespace plain_wallet
{
typedef epee::json_rpc::response<epee::json_rpc::dummy_result, error> error_response;
plain_wallet_api_impl::plain_wallet_api_impl(const std::string ip, const std::string port):m_stop(false)
plain_wallet_api_impl::plain_wallet_api_impl(const std::string ip, const std::string port):
m_stop(false),
m_sync_finished(false)
{
m_wallet.reset(new tools::wallet2());
m_wallet->init(ip + ":" + port);
@ -159,6 +161,7 @@ namespace plain_wallet
epee::net_utils::connection_context_base stub_conn_context = AUTO_VAL_INIT(stub_conn_context);
std::string reference_stub;
bool call_found = false;
query_info.m_URI = "/json_rpc";
query_info.m_body = params;
m_rpc_wrapper->handle_http_request_map(query_info, response_info, stub_conn_context, call_found, reference_stub);
return response_info.m_body;

View file

@ -191,7 +191,7 @@ int main(int argc, char* argv[])
do_deadlock_test_main();
return 1;
}
else if (command_line::has_arg(vm, arg_deadlock_guard))
else if (command_line::has_arg(vm, arg_test_plain_wallet))
{
run_plain_wallet_api_test();
return 1;

View file

@ -19,11 +19,11 @@ using namespace epee;
void run_plain_wallet_api_test()
{
LOG_PRINT_L0("Creating instance...");
plain_wallet::hwallet hw = plain_wallet::create_instance("11211", "127.0.0.1.");
plain_wallet::hwallet hw = plain_wallet::create_instance("127.0.0.1", "11211");
LOG_PRINT_L0("Creating instance..." << std::hex << hw);
LOG_PRINT_L0("Generating wallet...");
std::string rsp = plain_wallet::generate(hw, std::string("E:\\tmp\\zano_testwallet_") + std::to_string(epee::misc_utils::get_tick_count()) + ".zan", "");
std::string rsp = plain_wallet::open(hw, std::string("E:\\tmp\\zano_testwallet_74565030.zan"), "");
LOG_PRINT_L0("RESPONSE:" << ENDL << rsp);
epee::json_rpc::response<plain_wallet::open_wallet_response, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response);
epee::serialization::load_t_from_json(ok_response, rsp);
@ -53,7 +53,7 @@ void run_plain_wallet_api_test()
std::string res = plain_wallet::invoke(hw, req_str);
epee::serialization::load_t_from_json(gbres, res);
LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: "
LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: "
<< ENDL << res);
}
@ -82,5 +82,80 @@ void run_plain_wallet_api_test()
epee::serialization::load_t_from_json(gbres, res);
LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: "
<< ENDL << res); }
<< ENDL << res);
}
plain_wallet::destroy_instance(hw);
return;
//-------
{
LOG_PRINT_L0("Creating instance...");
plain_wallet::hwallet hw = plain_wallet::create_instance("127.0.0.1", "11211");
LOG_PRINT_L0("Creating instance..." << std::hex << hw);
LOG_PRINT_L0("Generating wallet...");
std::string rsp = plain_wallet::generate(hw, std::string("E:\\tmp\\zano_testwallet_") + std::to_string(epee::misc_utils::get_tick_count()) + ".zan", "");
LOG_PRINT_L0("RESPONSE:" << ENDL << rsp);
epee::json_rpc::response<plain_wallet::open_wallet_response, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response);
epee::serialization::load_t_from_json(ok_response, rsp);
plain_wallet::start_sync_thread(hw);
LOG_PRINT_L0("Started sync thread.");
while (true)
{
std::string prog = plain_wallet::get_sync_status(hw);
plain_wallet::sync_status_response ssr = AUTO_VAL_INIT(ssr);
epee::serialization::load_t_from_json(ssr, prog);
LOG_PRINT_L0("Progress: " << ssr.progress << "Finished: " << ssr.finished);
if (ssr.finished)
break;
epee::misc_utils::sleep_no_w(1000);
}
LOG_PRINT_L0("Sync finished OK");
{
//request get wallet info:
epee::json_rpc::request<tools::wallet_public::COMMAND_RPC_GET_WALLET_INFO::request> gbreq = AUTO_VAL_INIT(gbreq);
gbreq.method = "get_wallet_info";
epee::json_rpc::response<tools::wallet_public::COMMAND_RPC_GET_WALLET_INFO::response, epee::json_rpc::error> gbres = AUTO_VAL_INIT(gbres);
std::string req_str = epee::serialization::store_t_to_json(gbreq);
std::string res = plain_wallet::invoke(hw, req_str);
epee::serialization::load_t_from_json(gbres, res);
LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: "
<< ENDL << res);
}
{
//request balance
epee::json_rpc::request<tools::wallet_public::COMMAND_RPC_GET_BALANCE::request> gbreq = AUTO_VAL_INIT(gbreq);
gbreq.method = "getbalance";
epee::json_rpc::response<tools::wallet_public::COMMAND_RPC_GET_BALANCE::response, epee::json_rpc::error> gbres = AUTO_VAL_INIT(gbres);
std::string req_str = epee::serialization::store_t_to_json(gbreq);
std::string res = plain_wallet::invoke(hw, req_str);
epee::serialization::load_t_from_json(gbres, res);
LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], balance: "
<< gbres.result.balance << ", unlocked_balance: " << gbres.result.unlocked_balance);
}
{
//request balance
epee::json_rpc::request<tools::wallet_public::COMMAND_RPC_STORE::request> gbreq = AUTO_VAL_INIT(gbreq);
gbreq.method = "store";
epee::json_rpc::response<tools::wallet_public::COMMAND_RPC_STORE::response, epee::json_rpc::error> gbres = AUTO_VAL_INIT(gbres);
std::string req_str = epee::serialization::store_t_to_json(gbreq);
std::string res = plain_wallet::invoke(hw, req_str);
epee::serialization::load_t_from_json(gbres, res);
LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: "
<< ENDL << res);
}
}
}