mirror of
https://github.com/monero-project/monero.git
synced 2025-08-03 19:44:28 -04:00
Subaddresses
This commit is contained in:
parent
86e9de588c
commit
53ad5a0f42
66 changed files with 3224 additions and 868 deletions
|
@ -158,11 +158,13 @@ namespace cryptonote {
|
|||
//-----------------------------------------------------------------------
|
||||
std::string get_account_address_as_str(
|
||||
bool testnet
|
||||
, bool subaddress
|
||||
, account_public_address const & adr
|
||||
)
|
||||
{
|
||||
uint64_t address_prefix = testnet ?
|
||||
config::testnet::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX;
|
||||
(subaddress ? config::testnet::CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX : config::testnet::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX) :
|
||||
(subaddress ? config::CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX);
|
||||
|
||||
return tools::base58::encode_addr(address_prefix, t_serializable_object_to_blob(adr));
|
||||
}
|
||||
|
@ -173,8 +175,7 @@ namespace cryptonote {
|
|||
, crypto::hash8 const & payment_id
|
||||
)
|
||||
{
|
||||
uint64_t integrated_address_prefix = testnet ?
|
||||
config::testnet::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX;
|
||||
uint64_t integrated_address_prefix = testnet ? config::testnet::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX;
|
||||
|
||||
integrated_address iadr = {
|
||||
adr, payment_id
|
||||
|
@ -193,10 +194,8 @@ namespace cryptonote {
|
|||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
bool get_account_integrated_address_from_str(
|
||||
account_public_address& adr
|
||||
, bool& has_payment_id
|
||||
, crypto::hash8& payment_id
|
||||
bool get_account_address_from_str(
|
||||
address_parse_info& info
|
||||
, bool testnet
|
||||
, std::string const & str
|
||||
)
|
||||
|
@ -205,6 +204,8 @@ namespace cryptonote {
|
|||
config::testnet::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX;
|
||||
uint64_t integrated_address_prefix = testnet ?
|
||||
config::testnet::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX;
|
||||
uint64_t subaddress_prefix = testnet ?
|
||||
config::testnet::CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX;
|
||||
|
||||
if (2 * sizeof(public_address_outer_blob) != str.size())
|
||||
{
|
||||
|
@ -218,18 +219,27 @@ namespace cryptonote {
|
|||
|
||||
if (integrated_address_prefix == prefix)
|
||||
{
|
||||
has_payment_id = true;
|
||||
info.is_subaddress = false;
|
||||
info.has_payment_id = true;
|
||||
}
|
||||
else if (address_prefix == prefix)
|
||||
{
|
||||
has_payment_id = false;
|
||||
info.is_subaddress = false;
|
||||
info.has_payment_id = false;
|
||||
}
|
||||
else if (subaddress_prefix == prefix)
|
||||
{
|
||||
info.is_subaddress = true;
|
||||
info.has_payment_id = false;
|
||||
}
|
||||
else {
|
||||
LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << address_prefix << " or " << integrated_address_prefix);
|
||||
LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << address_prefix
|
||||
<< " or " << integrated_address_prefix
|
||||
<< " or " << subaddress_prefix);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (has_payment_id)
|
||||
if (info.has_payment_id)
|
||||
{
|
||||
integrated_address iadr;
|
||||
if (!::serialization::parse_binary(data, iadr))
|
||||
|
@ -237,19 +247,19 @@ namespace cryptonote {
|
|||
LOG_PRINT_L1("Account public address keys can't be parsed");
|
||||
return false;
|
||||
}
|
||||
adr = iadr.adr;
|
||||
payment_id = iadr.payment_id;
|
||||
info.address = iadr.adr;
|
||||
info.payment_id = iadr.payment_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!::serialization::parse_binary(data, adr))
|
||||
if (!::serialization::parse_binary(data, info.address))
|
||||
{
|
||||
LOG_PRINT_L1("Account public address keys can't be parsed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!crypto::check_key(adr.m_spend_public_key) || !crypto::check_key(adr.m_view_public_key))
|
||||
if (!crypto::check_key(info.address.m_spend_public_key) || !crypto::check_key(info.address.m_view_public_key))
|
||||
{
|
||||
LOG_PRINT_L1("Failed to validate address keys");
|
||||
return false;
|
||||
|
@ -284,51 +294,27 @@ namespace cryptonote {
|
|||
}
|
||||
|
||||
//we success
|
||||
adr = blob.m_address;
|
||||
has_payment_id = false;
|
||||
info.address = blob.m_address;
|
||||
info.is_subaddress = false;
|
||||
info.has_payment_id = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
bool get_account_address_from_str(
|
||||
account_public_address& adr
|
||||
, bool testnet
|
||||
, std::string const & str
|
||||
)
|
||||
{
|
||||
bool has_payment_id;
|
||||
crypto::hash8 payment_id;
|
||||
return get_account_integrated_address_from_str(adr, has_payment_id, payment_id, testnet, str);
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
bool get_account_address_from_str_or_url(
|
||||
cryptonote::account_public_address& address
|
||||
, bool& has_payment_id
|
||||
, crypto::hash8& payment_id
|
||||
address_parse_info& info
|
||||
, bool testnet
|
||||
, const std::string& str_or_url
|
||||
, std::function<std::string(const std::string&, const std::vector<std::string>&, bool)> dns_confirm
|
||||
)
|
||||
{
|
||||
if (get_account_integrated_address_from_str(address, has_payment_id, payment_id, testnet, str_or_url))
|
||||
if (get_account_address_from_str(info, testnet, str_or_url))
|
||||
return true;
|
||||
bool dnssec_valid;
|
||||
std::string address_str = tools::dns_utils::get_account_address_as_str_from_url(str_or_url, dnssec_valid, dns_confirm);
|
||||
return !address_str.empty() &&
|
||||
get_account_integrated_address_from_str(address, has_payment_id, payment_id, testnet, address_str);
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
bool get_account_address_from_str_or_url(
|
||||
cryptonote::account_public_address& address
|
||||
, bool testnet
|
||||
, const std::string& str_or_url
|
||||
, std::function<std::string(const std::string&, const std::vector<std::string>&, bool)> dns_confirm
|
||||
)
|
||||
{
|
||||
bool has_payment_id;
|
||||
crypto::hash8 payment_id;
|
||||
return get_account_address_from_str_or_url(address, has_payment_id, payment_id, testnet, str_or_url, dns_confirm);
|
||||
get_account_address_from_str(info, testnet, address_str);
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
bool operator ==(const cryptonote::transaction& a, const cryptonote::transaction& b) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue