Skip to content

Commit

Permalink
node runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Jul 3, 2024
1 parent 8e4cd44 commit 55153c9
Show file tree
Hide file tree
Showing 14 changed files with 510 additions and 6 deletions.
60 changes: 60 additions & 0 deletions Cargo.lock

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

17 changes: 17 additions & 0 deletions container-chains/nodes/simple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ cumulus-relay-chain-interface = { workspace = true }

pallet-shared-storage = { workspace = true }

# profile valdiation rpc
profile-validation-runtime-api = { workspace = true }
profile-validation-rpc = { workspace = true }


# Department funding rpc
department-funding-runtime-api = { workspace = true }
department-funding-rpc= {workspace = true }

# Postive exterality rpc
positive-externality-runtime-api = { workspace = true }
positive-externality-rpc= { workspace = true }

# Project tip rpc
project-tips-runtime-api = { workspace = true }
project-tips-rpc= { workspace = true }


[build-dependencies]
substrate-build-script-utils = { workspace = true }
Expand Down
12 changes: 12 additions & 0 deletions container-chains/nodes/simple/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>.

use hex_literal::hex;
use {
container_chain_template_simple_runtime::{
AccountId, MaintenanceModeConfig, MigrationsConfig, PolkadotXcmConfig, Signature,
Expand Down Expand Up @@ -208,5 +209,16 @@ pub fn pre_funded_accounts() -> Vec<AccountId> {
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
hex!("2e778beae3cc11fd7ea694f4ff8b54922d67e0599c356f393277ed9711d6364b").into(),
hex!("2e1c14cd13a2b090a62203809d8ce3eaac7417a4a0272438568eb04cae330669").into(),
hex!("ba0ce278d82ef9a686cb60a801125a8d11b32caa2456ebdcfe7ff687bb9bf540").into(),
hex!("600f10bdbf233ac6614eea62ae45d269b43c759e4ddf0bc1a70ffcbc95499c6c").into(),
hex!("c2da35a7aed402249295971abe8f10e0b03d861a0571e56115bcc6f8828dd939").into(),
hex!("186863b612097dec4ce7b9772381935baa7fc6dc7c44695f0384174f1b131156").into(),
hex!("70c3f87a26743fed9194f8fc67bfdd9a211f3b00f5c80459107022d096dbf928").into(),
hex!("cab4abef5dda97cc98eb0f3a5e0329bd2c1b892b5f442021a634c7e79e6f6e29").into(),
hex!("ac926b4e81989ca51c9ac6f0ef9c7db08d5334bb0a5c3b0194bf92d215b50f3f").into(),
hex!("186c72f04de9c1a74cee6836c08b6d56a88e90ab5a6127693a55379e8e03d919").into(),
hex!("b02de28c52fe59f9a3d8779cd8c6ee7439cba45e48e7ee582f5cc939c7b5946c").into(),
]
}
15 changes: 14 additions & 1 deletion container-chains/nodes/simple/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ where
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
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>,
{
use substrate_frame_rpc_system::{System, SystemApiServer};
use department_funding_rpc::DepartmentFundingApiServer;
use positive_externality_rpc::PositiveExternalityApiServer;
use profile_validation_rpc::ProfileValidationApiServer;
use project_tips_rpc::ProjectTipsApiServer;

let mut module = RpcExtension::new(());
let FullDeps {
Expand All @@ -83,7 +91,7 @@ where
xcm_senders,
} = deps;

module.merge(System::new(client, pool, deny_unsafe).into_rpc())?;
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;

// Manual seal
if let Some(command_sink) = command_sink {
Expand All @@ -104,5 +112,10 @@ where
)?;
}

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())?;

Ok(module)
}
107 changes: 107 additions & 0 deletions container-chains/runtime-templates/simple/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ pub type SignedBlock = generic::SignedBlock<Block>;
/// BlockId type as expected by this runtime.
pub type BlockId = generic::BlockId<Block>;


pub type ChallengePostId = u64;

pub type DepartmentRequiredFundId = u64;

pub type ProjectId = u64;

/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
frame_system::CheckNonZeroSender<Runtime>,
Expand Down Expand Up @@ -779,6 +786,106 @@ mod benches {
}

impl_runtime_apis! {
impl profile_validation_runtime_api::ProfileValidationApi<Block, AccountId> for Runtime {

fn get_challengers_evidence(profile_user_account: AccountId, offset: u64, limit: u16) -> Vec<ChallengePostId> {
ProfileValidation::get_challengers_evidence(profile_user_account, offset, limit)
}

fn get_evidence_period_end_block(profile_user_account: AccountId) -> Option<u32> {
ProfileValidation::get_evidence_period_end_block(profile_user_account)
}

fn get_staking_period_end_block(profile_user_account: AccountId) -> Option<u32> {
ProfileValidation::get_staking_period_end_block(profile_user_account)
}
fn get_drawing_period_end(profile_user_account: AccountId) -> (u64, u64, bool) {
ProfileValidation::get_drawing_period_end(profile_user_account)
}
fn get_commit_period_end_block(profile_user_account: AccountId) -> Option<u32> {
ProfileValidation::get_commit_period_end_block(profile_user_account)
}

fn get_vote_period_end_block(profile_user_account: AccountId) -> Option<u32> {
ProfileValidation::get_vote_period_end_block(profile_user_account)
}
fn selected_as_juror(profile_user_account: AccountId, who: AccountId) -> bool {
ProfileValidation::selected_as_juror(profile_user_account, who)
}
}

impl department_funding_runtime_api::DepartmentFundingApi<Block, AccountId> for Runtime {

fn get_evidence_period_end_block(department_required_fund_id: DepartmentRequiredFundId) -> Option<u32> {
DepartmentFunding::get_evidence_period_end_block(department_required_fund_id)
}

fn get_staking_period_end_block(department_required_fund_id: DepartmentRequiredFundId) -> Option<u32> {
DepartmentFunding::get_staking_period_end_block(department_required_fund_id)
}
fn get_drawing_period_end(department_required_fund_id: DepartmentRequiredFundId) -> (u64, u64, bool) {
DepartmentFunding::get_drawing_period_end(department_required_fund_id)
}
fn get_commit_period_end_block(department_required_fund_id: DepartmentRequiredFundId) -> Option<u32> {
DepartmentFunding::get_commit_period_end_block(department_required_fund_id)
}

fn get_vote_period_end_block(department_required_fund_id: DepartmentRequiredFundId) -> Option<u32> {
DepartmentFunding::get_vote_period_end_block(department_required_fund_id)
}
fn selected_as_juror(department_required_fund_id: DepartmentRequiredFundId, who: AccountId) -> bool {
DepartmentFunding::selected_as_juror(department_required_fund_id, who)
}
}

impl positive_externality_runtime_api::PositiveExternalityApi<Block, AccountId> for Runtime {

fn get_evidence_period_end_block(user_to_calculate: AccountId) -> Option<u32> {
PositiveExternality::get_evidence_period_end_block(user_to_calculate)
}

fn get_staking_period_end_block(user_to_calculate: AccountId) -> Option<u32> {
PositiveExternality::get_staking_period_end_block(user_to_calculate)
}
fn get_drawing_period_end(user_to_calculate: AccountId) -> (u64, u64, bool) {
PositiveExternality::get_drawing_period_end(user_to_calculate)
}
fn get_commit_period_end_block(user_to_calculate: AccountId) -> Option<u32> {
PositiveExternality::get_commit_period_end_block(user_to_calculate)
}

fn get_vote_period_end_block(user_to_calculate: AccountId) -> Option<u32> {
PositiveExternality::get_vote_period_end_block(user_to_calculate)
}
fn selected_as_juror(user_to_calculate: AccountId, who: AccountId) -> bool {
PositiveExternality::selected_as_juror(user_to_calculate, who)
}
}

impl project_tips_runtime_api::ProjectTipsApi<Block, AccountId> for Runtime {

fn get_evidence_period_end_block(project_id: ProjectId) -> Option<u32> {
ProjectTips::get_evidence_period_end_block(project_id)
}

fn get_staking_period_end_block(project_id: ProjectId) -> Option<u32> {
ProjectTips::get_staking_period_end_block(project_id)
}
fn get_drawing_period_end(project_id: ProjectId) -> (u64, u64, bool) {
ProjectTips::get_drawing_period_end(project_id)
}
fn get_commit_period_end_block(project_id: ProjectId) -> Option<u32> {
ProjectTips::get_commit_period_end_block(project_id)
}

fn get_vote_period_end_block(project_id: ProjectId) -> Option<u32> {
ProjectTips::get_vote_period_end_block(project_id)
}
fn selected_as_juror(project_id: ProjectId, who: AccountId) -> bool {
ProjectTips::selected_as_juror(project_id, who)
}
}

impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ sc-rpc = { workspace = true}
sp-api = { workspace = true }
sp-blockchain = {workspace = true }
sp-runtime = { workspace = true }
parity-scale-codec = { workspace = true }
department-funding-runtime-api = { workspace = true}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use jsonrpsee::{
proc_macros::rpc,
types::error::{CallError, ErrorCode, ErrorObject},
};
use sp_api::codec::Codec;
use parity_scale_codec::Codec;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::Block as BlockT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ sc-rpc = { workspace = true }
sp-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-runtime = { workspace = true }
parity-scale-codec = { workspace = true }
positive-externality-runtime-api = { workspace = true}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use jsonrpsee::{
types::error::{CallError, ErrorCode, ErrorObject},
};
use positive_externality_runtime_api::PositiveExternalityApi as PositiveExternalityRuntimeApi;
use sp_api::codec::Codec;
use parity_scale_codec::Codec;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::Block as BlockT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ sc-rpc = { workspace = true }
sp-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-runtime = { workspace = true }
parity-scale-codec = { workspace = true }
profile-validation-runtime-api = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use jsonrpsee::{
types::error::{CallError, ErrorCode, ErrorObject},
};
use profile_validation_runtime_api::ProfileValidationApi as ProfileValidationRuntimeApi;
use sp_api::codec::Codec;
use parity_scale_codec::Codec;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::Block as BlockT;
Expand Down
1 change: 1 addition & 0 deletions custom-pallets/project-tips/project-tips-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ sc-rpc = { workspace = true }
sp-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-runtime = { workspace = true }
parity-scale-codec = { workspace = true }
project-tips-runtime-api = { workspace = true }
2 changes: 1 addition & 1 deletion custom-pallets/project-tips/project-tips-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use jsonrpsee::{
types::error::{CallError, ErrorCode, ErrorObject},
};
use project_tips_runtime_api::ProjectTipsApi as ProjectTipsRuntimeApi;
use sp_api::codec::Codec;
use parity_scale_codec::Codec;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::Block as BlockT;
Expand Down
Loading

0 comments on commit 55153c9

Please sign in to comment.