PlatON Lectures: Online Open Class on PlatON Smart Contract (II)

Cross Contract Call

Currently, we support two cross contract calls:

platon_call : a direct contract call

platon_delegate_call : a cross contract call

Both of them are template functions, and should add the specific returned value type of called contract value. The returned value is a pair, of which the first element is the return value of the called contract call, and the second element is a boolean type, showing whether it succeed or failed.

The target contract target_contract defines method_one and method-two , and get the addresses after deploying the target contract.

Regarding user contract, developers can call target_contract with platon-call or platon_delegate_call .






Smart Contract Suspension

PlatON provides assert function platon_assert . When it failed, contract suspends while the gas has been consumed.

According to the security strategy, developer can apply platon_panic function to suspend the smart contract. Under such circumstance, gas will run out.





Smart Contract Events

PLATON_EVENT macro is used in smart contract events. There are two kinds of PLATON_EVENT macros: theme and general parameters, which are used for searching, showing users’ event info, respectively.

PLATON_EVENTn , “ n ” refers to the number of topics, and the actual number of topics is n+1. The first topic is the name of event. Currently, PlatON doesn’t support anonymous event, and the anonymous of generated abi file is false.

In order to stop the event topic from being too long, if the field of topic in the receipt is of value type such as boolean, integer, floating-point computer, etc., then the value refers to the byte array of bigendian; If not, the value is a 32-byt array that has been rlp-coded and then Keccak-hashed.



Define Events

The name refers to the name of event, topic_type and args_type refer to the event types such as std::string, unit 32_t, etc. Currently, the topic_type of smart contract events support all types, and topic_type can only be placed behind name.





Trigger Events

The name refers to the name of event, topic_data and args_date refer to the specific parameters such as std::string (hello), 21, etc. Currently, the topic_data can only be placed behind name.





For example. Define an event named transfer with PLATON_EVENT1 . This event includes a topic, namely, an index. However, they are two indexes in this event including the constant std:string type of which the topic refers to the name of event, and the customized std::string type of which the topic and unit32_t refer to the parameter types of events. Trigger transfer event with PLATON_EMIT_EVENT1 , the specific index value is name , and the parameter value of event is value .





Smart Contract Debugging

Developer can debug the smart contract through printing log and realized by DUBUG macro. This macro can receive any parameters, each parameters should be separated by comma. The default smart contract won’t print the debugging details. If you want to enable it, just add #undef NDEBUG in front of all head files.

1 个赞