スマートコントラクトにディスパッチャを実装したい。私はこれについて研究し、理論的には理解していますが、実際には理解していません。ディスパッチャを使用する正確な理由は何ですか?基本的に、コードとレシーバーをチェックする適用アクションハンドラーが必要です。しかし、私は正確な必要性と、可能であれば簡単に理解するためのいくつかの有用なリンクを知りたいです。また、任意のチュートリアル。スマートコントラクトにディスパッチャーを実装する方法は?ありがとうございました。
スマートコントラクトのディスパッチャ
Usually, you don't need to implement dispatcher by yourself. [[eosio::action]]
and [[eosio::on_notify]]
will generate a proper action dispatcher automatically. There were some security accidents by writing incomplete action dispatcher. If you don't know what you are doing exactly, it's better to rely on automatic generation of action dispatcher by eosio-cpp
.
Basically, EOSIO calls apply()
function by default for every action. You can consider it like main()
in normal program. It is an entry point of executing an action. apply()
function instantiates your contract class (You should've written classes inheriting from eosio::contract
), and deserializes name
and data
fields in action. name
indicates the name which this action wants to call like transfer
in eosio::token
and data
are arguments like (from, to, quantity, memo)
needed to be passed to function. By these information, apply()
will call a proper function and pass arguments to it.
Refer to this to understand how generated apply()
looks like.