Skip to content

Commit

Permalink
Merge pull request #484 from beemdvp/main
Browse files Browse the repository at this point in the history
Make into great again
  • Loading branch information
iamyulong authored Sep 8, 2022
2 parents 9d7ae1d + b88dc90 commit 6a431b4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions scrypto-derive/src/blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,14 @@ fn generate_stubs(
pub component: ::scrypto::component::Component,
}

impl From<ComponentAddress> 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()
Expand Down Expand Up @@ -645,6 +653,14 @@ mod tests {
pub component: ::scrypto::component::Component,
}

impl From<ComponentAddress> 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()
Expand Down Expand Up @@ -727,6 +743,14 @@ mod tests {
pub component: ::scrypto::component::Component,
}

impl From<ComponentAddress> 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()
Expand Down
7 changes: 7 additions & 0 deletions scrypto/src/component/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ impl TryFrom<&[u8]> for Component {
}
}

impl From<ComponentAddress> 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<u8> {
self.0.to_vec()
Expand Down

0 comments on commit 6a431b4

Please sign in to comment.