sys
Provides essential system-level functionalities, including log, revert, require, etc.
import
{
sys
} from "@artela/aspect-libs";
sys
1. revert
Rollback the current transaction and return the information to the node.
revert(message: string)
Parameter
- string : error message.
Example
sys.revert("error message");
When executes sys.revert
, the program will be interrupted to continue execution, and a Message log will be printed on the server.
Warning
- If 'revert' is triggered within the Join-points of
PreContractCall, PostContractCall, PreTxExecute, PostTxExecute, and Operation
, it will revert transaction in blockchain. - If 'revert' is executed within the
VerifyTx
pointcut, it will drop the transaction from the MemPool.
2. require
The require function is used to confirm the validity of the condition and if an error occurs, the
termination program
continues to run.
require(condition: bool, message: string = ''): void
Parameter
- condition : bool
- message : string
Example
sys.require(1 == 2, "Not equal")
If the condition evaluates to false, the program will be interrupted, and a message log will be printed on the server.
Warning
- If 'require' is triggered within the Join-points of
PreContractCall, PostContractCall, PreTxExecute, PostTxExecute, and Operation
, it will revert transaction in blockchain. - If 'require' is executed within the
VerifyTx
pointcut, it will drop the transaction from the MemPool.
3. log
Log information to the server.
log(message: string): void
Parameter
- string : log message.
Example
{
sys.log("print message");
}
Log printing is generally used in program debugging. However, printing too many logs will consume system performance, and it will limit this function on produce mode.