Now, we have two conditional branches.
For each of them, a different behaviour will be programmed. Also, once the programmed action is finished, we’d want to generate some kind of a message regarding that execution.
For the branch, True
, which implies that sender and owner addresses are the same, we will use the accept
keyword, to accept the payment sent.
But when the condition yields False
, we don’t want to accept the payment, but we still want to have some action to signal that the execution of the program has finished.
For doing this, we’ll be sending a message to the sender.
We’ll learn more details about how to send such messages in the coming lessons, but for now let’s first define a code that indicates that the sender is not the owner.
We can define this code in the library
section of our code.
A library is declared in the preamble of a contract using the keyword library
followed by the name of the library. In our current example a library declaration would look as follows:
This library will be used to store program constants (with a scope that covers the entire contract) and also some utility functions using the let x = y in expr
construct. We’ll discuss utility functions later.
You can see the details of syntax in the Cheat Sheet in the Task section below.
For now, we need to define a program constant (or what we’ll later refer to as code
) for the error message that says that the sender is not the owner.
SocialMediaPayment
.Uint32
type of variable with variable name not_owner_code
and value 1
.0
. In the library section, define a Uint128
type of variable with variable name zero
and value 0
.Show Solution
scilla_version 0
import BoolUtils
(* Start typing from the line below. First define the library *)
(* Now define the variable zero for Uint128 0 *)
(* Now, in the line below, define the variable not_owner_code of type Uint32 and value 1 *)
contract SocialMediaPayment (owner: ByStr20)
transition deposit()
sender_is_owner = builtin eq _sender owner;
match sender_is_owner with
| False =>
| True =>
end
end
123456789101112131415161718192021