Skip to content

Commit

Permalink
Nits
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Dec 21, 2023
1 parent bb4b7fc commit ddbebba
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions sdk/src/types/block/rand/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,57 @@

use crate::types::block::{
address::{
AccountAddress, Address, AddressCapabilities, AddressCapabilityFlag, AnchorAddress, Ed25519Address,
ImplicitAccountCreationAddress, MultiAddress, NftAddress, RestrictedAddress, WeightedAddress,
AccountAddress, Address, AddressCapabilities, AnchorAddress, Ed25519Address, ImplicitAccountCreationAddress,
MultiAddress, NftAddress, RestrictedAddress, WeightedAddress,
},
capabilities::CapabilityFlag,
output::{AccountId, AnchorId, NftId},
rand::{bytes::rand_bytes_array, number::rand_number},
};

/// Generates a random Ed25519 address.
/// Generates a random [`Ed25519Address`].
pub fn rand_ed25519_address() -> Ed25519Address {
Ed25519Address::new(rand_bytes_array())
}

/// Generates a random account address.
/// Generates a random [`AccountAddress`].
pub fn rand_account_address() -> AccountAddress {
AccountAddress::new(AccountId::from(rand_bytes_array()))
}

/// Generates a random NFT address.
/// Generates a random [`NftAddress`].
pub fn rand_nft_address() -> NftAddress {
NftAddress::new(NftId::from(rand_bytes_array()))
}

/// Generates a random anchor address.
/// Generates a random [`AnchorAddress`].
pub fn rand_anchor_address() -> AnchorAddress {
AnchorAddress::new(AnchorId::from(rand_bytes_array()))
}

/// Generates a random implicit address.
/// Generates a random [`ImplicitAccountCreationAddress`].
pub fn rand_implicit_address() -> ImplicitAccountCreationAddress {
ImplicitAccountCreationAddress::new(*rand_ed25519_address())
}

/// Generates a random restricted address.
pub fn rand_restricted_address() -> RestrictedAddress {
RestrictedAddress::new(rand_address())
.unwrap()
.with_allowed_capabilities(AddressCapabilities::all())
/// Generates a random [`WeightedAddress`].
pub fn rand_weighted_address() -> WeightedAddress {
WeightedAddress::new(rand_address(), 1).unwrap()
}

/// Generates a random Multi address.
/// Generates a random [`MultiAddress`].
pub fn rand_multi_address() -> MultiAddress {
MultiAddress::new([rand_weighted_address()], 1).unwrap()
}

/// Generates a random weighted address.
pub fn rand_weighted_address() -> WeightedAddress {
WeightedAddress::new(rand_address(), 1).unwrap()
/// Generates a random [`RestrictedAddress`].
pub fn rand_restricted_address() -> RestrictedAddress {
RestrictedAddress::new(rand_address())
.unwrap()
.with_allowed_capabilities(AddressCapabilities::all())
}

// TODO handle all address kinds
/// Generates a random address.
/// Generates a random [`Address`].
pub fn rand_address() -> Address {
match rand_number::<u64>() % 4 {
0 => rand_ed25519_address().into(),
Expand Down

0 comments on commit ddbebba

Please sign in to comment.