Wallet: added subaddress detection

This commit is contained in:
SChernykh
2025-09-21 15:50:08 +02:00
parent 0d101f0ae6
commit a4e1f00993
5 changed files with 52 additions and 24 deletions

View File

@@ -314,6 +314,11 @@ bool Params::valid() const
return false;
}
if (m_wallet.is_subaddress()) {
LOGERR(1, "Wallet address must be a main address (starting with 4...). Try \"p2pool --help\".");
return false;
}
if (m_mergeMiningHosts.size() > 10) {
LOGERR(1, "Too many merge mining blockchains.");
return false;

View File

@@ -284,7 +284,7 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, const SideChain& si
hash view_pub_key;
READ_BUF(spend_pub_key.h, HASH_SIZE);
READ_BUF(view_pub_key.h, HASH_SIZE);
if (!m_minerWallet.assign(spend_pub_key, view_pub_key, sidechain.network_type())) {
if (!m_minerWallet.assign(spend_pub_key, view_pub_key, sidechain.network_type(), false)) {
return __LINE__;
}

View File

@@ -33,6 +33,8 @@ namespace {
// Values taken from cryptonote_config.h (CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX)
constexpr uint64_t valid_prefixes[] = { 18, 53, 24 };
constexpr uint64_t valid_prefixes_subaddress[] = { 42, 63, 36 };
constexpr std::array<int, 9> block_sizes{ 0, 2, 3, 5, 6, 7, 9, 10, 11 };
constexpr int num_full_blocks = p2pool::Wallet::ADDRESS_LENGTH / block_sizes.back();
constexpr int last_block_size = p2pool::Wallet::ADDRESS_LENGTH % block_sizes.back();
@@ -77,7 +79,7 @@ static_assert(rev_alphabet.num_symbols == 58, "Check alphabet");
namespace p2pool {
Wallet::Wallet(const char* address) : m_prefix(0), m_checksum(0), m_type(NetworkType::Invalid)
Wallet::Wallet(const char* address) : m_prefix(0), m_checksum(0), m_type(NetworkType::Invalid), m_subaddress(false)
{
decode(address);
}
@@ -98,6 +100,7 @@ Wallet& Wallet::operator=(const Wallet& w)
m_viewPublicKey = w.m_viewPublicKey;
m_checksum = w.m_checksum;
m_type = w.m_type;
m_subaddress = w.m_subaddress;
return *this;
}
@@ -152,6 +155,10 @@ bool Wallet::decode(const char* address)
case valid_prefixes[1]: m_type = NetworkType::Testnet; break;
case valid_prefixes[2]: m_type = NetworkType::Stagenet; break;
case valid_prefixes_subaddress[0]: m_type = NetworkType::Mainnet; m_subaddress = true; break;
case valid_prefixes_subaddress[1]: m_type = NetworkType::Testnet; m_subaddress = true; break;
case valid_prefixes_subaddress[2]: m_type = NetworkType::Stagenet; m_subaddress = true; break;
default:
return false;
}
@@ -175,7 +182,7 @@ bool Wallet::decode(const char* address)
return valid();
}
bool Wallet::assign(const hash& spend_pub_key, const hash& view_pub_key, NetworkType type)
bool Wallet::assign(const hash& spend_pub_key, const hash& view_pub_key, NetworkType type, bool subaddress)
{
ge_p3 point;
if ((ge_frombytes_vartime(&point, spend_pub_key.h) != 0) || (ge_frombytes_vartime(&point, view_pub_key.h) != 0)) {
@@ -184,9 +191,9 @@ bool Wallet::assign(const hash& spend_pub_key, const hash& view_pub_key, Network
switch (type)
{
case NetworkType::Mainnet: m_prefix = valid_prefixes[0]; break;
case NetworkType::Testnet: m_prefix = valid_prefixes[1]; break;
case NetworkType::Stagenet: m_prefix = valid_prefixes[2]; break;
case NetworkType::Mainnet: m_prefix = subaddress ? valid_prefixes_subaddress[0] : valid_prefixes[0]; break;
case NetworkType::Testnet: m_prefix = subaddress ? valid_prefixes_subaddress[1] : valid_prefixes[1]; break;
case NetworkType::Stagenet: m_prefix = subaddress ? valid_prefixes_subaddress[2] : valid_prefixes[2]; break;
default: m_prefix = 0; break;
}
@@ -204,6 +211,7 @@ bool Wallet::assign(const hash& spend_pub_key, const hash& view_pub_key, Network
memcpy(&m_checksum, md, sizeof(m_checksum));
m_type = type;
m_subaddress = subaddress;
return true;
}

View File

@@ -37,7 +37,7 @@ public:
FORCEINLINE bool valid() const { return m_type != NetworkType::Invalid; }
bool decode(const char* address);
bool assign(const hash& spend_pub_key, const hash& view_pub_key, NetworkType type);
bool assign(const hash& spend_pub_key, const hash& view_pub_key, NetworkType type, bool subaddress);
void encode(char (&buf)[ADDRESS_LENGTH]) const;
@@ -58,6 +58,7 @@ public:
FORCEINLINE const hash& view_public_key() const { return m_viewPublicKey; }
FORCEINLINE uint32_t checksum() const { return m_checksum; }
FORCEINLINE NetworkType type() const { return m_type; }
FORCEINLINE bool is_subaddress() const { return m_subaddress; }
private:
uint64_t m_prefix;
@@ -65,6 +66,7 @@ private:
hash m_viewPublicKey;
uint32_t m_checksum;
NetworkType m_type;
bool m_subaddress;
};
} // namespace p2pool