Chapter 3: Advanced

Lesson 1: Registering users

Earlier, in the first chapter, we stored user names using variables. However, there might be thousands (or millions) of users for an application. We will need a better way to store those names, than the ones we discussed in the last chapter.

Before we move towards that objective, first let’s simply create a transition which will collect information from the user and allow them to register.

We have a task for you!

After the end of the previous transition, declare a new transition with the name register_user. You can currently leave the brackets after the transition name empty. Also, make sure to end the declaration of the transition with end keyword.

Your Workspace

Show Solution

Solution

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

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)
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
(* Start typing from the line below *)
transition register_user ()
end
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)

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

(* Start typing from the line below *)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42