C++ Magic Numbers
psibase::AccountNumber
struct psibase::AccountNumber {
uint64_t value; // Number form
AccountNumber(...); // Construct the empty name
AccountNumber(...); // Construct from 64-bit value
AccountNumber(...); // Construct from string (name)
str(...); // Get string (name)
};
An account number or name.
Psibase account numbers are 64-bit values which are compressed
from strings (names). Names may be 0 to 18 characters long and
contain the characters a-z
, 0-9
, and -
(hyphen).
Non-empty names must begin with a letter.
There are some names which meet the above rules, but fail to compress down to 64 bits. These names are invalid. Likewise, there are some 64-bit integers which aren't the compressed form of valid names; these are also invalid.
The empty name ""
is value 0.
psibase::AccountNumber::AccountNumber
psibase::AccountNumber::AccountNumber();
Construct the empty name.
psibase::AccountNumber::AccountNumber
explicit psibase::AccountNumber::AccountNumber(
uint64_t value
);
Construct from 64-bit value.
This doesn't do any checking; if value
isn't valid, then
str will return a string which doesn't round-trip back to
value
.
psibase::AccountNumber::AccountNumber
explicit psibase::AccountNumber::AccountNumber(
std::string_view s
);
Construct from string (name).
This does minimal checking; if s
isn't valid, then
str will return a string which doesn't match s
.
Many, but not all, invalid names produce value 0
.
psibase::AccountNumber::str
std::string psibase::AccountNumber::str() const;
Get string (name).
psibase::MethodNumber
struct psibase::MethodNumber {
uint64_t value; // Number form
MethodNumber(...); // Construct the empty name
MethodNumber(...); // Construct from 64-bit value
MethodNumber(...); // Construct from string (name)
str(...); // Get string (name)
operator<=>(...); // Comparisons
};
A method number or name.
Psibase method numbers are 64-bit values which are compressed
from strings (names). They contain the characters a-z
, and
0-9
. Non-empty names must begin with a letter. A-Z
round-trips as a-z
. _
(underscore) is dropped.
There are some names which meet the above rules, but fail to compress down to 64 bits. These names are invalid. Likewise, there are some 64-bit integers which aren't the compressed form of valid names; these are also invalid. Some invalid names fall back to a hash (below).
There is a special case when bit 48 is set. str()
returns
a string which begins with #
followed by 16 letters. This
is an alternative hex representation which represents the
hash of a name which failed to compress. Once a name is in
this form, it will round trip with no further changes.
The empty name ""
is value 0.
psibase::MethodNumber::MethodNumber
psibase::MethodNumber::MethodNumber();
Construct the empty name.
psibase::MethodNumber::MethodNumber
explicit psibase::MethodNumber::MethodNumber(
uint64_t v
);
Construct from 64-bit value.
This doesn't do any checking; if value
isn't valid, then
str will return a string which doesn't round-trip back to
value
.
psibase::MethodNumber::MethodNumber
explicit psibase::MethodNumber::MethodNumber(
std::string_view s
);
Construct from string (name).
This does minimal checking; if s
isn't valid, then
str will return a string which doesn't match s
.
Many, but not all, invalid names produce a hashed value.
Some produce 0.
psibase::MethodNumber::str
std::string psibase::MethodNumber::str() const;
Get string (name).
psibase::MethodNumber::operator<=>
std::strong_ordering psibase::MethodNumber::operator<=>(
const MethodNumber &
) const;
Comparisons.
Compares by 64-bit value
. This does not sort by the
string (name) form.