ixc_message_api/account_id.rs
1/// Account ID is a unique integer identifier for an account.
2/// Every account has one and only one account identifier.
3/// This is distinct from an account's "address".
4/// An account may actually have multiple addresses in
5/// different "address spaces" from the point of view of
6/// an external user, but an account always has one unique account ID.
7/// The account ID zero is reserved for the "null account" meaning
8/// that the account is not valid or does not exist.
9#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
10pub struct AccountID(u64);
11
12impl AccountID {
13 /// The empty account ID.
14 pub const EMPTY: AccountID = AccountID(0);
15
16 /// Creates a new account ID from the given integer.
17 pub const fn new(id: u64) -> Self {
18 AccountID(id)
19 }
20
21 /// Returns true if the account ID is zero.
22 /// The account ID zero is reserved for the "null account" meaning
23 /// that the account is not valid or does not exist.
24 pub fn is_empty(&self) -> bool {
25 self.0 == 0
26 }
27}
28
29impl Into<u64> for AccountID {
30 fn into(self) -> u64 {
31 self.0
32 }
33}
34
35impl From<u64> for AccountID {
36 fn from(value: u64) -> Self {
37 AccountID(value)
38 }
39}