Skip to content

Commit

Permalink
Merge pull request #143 from victor-tucci/dev
Browse files Browse the repository at this point in the history
paymentid fix in resolve_address()
  • Loading branch information
sanada08 committed Mar 15, 2024
2 parents 27fcc4c + a241be0 commit 7135892
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3546,6 +3546,52 @@ namespace cryptonote { namespace rpc {
res.status = STATUS_OK;
return res;
}

//------------------------------------------------------------------------------------------------------------------------------
BNS_LOOKUP::response core_rpc_server::invoke(BNS_LOOKUP::request&& req, rpc_context context)
{
BNS_LOOKUP::response res{};

std::string name = tools::lowercase_ascii_string(std::move(req.name));

BNS_NAMES_TO_OWNERS::request name_to_owner_req{};
name_to_owner_req.entries.push_back(bns::name_to_base64_hash(name));
auto name_to_owner_res = invoke(std::move(name_to_owner_req), context);

if(name_to_owner_res.entries.size() != 1){
throw rpc_error{ERROR_INVALID_RESULT, "Invalid data returned from BNS_NAMES_TO_OWNERS"};
}

auto entries = name_to_owner_res.entries.back();
{
res.name_hash = entries.name_hash;
res.owner = entries.owner;
if (entries.backup_owner) res.backup_owner = entries.backup_owner;
res.expiration_height = entries.expiration_height;
res.update_height = entries.update_height;
res.txid = entries.txid;

if(!entries.encrypted_bchat_value.empty()){
BNS_VALUE_DECRYPT::request bns_value_decrypt_req{name, "bchat", entries.encrypted_bchat_value};
auto bns_value_decrypt_res = invoke(std::move(bns_value_decrypt_req), context);
res.bchat_value = bns_value_decrypt_res.value;
}
if(!entries.encrypted_belnet_value.empty()){
BNS_VALUE_DECRYPT::request bns_value_decrypt_req{name, "belnet", entries.encrypted_belnet_value};
auto bns_value_decrypt_res = invoke(std::move(bns_value_decrypt_req), context);
res.belnet_value = bns_value_decrypt_res.value;
}
if(!entries.encrypted_wallet_value.empty()){
BNS_VALUE_DECRYPT::request bns_value_decrypt_req{name, "wallet", entries.encrypted_wallet_value};
auto bns_value_decrypt_res = invoke(std::move(bns_value_decrypt_req), context);
res.wallet_value = bns_value_decrypt_res.value;
}
}

res.status = STATUS_OK;
return res;
}

//------------------------------------------------------------------------------------------------------------------------------
BNS_OWNERS_TO_NAMES::response core_rpc_server::invoke(BNS_OWNERS_TO_NAMES::request&& req, rpc_context context)
{
Expand Down
1 change: 1 addition & 0 deletions src/rpc/core_rpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ namespace cryptonote::rpc {
TEST_TRIGGER_P2P_RESYNC::response invoke(TEST_TRIGGER_P2P_RESYNC::request&& req, rpc_context context);
TEST_TRIGGER_UPTIME_PROOF::response invoke(TEST_TRIGGER_UPTIME_PROOF::request&& req, rpc_context context);
BNS_NAMES_TO_OWNERS::response invoke(BNS_NAMES_TO_OWNERS::request&& req, rpc_context context);
BNS_LOOKUP::response invoke(BNS_LOOKUP::request&& req, rpc_context context);
BNS_OWNERS_TO_NAMES::response invoke(BNS_OWNERS_TO_NAMES::request&& req, rpc_context context);
BNS_RESOLVE::response invoke(BNS_RESOLVE::request&& req, rpc_context context);
BNS_VALUE_DECRYPT::response invoke(BNS_VALUE_DECRYPT::request&& req, rpc_context context);
Expand Down
17 changes: 17 additions & 0 deletions src/rpc/core_rpc_server_commands_defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,23 @@ KV_SERIALIZE_MAP_CODE_BEGIN(BNS_NAMES_TO_OWNERS::response)
KV_SERIALIZE(status)
KV_SERIALIZE_MAP_CODE_END()

KV_SERIALIZE_MAP_CODE_BEGIN(BNS_LOOKUP::request)
KV_SERIALIZE(name)
KV_SERIALIZE_MAP_CODE_END()

KV_SERIALIZE_MAP_CODE_BEGIN(BNS_LOOKUP::response)
KV_SERIALIZE(name_hash)
KV_SERIALIZE(owner)
KV_SERIALIZE(backup_owner)
KV_SERIALIZE(bchat_value)
KV_SERIALIZE(wallet_value)
KV_SERIALIZE(belnet_value)
KV_SERIALIZE(update_height)
KV_SERIALIZE(expiration_height)
KV_SERIALIZE(txid)
KV_SERIALIZE(status)
KV_SERIALIZE_MAP_CODE_END()

KV_SERIALIZE_MAP_CODE_BEGIN(BNS_OWNERS_TO_NAMES::request)
KV_SERIALIZE(entries)
KV_SERIALIZE(include_expired)
Expand Down
33 changes: 33 additions & 0 deletions src/rpc/core_rpc_server_commands_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2473,6 +2473,38 @@ namespace rpc {
};
};

BELDEX_RPC_DOC_INTROSPECT
// Get the name mapping for a Beldex Name Service entry. Beldex currently supports mappings
// for Bchat and Belnet and wallet.
struct BNS_LOOKUP : PUBLIC
{
static constexpr auto names() { return NAMES("bns_lookup"); }

static constexpr size_t MAX_REQUEST_ENTRIES = 256;
struct request
{
std::string name; // Entries to look up
KV_MAP_SERIALIZABLE
};

struct response
{
std::string name_hash; // The hash of the name that was queried, in base64
std::string owner; // The public key that purchased the Beldex Name Service entry.
std::optional<std::string> backup_owner; // The backup public key that the owner specified when purchasing the Beldex Name Service entry. Omitted if no backup owner.
std::optional<std::string> bchat_value; // The encrypted value that the name maps to. See the `BNS_RESOLVE` description for information on how this value can be decrypted.
std::optional<std::string> wallet_value; // The encrypted value that the name maps to. See the `BNS_RESOLVE` description for information on how this value can be decrypted.
std::optional<std::string> belnet_value; // The encrypted value that the name maps to. See the `BNS_RESOLVE` description for information on how this value can be decrypted.
uint64_t update_height; // The last height that this Beldex Name Service entry was updated on the Blockchain.
std::optional<uint64_t> expiration_height;// For records that expire, this will be set to the expiration block height.
std::string txid; // The txid of the mapping's most recent update or purchase.

std::string status; // Generic RPC error code. "OK" is the success value.

KV_MAP_SERIALIZABLE
};
};

BELDEX_RPC_DOC_INTROSPECT
// Get all the name mappings for the queried owner. The owner can be either a ed25519 public key or Monero style
// public key; by default purchases are owned by the spend public key of the purchasing wallet.
Expand Down Expand Up @@ -2676,6 +2708,7 @@ namespace rpc {
TEST_TRIGGER_P2P_RESYNC,
TEST_TRIGGER_UPTIME_PROOF,
BNS_NAMES_TO_OWNERS,
BNS_LOOKUP,
BNS_OWNERS_TO_NAMES,
BNS_RESOLVE,
BNS_VALUE_DECRYPT,
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/core_rpc_server_error_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ constexpr int16_t
ERROR_UNSUPPORTED_RPC = -11,
ERROR_MINING_TO_SUBADDRESS = -12,
ERROR_REGTEST_REQUIRED = -13,
ERROR_INVALID_VALUE_LENGTH = -14;
ERROR_INVALID_VALUE_LENGTH = -14,
ERROR_INVALID_RESULT = -15;

}}
1 change: 1 addition & 0 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6483,6 +6483,7 @@ std::optional<std::string> wallet2::resolve_address(std::string address, uint64_
if (cryptonote::get_account_address_from_str(info, m_nettype, address))
{
result = true;
return address;
} else {
std::string name = tools::lowercase_ascii_string(std::move(address));
std::string reason;
Expand Down

0 comments on commit 7135892

Please sign in to comment.