Keep commonly used functions inline
This commit is contained in:
parent
57d263df1e
commit
e246aa4e40
2 changed files with 104 additions and 154 deletions
|
|
@ -61,11 +61,6 @@ std::string nano::public_key::to_account () const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
nano::public_key::public_key () :
|
|
||||||
uint256_union{ 0 }
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nano::public_key const & nano::public_key::null ()
|
nano::public_key const & nano::public_key::null ()
|
||||||
{
|
{
|
||||||
return nano::hardened_constants::get ().not_an_account;
|
return nano::hardened_constants::get ().not_an_account;
|
||||||
|
|
@ -143,12 +138,6 @@ bool nano::public_key::decode_account (std::string const & source_a)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
nano::uint256_union::uint256_union (nano::uint256_t const & number_a)
|
|
||||||
{
|
|
||||||
bytes.fill (0);
|
|
||||||
boost::multiprecision::export_bits (number_a, bytes.rbegin (), 8, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct a uint256_union = AES_ENC_CTR (cleartext, key, iv)
|
// Construct a uint256_union = AES_ENC_CTR (cleartext, key, iv)
|
||||||
void nano::uint256_union::encrypt (nano::raw_key const & cleartext, nano::raw_key const & key, uint128_union const & iv)
|
void nano::uint256_union::encrypt (nano::raw_key const & cleartext, nano::raw_key const & key, uint128_union const & iv)
|
||||||
{
|
{
|
||||||
|
|
@ -157,11 +146,6 @@ void nano::uint256_union::encrypt (nano::raw_key const & cleartext, nano::raw_ke
|
||||||
enc.ProcessData (bytes.data (), cleartext.bytes.data (), sizeof (cleartext.bytes));
|
enc.ProcessData (bytes.data (), cleartext.bytes.data (), sizeof (cleartext.bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nano::uint256_union::is_zero () const
|
|
||||||
{
|
|
||||||
return qwords[0] == 0 && qwords[1] == 0 && qwords[2] == 0 && qwords[3] == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string nano::uint256_union::to_string () const
|
std::string nano::uint256_union::to_string () const
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
@ -193,22 +177,9 @@ nano::uint256_union nano::uint256_union::operator^ (nano::uint256_union const &
|
||||||
nano::uint256_union::uint256_union (std::string const & hex_a)
|
nano::uint256_union::uint256_union (std::string const & hex_a)
|
||||||
{
|
{
|
||||||
auto error (decode_hex (hex_a));
|
auto error (decode_hex (hex_a));
|
||||||
|
|
||||||
release_assert (!error);
|
release_assert (!error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nano::uint256_union::clear ()
|
|
||||||
{
|
|
||||||
qwords.fill (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
nano::uint256_t nano::uint256_union::number () const
|
|
||||||
{
|
|
||||||
nano::uint256_t result;
|
|
||||||
boost::multiprecision::import_bits (result, bytes.begin (), bytes.end ());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void nano::uint256_union::encode_hex (std::string & text) const
|
void nano::uint256_union::encode_hex (std::string & text) const
|
||||||
{
|
{
|
||||||
debug_assert (text.empty ());
|
debug_assert (text.empty ());
|
||||||
|
|
@ -281,41 +252,6 @@ bool nano::uint256_union::decode_dec (std::string const & text)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
nano::uint256_union::uint256_union (uint64_t value0)
|
|
||||||
{
|
|
||||||
*this = nano::uint256_t (value0);
|
|
||||||
}
|
|
||||||
|
|
||||||
nano::uint512_union::uint512_union (nano::uint256_union const & upper, nano::uint256_union const & lower)
|
|
||||||
{
|
|
||||||
uint256s[0] = upper;
|
|
||||||
uint256s[1] = lower;
|
|
||||||
}
|
|
||||||
|
|
||||||
nano::uint512_union::uint512_union (nano::uint512_t const & number_a)
|
|
||||||
{
|
|
||||||
bytes.fill (0);
|
|
||||||
boost::multiprecision::export_bits (number_a, bytes.rbegin (), 8, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool nano::uint512_union::is_zero () const
|
|
||||||
{
|
|
||||||
return qwords[0] == 0 && qwords[1] == 0 && qwords[2] == 0 && qwords[3] == 0
|
|
||||||
&& qwords[4] == 0 && qwords[5] == 0 && qwords[6] == 0 && qwords[7] == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void nano::uint512_union::clear ()
|
|
||||||
{
|
|
||||||
bytes.fill (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
nano::uint512_t nano::uint512_union::number () const
|
|
||||||
{
|
|
||||||
nano::uint512_t result;
|
|
||||||
boost::multiprecision::import_bits (result, bytes.begin (), bytes.end ());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void nano::uint512_union::encode_hex (std::string & text) const
|
void nano::uint512_union::encode_hex (std::string & text) const
|
||||||
{
|
{
|
||||||
debug_assert (text.empty ());
|
debug_assert (text.empty ());
|
||||||
|
|
@ -350,13 +286,6 @@ bool nano::uint512_union::decode_hex (std::string const & text)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
nano::uint512_union & nano::uint512_union::operator^= (nano::uint512_union const & other_a)
|
|
||||||
{
|
|
||||||
uint256s[0] ^= other_a.uint256s[0];
|
|
||||||
uint256s[1] ^= other_a.uint256s[1];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string nano::uint512_union::to_string () const
|
std::string nano::uint512_union::to_string () const
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
@ -421,28 +350,9 @@ bool nano::validate_message (nano::public_key const & public_key, nano::uint256_
|
||||||
nano::uint128_union::uint128_union (std::string const & string_a)
|
nano::uint128_union::uint128_union (std::string const & string_a)
|
||||||
{
|
{
|
||||||
auto error (decode_hex (string_a));
|
auto error (decode_hex (string_a));
|
||||||
|
|
||||||
release_assert (!error);
|
release_assert (!error);
|
||||||
}
|
}
|
||||||
|
|
||||||
nano::uint128_union::uint128_union (uint64_t value_a)
|
|
||||||
{
|
|
||||||
*this = nano::uint128_t (value_a);
|
|
||||||
}
|
|
||||||
|
|
||||||
nano::uint128_union::uint128_union (nano::uint128_t const & number_a)
|
|
||||||
{
|
|
||||||
bytes.fill (0);
|
|
||||||
boost::multiprecision::export_bits (number_a, bytes.rbegin (), 8, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
nano::uint128_t nano::uint128_union::number () const
|
|
||||||
{
|
|
||||||
nano::uint128_t result;
|
|
||||||
boost::multiprecision::import_bits (result, bytes.begin (), bytes.end ());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void nano::uint128_union::encode_hex (std::string & text) const
|
void nano::uint128_union::encode_hex (std::string & text) const
|
||||||
{
|
{
|
||||||
debug_assert (text.empty ());
|
debug_assert (text.empty ());
|
||||||
|
|
@ -717,16 +627,6 @@ std::string nano::uint128_union::format_balance (nano::uint128_t scale, int prec
|
||||||
return ::format_balance (number (), scale, precision, group_digits, thousands_sep, decimal_point, grouping);
|
return ::format_balance (number (), scale, precision, group_digits, thousands_sep, decimal_point, grouping);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nano::uint128_union::clear ()
|
|
||||||
{
|
|
||||||
qwords.fill (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool nano::uint128_union::is_zero () const
|
|
||||||
{
|
|
||||||
return qwords[0] == 0 && qwords[1] == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string nano::uint128_union::to_string () const
|
std::string nano::uint128_union::to_string () const
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
@ -741,31 +641,6 @@ std::string nano::uint128_union::to_string_dec () const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
nano::hash_or_account::hash_or_account () :
|
|
||||||
account{}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nano::hash_or_account::hash_or_account (uint64_t value_a) :
|
|
||||||
raw{ value_a }
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nano::hash_or_account::hash_or_account (uint256_union const & value_a) :
|
|
||||||
raw{ value_a }
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool nano::hash_or_account::is_zero () const
|
|
||||||
{
|
|
||||||
return raw.is_zero ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void nano::hash_or_account::clear ()
|
|
||||||
{
|
|
||||||
raw.clear ();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool nano::hash_or_account::decode_hex (std::string const & text_a)
|
bool nano::hash_or_account::decode_hex (std::string const & text_a)
|
||||||
{
|
{
|
||||||
return raw.decode_hex (text_a);
|
return raw.decode_hex (text_a);
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,13 @@ class uint128_union
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint128_union () = default;
|
uint128_union () = default;
|
||||||
uint128_union (uint64_t);
|
uint128_union (uint64_t value) :
|
||||||
uint128_union (nano::uint128_t const &);
|
uint128_union (nano::uint128_t{ value }){};
|
||||||
|
uint128_union (nano::uint128_t const & value)
|
||||||
|
{
|
||||||
|
bytes.fill (0);
|
||||||
|
boost::multiprecision::export_bits (value, bytes.rbegin (), 8, false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode from hex string
|
* Decode from hex string
|
||||||
|
|
@ -42,9 +47,21 @@ public:
|
||||||
std::string format_balance (nano::uint128_t scale, int precision, bool group_digits) const;
|
std::string format_balance (nano::uint128_t scale, int precision, bool group_digits) const;
|
||||||
std::string format_balance (nano::uint128_t scale, int precision, bool group_digits, std::locale const & locale) const;
|
std::string format_balance (nano::uint128_t scale, int precision, bool group_digits, std::locale const & locale) const;
|
||||||
|
|
||||||
nano::uint128_t number () const;
|
void clear ()
|
||||||
void clear ();
|
{
|
||||||
bool is_zero () const;
|
qwords.fill (0);
|
||||||
|
}
|
||||||
|
bool is_zero () const
|
||||||
|
{
|
||||||
|
return qwords[0] == 0 && qwords[1] == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
nano::uint128_t number () const
|
||||||
|
{
|
||||||
|
nano::uint128_t result;
|
||||||
|
boost::multiprecision::import_bits (result, bytes.begin (), bytes.end ());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::string to_string () const;
|
std::string to_string () const;
|
||||||
std::string to_string_dec () const;
|
std::string to_string_dec () const;
|
||||||
|
|
@ -100,8 +117,13 @@ class uint256_union
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint256_union () = default;
|
uint256_union () = default;
|
||||||
uint256_union (uint64_t);
|
uint256_union (uint64_t value) :
|
||||||
uint256_union (uint256_t const &);
|
uint256_union (nano::uint256_t{ value }){};
|
||||||
|
uint256_union (uint256_t const & value)
|
||||||
|
{
|
||||||
|
bytes.fill (0);
|
||||||
|
boost::multiprecision::export_bits (value, bytes.rbegin (), 8, false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode from hex string
|
* Decode from hex string
|
||||||
|
|
@ -119,9 +141,21 @@ public:
|
||||||
void encode_dec (std::string &) const;
|
void encode_dec (std::string &) const;
|
||||||
bool decode_dec (std::string const &);
|
bool decode_dec (std::string const &);
|
||||||
|
|
||||||
nano::uint256_t number () const;
|
void clear ()
|
||||||
void clear ();
|
{
|
||||||
bool is_zero () const;
|
qwords.fill (0);
|
||||||
|
}
|
||||||
|
bool is_zero () const
|
||||||
|
{
|
||||||
|
return owords[0].is_zero () && owords[1].is_zero ();
|
||||||
|
}
|
||||||
|
|
||||||
|
nano::uint256_t number () const
|
||||||
|
{
|
||||||
|
nano::uint256_t result;
|
||||||
|
boost::multiprecision::import_bits (result, bytes.begin (), bytes.end ());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::string to_string () const;
|
std::string to_string () const;
|
||||||
|
|
||||||
|
|
@ -197,19 +231,17 @@ class public_key final : public uint256_union
|
||||||
public:
|
public:
|
||||||
using uint256_union::uint256_union;
|
using uint256_union::uint256_union;
|
||||||
|
|
||||||
public_key ();
|
public_key () :
|
||||||
|
uint256_union{ 0 } {};
|
||||||
|
|
||||||
static const public_key & null ();
|
static const public_key & null ();
|
||||||
|
|
||||||
std::string to_node_id () const;
|
bool decode_node_id (std::string const &);
|
||||||
bool decode_node_id (std::string const & source_a);
|
|
||||||
void encode_account (std::string &) const;
|
void encode_account (std::string &) const;
|
||||||
std::string to_account () const;
|
|
||||||
bool decode_account (std::string const &);
|
bool decode_account (std::string const &);
|
||||||
|
|
||||||
operator nano::link const & () const;
|
std::string to_node_id () const;
|
||||||
operator nano::root const & () const;
|
std::string to_account () const;
|
||||||
operator nano::hash_or_account const & () const;
|
|
||||||
|
|
||||||
public: // Keep operators inlined
|
public: // Keep operators inlined
|
||||||
auto operator<=> (nano::public_key const & other) const
|
auto operator<=> (nano::public_key const & other) const
|
||||||
|
|
@ -228,6 +260,18 @@ public: // Keep operators inlined
|
||||||
{
|
{
|
||||||
return number ();
|
return number ();
|
||||||
}
|
}
|
||||||
|
operator nano::link () const
|
||||||
|
{
|
||||||
|
return nano::link{ *this };
|
||||||
|
}
|
||||||
|
operator nano::root () const
|
||||||
|
{
|
||||||
|
return nano::root{ *this };
|
||||||
|
}
|
||||||
|
operator nano::hash_or_account () const
|
||||||
|
{
|
||||||
|
return nano::hash_or_account{ *this };
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class wallet_id : public uint256_union
|
class wallet_id : public uint256_union
|
||||||
|
|
@ -241,16 +285,26 @@ using account = public_key;
|
||||||
class hash_or_account
|
class hash_or_account
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
hash_or_account ();
|
hash_or_account () :
|
||||||
hash_or_account (uint64_t);
|
account{} {};
|
||||||
explicit hash_or_account (uint256_union const &);
|
hash_or_account (uint64_t value) :
|
||||||
|
raw{ value } {};
|
||||||
|
explicit hash_or_account (uint256_union const & value) :
|
||||||
|
raw{ value } {};
|
||||||
|
|
||||||
bool is_zero () const;
|
void clear ()
|
||||||
void clear ();
|
{
|
||||||
|
raw.clear ();
|
||||||
|
}
|
||||||
|
bool is_zero () const
|
||||||
|
{
|
||||||
|
return raw.is_zero ();
|
||||||
|
}
|
||||||
|
|
||||||
std::string to_string () const;
|
|
||||||
bool decode_hex (std::string const &);
|
bool decode_hex (std::string const &);
|
||||||
bool decode_account (std::string const &);
|
bool decode_account (std::string const &);
|
||||||
|
|
||||||
|
std::string to_string () const;
|
||||||
std::string to_account () const;
|
std::string to_account () const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -345,18 +399,39 @@ class uint512_union
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint512_union () = default;
|
uint512_union () = default;
|
||||||
uint512_union (nano::uint256_union const &, nano::uint256_union const &);
|
uint512_union (nano::uint256_union const & upper, nano::uint256_union const & lower) :
|
||||||
uint512_union (nano::uint512_t const &);
|
uint256s{ upper, lower } {};
|
||||||
|
uint512_union (nano::uint512_t const & value)
|
||||||
|
{
|
||||||
|
bytes.fill (0);
|
||||||
|
boost::multiprecision::export_bits (value, bytes.rbegin (), 8, false);
|
||||||
|
}
|
||||||
|
|
||||||
nano::uint512_union & operator^= (nano::uint512_union const &);
|
nano::uint512_union & operator^= (nano::uint512_union const & other)
|
||||||
|
{
|
||||||
|
uint256s[0] ^= other.uint256s[0];
|
||||||
|
uint256s[1] ^= other.uint256s[1];
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void encode_hex (std::string &) const;
|
void encode_hex (std::string &) const;
|
||||||
bool decode_hex (std::string const &);
|
bool decode_hex (std::string const &);
|
||||||
|
|
||||||
void clear ();
|
void clear ()
|
||||||
bool is_zero () const;
|
{
|
||||||
|
bytes.fill (0);
|
||||||
|
}
|
||||||
|
bool is_zero () const
|
||||||
|
{
|
||||||
|
return uint256s[0].is_zero () && uint256s[1].is_zero ();
|
||||||
|
}
|
||||||
|
|
||||||
nano::uint512_t number () const;
|
nano::uint512_t number () const
|
||||||
|
{
|
||||||
|
nano::uint512_t result;
|
||||||
|
boost::multiprecision::import_bits (result, bytes.begin (), bytes.end ());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::string to_string () const;
|
std::string to_string () const;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue