Skip to content

Commit

Permalink
setBnsRecord and resolveAddress functions added in libwalletapi
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-tucci committed Feb 13, 2024
1 parent 4e375a9 commit 5ed3546
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/wallet/api/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,8 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<std:
bool error = false;
auto w = wallet();
for (size_t i = 0; i < dst_addr.size() && !error; i++) {
if(!cryptonote::get_account_address_from_str(info, m_wallet_ptr->nettype(), dst_addr[i])) {
std::optional<std::string> address = w->resolve_address(dst_addr[i]);
if(!cryptonote::get_account_address_from_str(info, m_wallet_ptr->nettype(), *address)) {
// TODO: copy-paste 'if treating as an address fails, try as url' from simplewallet.cpp:1982
setStatusError(tr("Invalid destination address"));
error = true;
Expand Down Expand Up @@ -2123,6 +2124,24 @@ PendingTransaction *WalletImpl::bnsRenewTransaction(std::string &name,std::strin
return transaction;
}

EXPORT
bool WalletImpl::setBnsRecord(const std::string &name)
{
std::string reason;
auto name_str = tools::lowercase_ascii_string(name);
if (bns::validate_bns_name(name_str, &reason))
{
std::string name_hash_str = bns::name_to_base64_hash(name);
tools::wallet2::bns_detail detail = {
name_str,
name_hash_str};
wallet()->set_bns_cache_record(detail);
return true;
}
setStatusError(tr("Invalid BNS name '" + name_str + "': " + reason));
return false;
}

EXPORT
PendingTransaction *WalletImpl::createSweepUnmixableTransaction()

Expand Down
1 change: 1 addition & 0 deletions src/wallet/api/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class WalletImpl : public Wallet
uint32_t priority=0,
uint32_t m_current_subaddress_account = 0,
std::set<uint32_t> subaddr_indices = {}) override;
bool setBnsRecord(const std::string &name) override;
PendingTransaction* createSweepUnmixableTransaction() override;
bool submitTransaction(std::string_view filename) override;
UnsignedTransaction* loadUnsignedTx(std::string_view unsigned_filename) override;
Expand Down
7 changes: 7 additions & 0 deletions src/wallet/api/wallet2_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,13 @@ struct Wallet
uint32_t m_current_subaddress_account = 0,
std::set<uint32_t> subaddr_indices = {}) = 0;

/*!
* \brief setBnsRecord - attach an name and namehash to a wallet cache attribute
* \param name - the key
* \return true if successful, false otherwise
*/
virtual bool setBnsRecord(const std::string &name) = 0;

/*!
* \brief createSweepUnmixableTransaction creates transaction with unmixable outputs.
* \return PendingTransaction object. caller is responsible to check PendingTransaction::status()
Expand Down

0 comments on commit 5ed3546

Please sign in to comment.