diff --git a/Cargo.lock b/Cargo.lock index c2b02bf..3ef431b 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -8367,6 +8367,17 @@ dependencies = [ "substrate-fixed", ] +[[package]] +name = "pallet-governance-api" +version = "0.1.0" +dependencies = [ + "pallet-torus0", + "parity-scale-codec", + "polkadot-sdk", + "scale-info", + "substrate-fixed", +] + [[package]] name = "pallet-grandpa" version = "38.0.0" @@ -16921,6 +16932,7 @@ dependencies = [ "pallet-evm-precompile-sha3fips", "pallet-evm-precompile-simple", "pallet-governance", + "pallet-governance-api", "pallet-torus0", "parity-scale-codec", "polkadot-sdk", diff --git a/Cargo.toml b/Cargo.toml index 1c17589..23811d5 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] @@ -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" diff --git a/pallets/governance/Cargo.toml b/pallets/governance/Cargo.toml index 238a132..3b0d497 100644 --- a/pallets/governance/Cargo.toml +++ b/pallets/governance/Cargo.toml @@ -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 } diff --git a/pallets/governance/api/Cargo.toml b/pallets/governance/api/Cargo.toml new file mode 100644 index 0000000..fbb2848 --- /dev/null +++ b/pallets/governance/api/Cargo.toml @@ -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 } diff --git a/pallets/governance/api/src/lib.rs b/pallets/governance/api/src/lib.rs new file mode 100644 index 0000000..f7efddd --- /dev/null +++ b/pallets/governance/api/src/lib.rs @@ -0,0 +1,12 @@ +use codec::Codec; +use polkadot_sdk::sp_api; + +sp_api::decl_runtime_apis! { + #[api_version(1)] + pub trait GovernanceApi + where AccountId: Codec { + fn get_dao_treasury_address() -> AccountId; + + fn is_whitelisted(key: &AccountId) -> bool; + } +} diff --git a/pallets/governance/src/lib.rs b/pallets/governance/src/lib.rs index 9d72122..7d933a5 100644 --- a/pallets/governance/src/lib.rs +++ b/pallets/governance/src/lib.rs @@ -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; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index f627e5a..0e93d99 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -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 = [ diff --git a/runtime/src/apis.rs b/runtime/src/apis.rs index 64d819f..5631540 100644 --- a/runtime/src/apis.rs +++ b/runtime/src/apis.rs @@ -463,4 +463,15 @@ impl_runtime_apis! { ) } } + + + impl pallet_governance_api::GovernanceApi for Runtime { + fn get_dao_treasury_address() -> AccountId { + pallet_governance::DaoTreasuryAddress::::get() + } + + fn is_whitelisted(key: &AccountId) -> bool { + pallet_governance::whitelist::is_whitelisted::(key) + } + } }