Skip to content

Commit

Permalink
Update lib.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
crStiv authored Jan 9, 2025
1 parent 92367b0 commit 2c1ca78
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions crates/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,51 @@ pub use types::*;
Serialize,
Deserialize,
)]
/// Account data
/// Account data structure that holds public keys and signature threshold
/// for multi-signature authorization.
///
/// # Example
/// ```
/// use namada_account::{Account, AccountPublicKeysMap};
/// use namada_core::address::Address;
///
/// let public_keys_map = AccountPublicKeysMap::default();
/// let account = Account {
/// public_keys_map,
/// threshold: 1,
/// address: Address::decode("...").unwrap(),
/// };
/// ```
pub struct Account {
/// The map between indexes and public keys for an account
pub public_keys_map: AccountPublicKeysMap,
/// The account signature threshold
/// The minimum number of signatures required to authorize an action
pub threshold: u8,
/// The address corresponding to the account owner
/// The unique address corresponding to the account owner
pub address: Address,
}

impl Account {
/// Retrieve a public key from the index
/// Retrieve a public key by its index in the account's public keys map.
/// Returns None if the index is not found.
pub fn get_public_key_from_index(
&self,
index: u8,
) -> Option<common::PublicKey> {
self.public_keys_map.get_public_key_from_index(index)
}

/// Retrieve the index of a public key
/// Find the index assigned to a given public key in this account.
/// Returns None if the public key is not associated with this account.
pub fn get_index_from_public_key(
&self,
public_key: &common::PublicKey,
) -> Option<u8> {
self.public_keys_map.get_index_from_public_key(public_key)
}

/// Get all public keys of the account
/// Get a vector containing all public keys associated with this account.
/// The keys are returned in no particular order.
pub fn get_all_public_keys(&self) -> Vec<common::PublicKey> {
self.public_keys_map.pk_to_idx.keys().cloned().collect()
}
Expand Down

0 comments on commit 2c1ca78

Please sign in to comment.