Skip to content

Commit

Permalink
feat: implement custom nested decode to support nfts with extra attri…
Browse files Browse the repository at this point in the history
…butes

Refs: #43
  • Loading branch information
bucurdavid committed Feb 8, 2024
1 parent 8c36615 commit 7f36518
Showing 1 changed file with 17 additions and 44 deletions.
61 changes: 17 additions & 44 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,50 +73,23 @@ impl<M: ManagedTypeApi> TopDecode for DataNftAttributes<M> {

impl<M: ManagedTypeApi> NestedDecode for DataNftAttributes<M> {
fn dep_decode<I: NestedDecodeInput>(input: &mut I) -> Result<Self, DecodeError> {
let data_stream_url: Result<ManagedBuffer<M>, _> = ManagedBuffer::dep_decode(input);
let creator: Result<ManagedAddress<M>, _> = ManagedAddress::dep_decode(input);

let mut data_stream_url_value = None;
let mut creator_value = None;

// Assign the decoded values if successful
if let Ok(value) = data_stream_url.into() {
data_stream_url_value = Some(value);
}

if let Ok(value) = creator.into() {
creator_value = Some(value);
}

if data_stream_url_value.is_some() && creator_value.is_some() {
return Result::Ok(DataNftAttributes {
data_stream_url: data_stream_url_value.unwrap(),
data_preview_url: ManagedBuffer::from(""),
data_marshal_url: ManagedBuffer::from(""),
creator: creator_value.unwrap(),
creation_time: u64::from(0u8),
title: ManagedBuffer::from(""),
description: ManagedBuffer::from(""),
});
} else {
let data_stream_url = ManagedBuffer::dep_decode(input)?;
let data_preview_url = ManagedBuffer::dep_decode(input)?;
let data_marshal_url = ManagedBuffer::dep_decode(input)?;
let creator = ManagedAddress::dep_decode(input)?;
let creation_time = u64::dep_decode(input)?;
let title = ManagedBuffer::dep_decode(input)?;
let description = ManagedBuffer::dep_decode(input)?;

Result::Ok(DataNftAttributes {
data_stream_url,
data_preview_url,
data_marshal_url,
creator,
creation_time,
title,
description,
})
}
let data_stream_url = ManagedBuffer::dep_decode(input)?;
let data_preview_url = ManagedBuffer::dep_decode(input)?;
let data_marshal_url = ManagedBuffer::dep_decode(input)?;
let creator = ManagedAddress::dep_decode(input)?;
let creation_time = u64::dep_decode(input)?;
let title = ManagedBuffer::dep_decode(input)?;
let description = ManagedBuffer::dep_decode(input)?;

Result::Ok(DataNftAttributes {
data_stream_url,
data_preview_url,
data_marshal_url,
creator,
creation_time,
title,
description,
})
}
}
#[multiversx_sc::module]
Expand Down

0 comments on commit 7f36518

Please sign in to comment.