Skip to content

Commit

Permalink
refac: run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
My Name committed Feb 22, 2024
1 parent 91b7048 commit e7f721c
Show file tree
Hide file tree
Showing 29 changed files with 2,124 additions and 2,242 deletions.
6 changes: 3 additions & 3 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use node_subspace_runtime::{
AccountId, AuraConfig, BalancesConfig, GrandpaConfig, Signature,
SubspaceModuleConfig, SudoConfig, SystemConfig, WASM_BINARY, Precompiles, RuntimeGenesisConfig
AccountId, AuraConfig, BalancesConfig, GrandpaConfig, Precompiles, RuntimeGenesisConfig,
Signature, SubspaceModuleConfig, SudoConfig, SystemConfig, WASM_BINARY,
};
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
Expand Down Expand Up @@ -230,7 +230,7 @@ fn network_genesis(
block: u32,
) -> RuntimeGenesisConfig {
use node_subspace_runtime::{EVMChainIdConfig, EVMConfig};

RuntimeGenesisConfig {
system: SystemConfig {
// Add Wasm runtime to storage.
Expand Down
2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn run() -> sc_cli::Result<()> {

runner.sync_run(|config| {
use sp_io::SubstrateHostFunctions;

// This switch needs to be in the client, since the client decides
// which sub-commands it wants to support.
match cmd {
Expand Down
4 changes: 2 additions & 2 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ where
P: TransactionPool + 'static,
{
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use subspace_rpc::{SubspaceApiServer, SubspacePallet};
use substrate_frame_rpc_system::{System, SystemApiServer};
use subspace_rpc::{SubspacePallet, SubspaceApiServer};


let mut module = RpcModule::new(());
let FullDeps { client, pool, deny_unsafe } = deps;

Expand Down
15 changes: 9 additions & 6 deletions pallets/subspace/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
#![cfg_attr(not(feature = "std"), no_std)]

use sp_runtime::{DispatchError, MultiSignature, traits::{Verify, IdentifyAccount}};
use sp_runtime::{sp_std::prelude::Vec, ArithmeticError};
use parity_scale_codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_arithmetic::per_things::Percent;
use sp_runtime::{
sp_std::prelude::Vec,
traits::{IdentifyAccount, Verify},
ArithmeticError, DispatchError, MultiSignature,
};

type Result<T> = core::result::Result<T, DispatchError>;
type Signature = MultiSignature;
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;

#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo, Serialize, Deserialize)]
pub struct ModuleStats{
pub struct ModuleStats {
pub last_update: u64,
pub registration_block: u64,
pub stake_from: Vec<(AccountId, u64)>, /* map of key to stake on this module/key * (includes delegations) */
pub stake_from: Vec<(AccountId, u64)>, /* map of key to stake on this module/key * (includes
* delegations) */
pub emission: u64,
pub incentive: u16,
pub dividends: u16,
Expand All @@ -36,7 +40,6 @@ pub struct ModuleInfo {
pub stats: ModuleStats,
}


// sp_api::decl_runtime_apis! {
// pub trait SubspaceRuntimeApi where
// AccountId: <<Signature as Verify>::Signer as IdentifyAccount>::AccountId
Expand All @@ -52,4 +55,4 @@ sp_api::decl_runtime_apis! {

fn get_module_info(key: AccountId, netuid: u16) -> ModuleInfo;
}
}
}
39 changes: 24 additions & 15 deletions pallets/subspace/rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
use subspace_runtime_api::ModuleInfo;
pub use subspace_runtime_api::SubspaceRuntimeApi;
use jsonrpsee::{
core::{Error as JsonRpseeError, 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};
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, IdentifyAccount, Verify},
DispatchError, MultiSignature,
};
use std::sync::Arc;
use sp_runtime::{DispatchError, MultiSignature, traits::{Verify, IdentifyAccount}};
use subspace_runtime_api::ModuleInfo;
pub use subspace_runtime_api::SubspaceRuntimeApi;

type Signature = MultiSignature;
type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;


#[derive(serde::Deserialize, serde::Serialize)]
pub struct Custom {
code: u32,
burn_rate: u16,
}

#[rpc(client, server)]
pub trait SubspaceApi<BlockHash, AccountId>
{
pub trait SubspaceApi<BlockHash, AccountId> {
#[method(name = "subspace_getBurnRate")]
fn get_burn_rate(&self, at: Option<BlockHash>) -> RpcResult<Custom>;

#[method(name = "subspace_getModuleInfo")]
fn get_module_info(&self, key: AccountId, netuid: u16, at: Option<BlockHash>) -> RpcResult<ModuleInfo>;


fn get_module_info(
&self,
key: AccountId,
netuid: u16,
at: Option<BlockHash>,
) -> RpcResult<ModuleInfo>;
}

pub struct SubspacePallet<C, Block> {
Expand All @@ -50,19 +54,24 @@ where
C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
C::Api: SubspaceRuntimeApi<Block>,
{
fn get_burn_rate(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Custom> {
fn get_burn_rate(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Custom> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);

let value = api.get_burn_rate(at).map_err(runtime_error_into_rpc_err);
Ok(Custom{ code: 200, burn_rate: value.unwrap()})
Ok(Custom { code: 200, burn_rate: value.unwrap() })
}

fn get_module_info(&self, key: AccountId, netuid: u16, at: Option<<Block as BlockT>::Hash>) -> RpcResult<ModuleInfo> {
fn get_module_info(
&self,
key: AccountId,
netuid: u16,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<ModuleInfo> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);

let value = api.get_module_info(at, key, netuid, ).map_err(runtime_error_into_rpc_err);
let value = api.get_module_info(at, key, netuid).map_err(runtime_error_into_rpc_err);
Ok(value.unwrap())
}
}
Expand All @@ -77,4 +86,4 @@ fn runtime_error_into_rpc_err(err: impl std::fmt::Debug) -> JsonRpseeError {
Some(format!("{:?}", err)),
))
.into()
}
}
Loading

0 comments on commit e7f721c

Please sign in to comment.