在one of the substrate tutorials中,我们展示了如何从控制台提交事务:
post({
sender: runtime.indices.ss58Decode('F7Hs'),
call: calls.demo.setPayment(1000),
}).tie(console.log)
这将提交transaction。但是,如果我想提交inherent extrinsic,该怎么办?例如,我有一个带有可递增计数器的模块:
use support::{decl_storage, decl_module, dispatch::Result, StorageValue};
use system::{ensure_inherent};
pub trait Trait: system::Trait {}
decl_storage! {
trait Store for Module<T: Trait> as KittyStorage {
pub Counter config(counter): i64;
}
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
/// Increment the module's counter.
fn increment(origin) -> Result {
let _sender = ensure_inherent(origin)?;
let counter = <Counter<T>>::get() ;
if counter == i64::max_value() {
Err("counter already reached its max value")
} else {
<Counter<T>>::put(counter + 1);
Ok(())
}
}
}
}
由于ensure_inherent
,当用post
提交时,事务失败。那么如何在上面定义的模块中调用increment()
?