forked from lthn/blockchain
multiple fixes over wallet/core api
This commit is contained in:
parent
b4cdae8bd8
commit
dbd8c39fe2
7 changed files with 78 additions and 51 deletions
|
|
@ -494,6 +494,39 @@ namespace currency
|
|||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_validate_signature(const COMMAND_VALIDATE_SIGNATURE::request& req, COMMAND_VALIDATE_SIGNATURE::response& res, epee::json_rpc::error& er, connection_context& cntx)
|
||||
{
|
||||
if (!m_p2p.get_connections_count())
|
||||
{
|
||||
res.status = API_RETURN_CODE_DISCONNECTED;
|
||||
return true;
|
||||
}
|
||||
std::string buff = epee::string_encoding::base64_decode(req.buff);
|
||||
crypto::public_key pkey = req.pkey;
|
||||
|
||||
if(pkey == currency::null_pkey)
|
||||
{
|
||||
//need to load pkey from alias
|
||||
extra_alias_entry_base eaeb = AUTO_VAL_INIT(eaeb);
|
||||
if (!m_core.get_blockchain_storage().get_alias_info(req.alias, eaeb))
|
||||
{
|
||||
res.status = API_RETURN_CODE_NOT_FOUND;
|
||||
return true;
|
||||
}
|
||||
pkey = eaeb.m_address.spend_public_key;
|
||||
}
|
||||
|
||||
crypto::hash h = crypto::cn_fast_hash(buff.data(), buff.size());
|
||||
bool sig_check_res = crypto::check_signature(h, pkey, req.sig);
|
||||
if (!sig_check_res)
|
||||
{
|
||||
res.status = API_RETURN_CODE_FAIL;
|
||||
return true;
|
||||
}
|
||||
res.status = API_RETURN_CODE_OK;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_get_pos_mining_details(const COMMAND_RPC_GET_POS_MINING_DETAILS::request& req, COMMAND_RPC_GET_POS_MINING_DETAILS::response& res, connection_context& cntx)
|
||||
{
|
||||
if (!m_p2p.get_connections_count())
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ namespace currency
|
|||
bool on_get_alt_block_details(const COMMAND_RPC_GET_BLOCK_DETAILS::request& req, COMMAND_RPC_GET_BLOCK_DETAILS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
||||
bool on_get_alt_blocks_details(const COMMAND_RPC_GET_ALT_BLOCKS_DETAILS::request& req, COMMAND_RPC_GET_ALT_BLOCKS_DETAILS::response& res, connection_context& cntx);
|
||||
bool on_get_est_height_from_date(const COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::request& req, COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::response& res, connection_context& cntx);
|
||||
|
||||
bool on_validate_signature(const COMMAND_VALIDATE_SIGNATURE::request& req, COMMAND_VALIDATE_SIGNATURE::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
|
||||
|
||||
|
||||
|
|
@ -149,7 +149,8 @@ namespace currency
|
|||
MAP_JON_RPC ("reset_transaction_pool", on_reset_transaction_pool, COMMAND_RPC_RESET_TX_POOL)
|
||||
MAP_JON_RPC ("get_current_core_tx_expiration_median", on_get_current_core_tx_expiration_median, COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN)
|
||||
//
|
||||
MAP_JON_RPC_WE("marketplace_global_get_offers_ex", on_get_offers_ex, COMMAND_RPC_GET_OFFERS_EX)
|
||||
MAP_JON_RPC_WE("marketplace_global_get_offers_ex", on_get_offers_ex, COMMAND_RPC_GET_OFFERS_EX)
|
||||
MAP_JON_RPC_WE("validate_signature", on_validate_signature, COMMAND_VALIDATE_SIGNATURE)
|
||||
CHAIN_TO_PHANDLER(m_prpc_chain_handler)
|
||||
END_JSON_RPC_MAP()
|
||||
CHAIN_TO_PHANDLER(m_prpc_chain_handler)
|
||||
|
|
|
|||
|
|
@ -1584,6 +1584,34 @@ namespace currency
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
struct COMMAND_VALIDATE_SIGNATURE
|
||||
{
|
||||
struct request
|
||||
{
|
||||
std::string buff; //base64 encoded data
|
||||
crypto::signature sig = currency::null_sig;
|
||||
crypto::public_key pkey = currency::null_pkey;
|
||||
std::string alias;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(buff)
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(sig)
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(pkey)
|
||||
KV_SERIALIZE(alias)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
||||
struct response
|
||||
{
|
||||
std::string status;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(status)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
struct void_struct
|
||||
{
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
|
|
|
|||
|
|
@ -1389,7 +1389,9 @@ namespace wallet_public
|
|||
|
||||
struct response
|
||||
{
|
||||
std::string status;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(status)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
|
@ -1400,7 +1402,6 @@ namespace wallet_public
|
|||
{
|
||||
std::string buff; //base64 encoded data
|
||||
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(buff)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
|
|
@ -1409,37 +1410,16 @@ namespace wallet_public
|
|||
|
||||
struct response
|
||||
{
|
||||
crypto::signature sig;
|
||||
crypto::signature sig = currency::null_sig;
|
||||
crypto::public_key pkey = currency::null_pkey;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(sig)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
struct COMMAND_VALIDATE_SIGNATURE
|
||||
{
|
||||
struct request
|
||||
{
|
||||
std::string buff; //base64 encoded data
|
||||
crypto::signature sig;
|
||||
crypto::public_key pkey;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(buff)
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(sig)
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(pkey)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
||||
struct response
|
||||
{
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
struct COMMAND_ENCRYPT_DATA
|
||||
{
|
||||
struct request
|
||||
|
|
|
|||
|
|
@ -22,18 +22,18 @@ using namespace epee;
|
|||
|
||||
#define WALLET_RPC_BEGIN_TRY_ENTRY() try { GET_WALLET();
|
||||
#define WALLET_RPC_CATCH_TRY_ENTRY() } \
|
||||
catch (const tools::error::wallet_error& e) \
|
||||
{ \
|
||||
er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; \
|
||||
er.message = e.error_code(); \
|
||||
return false; \
|
||||
} \
|
||||
catch (const tools::error::daemon_busy& e) \
|
||||
{ \
|
||||
er.code = WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY; \
|
||||
er.message = e.what(); \
|
||||
return false; \
|
||||
} \
|
||||
catch (const tools::error::wallet_error& e) \
|
||||
{ \
|
||||
er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; \
|
||||
er.message = e.error_code(); \
|
||||
return false; \
|
||||
} \
|
||||
catch (const std::exception& e) \
|
||||
{ \
|
||||
er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; \
|
||||
|
|
@ -1001,21 +1001,7 @@ namespace tools
|
|||
WALLET_RPC_BEGIN_TRY_ENTRY();
|
||||
std::string buff = epee::string_encoding::base64_decode(req.buff);
|
||||
w.get_wallet()->sign_buffer(buff, res.sig);
|
||||
return true;
|
||||
WALLET_RPC_CATCH_TRY_ENTRY();
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool wallet_rpc_server::on_validate_signature(const wallet_public::COMMAND_VALIDATE_SIGNATURE::request& req, wallet_public::COMMAND_VALIDATE_SIGNATURE::response& res, epee::json_rpc::error& er, connection_context& cntx)
|
||||
{
|
||||
WALLET_RPC_BEGIN_TRY_ENTRY();
|
||||
std::string buff = epee::string_encoding::base64_decode(req.buff);
|
||||
bool r = w.get_wallet()->validate_sign(buff, req.sig, req.pkey);
|
||||
if (!r)
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT;
|
||||
er.message = "WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT";
|
||||
return false;
|
||||
}
|
||||
res.pkey = w.get_wallet()->get_account().get_public_address().spend_public_key;
|
||||
return true;
|
||||
WALLET_RPC_CATCH_TRY_ENTRY();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,7 +135,6 @@ namespace tools
|
|||
|
||||
//basic crypto operations
|
||||
MAP_JON_RPC_WE("sign_message", on_sign_message, wallet_public::COMMAND_SIGN_MESSAGE)
|
||||
MAP_JON_RPC_WE("validate_signature", on_validate_signature, wallet_public::COMMAND_VALIDATE_SIGNATURE)
|
||||
MAP_JON_RPC_WE("encrypt_data", on_encrypt_data, wallet_public::COMMAND_ENCRYPT_DATA)
|
||||
MAP_JON_RPC_WE("decrypt_data", on_decrypt_data, wallet_public::COMMAND_DECRYPT_DATA)
|
||||
END_JSON_RPC_MAP()
|
||||
|
|
@ -187,7 +186,6 @@ namespace tools
|
|||
bool on_mw_select_wallet(const wallet_public::COMMAND_MW_SELECT_WALLET::request& req, wallet_public::COMMAND_MW_SELECT_WALLET::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
|
||||
bool on_sign_message(const wallet_public::COMMAND_SIGN_MESSAGE::request& req, wallet_public::COMMAND_SIGN_MESSAGE::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_validate_signature(const wallet_public::COMMAND_VALIDATE_SIGNATURE::request& req, wallet_public::COMMAND_VALIDATE_SIGNATURE::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_encrypt_data(const wallet_public::COMMAND_ENCRYPT_DATA::request& req, wallet_public::COMMAND_ENCRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_decrypt_data(const wallet_public::COMMAND_DECRYPT_DATA::request& req, wallet_public::COMMAND_DECRYPT_DATA::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
|
||||
|
|
|
|||
|
|
@ -2063,6 +2063,7 @@ bool wallets_manager::on_mw_get_wallets(const tools::wallet_public::COMMAND_MW_G
|
|||
bool wallets_manager::on_mw_select_wallet(const tools::wallet_public::COMMAND_MW_SELECT_WALLET::request& req, tools::wallet_public::COMMAND_MW_SELECT_WALLET::response& res, epee::json_rpc::error& er, epee::net_utils::connection_context_base& cntx)
|
||||
{
|
||||
this->on_mw_select_wallet(req.wallet_id);
|
||||
res.status = API_RETURN_CODE_OK;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue