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
Whole project compiling
  • Loading branch information
ntn-x2 committed Oct 19, 2022
commit 901c0337d1a4a1124d0fa98bd2c5104d558e27fd
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.

1 change: 0 additions & 1 deletion nodes/parachain/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ where
{
use frame_rpc_system::{System, SystemApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use public_credentials_rpc::{PublicCredentialsApiServer, PublicCredentialsQuery};

let mut module = RpcModule::new(());
let FullDeps {
Expand Down
10 changes: 2 additions & 8 deletions nodes/parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ where
+ sp_block_builder::BlockBuilder<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+ frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
Executor: sc_executor::NativeExecutionDispatch + 'static,
RB: FnOnce(
Expand Down Expand Up @@ -493,13 +493,7 @@ where
+ frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ sp_consensus_aura::AuraApi<Block, AuthorityId>
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ public_credentials_rpc::PublicCredentialsRuntimeApi<
Block,
AssetDid,
Hash,
CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<Hash>>,
>,
+ cumulus_primitives_core::CollectCollationInfo<Block>,
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
{
start_node_impl::<API, RE, _, _, _>(
Expand Down
3 changes: 3 additions & 0 deletions runtimes/clone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public-credentials-runtime-api = {path = "../../rpc/public-credentials/runtime-a
# KILT pallets & primitives
pallet-did-lookup = {path = "../../pallets/pallet-did-lookup", default-features = false}
public-credentials = {path = "../../pallets/public-credentials", default-features = false}
kilt-support = {default-features = false, path = "../../support"}
runtime-common = {path = "../../runtimes/common", default-features = false}

# Substrate dependencies
Expand Down Expand Up @@ -96,6 +97,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system-benchmarking",
"frame-system/runtime-benchmarks",
"kilt-support/runtime-benchmarks",
"hex-literal",
"pallet-balances/runtime-benchmarks",
"pallet-did-lookup/runtime-benchmarks",
Expand Down Expand Up @@ -123,6 +125,7 @@ std = [
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"frame-try-runtime/std",
"kilt-support/std",
"log/std",
"pallet-aura/std",
"pallet-authorship/std",
Expand Down
12 changes: 7 additions & 5 deletions runtimes/clone/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ use sp_version::RuntimeVersion;
use xcm::opaque::latest::BodyId;
use xcm_executor::XcmExecutor;

use kilt_support::traits::ItemFilter;
use runtime_common::{
assets::AssetDid,
assets::{AssetDid, PublicCredentialsFilter},
authorization::AuthorizationId,
constants::{self, HOURS, MILLI_KILT},
errors::PublicCredentialsApiError,
fees::{ToAuthor, WeightToFee},
AccountId, AuthorityId, Balance, BlockHashCount, BlockLength, BlockNumber, BlockWeights, DidIdentifier, FeeSplit,
Hash, Header, Index, Signature, SlowAdjustingFeeUpdate,
Expand Down Expand Up @@ -578,13 +580,13 @@ impl_runtime_apis! {
}
}

impl public_credentials_runtime_api::PublicCredentials<Block, AssetDid, Hash, public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<Hash>>> for Runtime {
fn get_credential(_credential_id: Hash) -> Option<public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<Hash>>> {
impl public_credentials_runtime_api::PublicCredentials<Block, Vec<u8>, Hash, public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<Hash>>, PublicCredentialsFilter<Hash, AccountId>, PublicCredentialsApiError> for Runtime {
fn get_credential(credential_id: Hash) -> Option<public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<Hash>>> {
None
}

fn get_credentials(_subject: AssetDid) -> Vec<(Hash, public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<Hash>>)> {
vec![]
fn get_credentials(subject: Vec<u8>, filter: Option<PublicCredentialsFilter<Hash, AccountId>>) -> Result<Vec<(Hash, public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<Hash>>)>, PublicCredentialsApiError> {
Ok(vec![])
}
}

Expand Down
7 changes: 6 additions & 1 deletion runtimes/common/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@ impl TryFrom<String> for AssetDid {

/// Filter for public credentials retrieved for a provided subject as specified
/// in the runtime API interface.
#[derive(Encode, Decode, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub enum PublicCredentialsFilter<CTypeHash, Attester> {
/// Filter credentials that match a specified Ctype.
CtypeHash(CTypeHash),
/// Filter credentials that have been issued by the specified attester.
Attester(Attester),
}

#[test]
fn test_filter() {
print!("{:?}", PublicCredentialsFilter::<Hash, AccountId>::type_info());
}

impl ItemFilter<CredentialEntry<Hash, AccountId, BlockNumber, AccountId, Balance, AuthorizationId<Hash>>>
for PublicCredentialsFilter<Hash, AccountId>
{
Expand Down
1 change: 0 additions & 1 deletion runtimes/common/src/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use attestation::AttestationAccessControl;
use public_credentials::PublicCredentialsAccessControl;

#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum AuthorizationId<DelegationId> {
Delegation(DelegationId),
}
Expand Down
16 changes: 12 additions & 4 deletions runtimes/peregrine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ use xcm_executor::XcmExecutor;

use delegation::DelegationAc;
use did_rpc_runtime_api::runtime_decl_for_DidApi::DidApiV2;
use kilt_support::traits::ItemFilter;
use pallet_did_lookup::{linkable_account::LinkableAccountId, migrations::EthereumMigration};
pub use parachain_staking::InflationInfo;
pub use public_credentials;

use runtime_common::{
assets::AssetDid,
assets::{AssetDid, PublicCredentialsFilter},
authorization::{AuthorizationId, PalletAuthorize},
constants::{self, EXISTENTIAL_DEPOSIT, KILT},
errors::PublicCredentialsApiError,
fees::{ToAuthor, WeightToFee},
migrations, pallet_id, AccountId, AuthorityId, Balance, BlockHashCount, BlockLength, BlockNumber, BlockWeights,
DidIdentifier, FeeSplit, Hash, Header, Index, Signature, SlowAdjustingFeeUpdate,
Expand Down Expand Up @@ -1289,14 +1291,20 @@ 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>>, PublicCredentialsFilter<Hash, AccountId>, 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>, filter: Option<PublicCredentialsFilter<Hash, AccountId>>) -> 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)?;
let credentials_prefix = public_credentials::Credentials::<Runtime>::iter_prefix(&asset_did);
if let Some(filter) = filter {
Ok(credentials_prefix.filter(|(_, entry)| filter.should_include(&entry)).collect())
} else {
Ok(credentials_prefix.collect())
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions runtimes/spiritnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ use xcm_executor::XcmExecutor;

use delegation::DelegationAc;
use did_rpc_runtime_api::runtime_decl_for_DidApi::DidApiV2;
use kilt_support::traits::ItemFilter;
use pallet_did_lookup::{linkable_account::LinkableAccountId, migrations::EthereumMigration};
pub use parachain_staking::InflationInfo;
pub use public_credentials;

use runtime_common::{
assets::AssetDid,
assets::{AssetDid, PublicCredentialsFilter},
authorization::{AuthorizationId, PalletAuthorize},
constants::{self, EXISTENTIAL_DEPOSIT, KILT},
errors::PublicCredentialsApiError,
fees::{ToAuthor, WeightToFee},
migrations, pallet_id, AccountId, AuthorityId, Balance, BlockHashCount, BlockLength, BlockNumber, BlockWeights,
DidIdentifier, FeeSplit, Hash, Header, Index, Signature, SlowAdjustingFeeUpdate,
Expand Down Expand Up @@ -1283,14 +1285,20 @@ 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>>, PublicCredentialsFilter<Hash, AccountId>, 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>, filter: Option<PublicCredentialsFilter<Hash, AccountId>>) -> 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)?;
let credentials_prefix = public_credentials::Credentials::<Runtime>::iter_prefix(&asset_did);
if let Some(filter) = filter {
Ok(credentials_prefix.filter(|(_, entry)| filter.should_include(&entry)).collect())
} else {
Ok(credentials_prefix.collect())
}
}
}

Expand Down