Skip to content

Commit

Permalink
Accept IntoIterator in MetadataFeature::new()
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed Jan 11, 2024
1 parent d316432 commit e314ebe
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 22 deletions.
5 changes: 1 addition & 4 deletions sdk/examples/client/output/build_account_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ async fn main() -> Result<()> {
// Account id needs to be null the first time
let account_output = AccountOutputBuilder::new_with_minimum_amount(storage_score_params, AccountId::null())
.add_feature(SenderFeature::new(address.clone()))
.add_feature(MetadataFeature::new(std::collections::BTreeMap::from_iter(vec![(
metadata.to_vec(),
metadata.to_vec(),
)]))?)
.add_feature(MetadataFeature::new([(metadata.to_vec(), metadata.to_vec())])?)
.add_immutable_feature(IssuerFeature::new(address.clone()))
.add_immutable_feature(MetadataFeature::new(std::collections::BTreeMap::from_iter(vec![(
metadata.to_vec(),
Expand Down
5 changes: 1 addition & 4 deletions sdk/examples/client/output/build_basic_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ async fn main() -> Result<()> {
// with metadata feature block
basic_output_builder
.clone()
.add_feature(MetadataFeature::new(std::collections::BTreeMap::from_iter(vec![(
KEY.to_vec(),
METADATA.to_vec(),
)]))?)
.add_feature(MetadataFeature::new([(KEY.to_vec(), METADATA.to_vec())])?)
.finish_output()?,
// with storage deposit return
basic_output_builder
Expand Down
8 changes: 4 additions & 4 deletions sdk/examples/client/output/build_nft_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ async fn main() -> Result<()> {
let nft_output = NftOutputBuilder::new_with_minimum_amount(storage_score_params, NftId::null())
.add_unlock_condition(AddressUnlockCondition::new(address.clone()))
.add_feature(SenderFeature::new(address.clone()))
.add_feature(MetadataFeature::new(std::collections::BTreeMap::from_iter(vec![(
.add_feature(MetadataFeature::new([(
"mutable".as_bytes().to_vec(),
MUTABLE_METADATA.as_bytes().to_vec(),
)]))?)
)])?)
.add_feature(TagFeature::new(TAG)?)
.add_immutable_feature(IssuerFeature::new(address))
.add_immutable_feature(MetadataFeature::new(std::collections::BTreeMap::from_iter(vec![(
.add_immutable_feature(MetadataFeature::new([(
"IRC27".as_bytes().to_vec(),
tip_27_immutable_metadata.as_bytes().to_vec(),
)]))?)
)])?)
.finish_output()?;

println!("{nft_output:#?}");
Expand Down
10 changes: 2 additions & 8 deletions sdk/examples/how_tos/outputs/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,12 @@ async fn main() -> Result<()> {
// with metadata feature block
nft_output_builder
.clone()
.add_feature(MetadataFeature::new(std::collections::BTreeMap::from_iter(vec![(
b"Hello".to_vec(),
b"World!".to_vec(),
)]))?)
.add_feature(MetadataFeature::new([(b"Hello".to_vec(), b"World!".to_vec())])?)
.finish_output()?,
// with immutable metadata feature block
nft_output_builder
.clone()
.add_immutable_feature(MetadataFeature::new(std::collections::BTreeMap::from_iter(vec![(
b"Hello".to_vec(),
b"World!".to_vec(),
)]))?)
.add_immutable_feature(MetadataFeature::new([(b"Hello".to_vec(), b"World!".to_vec())])?)
.finish_output()?,
// with tag feature
nft_output_builder
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/types/block/output/feature/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ impl MetadataFeature {

/// Creates a new [`MetadataFeature`].
#[inline(always)]
pub fn new(data: impl Into<BTreeMap<Vec<u8>, Vec<u8>>>) -> Result<Self, Error> {
let data = data.into();
pub fn new(data: impl IntoIterator<Item = (Vec<u8>, Vec<u8>)>) -> Result<Self, Error> {
let data: BTreeMap<Vec<u8>, Vec<u8>> = data.into_iter().collect();

for key in data.keys() {
if !key.iter().all(|b| b.is_ascii_graphic()) {
Expand Down

0 comments on commit e314ebe

Please sign in to comment.