diff --git a/rpc/did/runtime-api/src/lib.rs b/rpc/did/runtime-api/src/lib.rs index cc44451286..8aba8fd945 100644 --- a/rpc/did/runtime-api/src/lib.rs +++ b/rpc/did/runtime-api/src/lib.rs @@ -103,6 +103,7 @@ pub type RawDidLinkedInfo; 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 where @@ -142,4 +143,35 @@ sp_api::decl_runtime_apis! { fn query_did(did: DidIdentifier) -> Option>; fn query_did(did: DidIdentifier) -> Option>; } + + pub trait Did 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 + fn query_by_web3_name(name: Vec) -> Option>; + /// Given an account address this returns: + /// * the DID + /// * public keys stored for the did + /// * the web3name (optional) + /// * associated accounts + /// * service endpoints + fn query_by_account(account: LinkableAccountId) -> Option>; + /// Given a did this returns: + /// * the DID + /// * public keys stored for the did + /// * the web3name (optional) + /// * associated accounts + /// * service endpoints + fn query(did: DidIdentifier) -> Option>; + } } diff --git a/runtimes/peregrine/src/lib.rs b/runtimes/peregrine/src/lib.rs index 927383ec83..a1496e22ab 100644 --- a/runtimes/peregrine/src/lib.rs +++ b/runtimes/peregrine/src/lib.rs @@ -46,6 +46,7 @@ use sp_version::RuntimeVersion; use xcm_executor::XcmExecutor; use delegation::DelegationAc; +use did_rpc_runtime_api::runtime_decl_for_DidApi::DidApiV2; use pallet_did_lookup::{linkable_account::LinkableAccountId, migrations::EthereumMigration}; pub use parachain_staking::InflationInfo; pub use public_credentials; @@ -1240,6 +1241,54 @@ 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) -> Option + > { + 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::PublicCredentialsApi::DelegationNodeId>>> for Runtime { fn get_credential(credential_id: Hash) -> Option::DelegationNodeId>>> { let subject = public_credentials::CredentialSubjects::::get(&credential_id)?; diff --git a/runtimes/spiritnet/src/lib.rs b/runtimes/spiritnet/src/lib.rs index 44d5a596fd..00773952c6 100644 --- a/runtimes/spiritnet/src/lib.rs +++ b/runtimes/spiritnet/src/lib.rs @@ -46,6 +46,7 @@ use sp_version::RuntimeVersion; use xcm_executor::XcmExecutor; use delegation::DelegationAc; +use did_rpc_runtime_api::runtime_decl_for_DidApi::DidApiV2; use pallet_did_lookup::{linkable_account::LinkableAccountId, migrations::EthereumMigration}; pub use parachain_staking::InflationInfo; pub use public_credentials; @@ -1234,6 +1235,54 @@ 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) -> Option + > { + 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::PublicCredentialsApi::DelegationNodeId>>> for Runtime { fn get_credential(credential_id: Hash) -> Option::DelegationNodeId>>> { let subject = public_credentials::CredentialSubjects::::get(&credential_id)?; diff --git a/runtimes/standalone/src/lib.rs b/runtimes/standalone/src/lib.rs index 56749688f9..fae8ad923b 100644 --- a/runtimes/standalone/src/lib.rs +++ b/runtimes/standalone/src/lib.rs @@ -50,6 +50,7 @@ use sp_std::prelude::*; use sp_version::RuntimeVersion; use delegation::DelegationAc; +use did_rpc_runtime_api::runtime_decl_for_DidApi::DidApiV2; use pallet_did_lookup::{linkable_account::LinkableAccountId, migrations::EthereumMigration}; use runtime_common::{ assets::AssetDid, @@ -992,6 +993,54 @@ 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) -> Option + > { + 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::PublicCredentialsApi::DelegationNodeId>>> for Runtime { fn get_credential(credential_id: Hash) -> Option::DelegationNodeId>>> { let subject = public_credentials::CredentialSubjects::::get(&credential_id)?;