Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api/nonfungibles): pallet + devnet runtime #339

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
aff6408
chore: fork pallet nfts (#382)
chungquantin Nov 18, 2024
f205909
chore: fork pallet nfts
chungquantin Nov 13, 2024
9cc20fe
chore: forked pallet nfts
chungquantin Oct 14, 2024
707bd80
fix: formatting
chungquantin Oct 14, 2024
7f5cec5
feat: add nonfungibles implementation
chungquantin Oct 14, 2024
cd84ed8
chore: add nfts pallet
chungquantin Oct 14, 2024
3fad994
feat: add new storage items to pallet-nfts
chungquantin Oct 15, 2024
bc2deee
feat: check allowance
chungquantin Oct 16, 2024
1946b15
test(nfts): check account balance & test total supply
chungquantin Oct 16, 2024
684d870
test(nfts): allowance works
chungquantin Oct 16, 2024
90ab45e
refactor(test): check_allowance_works
chungquantin Oct 16, 2024
f862516
fix(nfts): cancel / approve collection transfer
chungquantin Oct 17, 2024
7e55eb1
test(nfts): cancel approval collection
chungquantin Oct 17, 2024
af87aaf
test(nfts): update approval test cases
chungquantin Oct 17, 2024
06c0db9
feat(nfts): get attribute read method
chungquantin Oct 17, 2024
9c5eb78
feat(nonfungibles + nfts): add new methods to manage attributes
chungquantin Oct 17, 2024
9096b3f
refactor(nfts): toml lock file
chungquantin Oct 18, 2024
4334944
fix(pallet-api): propagate try-runtime feature
chungquantin Oct 18, 2024
a38fc47
fix(api/nonfungibles): unit tests
chungquantin Oct 18, 2024
a1f4468
test(api/nonfungibles): encoding_read_result
chungquantin Oct 18, 2024
80b378e
refactor(api/nonfungibles): pallet tests
chungquantin Oct 18, 2024
f3e7e4a
test(nonfungibles): add tests and remove collection owner read
chungquantin Oct 21, 2024
e0c896c
chore: update pallet & runtime
chungquantin Nov 11, 2024
f67dab1
fix: becnhmark helper
chungquantin Nov 12, 2024
a4e16e8
feat: multi instances & function comments
chungquantin Nov 13, 2024
73e1df5
feat(devnet): pallet nfts instance configuration
chungquantin Nov 13, 2024
bbb9bb4
chore: resolve feedback
chungquantin Nov 16, 2024
e07565d
feat(api/nonfungibles): destroy collection witness data & weights (#383)
chungquantin Nov 16, 2024
9dd80cc
chore: clippy
chungquantin Nov 18, 2024
73f4994
chore: taplo fmt
chungquantin Nov 18, 2024
f66a44d
chore: fork pallet nfts
chungquantin Nov 13, 2024
ffb6b21
chore: resolve feedback
chungquantin Nov 16, 2024
dad89cb
feat: nfts pallet optimization
chungquantin Nov 19, 2024
6ef968f
chore: fork pallet nfts (#382)
chungquantin Nov 18, 2024
40471b7
chore: fork pallet nfts
chungquantin Nov 13, 2024
cbe485c
chore: forked pallet nfts
chungquantin Oct 14, 2024
386f50f
fix: formatting
chungquantin Oct 14, 2024
5ff3fc1
feat: add nonfungibles implementation
chungquantin Oct 14, 2024
550f20a
chore: add nfts pallet
chungquantin Oct 14, 2024
1580a67
feat: add new storage items to pallet-nfts
chungquantin Oct 15, 2024
8b8d353
feat: check allowance
chungquantin Oct 16, 2024
95b2de9
test(nfts): check account balance & test total supply
chungquantin Oct 16, 2024
5436b73
test(nfts): allowance works
chungquantin Oct 16, 2024
b02bea9
refactor(test): check_allowance_works
chungquantin Oct 16, 2024
c7294da
fix(nfts): cancel / approve collection transfer
chungquantin Oct 17, 2024
63c51a8
test(nfts): cancel approval collection
chungquantin Oct 17, 2024
3158512
test(nfts): update approval test cases
chungquantin Oct 17, 2024
4ddca6d
feat(nfts): get attribute read method
chungquantin Oct 17, 2024
cc2c687
feat(nonfungibles + nfts): add new methods to manage attributes
chungquantin Oct 17, 2024
0640655
refactor(nfts): toml lock file
chungquantin Oct 18, 2024
ecca06d
fix(pallet-api): propagate try-runtime feature
chungquantin Oct 18, 2024
26a707f
fix(api/nonfungibles): unit tests
chungquantin Oct 18, 2024
87eb655
test(api/nonfungibles): encoding_read_result
chungquantin Oct 18, 2024
0de5231
refactor(api/nonfungibles): pallet tests
chungquantin Oct 18, 2024
a8adbed
test(nonfungibles): add tests and remove collection owner read
chungquantin Oct 21, 2024
34556bd
chore: update pallet & runtime
chungquantin Nov 11, 2024
8203783
fix: becnhmark helper
chungquantin Nov 12, 2024
8104138
feat: multi instances & function comments
chungquantin Nov 13, 2024
7408afc
feat(devnet): pallet nfts instance configuration
chungquantin Nov 13, 2024
7fbc606
chore: resolve feedback
chungquantin Nov 16, 2024
26e4d4e
feat(api/nonfungibles): destroy collection witness data & weights (#383)
chungquantin Nov 16, 2024
7dce4af
chore: clippy
chungquantin Nov 18, 2024
0286433
chore: taplo fmt
chungquantin Nov 18, 2024
a35abfa
chore: fork pallet nfts
chungquantin Nov 13, 2024
9fbb78e
Merge remote-tracking branch 'refs/remotes/origin/chungquantin/feat-n…
chungquantin Nov 19, 2024
b0fbeb3
chore: fork pallet nfts
chungquantin Nov 13, 2024
98217ae
chore: resolve feedback
chungquantin Nov 16, 2024
d954c70
feat: nfts pallet optimization
chungquantin Nov 19, 2024
b76dc4d
chore: fork pallet nfts (#382)
chungquantin Nov 18, 2024
aa829a7
Merge remote-tracking branch 'refs/remotes/origin/chungquantin/feat-n…
chungquantin Nov 19, 2024
9d1658e
feat: add new storage items and optimize
chungquantin Nov 19, 2024
873fa43
chore: fork pallet nfts
chungquantin Nov 13, 2024
b3bae12
chore: forked pallet nfts
chungquantin Oct 14, 2024
3ead07a
fix: formatting
chungquantin Oct 14, 2024
7aa2863
feat: add nonfungibles implementation
chungquantin Oct 14, 2024
151251d
chore: add nfts pallet
chungquantin Oct 14, 2024
90bdcdd
feat: add new storage items to pallet-nfts
chungquantin Oct 15, 2024
d2f26b4
feat: check allowance
chungquantin Oct 16, 2024
24202b3
test(nfts): check account balance & test total supply
chungquantin Oct 16, 2024
23c030f
test(nfts): allowance works
chungquantin Oct 16, 2024
4972e42
refactor(test): check_allowance_works
chungquantin Oct 16, 2024
00ea70d
fix(nfts): cancel / approve collection transfer
chungquantin Oct 17, 2024
36e6795
test(nfts): cancel approval collection
chungquantin Oct 17, 2024
ad366a2
test(nfts): update approval test cases
chungquantin Oct 17, 2024
7b9d587
feat(nfts): get attribute read method
chungquantin Oct 17, 2024
2e80aa4
feat(nonfungibles + nfts): add new methods to manage attributes
chungquantin Oct 17, 2024
47a0f52
refactor(nfts): toml lock file
chungquantin Oct 18, 2024
938d013
fix(pallet-api): propagate try-runtime feature
chungquantin Oct 18, 2024
53376a9
fix(api/nonfungibles): unit tests
chungquantin Oct 18, 2024
0626125
test(api/nonfungibles): encoding_read_result
chungquantin Oct 18, 2024
fc51fd6
refactor(api/nonfungibles): pallet tests
chungquantin Oct 18, 2024
4318271
test(nonfungibles): add tests and remove collection owner read
chungquantin Oct 21, 2024
bb96314
chore: update pallet & runtime
chungquantin Nov 11, 2024
ffc68f5
fix: becnhmark helper
chungquantin Nov 12, 2024
e070e36
feat: multi instances & function comments
chungquantin Nov 13, 2024
b5cea8e
feat(devnet): pallet nfts instance configuration
chungquantin Nov 13, 2024
0c26474
chore: resolve feedback
chungquantin Nov 16, 2024
2b6ed27
feat(api/nonfungibles): destroy collection witness data & weights (#383)
chungquantin Nov 16, 2024
498e927
chore: clippy
chungquantin Nov 18, 2024
33b9ca7
chore: taplo fmt
chungquantin Nov 18, 2024
d7bc57e
chore: fork pallet nfts
chungquantin Nov 13, 2024
862f23b
chore: fork pallet nfts
chungquantin Nov 13, 2024
8c8d003
chore: forked pallet nfts
chungquantin Oct 14, 2024
24ddc7d
fix: formatting
chungquantin Oct 14, 2024
8c25fcf
feat: add nonfungibles implementation
chungquantin Oct 14, 2024
b131c60
chore: add nfts pallet
chungquantin Oct 14, 2024
1a54094
feat: add new storage items to pallet-nfts
chungquantin Oct 15, 2024
22651ba
feat: check allowance
chungquantin Oct 16, 2024
97917ae
test(nfts): check account balance & test total supply
chungquantin Oct 16, 2024
2282b76
test(nfts): allowance works
chungquantin Oct 16, 2024
d803fbb
refactor(test): check_allowance_works
chungquantin Oct 16, 2024
1221f18
fix(nfts): cancel / approve collection transfer
chungquantin Oct 17, 2024
8fcf123
test(nfts): cancel approval collection
chungquantin Oct 17, 2024
1034a65
test(nfts): update approval test cases
chungquantin Oct 17, 2024
8cdf05d
feat(nfts): get attribute read method
chungquantin Oct 17, 2024
b467b40
feat(nonfungibles + nfts): add new methods to manage attributes
chungquantin Oct 17, 2024
54b8228
refactor(nfts): toml lock file
chungquantin Oct 18, 2024
52aea7f
test(api/nonfungibles): encoding_read_result
chungquantin Oct 18, 2024
22456c7
test(nonfungibles): add tests and remove collection owner read
chungquantin Oct 21, 2024
e2cf885
chore: update pallet & runtime
chungquantin Nov 11, 2024
c3be7e1
feat: multi instances & function comments
chungquantin Nov 13, 2024
f8acb26
chore: resolve feedback
chungquantin Nov 16, 2024
874fb92
feat(api/nonfungibles): destroy collection witness data & weights (#383)
chungquantin Nov 16, 2024
fba13cf
chore: clippy
chungquantin Nov 18, 2024
946ad65
chore: taplo fmt
chungquantin Nov 18, 2024
7bfbd43
chore: fork pallet nfts
chungquantin Nov 13, 2024
dcb4e33
Merge remote-tracking branch 'refs/remotes/origin/chungquantin/feat-n…
chungquantin Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pallets/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ frame-benchmarking.workspace = true
frame-support.workspace = true
frame-system.workspace = true
pallet-assets.workspace = true
pallet-nfts.workspace = true
sp-runtime.workspace = true
sp-std.workspace = true

Expand All @@ -37,6 +38,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
"pop-chain-extension/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
Expand All @@ -47,6 +49,7 @@ std = [
"frame-system/std",
"pallet-assets/std",
"pallet-balances/std",
"pallet-nfts/std",
"pop-chain-extension/std",
"scale-info/std",
"sp-core/std",
Expand All @@ -57,5 +60,6 @@ std = [
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-nfts/try-runtime",
"sp-runtime/try-runtime",
]
1 change: 1 addition & 0 deletions pallets/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod extension;
pub mod fungibles;
#[cfg(test)]
mod mock;
pub mod nonfungibles;

/// Trait for performing reads of runtime state.
pub trait Read {
Expand Down
93 changes: 90 additions & 3 deletions pallets/api/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use codec::{Decode, Encode};
use frame_support::{
derive_impl, parameter_types,
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, Everything},
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Everything},
};
use frame_system::{EnsureRoot, EnsureSigned};
use pallet_nfts::PalletFeatures;
use scale_info::TypeInfo;
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Lazy, Verify},
BuildStorage,
};

Expand All @@ -29,6 +32,8 @@ frame_support::construct_runtime!(
Assets: pallet_assets::<Instance1>,
Balances: pallet_balances,
Fungibles: crate::fungibles,
Nfts: pallet_nfts::<Instance1>,
NonFungibles: crate::nonfungibles
}
);

Expand Down Expand Up @@ -91,7 +96,7 @@ impl pallet_assets::Config<AssetsInstance> for Test {
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type CallbackHandle = ();
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<u64>>;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<Self::AccountId>>;
type Currency = Balances;
type Extra = ();
type ForceOrigin = EnsureRoot<u64>;
Expand All @@ -110,6 +115,88 @@ impl crate::fungibles::Config for Test {
type WeightInfo = ();
}

parameter_types! {
pub storage Features: PalletFeatures = PalletFeatures::all_enabled();
}

#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, TypeInfo)]
pub struct Noop;

impl IdentifyAccount for Noop {
type AccountId = AccountId;

fn into_account(self) -> Self::AccountId {
0
}
}

impl Verify for Noop {
type Signer = Noop;

fn verify<L: Lazy<[u8]>>(
&self,
_msg: L,
_signer: &<Self::Signer as IdentifyAccount>::AccountId,
) -> bool {
false
}
}

#[cfg(feature = "runtime-benchmarks")]
impl pallet_nfts::pallet::BenchmarkHelper<u32, u32, Noop, u64, Noop> for () {
fn collection(i: u16) -> u32 {
i.into()
}

fn item(i: u16) -> u32 {
i.into()
}

fn signer() -> (Noop, u64) {
unimplemented!()
}

fn sign(signer: &Noop, message: &[u8]) -> Noop {
unimplemented!()
}
}

type NftsInstance = pallet_nfts::Instance1;
impl pallet_nfts::Config<NftsInstance> for Test {
type ApprovalsLimit = ConstU32<10>;
type AttributeDepositBase = ConstU128<1>;
type CollectionDeposit = ConstU128<2>;
type CollectionId = u32;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<u64>>;
type Currency = Balances;
type DepositPerByte = ConstU128<1>;
type Features = Features;
type ForceOrigin = frame_system::EnsureRoot<Self::AccountId>;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type ItemAttributesApprovalsLimit = ConstU32<2>;
type ItemDeposit = ConstU128<1>;
type ItemId = u32;
type KeyLimit = ConstU32<50>;
type Locker = ();
type MaxAttributesPerCall = ConstU32<2>;
type MaxDeadlineDuration = ConstU64<10000>;
type MaxTips = ConstU32<10>;
type MetadataDepositBase = ConstU128<1>;
type OffchainPublic = Noop;
type OffchainSignature = Noop;
type RuntimeEvent = RuntimeEvent;
type StringLimit = ConstU32<50>;
type ValueLimit = ConstU32<50>;
type WeightInfo = ();
}

impl crate::nonfungibles::Config for Test {
type NftsInstance = NftsInstance;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}

pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
Expand Down
110 changes: 110 additions & 0 deletions pallets/api/src/nonfungibles/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//! Benchmarking setup for pallet_api::nonfungibles

use frame_benchmarking::{account, v2::*};
use frame_support::{traits::nonfungibles_v2::Inspect, BoundedVec};
use sp_runtime::traits::Zero;

use super::{AttributeNamespace, CollectionIdOf, Config, ItemIdOf, NftsInstanceOf, Pallet, Read};
use crate::Read as _;

const SEED: u32 = 1;

#[benchmarks(
where
<pallet_nfts::Pallet<T, NftsInstanceOf<T>> as Inspect<<T as frame_system::Config>::AccountId>>::ItemId: Zero,
<pallet_nfts::Pallet<T, NftsInstanceOf<T>> as Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: Zero,
)]
mod benchmarks {
use super::*;

#[benchmark]
// Storage: `Collection`
fn total_supply() {
#[block]
{
Pallet::<T>::read(Read::TotalSupply(CollectionIdOf::<T>::zero()));
}
}

#[benchmark]
// Storage: `AccountBalance`
fn balance_of() {
#[block]
{
Pallet::<T>::read(Read::BalanceOf {
collection: CollectionIdOf::<T>::zero(),
owner: account("Alice", 0, SEED),
});
}
}

#[benchmark]
// Storage: `Allowances`, `Item`
fn allowance() {
#[block]
{
Pallet::<T>::read(Read::Allowance {
collection: CollectionIdOf::<T>::zero(),
owner: account("Alice", 0, SEED),
operator: account("Bob", 0, SEED),
item: Some(ItemIdOf::<T>::zero()),
});
}
}

#[benchmark]
// Storage: `Item`
fn owner_of() {
#[block]
{
Pallet::<T>::read(Read::OwnerOf {
collection: CollectionIdOf::<T>::zero(),
item: ItemIdOf::<T>::zero(),
});
}
}

#[benchmark]
// Storage: `Attribute`
fn get_attribute() {
#[block]
{
Pallet::<T>::read(Read::GetAttribute {
key: BoundedVec::default(),
collection: CollectionIdOf::<T>::zero(),
item: ItemIdOf::<T>::zero(),
namespace: AttributeNamespace::CollectionOwner,
});
}
}

#[benchmark]
// Storage: `Collection`
fn collection() {
#[block]
{
Pallet::<T>::read(Read::Collection(CollectionIdOf::<T>::zero()));
}
}

#[benchmark]
// Storage: `NextCollectionId`
fn next_collection_id() {
#[block]
{
Pallet::<T>::read(Read::NextCollectionId);
}
}

#[benchmark]
// Storage: `ItemMetadata`
fn item_metadata() {
#[block]
{
Pallet::<T>::read(Read::ItemMetadata {
collection: CollectionIdOf::<T>::zero(),
item: ItemIdOf::<T>::zero(),
});
}
}
}
Loading
Loading