Skip to content

Commit

Permalink
feat: impl base governance api
Browse files Browse the repository at this point in the history
  • Loading branch information
devwckd committed Dec 18, 2024
1 parent 789798e commit 77f4f30
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 8 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

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

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
[workspace]
members = ["node", "runtime", "pallets/*", "test-utils", "xtask"]
members = [
"node",
"runtime",
"pallets/*",
"pallets/**/api",
"test-utils",
"xtask",
]
resolver = "2"

[workspace.package]
Expand All @@ -11,6 +18,7 @@ edition = "2021"
torus-node = { path = "./node", default-features = false }
torus-runtime = { path = "./runtime", default-features = false }
pallet-governance = { path = "./pallets/governance", default-features = false }
pallet-governance-api = { path = "./pallets/governance/api", default-features = false }
pallet-torus0 = { path = "./pallets/torus0", default-features = false }

test-utils.path = "./test-utils"
Expand Down
7 changes: 1 addition & 6 deletions pallets/governance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ try-runtime = ["polkadot-sdk/try-runtime"]
[dependencies]
codec = { workspace = true, features = ["derive"] }
pallet-torus0 = { workspace = true }
polkadot-sdk = { workspace = true, features = [
"experimental",
"runtime",
"pallet-sudo",
"sc-telemetry",
] }
polkadot-sdk = { workspace = true, features = ["experimental", "runtime"] }
scale-info = { workspace = true, features = ["derive"] }
substrate-fixed = { workspace = true }
25 changes: 25 additions & 0 deletions pallets/governance/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "pallet-governance-api"
description = "The chain's governance pallet api."
version = "0.1.0"
license = "MIT-0"
authors.workspace = true
edition.workspace = true

[features]
default = ["std"]
std = ["codec/std", "polkadot-sdk/std", "scale-info/std", "substrate-fixed/std"]
runtime-benchmarks = ["polkadot-sdk/runtime-benchmarks"]
try-runtime = ["polkadot-sdk/try-runtime"]

[dependencies]
codec = { workspace = true, features = ["derive"] }
pallet-torus0 = { workspace = true }
polkadot-sdk = { workspace = true, features = [
"experimental",
"runtime",
"pallet-sudo",
"sc-telemetry",
] }
scale-info = { workspace = true, features = ["derive"] }
substrate-fixed = { workspace = true }
12 changes: 12 additions & 0 deletions pallets/governance/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use codec::Codec;
use polkadot_sdk::sp_api;

sp_api::decl_runtime_apis! {
#[api_version(1)]
pub trait GovernanceApi<AccountId>
where AccountId: Codec {
fn get_dao_treasury_address() -> AccountId;

fn is_whitelisted(key: &AccountId) -> bool;
}
}
2 changes: 1 addition & 1 deletion pallets/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod curator;
mod ext;
mod proposal;
mod voting;
mod whitelist;
pub mod whitelist;

use crate::application::AgentApplication;
use crate::config::GovernanceConfiguration;
Expand Down
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pallet-evm-precompile-simple.workspace = true
# Local dependencies
pallet-torus0.workspace = true
pallet-governance.workspace = true
pallet-governance-api.workspace = true

[build-dependencies]
polkadot-sdk = { optional = true, workspace = true, features = [
Expand Down
11 changes: 11 additions & 0 deletions runtime/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,15 @@ impl_runtime_apis! {
)
}
}


impl pallet_governance_api::GovernanceApi<Block, AccountId> for Runtime {
fn get_dao_treasury_address() -> AccountId {
pallet_governance::DaoTreasuryAddress::<Runtime>::get()
}

fn is_whitelisted(key: &AccountId) -> bool {
pallet_governance::whitelist::is_whitelisted::<Runtime>(key)
}
}
}

0 comments on commit 77f4f30

Please sign in to comment.