Skip to content

Commit

Permalink
Merge pull request #690 from radixdlt/feature/from-component-address-abi
Browse files Browse the repository at this point in the history
Feature: From component address abi
  • Loading branch information
talekhinezh authored Dec 19, 2022
2 parents 633d7f7 + 4790070 commit 0848b1a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
32 changes: 31 additions & 1 deletion radix-engine/src/engine/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,37 @@ where
return maybe_lock_handle;
}
}
Err(err) => return Err(err),
Err(err) => {
match &err {
// TODO: This is a hack to allow for package imports to be visible
// TODO: Remove this once we are able to get this information through the Blueprint ABI
RuntimeError::CallFrameError(CallFrameError::RENodeNotVisible(
RENodeId::Global(GlobalAddress::Package(package_address)),
)) => {
let node_id = RENodeId::Global(GlobalAddress::Package(*package_address));
let offset = SubstateOffset::Global(GlobalOffset::Global);
self.track
.acquire_lock(
SubstateId(node_id, offset.clone()),
LockFlags::read_only(),
)
.map_err(|_| err.clone())?;
self.track
.release_lock(SubstateId(node_id, offset.clone()), false)
.map_err(|_| err)?;
self.current_frame
.add_stored_ref(node_id, RENodeVisibilityOrigin::Normal);
self.current_frame.acquire_lock(
&mut self.heap,
&mut self.track,
node_id,
offset.clone(),
flags,
)?
}
_ => return Err(err),
}
}
};

if let Some(lock_handle) = derefed_lock {
Expand Down
12 changes: 6 additions & 6 deletions scrypto-derive/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn handle_import(input: TokenStream) -> Result<TokenStream> {

let package_address = blueprint.package_address;
let blueprint_name = blueprint.blueprint_name;
let ident = format_ident!("{}", blueprint_name);
let ident = format_ident!("{}GlobalComponentRef", blueprint_name);
trace!("Blueprint name: {}", blueprint_name);

let mut structs: Vec<Item> = vec![];
Expand Down Expand Up @@ -446,10 +446,10 @@ mod tests {
quote! {
#[derive(::sbor::TypeId, ::sbor::Encode, ::sbor::Decode, ::scrypto::Describe)]
#[sbor(custom_type_id = "::scrypto::data::ScryptoCustomTypeId")]
pub struct Simple {
pub struct SimpleGlobalComponentRef {
component_address: ::scrypto::model::ComponentAddress,
}
impl Simple {
impl SimpleGlobalComponentRef {
pub fn new() -> ::scrypto::model::ComponentAddress {
::scrypto::runtime::Runtime::call_function(
::scrypto::model::PackageAddress::try_from_hex("056967d3d49213394892980af59be76e9b3e7cc4cb78237460d0c7").unwrap(),
Expand All @@ -466,15 +466,15 @@ mod tests {
)
}
}
impl From<::scrypto::model::ComponentAddress> for Simple {
impl From<::scrypto::model::ComponentAddress> for SimpleGlobalComponentRef {
fn from(component_address: ::scrypto::model::ComponentAddress) -> Self {
Self {
component_address
}
}
}
impl From<Simple> for ::scrypto::model::ComponentAddress {
fn from(a: Simple) -> ::scrypto::model::ComponentAddress {
impl From<SimpleGlobalComponentRef> for ::scrypto::model::ComponentAddress {
fn from(a: SimpleGlobalComponentRef) -> ::scrypto::model::ComponentAddress {
a.component_address
}
}
Expand Down
4 changes: 2 additions & 2 deletions scrypto-tests/tests/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ import! {

blueprint! {
struct UseImport {
simple: Simple
simple: SimpleGlobalComponentRef
}

impl UseImport {
Expand All @@ -182,5 +182,5 @@ blueprint! {

#[test]
fn test_import_from_abi() {
let _ = Simple::from(ComponentAddress::Normal([0; 26]));
let _ = SimpleGlobalComponentRef::from(ComponentAddress::Normal([0; 26]));
}
3 changes: 2 additions & 1 deletion scrypto-tests/tests/import2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ blueprint! {

#[test]
fn test_import_from_abi() {
let _ = Simple::from(ComponentAddress::Normal([0; 26]));
let _ = SimpleGlobalComponentRef::from(ComponentAddress::Normal([0; 26]));
let _: SimpleGlobalComponentRef = ComponentAddress::Normal([0; 26]).into();
}

0 comments on commit 0848b1a

Please sign in to comment.