Skip to content

Commit

Permalink
Merge 792a283 into 280b6bf
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey authored Aug 21, 2023
2 parents 280b6bf + 792a283 commit 0f3006c
Show file tree
Hide file tree
Showing 59 changed files with 2,933 additions and 1,007 deletions.
Binary file modified assets/faucet.wasm
Binary file not shown.
Binary file modified assets/flash_loan.wasm
Binary file not shown.
Binary file modified assets/genesis_helper.wasm
Binary file not shown.
Binary file modified assets/metadata.wasm
Binary file not shown.
Binary file modified assets/radiswap.wasm
Binary file not shown.
10 changes: 6 additions & 4 deletions radix-engine-common/src/data/scrypto/custom_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::internal_prelude::*;

pub type ScryptoTypeKind<L> = TypeKind<ScryptoCustomTypeKind, L>;
pub type ScryptoSchema = Schema<ScryptoCustomSchema>;
pub type VersionedScryptoSchema = VersionedSchema<ScryptoCustomSchema>;
pub type ScryptoTypeData<L> = TypeData<ScryptoCustomTypeKind, L>;

/// A schema for the values that a codec can decode / views as valid
Expand Down Expand Up @@ -202,12 +203,13 @@ impl CustomSchema for ScryptoCustomSchema {
}

pub trait HasSchemaHash {
fn generate_schema_hash(&self) -> Hash;
fn generate_schema_hash(&self) -> SchemaHash;
}

impl HasSchemaHash for Schema<ScryptoCustomSchema> {
fn generate_schema_hash(&self) -> Hash {
hash(scrypto_encode(self).unwrap())
// TODO(David) - change to hash the VersionedScryptoSchema when we use that in substates
impl HasSchemaHash for ScryptoSchema {
fn generate_schema_hash(&self) -> SchemaHash {
SchemaHash::from(hash(scrypto_encode(self).unwrap()))
}
}

Expand Down
2 changes: 2 additions & 0 deletions radix-engine-common/src/data/scrypto/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub type ScryptoDecoder<'a> = VecDecoder<'a, ScryptoCustomValueKind>;
pub type ScryptoTraverser<'a> = VecTraverser<'a, ScryptoCustomTraversal>;
pub type ScryptoValueKind = ValueKind<ScryptoCustomValueKind>;
pub type ScryptoValue = Value<ScryptoCustomValueKind, ScryptoCustomValue>;
pub type RawScryptoValue<'a> = RawValue<'a, ScryptoCustomExtension>;
pub type RawScryptoPayload<'a> = RawPayload<'a, ScryptoCustomExtension>;

// The following trait "aliases" are to be used in parameters.
//
Expand Down
11 changes: 7 additions & 4 deletions radix-engine-common/src/types/type_identifier.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use crate::crypto::Hash;
use crate::Sbor;
use sbor::LocalTypeIndex;
use crate::internal_prelude::*;

define_wrapped_hash!(
/// Represents a particular schema under a package
SchemaHash
);

/// An Identifier for a structural type. This can be treated almost
/// like a pointer as two equivalent type identifiers will map to
/// the same schema
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Sbor)]
pub struct TypeIdentifier(pub Hash, pub LocalTypeIndex);
pub struct TypeIdentifier(pub SchemaHash, pub LocalTypeIndex);

/// A reference to the type to substitute with for the case of
/// generics.
Expand Down
125 changes: 24 additions & 101 deletions radix-engine-interface/src/blueprints/package/substates.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
use crate::api::CollectionIndex;
use crate::blueprints::package::BlueprintType;
use crate::schema::*;
use crate::types::*;
use crate::*;
use radix_engine_common::crypto::Hash;
use radix_engine_interface::blueprints::resource::Vault;
use sbor::rust::fmt;
use sbor::rust::fmt::{Debug, Formatter};
use sbor::rust::prelude::*;
use crate::internal_prelude::*;

pub const PACKAGE_CODE_ID: u64 = 0u64;
pub const RESOURCE_CODE_ID: u64 = 1u64;
Expand All @@ -22,90 +14,35 @@ pub const ROLE_ASSIGNMENT_CODE_ID: u64 = 12u64;
pub const POOL_CODE_ID: u64 = 13u64;
pub const TRANSACTION_TRACKER_CODE_ID: u64 = 14u64;

