Skip to content

Commit

Permalink
Update the package-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Jul 5, 2024
1 parent e700b31 commit b08539b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions libraries/package-loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build = "build.rs"
[dependencies]
radix-common = { workspace = true }
scrypto-compiler = { workspace = true }
radix-substate-store-queries = { workspace = true }
radix-engine-interface = { workspace = true }

getrandom = { version = "0.2.12", features = ["js"] }

Expand All @@ -19,7 +19,6 @@ cargo_toml = { version = "0.18.0", optional = true }

radix-engine = { workspace = true, optional = true }
radix-common = { workspace = true, optional = true }
radix-engine-interface = { workspace = true, optional = true }

[features]
default = []
Expand All @@ -28,7 +27,6 @@ build-time-blueprints = [
"dep:cargo_toml",
"dep:radix-engine",
"dep:radix-common",
"dep:radix-engine-interface",
"dep:wasm-opt",
]

Expand Down
27 changes: 21 additions & 6 deletions libraries/package-loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,29 @@
#[allow(unused, clippy::module_inception)]
mod package_loader {
use radix_common::prelude::*;
use radix_substate_store_queries::typed_substate_layout::*;
use std::sync::*;

const PACKAGES_BINARY: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/compiled_packages.bin"));

static PACKAGES: OnceLock<HashMap<String, (Vec<u8>, PackageDefinition)>> =
OnceLock::new();
static PACKAGES: OnceLock<
HashMap<
String,
(
Vec<u8>,
radix_engine_interface::blueprints::package::PackageDefinition,
),
>,
> = OnceLock::new();

pub struct PackageLoader;
impl PackageLoader {
pub fn get(name: &str) -> (Vec<u8>, PackageDefinition) {
pub fn get(
name: &str,
) -> (
Vec<u8>,
radix_engine_interface::blueprints::package::PackageDefinition,
) {
let packages = PACKAGES
.get_or_init(|| scrypto_decode(PACKAGES_BINARY).unwrap());
if let Some(rtn) = packages.get(name) {
Expand All @@ -46,12 +57,16 @@ mod package_loader {
#[allow(unused, clippy::module_inception)]
mod package_loader {
use radix_common::prelude::*;
use radix_substate_store_queries::typed_substate_layout::*;
use std::path::PathBuf;

pub struct PackageLoader;
impl PackageLoader {
pub fn get(name: &str) -> (Vec<u8>, PackageDefinition) {
pub fn get(
name: &str,
) -> (
Vec<u8>,
radix_engine_interface::blueprints::package::PackageDefinition,
) {
let package_dir = PathBuf::from_str(env!("CARGO_MANIFEST_DIR"))
.unwrap()
.parent()
Expand Down

0 comments on commit b08539b

Please sign in to comment.