Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.

Augment DelegatedDispatchVerifier trait #42

Merged
merged 2 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ mod tests {
// We aren't testing doughnut verification here just return `Ok(())`
pub struct MockDelegatedDispatchVerifier<T: system::Trait>(rstd::marker::PhantomData<T>);
impl<T: system::Trait> DelegatedDispatchVerifier<T::Doughnut> for MockDelegatedDispatchVerifier<T> {
type AccountId = <Self as system::Trait>::AccountId;
cowboy-bebug marked this conversation as resolved.
Show resolved Hide resolved
const DOMAIN: &'static str = "";
fn verify_dispatch(
_doughnut: &T::Doughnut,
Expand Down
1 change: 1 addition & 0 deletions frame/executive/tests/doughnut_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl_outer_dispatch! {

pub struct MockDelegatedDispatchVerifier<T: system::Trait>(rstd::marker::PhantomData<T>);
impl<T: system::Trait> DelegatedDispatchVerifier<T::Doughnut> for MockDelegatedDispatchVerifier<T> {
type AccountId = <Self as system::Trait>::AccountId;
cowboy-bebug marked this conversation as resolved.
Show resolved Hide resolved
const DOMAIN: &'static str = "test";
fn verify_dispatch(
doughnut: &T::Doughnut,
Expand Down
13 changes: 13 additions & 0 deletions frame/support/src/additional_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ impl<T, U> ChargeFee<T> for DummyChargeFee<T, U> {
/// The `verify()` hook is injected into every module/method on the runtime.
/// When a doughnut proof is included along with a transaction, `verify` will be invoked just before executing method logic.
pub trait DelegatedDispatchVerifier<Doughnut> {
type AccountId;

/// The doughnut permission domain it verifies
const DOMAIN: &'static str;
/// Check the doughnut authorizes a dispatched call to `module` and `method` for this domain
Expand All @@ -60,10 +62,21 @@ pub trait DelegatedDispatchVerifier<Doughnut> {
module: &str,
method: &str,
) -> Result<(), &'static str>;

/// Check the doughnut authorizes a dispatched call from runtime to the specified contract address for this domain.
fn verify_runtime_to_contract_dispatch(caller: &Self::AccountId, doughnut: &Doughnut, contract_addr: &Self::AccountId) -> Result<(), &'static str> {
Err("Doughnut runtime to contract dispatch verification is not implemented for this domain")
}

/// Check the doughnut authorizes a dispatched call from a contract to another contract with the specified addresses for this domain.
fn verify_contract_to_contract_dispatch(caller: &Self::AccountId, doughnut: &Doughnut, contract_addr: &Self::AccountId) -> Result<(), &'static str> {
Err("Doughnut contract to contract dispatch verification is not implemented for this domain")
}
}

/// A dummy implementation for when dispatch verifiaction is not needed
impl<Doughnut> DelegatedDispatchVerifier<Doughnut> for () {
type AccountId = u64;
const DOMAIN: &'static str = "";
fn verify_dispatch(_: &Doughnut, _: &str, _: &str) -> Result<(), &'static str> {
Ok(())
Expand Down
1 change: 1 addition & 0 deletions prml/doughnut/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ where
pub struct PlugDoughnutDispatcher<Runtime: DoughnutRuntime>(rstd::marker::PhantomData<Runtime>);

impl<Runtime: DoughnutRuntime> DelegatedDispatchVerifier<Runtime::Doughnut> for PlugDoughnutDispatcher<Runtime> {
type AccountId = Runtime::AccountId;
const DOMAIN: &'static str = "plug";
/// Verify a Doughnut proof authorizes method dispatch given some input parameters
fn verify_dispatch(
Expand Down