mirror of
https://github.com/oxen-io/oxen-core.git
synced 2023-12-14 02:22:56 +01:00
Updates the formatting for buying and updating LNS mappings (#1110)
* Updates the formatting for buying and updating LNS mappings Previously there was no detail on the inputted information to the LNS commands for buy and update. This commit outputs the information to the command line for the user to review. * Update command now queries previous LNS data * Remove comments * check for null on response pointer * update if path * Fix up scope of response
This commit is contained in:
parent
4f1b0786a0
commit
385d8cf104
3 changed files with 83 additions and 22 deletions
|
@ -5658,7 +5658,7 @@ bool simple_wallet::confirm_and_send_tx(std::vector<cryptonote::address_parse_in
|
|||
{
|
||||
prompt << tr("WARNING: this is a non default ring size, which may harm your privacy. Default is recommended.");
|
||||
}
|
||||
prompt << ENDL << tr("Is this okay?");
|
||||
prompt << ENDL << ENDL << tr("Is this okay?");
|
||||
|
||||
std::string accepted = input_line(prompt.str(), true);
|
||||
if (std::cin.eof())
|
||||
|
@ -6383,6 +6383,7 @@ bool simple_wallet::lns_buy_mapping(const std::vector<std::string>& args)
|
|||
std::string const &name = local_args[0];
|
||||
std::string const &value = local_args[1];
|
||||
|
||||
|
||||
SCOPED_WALLET_UNLOCK();
|
||||
std::string reason;
|
||||
std::vector<tools::wallet2::pending_tx> ptx_vector;
|
||||
|
@ -6408,6 +6409,17 @@ bool simple_wallet::lns_buy_mapping(const std::vector<std::string>& args)
|
|||
info.address = m_wallet->get_subaddress({m_current_subaddress_account, 0});
|
||||
info.is_subaddress = m_current_subaddress_account != 0;
|
||||
dsts.push_back(info);
|
||||
|
||||
std::cout << std::endl << tr("Buying Loki Name System Record") << std::endl << std::endl;
|
||||
std::cout << boost::format(tr("Name: %s")) % name << std::endl;
|
||||
std::cout << boost::format(tr("Value: %s")) % value << boost::format(tr(" for %s")) % "Session" << std::endl;
|
||||
std::cout << boost::format(tr("Owner: %s")) % (owner.size() ? owner : m_wallet->get_subaddress_as_str({m_current_subaddress_account, 0}) + " (this wallet) ") << std::endl;
|
||||
if(backup_owner.size()) {
|
||||
std::cout << boost::format(tr("Backup Owner: %s")) % backup_owner << std::endl;
|
||||
} else {
|
||||
std::cout << tr("Backup Owner: (none)") << std::endl;
|
||||
}
|
||||
|
||||
if (!confirm_and_send_tx(dsts, ptx_vector, priority == tools::tx_priority_blink))
|
||||
return false;
|
||||
}
|
||||
|
@ -6449,8 +6461,11 @@ bool simple_wallet::lns_update_mapping(const std::vector<std::string>& args)
|
|||
SCOPED_WALLET_UNLOCK();
|
||||
std::string reason;
|
||||
std::vector<tools::wallet2::pending_tx> ptx_vector;
|
||||
std::vector<cryptonote::COMMAND_RPC_LNS_NAMES_TO_OWNERS::response_entry> response;
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
ptx_vector = m_wallet->lns_create_update_mapping_tx(lns::mapping_type::session,
|
||||
name,
|
||||
value.size() ? &value : nullptr,
|
||||
|
@ -6460,20 +6475,57 @@ bool simple_wallet::lns_update_mapping(const std::vector<std::string>& args)
|
|||
&reason,
|
||||
priority,
|
||||
m_current_subaddress_account,
|
||||
subaddr_indices);
|
||||
subaddr_indices,
|
||||
&response);
|
||||
if (ptx_vector.empty())
|
||||
{
|
||||
tools::fail_msg_writer() << reason;
|
||||
return true;
|
||||
}
|
||||
|
||||
lns::mapping_value encrypted_value = {};
|
||||
encrypted_value.len = response[0].encrypted_value.size() / 2;
|
||||
lokimq::from_hex(response[0].encrypted_value.begin(), response[0].encrypted_value.end(), encrypted_value.buffer.begin());
|
||||
|
||||
lns::mapping_value old_value = {};
|
||||
if (!lns::decrypt_mapping_value(name, encrypted_value, old_value))
|
||||
{
|
||||
fail_msg_writer() << "Failed to decrypt the mapping value=" << response[0].encrypted_value;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<cryptonote::address_parse_info> dsts;
|
||||
cryptonote::address_parse_info info = {};
|
||||
info.address = m_wallet->get_subaddress({m_current_subaddress_account, 0});
|
||||
info.is_subaddress = m_current_subaddress_account != 0;
|
||||
dsts.push_back(info);
|
||||
|
||||
std::cout << std::endl << tr("Updating Loki Name System Record") << std::endl << std::endl;
|
||||
std::cout << boost::format(tr("Name: %s")) % name << std::endl;
|
||||
|
||||
if(value.size()) {
|
||||
std::cout << boost::format(tr("Old Value: %s")) % old_value.to_readable_value(m_wallet->nettype(),static_cast<lns::mapping_type>(response[0].type)) << std::endl;
|
||||
std::cout << boost::format(tr("New Value: %s")) % value << std::endl;
|
||||
} else {
|
||||
std::cout << boost::format(tr("Value: %s")) % old_value.to_readable_value(m_wallet->nettype(),static_cast<lns::mapping_type>(response[0].type)) << std::endl;
|
||||
}
|
||||
|
||||
if(owner.size()) {
|
||||
std::cout << boost::format(tr("Old Owner: %s")) % response[0].owner << std::endl;
|
||||
std::cout << boost::format(tr("New Owner: %s")) % owner << std::endl;
|
||||
} else {
|
||||
std::cout << boost::format(tr("Owner: %s (unchanged)")) % response[0].owner << std::endl;
|
||||
}
|
||||
|
||||
if(backup_owner.size()) {
|
||||
std::cout << boost::format(tr("Old Backup Owner: %s")) % (response[0].backup_owner.empty() ? "(none)" : response[0].backup_owner) << std::endl;
|
||||
std::cout << boost::format(tr("New Backup Owner: %s")) % backup_owner << std::endl;
|
||||
} else {
|
||||
std::cout << boost::format(tr("Backup Owner: %s (unchanged)")) % (response[0].backup_owner.empty() ? "(none)" : response[0].backup_owner) << std::endl;
|
||||
}
|
||||
if (!confirm_and_send_tx(dsts, ptx_vector, false /*blink*/))
|
||||
return false;
|
||||
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
|
|
|
@ -8478,7 +8478,8 @@ static lns_prepared_args prepare_tx_extra_loki_name_system_values(wallet2 const
|
|||
std::string const *backup_owner,
|
||||
bool make_signature,
|
||||
uint32_t account_index,
|
||||
std::string *reason)
|
||||
std::string *reason,
|
||||
std::vector<cryptonote::COMMAND_RPC_LNS_NAMES_TO_OWNERS::response_entry> *response)
|
||||
{
|
||||
lns_prepared_args result = {};
|
||||
if (priority == tools::tx_priority_blink)
|
||||
|
@ -8521,25 +8522,29 @@ static lns_prepared_args prepare_tx_extra_loki_name_system_values(wallet2 const
|
|||
}
|
||||
|
||||
boost::optional<std::string> failed;
|
||||
std::vector<cryptonote::COMMAND_RPC_LNS_NAMES_TO_OWNERS::response_entry> response = wallet.lns_names_to_owners(request, failed);
|
||||
std::vector<cryptonote::COMMAND_RPC_LNS_NAMES_TO_OWNERS::response_entry> response_;
|
||||
if (!response) {
|
||||
response = &response_;
|
||||
}
|
||||
*response = wallet.lns_names_to_owners(request, failed);
|
||||
if (failed)
|
||||
{
|
||||
if (reason) *reason = "Failed to query previous owner for LNS entry, reason=" + *failed;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (response.size())
|
||||
if (response->size())
|
||||
{
|
||||
if (!epee::string_tools::hex_to_pod(response[0].txid, result.prev_txid))
|
||||
if (!epee::string_tools::hex_to_pod((*response)[0].txid, result.prev_txid))
|
||||
{
|
||||
if (reason) *reason = "Failed to convert response txid=" + response[0].txid + " from the daemon into a 32 byte hash, it must be a 64 char hex string";
|
||||
if (reason) *reason = "Failed to convert response txid=" + (*response)[0].txid + " from the daemon into a 32 byte hash, it must be a 64 char hex string";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (make_signature)
|
||||
{
|
||||
if (response.empty())
|
||||
if (response->empty())
|
||||
{
|
||||
if (reason) *reason = "Signature requested when preparing LNS TX but record to update does not exist";
|
||||
return result;
|
||||
|
@ -8547,16 +8552,16 @@ static lns_prepared_args prepare_tx_extra_loki_name_system_values(wallet2 const
|
|||
|
||||
cryptonote::address_parse_info curr_owner_parsed = {};
|
||||
cryptonote::address_parse_info curr_backup_owner_parsed = {};
|
||||
bool curr_owner = cryptonote::get_account_address_from_str(curr_owner_parsed, wallet.nettype(), response[0].owner);
|
||||
bool curr_backup_owner = cryptonote::get_account_address_from_str(curr_backup_owner_parsed, wallet.nettype(), response[0].backup_owner);
|
||||
if (!try_generate_lns_signature(wallet, response[0].owner, owner, backup_owner, result))
|
||||
bool curr_owner = cryptonote::get_account_address_from_str(curr_owner_parsed, wallet.nettype(), (*response)[0].owner);
|
||||
bool curr_backup_owner = cryptonote::get_account_address_from_str(curr_backup_owner_parsed, wallet.nettype(), (*response)[0].backup_owner);
|
||||
if (!try_generate_lns_signature(wallet, (*response)[0].owner, owner, backup_owner, result))
|
||||
{
|
||||
if (!try_generate_lns_signature(wallet, response[0].backup_owner, owner, backup_owner, result))
|
||||
if (!try_generate_lns_signature(wallet, (*response)[0].backup_owner, owner, backup_owner, result))
|
||||
{
|
||||
if (reason)
|
||||
{
|
||||
*reason = "Signature requested when preparing LNS TX, but this wallet is not the owner of the record owner=" + response[0].owner;
|
||||
if (response[0].backup_owner.size()) *reason += ", backup_owner=" + response[0].backup_owner;
|
||||
*reason = "Signature requested when preparing LNS TX, but this wallet is not the owner of the record owner=" + (*response)[0].owner;
|
||||
if ((*response)[0].backup_owner.size()) *reason += ", backup_owner=" + (*response)[0].backup_owner;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -8578,7 +8583,8 @@ std::vector<wallet2::pending_tx> wallet2::lns_create_buy_mapping_tx(lns::mapping
|
|||
uint32_t account_index,
|
||||
std::set<uint32_t> subaddr_indices)
|
||||
{
|
||||
lns_prepared_args prepared_args = prepare_tx_extra_loki_name_system_values(*this, type, priority, name, &value, owner, backup_owner, false /*make_signature*/, account_index, reason);
|
||||
std::vector<cryptonote::COMMAND_RPC_LNS_NAMES_TO_OWNERS::response_entry> response;
|
||||
lns_prepared_args prepared_args = prepare_tx_extra_loki_name_system_values(*this, type, priority, name, &value, owner, backup_owner, false /*make_signature*/, account_index, reason, &response);
|
||||
if (!owner)
|
||||
prepared_args.owner = lns::make_monero_owner(get_subaddress({account_index, 0}), account_index != 0);
|
||||
|
||||
|
@ -8641,7 +8647,8 @@ std::vector<wallet2::pending_tx> wallet2::lns_create_update_mapping_tx(lns::mapp
|
|||
std::string *reason,
|
||||
uint32_t priority,
|
||||
uint32_t account_index,
|
||||
std::set<uint32_t> subaddr_indices)
|
||||
std::set<uint32_t> subaddr_indices,
|
||||
std::vector<cryptonote::COMMAND_RPC_LNS_NAMES_TO_OWNERS::response_entry> *response)
|
||||
{
|
||||
if (!value && !owner && !backup_owner)
|
||||
{
|
||||
|
@ -8650,7 +8657,7 @@ std::vector<wallet2::pending_tx> wallet2::lns_create_update_mapping_tx(lns::mapp
|
|||
}
|
||||
|
||||
bool make_signature = signature == nullptr;
|
||||
lns_prepared_args prepared_args = prepare_tx_extra_loki_name_system_values(*this, type, priority, name, value, owner, backup_owner, make_signature, account_index, reason);
|
||||
lns_prepared_args prepared_args = prepare_tx_extra_loki_name_system_values(*this, type, priority, name, value, owner, backup_owner, make_signature, account_index, reason, response);
|
||||
if (!prepared_args) return {};
|
||||
|
||||
if (!make_signature)
|
||||
|
@ -8699,13 +8706,14 @@ std::vector<wallet2::pending_tx> wallet2::lns_create_update_mapping_tx(std::stri
|
|||
std::string *reason,
|
||||
uint32_t priority,
|
||||
uint32_t account_index,
|
||||
std::set<uint32_t> subaddr_indices)
|
||||
std::set<uint32_t> subaddr_indices,
|
||||
std::vector<cryptonote::COMMAND_RPC_LNS_NAMES_TO_OWNERS::response_entry> *response)
|
||||
{
|
||||
lns::mapping_type mapping_type = lns::mapping_type::session;
|
||||
if (!lns::validate_mapping_type(type, &mapping_type, reason))
|
||||
return {};
|
||||
|
||||
std::vector<wallet2::pending_tx> result = lns_create_update_mapping_tx(mapping_type, name, value, owner, backup_owner, signature, reason, priority, account_index, subaddr_indices);
|
||||
std::vector<wallet2::pending_tx> result = lns_create_update_mapping_tx(mapping_type, name, value, owner, backup_owner, signature, reason, priority, account_index, subaddr_indices, response);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -8740,7 +8748,8 @@ bool wallet2::lns_make_update_mapping_signature(lns::mapping_type type,
|
|||
uint32_t account_index,
|
||||
std::string *reason)
|
||||
{
|
||||
lns_prepared_args prepared_args = prepare_tx_extra_loki_name_system_values(*this, type, tx_priority_unimportant, name, value, owner, backup_owner, true /*make_signature*/, account_index, reason);
|
||||
std::vector<cryptonote::COMMAND_RPC_LNS_NAMES_TO_OWNERS::response_entry> response;
|
||||
lns_prepared_args prepared_args = prepare_tx_extra_loki_name_system_values(*this, type, tx_priority_unimportant, name, value, owner, backup_owner, true /*make_signature*/, account_index, reason, &response);
|
||||
if (!prepared_args) return false;
|
||||
|
||||
if (prepared_args.prev_txid == crypto::null_hash)
|
||||
|
|
|
@ -1543,8 +1543,8 @@ private:
|
|||
|
||||
// signature: (Optional) If set, use the signature given, otherwise by default derive the signature from the wallet spend key as an ed25519 key.
|
||||
// The signature is derived from the hash of the previous txid blob and previous value blob of the mapping. By default this is signed using the wallet's spend key as an ed25519 keypair.
|
||||
std::vector<wallet2::pending_tx> lns_create_update_mapping_tx(lns::mapping_type type, std::string name, std::string const *value, std::string const *owner, std::string const *backup_owner, std::string const *signature, std::string *reason, uint32_t priority = 0, uint32_t account_index = 0, std::set<uint32_t> subaddr_indices = {});
|
||||
std::vector<wallet2::pending_tx> lns_create_update_mapping_tx(std::string const &type, std::string const &name, std::string const *value, std::string const *owner, std::string const *backup_owner, std::string const *signature, std::string *reason, uint32_t priority = 0, uint32_t account_index = 0, std::set<uint32_t> subaddr_indices = {});
|
||||
std::vector<wallet2::pending_tx> lns_create_update_mapping_tx(lns::mapping_type type, std::string name, std::string const *value, std::string const *owner, std::string const *backup_owner, std::string const *signature, std::string *reason, uint32_t priority = 0, uint32_t account_index = 0, std::set<uint32_t> subaddr_indices = {}, std::vector<cryptonote::COMMAND_RPC_LNS_NAMES_TO_OWNERS::response_entry> *response = {});
|
||||
std::vector<wallet2::pending_tx> lns_create_update_mapping_tx(std::string const &type, std::string const &name, std::string const *value, std::string const *owner, std::string const *backup_owner, std::string const *signature, std::string *reason, uint32_t priority = 0, uint32_t account_index = 0, std::set<uint32_t> subaddr_indices = {}, std::vector<cryptonote::COMMAND_RPC_LNS_NAMES_TO_OWNERS::response_entry> *response = {});
|
||||
|
||||
// Generate just the signature required for putting into lns_update_mapping command in the wallet
|
||||
bool lns_make_update_mapping_signature(lns::mapping_type type, std::string name, std::string const *value, std::string const *owner, std::string const *backup_owner, lns::generic_signature &signature, uint32_t account_index = 0, std::string *reason = nullptr);
|
||||
|
|
Loading…
Reference in a new issue