2 Package equity provides a compiler for Bytom's Equity contract language.
4 A contract is a means to lock some payment in the output of a
5 transaction. It contains a number of clauses, each describing a way to
6 unlock, or redeem, the payment in a subsequent transaction. By
7 executing the statements in a clause, using contract arguments
8 supplied by the payer and clause arguments supplied by the redeemer,
9 nodes in a Bytom network can determine whether a proposed spend is
12 The language definition is in flux, but here's what's implemented as
17 contract = "contract" identifier "(" [params] ")" "locks" amount_identifier of asset_identifier "{" clause+ "}"
19 The value(amount_identifier of asset_identifier) after "locks" is a name for
20 the value locked by the contract. It must be unlocked or re-locked (with "unlock"
21 or "lock") in every clause.
23 clause = "clause" identifier "(" [params] ")" "{" statement+ "}"
25 statement = verify | unlock | lock | define | assign | if/else
27 verify = "verify" expr
29 Verifies that boolean expression expr produces a true result.
31 unlock = "unlock" expr "of" expr
33 The first expr must be an amount, the second must be an asset.
34 the value(expr "of" expr) must evaluate to the contract value.
35 This unlocks that value for any use.
37 lock = "lock" expr "of" expr "with" expr
39 The first expr must be an amount, the second must be an asset.
40 The later expr after "with" must be a program. This expression describe that
41 the value(expr "of" expr) is unlocked and re-locks it with the new program immediately.
43 define = "define" identifier : TypeName ["=" expr]
45 Define a temporary variable "identifier" with type "TypeName". the identifier can be defined only
46 or assigned with expr.
48 assign = "assign" identifier "=" expr
50 Assign a temporary variable "identifier" with expr. Please note that
51 the "identifier" must be the defined variable with "define" expression.
53 if = "if" expr "{" statement+ "}" [else "{" statement+ "}"]
55 The check condition after "if" must be boolean expression. The if-else executes the statements
56 inside the body of if-statement when condition expression is true, otherwise executes the statements
57 inside the body of else-statement.
59 params = param | params "," param
61 param = identifier ":" type
63 The identifier are individual parameter name. The identifier after the colon is their type.
66 Amount; Asset; Boolean; Hash; Integer; Program;
67 PublicKey; Signature; String
69 idlist = identifier | idlist "," identifier
71 expr = unary_expr | binary_expr | call_expr | identifier | "(" expr ")" | literal
73 unary_expr = unary_op expr
75 binary_expr = expr binary_op expr
77 call_expr = expr "(" [args] ")"
79 If expr is the name of an Equity contract, then calling it (with
80 the appropriate arguments) produces a program suitable for use
83 Otherwise, expr should be one of these builtin functions:
94 The lesser of x and y.
96 The greater of x and y.
97 checkTxSig(pubkey, signature)
98 Whether signature matches both the spending
99 transaction and pubkey.
101 The concatenation of x and y.
103 The concatenation of x with the bytecode sequence
104 needed to push y on the BVM stack.
106 Whether the spending transaction is happening before
109 Whether the spending transaction is happening after
111 checkTxMultiSig([pubkey1, pubkey2, ...], [sig1, sig2, ...])
112 Like checkTxSig, but for M-of-N signature checks.
113 Every sig must match both the spending transaction and
114 one of the pubkeys. There may be more pubkeys than
115 sigs, but they are only checked left-to-right so must
116 be supplied in the same order as the sigs. The square
117 brackets here are literal and must appear as shown.
121 binary_op = ">" | "<" | ">=" | "<=" | "==" | "!=" | "^" | "|" |
122 "+" | "-" | "&" | "<<" | ">>" | "%" | "*" | "/"
124 args = expr | args "," expr
126 literal = int_literal | str_literal | hex_literal