我有一个接受调用的方法(类似于 sudo 或恢复托盘),我想在调度它之前对调用运行一些验证。验证主要围绕限制我们可以通过此方法调用的方法。
这是我的示例代码:
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn deposit_event() = default;
pub fn foo(origin, call: Box<<T as Trait>::Call>) -> DispatchResult {
ensure_signed(origin)?;
let sender = match *call {
Call::test(x) => Ok(()),
_ => Err(())
};
Ok(())
}
pub fn test(origin, x: u32) -> DispatchResult {
Ok(())
}
}
}
在这个例子中,我只希望它在call
调用我的test()
函数时成功。
不幸的是,我收到关于类型不匹配的错误,任何帮助将不胜感激,谢谢。
我得到的错误是:
Call::test(x) => Ok(()),
| ^^^^^^^^^^^^^ expected associated type, found enum Call
|
= note: expected associated type <T as Trait>::Call
found enum Call<_>
= note: consider constraining the associated type <T as Trait>::Call to Call<_> or calling a method that returns <T as Trait>::Call