Chapter 3: Advanced

Lesson 2: Parameters for new users

When users will call the register_user transition, they'll have to provide some data to the transition so that they could be uniquely registered. We’ll ask the users to provide:

  • Their twitter id
  • Their wallet id
  • We have covered this in the first chapter but for a quick reference, in case we want to declare multiple parameters for a transition, then we can do so by separating the parameter names and types by commas, as shown below:

    We have a task for you!

    In the bracket after the transitionregister_user declare two variables:

  • Declare variable user_address of the type ByStr20. This will hold the wallet address of the user.
  • Declare variable twitter_username of the type String. This will hold the twitter id of the user.
  • 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
    (*type within the brackets in the line below *)
    transition register_user (user_address: ByStr20, twitter_username: String)
    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
    
    (*type within  the brackets in the line below *)
    transition register_user ()
    
    
    end
    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