mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-19 18:05:41 +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:
@@ -526,6 +526,12 @@ pub mod pallet {
|
||||
price: Option<PriceWithDirection<ItemPrice<T, I>>>,
|
||||
deadline: <T as SystemConfig>::BlockNumber,
|
||||
},
|
||||
/// New attributes have been set for an `item` of the `collection`.
|
||||
PreSignedAttributesSet {
|
||||
collection: T::CollectionId,
|
||||
item: T::ItemId,
|
||||
namespace: AttributeNamespace<T::AccountId>,
|
||||
},
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
@@ -614,6 +620,8 @@ pub mod pallet {
|
||||
IncorrectMetadata,
|
||||
/// Can't set more attributes per one call.
|
||||
MaxAttributesLimitReached,
|
||||
/// The provided namespace isn't supported in this call.
|
||||
WrongNamespace,
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
@@ -1824,6 +1832,33 @@ pub mod pallet {
|
||||
ensure!(signature.verify(&*msg, &signer), Error::<T, I>::WrongSignature);
|
||||
Self::do_mint_pre_signed(origin, mint_data, signer)
|
||||
}
|
||||
|
||||
/// Set attributes for an item by providing the pre-signed approval.
|
||||
///
|
||||
/// Origin must be Signed and must be an owner of the `data.item`.
|
||||
///
|
||||
/// - `data`: The pre-signed approval that consists of the information about the item,
|
||||
/// attributes to update and until what block number.
|
||||
/// - `signature`: The signature of the `data` object.
|
||||
/// - `signer`: The `data` object's signer. Should be an owner of the collection for the
|
||||
/// `CollectionOwner` namespace.
|
||||
///
|
||||
/// Emits `AttributeSet` for each provided attribute.
|
||||
/// Emits `ItemAttributesApprovalAdded` if the approval wasn't set before.
|
||||
/// Emits `PreSignedAttributesSet` on success.
|
||||
#[pallet::call_index(38)]
|
||||
#[pallet::weight(T::WeightInfo::set_attributes_pre_signed(data.attributes.len() as u32))]
|
||||
pub fn set_attributes_pre_signed(
|
||||
origin: OriginFor<T>,
|
||||
data: PreSignedAttributesOf<T, I>,
|
||||
signature: T::OffchainSignature,
|
||||
signer: T::AccountId,
|
||||
) -> DispatchResult {
|
||||
let origin = ensure_signed(origin)?;
|
||||
let msg = Encode::encode(&data);
|
||||
ensure!(signature.verify(&*msg, &signer), Error::<T, I>::WrongSignature);
|
||||
Self::do_set_attributes_pre_signed(origin, data, signer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user