Sesión 8: Fundamentos de Rust - Parte 2
Ethereum Lima·Sun, Aug 9, 2026, 12:00 AM
https://bootcamp.ethlima.org/
Transcript
Now, starting the RAS part of the mini-project and also finishing module 3, we present Henry Ken Carazona again. He is a software engineer, he has been in the community for quite some time, he is in the Ross Peru community and of course he has already given us a first lesson in fundamentals. in which not only was the theo part spoken. Uh, we've already shared a little bit because currently hello, how are you? Can you hear me?
Yes. Hello, guys. They would wait a while for me to turn on my camera here on my other laptop. While I'm projecting. It's being updated, but let's see how it goes, guys.
This, if let's say it's the first time they're going to see the chat with me, you can put it in the chat as a way to give them a little introduction if they haven't seen it before. But in short, well, last session we covered topics like the basics and that's it. And well, we'll probably keep playing some things. Last week we looked at topics of structures, that is, whether they come from programming, for example, JavaScript or Python, it's similar. Okay, let's see, here's the project.
Last time I think time didn't get the better of us . Okay, give me a tap. Already. Let's see, let's see, let's see. Okay, this is a brief introduction to what we saw last week, so it's super quick.
Uh, when we created a project in RAS, I also shared the material to create your first project in RAS, both the commands and the guides to be able to, let's say, move forward, right? The materials from which you can obtain the basics as well as to start creating projects. But basically, yes, purely in the programming part we can generate modules so that we can call them in the main file of our project using the same names they have. This first session one is our project, it consists of a Tom position, just as in Android we have, well, let's say, the place where we package the versions. That's exactly what it is here.
I'm using an ID called Ross Rover from Intel, which allows me to make an instant modification to any change , right? If I add dependencies, I don't have to refresh; it downloads automatically, right? That's the beauty of, let's say, the language, that it makes things easier to install. This, we already have variables just like any other language, so by default the variables will be immutable. That's what we were telling him.
Uh, the idea of immutability is precisely one of the pillars of RAS, which is that we cannot give a value to another variable, right? In other words, I cannot define the value here. For example, here I think I have, look, here I have x, right? I ca n't tell him you're worth six now because that would be a mistake, wouldn't it? He says, "Hey, you can't assign a new value to a variable because it already has a value."
They're just little things that, well, it would be a matter of seeing. Then we have the issue of constants, right? Okay, sorry, where we present a data structure where we can see, right?, that it is more accessible. In this case it would be 21 21 m000ones, right?
But with a low font size so that it is more legible. And we've also talked about the types, haven't we? These are 64 bits, 32 bits, right? This U with the i, this u is therefore without a sign and the i is with a sign. Well, here's a little more about the types, and if you want to see it right here, right?
This one, the u, sorry, the u is without a sign, it can never be negative. And the letter i can indeed be negative, since it has a sign, right? It's just like a protection against, let's say, cases where a value can be negative, and if it becomes negative, it defaults to zero . And well, after that we have the 64-bit and 32-bit values. Let's understand this as, let's say, the memory space where it will be stored.
Uh, we also have uh the 64-bit and 32-bit floating-point numbers. They are not very common, but they can also be used. The Bulians, if we come from programming, here are the true or false values, which in the end, well, this is for Bulian logic, right? Cer, uh, true, false, right? Uh, then we have streams, and here we were talking a bit about references, not to generate an exact copy and increase memory usage, but to take a pointer to an object and only be read-only, right?
in order to be able to read a value and then work on it. And then we have the stream itself, which is a reference, but in this case we are already creating a stram value, and a bit of format combination that allows us to concatenate or work on text strings. We also have tuples, right? Which is identified with the parentheses and here we can store different types of data, the destructuring, right? For example, here we have a transaction that is a tuple and we can extract values and work with those values, and in this way we don't work with the indexes, right?
CER transaction, transaction one, transaction two. Then we have arrays that are delimited by a specific quantity and of a specific type, right? And if we change a value here, then we would have to add it here. And well, here, like any other programming language, we work with indices, starting with 0 1 2 3 4. Then we'll look at some functions.
Functions are defined using the reserved word fn function. In this case, he is saying hello. We receive parameters referencing a string and a 32-bit numeric value and we return a string and at the end we do a format and here in this case we concatenate the values. For each key that we add inside the quotation marks, we have to add a variable that will be passed to the value of the key. Uh, then we have, well here we can do mathematical operations, right?
In this case, to calculate a percentage, we take the amount that comes as a parameter, divide the percentage by 100 and return a 64- bit number. Here too, the same logic applies to doubling, to check if it is even or odd, to check if a is greater than b, we return a and if not, we return b. And well, here are more operations. Here we will return a tuple of a sum with the product of two values that will serve as input and we return the tuple. And here are a few examples.
This code was shared last week and you can go view it. This also applies to control flows, right? The if, the loop, the while, the for, and the match. We use if statements for conditionals, right? If this happens, we will do such and such.
If that doesn't happen and something else happens, we do this thing. And if none of those happen and something else happens, anything else, we do this other thing. It's logical. And then, well, we print. In this case we are iterating, right?
This, this is the next one also of the control flows, which is, for example, the for loop that we are going to iterate through for the number of cases. In this case we have 1, 2, 3 cases. We will iterate four times and in each iteration config will take these values. First, it will take this one and enter this flow. That state is eh of the configuration is equal to zero.
In this case, yes. Here too, so you remember zero as a 32-bit integer, okay? And if it is zero, as in the first case, then it will come out pending. If it is greater than zero, but less than six, it will come out as confirmed. And if it's already greater than six, then it will be confirmed and will be shown for each one of these.
Then we have the loop, right? This one, to keep iterating. In this case, we work with the reserved loop parabola. until in this case the value is greater than 1000. And here we multiply the value by, that is, we multiply by two until it exceeds that value and it comes out.
Oh, another thing to remember is the while loop. Here we remember that we are adding up the total as the value of i of the index so that when it meets any of those conditions, that's why i, right? In other words, this and this are true. Uh-huh . This condition is met, then it exits the loop and returns this thing here, which is the accumulated amount.
And here's the thing, what I was telling you about, right? Uh, this amount will be taken for each iteration and this is precisely the reference of the vector. Today we're going to talk about vectors. The reference for the amounts, which are the vector part, is a vector where we can store different types of data and we will be printing them. For each iteration, the weight will be printed.
Then we have the use of indexes with iter and enumerate, it's the same thing, isn't it? Except in this case, we worked on it this way. Let's say we're going to work with a tuple that will return an index and the amount of amounts, that is, from here, sorry, from here and for each of them we're going to have an index. Index in the first one will be zero. There's a difference here: when we work with Ford, we have to make a reference to the amount, but when we work with Enumerate and iterable, we don't have to make a reference because internally the iterate enumerate makes the reference and we would already be working with the amount reference and with that we will be printing the index with the amount.
Okay, if you want we can run it so you can see it. Here it is. There's a bit of logic here, isn't there? What I was telling you about the variables and the blocks with the data types, right? This is the value that can be negative.
This is the address. Okay, but let's go straight to for loops. Here's the if. And here we have the forum. And here we have the for loop with index.
Look, here I was showing the index. In this case we start at 0 1 2 3 and the amount 500, this 1275 and 3,000 which are exactly these values. You say, "Hey, but damn, I use the index starting from one." Already. So in this case, we simply put + one here.
And if we run it again, this, we go here and here, well, it starts from one. In the end, it's similar to any other programming language in terms of logic, but it's okay. Now we also have the match that we were working with and later we will work with the Enum, but here the match is ultimately for mapping, right? Hey, if this value is equal to this case, then we do this. If the next value is equal to this case, then no?
If it's the same as this other case, then we'll do this action. That's why the descriptions, right? We're going to get the descriptions, these descriptions based on this match. We are going to return a string here. This will return a string.
The description will be a str reference, which are these values here. They will be stored here. Based on the code and code, it will iterate through the set of codes, and these codes are from here, and it will iterate 1, 2, 3 times, and in each iteration it will take these values. In the first iteration, it will take the 32-bit zero, the 1, the 2, and the 99. Here's a hack.
I don't know if you've seen, if you 've noticed, that the first value always defines the type when we talk about an array. Why are we doing this? so that the variable 'codes' automatically knows that this is a 32-bit array, this 32-bit array. And well, that counts, right? 1 2 3 4 are an array of four values.
In that way, at least with the first one, this value is already typed, we can, let's say, define what code will have such a value, right? Already. There's a match by ranks here, right? From 0 to 99, from 100 to 999. These two points are like a little help so that you can, let's say, work on it, right?
In other words, to have the notion, right? This is how it works, right? 0 point 99 to say that we are working from 0 to 99 and well, it's shorter than applying an if. Let's see, a touch. That's control, overship, which is ultimately the main idea that there is only one owner, right?
And here we've seen some of these topics like moving, cloning, the same reference, mutable references, and scope, right? For example, to move, in this case, the property is moved to another value, and with this... Let's see, let's see, let's see. Oh, I see. Let's see, let's see.
Oh, excuse me, excuse me. Yes, now we're talking. Ah, I was already setting it up. Yes, now I think they can see me. Perfect.
Already. The thing is, I have my laptop here and sorry if they don't recognize me. I cut my hair yesterday. This is where I've been working on the project, right? And here it will be easier for me because I can have the chat at hand and see if they are typing.
Okay, fine. This, it's already a bit of a shift in the variable, I'll explain it to you, right? Let's define S1 as having the value of Ethereum in stream, but now we want to move the value to S2, whatever the case may be, simply, because in this case we want to move S2. Uh, S1 has the value of Ethereum, we're going to transfer it to S2, but when we do this process, S1 will no longer own that value. Therefore, if we uncomment this, it will give us an error.
He says, "Hey, darn, this variable has been moved, you can't use it anymore, right? That's why this is happening. Let's see. Oh, there's an audio problem there, let me know. Okay, in this case I'm using the camera here and here.
Okay. Um, then we have the detail of primitive values, like numeric variables as well as Booleans, which make copying implicit. Copying is similar to moving it, not so similar because it doesn't actually move, it simply makes a copy, and when you make a copy you can continue using the first value because, well, you've made a copy. They both have the same value, but they don't refer to a common object, they're simply in different contexts. Hm.
And you can use, for example, here A is worth 42, B is worth A, but here you can see we're referencing, that is, we're calling A, so A still has a value. Um, which is similar to cloning, which is like A copy, right? That's what we were talking about, but cloning is like explicitly copying, okay? I mean, numeric variables do it implicitly. I mean, when you do it yourself, well, when you pass the value of `a` implicitly.
But if you want to do it more explicitly, you use the reserved word `clone`, and you get the value of one, of two, and it works. We have to use it sparingly because we're generating more memory . I don't know if I mentioned it before. The boss is ultimately the mountain where you keep loading things, increasing and increasing, but it's not very advisable. It's like using a language and taking away its essential strengths, what makes RAS so powerful, which is making it as fast as possible.
From there, it's done through these little things, right? Hey, don't use ` create copies`, you can use references. We're going to look at a bit of the... Mutable references, right? Where there can only be one.
I think that's something to remember, right? A single reference when it's mutable, but you can create different immutable references, right? Because they'll only be displayed and worked on. Uh, precisely the references, borrowing is precisely the references. We have this with this value and we want to borrow, this is the detail, it's borrowing, we're going to borrow the value of S1 to the function to do something.
In this case, we're not giving the value, we're not, let's say, giving the property, and we're only borrowing the reference. Imagine it as a pointer that takes the value but only reads it, okay? Because in this case it's an immutable variable, it will only read it, it will only see it and work from the value. In this case, when it takes the long value, it receives that variable from a reference, we know that this symbol for person, from a string reference, the value will be a string, but it will be a reference and we're going to return an index. In this In this case, the index will be the size of the text reference.
We haven't modified the text; we 've simply taken it and used it to return a value, which in this case is its size. And with this, we'll store it in `long`, and `long` automatically recognizes it, saying, "Ah, this is this value." And that's what we're going to print. This value has this size, which is right here. [Move, sorry, fly, but this is in the other recording, but just to remind you.]
Here we have references, right? R is this here. Let's see, sorry, I just got lost. It has characteristics. Here's this value here, which is this one; it has 15 characteristics, or well, five 15 characters, sorry.
Okay. Now, you can have multiple immutable references. This is what I mentioned. That is, you can have multiple references that you can only see because you're not going to modify them. That's why you can make R1 a reference to S1, R2 a reference to S2, and you can print both.
Here it is. R1 is the same, R2 is the same, because that's what they observe. Okay, this is the function. Now, you can also work with mutable references; you can modify a value. In this case, we have a variable called project, which will be a string, but it will be mutable.
And well, its value will be my app. In this case, it should be my app. Now we're going to use a function called add network, but we're going to pass a mutable reference, project, as a parameter . Let's see what the function does. The function receives a name, right?
, of mutable reference. It's a mutable string reference, and what it will ultimately return is the same value, name, but it will add it to Arbitrium. Well, push string is adding a string; in this case, it's Arbitrium. And if we go here, this is what my app will print in Arbitrium. If I reload because I added some text there.
Let's see, just a moment. Okay, here's My App in Arbitrium. Uh, there. Here, we've passed it on, and as I mentioned, right? There can only be one mutable reference that we can modify at a time.
Why does this happen? I explained this, and ultimately it's precisely to avoid generating nulls, right? For example, if I have a value and two people are modifying it simultaneously, we can create a conflict, and by creating a conflict, we lose a lot of data. It's somewhat illogical, is n't it? I know there are languages that can do this, but RAS specifically wants to avoid these problems, and that's why it works with mutable references, but only one can be modified at a time.
Following this, here we have the scope. As I mentioned, the scope is part of a loop, whether for or if. The scope is delimited by curly braces. It's the area, the space where a variable, a reference, or a function will live. It's where it will reside.
Outside of that, you can't... To refer to that value because it's out of scope, it's already outside the scope, right? Um, for example, here we're seeing, right?, that it's going to be temporary. That's a temporary stream.
It prints that within the scope and it works. But after that, I mean, after leaving the scope, it says that it's released. Um, I mentioned this, right? This is the nice thing. Ras, Ras doesn't have the garbar collector issue, which Java, for example, already has, where when you compile, there's , let's say, someone cleaning up, sweeping up all the things that are n't used.
In this case, to avoid this complication, because that ultimately generates runtime delays, it generates processing delays, which is what we're looking for to reduce costs in terms of contracts on the blockchain. And that's what makes it fast in many aspects, because Ras isn't just for blockchain. Um, by managing it from this perspective, it doesn't generate someone who has to control what cleans up and what doesn't. In this case, for example, the GC is ultimately the garbage collector, right? There's no leak, no gap where we have the garbage, so to speak.
"Garbage" isn't a misnomer; literally, the garbage collector is what cleans up the garbage. So, we have, well, here for example, if we uncomment this, we'll get an error because it's no longer within the scope; it's outside the scope. Right here, an error: we can't find it within the scope. In this case, the scope is these two curly braces. So, let's delete this because it doesn't recognize anything within that scope.
And if you look, it doesn't exist. It only exists within its curly braces. If you have any doubts, you can comment, but here's the evidence, okay? And then there are the topics of structures and enums. If you've worked with TScript or Java, you've surely seen something about enums.
In this case, we're going to look at structures, let's understand them as classes. We already know that classes are... A template of what an entity, an object, will contain. In this case, for example, a transaction has someone who is going to send it, right? For example, me, Henry, to whom, I don't know, in this case it could be to Javier.
Um, an amount, a quantity, in this case it will be a 64- bit value, and a block, an identifier in the transaction, of 32 bits. I'm guiding you this way so that you also go hand in hand, hey, how do you handle it in blockchain, right? Because in the end, this is a case of a blockchain transaction, and this `<transaction>` to derive from `<transaction>` is precisely so that it is displayed in the console. Without this, it won't be displayed in the console, and if we call it a "difficulty" error, well, it won't be displayed, it won't be an error. No, you can't display it here right now.
This here is precisely the transaction, which is a structure, we call it this way, two dots and the `<transaction>` Below. If we don't have this in our structure, we're going to get an error here. Let's see, let's try it. For example, if I do this, we get the error here, right? Hey, transaction can't be implemented as a debugger, that is, to debug in the console section you have to add...
uh, it tells us right here, right? Hey, add this from here to transaction. If I click and go to transaction... Let's see, sorry, where is transaction? Well, it's already been added .
That's precisely why we understand structure as a template, right? It's a class for our objects. Here we define a function, we pass parameters, we return... that's the concept right here, right? Of implementing the structure.
When you define a structure, you also define an implementation of the structure and within it you define the functions. Just like in Java, for example. In Java you define your class, right? Your things and you also have your functions, right? Uh, your gaer, your ceder, your function, your string, your function calculates based on a percentage or something of your attributes.
Okay. Well, similarly, here you implement it with the same name as your structure, and inside, for example, this is a constructor that will generate a new transaction, a function that will be called new transaction. We pass all the parameters it will receive: a stream reference for D, a stream reference for where it will go, a 64-bit number for the amount, a 32-bit number for the lock identifier, and we're going to return ourselves, that is, to the structure—that's why the 'self'—and that's why we return a transaction where we'll pass D with a ' to stream' to ensure it's a stream, and the amount and blocks will go just like that. There's a concept from Shutter Hat here, which is precisely that if it has the same name for both input and output, just use it. Uh, That's right, is n't it?
If the variable is the same name as the field, then just use it. But here it can't be like that because we're parsing safely to ensure it's a stream. And here we have functions that can be useful, right? For example, to check if it's valid. We parse ourselves.
Imagine it as a structure: we parse ourselves and we 'll return a Boolean value if it's true or false, if it's valid, right? If a transaction is valid, what does it do? The same transaction, right? Self, right? So it relates it, right?
When we talk about Celes, the same transaction, if the amount is greater than zero and the sender is different from the recipient, I mean, I ca n't say, "Oh, I'm at the bank, there's no concept," no. I can't self-plin, I can't send a plin to myself. It's possible, but it 's not ideal. In this case, for example, it's this validation. I can't transfer to myself, nor can the amount I can transfer be zero.
If these two things happen , if it's zero, if I 'm transferring to myself, it will return false. But if, in the end, these things don't happen, for example, if the amount is greater and I 'm transferring to another person, this will return true because we're returning a Bulian value, and this ultimately becomes something Bulian. It's logic, right? I mean, it's something we deal with, for example, in academia or at university; it's logic. It's about saying, "No, if this happens and this happens, we're going to do such and such."
Uh, the i, which in the end means these two have to happen no matter what. Uh, if any of these don't happen, we end up returning a negative value, which in this case is false and it's, let's say, kind of like an English legend, right? Uh, in this case, for example, a summary that is your stream in Java, for example, that we are going to return a stream that will return the details of the transaction. In this case, the transaction will have a block, it will have who is sending it to whom, and the amount being sent. And just when I select, you can see what is going to be placed.
Already. And here's a demo, right? Uh, I define these transactions. Here I define it as an invalid transaction because Carlos is, let's say, transferring to himself. And that's what's going to be shown here, right?
It is a valid transaction and Carlos is an invalid transaction because he has violated the concept that he cannot transfer to himself. And with this, we have control over what we handle. Okay. And we already know that this is for debugging. And here or here we have the topic of the Enom.
Hey, ENOMs, if you've seen this TypeScript or even in Java, there's the topic of Enums. The Enumores that you define for, let's say, categories. In this case, a transaction can have states. It can have a pending state , a confirmed state, and a failed state. If it is confirmed, we will display a block, the transaction identifier, which will be a 32-bit block, well, 32 bits.
And if it has failed, we have to show why it has failed. That's why we return a stream and that's it. Now that we're on the right track, we'll show this value, right? In this pending case, well, here in the current state we're going to show, right? Hey, we're waiting for the block.
If the transaction is confirmed, we will work with the block and show that the block has been included, such. Now if it has failed, let's capture the reason and show that it failed because of such and such. This is how we're going to show it, right? Now, then we have some cases of NO, right? Our descriptive method is to see what works , isn't it?
Uh, this is exactly where the match issue comes in, right? We're going to mark the states that we're always going to receive this detail, right? The references. Usage needs to be optimized . In this case, we capture a reference to a transaction state and we are going to return a string.
That's why these texts. Look, the great thing about the ID is that, look, I select it and it tells me, "It 's already a string, and these are the cases it will return. If it's in a pending state, it returns that the block is included. If it's in a confirmed state, it says that such and such has been confirmed, and if it failed, it failed because of such and such. That's what our function will return.
And when we execute these transactions, right? In this case, pending, confirmed with block such and such, failed because of this, pending, failed because of this other thing, failed because of this other thing, and confirmed, it will return this information with its respective parameters, which is precisely here, for example, the first one says that it's pending, it says, "Hey, uh, the minol is waiting for the inclusion of the block, which is precisely the message we showed above." Now, the next one is a confirmed transaction. It says, " The block with this value has been included." The next one is a failed transaction, in this case, insufficient gas.
The next one has included the block, and it's waiting for the block, right? In the end, depending on the transaction states, it will show something. Here we have the issue of SOM and NOM. This is precisely to avoid the use of undefined nulls. SOM means something doesn't exist.
It forces you to work with these two cases. It's either something or nothing, but you manage it, and you won't get these details like, "Oh, the value ended up as an undefined null." In this case, we have the addresses, right? In this case, Alice will have 100, Bob will have 300, and Carlos will have zero. Now, for any other case, it does n't exist, right?
That is, the address wasn't found. And here we're going to work... This whole process is precisely about options. If you've seen generics in Java, you probably understand it a bit, right? In the end, we're working with a generic, right?
It's a very general value; it can be anything and can be included here, right? If my generic here is a stream, then it can be passed as a stream, or if it's a generic like, I don't know, or a floating-point value, then a floating-point value can be passed, but it will have to capture that value. Okay. And this is how it works , right? Okay.
Now, what are we going to do? We're going to generate a list of arrays, four stream reference values. My ` Alice Bob` automatically detects this , an unknown value to return from an error, and a `Carlos`. Now we're going to match all these addresses. We're going to look up their balance, which is this here, right?
I mean, we're going to print it, right? Yes, well, here we're going to print the balance, and if the balance is negative, then it prints Zero. That's why this is the wrap or zero. And we're going to print whether the balance is something or nothing, which will be printed as true or false, if I remember correctly. Here it is.
Okay. Now, to do these things, we're going to work here on the balance, right? Balance. We're going to capture the addresses, right? The addresses, which, to reiterate, right?
This one here will take these values for each iteration because it will take the values of address. Address is an array of values, and for each iteration, this here will become the value of ADDR. And we're going to work with this here, right? Okay. Uh, addr, look, we're going to do it this way.
I'm going to copy it here, I'm going to turn it off here so you understand. And in this is the first case, it will be turned off here, pasted here, and turned off here. Now we're going to do Alice, we're going to check if it exists, if it's something, it won't detect If it's something, it will display it, but if it doesn't detect it, if it can't find it, it will return to N. That's the case with unknown. It won't detect unknown because it doesn't exist.
It will go here, it will go here, and here it will return unknown. Let's see, where is it? No, it hasn't been found. It's not there, there it is, look. Sorry, sorry.
Okay. And it will keep iterating like this. Why am I doing this? So you understand that, for example, these are, let's say, the addresses we have, okay? And Address can only have these values.
That's why, since unknown isn't here, it will enter this case, this match. It will return non, and since it's not here, it will enter... it will print this unknown not found. That's why it prints this here. Let's see, this one here.
But for any of the other cases, it would print, it would print its, let's say, its balance, right? For example, Bob says he's 30, for example, here 's Bob 30. Uh, we have Alice, who is 1500, who is here. Uh, we have, for example, Carlos, who is zero, right? And that's going to print, it's going to come in here, it's going to print his address and his balance.
Okay. Then we have useful methods that, precisely, if it's something, in this case, for example, let's see how I explain this. Okay, look, here we have Alice's balance. Alice is going to have a positive balance because Alice has 1500. Since it's something, since Alice is something because it's going to come in, it's going to print here as true.
Som true. But if Alice is n't something, it should print here as non, that is, it's not something, and below it should print true. Let's see, I don't know if you're making me understand or I've lost you, for example, unknown, which isn't something but rather non. It should be printed the other way around. Here we have unknown.
Unknown is. Ah, unknown is because it doesn't exist here Enter, enter this case, and as it is, when I say balance, it's something, it's not, here it will enter as false. And when I say balance is, that is, it's nothing because it entered here, it will be placed as true. It's the other way around, if you've noticed, it's the other way around. If I put ali here, first it will come out as true and then it will come out as false.
True and false because, uh, Alice is something, it does have a value of something, and it can't be, it's not something, that's why if it is something it won't be true. If it's nothing, it will be false. There, if you don't understand, just comment. There we can explain it. Now, if we are only interested in knowing if it is something and not, we can do it in this simpler way , without involving.
For example, if the variable of something passing the balance, uh, let's say these values will be, uh, let's look for Bob's balance, right? In the end we know that Bob is something. This Bob is something already and has the balance of 300. In this case, it will work because here it will be Bob's balance, that is, it will be something like 300. 300 will enter here, here it will say BOB's balance, not 300.
And that's precisely what it prints here, because it's making the match, because this function enters and here it says, where is BOP? Bob is this, BOP is 300. And we, in the end, return the generic value, which is 300. And this here is precisely what it returns here, that is, this becomes 300, right? The balance becomes 300, and when we call 300, we display it, and that's what's shown here.
Oh, no, I don't know if you get lost, but let me know. We're doing a recap here. It's a bit of logic, right? Hey, since BOP is something, in the end we're going to display it. And here's a little exercise, well...
Um, there are some extra things for you to see, but it's basically something we 've already covered, right? In this case, we have a block, right? And here, a block is a structure, right? Which is exactly what we were looking at here. There's a vector concept that we'll look at today.
And we're going to create this block with a number and a hash, and we're going to add transactions to the block. We're going to add amounts to them, right? For example, here, `add transaction` in the block is a function within the block's implementation, a bit of what we've been seeing: ` add transaction`, which will make a mutable reference to itself, it will modify itself and obtain a 64-bit number, and what it will do is take itself, it will take the transactions, the array of transactions, and it will push, that is, it will add a new amount. Right? So when we add 500, 1275, we're adding the transactions to, let's say, in my case, right?
Wow, I've spent 500, I've spent 10000, I've spent 75, and it's going to keep adding. Now, what is the amount? When we go to block, amount, where is it? Over there, transactions is a vector of the amounts, right? It's precisely a 64-bit vector.
For example, if we go here, right? For example, when we create a new block, we only pass the number and the hash. We don't pass the transactions because the transactions are going to be added. This is a function to calculate the time. And here we add the transactions.
That's why we make the mutable reference to itself and put the amounts into the vector. Then this is the number of transactions. Here we get the len, the size of the transactions in the vector. We're going to sum, we're going to iterate, right? The point is to iterate, let's say, all the transactions and then we're going to sum them.
And that's what it's going to return. Now, here's where it's validated, right? If it's large, if, let's say, the amount is greater than the threshold, right? We return true or false, that's why it's Bulian, right? It's a Bulian return.
If the amount is greater than the threshold, we'll return true. But if not, we'll return false. So, the largest transaction, what's the largest transaction? It gets the transactions, it's going to iterate, it's going to copy the maximum value because it's going to be a new value, it's not going to be a reference, but a new value. Now, to print transactions, first it's going to check if the transactions and my transactions are empty.
I'm going to print "no transactions" and return. But otherwise, we're going to iterate, right? We're going to do an enumerative iteration of my transactions. And we're going to return the amount at index and we're going to print, right? Uh, with index such and such, amount such and such.
This is to get the time and this is for Let's see if it's recent. And here we have the exercise, right? Block X with the hashtag has three transactions. We've pushed three transactions. The total is X because we've added our transactions, and the threshold is large because it exceeds 1000, since it's 1000, this is 1775.
If we look for the threshold, the threshold is here because we're saying, "No, hey, my transactions are greater than the threshold, and what is the threshold?" We pass the threshold as a parameter to verify, right? Yes, he/she is older. If we enter 2000 here, it will return false because 1700 is less than 2000. Now, what is the larger transaction?
It's something and it's 10000. That's precisely the function of this larger transaction. We return a generic, an option, right? An optional generic where we will iterate, copy, and return the maximum. That's why this is coming back to us, right?
Ah, then we have transaction details, that is, this is where the transactions should be printed. There should be transaction details here; we call to print transactions and there's a for loop inside, right? And it will show us all the transactions we have made, which is what we have pushed. And then we have the timestamp, right? To capture the current time.
And if it's recent, where is it? It's here. Yes, it's very recent. There's a logic to this, isn't there? To verify this, there is a function called the saturate sub, which is a function that calculates from the last operation or the last value.
In this case we are doing this, we have our reference to ourselves, the current 32-bit block, that is, we are going to take the current block as a reference and we are going to return true or false. Now, in the current block, we're going to execute this function based on the number of transactions , the number we're working with, the last number, and we're going to check if it's less. It's logical, isn't it? So, in the end, all of this is logic that you can build up, right? Hey, I want to do such an operation for such a thing and let's say you build it to, let's say, show, that's programming.
In this case, well, it's a slightly more complicated thing, isn't it? So here's the thing, isn't it? It is recent with respect to a given current block , that is, within the last 100 blocks. This is a case, isn't it, where the question arises, is n't it, whether the transaction that has been carried out with respect to the current block is recent in the last 100 transactions and this is used as a way to work with it. It's a way, it's a function where we optimize the use because it's already specialized for this type of operation.
With this we made a reminder. Now I would like to talk a little bit about what we are going to see today. Just like last week, this week we were comparing Solidity with Arbitrium Stylus with RAS, this is a bit about the differences, right? What makes RAS so attractive is precisely the detail of its handling of nulls, undefined values, the handling of a single owner, and a more native or low-level handling, unlike, for example, Solidity, which is a bit more expensive and has a higher level of computing power. in computing capacity, uh, and well, its interoperability is not closed, right?
And that, for example, is one case. Today we're going to look at, for example, the details of panic, right? We're going to panic, aren't we ? Uh, what do you mean by panic? When something happens that shouldn't, right?
For example, in basic math, numbers cannot be divided by zero. And if it happens, let's panic. It's kind of a reference point so you have an idea, right? Something is being done that shouldn't be happening, and that's when he panics. Panic sets in, the compiler tells you, "No, hey, you can't do that."
And there you can correct it and there you avoid, let's say, problems in production, right? It's, let's say, the interpretation so that they can understand it, right? Ultimately, these are mistakes that are not recoverable, they are unrecoverable, right? Cases like critical buses, committed invariant states, division by zero, right? Which is exactly what I told you, a consequence, well, a consequence in blockchain, right?
Uh, an immediate review of the transactions needs to be carried out; there may be a gas leak, right? Let's see, where is it? Already. And the panic button is precisely to prevent your system from crashing , right? It's a silent crash that you can detect, right?
The compiler forces you to do it, right? So you model the cases correctly and don't panic, right? That's the idea. Uh, then we have recoverable errors where we can, for example, in any other language this is also worked on, which are exceptions, right? In this case, we capture the errors and from those errors, we return some action, we show something to the user.
In this case, for example, we work with Resul and two generics, its use cases, right? Invalid user input. It's very common, I don't know, for example, in Java, in Springbot we handle the Global Handler or the same Handler or Deception, which is precisely when we receive a value that, for example, shouldn't have been entered or if it was entered, we have to return an error, but in order to show the user, hey, you made a mistake adding this, the user will know because the user won't see the console. Ultimately, the user will see something visual. And the idea behind these errors is precisely to propagate an error that the user can understand.
This is how errors are handled, but these are recoverable errors that we can capture and work on and show something based on that. Uh, invalid user inputs , insufficient balances. Hey, you made a transaction, but it has no balance. Or business validations, right? Within the business context, let's understand, because it can be anything, right?
blockchain. In this case, blockchain, well, the transactions, there are operations that will serve as your business flow, right? And that's where you have to validate, okay? You have to understand that when we talk about business, we're talking about logic. logic within your use case.
Well, then we have the consequences, right? Blockchain, right? Uh, we have two cases, either it returns that everything is correct or it returns that there was an error and that's where we control it, right? Error with the contract, insufficient balance and that's where the enumerations come in. These are things we're looking at and they'll be used, and later on in subsequent sessions they'll be used.
Here, for example, the contract, right? A contract error can have two things. Either you have an insufficient balance where what you have available and what is required will be used, or you have a zero balance. In other words, since the amount is zero, you ca n't do anything. Okay , now.
Uh, the boil, well, boiler prate is precisely or also in Java what is called verbosity, right? Which is precisely being redundant or doing more things than can be simplified. For example, you have a function that performs if and value calculations. You do many ifan yidad given and and and you don't go out, you don't return. What you're doing is creating complexity.
There's a concept called complexity, which is one of the details in code quality that, if you exceed the nesting limits, should cause an error. There are already tools that are used, for example, Sonar to detect that, where in the end you have to generate quality code that is optimal, scalable, maintainable and one of those details is generating more complexity than you should. or to be very verbose in doing something. By verbose, I mean generating too much code if it can be done in less code. For example, this is a case that we're going to see in code, but this is the case in which there is an operator in RAST that allows us to do things more efficiently within error control, which is the question mark that is precisely, let's say, enclosed in a circle, which tells us: here we are going to show an error if an error occurred, and below it says, if nothing happened above and it arrives here, here we are going to show: The error did occur here; it is an upward propagation.
Uh, what happens with this is that you no longer generate insanity, uh, where you say, "No, hey, if this happens, we have, I mean, if something happens, okay, this happens, if something happens, error, the other happens." And then we have another case, right? In the block, if this happens, then this happens. If the other thing happens, uh, if an error occurs, this happens, which we're going to see in code right now, which is, let's say, like this here, right?, which is precisely the amount, having it at the bottom, without the question mark, and the same for the block, the bottom part.
And we solve that by extracting that logic and using the question mark so that we only capture the error. Well, at that point, it's our little flag that tells us, "No, if a mistake happens here, we're going to work on it." Uh, it's called automatic error propagation. Now we have several things to show. In this case we are going to look at vectors.
Vectors are like arrays, but arrays that you can add to, stretch, have no limit, and you can add different values of different types. We've been looking at it in past sessions, and we also saw it in the recap. Then we have anonymous functions, or the second option, which shows that they are filters. If you've seen topics like lambda or anonymous functions in JavaScript or TypeScript, it's similar; instead of creating a named function, it's a function without a name that ultimately works like a constant to make it easier to work with, right? Uh, then we have the processed output, right?
Where we iterate, well, there's a consumed iterator, right? In this case, one use case of data ready for mutation. Uh, these are native tools in RAS that will allow us to work more easily. Here we have a structure that's somewhat helpful to remember, right? A structure where we can work with vectors and, well, the implementations to generate the use case functions for the structure.
Uh, there's a sort of fork in the road here, you know? The use cases, right?, with Solidity and below also with Stylus RAS. Uh, interoperability issues, we've already been talking about that, right? This, how could it be done.
In this case, we ultimately have a user transaction that calls the data, enters the Bitum router, and we can work with A. It's a more globalized approach to blockchain for interoperability, right? You can have your code in Stylus and your other code in Solity, and the idea is to work on it bidirectionally, right? A contract in Solidity can be invoked by functions in a RAS contract, right? Frictionless.
The idea, then, is that it doesn't branch off. No no no no no no. In other words, a bifurcation at a level where there is no connectivity or interoperability to use either A or B. And well, pure and simple, we have, for example, issues of structures, but Arbitrium, Arbitrium in the end already has everything pre- digested, so to speak, for you to work with. In this case, you can work with public structures, right?
Well, in the first case we have volatile RAM, in the second case we have L2 cache persistence. Uh, for example, for numerical values, right? We have standard numbering and it says, "This thing about using Raso Solidity is only for arbitrarium or EVMs in general." Well, right now we're focusing on creating contracts. Well, in this case, the use of one or the other is very ingrained, isn't it?
Ultimately, you can use whatever technology you want, but in this case we're talking about RAS because in certain aspects it's more efficient and it's, let's say, a standard nowadays. Just last week I was telling you that RAS is practically getting into everything in Linux; it's migrating parts of Linux code to be able to work on RAS, right? In other words, migrating from C+ to RAS. And for example, for the builders on the front end, right? It is being built, for example, RC Pack, which is similar to webcando RAS or Boom, which is precisely a faster npm packer, right?
faster than MP. Uh, we're planning to migrate to RAS precisely because it has these benefits of speed, because it has a better, better improvement in terms of memory, and for that reason, right? And in the end, that's the idea, right? Or what use depends a lot on what you want to carry. I don't know if I answered your question there, but you can comment there if you want .
Uh, in Arbitrium we have the 256-bit standard, right? Compatible with EBM. Uh, we have functions, right? Internal functions. Uh, in arbitration we have automatic export for public use.
Uh, and here's a small example that we'll also look at at the code level. And the Stylus SDK does not use macros. Uh, I don't think I mentioned these, they're called macros. There we were looking at the debugging tools that allow us to, if you've worked with decorators, for example, in Java or Python, it's like giving a function an extra capacity, right? It's about giving it more capacity.
In this case, the functions or structures are given the ability to perform certain actions or operations, right?, which expand the pure RAS code and handle more complex reading and writing in blockchain, right? Okay, here we have, for example, a raw source file, which is what we've been looking at, a counter structure with its, let's say, parameters and an implementation of its functions. And here we have the AVI of Solidity internal, which works with an interface with Tycript, right? This is a function, so you can see the difference a little , right?
function eh returns and aha there we have, for example, to increment. It's similar, only the syntax changes, let's say. Hey, your RAS code disguises itself as Soliti thanks to the automatically generated interface. The rest of the ecosystem interacts with your contract. Already.
Well, there are quite a few of these principles here, aren't there? Uh, you have to do a prior validation, right? Stylus check fee for checking with Stylus. Uh, you need to prioritize optimization, right? Maximize optimization.
Well, the weight has to be less. And what about finances, right? Estimate how much gas you will consume. Uh, there are deployment issues, right? With a stylus you can unfold it like this.
I'm deploying them and your private key, right? This is to activate the chain. Uh, we're not going to get into this too much, are we? Because the idea is precisely to see a little bit of RAS, to understand RAS so that you can see this later on, but here is some of the material if you want to move forward. Uh, there's a stylus structure here, isn't there?
It generates a charge, a CRC with lip. RS, right? Unlike what we 've been seeing, here we're going to generate libraries, and here are some examples, right? Okay . And now, uh, those QR codes, uh, no, don't scan them because I forgot to change them there.
Okay, but I'll share the material with you after the session. We're going to look at some code now. It was executed there. And well, let me explain a little, shall I? Well, I don't know how much time I have left.
I think I've used 40 minutes out of the 2 hours, but we'll see how it goes. 40 a little more. I think it's been an hour. Okay, so, let's look at the panic issue, shall we? We're going to panic a little and in this case we're going to divide by zero.
Okay, let's explain, because maybe for the new ones, well, we have our main file, the M RS, where everything we're going to do will be loaded, right? In this case it is a main function that comes by default. By default, it comes just like that. And we are loading our modules. That's why mod of S1, error, handler, S2, the iterators that we are going to see.
And here we are calling the files, right?, our modules and we are going to call demo. The demo function is precisely the public function that exposes each RAS file and is what it will display. Let's work on S1 first. S1.
Here I defined three basic functions to see the panic result and the question mark operator, only here I have put Q. First we are going to divide by zero. What happens if we divide by zero? Well, before dividing by zero, let's do a typical division. B, if B is equal to er, that is, if the one we are going to divide by is zero, then we are going to leave, right?
Panic, hey, you can't divide this contract, it would be invalid, right? Well, it's not a validation, which is precisely what we're going to test here. And if this doesn't happen , then we proceed to divide ent and return a numerical value, since it's 64 bits, which is exactly what's here. If you can see it in RAS, then it's not necessary to use the return command or put the semicolon at the end. Well, they're little things that make things easier, right?
And RAS detects, right? Hey, you're already returning the value. Okay, now we're going to call the panic function, where we're going to divide. In this case, this will give us 25. 100 / 4 because it is 25, it is a valid value.
But what happens when we try to divide 100 by zero? What happens is that when we run this, we get this error here, which is precisely the panic. He's panicking, and it's the 25th, isn't it? Above, we show. Let's go here and enter this panic here and we can keep iterating.
Well, here's a bit of panic code from RAS itself. And if we, well, it doesn't come out here, right? Hey, you're entering this mini-project file here and it's showing up here, right? Division by zero. The state invalidates the contract, which is precisely the message here.
This doesn't come out as the exception, does it? Hey, a generic exception, a panic, huh, you can't divide by zero and it comes out, right? The bread, the pani handler, and all that. That's precisely why we've enabled this. If we comment it out again and run it again , nothing happens because I didn't panic.
Just like when an error occurs in any other programming language, all flow is cut off. And the idea is not to cut it off, not because, well, we're not controlling the error and it stays there, your flow gets paralyzed and that's a real panic. Now we're going to work on recoverable errors. This is when we manage the error, we've already encountered panic. So, how do we manage it?
If it happens, right? In this case, uh, for example, there are two things that will always happen. Either everything went well or there was a mistake. In this case, when it happened, okay, we took a generic, right? It says, "Hey, the operation was successful and contains such a value, but when there was an error, the operation failed and contains such a value."
In this case, we're going to generate three errors, three types of errors with an enum, right? Uh, contract error. One is the insufficient balance where we will use the available amount and the required amount. So that's an invalid address, right? An address that doesn't exist and a zero amount.
Hey, your balance is zero, you can't take any actions. Next, we're going to define a function called this transfer where we'll do the logic, right? We have the balance, we're going to pass the destination as a string reference and an amount as a 64-bit number. And we're going to return, aren't we? We're going to return a result, right?
And this result is exactly what we are seeing here, the result can be OK or error. Result and we're going to control with the contract error enums and in the end, well, this will also be returned. Excuse me. It will be returned, therefore, as a 64- bit value, a generic value that is precisely for these cases. We'll see it in a moment.
Ah, I see. If the amount we are passing is zero, we throw an error. Error, contract error, your amount is zero. And so we returned. If this doesn't happen and the following occurs, if the destination is empty, right?
If we are sending to someone who doesn't exist, we will also return an error, but this error will be that the address you want to send to is invalid. Now, if the amount, or rather, if the balance is less than the amount, right? I mean, damn, I have x amount, but what I have does n't cover what I want to buy or what I want to transfer. What happens is that we're also going to have an error because I don't have enough, and the error will be insufficient balance, and we're going to say, "Hey, you have this much and the amount, well, uh, sure, and the amount you want to transfer is this much so you can see it," and if everything happens correctly, we return an "OK," meaning everything happened correctly, and we return the balance minus the amount because it went through correctly. If we do n't handle these errors and if we just give the OK and one of these cases occurs, we're going to panic because we're not controlling the errors.
That's the detail of controlled errors so as not to panic, because we map what kind of errors we find or what kind of errors can occur in the business, but they are errors that we can foresee and control. Hey, if this happened, um, I'm going to show you this. And that's it . Well, and in the end, your new balance will be the difference between the amount and what we ultimately return. Now we're going to use the transfer function here and we're going to generate cases.
We're going to generate a variable called cases, which will be a reference to an array that will have, let's say, a set of tuples, right? Uh, the tuples will have number values, a string reference, and another 64-bit number. And those values will be the reference for this arrangement here. Here it goes. Let's explain it little by little.
It's a matrix in the end, isn't it? It's a matrix type. And it says, we're going to have 1 2 3 cu tuples. Already. Now we have these certain values.
In this case, we have what I have, right? The amount and what I am going to transfer. So, I have 1000, I'm going to transfer 500. If I do the subtraction, it works, that's why it's okay. And of course, my username is Bob.
I currently have 100, but I want to transfer this 500. Here I'm going to get an " insufficient balance" message because I can't subtract this 100 from, say, 500. And then here we have this 500 and I'm going to transfer 100. But the problem is that the destination I want to transfer to doesn't exist; it's a invalid address. Now we have a zero amount, right?
Hey, I have 500, but the amount I want to transfer is zero. I cannot transfer a zero value, that's why it will enter a zero amount error. And here we'll iterate. We already have the cases here. These are the cases of transactions that are happening there, and we want to show these cases based on the case studies we have.
That's why we're going to iterate with the forum, right? And here we're going to deconstruct for each iteration . The beautiful thing. Look, we are deconstructing the concept of deconstruction. We have a tuple and we are pulling all the values and that's what we're going to use.
But we're not just deconstructing, we're taking that deconstruction as a reference point, right? So that they can understand it. If they get lost, they'll still mention it, right? But we are taking the reference of the tuple of cases but unstructured. And well, here we have the cases that are these cases here.
For each of these cases, this will be worked on here, and through destructuring, these values will come in . So the balance will be this, the destination will be this, and the amount will be this. And now when that happens, we want to make a match. We are using everything we have been seeing in these two sessions. We're going to compare the match, right?
Hey, in this case we're going to call the transaction function that we've been looking at here, where we check for errors and if no errors occur we return OK with the new balance. In this case, when we transfer and pass those values, we are going to generate certain cases. First, in the case that everything happened correctly and we obtain, since everything happened correctly, we will obtain our new balance which is precisely subtracted here. We already have our new balance and that's what we're showing. We print.
Okay. The remaining balance given to your transaction is so much. Okay, it should be here. It's this one right here. Uh, the remaining balance is 500.
Why? Because 1000 men were subtracted. You use the current amount minus the amount you transferred and it returns 500. Now, uh, the next case, that case already happened that way. Now, the next case.
Oh, I think someone has their microphone on. Then we have the case of insufficient balance and we're going to, well in this case, we're going to return an error, right? Well, from this error in the enum case, right? insufficient balance of our error. So we're going to get what's available and what's required, and then we're going to print it.
There was an error, the balance is insufficient, you have so much, you need so much , which is exactly the case here. Now we're going to explain a little bit, because this is where this second case comes in. What's going on? I have 100 and I want to pay with 500. Go in, transfer, and enter this block here because it's not zero or empty.
I have 100 and I want to transfer 500, it's not possible. So here we made a mistake and captured the balance and the amount. So that? for us to work on it. In this case here, we capture the amount and the balance so we can show you how much you have available, but how much you need, and that's what it shows here, right?
You have 100 and you need 500, that is, what you are going to spend. Yes, if you have any doubts, feel free to ask, but this is the process that follows. Already. Then we have the case of invalid address, where if the address is invalid, it will show us, hey, the address is invalid. In this case we are going to transfer and it will enter this case here.
The destination is empty, which is precisely our case three. Hey, destination is empty. Uh, then we have the case of the zero amount, which is the last case, right? Where the error is going to be a match, right? So, let's get down to brass tacks and find out what's going on .
In this case, the amount will be zero. Because? Because if we go here, we see that the amount is zero and when it goes to transfer it enters at zero amount. Since it enters a zero amount, what it does is return this error and when it returns that error it will show me this here. Enter here, enter this case, as it returned zero amount, enter this case and say, "Hey, error, the amount is higher."
Uh, I did it in order here, right? Uh, and that's exactly what it says here, right? The address is invalid and the amount cannot be zero. But in this case, for example, I want to generate more cases, right? For example, let's put, I don't know, this, I have 40, it's a case of mine.
In this case I'm going to put my name, for example, Henry. And here I'm going to pass it on, let's say I'm going to try to spend 100. If I run it and I'm going to check this. Let's see, let's see. No, we're not here.
And here we are. It says here, you have 40, but you need 300 for your transaction, so it's working. Here you can add cases, I don't know, for example, or work on that, right? For example, instead of 300 I put zero. It has to come out here, well, hey, the amount is zero, right?
You cannot make a transaction with a zero value amount. Error, the amount must be greater than zero. And if I put in, for example, this 20, it should work for me because what I'm going to spend is less than what I have, right? In this case, it comes out okay, the balance is 20 because it subtracted 40 from 20. Okay, that's the case.
Then we have the question mark operator which allows us to propagate errors upwards. In this case we have two ways to do it. Well, these are auxiliary functions, right? One to stop the amount and the other to split the block, which is a bit logical, isn't it? We're going to partition one number into a 32-bit number and the other into a 64-bit number, right?
It's not that complicated. It says, we're going to take one 64-bit result and one 32-bit result. So what are we going to do? We're going to generate two functions, one verbose with lots of verbs and the other with the question mark operator to see the difference, how clean it is, how much simpler. Now, this here will be similar in both, we're going to work on both, right?
To process a transaction, we're going to receive an amount, a block, and in the end we're going to return a stream, and well, a result of a stream, and or well, a number standing still, and below, well, it 's the same thing, right? It is similar to block amount and at the end we return string and this is the partial number. What will differ is this block here. Here we see a bit of redundancy. Look, we have to stop the amount and we're going to stop the block, but for each one of them we generate an OK and an error.
They've seen callbacks there, this is like a callback. You generate a callback, right? Hey, you have this thing, this happens, you do this, the other thing happens, you do the other thing. You have another case, this happens, you do this, the other thing happens, you do the other thing. It is similar.
It's a true callback for cases of errors or failures, but it's verbose, it's very redundant, isn't it? In this case, if it happens, well, okay, we return the value; if an error occurs, well, we return the error message, and the same below is redundant; and if neither of those happens, well, in the end we show the results, right? We show the amount and the block. Ah, I see. But he's very verbose.
Now let's see how it's done with the question mark. We have the amount and the block. We make the call directly to the function. We're not matching because that's not going to be the case. It's going to be downstairs.
And here we pass the amount and add the following question mark. If it fails, return error here. If it fails here, return the error here. The same below. If it fails here, return the error here.
In other words, this could have been executed correctly, but if it failed here, it will return to the error here. Already. And if none of those happen, everything was OK, because here, in this case, we return the amount and the block. Now, let's see, sorry. Let's see, a There it is.
Already. Now we too are going to work by operating with the question mark. This is an auxiliary function where we're going to work on processing transactions, which is exactly what we've been working on, and we're going to generate cases so you can see, right? Examples, we have these cases, we have three cases, right? Which is pretty much the same thing, isn't it?
It is an array of tuples where we have 1500 ABC, 1500 eh value 1, value 2, x y z. Now we're going to iterate, we're going to do a for loop, we're going to destructure and we're going to get this based on the cases. Now this is where we're going to make the match and this is where we're going to work on the OK and the error. Based on the transaction processing, this value from here will go here. That will be passed to the function to process transaction, in this case 1500 and this block here.
And based on that, we're going to work here. I do n't know if I made myself clear. We're going to split this at the end, I mean, right now they're streaming and we're going to split it so they're numbers, right? In this case, well, at first glance, they're just numbers, so everything's going to be okay. And here it is, isn't it?
Okay, so 100 and a value of that, but the second one, the first one is text and the third one, the second one is text. Errors eventually occur because it cannot be parsed, but let's see where the error occurs. In this case we have ABC, right? If everything went well, it will show me, okay, that happened, but if there was an error, it will tell me the partial error and show me what went wrong. In this case, the first thing that failed was the amount.
Uh-huh . And the second one he missed was in the block. So when we perform the transaction and verify based on the match, that is, we match, right? Hey, what happened? It works, right?
Invalid partitioning error. Well, the digit hasn't been found correctly because we're trying to partition a string into a number, and it can't be done . And the same thing happens down below , right? Now, it doesn't show up here . Oh no, yes, it does show it.
For example, this is the verbose one. Ta ta ta. with the Ya. Let's see. And that's it.
And in this way it 's cleaner, easier and more legible to understand, right? Because it's simpler, isn't it? You don't generate as much redundancy. In web development, there is a concept called the Calbac hell, that is, the infinite calls. When we refer to the bald man's hell, which is entering a loop, we have a condition that internally occurs either okay or false, right?
This and within we lose traceability because we enter into iterations, iterations, iterations and we enter into the hell of the bald man that they call it, it is because in the end you get lost in so many iterations. That's why the ideal thing is to abstract, right? In this case, we are abstracting in this way, and in the end, we are doing a separate match at runtime where we are working with the OK and/or the error, and in this way, we generalize and work more efficiently, and it is more readable, shorter, and easier to read. So far we've seen how there are uncontrolled errors that cause panic and controlled errors that we can handle with OK or error. And we can handle controlled errors with enums to see the error cases.
Here we can also see the iterators where we're going to see some details, right? Uh, vectors are dynamic lists, right? That they can grow in the HEP. Be careful because in the end, the HEP can accumulate, and accumulating is a mountain, isn't it? It's the mound and we can keep adding things to it.
Uh, then we have anonymous functions, right?, which are like lambdas or anonymous functions in uh in JavaScript. And then we have the iterators, right?, to transform, uh, on collections. In Java, for example, for reactive programming, or rather, reactive programming, it's a type of programming where within the collections you start performing actions, right?
You have a list, you generate it as a collection and inside, I don't know, you multiply all the values by two and you have a new array with all the values by two. Well, that's exactly it, it's iteration and iterators, uh, you work with collections, it's like having a similarity, right? So you know, listen, this can happen . And here we have a few things that we're going to see that are similar to Java, right? Filter, map, collect, zoom, that is, these are things that in programming languages don't vary much.
And well, the compiler generates code that is as efficient as a manual loop. A detail I left there. That's enough. Here we have three things: a vector demo, an anonymous functions demo, and an iterators demo. Let's look at the vectors.
This way you can generate a vector. As we're going to add things to it, we're going to modify it, we're going to make it a mutable vector. That's why it's going to be a mutable variable called transaction, its type will be vector, and the values it will obtain will be 64-bit numbers, and we're going to initialize it as a new vector, right? Vector two points and new. After that, we'll push the transactions, well, the transaction that is a vector, we'll keep adding them.
We placed push point 500 push 12 push 75 and so we will keep adding. In the end, this generates a vector with 1, 2, 3, four values, so we can work with it. This was possible because it is a mutable value and we can modify it. Oh, and there are a few things here, aren't there? For example, let's print the transactions.
In this case, let's see, the transaction, this is precisely to show the transaction, the array of transactions for debugging, right? Always remember that. We are going through the list of transactions. Next, we're going to add, and here it is precisely from the programming more oriented to the function part, right? Functions.
For example, we have the transaction, our list of transactions. We're going to iterate with this method within this vector. We're going to iterate the vector and add it one by one. And then we're going to return a 64-bit value. And that's what it will ultimately show.
If we go here, we have the transactions. This is what prints all the transactions we have pushed. 500, 1200, 75, 3000. Ah, I think they told me last week that it wasn't visible. Listen, I think they should have told me.
Let's see. Let's see, let's see, let's see. I mean, I think you can see it there. Look, just in case, I'm already nearsighted, but my screen is big and I don't notice it much, but there maybe they have a smaller screen and it gets complicated. Following this, we have the next function that has added everything up, which is precisely the total.
And with this simple function we have added, no, we haven't had the need to create a specific function to keep iterating, right?, with a for loop, we keep adding. In other words, we already have a method that helps us within vectors, which is the iter method . And after that, we can give it one more capacity, that is, pass it another function called add to return a 64-bit numeric value . Then we have the issue of quantity, right?
Finally, the transactions, we're going to count transactions here, it also has a method called this count this or well, get the number of characters. And here's a tip. For example, I can give it control and it takes me to the back row in this case, right? For example, bec of the vector, all the functions it can have, right? In this case, everything is a vector.
This is what they do at the code level. If you want to know, hey, how does he do it? It passes to itself. This, and well, here's a bit of code, isn't there? And that's where they can see, so they can understand what it ultimately does internally.
Yes, but it's already here for you to use. The other thing, for example, to obtain the highest value, we have our transaction vector. Let's iterate, let's get the maximum, and in this case, well, if it's a value, then this is the point to stop, right? If it's a zero value, well, let's say a negative value, then we get zero. Uh, the same goes for the minimum, precisely to control it.
For example, we have the quantity of the size, we have four values, 1 2 3 4. Then we have the maximum value which is 3,000. There you can see that it is detecting correctly. And the minimum is 75. Okay?
Now, how can you initialize a vector? There is a way to do this using a macro called bec with the exclamation mark, and inside it you pass the values. In this case, I'm passing, as I've already given you the tip, the first value is passed the type, in this case it 's a 32-bit number, and it will automatically say, "Ah, it's a vector of all the 32- bit values." But this is a macro, let's say, it's a function that's already designed so that you can generate your vector. In this case, you initialize a vector with these values here, 1 2 3 cu 5 values and that and at the end we print, right?
, the confirmations which at the end are those values and are printed in this way. But this is another way, isn't it? You no longer generate manual pushes; this process is a bit lengthy, and you simply do it much faster this way. Then we have the anonymous east functions . Right here we are already using the macro called bec to generate a vector, right?
, of these transactions. And now we're going to generate some anonymous functions, right?, that capture variables from the environment. This is the syntax. We're going to pass the parameters.
between two of these, let's call them sticks. And then we're going to generate an expression where we'll use the parameters. In this case we are generating an immutable variable called 64- bit threshold because we are saying it is a 64-bit value of 500. And then we're going to generate an anonymous function, right? We are calling fn function, function name.
We pass parameters, we perform an action. In this case, it already detects it here, right? It is a function that will obtain a 64- bit value and return a boolean. From what point? From right here.
What does it do? This is what it does. We are going to pass the amount as a parameter, and the amount will be 64 bits. That's why it says 64 bits here. And we're going to take action.
The action is eh the amount is greater than or equal to the threshold. This is what will be returned and since this is a logical operation, it will return a boolean. If the amount is greater than or equal to the threshold, it will return true. If the amount is less than the threshold, it will return false. Because, well, it's logical, isn't it?
In other words, that case is not being fulfilled. And that's why it tells us, "No, hey, it's returning false. Now, to double it here, well, before we see this, before we see this, we're going to go here, right? We're going to have the 64-bit amount as a parameter, and we're going to multiply that amount by two. We're going to get double.
That's why it tells us here, right? Hey, it 's a function that's going to return a 64-bit value because we're returning the amount multiplied by two. We're not generating functions; we're simply generating logic in a line of code. It's precisely to make it easier because you can do this, let's say, with a function, but it would be more verbose, I mean, it would generate more logic than you could do simply, right? That's why there 's the issue of lambda in Python, for example, because you can do your function in a single line, or for example in Anonymous functions in JavaScript or TypeScript, where you can also do it in a single line and you don't have to fill your workspace with functions, and this way you can work, you can become more advanced, right?
And here are a few functions that will be useful to you. ITER, and we've been seeing it in all these sessions, is for iterating, which is like generating your for loop, but it's a more optimized for these kinds of tasks, right? Regarding references, right? For example, the dot with `for` to copy, right? Uh, you convert the reference into a value that you can use because you're copying, you're making an explicit copy.
`filter`, which will be useful precisely for filtering, right? That is, you keep only what happens under a certain condition, right? ` map`, just like in Java, what it allows you to do is take your array, perform an action, transform it, and return it as another array, and `collect`, right? Where you can materialize the result in a vector. In the end, we'll...
to obtain in a vector. And here's an example. In this case, we're going to generate a variable called "large duplicates," which will be a 64-bit vector. From the transactions we've generated here, we're going to do this: we're going to iterate, we're going to copy, we're going to make a copy of these transactions so we do n't have to touch the actual transactions, but rather our copy. We're going to filter this copy and use what we just did, which are anonymous functions.
We're going to pass a reference as a parameter, right?, of a 64-bit numeric value . And then we're going to say, right?, let's execute a function called "is large." And "is large" will receive m.
If we control-click on M, we'll go to our anonymous function where what we passed is a 64-bit number, that's why we see 64 here. We're just going to use the reference, as we know, to optimize, that's why it 's recognizing it. And we're simply calling our function "is large." Large. If we click here on my cursor, we can see that it's a function, right?
Well, it's a variable called `large`, which is ultimately a function that receives a 64-bit numeric value and returns a Boolean, which is what we've been talking about. Now, ` M` is, let's say, for each iteration, this value here, right? It's going to get the value of each iteration. In this case, it's going to get 500 first, and it's going to be compared with the threshold. Ah, let's see, here we're moving to the amount, and here this is the threshold.
Here's the threshold. It's going to be compared with this, right? That's why the threshold is being called here. Now, in the first iteration, we're going to get 500. Let's say 500 is greater than 500, or greater than or equal to 500, it's going to be true, so it's going to show true.
Okay, ` original` will show all the transactions. `large` will show Right now, here's what we're going to work on. If this is true, it will filter for those that are true. Here, it will be a match; it will get all the true values and, based solely on that, generate a new vector. That's why the map function will now look for duplicates.
In other words, from our array that we had, it will call the duplicates value, right? Or well, it won't look for duplicates, sorry, it will duplicate our array that meets the condition of being greater than or equal to the threshold to duplicate those values, right? That is, it will duplicate this one here, this one here, this one here, and this one here. It won't take 50, it won't take 75; it won't consider those because they don't meet the filter of being greater than the threshold. It will map—it won't map only—the values that meet the condition, and it will duplicate them and generate a new vector, which is exactly this.
Here, it duplicated 500, it duplicated 10000, it duplicated 3000 and doubled 800. I don't consider 50 because it doesn't meet the condition, I don't consider 75 because it also doesn't meet the condition. Then we print the transactions, or oh no, sorry, here. Add and count, right? Starting from the iterators, the total, that is, we're going to add up, right?
, the total. We're going to get our original transactions. We're going to iterate these transactions. We're going to generate a copy. We're going to filter this copy with this condition.
We're going to take the reference of M, which is going to be a 64-bit number, right? As a parameter. This is an anonymous function. It's already an anonymous function. We're going to get the reference of M.
And here it's going to return true or false. Okay. What happens? We're going to say, "Hey, the value of m for each iteration is greater than 500. If it's greater than 500, it meets this filter, right?"
If m, that is, from the list of iterators of these data sets, each of them will iterate. If any of these is greater than 500, it will copy it into a new vector and add it, it will add this value. So, what are the values greater than 500? Greater than or equal to, this one here, 10000, 3000 and 800. Only those values will be added because in the end we're going to add them up, but simply put, and when they meet this condition, they are filtered by that condition, and that's why the copy is for copying and working on that and not touching the real transactions.
We cannot touch the original transactions, as it is an immutable value, that's why we copy them. Then we have the large quantities. Here we're going to filter out the large quantities that are greater than 500. The flow is similar. transactions, we iterate, we filter by a condition.
In this case we are going to make a, let's call it a reference to the DM reference. And in this case we're going to look for this condition which is the same, right? Greater than or equal to 500. And we're going to count the same ones that are greater than 500, which are the large values, uh, 1000, 1000, 2,400, 6,000, uh, 1600, and in the end we're going to print, right? The total number of big ones, right?
This is precisely where there should be a touch that isn't there. There it is already. The total is 500. Hold on. Already.
Here is the total. So, the sum of the large operations is going to be 1500. That is, the sum of these, precisely these, greater than 500. If we can see 1000 or well, 13. Ah, ta ta ta big.
Clear. Here it goes. It's going to add up now. 500. It's coming out here at 5,500.
Ah, sorry. That's because I'm adding the duplicate. It's adding up these values here. 500, 100,000, and 800. And that gives 5500.
Now, how many large transactions are there? He has counted them, therefore, under this criterion. He's going to count, then, 1, 2, 3 and 1. That's why he says there are four transactions. Now then we have the f which is the general accumulator.
And here we are, already leveling up a bit. We will have a variable called product that will return a 64-bit numeric value. We're going to fly a little bit there. We already have the one that will be initialized with a vector of these values 1, 2, 3 and 4 of 64 bits. It's going to iterate these values and it's going to be an f, right?
Uh, in this case it's going to initialize to zero, right? We are going to pass an anonymous function where we will have some input parameters which will be the ACC and the reference of X and we are going to multiply them. Already. Uh, what's the point of doing this in the end? It's the multiplication of everything, right?
In other words, the accumulated amount is multiplied by the previous amount. This is like factorial, isn't it? This is, let's say, the equivalent of the factorial. We're... we just did the factorial.
It will iterate 1 2 3 4 and will be multiplied by the accumulated total. We have our accumulated amount, it will start at one, obviously, and it will be multiplied by the next number. That's why we get the reference from the following. And with this it will multiply and return at the end the final product which will be 24. But well, it's a little help, right?
, that will help you to iterate, right? It is a general accumulator; it will accumulate in this case under a condition which is a multiplication. Now let's look at iterators, shall we ? About structures. We have a transaction.
Here we have, for example, functions, right? Well, we already know it's a bit of what we 've seen, right? Who is the amount for and if it's valid, and it's going to be a bull, right? Is it valid? True.
If not, false. Now we have some transaction vectors, right? We're going to call the transactions and initialize this. It's going to be Alice into to define what is a string for BOB, the amount, and it's going to be a true value. The same applies to any other transaction, right?
In other words, these are cases, these are examples of transactions to be able to work easily. And in the end we're going to use, uh, a few things that we'll show you right now . For example, let's filter out the valid ones, right? Here we have the valid ones, they will be based on the exact parameter of whether they are valid. The valid ones will be a reference vector for the transactions.
We already know that we cannot touch the transactions themselves, we will simply touch the references and that's what we will work on. We're going to take our transactions, iterate through those transactions, filter by a condition, and pass an anonymous function. We're going to go through each iteration, each of these transactions, and we're going to verify if it's valid. In this case we will only take the valid ones. The valid ones are true, which are two, and we are going to store them in a collection.
Now the total will be a 64-bit integer of the valid ones. Let's iterate, let's generate a new value with MAP. We're going to use an anonymous function to capture the amounts of each valid transaction, because we 've already validated them and now have a new vector with only the valid transactions. And in this new vector we are going to obtain the amount of each of these valid transactions and we are going to add them up. And that's what we're going to be printing, right?
One, the size of the transactions. 1 2 3 4. Next, we go to the size of valid transactions, which are two, which is precisely what they say is valid true. And then the sum of these valid transactions, which is 500 + 1500, is therefore 2000. Or that's exactly what we have here.
Now, here we have another logic which is the issue of we are going to iterate over the transactions, the references of the valid transactions and each iteration we are going to take one of the transactions, which are only two transactions because only two are valid. True. And we're going to print out which transactions are valid, from whom, to whom, and the amount, which is precisely these two valid transactions from Alice Abob, from Alice Abob because it is valid, and from Carlos Alice, from Carlos Alice because it is also valid. Now, that's this section here. And now we're going to look at the topic of elini, and I mean, some or all of it is, let's say, another iterator that might be useful to you.
Now we are going to create a variable called "hay hay grande", that is, there is a large value, right? It's going to be bulean, it's going to be true false. And what we're going to do here is, under the transactions, our transaction vector, we're going to iterate, that is, it's a for loop, right? You can do your for manually or you can place it like this, right? Let's make it simpler and check if there is one that meets this condition.
First, let's go; obviously, we have to work with something. In this case, we will obtain the transaction on each iteration . That's why we're going to have the transaction reference and we're going to do this action. We will validate that the transaction amount is greater than 1000. Only if the transaction amount is greater than 1000 will we return.
Well, this is ultimately a Buian operation, that is, if it is greater than 1000, if any of them is greater than 1000, it will return true. And if this returns true, then it will say, "Hey, is there a big one?" Yes, true, Puliana, because we validate that one of the amounts of all the transactions is greater than 1000. If we look at, for example, the transactions, uh, 500, 200, 1500, we find one that is greater than 1000, that's why it will return true. For example, if we're going to try removing "this is less than 1000", it will return false.
For example, here it says true. For example, if we put 500 here instead and run it again, uh, let's see, is there any transaction greater than 1000? It says false, no, it does not exist, it did not find, it did not find under that criterion. That's why it's like that, from the ni. Now, all transactions are valid.
We generate another variable called all transactions are valid, which will be bulean, it will fulfill a condition. We're going to take all the transactions, we're going to iterate, that is, we're going to generate a loop and we're going to compare them all, that is, they all have to meet this condition. We will pass the transaction as a parameter , the transaction reference, and all of them must meet the condition of true and be valid. In other words, the first one is true, we're already checked, the second one is true, we're checked, the third one is false, it failed there and in the end it will return false because it is false. In other words, not all transactions are valid, which is our case.
We only have two valid ones and two invalid ones. That's why it returns false. Uh-huh . It's like a wild one. But here you no longer control it, I mean, for each iteration, it 's simply easier, it's like reading English, right?
Transaction, I'm going to iterate, I'm going to compare, they all have to meet this condition and obviously I'm passing this transaction in each iteration. Now let's imagine that we put true here. True, true. Since they are all true, it should give me this true, since all transactions are valid. And here it is .
All transactions are valid. Of course, because they're all true. If any of them are false, well, it's going to return to me, because, well, not all transactions are valid. That's why the issue with iterators is whether... Ah, let's see, where is it?
Where is? Where is? Okay, I'm completely lost here with "Ya, ya acá está falso" because a 10 is incorrect. I've been teaching you, let's say, the basics, how to create your functions to work on them; it's like programming in any other language, but this is a slightly more advanced level where you can do the same thing but cleaner and shorter using anonymous functions. Obviously, they are not for all cases.
There are cases where you do need to work with a specialized function to reuse them. In this case, well, they are not being reused, they are only for one condition. But if you're going to reuse them in several sections, it's better to create your own function and simply call them. In this case I 'm passing them directly, but up here you've seen that I called an anonymous function of this type here , for example, as a function. This is another way of how this works, isn't it?
This is still a function, but if I control click it, it becomes a variable; it's a function, but anonymous, right? Or the other option is that you can easily copy this from here and instead of passing this from here, you put it like this. Of course, here you also have to cross the threshold, you have to do more things than what would be too much, right? On the other hand, things are made easier for you here. We're going to get things sorted a bit faster so we can work, right?
Hey, counter contract in Raspuro. Here I will show two examples. One works on a contract in pure RAS and the other with Stylus. For example, a demo to get you warmed up for the following sessions. Already.
Okay, let's get this done quickly because my laptop battery is running out. Yes, this is a Hello War of a smart contract that has been implemented with everything learned in the sessions, right? This is the demo, so to speak, of the day. Uh, we already know, structure with its implementation, vectors and the options for managing okay or error. Uh, results or well, sorry, the option for generics, the result for OK.
Uh, uh, well, here it's one thing, right? To prevent overflow, right? To check the checked at and the mull that we're about to see, the history, right? These are things that you'll see later on, with the topic of Solidity or this one with Stilus. And then we have access control; only the owner can access it.
These are the first sessions they've had with me, but later on they'll see more developed things, right? Uh, this contract is equivalent to the official Arbitrion Stylus repo, which you can find here and which I'll share with you later, where you can go over there . I don't know if they've already shared this, but here you have, for example, the official Styl Hello War repo so you can upload it there. After the session, I'll send it to you so the guys can share it, but we'll keep an eye on it, right? For example, let's see, we have operations here, you can already see that it's much more verbose.
It's approximately 200 lines because we're doing everything manually. They already have the repo, they can start looking at it, but yes, kind of like, to start looking at it so that we don't waste too much time. Uh, we have our contract which is going to be a mutable variable, right? The contract will be for our owner. Let's print the basic operations, shall we?
For example, uh, increase or add number or the MUL number, right? We're going to drive. This is a function we are working on where we will pass the result as a parameter. This is an auxiliary function to print the result of each operation where we are going to obtain a result, right? Whether we return a 64-bit value or a contract error, we then match what happened.
If everything happened, okay? So we return the 64-bit value and if there was an error, we display the error, right? And here we deal with the issue of error, right? In this case, we have an owner-only error, right? Operation restricted by the owner.
Let's see, I don't know if I can. There it is. Um, or a mistake, well, this one's more generic, right? This is an error that is not controlled, and we simply show the error that we are going to get, so it is a controlled error, right? In other words, the error will appear , it won't disrupt the flow, but we're not handling it with an enum.
Already. So here we have our types of errors, right? This is the upper overflow, right? This is, let's say, this is already being handled, only here we have to work on it manually because, let's say, we are doing it manually. We have an overflow here, don't we?
Overflow, zoom, or multiplication. We have a lower overflow, right? It's the opposite, isn't it? It's when we do a subtraction and well, the sole owner, which is exactly what we just saw. We have a history of transactions here, right?
It's an enum, isn't it? It is also an operation module where we can increment, add, multiply, change, or subtract. I think they're writing something there, okay? And then we have a transaction log, the previous value, the new value, right?, which are ultimately a structure, the contract, right?
, the value, the owner, and the history, which will be a transaction log vector and the implementation of the contract, right? To create a new operation, we take the reference from the owner stream, and we'll return to ourselves. In this case we're going to print, right?, that it has been deployed by the owner. This case is a contract where we are going to pass the contract values which are value, owner, history.
The value will start with zero. The owner will start with the owner value that we will pass when creating the new contract and the history will be a vector of zero, a new vector. We are going to generate auxiliary functions, they are get and ceder. In this case it functions as a view for Solidity. This one, to show here, is an increase of one, right?
Uh, to prevent integer overflow, right? This is to prevent the issue of loss of funds. These are already business-oriented functions that you can start looking at. In this case, it changes itself in a mutable way to modify itself. The previous one then passes the previous value, compares it, and performs a checkout.
So, if everything was correct, there was an error, then here the error is checked, if not, then it goes on to register. And well, there's a bit more logic here. Here's a function to add, to multiply the value by n, uh, to assign the direct value. The final point is logic that we've already been seeing. In the end, the general flow will be fulfilled, so to speak .
They know that "pup" is meant to be public, so that it can be used outside of the scope. uh FN, well, it's a function, the erase, that is, the mutable reference of itself, because it's going to modify itself. The `cer` command will return either a result, a 64-bit numeric value, or a controlled error. And here it goes, well it's going to be logical, right?, the previous value will be inserted.
That's enough. Yeah, and that's it. Okay, here's a function for subtracting, a function for averaging the history. Right here, look, we're on the last thing we saw, which is the topic of anonymous functions, uh, the SOM has to be something, right? That's what we 've been looking at, viewing history, which is for printing the history, uh, registration issues.
I think they're already writing , uh, and it's precisely our contract done manually and here in the demo, well what we're going to be doing is increment, is adding a number, multiplying by three, is this, let's say, controlling access, right? For example, a hacker, right? Uh, or let Alice do the action. In this case, we are printing the current value, we are subtracting the average, and for example, these are all the actions that have been done, and here it is, for example, we can see, right? Okay, let's see, we can go through it part by part before we run out of time.
Let's see, let's see. Basic operations. Ah. And here it is, uh, there. And we're going to print these values that will be handled, right?
Increment one, increment two, then it will increase by 2 + 8, so 10, then it will be multiplied by 3, that's why it's worth 30, which are logical functions, right? Functions related to logic. Then we have the errors, the controlled errors, right? For example, here there is an error only the owner because the hacker is trying to, let's say, generate a new transaction and when he does, Alice, who is the owner, it works okay. Here we show the history of all the increases that have been made.
Ah, here, for example, we do a reset or an average, right? To a value of zero, right? We're doing a reset here, right? From the contract, we reset everything because the CER is the owner and we do a to avoid generating negative values and that's what we print. Then the average, right?
Well, the average is what we use the average function which calculates the average using an anonymous function. Here it is, look, right? Here it will be added up and then divided by the size of the list. Here's a detail: you've probably seen in other languages when you use `has this` followed by a type, it means, "Hey, while I'm showing you this, I want to specify that this is a 64-bit numeric value, because this could easily generate a floating-point number, and we avoid working with floating-point numbers. It's dangerous."
In other words, it's possible now, but for issues like this, where you have to be very meticulous, we avoid it. That's why we say, "Hey, it's an assertion, right?" In other words, we are, let's say, specifying that it has to be that value or, well, of that type. And now we're a match, right? If the average of the history is something with P, the average is so much.
Now, if the average is no, that is, we have no transactions, it will say, "Hey, you don't have a history yet." In this case we do have a history, so we get 23. Now the last one to finish. This is already with Arbitrium and it's what you'll be seeing later on , that's why it 's commented out, but this is just to get you warmed up so you can see how here you can already see that there's less code. There are 128 compared to the 200 that were on the other side because it was more manual, almost 200.
And here, of course, I have several printouts that can easily be removed, but in this case, well, here there's a bit of the part already giving them a pass so they can go and see the other sections and free them up a bit from what is ras, right? In this case, we have worked with Raspuro and the next step is to work with Stylos, with the SDK. Hey, but here's a demo, right? It's a comparison of raspuro with est, which is exactly what I showed you in the PPT, right? Uh, the structures, right?
In RAM, right? In comparison with these types of decorators that work for persistence in blockchain. For example, we work in RAS with 64-bit, more primitive types, but STUS works with 256- bit storage, right? Uh, visibility, right? We handle it as public, this public function, but they use this prop, right?
, of public to generate for Solidity automatically. Oh no , my combo is dying now. And well, here's a bit of the deployment flow, right? In other words, your coding on RAS is loaded into the bill in a binary file, then deployed with Stylus, and the contract then begins to live on the blockchain. Okay, and here are some steps for you to install Stylus, to add the necessary dependencies, to get your first Stylus Hello War, to load it, to check and verify that it's valid, and to deploy it, which is exactly what we were looking at.
And well, here's a bit of code if you want to start looking. Ah, likewise, for example, here's the issue of the guy, right?, who manages Stylus, uh, the storage, which are these Stylus props. And well, here's an example of a contract, of a contract implementation that consists of simpler functions, right? In other words, the set number of what we had done, several lines of code, is done this way.
Multiplying numbers is done this way. It's literally three lines, adding a number, incrementing, it's simpler. Here is the contract and in this way the functions can be generated. And so that you're not left hanging, I'm going to show you a Web 3 system that we made with some guys, so you can see the power of Ras. Yes, except we did this with Solana, but this is a Sentinel platform for a, what's it called?
Factory, that is, it buys debt and finances it for, let's say, people who don't have the money instantly to make payments to the State, and all of this is like a POC. I don't know if I mentioned it here, but this is precisely where the environments are, right? Development, the CU Test part, the main that already works in the production part and the local. This is connected to a wallet called Phantom, for example. And here we have two points under the sun of Solana.
And this has been worked out. Here, things are done differently . And this is worked on with... I do n't know if I have it here. Oh, darn, I don't have it.
With a charge, which is another way of working on it. Damn , I owe you guys that. So, or I think I can. Ah, I had it here last session. No, I do n't have it charged, but okay.
Uh, it's not a POC. Uh, Sentinel was a POC, it's working on Depnet. It's the kind of thing you'd integrate into a banknote. It's more of an example to show how it can be done, but the only thing missing would be to propagate it to Testnet and Mynet, but it was a proof of concept for viability. It's done at the expense of the client.
Hey, if you're interested in this material, I'll share the repo with you. I would share it from my laptop, which I do have, but the problem is that it's already at 4% and it's about to shut down, meaning my face is going to disappear, but that's it. This, this is precisely the one from Stylus so you can try your first Hello War. And that's it. Okay, there are several guys who I think haven't logged on, or well, haven't logged on with me.
Nativnar opens a touch or well, if you want to look me up on LinkedIn I'm this person and you can find me there to ask me about things, right? In other words, if they have any doubts, they can look for me there. Uh, that would be from my side. I don't know if they had any questions or or or I don't know. Well, thank you very much for your attention, and feel free to write to me if you need anything.
Great, Henry. Hey, can you hear me, by the way? Yes, yes, yes. Ah, I see. Brilliant.
Well, thanks for the session. Actually, the overall overview of the RAS landscape is immense, and managing to convey it in two talks is pretty great. Well, anyway, as we mentioned at the beginning, this is just the initial part to do more advanced things in the future, right? Uh, and we're waiting to see how the ecosystem reacts to do more complete things, right? Uh, maybe 8 or 10 sessions in the future, right?
Yeah, and great, great. This great overview will be useful for the entire project, not only for the next three weeks , but also for the hacat, right? Uh, likewise, um, welcome, guys, so you can write to the speaker. Anyway, you can leave your comments on Discord, in the forum section or the general section, and we'll be sharing all this content there so you can have it handy. We already have this link for anyone who has come through here.
Either we upload it to the platform or we upload it here too; I found some doubts about the platform. Remember that the content is uploaded in modules so that you can follow along, right? So, well, thank you Henry, and well, thank you all. Here is the attendance list and you can register now. Thank you all for your attention.
Automatic transcript — names and jargon may be misspelled.