implemented exented wallet api, finished plain wallet test(but not tested yet)
This commit is contained in:
parent
c0f1d7b577
commit
03f04c9dd9
12 changed files with 122 additions and 10 deletions
|
|
@ -13,7 +13,6 @@ set(VERSION "1.0")
|
|||
cmake_policy(SET CMP0020 OLD)
|
||||
endif()
|
||||
|
||||
set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "Andrey Sabelnikov")
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
# build types
|
||||
|
|
@ -24,7 +23,11 @@ if (UNIX AND NOT APPLE)
|
|||
endif()
|
||||
else()
|
||||
# multi configurations for MSVC and XCode
|
||||
set(CMAKE_CONFIGURATION_TYPES "Release")
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
||||
set(CMAKE_CONFIGURATION_TYPES "Release")
|
||||
else()
|
||||
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
|
||||
endif()
|
||||
endif()
|
||||
message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}, and built type: ${CMAKE_BUILD_TYPE}")
|
||||
|
||||
|
|
@ -169,7 +172,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
|||
set(Boost_LIBRARIES "libboost.a")
|
||||
set(Boost_VERSION "ofxiOSBoost 1.60.0")
|
||||
else()
|
||||
find_package(Boost 1.55 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options ) #locale
|
||||
find_package(Boost 1.55 REQUIRED COMPONENTS system filesystem locale thread timer date_time chrono regex serialization atomic program_options ) #locale
|
||||
endif()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ using namespace currency;
|
|||
#endif
|
||||
#define BLOCK_POS_STRICT_SEQUENCE_LIMIT 20
|
||||
|
||||
#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX "_v1"
|
||||
|
||||
DISABLE_VS_WARNINGS(4267)
|
||||
|
||||
|
|
|
|||
|
|
@ -192,7 +192,9 @@
|
|||
|
||||
|
||||
#define CURRENCY_POOLDATA_FOLDERNAME_PREFIX "poolstate_"
|
||||
#define CURRENCY_POOLDATA_FOLDERNAME_SUFFIX "_v1"
|
||||
#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_PREFIX "blockchain_"
|
||||
#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX "_v1"
|
||||
|
||||
#define P2P_NET_DATA_FILENAME "p2pstate.bin"
|
||||
#define MINER_CONFIG_FILENAME "miner_conf.json"
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ DISABLE_VS_WARNINGS(4244 4345 4503) //'boost::foreach_detail_::or_' : decorated
|
|||
#define TRANSACTION_POOL_OPTIONS_ID_STORAGE_MAJOR_COMPATIBILITY_VERSION 92 // DON'T CHANGE THIS, if you need to resync db! Change TRANSACTION_POOL_MAJOR_COMPATIBILITY_VERSION instead!
|
||||
#define TRANSACTION_POOL_MAJOR_COMPATIBILITY_VERSION BLOCKCHAIN_STORAGE_MAJOR_COMPATIBILITY_VERSION + 1
|
||||
|
||||
#define CURRENCY_POOLDATA_FOLDERNAME_SUFFIX "_v1"
|
||||
|
||||
#define CONFLICT_KEY_IMAGE_SPENT_DEPTH_TO_REMOVE_TX_FROM_POOL 50 // if there's a conflict in key images between tx in the pool and in the blockchain this much depth in required to remove correspongin tx from pool
|
||||
|
||||
|
|
|
|||
|
|
@ -2589,6 +2589,11 @@ uint64_t wallet2::get_recent_transfers_total_count()
|
|||
return m_transfer_history.size();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
uint64_t wallet2::get_transfer_entries_count()
|
||||
{
|
||||
return m_transfers.size();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::get_recent_transfers_history(std::vector<wallet_public::wallet_transfer_info>& trs, size_t offset, size_t count, uint64_t& total)
|
||||
{
|
||||
if (offset >= m_transfer_history.size())
|
||||
|
|
|
|||
|
|
@ -466,6 +466,7 @@ namespace tools
|
|||
|
||||
void get_recent_transfers_history(std::vector<wallet_public::wallet_transfer_info>& trs, size_t offset, size_t count, uint64_t& total);
|
||||
uint64_t get_recent_transfers_total_count();
|
||||
uint64_t get_transfer_entries_count();
|
||||
void get_unconfirmed_transfers(std::vector<wallet_public::wallet_transfer_info>& trs);
|
||||
void init(const std::string& daemon_address = "http://localhost:8080");
|
||||
bool deinit();
|
||||
|
|
|
|||
|
|
@ -206,6 +206,37 @@ namespace wallet_public
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct COMMAND_RPC_GET_WALLET_INFO
|
||||
{
|
||||
struct request
|
||||
{
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
std::string address;
|
||||
std::string path;
|
||||
uint64_t transfers_count;
|
||||
uint64_t transfer_entries_count;
|
||||
bool is_whatch_only;
|
||||
std::vector<std::string> utxo_distribution;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(address)
|
||||
KV_SERIALIZE(path)
|
||||
KV_SERIALIZE(transfers_count)
|
||||
KV_SERIALIZE(transfer_entries_count)
|
||||
KV_SERIALIZE(is_whatch_only)
|
||||
KV_SERIALIZE(utxo_distribution)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct trnsfer_destination
|
||||
{
|
||||
uint64_t amount;
|
||||
|
|
|
|||
|
|
@ -186,6 +186,29 @@ namespace tools
|
|||
}
|
||||
return true;
|
||||
}
|
||||
bool wallet_rpc_server::on_getwallet_info(const wallet_public::COMMAND_RPC_GET_WALLET_INFO::request& req, wallet_public::COMMAND_RPC_GET_WALLET_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx)
|
||||
{
|
||||
try
|
||||
{
|
||||
res.address = m_wallet.get_account().get_public_address_str();
|
||||
res.is_whatch_only = m_wallet.is_watch_only();
|
||||
res.path = epee::string_encoding::convert_to_ansii(m_wallet.get_wallet_path());
|
||||
res.transfers_count = m_wallet.get_recent_transfers_total_count();
|
||||
res.transfer_entries_count = m_wallet.get_transfer_entries_count();
|
||||
std::map<uint64_t, uint64_t> distribution;
|
||||
m_wallet.get_utxo_distribution(distribution);
|
||||
for (const auto& ent : distribution)
|
||||
res.utxo_distribution.push_back(std::to_string(ent.first) + ":" + std::to_string(ent.second));
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
|
||||
er.message = e.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool wallet_rpc_server::on_transfer(const wallet_public::COMMAND_RPC_TRANSFER::request& req, wallet_public::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ namespace tools
|
|||
BEGIN_JSON_RPC_MAP("/json_rpc")
|
||||
MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_public::COMMAND_RPC_GET_BALANCE)
|
||||
MAP_JON_RPC_WE("getaddress", on_getaddress, wallet_public::COMMAND_RPC_GET_ADDRESS)
|
||||
MAP_JON_RPC_WE("get_wallet_info", on_getwallet_info, wallet_public::COMMAND_RPC_GET_WALLET_INFO)
|
||||
MAP_JON_RPC_WE("transfer", on_transfer, wallet_public::COMMAND_RPC_TRANSFER)
|
||||
MAP_JON_RPC_WE("store", on_store, wallet_public::COMMAND_RPC_STORE)
|
||||
MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_public::COMMAND_RPC_GET_PAYMENTS)
|
||||
|
|
@ -66,6 +67,7 @@ namespace tools
|
|||
//json_rpc
|
||||
bool on_getbalance(const wallet_public::COMMAND_RPC_GET_BALANCE::request& req, wallet_public::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_getaddress(const wallet_public::COMMAND_RPC_GET_ADDRESS::request& req, wallet_public::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_getwallet_info(const wallet_public::COMMAND_RPC_GET_WALLET_INFO::request& req, wallet_public::COMMAND_RPC_GET_WALLET_INFO::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_transfer(const wallet_public::COMMAND_RPC_TRANSFER::request& req, wallet_public::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_store(const wallet_public::COMMAND_RPC_STORE::request& req, wallet_public::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_get_payments(const wallet_public::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_public::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
|
|
|
|||
|
|
@ -284,8 +284,10 @@ bool generate_events(currency::core& c, cct_events_t& events, const cct_wallets_
|
|||
bool clean_data_directory(boost::program_options::variables_map& vm)
|
||||
{
|
||||
std::string config_folder = command_line::get_arg(vm, command_line::arg_data_dir);
|
||||
const std::string bch_db_folder_path = config_folder + ("/" CURRENCY_BLOCKCHAINDATA_FOLDERNAME_PREFIX) + "lmdb" + CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX;
|
||||
const std::string pool_db_folder_path = config_folder + ("/" CURRENCY_POOLDATA_FOLDERNAME_PREFIX) + "lmdb" + CURRENCY_POOLDATA_FOLDERNAME_SUFFIX;
|
||||
|
||||
static const char* const files[] = { CURRENCY_BLOCKCHAINDATA_FOLDERNAME, CURRENCY_POOLDATA_FOLDERNAME, MINER_CONFIG_FILENAME };
|
||||
static const char* const files[] = { bch_db_folder_path.c_str(), pool_db_folder_path.c_str(), MINER_CONFIG_FILENAME };
|
||||
for (size_t i = 0; i < sizeof files / sizeof files[0]; ++i)
|
||||
{
|
||||
boost::filesystem::path filename(config_folder + "/" + files[i]);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ using namespace epee;
|
|||
#include "generate_test_genesis.h"
|
||||
#include "deadlock_guard_test.h"
|
||||
#include "difficulty_analysis.h"
|
||||
#include "plain_wallet_tests.h"
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
|
|
@ -53,6 +54,7 @@ namespace
|
|||
const command_line::arg_descriptor<size_t> arg_generate_test_genesis_json = { "generate-test-genesis-json", "generates test genesis json, specify amount of accounts", 0, true };
|
||||
const command_line::arg_descriptor<bool> arg_deadlock_guard = { "test-deadlock-guard", "Do deadlock guard test", false, true };
|
||||
const command_line::arg_descriptor<std::string> arg_difficulty_analysis = { "difficulty-analysis", "Do difficulty analysis", "", true };
|
||||
const command_line::arg_descriptor<bool> arg_test_plain_wallet = { "test-plainwallet", "Do testing of plain wallet interface", false, true };
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -104,8 +106,7 @@ int main(int argc, char* argv[])
|
|||
command_line::add_arg(desc_options, arg_max_tx_in_pool);
|
||||
command_line::add_arg(desc_options, arg_deadlock_guard);
|
||||
command_line::add_arg(desc_options, arg_difficulty_analysis);
|
||||
|
||||
|
||||
command_line::add_arg(desc_options, arg_test_plain_wallet);
|
||||
|
||||
|
||||
test_serialization();
|
||||
|
|
@ -190,6 +191,11 @@ int main(int argc, char* argv[])
|
|||
do_deadlock_test_main();
|
||||
return 1;
|
||||
}
|
||||
else if (command_line::has_arg(vm, arg_deadlock_guard))
|
||||
{
|
||||
run_plain_wallet_api_test();
|
||||
return 1;
|
||||
}
|
||||
else if (command_line::get_arg(vm, arg_test_core_concurrency))
|
||||
{
|
||||
for (size_t i = 0; i != repeat_count; i++)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ void run_plain_wallet_api_test()
|
|||
LOG_PRINT_L0("Creating instance..." << std::hex << hw);
|
||||
|
||||
LOG_PRINT_L0("Generating wallet...");
|
||||
std::string rsp = plain_wallet::generate(hw, "E:\\tmp\\sdsd", "");
|
||||
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);
|
||||
|
|
@ -39,9 +39,48 @@ void run_plain_wallet_api_test()
|
|||
LOG_PRINT_L0("Progress: " << ssr.progress << "Finished: " << ssr.finished);
|
||||
if (ssr.finished)
|
||||
break;
|
||||
epee::misc_utils::sleep_no_w(100);
|
||||
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); }
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue