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

How to analyze Command Registration and Communication Mechanism through EOS Code

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

In this issue, the editor will bring you about how to register commands and analyze the communication mechanism through EOS code. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.

The client is cleos and the server is nodeos. It is a very important mechanism to control and manage the entire EOS chain through the cleos command line.

The communication between the client and the server adopts the RESTful software architecture style. Each resource on the server corresponds to a unique URL address. The client encapsulates the URL address as a http request to send to the server, requests the corresponding resources or performs the corresponding operations.

Client send message flow

Take the money transfer as an example to illustrate the EOS message processing process. The transfer command is initiated by the cleos client. In the main function, the transfer command is parsed, and the information such as the transaction sender, the transaction receiver and the number of token is encapsulated into a mutable_variant_object object through the create_transfer function, and then the send_action function is called to send the transaction information to the server and packaged into the block chain.

. / cleos transfer sender recipient amount memo

Programs/cleos/main.cpp

Main ()

{

...

Send_actions ({create_transfer (sender, recipient, amount, memo)})

...

}

Void send_actions {

Auto result = push_actions (move (actions), extra_kcpu, compression)

...

}

Fc::variant push_actions {

Signed_transaction trx

Trx.actions = std::forward (actions)

Return push_transaction (trx, extra_kcpu, compression)

}

Fc::variant push_transaction {

Trx.set_reference_block (ref_block_id)

/ / send the "/ V1/chain/push_transaction" URL address to the server

If (! tx_dont_broadcast) {

Return call (push_txn_func, packed_transaction (trx, compression))

}

}

Fc::variant call {

Try {

Return eosio::client::http::do_http_call (url, path, fc::variant (v))

}

}

Fc::variant do_http_call {

/ / encapsulate the requested URL into a http package

Request_stream get_resource ()

Auto handler_itr = url_handlers.find (resource)

If (handler_itr! = url_handlers.end ()) {

Handler_itr- > second (resource, body, [con] (int code, string body) {

Con- > set_body (body)

Con- > set_status (websocketpp::http::status_code::value (code))

});

}

...

}

Register the URL handler

Url_handlers is a map collection of key-value pairs of URL and handler functions, managed by class http_plugin_impl, and other plug-in modules register URL callback functions through the add_api function.

Plugins/http_plugin/http_plugin.cpp

Class http_plugin_impl {

Map url_handlers

...

}

Void add_api (const api_description& api) {

For (const auto& call: api)

Add_handler (call.first, call.second)

}

Void http_plugin::add_handler {

...

My- > url_handlers.insert (std::make_pair (url,handler))

}

For example, the chain_api_plugin plug-in registers the following URL callback function in the startup function, including querying block information and processing transaction data:

Void chain_api_plugin::plugin_startup () {

App (). Get_plugin (). Add_api ({

CHAIN_RO_CALL (get_info, 200)

CHAIN_RO_CALL (get_block, 200)

...

CHAIN_RW_CALL (push_transaction, 202)

CHAIN_RW_CALL (push_transactions, 202)

});

}

The above is the editor for you to share how to use EOS code for command registration and communication mechanism analysis, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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

Network Security

Wechat

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

12
Report