Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Rename credential filter
  • Loading branch information
ntn-x2 committed Oct 19, 2022
commit 3232d485bcbd559a8ebb87358864ed515df08fa8
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions nodes/common/src/public_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

use serde::{Deserialize, Serialize};

use kilt_support::deposit::Deposit;
use kilt_support::{deposit::Deposit, traits::ItemFilter};
use public_credentials::CredentialEntry;

use public_credentials_rpc::PublicCredentialsFilter;

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
/// Thin wrapper around a runtime credential entry as specified in the
/// `public-credentials` pallet. This wrapper implements all the
/// (de-)serialization logic.
Expand Down Expand Up @@ -68,7 +67,7 @@ pub enum PublicCredentialFilter<CTypeHash, Attester> {
}

impl<CTypeHash, Attester, BlockNumber, AccountId, Balance, AuthorizationId>
PublicCredentialsFilter<CredentialEntry<CTypeHash, Attester, BlockNumber, AccountId, Balance, AuthorizationId>>
ItemFilter<CredentialEntry<CTypeHash, Attester, BlockNumber, AccountId, Balance, AuthorizationId>>
for PublicCredentialFilter<CTypeHash, Attester>
where
CTypeHash: Eq,
Expand Down
1 change: 1 addition & 0 deletions rpc/public-credentials/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sp-blockchain = {git = "https://github.com/paritytech/substrate", default-featur
sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29"}

# Internal runtime dependencies
kilt-support = {path = "../../support"}
public-credentials-runtime-api = {version = "1.8.0", path = "./runtime-api"}

[features]
Expand Down
8 changes: 2 additions & 6 deletions rpc/public-credentials/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::{generic::BlockId, traits::Block as BlockT};

/// Filter that can be used after the credentials for a given subject have been
/// retrieved from the blockchain state.
pub trait PublicCredentialsFilter<Credential> {
fn should_include(&self, credential: &Credential) -> bool;
}
use kilt_support::traits::ItemFilter;

#[rpc(client, server, namespace = "publicCredentials")]
pub trait PublicCredentialsApi<BlockHash, OuterSubjectId, OuterCredentialId, OuterCredentialEntry, CredentialFilter> {
Expand Down Expand Up @@ -161,7 +157,7 @@ impl<
CredentialId: Codec + Send + Sync + 'static + TryFrom<OuterCredentialId> + Into<OuterCredentialId>,
CredentialEntry: Codec + Send + Sync + 'static,
OuterCredentialEntry: Send + Sync + 'static + From<CredentialEntry>,
CredentialFilter: Send + Sync + 'static + PublicCredentialsFilter<CredentialEntry>,
CredentialFilter: Send + Sync + 'static + ItemFilter<CredentialEntry>,
{
fn get_credential(
&self,
Expand Down
5 changes: 5 additions & 0 deletions support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ pub trait GenerateBenchmarkOrigin<OuterOrigin, AccountId, SubjectId> {
pub trait GetWorstCase {
fn worst_case() -> Self;
}

/// Generic filter.
pub trait ItemFilter<Item> {
fn should_include(&self, credential: &Item) -> bool;
}
Comment on lines +80 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a similar trait in Frame support(?).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about InstanceFilter ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but in the last conversation we had (#378 (comment))
we agreed we don't need any superset logic, so I would rather not use that. I would be happy to use any other trait that would work, otherwise we can keep it as it is, and get rid of it in the future if needed.