Skip to content

Commit

Permalink
Remove old DID runtime API (#425)
Browse files Browse the repository at this point in the history
Co-authored-by: William Freudenberger <william@kilt.io>
  • Loading branch information
ntn-x2 and wischli authored Oct 21, 2022
1 parent b84929a commit 5a14b10
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 207 deletions.
46 changes: 6 additions & 40 deletions rpc/did/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,47 +103,7 @@ pub type RawDidLinkedInfo<DidIdentifier, AccountId, LinkableAccountId, Balance,
>;

sp_api::decl_runtime_apis! {
// TODO: Remove this runtime API when the SDK team agrees that it is time to introduce a breaking change.
#[api_version(2)]
/// The API to query DID information.
pub trait DidApi<DidIdentifier, AccountId, LinkableAccountId, Balance, Key: Ord, BlockNumber> where
DidIdentifier: Codec,
AccountId: Codec,
LinkableAccountId: Codec,
BlockNumber: Codec + MaxEncodedLen,
Key: Codec,
Balance: Codec,
{
/// Given a web3name this returns:
/// * the DID
/// * public keys stored for the did
/// * the web3name (optional)
/// * associated accounts
/// * service endpoints
#[changed_in(2)]
fn query_did_by_w3n(name: Vec<u8>) -> Option<RawDidLinkedInfo<DidIdentifier, AccountId, AccountId, Balance, Key, BlockNumber>>;
fn query_did_by_w3n(name: Vec<u8>) -> Option<RawDidLinkedInfo<DidIdentifier, AccountId, LinkableAccountId, Balance, Key, BlockNumber>>;
/// Given an account address this returns:
/// * the DID
/// * public keys stored for the did
/// * the web3name (optional)
/// * associated accounts
/// * service endpoints
// See https://paritytech.github.io/substrate/master/sp_api/macro.decl_runtime_apis.html#declaring-multiple-api-versions for more details
#[changed_in(2)]
fn query_did_by_account_id(account: AccountId) -> Option<RawDidLinkedInfo<DidIdentifier, AccountId, AccountId, Balance, Key, BlockNumber>>;
fn query_did_by_account_id(account: LinkableAccountId) -> Option<RawDidLinkedInfo<DidIdentifier, AccountId, LinkableAccountId, Balance, Key, BlockNumber>>;
/// Given a did this returns:
/// * the DID
/// * public keys stored for the did
/// * the web3name (optional)
/// * associated accounts
/// * service endpoints
#[changed_in(2)]
fn query_did(did: DidIdentifier) -> Option<RawDidLinkedInfo<DidIdentifier, AccountId, AccountId, Balance, Key, BlockNumber>>;
fn query_did(did: DidIdentifier) -> Option<RawDidLinkedInfo<DidIdentifier, AccountId, LinkableAccountId, Balance, Key, BlockNumber>>;
}

pub trait Did<DidIdentifier, AccountId, LinkableAccountId, Balance, Key: Ord, BlockNumber> where
DidIdentifier: Codec,
AccountId: Codec,
Expand All @@ -158,20 +118,26 @@ sp_api::decl_runtime_apis! {
/// * the web3name (optional)
/// * associated accounts
/// * service endpoints
#[changed_in(2)]
fn query_by_web3_name(name: Vec<u8>) -> Option<RawDidLinkedInfo<DidIdentifier, AccountId, AccountId, Balance, Key, BlockNumber>>;
fn query_by_web3_name(name: Vec<u8>) -> Option<RawDidLinkedInfo<DidIdentifier, AccountId, LinkableAccountId, Balance, Key, BlockNumber>>;
/// Given an account address this returns:
/// * the DID
/// * public keys stored for the did
/// * the web3name (optional)
/// * associated accounts
/// * service endpoints
#[changed_in(2)]
fn query_by_account(account: AccountId) -> Option<RawDidLinkedInfo<DidIdentifier, AccountId, AccountId, Balance, Key, BlockNumber>>;
fn query_by_account(account: LinkableAccountId) -> Option<RawDidLinkedInfo<DidIdentifier, AccountId, LinkableAccountId, Balance, Key, BlockNumber>>;
/// Given a did this returns:
/// * the DID
/// * public keys stored for the did
/// * the web3name (optional)
/// * associated accounts
/// * service endpoints
#[changed_in(2)]
fn query(did: DidIdentifier) -> Option<RawDidLinkedInfo<DidIdentifier, AccountId, AccountId, Balance, Key, BlockNumber>>;
fn query(did: DidIdentifier) -> Option<RawDidLinkedInfo<DidIdentifier, AccountId, LinkableAccountId, Balance, Key, BlockNumber>>;
}
}
8 changes: 4 additions & 4 deletions runtimes/clone/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ impl_runtime_apis! {
}

// Solely required from parachain client
impl did_rpc_runtime_api::DidApi<
impl did_rpc_runtime_api::Did<
Block,
AccountId,
AccountId,
Expand All @@ -540,7 +540,7 @@ impl_runtime_apis! {
Hash,
BlockNumber
> for Runtime {
fn query_did_by_w3n(_: Vec<u8>) -> Option<did_rpc_runtime_api::RawDidLinkedInfo<
fn query_by_web3_name(_: Vec<u8>) -> Option<did_rpc_runtime_api::RawDidLinkedInfo<
AccountId,
AccountId,
LinkableAccountId,
Expand All @@ -552,7 +552,7 @@ impl_runtime_apis! {
None
}

fn query_did_by_account_id(_: LinkableAccountId) -> Option<
fn query_by_account(_: LinkableAccountId) -> Option<
did_rpc_runtime_api::RawDidLinkedInfo<
AccountId,
AccountId,
Expand All @@ -565,7 +565,7 @@ impl_runtime_apis! {
None
}

fn query_did(_: AccountId) -> Option<
fn query(_: AccountId) -> Option<
did_rpc_runtime_api::RawDidLinkedInfo<
AccountId,
AccountId,
Expand Down
63 changes: 8 additions & 55 deletions runtimes/peregrine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ use sp_version::RuntimeVersion;
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;
Expand Down Expand Up @@ -1152,7 +1151,7 @@ impl_runtime_apis! {
}
}

impl did_rpc_runtime_api::DidApi<
impl did_rpc_runtime_api::Did<
Block,
DidIdentifier,
AccountId,
Expand All @@ -1161,7 +1160,7 @@ impl_runtime_apis! {
Hash,
BlockNumber
> for Runtime {
fn query_did_by_w3n(name: Vec<u8>) -> Option<did_rpc_runtime_api::RawDidLinkedInfo<
fn query_by_web3_name(name: Vec<u8>) -> Option<did_rpc_runtime_api::RawDidLinkedInfo<
DidIdentifier,
AccountId,
LinkableAccountId,
Expand All @@ -1176,10 +1175,12 @@ impl_runtime_apis! {
did::Did::<Runtime>::get(&owner_info.owner).map(|details| (owner_info, details))
})
.map(|(owner_info, details)| {
let accounts = pallet_did_lookup::ConnectedAccounts::<Runtime>::iter_key_prefix(&owner_info.owner).collect();
let accounts = pallet_did_lookup::ConnectedAccounts::<Runtime>::iter_key_prefix(
&owner_info.owner,
).collect();
let service_endpoints = did::ServiceEndpoints::<Runtime>::iter_prefix(&owner_info.owner).map(|e| From::from(e.1)).collect();

did_rpc_runtime_api::RawDidLinkedInfo {
did_rpc_runtime_api::RawDidLinkedInfo{
identifier: owner_info.owner,
w3n: Some(name.into()),
accounts,
Expand All @@ -1189,7 +1190,7 @@ impl_runtime_apis! {
})
}

fn query_did_by_account_id(account: LinkableAccountId) -> Option<
fn query_by_account(account: LinkableAccountId) -> Option<
did_rpc_runtime_api::RawDidLinkedInfo<
DidIdentifier,
AccountId,
Expand Down Expand Up @@ -1218,7 +1219,7 @@ impl_runtime_apis! {
})
}

fn query_did(did: DidIdentifier) -> Option<
fn query(did: DidIdentifier) -> Option<
did_rpc_runtime_api::RawDidLinkedInfo<
DidIdentifier,
AccountId,
Expand All @@ -1243,54 +1244,6 @@ impl_runtime_apis! {
}
}

impl did_rpc_runtime_api::Did<
Block,
DidIdentifier,
AccountId,
LinkableAccountId,
Balance,
Hash,
BlockNumber
> for Runtime {
fn query_by_web3_name(name: Vec<u8>) -> Option<did_rpc_runtime_api::RawDidLinkedInfo<
DidIdentifier,
AccountId,
LinkableAccountId,
Balance,
Hash,
BlockNumber
>
> {
Self::query_did_by_w3n(name)
}

fn query_by_account(account: LinkableAccountId) -> Option<
did_rpc_runtime_api::RawDidLinkedInfo<
DidIdentifier,
AccountId,
LinkableAccountId,
Balance,
Hash,
BlockNumber
>
> {
Self::query_did_by_account_id(account)
}

fn query(did: DidIdentifier) -> Option<
did_rpc_runtime_api::RawDidLinkedInfo<
DidIdentifier,
AccountId,
LinkableAccountId,
Balance,
Hash,
BlockNumber
>
> {
Self::query_did(did)
}
}

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)?;
Expand Down
63 changes: 8 additions & 55 deletions runtimes/spiritnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ use sp_version::RuntimeVersion;
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;
Expand Down Expand Up @@ -1146,7 +1145,7 @@ impl_runtime_apis! {
}
}

