Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Add default implementation #155

Merged
merged 1 commit into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions modules/fee-market/src/s2s/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ where
let root_account = RootAccount::get();
let account = match submitter {
Sender::Signed(submitter) => submitter,
Sender::Root => root_account
Sender::Root => root_account
.as_ref()
.ok_or("Sending messages using Root origin is disallowed.")?,
Sender::None => Err("Sending messages using None origin is disallowed.")?
Sender::None => Err("Sending messages using None origin is disallowed.")?,
};

<T as Config<I>>::Currency::transfer(
Expand Down
2 changes: 1 addition & 1 deletion modules/messages/src/instant_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
Sender::Root => root_account
.as_ref()
.ok_or("Sending messages using Root origin is disallowed.")?,
Sender::None => Err("Sending messages using None origin is disallowed.")?
Sender::None => Err("Sending messages using None origin is disallowed.")?,
};

Currency::transfer(
Expand Down
17 changes: 16 additions & 1 deletion primitives/message-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ pub trait CallValidate<AccountId, Origin, Call> {
///
/// This will be called before the call enter dispatch phase. If failed, the message(call) will
/// be not be processed by this relayer, latter relayers can still continue process it.
fn check_receiving_before_dispatch(relayer_account: &AccountId, call: &Call) -> Result<(), &'static str>;
fn check_receiving_before_dispatch(
relayer_account: &AccountId,
call: &Call,
) -> Result<(), &'static str>;
/// In-dispatch call validation
///
/// This will be called in the dispatch process, If failed, return message dispatch errors.
Expand All @@ -177,3 +180,15 @@ pub trait CallValidate<AccountId, Origin, Call> {
call: &Call,
) -> Result<(), TransactionValidityError>;
}

/// CallValidate's default implementation, no additional validation
pub enum Everything {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why enum?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just follow the substrate style:

pub enum Everything {}
impl<T> Contains<T> for Everything {
	fn contains(_: &T) -> bool {
		true
	}
}

and https://www.reddit.com/r/rust/comments/91mgqk/empty_enum_vs_empry_struct/. Enum makes sense here, we don't need to instance this type in runtime.

impl<AccountId, Origin, Call> CallValidate<AccountId, Origin, Call> for Everything {
fn check_receiving_before_dispatch(_: &AccountId, _: &Call) -> Result<(), &'static str> {
Ok(())
}

fn call_validate(_: &AccountId, _: &Origin, _: &Call) -> Result<(), TransactionValidityError> {
Ok(())
}
}