mutate returns a value (#945)

* mutate returns a value

* code comment fixes

* fix the compile
This commit is contained in:
guanqun
2018-10-26 17:13:16 +08:00
committed by Gav Wood
parent 10210b9520
commit b1976c9014
3 changed files with 32 additions and 19 deletions
+6 -1
View File
@@ -251,8 +251,13 @@ impl<T: Trait> Module<T> {
fn accumulate_foo(origin: T::Origin, increase_by: T::Balance) -> Result {
let _sender = ensure_signed(origin)?;
let prev = <Foo<T>>::get();
// Because Foo has 'default', the type of 'foo' in closure is the raw type instead of an Option<> type.
<Foo<T>>::mutate(|foo| *foo = *foo + increase_by);
let result = <Foo<T>>::mutate(|foo| {
*foo = *foo + increase_by;
*foo
});
assert!(prev + increase_by == result);
Ok(())
}