Skip to content

Commit

Permalink
rpc update
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Jul 28, 2024
1 parent ba07bf2 commit 26ed94e
Show file tree
Hide file tree
Showing 12 changed files with 589 additions and 212 deletions.
205 changes: 183 additions & 22 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ frame-support-test = { git = "https://github.com/paritytech/polkadot-sdk.git", t
pallet-insecure-randomness-collective-flip = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
sp-npos-elections = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false}
log = { version = "0.4.17", default-features = false }
jsonrpsee = { version = "0.22", features = ["client-core", "macros", "server"] }
sc-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
hex-literal = { version= " 0.4.1" }
## New end

parity-scale-codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [
Expand All @@ -116,3 +120,4 @@ pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", tag
sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false}
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
66 changes: 21 additions & 45 deletions custom-pallets/department-funding/department-funding-rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use department_funding_runtime_api::DepartmentFundingApi as DepartmentFundingRuntimeApi;
use jsonrpsee::{
core::{Error as JsonRpseeError, RpcResult},
proc_macros::rpc,
types::error::{CallError, ErrorCode, ErrorObject},
core::RpcResult,
proc_macros::rpc,
types::{ErrorObject, ErrorObjectOwned},
};
use parity_scale_codec::Codec;
use sp_api::ProvideRuntimeApi;
Expand Down Expand Up @@ -109,13 +109,9 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_evidence_period_end_block(at, department_required_fund_id);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -130,13 +126,9 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_staking_period_end_block(at, department_required_fund_id);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -151,13 +143,9 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_drawing_period_end(at, department_required_fund_id);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -173,13 +161,9 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_commit_period_end_block(at, department_required_fund_id);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -195,13 +179,9 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_vote_period_end_block(at, department_required_fund_id);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -218,13 +198,9 @@ where
self.client.info().best_hash);

let runtime_api_result = api.selected_as_juror(at, department_required_fund_id, who);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use jsonrpsee::{
core::{Error as JsonRpseeError, RpcResult},
proc_macros::rpc,
types::error::{CallError, ErrorCode, ErrorObject},
core::RpcResult,
proc_macros::rpc,
types::{ErrorObject, ErrorObjectOwned},
};
use parity_scale_codec::Codec;
use positive_externality_runtime_api::PositiveExternalityApi as PositiveExternalityRuntimeApi;
Expand Down Expand Up @@ -107,13 +107,10 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_evidence_period_end_block(at, user_to_calculate);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}

fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -126,15 +123,14 @@ where
let at = at.unwrap_or_else(||
// If the block hash is not supplied assume the best block.
self.client.info().best_hash);


fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}

let runtime_api_result = api.get_staking_period_end_block(at, user_to_calculate);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}

let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -149,13 +145,10 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_drawing_period_end(at, user_to_calculate);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}

fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -171,13 +164,10 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_commit_period_end_block(at, user_to_calculate);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}

fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -193,13 +183,10 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_vote_period_end_block(at, user_to_calculate);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}

fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -216,13 +203,10 @@ where
self.client.info().best_hash);

let runtime_api_result = api.selected_as_juror(at, user_to_calculate, who);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}

fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand Down
76 changes: 24 additions & 52 deletions custom-pallets/profile-validation/profile-validation-rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use jsonrpsee::{
core::{Error as JsonRpseeError, RpcResult},
proc_macros::rpc,
types::error::{CallError, ErrorCode, ErrorObject},
core::RpcResult,
proc_macros::rpc,
types::{ErrorObject, ErrorObjectOwned},
};
use parity_scale_codec::Codec;
use profile_validation_runtime_api::ProfileValidationApi as ProfileValidationRuntimeApi;
Expand Down Expand Up @@ -121,13 +121,9 @@ where

let runtime_api_result =
api.get_challengers_evidence(at, profile_user_account, offset, limit);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -143,13 +139,9 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_evidence_period_end_block(at, profile_user_account);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -164,13 +156,9 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_staking_period_end_block(at, profile_user_account);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -185,13 +173,9 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_drawing_period_end(at, profile_user_account);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -207,13 +191,9 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_commit_period_end_block(at, profile_user_account);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -229,13 +209,9 @@ where
self.client.info().best_hash);

let runtime_api_result = api.get_vote_period_end_block(at, profile_user_account);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand All @@ -252,13 +228,9 @@ where
self.client.info().best_hash);

let runtime_api_result = api.selected_as_juror(at, profile_user_account, who);
fn map_err(error: impl ToString, desc: &'static str) -> CallError {
CallError::Custom(ErrorObject::owned(
Error::RuntimeError.into(),
desc,
Some(error.to_string()),
))
}
fn map_err(error: impl ToString, desc: &'static str) -> ErrorObjectOwned {
ErrorObject::owned(Error::RuntimeError.into(), desc, Some(error.to_string()))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
}
Expand Down
Loading

0 comments on commit 26ed94e

Please sign in to comment.