While the last lesson may seem complex at first, the same format will be used again and again for sending messages, and you’ll get used to the syntax pretty soon.
In fact, we’ll be using the format once more in this lesson too. Now, that we’ve sent a message to the user for an error in the last lesson (telling the user that the sender wallet address wasn’t the same as the owner wallet address and therefore the deposit couldn’t be accepted,) we’ll also send a message for success.
So, this time we’ll focus on the true
condition of the branch.
Uint32
type of variable with variable name accepted_code
and value 0
.True
branch, we have to accept
the money which has been sent. So use the accept keyword.msg
with the following values:_tag
, the value should be empty, i.e., ""
._recipient
, we want to send the message to the initial sender, so the value should be: _sender
._amount
, the value should be zero
. Since we have defined it as a Uint128
variable in the library already, use that variable named zero
._code
, use the code that we have defined in the forst step of this task to indicate that sender is the owner, i.e.,accepted_code
.msg
, put this message in the list defined in the previous lesson (i.e. one_msg
variable type) and then send it.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
(* Start typing from the line below. declare a Uint32 type of variable with variable name “accepted_code” and value “0” *)
contract SocialMediaPayment (owner: ByStr20)
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 =>
(* Start typing from the line below for task 2, 3 and 4*)
end
end
1234567891011121314151617181920212223242526272829303132333435