From b88dc90e0ac532da807886eaa478d8db2bb9f2eb Mon Sep 17 00:00:00 2001 From: TalesOfBeem Date: Mon, 5 Sep 2022 14:49:08 +0100 Subject: [PATCH] make into great again --- scrypto-derive/src/blueprint.rs | 24 ++++++++++++++++++++++++ scrypto/src/component/component.rs | 7 +++++++ 2 files changed, 31 insertions(+) diff --git a/scrypto-derive/src/blueprint.rs b/scrypto-derive/src/blueprint.rs index b07dc4a9b2a..3ba5c080ecb 100644 --- a/scrypto-derive/src/blueprint.rs +++ b/scrypto-derive/src/blueprint.rs @@ -461,6 +461,14 @@ fn generate_stubs( pub component: ::scrypto::component::Component, } + impl From for #value_ident { + fn from(component: ComponentAddress) -> Self { + Self { + component: ::scrypto::component::Component::from(component) + } + } + } + impl ::scrypto::component::LocalComponent for #value_ident { fn package_address(&self) -> PackageAddress { self.component.package_address() @@ -645,6 +653,14 @@ mod tests { pub component: ::scrypto::component::Component, } + impl From for TestComponent { + fn from(component: ComponentAddress) -> Self { + Self { + component: ::scrypto::component::Component::from(component) + } + } + } + impl ::scrypto::component::LocalComponent for TestComponent { fn package_address(&self) -> PackageAddress { self.component.package_address() @@ -727,6 +743,14 @@ mod tests { pub component: ::scrypto::component::Component, } + impl From for TestComponent { + fn from(component: ComponentAddress) -> Self { + Self { + component: ::scrypto::component::Component::from(component) + } + } + } + impl ::scrypto::component::LocalComponent for TestComponent { fn package_address(&self) -> PackageAddress { self.component.package_address() diff --git a/scrypto/src/component/component.rs b/scrypto/src/component/component.rs index 97c9f54d45b..55a17e3e546 100644 --- a/scrypto/src/component/component.rs +++ b/scrypto/src/component/component.rs @@ -91,6 +91,13 @@ impl TryFrom<&[u8]> for Component { } } +impl From for Component { + fn from(component: ComponentAddress) -> Self { + let component_address = ComponentAddress::try_from(component.to_vec().as_slice()).unwrap(); + Self(component_address) + } +} + impl Component { pub fn to_vec(&self) -> Vec { self.0.to_vec()