Skip to content

Commit

Permalink
impl From<&OutputId> for {AliasAddress, NftAddress} (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Oct 23, 2023
1 parent 1095894 commit 5ce3a04
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion sdk/src/types/block/address/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion sdk/src/types/block/address/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5ce3a04

Please sign in to comment.