mirror of
https://github.com/monero-project/monero.git
synced 2026-07-28 22:51:07 -07:00
cryptonote_basic: remove legacy address parser
This commit is contained in:
@@ -127,26 +127,6 @@ namespace cryptonote {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
uint8_t get_account_address_checksum(const public_address_outer_blob& bl)
|
|
||||||
{
|
|
||||||
const unsigned char* pbuf = reinterpret_cast<const unsigned char*>(&bl);
|
|
||||||
uint8_t summ = 0;
|
|
||||||
for(size_t i = 0; i!= sizeof(public_address_outer_blob)-1; i++)
|
|
||||||
summ += pbuf[i];
|
|
||||||
|
|
||||||
return summ;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------------
|
|
||||||
uint8_t get_account_integrated_address_checksum(const public_integrated_address_outer_blob& bl)
|
|
||||||
{
|
|
||||||
const unsigned char* pbuf = reinterpret_cast<const unsigned char*>(&bl);
|
|
||||||
uint8_t summ = 0;
|
|
||||||
for(size_t i = 0; i!= sizeof(public_integrated_address_outer_blob)-1; i++)
|
|
||||||
summ += pbuf[i];
|
|
||||||
|
|
||||||
return summ;
|
|
||||||
}
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
std::string get_account_address_as_str(
|
std::string get_account_address_as_str(
|
||||||
network_type nettype
|
network_type nettype
|
||||||
, bool subaddress
|
, bool subaddress
|
||||||
@@ -193,96 +173,60 @@ namespace cryptonote {
|
|||||||
uint64_t integrated_address_prefix = get_config(nettype).CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX;
|
uint64_t integrated_address_prefix = get_config(nettype).CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX;
|
||||||
uint64_t subaddress_prefix = get_config(nettype).CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX;
|
uint64_t subaddress_prefix = get_config(nettype).CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX;
|
||||||
|
|
||||||
if (2 * sizeof(public_address_outer_blob) != str.size())
|
blobdata data;
|
||||||
|
uint64_t prefix;
|
||||||
|
if (!tools::base58::decode_addr(str, prefix, data))
|
||||||
{
|
{
|
||||||
blobdata data;
|
LOG_PRINT_L2("Invalid address format");
|
||||||
uint64_t prefix;
|
return false;
|
||||||
if (!tools::base58::decode_addr(str, prefix, data))
|
}
|
||||||
|
|
||||||
|
if (integrated_address_prefix == prefix)
|
||||||
|
{
|
||||||
|
info.is_subaddress = false;
|
||||||
|
info.has_payment_id = true;
|
||||||
|
}
|
||||||
|
else if (address_prefix == prefix)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
<< " or " << subaddress_prefix);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info.has_payment_id)
|
||||||
|
{
|
||||||
|
integrated_address iadr;
|
||||||
|
if (!::serialization::parse_binary(data, iadr))
|
||||||
{
|
{
|
||||||
LOG_PRINT_L2("Invalid address format");
|
LOG_PRINT_L1("Account public address keys can't be parsed");
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (integrated_address_prefix == prefix)
|
|
||||||
{
|
|
||||||
info.is_subaddress = false;
|
|
||||||
info.has_payment_id = true;
|
|
||||||
}
|
|
||||||
else if (address_prefix == prefix)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
<< " or " << subaddress_prefix);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (info.has_payment_id)
|
|
||||||
{
|
|
||||||
integrated_address iadr;
|
|
||||||
if (!::serialization::parse_binary(data, iadr))
|
|
||||||
{
|
|
||||||
LOG_PRINT_L1("Account public address keys can't be parsed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
info.address = iadr.adr;
|
|
||||||
info.payment_id = iadr.payment_id;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!::serialization::parse_binary(data, info.address))
|
|
||||||
{
|
|
||||||
LOG_PRINT_L1("Account public address keys can't be parsed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
info.address = iadr.adr;
|
||||||
|
info.payment_id = iadr.payment_id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Old address format
|
if (!::serialization::parse_binary(data, info.address))
|
||||||
std::string buff;
|
|
||||||
if(!string_tools::parse_hexstr_to_binbuff(str, buff))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(buff.size()!=sizeof(public_address_outer_blob))
|
|
||||||
{
|
{
|
||||||
LOG_PRINT_L1("Wrong public address size: " << buff.size() << ", expected size: " << sizeof(public_address_outer_blob));
|
LOG_PRINT_L1("Account public address keys can't be parsed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public_address_outer_blob blob = *reinterpret_cast<const public_address_outer_blob*>(buff.data());
|
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");
|
||||||
if(blob.m_ver > CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER)
|
return false;
|
||||||
{
|
|
||||||
LOG_PRINT_L1("Unknown version of public address: " << blob.m_ver << ", expected " << CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(blob.check_sum != get_account_address_checksum(blob))
|
|
||||||
{
|
|
||||||
LOG_PRINT_L1("Wrong public address checksum");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//we success
|
|
||||||
info.address = blob.m_address;
|
|
||||||
info.is_subaddress = false;
|
|
||||||
info.has_payment_id = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -40,22 +40,6 @@ namespace cryptonote {
|
|||||||
/* */
|
/* */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
struct public_address_outer_blob
|
|
||||||
{
|
|
||||||
uint8_t m_ver;
|
|
||||||
account_public_address m_address;
|
|
||||||
uint8_t check_sum;
|
|
||||||
};
|
|
||||||
struct public_integrated_address_outer_blob
|
|
||||||
{
|
|
||||||
uint8_t m_ver;
|
|
||||||
account_public_address m_address;
|
|
||||||
crypto::hash8 payment_id;
|
|
||||||
uint8_t check_sum;
|
|
||||||
};
|
|
||||||
#pragma pack (pop)
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
inline std::string return_first_address(const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid)
|
inline std::string return_first_address(const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid)
|
||||||
@@ -80,8 +64,6 @@ namespace cryptonote {
|
|||||||
size_t get_min_block_weight(uint8_t version);
|
size_t get_min_block_weight(uint8_t version);
|
||||||
size_t get_max_tx_size();
|
size_t get_max_tx_size();
|
||||||
bool get_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version);
|
bool get_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version);
|
||||||
uint8_t get_account_address_checksum(const public_address_outer_blob& bl);
|
|
||||||
uint8_t get_account_integrated_address_checksum(const public_integrated_address_outer_blob& bl);
|
|
||||||
|
|
||||||
std::string get_account_address_as_str(
|
std::string get_account_address_as_str(
|
||||||
network_type nettype
|
network_type nettype
|
||||||
@@ -150,4 +132,3 @@ namespace cryptonote {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool parse_hash256(const std::string &str_hash, crypto::hash& hash);
|
bool parse_hash256(const std::string &str_hash, crypto::hash& hash);
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,6 @@
|
|||||||
#define CRYPTONOTE_MAX_BLOCK_NUMBER 500000000
|
#define CRYPTONOTE_MAX_BLOCK_NUMBER 500000000
|
||||||
#define CRYPTONOTE_MAX_TX_SIZE 1000000
|
#define CRYPTONOTE_MAX_TX_SIZE 1000000
|
||||||
#define CRYPTONOTE_MAX_TX_PER_BLOCK 0x10000000
|
#define CRYPTONOTE_MAX_TX_PER_BLOCK 0x10000000
|
||||||
#define CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER 0
|
|
||||||
#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW 60
|
#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW 60
|
||||||
#define CURRENT_TRANSACTION_VERSION 2
|
#define CURRENT_TRANSACTION_VERSION 2
|
||||||
#define CURRENT_BLOCK_MAJOR_VERSION 1
|
#define CURRENT_BLOCK_MAJOR_VERSION 1
|
||||||
|
|||||||
@@ -532,9 +532,3 @@ TEST(get_account_address_from_str, fails_on_invalid_address_view_key)
|
|||||||
cryptonote::address_parse_info info;
|
cryptonote::address_parse_info info;
|
||||||
ASSERT_FALSE(cryptonote::get_account_address_from_str(info, cryptonote::MAINNET, addr_str));
|
ASSERT_FALSE(cryptonote::get_account_address_from_str(info, cryptonote::MAINNET, addr_str));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(get_account_address_from_str, parses_old_address_format)
|
|
||||||
{
|
|
||||||
cryptonote::address_parse_info info;
|
|
||||||
ASSERT_TRUE(cryptonote::get_account_address_from_str(info, cryptonote::MAINNET, "002391bbbb24dea6fd95232e97594a27769d0153d053d2102b789c498f57a2b00b69cd6f2f5c529c1660f2f4a2b50178d6640c20ce71fe26373041af97c5b10236fc"));
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user