Skip to content

Instantly share code, notes, and snippets.

View shawntabrizi's full-sized avatar

Shawn Tabrizi shawntabrizi

View GitHub Profile
use support::{decl_module, decl_storage, decl_event, StorageValue, dispatch::Result};
use system::ensure_signed;
use rstd::prelude::*;
use rstd::collections::btree_set::BTreeSet;
pub trait Trait: system::Trait {
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
}
decl_storage! {
@shawntabrizi
shawntabrizi / enum_module.rs
Created July 10, 2019 18:00
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,
@shawntabrizi
shawntabrizi / adder_module.rs
Created June 21, 2019 10:19
Simple adder for Substrate
use support::{decl_module, decl_storage, decl_event, StorageValue, dispatch::Result, ensure, StorageMap};
use system::ensure_signed;
pub trait Trait: system::Trait {
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
}
decl_storage! {
trait Store for Module<T: Trait> as calculator {
FinalResult: u64;
use support::{decl_module, dispatch::Result,
traits::{Currency, ExistenceRequirement, WithdrawReason}};
use system::ensure_signed;
// v1.0 branch
// use runtime_primitives::traits::As;
pub trait Trait: balances::Trait {}
decl_module! {
#![feature(prelude_import)]
#![no_std]
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
use support::{decl_module, decl_storage, decl_event, StorageValue, dispatch::Result};
use system::ensure_signed;
pub trait Trait: system::Trait {
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
}
type U8 = [u8; 1];
decl_storage! {
@shawntabrizi
shawntabrizi / demo.rs
Last active February 11, 2019 12:12
Gav Demo Runtime from Web3 Summit
// initialise with:
// post({sender: runtime.indices.ss58Decode('F7Gh'), call: calls.demo.setPayment(1000)}).tie(console.log)
use parity_codec::Encode;
use srml_support::{StorageValue, dispatch::Result, decl_module, decl_storage};
use runtime_primitives::traits::Hash;
use {balances, system::{self, ensure_signed}};
pub trait Trait: balances::Trait {}