pub const PACKAGE_FIELDS_PARTITION_OFFSET: PartitionOffset = PartitionOffset(0u8);

pub const PACKAGE_BLUEPRINTS_PARTITION_OFFSET: PartitionOffset = PartitionOffset(1u8);
pub const PACKAGE_BLUEPRINTS_COLLECTION_INDEX: CollectionIndex = 0u8;

pub const PACKAGE_BLUEPRINT_DEPENDENCIES_PARTITION_OFFSET: PartitionOffset = PartitionOffset(2u8);
pub const PACKAGE_BLUEPRINT_DEPENDENCIES_COLLECTION_INDEX: CollectionIndex = 1u8;

// There is no offset for the package schema collection as it is directly mapped to SCHEMAS_PARTITION
pub const PACKAGE_SCHEMAS_COLLECTION_INDEX: CollectionIndex = 2u8;

pub const PACKAGE_ROYALTY_PARTITION_OFFSET: PartitionOffset = PartitionOffset(3u8);
pub const PACKAGE_ROYALTY_COLLECTION_INDEX: CollectionIndex = 3u8;

pub const PACKAGE_AUTH_TEMPLATE_PARTITION_OFFSET: PartitionOffset = PartitionOffset(4u8);
pub const PACKAGE_AUTH_TEMPLATE_COLLECTION_INDEX: CollectionIndex = 4u8;

pub const PACKAGE_VM_TYPE_PARTITION_OFFSET: PartitionOffset = PartitionOffset(5u8);
pub const PACKAGE_VM_TYPE_COLLECTION_INDEX: CollectionIndex = 5u8;

pub const PACKAGE_ORIGINAL_CODE_PARTITION_OFFSET: PartitionOffset = PartitionOffset(6u8);
pub const PACKAGE_ORIGINAL_CODE_COLLECTION_INDEX: CollectionIndex = 6u8;

pub const PACKAGE_INSTRUMENTED_CODE_PARTITION_OFFSET: PartitionOffset = PartitionOffset(7u8);
pub const PACKAGE_INSTRUMENTED_CODE_COLLECTION_INDEX: CollectionIndex = 7u8;
define_wrapped_hash!(
/// Represents a particular instance of code under a package
CodeHash
);

#[derive(Copy, Debug, Clone, PartialEq, Eq, Sbor)]
pub enum VmType {
Native,
ScryptoV1,
}

#[derive(Debug, Clone, Sbor, PartialEq, Eq)]
pub struct PackageVmTypeSubstate {
pub vm_type: VmType,
}

#[derive(Clone, Sbor, PartialEq, Eq)]
pub struct PackageOriginalCodeSubstate {
pub code: Vec<u8>,
}

#[derive(Clone, Sbor, PartialEq, Eq)]
pub struct PackageInstrumentedCodeSubstate {
pub code: Vec<u8>,
}

impl Debug for PackageOriginalCodeSubstate {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("PackageOriginalCodeSubstate")
.field("len", &self.code.len())
.finish()
}
}

impl Debug for PackageInstrumentedCodeSubstate {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("PackageInstrumentedCodeSubstate")
.field("len", &self.code.len())
.finish()
}
}

#[derive(Debug, PartialEq, Eq, ScryptoSbor)]
pub struct PackageRoyaltyAccumulatorSubstate {
/// The vault for collecting package royalties.
pub royalty_vault: Vault,
}

