diff --git a/Cargo.lock b/Cargo.lock index 739317646a..dfea592dcb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2008,19 +2008,6 @@ dependencies = [ "substrate-wasm-builder", ] -[[package]] -name = "did-rpc" -version = "1.7.4" -dependencies = [ - "did-rpc-runtime-api", - "jsonrpsee", - "parity-scale-codec", - "sp-api", - "sp-blockchain", - "sp-core", - "sp-runtime", -] - [[package]] name = "did-rpc-runtime-api" version = "1.7.4" @@ -3657,7 +3644,6 @@ dependencies = [ "cumulus-relay-chain-interface", "cumulus-relay-chain-rpc-interface", "derive_more", - "did-rpc", "frame-benchmarking", "frame-benchmarking-cli", "futures 0.3.24", @@ -3665,7 +3651,6 @@ dependencies = [ "jsonrpsee", "log", "node-common", - "pallet-did-lookup", "pallet-transaction-payment-rpc", "parity-scale-codec", "parking_lot 0.12.1", @@ -4638,7 +4623,6 @@ name = "mashnet-node" version = "1.7.4" dependencies = [ "clap", - "did-rpc", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", @@ -4647,7 +4631,6 @@ dependencies = [ "log", "mashnet-node-runtime", "node-common", - "pallet-did-lookup", "pallet-transaction-payment", "pallet-transaction-payment-rpc", "public-credentials", diff --git a/Cargo.toml b/Cargo.toml index a91307b735..16e6b28fb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,6 @@ panic = "unwind" members = [ "nodes/*", "pallets/*", - "rpc/did", "rpc/did/runtime-api", "rpc/public-credentials", "rpc/public-credentials/runtime-api", diff --git a/nodes/parachain/Cargo.toml b/nodes/parachain/Cargo.toml index c34534827f..cc6e29a426 100644 --- a/nodes/parachain/Cargo.toml +++ b/nodes/parachain/Cargo.toml @@ -17,9 +17,7 @@ substrate-build-script-utils = {git = "https://github.com/paritytech/substrate", # Internal dependencies clone-runtime = {path = "../../runtimes/clone"} -did-rpc = {path = "../../rpc/did"} node-common = {path = "../common"} -pallet-did-lookup = {path = "../../pallets/pallet-did-lookup"} peregrine-runtime = {path = "../../runtimes/peregrine"} public-credentials = {path = "../../pallets/public-credentials"} public-credentials-rpc = {path = "../../rpc/public-credentials"} @@ -106,7 +104,6 @@ fast-gov = [ "runtime-common/fast-gov", ] runtime-benchmarks = [ - "pallet-did-lookup/runtime-benchmarks", "polkadot-service/runtime-benchmarks", "peregrine-runtime/runtime-benchmarks", "public-credentials/runtime-benchmarks", diff --git a/nodes/parachain/src/rpc.rs b/nodes/parachain/src/rpc.rs index 26e189a3b5..8cc5ff4ca4 100644 --- a/nodes/parachain/src/rpc.rs +++ b/nodes/parachain/src/rpc.rs @@ -33,7 +33,6 @@ use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; -use pallet_did_lookup::linkable_account::LinkableAccountId; use public_credentials::CredentialEntry; use runtime_common::{ assets::AssetDid, authorization::AuthorizationId, AccountId, Balance, Block, BlockNumber, DidIdentifier, Hash, @@ -59,7 +58,6 @@ where C::Api: frame_rpc_system::AccountNonceApi, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, C::Api: BlockBuilder, - C::Api: did_rpc::DidRuntimeApi, C::Api: public_credentials_rpc::PublicCredentialsRuntimeApi< Block, AssetDid, @@ -68,7 +66,6 @@ where >, P: TransactionPool + 'static, { - use did_rpc::{DidApiServer, DidQuery}; use frame_rpc_system::{System, SystemApiServer}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; use public_credentials_rpc::{PublicCredentialsApiServer, PublicCredentialsQuery}; @@ -87,7 +84,6 @@ where // to call into the runtime. // // `module.merge(YourRpcStruct::new(ReferenceToClient).into_rpc())?;` - module.merge(DidQuery::new(client.clone()).into_rpc())?; module.merge( PublicCredentialsQuery::< C, diff --git a/nodes/parachain/src/service.rs b/nodes/parachain/src/service.rs index 1e45b885b2..a103b7a40a 100644 --- a/nodes/parachain/src/service.rs +++ b/nodes/parachain/src/service.rs @@ -42,7 +42,6 @@ use sp_runtime::traits::BlakeTwo256; use std::{sync::Arc, time::Duration}; use substrate_prometheus_endpoint::Registry; -use pallet_did_lookup::linkable_account::LinkableAccountId; use public_credentials::CredentialEntry; use runtime_common::{ assets::AssetDid, authorization::AuthorizationId, AccountId, AuthorityId, Balance, BlockNumber, DidIdentifier, @@ -257,7 +256,6 @@ where + cumulus_primitives_core::CollectCollationInfo + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi + frame_rpc_system::AccountNonceApi - + did_rpc::DidRuntimeApi + public_credentials_rpc::PublicCredentialsRuntimeApi< Block, AssetDid, @@ -502,7 +500,6 @@ where + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi + sp_consensus_aura::AuraApi + cumulus_primitives_core::CollectCollationInfo - + did_rpc::DidRuntimeApi + public_credentials_rpc::PublicCredentialsRuntimeApi< Block, AssetDid, diff --git a/nodes/standalone/Cargo.toml b/nodes/standalone/Cargo.toml index 61feb9d608..4686f2d51e 100644 --- a/nodes/standalone/Cargo.toml +++ b/nodes/standalone/Cargo.toml @@ -15,10 +15,8 @@ substrate-build-script-utils = {git = "https://github.com/paritytech/substrate", [dependencies] # Internal dependencies -did-rpc = {path = "../../rpc/did"} mashnet-node-runtime = {path = "../../runtimes/standalone"} node-common = {path = "../common"} -pallet-did-lookup = {path = "../../pallets/pallet-did-lookup"} public-credentials = {path = "../../pallets/public-credentials"} public-credentials-rpc = {path = "../../rpc/public-credentials"} runtime-common = {path = "../../runtimes/common"} @@ -77,7 +75,6 @@ try-runtime-cli = {git = "https://github.com/paritytech/substrate", branch = "po default = [] runtime-benchmarks = [ "mashnet-node-runtime/runtime-benchmarks", - "pallet-did-lookup/runtime-benchmarks", "public-credentials/runtime-benchmarks", "runtime-common/runtime-benchmarks", ] diff --git a/nodes/standalone/src/rpc.rs b/nodes/standalone/src/rpc.rs index d3cf5d45f0..a4174c8bc7 100644 --- a/nodes/standalone/src/rpc.rs +++ b/nodes/standalone/src/rpc.rs @@ -33,7 +33,6 @@ use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; -use pallet_did_lookup::linkable_account::LinkableAccountId; use public_credentials::CredentialEntry; use runtime_common::{ assets::AssetDid, authorization::AuthorizationId, AccountId, Balance, Block, BlockNumber, DidIdentifier, Hash, @@ -59,7 +58,6 @@ where C::Api: frame_rpc_system::AccountNonceApi, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, C::Api: BlockBuilder, - C::Api: did_rpc::DidRuntimeApi, C::Api: public_credentials_rpc::PublicCredentialsRuntimeApi< Block, AssetDid, @@ -68,7 +66,6 @@ where >, P: TransactionPool + 'static, { - use did_rpc::{DidApiServer, DidQuery}; use frame_rpc_system::{System, SystemApiServer}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; use public_credentials_rpc::{PublicCredentialsApiServer, PublicCredentialsQuery}; @@ -88,7 +85,6 @@ where // to call into the runtime. // // `module.merge(YourRpcStruct::new(ReferenceToClient).into_rpc())?;` - module.merge(DidQuery::new(client.clone()).into_rpc())?; module.merge( PublicCredentialsQuery::< C, diff --git a/rpc/did/Cargo.toml b/rpc/did/Cargo.toml deleted file mode 100644 index b352459745..0000000000 --- a/rpc/did/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -edition = "2021" -name = "did-rpc" -version = "1.7.4" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.1.5" } -jsonrpsee = { version = "0.15.1", features = ["server", "macros"] } - -did-rpc-runtime-api = {version = "1.7.2", path = "./runtime-api"} - -sp-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29"} -sp-blockchain = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29"} -sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29"} -sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29"} - -[features] -default = ["std"] -std = [ - "codec/std", - "did-rpc-runtime-api/std", - "sp-api/std", - "sp-core/std", - "sp-runtime/std", -] diff --git a/rpc/did/runtime-api/src/lib.rs b/rpc/did/runtime-api/src/lib.rs index 5f01ed0ea4..cc44451286 100644 --- a/rpc/did/runtime-api/src/lib.rs +++ b/rpc/did/runtime-api/src/lib.rs @@ -103,7 +103,8 @@ pub type RawDidLinkedInfo; sp_api::decl_runtime_apis! { - /// The API to query account nonce (aka transaction index). + #[api_version(2)] + /// The API to query DID information. pub trait DidApi where DidIdentifier: Codec, AccountId: Codec, @@ -118,6 +119,8 @@ sp_api::decl_runtime_apis! { /// * the web3name (optional) /// * associated accounts /// * service endpoints + #[changed_in(2)] + fn query_did_by_w3n(name: Vec) -> Option>; fn query_did_by_w3n(name: Vec) -> Option>; /// Given an account address this returns: /// * the DID @@ -125,6 +128,9 @@ sp_api::decl_runtime_apis! { /// * 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>; fn query_did_by_account_id(account: LinkableAccountId) -> Option>; /// Given a did this returns: /// * the DID @@ -132,6 +138,8 @@ sp_api::decl_runtime_apis! { /// * the web3name (optional) /// * associated accounts /// * service endpoints - fn query_did(did: DidIdentifier) -> Option>; + #[changed_in(2)] + fn query_did(did: DidIdentifier) -> Option>; + fn query_did(did: DidIdentifier) -> Option>; } } diff --git a/rpc/did/src/lib.rs b/rpc/did/src/lib.rs deleted file mode 100644 index fc6e44ada5..0000000000 --- a/rpc/did/src/lib.rs +++ /dev/null @@ -1,261 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The KILT Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -use std::{fmt::Display, str::FromStr, sync::Arc}; - -use codec::{Codec, MaxEncodedLen}; -use did_rpc_runtime_api::{DidLinkedInfo, ServiceEndpoint}; -use jsonrpsee::{ - core::{async_trait, RpcResult}, - proc_macros::rpc, - types::error::{CallError, ErrorObject}, -}; -use sp_api::ProvideRuntimeApi; -use sp_blockchain::HeaderBackend; -use sp_runtime::{generic::BlockId, traits::Block as BlockT}; - -pub use did_rpc_runtime_api::DidApi as DidRuntimeApi; - -pub type RpcDidLinkedInfo = DidLinkedInfo< - DidIdentifier, - AccountId, - LinkableAccountId, - String, - String, - String, - String, - Balance, - Key, - BlockNumber, ->; - -fn raw_did_endpoint_to_rpc( - raw: ServiceEndpoint, Vec, Vec>, -) -> Option> { - Some(ServiceEndpoint { - id: String::from_utf8(raw.id).ok()?, - service_types: raw - .service_types - .into_iter() - .filter_map(|st| String::from_utf8(st).ok()) - .collect(), - urls: raw - .urls - .into_iter() - .filter_map(|url| String::from_utf8(url).ok()) - .collect(), - }) -} - -pub type DidRpcResponse = - Option>; - -#[rpc(client, server)] -pub trait DidApi -where - BlockNumber: MaxEncodedLen, - Key: Ord, - Balance: FromStr + Display, -{ - /// Given a web3name this returns: - /// * the DID - /// * public keys stored for the did - /// * the web3name (optional) - /// * associated accounts - /// * service endpoints - #[method(name = "did_queryByWeb3Name")] - fn query_did_by_w3n( - &self, - web3name: String, - at: Option, - ) -> RpcResult>; - - /// Given an account this returns: - /// * the DID - /// * public keys stored for the did - /// * the web3name (optional) - /// * associated accounts - /// * service endpoints - #[method(name = "did_queryByAccount")] - fn query_did_by_account_id( - &self, - account: LinkableAccountId, - at: Option, - ) -> RpcResult>; - - /// Given a did this returns: - /// * the DID - /// * public keys stored for the did - /// * the web3name (optional) - /// * associated accounts - /// * service endpoints - #[method(name = "did_query")] - fn query_did( - &self, - account: DidIdentifier, - at: Option, - ) -> RpcResult>; -} - -/// A struct that implements the [`DidRuntimeApi`]. -pub struct DidQuery { - client: Arc, - _marker: std::marker::PhantomData, -} - -impl DidQuery { - /// Create new `DidQuery` with the given reference to the client. - pub fn new(client: Arc) -> Self { - Self { - client, - _marker: Default::default(), - } - } -} - -/// Error type of this RPC api. -pub enum Error { - /// The transaction was not decodable. - DecodeError, - /// The call to runtime failed. - RuntimeError, -} - -impl From for i32 { - fn from(e: Error) -> i32 { - match e { - Error::RuntimeError => 1, - Error::DecodeError => 2, - } - } -} - -#[async_trait] -impl - DidApiServer<::Hash, DidIdentifier, AccountId, LinkableAccountId, Balance, Key, BlockNumber> - for DidQuery -where - AccountId: Codec + Send + Sync + 'static, - LinkableAccountId: Codec + Send + Sync + 'static, - DidIdentifier: Codec + Send + Sync + 'static, - Key: Codec + Ord, - Balance: Codec + FromStr + Display, - BlockNumber: Codec + MaxEncodedLen, - Block: BlockT, - Client: Send + Sync + 'static + ProvideRuntimeApi + HeaderBackend, - Client::Api: DidRuntimeApi, -{ - fn query_did_by_w3n( - &self, - web3name: String, - at: Option<::Hash>, - ) -> RpcResult>> { - let api = self.client.runtime_api(); - let at = BlockId::hash(at.unwrap_or_else(|| - // If the block hash is not provided, assume the best block. - self.client.info().best_hash)); - - match api.query_did_by_w3n(&at, web3name.into()) { - Err(e) => Err(CallError::Custom(ErrorObject::owned( - Error::RuntimeError.into(), - "Unable to query DID by web3name.", - Some(format!("{:?}", e)), - )) - .into()), - Ok(doc) => Ok(doc.map(|doc| RpcDidLinkedInfo { - // convert the w3n from a byte array to a string. if it's invalid utf-8 which should never happen, we - // ignore the w3n and pretend it doesn't exist. - w3n: doc.w3n.and_then(|w3n| String::from_utf8(w3n).ok()), - accounts: doc.accounts, - identifier: doc.identifier, - service_endpoints: doc - .service_endpoints - .into_iter() - .filter_map(raw_did_endpoint_to_rpc) - .collect(), - details: doc.details, - })), - } - } - - fn query_did_by_account_id( - &self, - account: LinkableAccountId, - at: Option<::Hash>, - ) -> RpcResult>> { - let api = self.client.runtime_api(); - let at = BlockId::hash(at.unwrap_or_else(|| - // If the block hash is not supplied assume the best block. - self.client.info().best_hash)); - - match api.query_did_by_account_id(&at, account) { - Err(e) => Err(CallError::Custom(ErrorObject::owned( - Error::RuntimeError.into(), - "Unable to query account by DID.", - Some(format!("{:?}", e)), - )) - .into()), - Ok(doc) => Ok(doc.map(|doc| RpcDidLinkedInfo { - // convert the w3n from a byte array to a string. if it's invalid utf-8 which should never happen, we - // ignore the w3n and pretend it doesn't exist. - w3n: doc.w3n.and_then(|w3n| String::from_utf8(w3n).ok()), - accounts: doc.accounts, - identifier: doc.identifier, - service_endpoints: doc - .service_endpoints - .into_iter() - .filter_map(raw_did_endpoint_to_rpc) - .collect(), - details: doc.details, - })), - } - } - - fn query_did( - &self, - did: DidIdentifier, - at: Option<::Hash>, - ) -> RpcResult>> { - let api = self.client.runtime_api(); - let at = BlockId::hash(at.unwrap_or_else(|| - // If the block hash is not supplied assume the best block. - self.client.info().best_hash)); - - match api.query_did(&at, did) { - Err(e) => Err(CallError::Custom(ErrorObject::owned( - Error::RuntimeError.into(), - "Unable to query DID details.", - Some(format!("{:?}", e)), - )) - .into()), - Ok(doc) => Ok(doc.map(|doc| RpcDidLinkedInfo { - // convert the w3n from a byte array to a string. if it's invalid utf-8 which should never happen, we - // ignore the w3n and pretend it doesn't exist. - w3n: doc.w3n.and_then(|w3n| String::from_utf8(w3n).ok()), - accounts: doc.accounts, - identifier: doc.identifier, - service_endpoints: doc - .service_endpoints - .into_iter() - .filter_map(raw_did_endpoint_to_rpc) - .collect(), - details: doc.details, - })), - } - } -}