-
Notifications
You must be signed in to change notification settings - Fork 2
Smart Contract Overview
martinbtm edited this page Sep 6, 2021
·
1 revision
Equity is a high-level language used by bytom to express contract programs. It is mainly used to describe specific assets on the bytom blockchain:
- All on-chain assets are locked in the contract program. Once the asset value (ie UTXO) is unlocked by a contract, it is only meant to be locked by one or more other contracts.
- The way that the contract protects the asset value (that is, UTXO) is that the transaction must meet the condition through the “verify” command executed through virtual machine.
contract ContractName ( parameters ) locks value { clauses }
-
ContractNamecontract name is defined by user -
parameterslist of contract parameters, which must conform to the basic type of contract language -
valueThe value of the asset (ie UTXO's asset type and corresponding value), which can be customized by the user. -
clauses(ie, functions) (one or more)
clause ClauseName ( parameters ) { statements }
or
clause ClauseName ( parameters ) requires name : amount of asset { statements }
-
ClauseNamename of clauses, which is defined by users -
parameterslist of clause / function parameter -
paymentsother restrictions that are required to spend UTXO. For example, when performing coin-to-coin transaction, it is necessary to verify that the counterparty of the transaction can provide a corresponding asset value. The major use case of such constraints are contract trading between different types of assets.
statements contract language,Only verify、lock and unlock
- the
verifystatement: for exampleverify expression,in which the result of expression must be bool type and true to continue execution - the
unlockstatement: for exampleunlock value,in whichvaluerepresents the value of corresponding asset - the
lockstatement: for examplelock value with program,in whichvaluerepresents the value of corresponding asset, andprogrammust be the program basic type.
Categories of contract: (Time type is temporarily disabled)
Amount Asset Boolean Hash Integer Program PublicKey Signature String
Built-in functions: (The built-in functions related to timing “before” and “after” are temporarily disabled, the alternative is to verify the block height functions “below” and “above”)
- abs(n) returns the absolute value of the value n.
- min(x, y) returns the smallest of the two values x and y.
- max(x, y) returns the largest of the two values x and y.
- size(s) returns the size of any type of byte.
- concat(s1, s2) returns the string generated from connecting the two strings s1 and s2
- concatpush(s1, s2) concatenates two string-type virtual machine execution opcodes s1 and s2 (ie s2 is joined behind s1) and pushes them onto the stack. The operation function is mainly used for nested contracts.
- below(height) Determines whether the current block height is lower than the parameter height, and returns true if it is, otherwise returns false.
- above(height) Determines whether the current block height is higher than the parameter height, and returns true if it is, otherwise returns false.
- sha3(s) returns the hashing result of byte type string parameter s via SHA3-256.
- sha256(s) returns the hashing result of byte type string parameter s via SHA-256
- checkTxSig(key, sig) verifies whether the multi-signature of the transaction is correct based on one PublicKey and one Signature.
- checkTxMultiSig([key1, key2, ...], [sig1, sig2, ...]) Verify that the multi-signature of the transaction is correct based on multiple PublicKeys and multiple Signatures.