kosi
April 20, 2021, 6:13pm
1
Hey guys,
I need to call some function that return bool value, inside a if statement.
So I have this code:
#[weight = 10_000 + T::DbWeight::get().writes(2)]
pub fn unlock(origin) -> dispatch::DispatchResult {
let user = ensure_signed(origin)?;
ensure!(user == Self::authority(), Error::<T>::Forbidden);
<Ends<T>>::put(T::BlockNumber::zero());
Paused::put(true);
Ok(())
}
Now I want to call it in if
statement, but I don't know how, I try with this code, but returns me this:
if (Self::unlock) {
| ^^^^^^^^^^^^^^ expected bool
, found fn item
If is unlock, then it should add amount on some accountId. Any help?
skysch
April 20, 2021, 6:25pm
2
Self::unlock
is a function, so you need to call it if you want its output like so:
if Self::unlock(origin) {...}
But given that unlock
returns dispatch::DispatchResult
you probably can't use that as a bool
either, so you probably need to call is_ok()
on it (or whatever it is you need.)
kosi
April 20, 2021, 7:52pm
3
Thank for the reply, but I have another error:
if Self::unlock(origin).is_ok() {
^^^^^^ value used here after move
I think it's because I have this line:
let user = ensure_signed(origin)?;
^^^^^^ value used here after move
How can I resolve this?
alice
April 20, 2021, 8:11pm
4
Please post error messages in code blocks, not quote blocks. Also, please post full errors.
4 Likes
system
Closed
July 19, 2021, 8:11pm
5
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.