Skip to content

Commit

Permalink
schelling game api for all
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Mar 28, 2024
1 parent 481cdc9 commit beb2a4e
Show file tree
Hide file tree
Showing 71 changed files with 943 additions and 984 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ impl SubstrateCli for Cli {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()?),
"" | "local" => Box::new(chain_spec::local_testnet_config()?),
path =>
Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
path => {
Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?)
},
})
}

Expand Down Expand Up @@ -121,7 +122,7 @@ pub fn run() -> sc_cli::Result<()> {
"Runtime benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
.into(),
)
);
}

cmd.run::<Block, service::ExecutorDispatch>(config)
Expand Down Expand Up @@ -170,8 +171,9 @@ pub fn run() -> sc_cli::Result<()> {

cmd.run(client, inherent_benchmark_data()?, Vec::new(), &ext_factory)
},
BenchmarkCmd::Machine(cmd) =>
cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()),
BenchmarkCmd::Machine(cmd) => {
cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone())
},
}
})
},
Expand Down
10 changes: 9 additions & 1 deletion node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ where
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: profile_validation_runtime_api::ProfileValidationApi<Block, AccountId>,
C::Api: department_funding_runtime_api::DepartmentFundingApi<Block, AccountId>,
C::Api: positive_externality_runtime_api::PositiveExternalityApi<Block, AccountId>,
C::Api: project_tips_runtime_api::ProjectTipsApi<Block, AccountId>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + 'static,

{
use department_funding_rpc::DepartmentFundingApiServer;
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use positive_externality_rpc::PositiveExternalityApiServer;
use profile_validation_rpc::ProfileValidationApiServer;
use project_tips_rpc::ProjectTipsApiServer;
use substrate_frame_rpc_system::{System, SystemApiServer};

let mut module = RpcModule::new(());
Expand All @@ -51,6 +56,9 @@ where
module.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
module.merge(profile_validation_rpc::ProfileValidation::new(client.clone()).into_rpc())?;
module.merge(department_funding_rpc::DepartmentFunding::new(client.clone()).into_rpc())?;
module.merge(positive_externality_rpc::PositiveExternality::new(client.clone()).into_rpc())?;
module.merge(project_tips_rpc::ProjectTips::new(client.clone()).into_rpc())?;

// Extend this RPC with a custom API by using the following syntax.
// `YourRpcStruct` should have a reference to a client, which is needed
Expand Down
55 changes: 11 additions & 44 deletions pallets/department-funding/department-funding-rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
use department_funding_runtime_api::DepartmentFundingApi as DepartmentFundingRuntimeApi;
use jsonrpsee::{
core::{Error as JsonRpseeError, RpcResult},
proc_macros::rpc,
types::error::{CallError, ErrorCode, ErrorObject},
};
use department_funding_runtime_api::DepartmentFundingApi as DepartmentFundingRuntimeApi;
use sp_api::codec::Codec;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::Block as BlockT;
use std::sync::Arc;
type ChallengePostId = u64;

type DepartmentRequiredFundId = u64;

#[rpc(client, server)]
pub trait DepartmentFundingApi<BlockHash, AccountId> {
#[method(name = "departmentfunding_challengerevidence")]
fn get_challengers_evidence(
&self,
department_required_fund_id: DepartmentRequiredFundId,
offset: u64,
limit: u16,
at: Option<BlockHash>,
) -> RpcResult<Vec<ChallengePostId>>;
#[method(name = "departmentfunding_evidenceperiodendblock")]
fn get_evidence_period_end_block(
&self,
Expand Down Expand Up @@ -76,7 +68,6 @@ impl<C, M> DepartmentFunding<C, M> {
}
}


/// Error type of this RPC api.
pub enum Error {
/// The transaction was not decodable.
Expand All @@ -94,8 +85,8 @@ impl From<Error> for i32 {
}
}


impl<C, Block, AccountId> DepartmentFundingApiServer<<Block as BlockT>::Hash, AccountId> for DepartmentFunding<C, Block>
impl<C, Block, AccountId> DepartmentFundingApiServer<<Block as BlockT>::Hash, AccountId>
for DepartmentFunding<C, Block>
where
Block: BlockT,
AccountId: Codec,
Expand All @@ -104,30 +95,6 @@ where
C: HeaderBackend<Block>,
C::Api: DepartmentFundingRuntimeApi<Block, AccountId>,
{
fn get_challengers_evidence(
&self,
department_required_fund_id: DepartmentRequiredFundId,
offset: u64,
limit: u16,
at: Option<Block::Hash>,
) -> RpcResult<Vec<ChallengePostId>> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(||
// If the block hash is not supplied assume the best block.
self.client.info().best_hash);

let runtime_api_result =
api.get_challengers_evidence(at, department_required_fund_id, offset, limit);
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)
}
fn get_evidence_period_end_block(
&self,
department_required_fund_id: DepartmentRequiredFundId,
Expand All @@ -147,7 +114,7 @@ where
))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
Ok(res)
}
fn get_staking_period_end_block(
&self,
Expand All @@ -168,7 +135,7 @@ where
))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
Ok(res)
}
fn get_drawing_period_end(
&self,
Expand All @@ -189,7 +156,7 @@ where
))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
Ok(res)
}

fn get_commit_period_end_block(
Expand All @@ -211,7 +178,7 @@ where
))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
Ok(res)
}

fn get_vote_period_end_block(
Expand All @@ -233,7 +200,7 @@ where
))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
Ok(res)
}

fn selected_as_juror(
Expand All @@ -256,6 +223,6 @@ where
))
}
let res = runtime_api_result.map_err(|e| map_err(e, "Unable to query dispatch info."))?;
Ok(res)
Ok(res)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

// use frame_support::sp_std::{vec::Vec};
// or
use frame_support::sp_std::{prelude::*};
use frame_support::sp_std::prelude::*;
use sp_api::codec::Codec;
type ChallengePostId = u64;
type DepartmentRequiredFundId= u64;

type DepartmentRequiredFundId = u64;

sp_api::decl_runtime_apis! {
pub trait DepartmentFundingApi<AccountId> where AccountId: Codec {
fn get_challengers_evidence(department_required_fund_id: DepartmentRequiredFundId, offset: u64, limit: u16) -> Vec<ChallengePostId>;

fn get_evidence_period_end_block(department_required_fund_id: DepartmentRequiredFundId) -> Option<u32>;
fn get_staking_period_end_block(department_required_fund_id: DepartmentRequiredFundId) -> Option<u32>;
fn get_drawing_period_end(department_required_fund_id: DepartmentRequiredFundId) -> (u64, u64, bool);
fn get_commit_period_end_block(department_required_fund_id: DepartmentRequiredFundId) -> Option<u32>;
fn get_vote_period_end_block(department_required_fund_id: DepartmentRequiredFundId) -> Option<u32>;
fn selected_as_juror(department_required_fund_id: DepartmentRequiredFundId, who: AccountId) -> bool;
}
}
}
Loading

0 comments on commit beb2a4e

Please sign in to comment.