-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(nonfungibles): CollectionConfig parameter
- Loading branch information
1 parent
58c3849
commit 45ac5ca
Showing
14 changed files
with
239 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/// Implements encoding and decoding traits for a wrapper type that represents | ||
/// bitflags. The wrapper type should contain a field of type `$size`, where | ||
/// `$size` is an integer type (e.g., u8, u16, u32) that can represent the bitflags. | ||
/// The `$bitflag_enum` type is the enumeration type that defines the individual bitflags. | ||
/// | ||
/// This macro provides implementations for the following traits: | ||
/// - `MaxEncodedLen`: Calculates the maximum encoded length for the wrapper type. | ||
/// - `Encode`: Encodes the wrapper type using the provided encoding function. | ||
/// - `EncodeLike`: Trait indicating the type can be encoded as is. | ||
/// - `Decode`: Decodes the wrapper type from the input. | ||
/// - `TypeInfo`: Provides type information for the wrapper type. | ||
macro_rules! impl_codec_bitflags { | ||
($wrapper:ty, $size:ty, $bitflag_enum:ty) => { | ||
impl ink::scale::MaxEncodedLen for $wrapper { | ||
fn max_encoded_len() -> usize { | ||
<$size>::max_encoded_len() | ||
} | ||
} | ||
impl ink::scale::Encode for $wrapper { | ||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R { | ||
self.0.bits().using_encoded(f) | ||
} | ||
} | ||
impl ink::scale::EncodeLike for $wrapper {} | ||
impl ink::scale::Decode for $wrapper { | ||
fn decode<I: ink::scale::Input>( | ||
input: &mut I, | ||
) -> ::core::result::Result<Self, ink::scale::Error> { | ||
let field = <$size>::decode(input)?; | ||
Ok(Self(BitFlags::from_bits(field as $size).map_err(|_| "invalid value")?)) | ||
} | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
impl ink::scale_info::TypeInfo for $wrapper { | ||
type Identity = Self; | ||
|
||
fn type_info() -> ink::scale_info::Type { | ||
ink::scale_info::Type::builder() | ||
.path(ink::scale_info::Path::new("BitFlags", module_path!())) | ||
.type_params(vec![ink::scale_info::TypeParameter::new( | ||
"T", | ||
Some(ink::scale_info::meta_type::<$bitflag_enum>()), | ||
)]) | ||
.composite( | ||
ink::scale_info::build::Fields::unnamed() | ||
.field(|f| f.ty::<$size>().type_name(stringify!($bitflag_enum))), | ||
) | ||
} | ||
} | ||
}; | ||
} | ||
pub(crate) use impl_codec_bitflags; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.