Now that we have defined a code that implies that the sender to deposit transition is not the owner of the smart contract, we’ll have to send that code as a response. We’ll do this through sending a message using the instruction send.
Send is used to send messages to other accounts, either in order to invoke transitions on another smart contract, or to transfer money to user accounts. To construct a message we use the given syntax.
A message must contain the compulsory fields _tag
,_recipient
and _amount
. The _recipient
field is the blockchain address (of type ByStr20
) that the message is to be sent to, and the _amount
field is the number of ZIL
to be transferred to that account. The value of the _tag
field is the name of the transition (of type String
) that is to be invoked on the _recipient
contract. If _recipient
is a user account, then the value of _tag
can be set to be ""
(the empty string). In fact, if the _recipient
is a user account, then the value of _tag
is ignored.
In addition to the compulsory fields the message may contain other fields, such as code above. However, if the message recipient is a contract, the additional fields must have the same names and types as the parameters of the transition being invoked on the recipient contract.
Sending a message is done using the send
instruction, which takes a list of messages as a parameter. Since we currently only send one message at a time, we use the library function one_msg
from the previous lesson.
To send out a message, we first construct the message, insert it into a list, and send it.
The details of this include understanding the list
functionality for Scilla. In our program, it will only be used in this one instance, so rather than going in the details, we’ll simply be using the above format. However, for more details, please feel free to read it at the list section of the scilla documentation.
False
branch of the conditions, declare a variable 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’ve 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 library to indicate that sender is not the owner, i.e.,not_owner_code
.msg
, put this message in the list defined in the step one (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
contract SocialMediaPayment (owner: ByStr20)
transition deposit()
sender_is_owner = builtin eq _sender owner;
match sender_is_owner with
| False =>
(* Start typing from the line below. Define the variable msg below with the values given in the second point of the task*)
(* Start typing from the line below. Copy the two lines given in the third point of the task below. *)
| True =>
end
end
1234567891011121314151617181920212223242526272829