impl Clone for PackageRoyaltyAccumulatorSubstate {
fn clone(&self) -> Self {
Self {
royalty_vault: Vault(self.royalty_vault.0.clone()),
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Sbor)]
pub enum BlueprintPayloadDef {
Static(TypeIdentifier), // Fully Resolved type is defined in package
Generic(u8), // Fully Resolved type is mapped directly to a generic defined by instance
// TODO: How to represent a structure containing a generic?
}

impl BlueprintPayloadDef {
pub fn from_type_ref(type_ref: TypeRef<LocalTypeIndex>, schema_hash: SchemaHash) -> Self {
match type_ref {
TypeRef::Static(type_index) => {
BlueprintPayloadDef::Static(TypeIdentifier(schema_hash, type_index))
}
TypeRef::Generic(index) => BlueprintPayloadDef::Generic(index),
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Sbor)]
pub struct FunctionSchema {
pub receiver: Option<ReceiverInfo>,
Expand Down Expand Up @@ -160,7 +97,7 @@ pub struct BlueprintDependencies {

#[derive(Debug, Clone, PartialEq, Eq, ScryptoSbor)]
pub struct PackageExport {
pub code_hash: Hash,
pub code_hash: CodeHash,
pub export_name: String,
}

Expand Down Expand Up @@ -339,7 +276,7 @@ pub struct IndexedStateSchema {

impl IndexedStateSchema {
pub fn from_schema(
schema_hash: Hash,
schema_hash: SchemaHash,
schema: BlueprintStateSchemaInit,
system_mappings: BTreeMap<usize, PartitionNumber>,
) -> Self {
Expand All @@ -350,20 +287,10 @@ impl IndexedStateSchema {
let schema_fields = schema
.fields
.into_iter()
.map(|field_schema| {
let pointer = match field_schema.field {
TypeRef::Static(type_index) => {
BlueprintPayloadDef::Static(TypeIdentifier(schema_hash, type_index))
}
TypeRef::Generic(instance_index) => {
BlueprintPayloadDef::Generic(instance_index)
}
};
FieldSchema {
field: pointer,
condition: field_schema.condition,
transience: field_schema.transience,
}
.map(|field_schema| FieldSchema {
field: BlueprintPayloadDef::from_type_ref(field_schema.field, schema_hash),
condition: field_schema.condition,
transience: field_schema.transience,
})
.collect();
fields = Some((
Expand All @@ -375,12 +302,8 @@ impl IndexedStateSchema {

let mut collections = Vec::new();
for (collection_index, collection_schema) in schema.collections.into_iter().enumerate() {
let schema = collection_schema.map(|type_ref| match type_ref {
TypeRef::Static(type_index) => {
BlueprintPayloadDef::Static(TypeIdentifier(schema_hash, type_index))
}
TypeRef::Generic(generic_index) => BlueprintPayloadDef::Generic(generic_index),
});
let schema = collection_schema
.map(|type_ref| BlueprintPayloadDef::from_type_ref(type_ref, schema_hash));

if let Some(partition_num) = system_mappings.get(&collection_index) {
collections.push((PartitionDescription::Physical(*partition_num), schema));
Expand Down
4 changes: 4 additions & 0 deletions radix-engine-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ pub mod prelude {
non_fungible_data_update_roles, recall_roles, role_entry, roles2, rule, withdraw_roles,
};
}

pub(crate) mod internal_prelude {
pub use crate::prelude::*;
}
28 changes: 0 additions & 28 deletions radix-engine-interface/src/types/node_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,13 @@ pub enum ComponentField {
State0,
}

#[repr(u8)]
#[derive(Debug, Clone, Sbor, PartialEq, Eq, Hash, PartialOrd, Ord, FromRepr)]
pub enum PackageField {
Royalty,
}

#[repr(u8)]
#[derive(Debug, Clone, Sbor, PartialEq, Eq, Hash, PartialOrd, Ord, FromRepr)]
pub enum FungibleResourceManagerField {
Divisibility,
TotalSupply,
}

#[repr(u8)]
#[derive(Debug, Clone, Sbor, PartialEq, Eq, Hash, PartialOrd, Ord, FromRepr)]
pub enum PackagePartitionOffset {
Fields,
Blueprints,
BlueprintDependencies,
RoyaltyConfig,
AuthConfig,
VmType,
OriginalCode,
InstrumentedCode,
}

impl TryFrom<u8> for PackagePartitionOffset {
type Error = ();

fn try_from(offset: u8) -> Result<Self, Self::Error> {
Self::from_repr(offset).ok_or(())
}
}

#[repr(u8)]
#[derive(Debug, Clone, Sbor, PartialEq, Eq, Hash, PartialOrd, Ord, FromRepr)]
pub enum NonFungibleResourceManagerPartitionOffset {
Expand Down Expand Up @@ -320,7 +293,6 @@ substate_key!(TypeInfoField);
substate_key!(RoyaltyField);
substate_key!(RoleAssignmentField);
substate_key!(ComponentField);
substate_key!(PackageField);
substate_key!(FungibleResourceManagerField);
substate_key!(FungibleVaultField);
substate_key!(FungibleBucketField);
Expand Down
Loading

0 comments on commit 0f3006c

Please sign in to comment.