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
Accept raw asset DID for runtime API
  • Loading branch information
ntn-x2 committed Oct 19, 2022
commit 52aeb5c97351525d05cb5b57ed8cf52eaa502c28
7 changes: 4 additions & 3 deletions rpc/public-credentials/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ use sp_std::vec::Vec;

sp_api::decl_runtime_apis! {
/// The API to query public credentials for a subject.
pub trait PublicCredentials<SubjectId, CredentialId, CredentialEntry> where
pub trait PublicCredentials<SubjectId, CredentialId, CredentialEntry, Error> where
SubjectId: Codec,
CredentialId: Codec,
CredentialEntry: Codec
CredentialEntry: Codec,
Error: Codec,
{
fn get_credential(credential_id: CredentialId) -> Option<CredentialEntry>;
fn get_credentials(subject: SubjectId) -> Vec<(CredentialId, CredentialEntry)>;
fn get_credentials(subject: SubjectId) -> Result<Vec<(CredentialId, CredentialEntry)>, Error>;
}
}
1 change: 1 addition & 0 deletions runtimes/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use sp_std::marker::PhantomData;
pub mod assets;
pub mod authorization;
pub mod constants;
pub mod errors;
pub mod fees;
pub mod migrations;
pub mod pallet_id;
Expand Down
8 changes: 5 additions & 3 deletions runtimes/standalone/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use runtime_common::{
assets::AssetDid,
authorization::{AuthorizationId, PalletAuthorize},
constants::{self, EXISTENTIAL_DEPOSIT, KILT},
errors::PublicCredentialsApiError,
fees::ToAuthor,
AccountId, Balance, BlockNumber, DidIdentifier, Hash, Index, Signature, SlowAdjustingFeeUpdate,
};
Expand Down Expand Up @@ -1041,14 +1042,15 @@ impl_runtime_apis! {
}
}

impl public_credentials_runtime_api::PublicCredentials<Block, AssetDid, Hash, public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<<Runtime as delegation::Config>::DelegationNodeId>>> for Runtime {
impl public_credentials_runtime_api::PublicCredentials<Block, Vec<u8>, Hash, public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<<Runtime as delegation::Config>::DelegationNodeId>>, PublicCredentialsApiError> for Runtime {
fn get_credential(credential_id: Hash) -> Option<public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<<Runtime as delegation::Config>::DelegationNodeId>>> {
let subject = public_credentials::CredentialSubjects::<Runtime>::get(&credential_id)?;
public_credentials::Credentials::<Runtime>::get(&subject, &credential_id)
}

fn get_credentials(subject: <Runtime as public_credentials::Config>::SubjectId) -> Vec<(Hash, public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<<Runtime as delegation::Config>::DelegationNodeId>>)> {
public_credentials::Credentials::<Runtime>::iter_prefix(&subject).collect()
fn get_credentials(subject: Vec<u8>) -> Result<Vec<(Hash, public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<<Runtime as delegation::Config>::DelegationNodeId>>)>, PublicCredentialsApiError> {
let asset_did = AssetDid::try_from(subject).map_err(|_| PublicCredentialsApiError::InvalidSubjectId)?;
Ok(public_credentials::Credentials::<Runtime>::iter_prefix(&asset_did).collect())
}
}

Expand Down