2 Package equity provides a compiler for Chain'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 Chain 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" identifier "{" clause+ "}"
19 The identifier after "locks" is a name for the value locked by
20 the contract. It must be unlocked or re-locked (with "unlock"
21 or "lock") in every clause.
23 clause = "clause" identifier "(" [params] ")" ["requires" requirements] "{" statement+ "}"
25 The requirements are blockchain values that must be present in
26 the spending transaction in order to spend the value locked by
27 the earlier transaction. Each such value must be re-locked
28 (with "lock") in its clause.
30 statement = verify | unlock | lock
32 verify = "verify" expr
34 Verifies that boolean expression expr produces a true result.
36 unlock = "unlock" expr
38 Expr must evaluate to the contract value. This unlocks that
41 lock = "lock" expr "with" expr
43 The first expr must be a blockchain value (i.e., one named
44 with "locks" or "requires"). The second expr must be a
45 program. This unlocks expr and re-locks it with the new
48 requirements = requirement | requirements "," requirement
50 requirement = identifier ":" expr "of" expr
52 The first expr must be an amount, the second must be an
53 asset. This denotes that the named value must have the given
54 quantity and asset type.
56 params = param | params "," param
58 param = idlist ":" identifier
60 The identifiers in idlist are individual parameter names. The
61 identifier after the colon is their type. Available types are:
63 Amount; Asset; Boolean; Hash; Integer; Program; PublicKey;
64 Signature; String; Time
66 idlist = identifier | idlist "," identifier
68 expr = unary_expr | binary_expr | call_expr | identifier | "(" expr ")" | literal
70 unary_expr = unary_op expr
72 binary_expr = expr binary_op expr
74 call_expr = expr "(" [args] ")"
76 If expr is the name of an Equity contract, then calling it (with
77 the appropriate arguments) produces a program suitable for use
80 Otherwise, expr should be one of these builtin functions:
91 The lesser of x and y.
93 The greater of x and y.
94 checkTxSig(pubkey, signature)
95 Whether signature matches both the spending
96 transaction and pubkey.
98 The concatenation of x and y.
100 The concatenation of x with the bytecode sequence
101 needed to push y on the ChainVM stack.
103 Whether the spending transaction is happening before
106 Whether the spending transaction is happening after
108 checkTxMultiSig([pubkey1, pubkey2, ...], [sig1, sig2, ...])
109 Like checkTxSig, but for M-of-N signature checks.
110 Every sig must match both the spending transaction and
111 one of the pubkeys. There may be more pubkeys than
112 sigs, but they are only checked left-to-right so must
113 be supplied in the same order as the sigs. The square
114 brackets here are literal and must appear as shown.
118 binary_op = ">" | "<" | ">=" | "<=" | "==" | "!=" | "^" | "|" |
119 "+" | "-" | "&" | "<<" | ">>" | "%" | "*" | "/"
121 args = expr | args "," expr
123 literal = int_literal | str_literal | hex_literal