mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-22 04:31:02 +00:00
[NFTs] Update attributes with offchain signature (#13390)
* Allow to mint with the pre-signed signatures * Another try * WIP: test encoder * Fix the deposits * Refactoring + tests + benchmarks * Add sp-core/runtime-benchmarks * Remove sp-core from dev deps * Enable full_crypto for benchmarks * Typo * Fix * Update frame/nfts/src/mock.rs Co-authored-by: Squirrel <gilescope@gmail.com> * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_nfts * Add docs * Add attributes into the pre-signed object & track the deposit owner for attributes * Update docs * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_nfts * Add the number of attributes provided to weights * Support pre-signed attributes * Update docs * Fix merge artifacts * Update docs * Add more tests * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_nfts * Update frame/nfts/src/types.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update types.rs --------- Co-authored-by: Squirrel <gilescope@gmail.com> Co-authored-by: command-bot <> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
This commit is contained in:
@@ -773,5 +773,55 @@ benchmarks_instance_pallet! {
|
||||
assert_last_event::<T, I>(Event::ItemMetadataSet { collection, item, data: metadata }.into());
|
||||
}
|
||||
|
||||
set_attributes_pre_signed {
|
||||
let n in 0 .. T::MaxAttributesPerCall::get() as u32;
|
||||
let (collection, _, _) = create_collection::<T, I>();
|
||||
|
||||
let item_owner: T::AccountId = account("item_owner", 0, SEED);
|
||||
let item_owner_lookup = T::Lookup::unlookup(item_owner.clone());
|
||||
|
||||
let signer_public = sr25519_generate(0.into(), None);
|
||||
let signer: T::AccountId = MultiSigner::Sr25519(signer_public).into_account().into();
|
||||
|
||||
T::Currency::make_free_balance_be(&item_owner, DepositBalanceOf::<T, I>::max_value());
|
||||
|
||||
let item = T::Helper::item(0);
|
||||
assert_ok!(Nfts::<T, I>::force_mint(
|
||||
SystemOrigin::Root.into(),
|
||||
collection,
|
||||
item,
|
||||
item_owner_lookup.clone(),
|
||||
default_item_config(),
|
||||
));
|
||||
|
||||
let mut attributes = vec![];
|
||||
let attribute_value = vec![0u8; T::ValueLimit::get() as usize];
|
||||
for i in 0..n {
|
||||
let attribute_key = make_filled_vec(i as u16, T::KeyLimit::get() as usize);
|
||||
attributes.push((attribute_key, attribute_value.clone()));
|
||||
}
|
||||
let pre_signed_data = PreSignedAttributes {
|
||||
collection,
|
||||
item,
|
||||
attributes,
|
||||
namespace: AttributeNamespace::Account(signer.clone()),
|
||||
deadline: One::one(),
|
||||
};
|
||||
let message = Encode::encode(&pre_signed_data);
|
||||
let signature = MultiSignature::Sr25519(sr25519_sign(0.into(), &signer_public, &message).unwrap());
|
||||
|
||||
frame_system::Pallet::<T>::set_block_number(One::one());
|
||||
}: _(SystemOrigin::Signed(item_owner.clone()), pre_signed_data, signature.into(), signer.clone())
|
||||
verify {
|
||||
assert_last_event::<T, I>(
|
||||
Event::PreSignedAttributesSet {
|
||||
collection,
|
||||
item,
|
||||
namespace: AttributeNamespace::Account(signer.clone()),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(Nfts, crate::mock::new_test_ext(), crate::mock::Test);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user