impl did_rpc_runtime_api::DidApi<
impl did_rpc_runtime_api::Did<
Block,
DidIdentifier,
AccountId,
Expand All @@ -1155,7 +1154,7 @@ impl_runtime_apis! {
Hash,
BlockNumber
> for Runtime {
fn query_did_by_w3n(name: Vec<u8>) -> Option<did_rpc_runtime_api::RawDidLinkedInfo<
fn query_by_web3_name(name: Vec<u8>) -> Option<did_rpc_runtime_api::RawDidLinkedInfo<
DidIdentifier,
AccountId,
LinkableAccountId,
Expand All @@ -1170,10 +1169,12 @@ impl_runtime_apis! {
did::Did::<Runtime>::get(&owner_info.owner).map(|details| (owner_info, details))
})
.map(|(owner_info, details)| {
let accounts: Vec<LinkableAccountId> = pallet_did_lookup::ConnectedAccounts::<Runtime>::iter_key_prefix(&owner_info.owner).collect();
let accounts = pallet_did_lookup::ConnectedAccounts::<Runtime>::iter_key_prefix(
&owner_info.owner,
).collect();
let service_endpoints = did::ServiceEndpoints::<Runtime>::iter_prefix(&owner_info.owner).map(|e| From::from(e.1)).collect();

did_rpc_runtime_api::RawDidLinkedInfo {
did_rpc_runtime_api::RawDidLinkedInfo{
identifier: owner_info.owner,
w3n: Some(name.into()),
accounts,
Expand All @@ -1183,7 +1184,7 @@ impl_runtime_apis! {
})
}

fn query_did_by_account_id(account: LinkableAccountId) -> Option<
fn query_by_account(account: LinkableAccountId) -> Option<
did_rpc_runtime_api::RawDidLinkedInfo<
DidIdentifier,
AccountId,
Expand Down Expand Up @@ -1212,7 +1213,7 @@ impl_runtime_apis! {
})
}

fn query_did(did: DidIdentifier) -> Option<
fn query(did: DidIdentifier) -> Option<
did_rpc_runtime_api::RawDidLinkedInfo<
DidIdentifier,
AccountId,
Expand All @@ -1237,54 +1238,6 @@ impl_runtime_apis! {
}
}

impl did_rpc_runtime_api::Did<
Block,
DidIdentifier,
AccountId,
LinkableAccountId,
Balance,
Hash,
BlockNumber
> for Runtime {
fn query_by_web3_name(name: Vec<u8>) -> Option<did_rpc_runtime_api::RawDidLinkedInfo<
DidIdentifier,
AccountId,
LinkableAccountId,
Balance,
Hash,
BlockNumber
>
> {
Self::query_did_by_w3n(name)
}

fn query_by_account(account: LinkableAccountId) -> Option<
did_rpc_runtime_api::RawDidLinkedInfo<
DidIdentifier,
AccountId,
LinkableAccountId,
Balance,
Hash,
BlockNumber
>
> {
Self::query_did_by_account_id(account)
}

fn query(did: DidIdentifier) -> Option<
did_rpc_runtime_api::RawDidLinkedInfo<
DidIdentifier,
AccountId,
LinkableAccountId,
Balance,
Hash,
BlockNumber
>
> {
Self::query_did(did)
}
}

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)?;
Expand Down
Loading

0 comments on commit 5a14b10

Please sign in to comment.