From 5ce3a04488166a9231058896d4d29374225fe80f Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 23 Oct 2023 09:19:32 +0200 Subject: [PATCH] impl From<&OutputId> for {AliasAddress, NftAddress} (#1488) --- sdk/CHANGELOG.md | 4 ++++ sdk/src/types/block/address/alias.rs | 11 ++++++++++- sdk/src/types/block/address/nft.rs | 11 ++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/sdk/CHANGELOG.md b/sdk/CHANGELOG.md index f3471ecfab..13f2cafaec 100644 --- a/sdk/CHANGELOG.md +++ b/sdk/CHANGELOG.md @@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 1.1.2 - 2023-MM-DD +### Added + +- `impl From<&OutputId> for {AliasAddress, NftAddress}`; + ### Fixed - `Account::claim_outputs()` if an input has less amount than min storage deposit; diff --git a/sdk/src/types/block/address/alias.rs b/sdk/src/types/block/address/alias.rs index 3e3208ffa8..ec26c48d6d 100644 --- a/sdk/src/types/block/address/alias.rs +++ b/sdk/src/types/block/address/alias.rs @@ -5,7 +5,10 @@ use core::str::FromStr; use derive_more::{AsRef, Deref, From}; -use crate::types::block::{output::AliasId, Error}; +use crate::types::block::{ + output::{AliasId, OutputId}, + Error, +}; /// An alias address. #[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, From, AsRef, Deref, packable::Packable)] @@ -48,6 +51,12 @@ impl FromStr for AliasAddress { } } +impl From<&OutputId> for AliasAddress { + fn from(output_id: &OutputId) -> Self { + Self(AliasId::from(output_id)) + } +} + impl core::fmt::Display for AliasAddress { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.0) diff --git a/sdk/src/types/block/address/nft.rs b/sdk/src/types/block/address/nft.rs index 0b0bbfe8d8..c316904f6e 100644 --- a/sdk/src/types/block/address/nft.rs +++ b/sdk/src/types/block/address/nft.rs @@ -5,7 +5,10 @@ use core::str::FromStr; use derive_more::{AsRef, Deref, From}; -use crate::types::block::{output::NftId, Error}; +use crate::types::block::{ + output::{NftId, OutputId}, + Error, +}; /// An NFT address. #[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, From, AsRef, Deref, packable::Packable)] @@ -48,6 +51,12 @@ impl FromStr for NftAddress { } } +impl From<&OutputId> for NftAddress { + fn from(output_id: &OutputId) -> Self { + Self(NftId::from(output_id)) + } +} + impl core::fmt::Display for NftAddress { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.0)