From ea97f3fdf2b7c280ccd3d5446577a232f8ff4f63 Mon Sep 17 00:00:00 2001 From: a5hk <5412540+a5hk@users.noreply.github.com> Date: Fri, 5 Mar 2021 17:10:42 +0330 Subject: [PATCH 1/2] fixed typo --- src/locales/instructions/en/chapter2/index.ts | 118 +++++++++--------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/src/locales/instructions/en/chapter2/index.ts b/src/locales/instructions/en/chapter2/index.ts index c4310641..3d6687de 100644 --- a/src/locales/instructions/en/chapter2/index.ts +++ b/src/locales/instructions/en/chapter2/index.ts @@ -3,12 +3,12 @@ import { IChapterInstruction } from '../../../../typings'; const l1 = ` ## Lesson 1: Making a transition for depositing tokens -In the last chapter, we learned about various kinds of variables, including implicit variable. -Let’s build a transition that actually uses that. -We’ll first wipe the variables from the first chapter, and from now onwards all the code that we’ll be using will help us directly build the social media payment application that we discussed. +In the last chapter, we learned about various kinds of variables, including implicit variable. +Let’s build a transition that actually uses that. +We’ll first wipe the variables from the first chapter, and from now onwards all the code that we’ll be using will help us directly build the social media payment application that we discussed. -First of all, in order to give ZIL tokens as rewards, the contract must have access to them. -In order to ensure that, we need to build a transition where the ZIL tokens can be deposited in the contract. +First of all, in order to give ZIL tokens as rewards, the contract must have access to them. +In order to ensure that, we need to build a transition where the ZIL tokens can be deposited in the contract. @@ -21,26 +21,26 @@ In order to ensure that, we need to build a transition where the ZIL tokens can const l2 = ` ## Lesson 2: Boolean operations -Now, we’ve to ensure that this transition can accept any amount of ZILs sent to it. We’ve already seen how to do this at the end of chapter 1. -We can simply repeat that process here and technically that’s fine. -However, for any actual application, you probably want to ensure that not everybody can send tokens to this transition. Can you think of a reason why you would deny getting an additional amount? -Well, for one thing, it will make your auditing really difficult if you don’t have a clear track of who’s sending the tokens to your contract. Also, it’s generally a good coding practice to manage access to transitions in a controlled manner. -So, we’ll program this transition so that only the owner can send money to it. +Now, we’ve to ensure that this transition can accept any amount of ZILs sent to it. We’ve already seen how to do this at the end of chapter 1. +We can simply repeat that process here and technically that’s fine. +However, for any actual application, you probably want to ensure that not everybody can send tokens to this transition. Can you think of a reason why you would deny getting an additional amount? +Well, for one thing, it will make your auditing really difficult if you don’t have a clear track of who’s sending the tokens to your contract. Also, it’s generally a good coding practice to manage access to transitions in a controlled manner. +So, we’ll program this transition so that only the owner can send money to it. -We’ve two variables: \`owner\` which is an immutable variable and will always remain constant and \`_sender\` which is an implicit variable and contains the wallet address of the user who has invoked the transition for that operation. We need to have a condition that ensures that deposit happens only when the two variables’s values are the same. +We’ve two variables: \`owner\` which is an immutable variable and will always remain constant and \`_sender\` which is an implicit variable and contains the wallet address of the user who has invoked the transition for that operation. We need to have a condition that ensures that deposit happens only when the two variables’s values are the same. -To do this, we’ll need to use comparison operators which are available in Scilla. These operators check whether the given comparison (such as, is a= b, or is a>b, or is a b, or is a let nil_msg = Nil {Message} in Cons {Message} msg nil_msg -\`\`\` - +\`\`\` + To send out a message, we first construct the message, insert it into a list, and send it: \`\`\` @@ -234,13 +234,13 @@ msg = {_tag : ""; _recipient : owner; _amount : bal; code : got_funds_code}; msgs = one_msg msg; send msgs \`\`\` - -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. + +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. ## Task: -1. In the library section of the code, copy paste the following standard code: +1. In the library section of the code, copy paste the following standard code: \`\`\` let one_msg = @@ -250,23 +250,23 @@ let one_msg = \`\`\` -2. In the 'False' branch of the conditions, declare a variable \`msg\` in the following format: +2. In the 'False' branch of the conditions, declare a variable \`msg\` in the following format: \`\`\` msg = {_tag : "abc"; _recipient : abc; _amount : abc; code : abc}; \`\`\` -Where you will use the following values in stead of the dummy value ‘abc’ used above: +Where you will use the following values in stead of the dummy value ‘abc’ used above: -For \`_tag\`, value should be empty, i.e., \` ""\`. +For \`_tag\`, value should be empty, i.e., \` ""\`. For the \`_recipient\`, we want to send the message to the initial sender, so the value should be: \`_sender\` For the \`_amount\`, the value should be zero. Since we’ve defined it as a \`Uint128\` variable in the library already, use that variable named \`zero\` -For the \`_code\`, use the code that we have defined in the library to indicate that sender is not the owner, i.e., \`not_owner_code\` +For the \`code\`, use the code that we have defined in the library to indicate that sender is not the owner, i.e., \`not_owner_code\` -3. Finally, after you have defined ‘\`msg\`, copy the two lines below that will put this message in the list defined in the step one (i.e. \`one_msg\` variable type) and then send it. +3. Finally, after you have defined ‘\`msg\`, copy the two lines below that will put this message in the list defined in the step one (i.e. \`one_msg\` variable type) and then send it. \`\`\` msgs = one_msg msg; @@ -279,35 +279,35 @@ send msgs const l7 = ` ## Lesson 7: Message (2) -While the last chapter 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. +While the last chapter 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. +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. +So, this time we’ll focus on the ‘true’ condition of the branch. ## Task: 1. In the library section, declare a \`Uint32\` type of variable with variable name \`accepted_code\` and value \`0\`. -2. Then, in the \`True\` branch, we have to accept the money which has been sent. So use the \`accept\` keyword. +2. Then, in the \`True\` branch, we have to accept the money which has been sent. So use the \`accept\` keyword. -3. Now, in the next line declare a variable \`msg\` in the following format: +3. Now, in the next line declare a variable \`msg\` in the following format: \`\`\` msg = {_tag : "abc"; _recipient : abc; _amount : abc; code : abc}; \`\`\` -Where you will use the following values in stead of the dummy value ‘abc’ used above: +Where you will use the following values in stead of the dummy value ‘abc’ used above: -For \`_tag\`, value should be empty, i.e., \`""\`. +For \`_tag\`, value should be empty, i.e., \`""\`. For the \`_recipient\`, we want to send the message to the initial sender, so the value should be: \`_sender\` For the \`_amount\`, the value should be zero. Since we’ve defined it as a \`Uint128\` 0 variable in the library already, use the variable name \`zero\` -For the \`_code\`, use the code that we have defined in the first step of this task to indicate that sender is the owner, i.e., \`accepted_code\` +For the \`code\`, use the code that we have defined in the first step of this task to indicate that sender is the owner, i.e., \`accepted_code\` -4. Finally, after you have defined \`msg\`, copy the two lines below that will put this message in the list defined in the step one (i.e. \`one_msg\` variable type) and then send it. +4. Finally, after you have defined \`msg\`, copy the two lines below that will put this message in the list defined in the step one (i.e. \`one_msg\` variable type) and then send it. \`\`\` msgs = one_msg msg; @@ -320,8 +320,8 @@ send msgs const l8 = ` ## Congrats! -You've learned handling import and library sections. You've also learned working with boolean operators, conditional branches and sending response messages. -In the next chapter, we'll learn about maps and events. We'll also learn working with another boolean operator in Scilla and will practice sending more messages as we continue to build our Social Media Payment smart contract. +You've learned handling import and library sections. You've also learned working with boolean operators, conditional branches and sending response messages. +In the next chapter, we'll learn about maps and events. We'll also learn working with another boolean operator in Scilla and will practice sending more messages as we continue to build our Social Media Payment smart contract. `; const chapter2: IChapterInstruction = { From dce0db10e7f166c1c5867be44c5ed5b93f2a3d16 Mon Sep 17 00:00:00 2001 From: a5hk <5412540+a5hk@users.noreply.github.com> Date: Fri, 5 Mar 2021 22:00:59 +0330 Subject: [PATCH 2/2] fixed typo in chapter 3 lesson 7 --- src/locales/instructions/en/chapter3/index.ts | 122 +++++++++--------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/src/locales/instructions/en/chapter3/index.ts b/src/locales/instructions/en/chapter3/index.ts index 748add92..92f31f8e 100644 --- a/src/locales/instructions/en/chapter3/index.ts +++ b/src/locales/instructions/en/chapter3/index.ts @@ -3,39 +3,39 @@ import { IChapterInstruction } from '../../../../typings'; const l1 = ` ## Lesson 1: Making a transition for 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. +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. +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. ## Task - 1. 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. + 1. 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. `; const l2 = ` ## Lesson 2: parameters for 'register_user' transition -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: +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: a. Their twitter id b. 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 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: \`\`\` transition transitionName (parameterName_1 : parameterType_1, parameterName_2 : parameterType_2, parameterName_3 : parameterType_3) - + end \`\`\` ## Task - In the bracket after the transition ‘register_user’ declare two variables: - -1. Declare variable ‘user_address’ of the type \`ByStr20\`. This will hold the wallet address of the user. + In the bracket after the transition ‘register_user’ declare two variables: + +1. Declare variable ‘user_address’ of the type \`ByStr20\`. This will hold the wallet address of the user. -2. Declare variable ‘twitter_username’ of the type \`String\`. This will hold the twitter id of the user. +2. Declare variable ‘twitter_username’ of the type \`String\`. This will hold the twitter id of the user. `; @@ -44,20 +44,20 @@ const l3 = ` Now, we want to limit the possibility of a same account creating multiple registrations. -In order to do so, we want to impose two conditions: +In order to do so, we want to impose two conditions: -i) Same wallet id shouldn't be able to register twice. -ii) Same twitter id shouldn’t be able to register twice. +i) Same wallet id shouldn't be able to register twice. +ii) Same twitter id shouldn’t be able to register twice. In order to impose these conditions, we’ll first have to create two records, one of already registered wallet ids and second of already registered twitter ids. -We’ll do so using ‘map’ feature. +We’ll do so using ‘map’ feature. A map of type \`map kt vt\` provides a key-value store where \`kt\` is the type of keys and \`vt \`is the type of values. \`kt\` may be any one of String, IntX, UintX, ByStrX or ByStr. \`vt\` may be any type except a function type. -We often provide the key-value \`kt\` as an input and look for the \`vt\` as the output value. For eg, \`kt\` could be a bank account number and \`vt\` could be the corresponding bank balance. +We often provide the key-value \`kt\` as an input and look for the \`vt\` as the output value. For eg, \`kt\` could be a bank account number and \`vt\` could be the corresponding bank balance. -The declaration for an empty map is done as follows at the start of the contract: +The declaration for an empty map is done as follows at the start of the contract: \`\`\` field a: Map FieldType1 FieldType2 = Emp FieldType1 FieldType2 @@ -70,26 +70,26 @@ Then the values are added to that empty map. (You can also check the other ways ## Task - After the start of the contract, declare two maps with no initial values: + After the start of the contract, declare two maps with no initial values: 1. A \`map\` with name \`users\` with key type \`ByStr20\` and value type \`String\` 2. Then declare another \`map\` with name \`used_usernames\` with key type \`String\` and value type \`Bool\` - - + + `; const l4 = ` -## Lesson 4: Map- Checking the existence of a value. +## Lesson 4: Map- Checking the existence of a value. -In order to check whether or not the user id or wallet id being sent by a user have been previously registered, we’ll need to read the value from the map. In this particular case, we simply need to check whether such value exists or not in a given map. +In order to check whether or not the user id or wallet id being sent by a user have been previously registered, we’ll need to read the value from the map. In this particular case, we simply need to check whether such value exists or not in a given map. -The format for doing that is as follows: +The format for doing that is as follows: \`\`\` b <- exists m[k] \`\`\` -This is also called In-place existence check. It check whether in map \`m\`, any value corresponding to key \`k\` exists or not and accordingly returns a Bool which in above example is stored in variable \`b\`. +This is also called In-place existence check. It check whether in map \`m\`, any value corresponding to key \`k\` exists or not and accordingly returns a Bool which in above example is stored in variable \`b\`. Existence checks through nested maps is supported with the syntax \`v <- exists m[k1][k2][...]\`. If one or more of the intermediate key(s) do not exist in the corresponding map, the result is False. @@ -98,7 +98,7 @@ Existence checks through nested maps is supported with the syntax \`v <- exists In the transition ‘register_user’ do the following two actions: -1. Check if the value of the variable \`user_address\` exists in the map \`users\` through the keyword \`exists\`, and then store the value in a new variable \`user_exists\`. This will all be done in a single line as shown in the example above. +1. Check if the value of the variable \`user_address\` exists in the map \`users\` through the keyword \`exists\`, and then store the value in a new variable \`user_exists\`. This will all be done in a single line as shown in the example above. 2. Then, in the next line, check if the value of the variable \`twitter_username\` exists in the map \`used_usernames\` through the keyword \`exists\`, and then store the value in a new variable \`username_exists\`. This will all be done in a single line as shown in the example above. @@ -107,33 +107,33 @@ Existence checks through nested maps is supported with the syntax \`v <- exists const l5 = ` ## Lesson 5: OR operation in Scilla -Now, we have two boolean values stored in the variables \`user_exists\` and \`username_exists\`. We are interested in checking whether any of these conditions are true. -To check that, we’ll use the boolean operator \`orb\` in scilla which returns true if any of the arguments are true, or else it will return false only if both arguments are false. -The format for using it is: +Now, we have two boolean values stored in the variables \`user_exists\` and \`username_exists\`. We are interested in checking whether any of these conditions are true. +To check that, we’ll use the boolean operator \`orb\` in scilla which returns true if any of the arguments are true, or else it will return false only if both arguments are false. +The format for using it is: \`\`\` a = orb boolVar1 boolVar2 \`\`\` -Here, \`boolVar1\` and \`boolVar2\` are two bool type variables. Using them with operator ‘orb’ returns a bool variable which is then being stored in variable \`a\`. +Here, \`boolVar1\` and \`boolVar2\` are two bool type variables. Using them with operator ‘orb’ returns a bool variable which is then being stored in variable \`a\`. ## Task -1. Use \`orb\` operator with the variable \`user_exists\` and \`username_exists\` and store the result in a new variable \`already_exists\`. This will all be done in a single line as shown in the example above. +1. Use \`orb\` operator with the variable \`user_exists\` and \`username_exists\` and store the result in a new variable \`already_exists\`. This will all be done in a single line as shown in the example above. `; const l6 = ` ## Lesson 6: Using match condition -We now have \`already_exists\` variable. If the value of this variable is true, then we don’t want to allow the user to register, however, if it’s false then we do want to allow the user to register. +We now have \`already_exists\` variable. If the value of this variable is true, then we don’t want to allow the user to register, however, if it’s false then we do want to allow the user to register. + +To implement this, we need to use a conditional structure which we learned in the previous chapter we can do through \`match\` keyword. -To implement this, we need to use a conditional structure which we learned in the previous chapter we can do through \`match\` keyword. +For a quick reference, the format for \`match\` is: -For a quick reference, the format for \`match\` is: - \`\`\` match [variablename] with | [pattern 1] => @@ -149,27 +149,27 @@ end ## Task -1. Use \`match\` on the variable \`already_exists\`. +1. Use \`match\` on the variable \`already_exists\`. 2. The two branches corresponding to \`match\` will be \`True\` and \`False\` -3. Make sure to use \`end\` to declare the end of the statements. +3. Make sure to use \`end\` to declare the end of the statements. We’ll fill in the code for the individual branches over the next lessons. - + `; const l7 = ` ## Lesson 7: Messages for the 'True' condition -In case \`already_exists\` variable is true, then we simply need to let the users know about that in a message. +In case \`already_exists\` variable is true, then we simply need to let the users know about that in a message. -We’ll be sending that message in the same way as we did in chapter 2. +We’ll be sending that message in the same way as we did in chapter 2. ## Task -1. First of all, we need to define the code for such an eventuality in the \`library\`. +1. First of all, we need to define the code for such an eventuality in the \`library\`. So, in the library section define a variable \`user_exists_code\` of \`Uint32\` type and value \`2\` 2. In the 'True' branch of the conditions, declare a variable \`msg\` in the following format: @@ -180,12 +180,12 @@ msg = {_tag : "abc"; _recipient : abc; _amount : abc; code : abc}; Where you will use the following values in stead of the dummy value ‘abc’ used above: -For \`_tag\`, value should be empty, i.e., \`""\`. +For \`_tag\`, value should be empty, i.e., \`""\`. For the \`_recipient\`, we want to send the message to the initial sender, so the value should be: \`_sender\` For the \`_amount\`, the value should be zero. Since we’ve defined it as a \`Uint128\` 0 variable in the library already, use the variable name \`zero\` -For the _code, use the code that we have defined in the library to indicate that the user already exists, i.e., ‘\`user_exists_code\` +For the \`code\`, use the code that we have defined in the library to indicate that the user already exists, i.e., ‘\`user_exists_code\` -3. Finally, after you have defined \`msg\`, copy the two lines below that will put this message in the list defined in the step one (i.e. one_msg variable type) and then send it. +3. Finally, after you have defined \`msg\`, copy the two lines below that will put this message in the list defined in the step one (i.e. one_msg variable type) and then send it. \`\`\` msgs = one_msg msg; @@ -198,17 +198,17 @@ send msgs const l8 = ` ## Lesson 8: Map- Adding entries -After finishing the code in the \`True\` branch of the condition, let’s focus on the \`False\` branch of the condition. +After finishing the code in the \`True\` branch of the condition, let’s focus on the \`False\` branch of the condition. -This branch implies that the user information has not previously existed in the maps, so what we now have to do is to register the user by updating their information in the maps of \`users\`and \`used_usernames\`. +This branch implies that the user information has not previously existed in the maps, so what we now have to do is to register the user by updating their information in the maps of \`users\`and \`used_usernames\`. -To add these values, we’ll be using in place insert operations that have the following format: +To add these values, we’ll be using in place insert operations that have the following format: \`\`\` m[k] := v \`\`\` -Where \`m\` is the map variable, \`k\` is the key variable and \`v\` is the value variable. +Where \`m\` is the map variable, \`k\` is the key variable and \`v\` is the value variable. Insertion into nested maps is supported with the syntax \`m[k1][k2][...] := v\`. If the intermediate key(s) does not exist in the nested maps, they are freshly created along with the map values they are associated with. @@ -216,18 +216,18 @@ Insertion into nested maps is supported with the syntax \`m[k1][k2][...] := v\`. ## Task 1. First, in the library section define a variable \`true\` which will be equal to \`True\` -Hint: for boolean variables, you can do this by typing \`let true =True\` in the library section. See the Cheat sheet below for a quick refresher. +Hint: for boolean variables, you can do this by typing \`let true =True\` in the library section. See the Cheat sheet below for a quick refresher. 2. Then, come to the 'False' branch in the transition. There, using the format described above, insert the value variable \`twitter_username\` with the corresponding key variable \`user_address\` in the map \`users\` 3. Similarly, in the next line, insert the value variable \`true\` with the corresponding key variable \`twitter_username\` in the map \`used_usernames\` - + `; const l9 = ` ## Lesson 9: Event -So far, we have primarily used messages to send notifications for the users. However, there is another way of sending information back. +So far, we have primarily used messages to send notifications for the users. However, there is another way of sending information back. A contract can also communicate to the outside world by emitting events. @@ -244,37 +244,37 @@ event e \`\`\` An emitted event must contain the compulsory field \`_eventname\` (of type \`String\`), and may contain other entries as well. The value of the \`_eventname\` entry must be a string literal. All events with the same name must have the same entry names and types. - -For the registration confirmation, we’ll be using event. + +For the registration confirmation, we’ll be using event. ## Task -1. After the previous step of updating the map entries, define an event \`e\` with \`_eventname\` equal to \`register_user\`. +1. After the previous step of updating the map entries, define an event \`e\` with \`_eventname\` equal to \`register_user\`. 2. For the second entry of the event, send the information about field \`user\` containing variable \`user_address\` -*Hint*: the \`_2 \` from the format above will look like \`user: user_address\` in this case. +*Hint*: the \`_2 \` from the format above will look like \`user: user_address\` in this case. 3. For the third entry of the event, send the information about field \`username\` containing variable \`twitter_username\` 4. Finally, in the next line, emit the event using \`event e\` - + `; const l10 = ` ## Congratulations! -You've come to the end of the current content. -More chapters will be updated in the future. +You've come to the end of the current content. +More chapters will be updated in the future. -*The full code can be seen at:* +*The full code can be seen at:* https://github.com/AmritKumar/zil-twitter/blob/master/scilla/Twitter.scilla -*The javascript code for connecting the front-end and the blockchain can be seen at:* +*The javascript code for connecting the front-end and the blockchain can be seen at:* https://github.com/AmritKumar/zil-twitter/blob/master/frontend/src/zilliqa.js -*The online IDE is available at the following URL:* +*The online IDE is available at the following URL:* https://savant-ide.zilliqa.com/ @@ -283,7 +283,7 @@ https://scilla.readthedocs.io/en/latest/index.html *For any feedback, reach out to us at the channels in the footer* - + ## Thanks! `;