Now, we have two boolean values stored in the variables user_exists
and username_exists
. We are interested in checking whether any of these conditions are true.
To check that, we’ll use the boolean operator orb
in scilla which returns true if any of the arguments are true, or else it will return false only if both arguments are false.
Here, boolVar1
and boolVar2
are two bool type variables. Using them with operator orb
returns a bool variable which is then being stored in variable result
.
Existence checks through nested maps is supported with the syntax v <- exists m[k1][k2][...]
. If one or more of the intermediate key(s) do not exist in the corresponding map, the result is False.
Use orb
operator with the variable user_exists
and username_exists
and store the result in a new variable already_exists
. This will all be done in a single line as shown in the example above.
Show Solution
scilla_version 0
import BoolUtils
library SocialMediaPayment
let one_msg =
fun (msg: Message) =>
let nil_msg = Nil {Message} in
Cons {Message} msg nil_msg
let zero = Uint128 0
let not_owner_code = Uint32 1
let accepted_code = Uint32 0
contract SocialMediaPayment (owner: ByStr20)
field users: Map ByStr20 String
= Emp ByStr20 String
field used_usernames: Map String Bool
= Emp String Bool
transition deposit()
sender_is_owner = builtin eq _sender owner;
match sender_is_owner with
| False =>
msg = { _tag: "";
_recipient: _sender;
_amount: zero;
code: not_owner_code};
msgs = one_msg msg;
send msgs
| True =>
accept;
msg = { _tag: "";
_recipient: _sender;
_amount: zero;
code: accepted_code};
msgs = one_msg msg;
send msgs
end
end
transition register_user (user_address: ByStr20, twitter_username: String)
user_exists <- exists users[user_address];
username_exists <- exists used_usernames[twitter_username]
(* Start typing from the line below *)
end
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657