forked from lthn/blockchain
added new api to update alias
This commit is contained in:
parent
d622078ef9
commit
47e10e7209
10 changed files with 80 additions and 14 deletions
|
|
@ -1294,7 +1294,7 @@ QString MainWindow::request_alias_update(const QString& param)
|
|||
|
||||
// view::transfer_response tr = AUTO_VAL_INIT(tr);
|
||||
currency::transaction res_tx = AUTO_VAL_INIT(res_tx);
|
||||
ar.error_code = m_backend.request_alias_update(tp.alias, tp.wallet_id, tp.fee, res_tx, tp.reward);
|
||||
ar.error_code = m_backend.request_alias_update(tp.alias, tp.wallet_id, tp.fee, res_tx);
|
||||
if (ar.error_code != API_RETURN_CODE_OK)
|
||||
return MAKE_RESPONSE(ar);
|
||||
|
||||
|
|
|
|||
|
|
@ -5396,13 +5396,28 @@ bool wallet2::daemon_get_asset_info(const crypto::public_key& asset_id, currency
|
|||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward)
|
||||
void wallet2::request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee)
|
||||
{
|
||||
COMMAND_RPC_GET_ALIAS_DETAILS::request req;
|
||||
req.alias = ai.m_alias;
|
||||
COMMAND_RPC_GET_ALIAS_DETAILS::response rsp = AUTO_VAL_INIT(rsp);
|
||||
bool r = m_core_proxy->call_COMMAND_RPC_GET_ALIAS_DETAILS(req, rsp);
|
||||
CHECK_AND_ASSERT_THROW_MES(r, "Failed to call_COMMAND_RPC_GET_ALIAS_DETAILS");
|
||||
|
||||
CHECK_AND_ASSERT_THROW_MES(rsp.status == API_RETURN_CODE_OK, "call_COMMAND_RPC_GET_ALIAS_DETAILS response: " << rsp.status);
|
||||
|
||||
|
||||
currency::account_public_address addr = AUTO_VAL_INIT(addr);
|
||||
currency::get_account_address_from_str(addr, rsp.alias_details.address);
|
||||
|
||||
CHECK_AND_ASSERT_THROW_MES(m_account.get_public_address().spend_public_key == addr.spend_public_key &&
|
||||
m_account.get_public_address().view_public_key == addr.view_public_key, "call_COMMAND_RPC_GET_ALIAS_DETAILS: ownership is not confirmed");
|
||||
|
||||
if (!validate_alias_name(ai.m_alias))
|
||||
{
|
||||
throw std::runtime_error(std::string("wrong alias characters: ") + ai.m_alias);
|
||||
}
|
||||
bool r = currency::sign_extra_alias_entry(ai, m_account.get_keys().account_address.spend_public_key, m_account.get_keys().spend_secret_key);
|
||||
r = currency::sign_extra_alias_entry(ai, m_account.get_keys().account_address.spend_public_key, m_account.get_keys().spend_secret_key);
|
||||
CHECK_AND_ASSERT_THROW_MES(r, "Failed to sign alias update");
|
||||
WLT_LOG_L2("Generated update alias info: " << ENDL
|
||||
<< "alias: " << ai.m_alias << ENDL
|
||||
|
|
|
|||
|
|
@ -416,7 +416,7 @@ namespace tools
|
|||
void cancel_offer_by_id(const crypto::hash& tx_id, uint64_t of_ind, uint64_t fee, currency::transaction& tx);
|
||||
void update_offer_by_id(const crypto::hash& tx_id, uint64_t of_ind, const bc_services::offer_details_ex& od, currency::transaction& res_tx);
|
||||
void request_alias_registration(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward = 0, const crypto::secret_key& authority_key = currency::null_skey); // if the given reward is 0, then the actual reward value will be requested via RPC
|
||||
void request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward);
|
||||
void request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee);
|
||||
bool check_available_sources(std::list<uint64_t>& amounts);
|
||||
|
||||
void deploy_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector<currency::tx_destination_entry>& destinations, currency::transaction& result_tx, crypto::public_key& new_asset_id);
|
||||
|
|
|
|||
|
|
@ -633,6 +633,29 @@ namespace wallet_public
|
|||
};
|
||||
};
|
||||
|
||||
struct COMMAND_RPC_UPDATE_ALIAS
|
||||
{
|
||||
DOC_COMMAND("Update an alias details/transwer alias ownership");
|
||||
|
||||
struct request
|
||||
{
|
||||
currency::alias_rpc_details al;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(al) DOC_DSCR("Alias details") DOC_END
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
crypto::hash tx_id;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(tx_id) DOC_DSCR("If success - transactions that performs registration(alias becomes available after few confirmations)") DOC_EXMP("97d91442f8f3c22683585eaa60b53757d49bf046a96269cef45c1bc9ff7300cc") DOC_END
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct transfer_destination
|
||||
{
|
||||
|
|
|
|||
|
|
@ -968,6 +968,31 @@ namespace tools
|
|||
WALLET_RPC_CATCH_TRY_ENTRY();
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool wallet_rpc_server::on_update_alias(const wallet_public::COMMAND_RPC_UPDATE_ALIAS::request& req, wallet_public::COMMAND_RPC_UPDATE_ALIAS::response& res, epee::json_rpc::error& er, connection_context& cntx)
|
||||
{
|
||||
WALLET_RPC_BEGIN_TRY_ENTRY();
|
||||
currency::extra_alias_entry ai = AUTO_VAL_INIT(ai);
|
||||
if (!alias_rpc_details_to_alias_info(req.al, ai))
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS;
|
||||
er.message = "WALLET_RPC_ERROR_CODE_WRONG_ADDRESS";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!currency::validate_alias_name(ai.m_alias))
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS;
|
||||
er.message = "WALLET_RPC_ERROR_CODE_WRONG_ADDRESS - Wrong alias name";
|
||||
return false;
|
||||
}
|
||||
|
||||
currency::transaction tx = AUTO_VAL_INIT(tx);
|
||||
w.get_wallet()->request_alias_update(ai, tx, w.get_wallet()->get_default_fee());
|
||||
res.tx_id = get_transaction_hash(tx);
|
||||
return true;
|
||||
WALLET_RPC_CATCH_TRY_ENTRY();
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool wallet_rpc_server::on_contracts_send_proposal(const wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx)
|
||||
{
|
||||
WALLET_RPC_BEGIN_TRY_ENTRY();
|
||||
|
|
|
|||
|
|
@ -116,6 +116,8 @@ namespace tools
|
|||
MAP_JON_RPC_WE("get_seed_phrase_info", on_get_seed_phrase_info, wallet_public::COMMAND_RPC_GET_SEED_PHRASE_INFO)
|
||||
MAP_JON_RPC_WE("get_mining_history", on_get_mining_history, wallet_public::COMMAND_RPC_GET_MINING_HISTORY)
|
||||
MAP_JON_RPC_WE("register_alias", on_register_alias, wallet_public::COMMAND_RPC_REGISTER_ALIAS)
|
||||
MAP_JON_RPC_WE("update_alias", on_update_alias, wallet_public::COMMAND_RPC_UPDATE_ALIAS)
|
||||
|
||||
//contracts API
|
||||
//MAP_JON_RPC_WE("contracts_send_proposal", on_contracts_send_proposal, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL)
|
||||
//MAP_JON_RPC_WE("contracts_accept_proposal", on_contracts_accept_proposal, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL)
|
||||
|
|
@ -186,7 +188,8 @@ namespace tools
|
|||
bool on_search_for_transactions2(const wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::request& req, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_get_mining_history(const wallet_public::COMMAND_RPC_GET_MINING_HISTORY::request& req, wallet_public::COMMAND_RPC_GET_MINING_HISTORY::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_register_alias(const wallet_public::COMMAND_RPC_REGISTER_ALIAS::request& req, wallet_public::COMMAND_RPC_REGISTER_ALIAS::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
|
||||
bool on_update_alias(const wallet_public::COMMAND_RPC_UPDATE_ALIAS::request& req, wallet_public::COMMAND_RPC_UPDATE_ALIAS::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
|
||||
|
||||
bool on_contracts_send_proposal(const wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
bool on_contracts_accept_proposal(const wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx);
|
||||
|
|
|
|||
|
|
@ -1459,7 +1459,7 @@ std::string wallets_manager::request_alias_registration(const currency::alias_rp
|
|||
return API_RETURN_CODE_ALREADY_EXISTS;
|
||||
}
|
||||
|
||||
std::string wallets_manager::request_alias_update(const currency::alias_rpc_details& al, uint64_t wallet_id, uint64_t fee, currency::transaction& res_tx, uint64_t reward)
|
||||
std::string wallets_manager::request_alias_update(const currency::alias_rpc_details& al, uint64_t wallet_id, uint64_t fee, currency::transaction& res_tx)
|
||||
{
|
||||
currency::extra_alias_entry ai = AUTO_VAL_INIT(ai);
|
||||
if (!currency::alias_rpc_details_to_alias_info(al, ai))
|
||||
|
|
@ -1480,7 +1480,7 @@ std::string wallets_manager::request_alias_update(const currency::alias_rpc_deta
|
|||
std::string api_return_code_result = API_RETURN_CODE_FAIL;
|
||||
do_exception_safe_call(
|
||||
[&]() {
|
||||
w->get()->request_alias_update(ai, res_tx, fee, reward);
|
||||
w->get()->request_alias_update(ai, res_tx, fee);
|
||||
api_return_code_result = API_RETURN_CODE_OK;
|
||||
},
|
||||
[&]() { return get_wallet_log_prefix(wallet_id) + "request_alias_update error: "; },
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public:
|
|||
std::string get_alias_info_by_address(const std::string& addr, currency::alias_rpc_details& res_details);
|
||||
std::string get_alias_info_by_name(const std::string& name, currency::alias_rpc_details& res_details);
|
||||
std::string request_alias_registration(const currency::alias_rpc_details& al, uint64_t wallet_id, uint64_t fee, currency::transaction& res_tx, uint64_t reward);
|
||||
std::string request_alias_update(const currency::alias_rpc_details& al, uint64_t wallet_id, uint64_t fee, currency::transaction& res_tx, uint64_t reward);
|
||||
std::string request_alias_update(const currency::alias_rpc_details& al, uint64_t wallet_id, uint64_t fee, currency::transaction& res_tx);
|
||||
std::string get_alias_coast(const std::string& a, uint64_t& coast);
|
||||
std::string validate_address(const std::string& addr, std::string& payment_id);
|
||||
std::string resync_wallet(uint64_t wallet_id);
|
||||
|
|
|
|||
|
|
@ -518,7 +518,7 @@ bool hard_fork_2_tx_extra_alias_entry_in_wallet::c1(currency::core& c, size_t ev
|
|||
r = false;
|
||||
try
|
||||
{
|
||||
alice_wlt->request_alias_update(ai_alice_update, res_tx, TESTS_DEFAULT_FEE, 0);
|
||||
alice_wlt->request_alias_update(ai_alice_update, res_tx, TESTS_DEFAULT_FEE);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
|
@ -540,7 +540,7 @@ bool hard_fork_2_tx_extra_alias_entry_in_wallet::c1(currency::core& c, size_t ev
|
|||
// update alias, change comment and address
|
||||
ai.m_text_comment = "Update to normal";
|
||||
ai.m_address = m_accounts[MINER_ACC_IDX].get_public_address();
|
||||
alice_wlt->request_alias_update(ai, res_tx, TESTS_DEFAULT_FEE, 0);
|
||||
alice_wlt->request_alias_update(ai, res_tx, TESTS_DEFAULT_FEE);
|
||||
|
||||
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
|
||||
r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c);
|
||||
|
|
@ -586,7 +586,7 @@ bool hard_fork_2_tx_extra_alias_entry_in_wallet::c1(currency::core& c, size_t ev
|
|||
|
||||
// update alias once again, change comment and address to auditable
|
||||
// alias updated by miner, as he's the owner now
|
||||
miner_wlt->request_alias_update(ai_alice_update, res_tx, TESTS_DEFAULT_FEE, 0);
|
||||
miner_wlt->request_alias_update(ai_alice_update, res_tx, TESTS_DEFAULT_FEE);
|
||||
|
||||
// after HF2: extra_alias_entry should be here, not extra_alias_entry_old
|
||||
r = have_type_in_variant_container<extra_alias_entry>(res_tx.extra);
|
||||
|
|
@ -1221,7 +1221,7 @@ bool hard_fork_2_alias_update_using_old_tx<before_hf_2>::c1(currency::core& c, s
|
|||
//
|
||||
{
|
||||
transaction tx_upd = AUTO_VAL_INIT(tx_upd);
|
||||
alice_wlt->request_alias_update(ai_upd, tx_upd, TESTS_DEFAULT_FEE, 0);
|
||||
alice_wlt->request_alias_update(ai_upd, tx_upd, TESTS_DEFAULT_FEE);
|
||||
std::string tx_upd_hex = epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(tx_upd));
|
||||
LOG_PRINT_L0("tx upd: " << ENDL << tx_upd_hex);
|
||||
}
|
||||
|
|
@ -1334,7 +1334,7 @@ bool hard_fork_2_incorrect_alias_update<before_hf_2>::c1(currency::core& c, size
|
|||
r = false;
|
||||
try
|
||||
{
|
||||
alice_wlt->request_alias_update(ai_upd, tx_upd, TESTS_DEFAULT_FEE, 0);
|
||||
alice_wlt->request_alias_update(ai_upd, tx_upd, TESTS_DEFAULT_FEE);
|
||||
}
|
||||
catch (tools::error::tx_rejected&)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1868,7 +1868,7 @@ bool gen_wallet_alias_via_special_wallet_funcs::c1(currency::core& c, size_t ev_
|
|||
|
||||
ai.m_text_comment = "Update!";
|
||||
ai.m_address = m_accounts[MINER_ACC_IDX].get_public_address();
|
||||
alice_wlt->request_alias_update(ai, res_tx, TESTS_DEFAULT_FEE, 0);
|
||||
alice_wlt->request_alias_update(ai, res_tx, TESTS_DEFAULT_FEE);
|
||||
|
||||
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool");
|
||||
r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue