Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the communication model of EOSIO block chain?

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "what is the communication model of EOSIO blockchain", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the communication model of EOSIO blockchain" article.

EOS Smart contract

Each EOS smart contract has a set of operations and types. Action represents a single operation. You can think of it as a function in JavaScript or a method in C #. Type defines the required content and structure to be used in the contract. Most of the time we use them for our watches.

Contracts in EOSIO can communicate with each other. It is implemented through a message-based communication architecture.

The EOS communication model is the way they communicate. There are two types of communication models: Inline Communication Model (inline communication model) and Deferred Communication Model (delay communication model).

Inline operation (inline communication model)

Inline operations are part of the inline communication model. If you know them, you can understand inline communication.

Let's take a look at the following picture:

The user performs the action from Smart contract A (Action # 1). When an operation starts to be executed, it triggers two other actions: operation Action # 1.1from smart contract B and operation Action # 1.2from smart contract C. Everything is done in the current transaction.

Actions that are performed in the current transaction and related to its completion are called inline action, or inline operations.

It is important to remember that inline operations are performed as part of the calling operation. Therefore, they have the same scope and permissions as the original transaction. This is the guarantee that they will be carried out. If one of the operations fails, the entire transaction will fail.

So, you should already know what inline communication means.

A request to perform an action as part of a calling operation is an example of inline communication, that is, inline communication.

Delay operation (delay communication mode)

The second type is the delayed communication model. It is interesting to represent the delay operations of the model because they are not executed in the same transaction. Let's take a look at the following picture:

We have the same transaction workflow. The only difference here is that the second operation performed from smart contract C is not inline but delay. The deferred operation is scheduled to run in the future.

According to the judgment of the producer, the delayed operation is best scheduled to run at a later time. There is no guarantee that the deferred operation will be performed.

Even if they are not part of the same transaction, they have permission to send their contracts.

So basically, delayed communication is conceptually in the form of operational notifications sent to peer-to-peer transactions.

Transaction and operation

Before continuing with the demonstration, let's examine some interesting things.

In EOSIO, there are differences between transactions and operations. An operation represents a single operation, while a transaction is a collection of one or more operations.

A deal can contain N actions. However, each transaction must be executed within 30ms or less. If the transaction contains multiple actions, and the sum of these actions is greater than 30 milliseconds, the entire transaction will fail.

Robot factory

We're going to be a robot. You can find projects with all the smart contracts and code in our GitHub.

As a robot company that creates the future, we want everything to be perfect. When you create a new robot, you should send a sale message and print it on the terminal. To implement these three operations, we will use inline operations.

Look at the code snippet below.

Void RobotFactory::create (account_name account, robot newRobot) {robotIndex robots (_ self, _ self); auto iterator = robots.find (newRobot.series_number); eosio_assert (iterator = = robots.end (), "Robot with this series number already exists"); robots.emplace (account, [&] (auto& robot) {robot.series_number = newRobot.series_number; robot.model = newRobot.model Robot.operating_system = newRobot.operating_system; robot.profession = newRobot.profession; robot.owner = name {account} .to _ string (); robot.manufactured = now ();}); / / Execute INLINE ACTION from another contract / / action ({permission_level}, {contract_deployer}, {contract_action}, {data_to_pass}). Send () Action (permission_level (account, N (active)), N (market), N (forsale), make_tuple (account, newRobot.series_number, newRobot.model, newRobot.manufactured). Send (); / / Execute INLINE ACTION from another contract / / action ({permission_level}, {contract_deployer}, {contract_action}, {data_to_pass}). Send () Action (permission_level (account, N (active)), N (messenger), N (printmessage), make_tuple (newRobot.model)). Send ();}

First, we start to create a new robot. When the operation is complete, it will have its first inline operation. We asked to send the robot a sale message, so we asked the RobotMarketplace intelligent contract for forsale.

Please note that when we ask Smart contract A to perform operations from Smart contract B, we should first add the appropriate permissions. We'll cover it in the next section, and for now, be sure to follow the guidelines in README.md.

After the first inline operation is completed, the second inline operation is completed. This time we asked for printmessage from the Messenger intelligence contract. Appropriate permissions should also be added.

In both cases, when we perform the create operation through the terminal, we have been notified that the operation has completed (or failed).

Cleos push action weyland create'{"account": "weyland", "newRobot": {"series_number": 14441992, "model": "A330", "operating_system": "DX42", "profession": "engineer", "owner": "", "manufactured": 0}}'- p weylandexecuted transaction: 9874a8a5f516ca540c44cafd8b9b371c856fe7958be1fc6268641cc7ab67fdaf 136 bytes 6000 us# weyland

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report