difftreelog
feat(rpc) adminlist/allowlist/last_token_id calls
in: master
10 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -1,5 +1,6 @@
use std::sync::Arc;
+use codec::Decode;
use jsonrpc_core::{Error as RpcError, ErrorCode, Result};
use jsonrpc_derive::rpc;
use nft_data_structs::{CollectionId, TokenId};
@@ -72,6 +73,13 @@
token: TokenId,
at: Option<BlockHash>,
) -> Result<u128>;
+
+ #[rpc(name = "nft_adminlist")]
+ fn adminlist(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<Vec<AccountId>>;
+ #[rpc(name = "nft_allowlist")]
+ fn allowlist(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<Vec<AccountId>>;
+ #[rpc(name = "nft_lastTokenId")]
+ fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;
}
pub struct Nft<C, P> {
@@ -125,6 +133,7 @@
for Nft<C, Block>
where
Block: BlockT,
+ AccountId: Decode,
C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
C::Api: NftRuntimeApi<Block, CrossAccountId, AccountId>,
CrossAccountId: pallet_common::account::CrossAccountId<AccountId>,
@@ -138,4 +147,8 @@
pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32);
pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> u128);
pass_method!(allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> u128);
+
+ pass_method!(adminlist(collection: CollectionId) -> Vec<AccountId>);
+ pass_method!(allowlist(collection: CollectionId) -> Vec<AccountId>);
+ pass_method!(last_token_id(collection: CollectionId) -> TokenId);
}
pallets/common/src/lib.rsdiffbeforeafterboth109 pub fn ignores_owned_amount(&self, user: &T::CrossAccountId) -> Result<bool, DispatchError> {109 pub fn ignores_owned_amount(&self, user: &T::CrossAccountId) -> Result<bool, DispatchError> {110 Ok(self.limits.owner_can_transfer && self.is_owner_or_admin(user)?)110 Ok(self.limits.owner_can_transfer && self.is_owner_or_admin(user)?)111 }111 }112 pub fn check_whitelist(&self, user: &T::CrossAccountId) -> DispatchResult {112 pub fn check_allowlist(&self, user: &T::CrossAccountId) -> DispatchResult {113 self.consume_sload()?;113 self.consume_sload()?;114114115 ensure!(115 ensure!(116 <WhiteList<T>>::get((self.id, user.as_sub())),116 <Allowlist<T>>::get((self.id, user.as_sub())),117 <Error<T>>::AddressNotInWhiteList117 <Error<T>>::AddressNotInAllowlist118 );118 );119 Ok(())119 Ok(())120 }120 }252 /// Collection is not in mint mode.252 /// Collection is not in mint mode.253 PublicMintingNotAllowed,253 PublicMintingNotAllowed,254 /// Address is not in white list.254 /// Address is not in white list.255 AddressNotInWhiteList,255 AddressNotInAllowlist,256256257 /// Collection name can not be longer than 63 char.257 /// Collection name can not be longer than 63 char.258 CollectionNameLimitExceeded,258 CollectionNameLimitExceeded,315 QueryKind = ValueQuery,315 QueryKind = ValueQuery,316 >;316 >;317317318 /// Whitelisted collection users318 /// Allowlisted collection users319 #[pallet::storage]319 #[pallet::storage]320 pub type WhiteList<T: Config> = StorageNMap<320 pub type Allowlist<T: Config> = StorageNMap<321 Key = (321 Key = (322 Key<Blake2_128Concat, CollectionId>,322 Key<Blake2_128Concat, CollectionId>,323 Key<Blake2_128Concat, T::AccountId>,323 Key<Blake2_128Concat, T::AccountId>,417 <DestroyedCollectionCount<T>>::put(destroyed_collections);418 <DestroyedCollectionCount<T>>::put(destroyed_collections);418 <CollectionById<T>>::remove(collection.id);419 <CollectionById<T>>::remove(collection.id);419 <IsAdmin<T>>::remove_prefix((collection.id,), None);420 <IsAdmin<T>>::remove_prefix((collection.id,), None);420 <WhiteList<T>>::remove_prefix((collection.id,), None);421 <Allowlist<T>>::remove_prefix((collection.id,), None);421 Ok(())422 Ok(())422 }423 }423424424 pub fn toggle_whitelist(425 pub fn toggle_allowlist(425 collection: &CollectionHandle<T>,426 collection: &CollectionHandle<T>,426 sender: &T::CrossAccountId,427 sender: &T::CrossAccountId,427 user: &T::CrossAccountId,428 user: &T::CrossAccountId,432 // =========433 // =========433434434 if allowed {435 if allowed {435 <WhiteList<T>>::insert((collection.id, user.as_sub()), true);436 <Allowlist<T>>::insert((collection.id, user.as_sub()), true);436 } else {437 } else {437 <WhiteList<T>>::remove((collection.id, user.as_sub()));438 <Allowlist<T>>::remove((collection.id, user.as_sub()));438 }439 }439440440 Ok(())441 Ok(())511512512 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId>;513 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId>;513 fn token_exists(&self, token: TokenId) -> bool;514 fn token_exists(&self, token: TokenId) -> bool;515 fn last_token_id(&self) -> TokenId;514516515 fn token_owner(&self, token: TokenId) -> T::CrossAccountId;517 fn token_owner(&self, token: TokenId) -> T::CrossAccountId;516 fn const_metadata(&self, token: TokenId) -> Vec<u8>;518 fn const_metadata(&self, token: TokenId) -> Vec<u8>;pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -177,6 +177,10 @@
token == TokenId::default()
}
+ fn last_token_id(&self) -> TokenId {
+ TokenId::default()
+ }
+
fn token_owner(&self, _token: TokenId) -> T::CrossAccountId {
T::CrossAccountId::default()
}
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -123,7 +123,7 @@
.ok_or(<CommonError<T>>::TokenValueTooLow)?;
if collection.access == AccessMode::WhiteList {
- collection.check_whitelist(owner)?;
+ collection.check_allowlist(owner)?;
}
// =========
@@ -161,8 +161,8 @@
);
if collection.access == AccessMode::WhiteList {
- collection.check_whitelist(from)?;
- collection.check_whitelist(to)?;
+ collection.check_allowlist(from)?;
+ collection.check_allowlist(to)?;
}
<PalletCommon<T>>::ensure_correct_receiver(to)?;
@@ -222,10 +222,10 @@
collection.mint_mode,
<CommonError<T>>::PublicMintingNotAllowed
);
- collection.check_whitelist(sender)?;
+ collection.check_allowlist(sender)?;
for (owner, _) in data.iter() {
- collection.check_whitelist(owner)?;
+ collection.check_allowlist(owner)?;
}
}
@@ -305,8 +305,8 @@
amount: u128,
) -> DispatchResult {
if collection.access == AccessMode::WhiteList {
- collection.check_whitelist(&owner)?;
- collection.check_whitelist(&spender)?;
+ collection.check_allowlist(&owner)?;
+ collection.check_allowlist(&spender)?;
}
if <Balance<T>>::get((collection.id, owner.as_sub())) < amount {
@@ -334,7 +334,7 @@
}
if collection.access == AccessMode::WhiteList {
// `from`, `to` checked in [`transfer`]
- collection.check_whitelist(spender)?;
+ collection.check_allowlist(spender)?;
}
let allowance = <Allowance<T>>::get((collection.id, from.as_sub(), spender.as_sub()))
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -41,7 +41,7 @@
};
use pallet_common::{
account::CrossAccountId, CollectionHandle, IsAdmin, Pallet as PalletCommon,
- Error as CommonError, CommonWeightInfo,
+ Error as CommonError, CommonWeightInfo, Allowlist,
};
use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};
use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};
@@ -311,7 +311,7 @@
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
let collection = <CollectionHandle<T>>::try_get(collection_id)?;
- <PalletCommon<T>>::toggle_whitelist(
+ <PalletCommon<T>>::toggle_allowlist(
&collection,
&sender,
&address,
@@ -340,7 +340,7 @@
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
let collection = <CollectionHandle<T>>::try_get(collection_id)?;
- <PalletCommon<T>>::toggle_whitelist(
+ <PalletCommon<T>>::toggle_allowlist(
&collection,
&sender,
&address,
@@ -923,3 +923,17 @@
}
}
}
+
+// TODO: limit returned entries?
+impl<T: Config> Pallet<T> {
+ pub fn adminlist(collection: CollectionId) -> Vec<T::AccountId> {
+ <IsAdmin<T>>::iter_prefix((collection,))
+ .map(|(a, _)| a)
+ .collect()
+ }
+ pub fn allowlist(collection: CollectionId) -> Vec<T::AccountId> {
+ <Allowlist<T>>::iter_prefix((collection,))
+ .map(|(a, _)| a)
+ .collect()
+ }
+}
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -185,6 +185,10 @@
<Pallet<T>>::token_exists(self, token)
}
+ fn last_token_id(&self) -> TokenId {
+ TokenId(<TokensMinted<T>>::get(self.id))
+ }
+
fn token_owner(&self, token: TokenId) -> T::CrossAccountId {
<Owner<T>>::get((self.id, token))
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -198,7 +198,7 @@
);
if collection.access == AccessMode::WhiteList {
- collection.check_whitelist(sender)?;
+ collection.check_allowlist(sender)?;
}
let burnt = <TokensBurnt<T>>::get(collection.id)
@@ -246,8 +246,8 @@
);
if collection.access == AccessMode::WhiteList {
- collection.check_whitelist(from)?;
- collection.check_whitelist(to)?;
+ collection.check_allowlist(from)?;
+ collection.check_allowlist(to)?;
}
<PalletCommon<T>>::ensure_correct_receiver(to)?;
@@ -314,10 +314,10 @@
collection.mint_mode,
<CommonError<T>>::PublicMintingNotAllowed
);
- collection.check_whitelist(sender)?;
+ collection.check_allowlist(sender)?;
for item in data.iter() {
- collection.check_whitelist(&item.owner)?;
+ collection.check_allowlist(&item.owner)?;
}
}
@@ -453,9 +453,9 @@
spender: Option<&T::CrossAccountId>,
) -> DispatchResult {
if collection.access == AccessMode::WhiteList {
- collection.check_whitelist(&sender)?;
+ collection.check_allowlist(&sender)?;
if let Some(spender) = spender {
- collection.check_whitelist(&spender)?;
+ collection.check_allowlist(&spender)?;
}
}
@@ -488,7 +488,7 @@
}
if collection.access == AccessMode::WhiteList {
// `from`, `to` checked in [`transfer`]
- collection.check_whitelist(spender)?;
+ collection.check_allowlist(spender)?;
}
if <Allowance<T>>::get((collection.id, token)).as_ref() != Some(spender) {
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -268,8 +268,8 @@
);
if collection.access == AccessMode::WhiteList {
- collection.check_whitelist(from)?;
- collection.check_whitelist(to)?;
+ collection.check_allowlist(from)?;
+ collection.check_allowlist(to)?;
}
<PalletCommon<T>>::ensure_correct_receiver(to)?;
@@ -361,11 +361,11 @@
collection.mint_mode,
<CommonError<T>>::PublicMintingNotAllowed
);
- collection.check_whitelist(sender)?;
+ collection.check_allowlist(sender)?;
for item in data.iter() {
for (user, _) in &item.users {
- collection.check_whitelist(&user)?;
+ collection.check_allowlist(&user)?;
}
}
}
@@ -485,8 +485,8 @@
amount: u128,
) -> DispatchResult {
if collection.access == AccessMode::WhiteList {
- collection.check_whitelist(&sender)?;
- collection.check_whitelist(&spender)?;
+ collection.check_allowlist(&sender)?;
+ collection.check_allowlist(&spender)?;
}
<PalletCommon<T>>::ensure_correct_receiver(spender)?;
@@ -517,7 +517,7 @@
}
if collection.access == AccessMode::WhiteList {
// `from`, `to` checked in [`transfer`]
- collection.check_whitelist(spender)?;
+ collection.check_allowlist(spender)?;
}
let allowance = <Allowance<T>>::get((collection.id, token, from.as_sub(), &spender))
primitives/rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -3,9 +3,11 @@
use nft_data_structs::{CollectionId, TokenId};
use sp_std::vec::Vec;
use sp_core::H160;
+use codec::Decode;
sp_api::decl_runtime_apis! {
pub trait NftApi<CrossAccountId, AccountId> where
+ AccountId: Decode,
CrossAccountId: pallet_common::account::CrossAccountId<AccountId>,
{
fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>;
@@ -27,5 +29,9 @@
/// Used for ethereum integration
fn eth_contract_code(account: H160) -> Option<Vec<u8>>;
+
+ fn adminlist(collection: CollectionId) -> Vec<AccountId>;
+ fn allowlist(collection: CollectionId) -> Vec<AccountId>;
+ fn last_token_id(collection: CollectionId) -> TokenId;
}
}
runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -972,6 +972,15 @@
fn eth_contract_code(account: H160) -> Option<Vec<u8>> {
<pallet_nft::NftErcSupport<Runtime>>::get_code(&account)
}
+ fn adminlist(collection: CollectionId) -> Vec<AccountId> {
+ <pallet_nft::Pallet<Runtime>>::adminlist(collection)
+ }
+ fn allowlist(collection: CollectionId) -> Vec<AccountId> {
+ <pallet_nft::Pallet<Runtime>>::allowlist(collection)
+ }
+ fn last_token_id(collection: CollectionId) -> TokenId {
+ dispatch_nft_runtime!(collection.last_token_id())
+ }
}
impl sp_api::Core<Block> for Runtime {