Function Usage
1. constant function and inconstant function
There are two types of function according to whether any change will be made on the chain: constant function and inconstant function. Constant function uses view/pure/constant to decorate, will return the result on the node it is called and not be broadcasted in the form of a transaction; Inconstant function will be broadcasted in the form of a transaction while be called, the function will change the data on the chain, such as transfer, changing the value of the internal variables of contracts, etc.
Note: If you use create command inside a contract (CREATE instruction), even use view/pure/constant to decorate the dynamically created contract function, this function will still be treated as inconstant function, be dealt in the form of transaction.
2. message calls
Message calls can call the functions of other contracts, also can transfer VS to the accounts of contract and none-contract. Like the common Vision triggercontract, Message calls have initiator, recipient, data, transfer amount, fees and return attributes. Any message call can generate a new one recursively. Contract can define the distribution of the remaining entropy in the internal message call. If it comes with OutOfEntropyException in the internal message call, it will return false, but not error. In the meanwhile, only the gas sent with the internal message call will be consumed, if entropy is not specified in call.value(entropy), all the remaining entropy will be used.
3. delegate call/call code/library
There is a special type of message call, delegate call. The difference with common message call is the code of the target address will be run in the context of the contract that initiates the call, msg.sender and msg.value remain unchanged. This means a contract can dynamically loadcode from another address while running. Storage, current address and balance all point to the contract that initiates the call, only the code is get from the address being called. This gives Solidity the ability to achieve the 'lib' function: the reusable code lib can be put in the storage of a contract to implement complex data structure library.
4. CREATE instruction
This command will create a new contract with a new address. The only difference with Ethereum is the newly generated Vision address used the smart contract creation transaction id and the hash of nonce called combined. Different from Ethereum, the defination of nonce is the comtract sequence number of the creation of the root call. Even there are many CREATE commands calls, contract number in sequence from 1. Refer to the source code for more detail. Note: Different from creating a contract by grpc's deploycontract, contract created by CREATE command does not store contract abi.
Updated over 3 years ago