Comment on page
Creating a Protocol Contract (Advanced)
You can create any contract you want, but there are some requirements that you need to follow:
src/contract/contractmanager.h, you will find a global
std::unordered_mapwhich contains the registered Protocol Contract addresses. You should stick to the same format as the other contracts, and add your contract address to the map.
It is required to pay attention to the state of the contract and how nodes will interact with each other. For example, if you have a contract that is doing parallel processing of a task, you need to make sure that this task can be replicated with the same result in any node. Not taking care of the state of a contract will eventually lead to undefined behavior, and that's a hornet's nest nobody wants to touch, right?
It is necessary to override the
ethCall()function in order to make functions callable by a transaction or an RPC
eth_call. Protocol Contracts don't have automatic function parsing and they don’t handle call reverts, so you need to handle it all yourself.
this->getCommit() == false, it means that the current call is trying to simulate if it's going to throw or not, but if
this->getCommit() == true, it means that the current call is trying to commit to the state, and you should do it respectively if it doesn't throw.
It is necessary to add a reference of your Protocol Contract to the
ContractManager. This is done within the
rdPoScontract (another Protocol Contract). See more under these files: