Created
May 27, 2019 12:02
-
-
Save shawntabrizi/2d0387a1f3728e98a95ada7c323db227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! { | |
pub struct Module<T: Trait> for enum Call where origin: T::Origin { | |
pub fn do_something(origin) -> Result | |
{ | |
let who = ensure_signed(origin)?; | |
let fee = 1337.into(); | |
// v1.0 branch | |
// let fee = T::Balance::sa(1337); | |
Self::pay_fee(who, fee)?; | |
// Do stuff after fee is paid successfully... | |
Ok(()) | |
} | |
} | |
} | |
impl<T: Trait> Module<T> { | |
fn pay_fee(who: T::AccountId, amount: T::Balance) -> Result { | |
let _ = <balances::Module<T> as Currency<_>>::withdraw( | |
&who, | |
amount, | |
WithdrawReason::Fee, | |
ExistenceRequirement::KeepAlive | |
)?; | |
Ok(()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment