-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
146 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,159 @@ | ||
use crate::prelude::*; | ||
use radix_engine_common::types::EntityType as ScryptoEntityType; | ||
|
||
/// Type of a wallet Radix Entity - Account or Identity (used by Personas). | ||
/// | ||
/// CAP26 uses this type to create separate key spaces for Accounts and Identities | ||
#[derive( | ||
Serialize, | ||
Deserialize, | ||
FromRepr, | ||
Clone, | ||
Copy, | ||
Debug, | ||
PartialEq, | ||
Eq, | ||
Hash, | ||
PartialOrd, | ||
Ord, | ||
)] | ||
#[repr(u32)] // it is u32 since used in Derivation Paths (CAP26) where each component is a u32. | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
enum AccountOrIdentityEntityTypePayload { | ||
Virtual { | ||
/// `is_legacy` will be `true` if the address was created using a `Secp256k1PublicKey` instead of `Ed25519PublicKey` | ||
is_legacy: bool, | ||
}, | ||
NonVirtual, | ||
} | ||
type AccountEntityTypePayload = AccountOrIdentityEntityTypePayload; | ||
type IdentityEntityTypePayload = AccountOrIdentityEntityTypePayload; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
enum FungibleOrNonFungibleEntityTypePayload { | ||
Fungible, | ||
NonFungible, | ||
} | ||
type ResourceEntityTypePayload = FungibleOrNonFungibleEntityTypePayload; | ||
type VaultEntityTypePayload = FungibleOrNonFungibleEntityTypePayload; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
enum ResourcePoolEntityTypePayload { | ||
SinglePool, | ||
TwoPools, | ||
MultiPool, | ||
} | ||
|
||
/// Used to allow easy implementations of different Address types, e.g. AccountAddress | ||
/// and ResourceAddress. | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
pub enum AbstractEntityType { | ||
/// The entity type used by Accounts. | ||
Account, | ||
/// The entity type used by Personas. | ||
Identity, | ||
/// Resource address | ||
Resource, | ||
/// `AccountAddress` uses this entity type | ||
Account { payload: AccountEntityTypePayload }, | ||
|
||
/// `OlympiaAccountAddress` uses this entity type. | ||
/// | ||
/// N.B. there is no corresponding `ScryptoEntityType` (radix_engine_common::types::EntityType) for this, | ||
/// since is outside of the Babylon NodeId and address space system. | ||
/// | ||
/// Also Olympia Account addresses uses bech32, not bech32m as Babylon uses. | ||
OlympiaAccount, | ||
|
||
/// `IdentityAddress` uses this entity type | ||
Identity { payload: IdentityEntityTypePayload }, | ||
|
||
/// `ResourceAddress` uses this entity type | ||
Resource { payload: ResourceEntityTypePayload }, | ||
|
||
/// `PackageAddress` uses this entity type | ||
Package, | ||
|
||
/// `ComponentAddress` uses this entity type | ||
Component, | ||
|
||
/// `AccessControllerAddress` uses this entity type | ||
AccessController, | ||
|
||
/// `ValidatorAddress` uses this entity type | ||
Validator, | ||
|
||
/// `VaultAddress` uses this entity type | ||
Vault { payload: VaultEntityTypePayload }, | ||
|
||
/// `ResourcePoolAddress` uses this entity type | ||
ResourcePool { | ||
payload: ResourcePoolEntityTypePayload, | ||
}, | ||
} | ||
impl AbstractEntityType { | ||
/// Conversion of the Radix Engines type for EntityType to Self. | ||
pub fn try_from(value: ScryptoEntityType) -> Result<Self> { | ||
pub fn try_from( | ||
value: ScryptoEntityType, | ||
) -> Result<AbstractEntityType, CommonError> { | ||
match value { | ||
ScryptoEntityType::GlobalVirtualEd25519Account => Ok(Self::Account), | ||
ScryptoEntityType::GlobalVirtualEd25519Account => { | ||
Ok(Self::Account { | ||
payload: AccountEntityTypePayload::Virtual { | ||
is_legacy: false, | ||
}, | ||
}) | ||
} | ||
ScryptoEntityType::GlobalAccount => Ok(Self::Account { | ||
payload: AccountEntityTypePayload::NonVirtual, | ||
}), | ||
ScryptoEntityType::GlobalVirtualSecp256k1Account => { | ||
Ok(Self::Account) | ||
Ok(Self::Account { | ||
payload: AccountEntityTypePayload::Virtual { | ||
is_legacy: true, | ||
}, | ||
}) | ||
} | ||
ScryptoEntityType::GlobalVirtualEd25519Identity => { | ||
Ok(Self::Identity) | ||
Ok(Self::Identity { | ||
payload: IdentityEntityTypePayload::Virtual { | ||
is_legacy: false, | ||
}, | ||
}) | ||
} | ||
ScryptoEntityType::GlobalIdentity => Ok(Self::Identity { | ||
payload: IdentityEntityTypePayload::NonVirtual, | ||
}), | ||
ScryptoEntityType::GlobalVirtualSecp256k1Identity => { | ||
error!("Identity created by Secp256k1 PublicKey found, this is a serious error."); | ||
Ok(Self::Identity { | ||
payload: IdentityEntityTypePayload::Virtual { | ||
is_legacy: true, | ||
}, | ||
}) | ||
} | ||
ScryptoEntityType::GlobalFungibleResourceManager => { | ||
Ok(Self::Resource) | ||
Ok(Self::Resource { | ||
payload: FungibleOrNonFungibleEntityTypePayload::Fungible, | ||
}) | ||
} | ||
ScryptoEntityType::GlobalNonFungibleResourceManager => { | ||
Ok(Self::Resource { | ||
payload: | ||
FungibleOrNonFungibleEntityTypePayload::NonFungible, | ||
}) | ||
} | ||
ScryptoEntityType::GlobalPackage => Ok(Self::Package), | ||
ScryptoEntityType::GlobalValidator => Ok(Self::Validator), | ||
ScryptoEntityType::GlobalOneResourcePool => { | ||
Ok(Self::ResourcePool { | ||
payload: ResourcePoolEntityTypePayload::SinglePool, | ||
}) | ||
} | ||
ScryptoEntityType::GlobalTwoResourcePool => { | ||
Ok(Self::ResourcePool { | ||
payload: ResourcePoolEntityTypePayload::TwoPools, | ||
}) | ||
} | ||
ScryptoEntityType::GlobalMultiResourcePool => { | ||
Ok(Self::ResourcePool { | ||
payload: ResourcePoolEntityTypePayload::MultiPool, | ||
}) | ||
} | ||
ScryptoEntityType::GlobalAccessController => { | ||
Ok(Self::AccessController) | ||
} | ||
ScryptoEntityType::InternalNonFungibleVault => Ok(Self::Vault { | ||
payload: VaultEntityTypePayload::NonFungible, | ||
}), | ||
ScryptoEntityType::InternalFungibleVault => Ok(Self::Vault { | ||
payload: VaultEntityTypePayload::Fungible, | ||
}), | ||
ScryptoEntityType::GlobalConsensusManager | ||
| ScryptoEntityType::GlobalTransactionTracker | ||
| ScryptoEntityType::GlobalGenericComponent | ||
| ScryptoEntityType::InternalFungibleVault | ||
| ScryptoEntityType::InternalGenericComponent | ||
| ScryptoEntityType::InternalKeyValueStore => { | ||
Err(CommonError::UnsupportedEntityType) | ||
} | ||
_ => Err(CommonError::UnsupportedEntityType), | ||
} | ||
} | ||
|
||
/// Human Readable Part (HRP) used to create account and identity addresses. | ||
pub fn hrp(&self) -> String { | ||
match self { | ||
Self::Account => "account".to_string(), | ||
Self::Identity => "identity".to_string(), | ||
Self::Resource => "resource".to_string(), | ||
} | ||
} | ||
} |
Empty file.