radix_common/types/
type_identifier.rs

1use crate::internal_prelude::*;
2
3define_wrapped_hash!(
4    /// Represents a particular schema under a package
5    SchemaHash
6);
7
8/*
9// NOTE: Conceptually we could have the following type, which can be used for _type identity_.
10// This isn't currently needed in the engine however, so is commented out to avoid dead code.
11```
12/// A global identifier for a type in a Radix network.
13/// A type is either well-known, or local to a node.
14/// This identifier includes the NodeId, which provides context for how to look-up the type.
15///
16/// If/when we add additional type metadata (eg translations, documentation),
17/// these will be added by the owner of the Node against the GlobalTypeAddress.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Sbor)]
19pub enum GlobalTypeAddress {
20    WellKnown(WellKnownTypeId),
21    NodeLocal(NodeId, SchemaHash, usize),
22}
23```
24*/
25
26/// An identifier for a type under a given node's schema context in the Radix network.
27///
28/// See also [`ScopedTypeId`] which captures an identifier for a type where the node
29/// is clear from context.
30///
31/// Note - this type provides scoping to a schema even for well-known types where
32/// the schema is irrelevant.
33#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Sbor)]
34pub struct FullyScopedTypeId<T: AsRef<NodeId>>(pub T, pub SchemaHash, pub LocalTypeId);
35
36impl<T: AsRef<NodeId>> FullyScopedTypeId<T> {
37    pub fn into_general(self) -> FullyScopedTypeId<NodeId> {
38        FullyScopedTypeId(*self.0.as_ref(), self.1, self.2)
39    }
40}
41
42/// An identifier for a type in the context of a schema.
43///
44/// The location of the schema store is not given in this type, and
45/// is known from context. Currently the schema store will be in the
46/// Schema partition under a node.
47///
48/// See also [`FullyScopedTypeId`] for the same type, but with the node schema
49/// location included.
50///
51/// Note - this type provides scoping to a schema even for well-known types where
52/// the schema is irrelevant.
53#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Sbor)]
54pub struct ScopedTypeId(pub SchemaHash, pub LocalTypeId);
55
56impl ScopedTypeId {
57    pub fn under_node<T: AsRef<NodeId>>(self, node: T) -> FullyScopedTypeId<T> {
58        FullyScopedTypeId(node, self.0, self.1)
59    }
60}
61
62/// A reference to the type to substitute with for the case of generics.
63#[derive(Debug, Clone, PartialEq, Eq, Hash, ManifestSbor, ScryptoSbor)]
64pub enum GenericSubstitution {
65    Local(ScopedTypeId),
66    /// Currently supports default version of blueprint only.
67    /// New variants can be added for specific version of blueprint in the future.
68    Remote(BlueprintTypeIdentifier),
69}
70
71#[derive(Debug, Clone, PartialEq, Eq, Hash, ManifestSbor, ScryptoSbor)]
72pub struct BlueprintTypeIdentifier {
73    pub package_address: PackageAddress,
74    pub blueprint_name: String,
75    pub type_name: String,
76}