Verifying Signed Messages

It is often useful to designate some functions as permissioned and, therefore, accessible only to a defined group. In this case, we check that the transaction that invokes the runtime function is signed before verifying that the signature corresponds to a member of the permissioned set.


# #![allow(unused_variables)]
#fn main() {
let who = ensure_signed(origin)?;
ensure!(Self::is_member(&who), "user is not a member of the group");
#}

We can define is_member similar to the helper methods in the Social Network recipe by defining a vector of AccountIds (current_member) that contains all members. We then search this vector for the AccountId in question within the body of the is_member method.


# #![allow(unused_variables)]
#fn main() {
impl<T: Trait> Module<T> {
    pub fn is_member(who: &T::AccountId) -> bool {
        Self::current_member().iter()
            .any(|&ref a| a == who)
    }
}
#}

To read more about checking for signed messages, see the relevant section in the Substrate collectables tutorial.

Custom Origin

  • todo