Skip to content

Instantly share code, notes, and snippets.

@shawntabrizi
Created July 10, 2019 18:00
Show Gist options
  • Save shawntabrizi/10015de643e936fdd1632e7fc4a586fe to your computer and use it in GitHub Desktop.
Save shawntabrizi/10015de643e936fdd1632e7fc4a586fe to your computer and use it in GitHub Desktop.
Substrate Enum
use support::{decl_module, decl_storage, StorageValue, dispatch::Result};
use system::ensure_signed;
use parity_codec::{ Encode, Decode };
#[derive(Encode, Decode, Clone, PartialEq)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum Choices {
None,
One,
Two,
Three,
}
pub trait Trait: timestamp::Trait {}
decl_storage! {
trait Store for Module<T: Trait> as TemplateModule {
Choice: Choices = Choices::None;
}
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub fn make_decision(origin, decision: Choices) -> Result {
let who = ensure_signed(origin)?;
<Choice<T>>::put(decision);
Ok(())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment