4 contract TrivialLock() locks amount of asset {
5 clause trivialUnlock() {
11 const LockWithPublicKey = `
12 contract LockWithPublicKey(publicKey: PublicKey) locks amount of asset {
13 clause unlockWithSig(sig: Signature) {
14 verify checkTxSig(publicKey, sig)
15 unlock amount of asset
20 const LockWithPKHash = `
21 contract LockWithPublicKeyHash(pubKeyHash: Hash) locks amount of asset {
22 clause spend(pubKey: PublicKey, sig: Signature) {
23 verify sha3(pubKey) == pubKeyHash
24 verify checkTxSig(pubKey, sig)
25 unlock amount of asset
30 const LockWith2of3Keys = `
31 contract LockWith3Keys(pubkey1, pubkey2, pubkey3: PublicKey) locks amount of asset {
32 clause unlockWith2Sigs(sig1, sig2: Signature) {
33 verify checkTxMultiSig([pubkey1, pubkey2, pubkey3], [sig1, sig2])
34 unlock amount of asset
39 const LockToOutput = `
40 contract LockToOutput(address: Program) locks amount of asset {
42 lock amount of asset with address
48 contract TradeOffer(requestedAsset: Asset, requestedAmount: Amount, sellerProgram: Program, sellerKey: PublicKey) locks amount of asset {
50 lock requestedAmount of requestedAsset with sellerProgram
51 unlock amount of asset
53 clause cancel(sellerSig: Signature) {
54 verify checkTxSig(sellerKey, sellerSig)
55 unlock amount of asset
60 const EscrowedTransfer = `
61 contract EscrowedTransfer(agent: PublicKey, sender: Program, recipient: Program) locks amount of asset {
62 clause approve(sig: Signature) {
63 verify checkTxSig(agent, sig)
64 lock amount of asset with recipient
66 clause reject(sig: Signature) {
67 verify checkTxSig(agent, sig)
68 lock amount of asset with sender
73 const RevealPreimage = `
74 contract RevealPreimage(hash: Hash) locks amount of asset {
75 clause reveal(string: String) {
76 verify sha3(string) == hash
77 unlock amount of asset
81 const PriceChanger = `
82 contract PriceChanger(askAmount: Amount, askAsset: Asset, sellerKey: PublicKey, sellerProg: Program) locks valueAmount of valueAsset {
83 clause changePrice(newAmount: Amount, newAsset: Asset, sig: Signature) {
84 verify checkTxSig(sellerKey, sig)
85 lock valueAmount of valueAsset with PriceChanger(newAmount, newAsset, sellerKey, sellerProg)
88 lock askAmount of askAsset with sellerProg
89 unlock valueAmount of valueAsset
94 const TestDefineVar = `
95 contract TestDefineVar(result: Integer) locks valueAmount of valueAsset {
96 clause LockWithMath(left: Integer, right: Integer) {
97 define calculate: Integer = left + right
98 verify left != calculate
99 verify result == calculate
100 unlock valueAmount of valueAsset
105 const TestAssignVar = `
106 contract TestAssignVar(result: Integer) locks valueAmount of valueAsset {
107 clause LockWithMath(first: Integer, second: Integer) {
108 define calculate: Integer = first
109 assign calculate = calculate + second
110 verify result == calculate
111 unlock valueAmount of valueAsset
117 contract TestSigIf(a: Integer, count:Integer) locks valueAmount of valueAsset {
118 clause check(b: Integer, c: Integer) {
125 unlock valueAmount of valueAsset
129 const TestIfAndMultiClause = `
130 contract TestIfAndMultiClause(a: Integer, cancelKey: PublicKey) locks valueAmount of valueAsset {
131 clause check(b: Integer, c: Integer) {
136 unlock valueAmount of valueAsset
138 clause cancel(sellerSig: Signature) {
139 verify checkTxSig(cancelKey, sellerSig)
140 unlock valueAmount of valueAsset
145 const TestIfNesting = `
146 contract TestIfNesting(a: Integer, count:Integer) locks valueAmount of valueAsset {
147 clause check(b: Integer, c: Integer, d: Integer) {
158 unlock valueAmount of valueAsset
160 clause cancel(e: Integer, f: Integer) {
166 unlock valueAmount of valueAsset
170 const TestConstantMath = `
171 contract TestConstantMath(result: Integer, hashByte: Hash, hashStr: Hash, outcome: Boolean) locks valueAmount of valueAsset {
172 clause calculation(left: Integer, right: Integer, boolResult: Boolean) {
173 verify result == left + right + 10
174 verify hashByte == sha3(0x31323330)
175 verify hashStr == sha3('string')
177 verify boolResult && (result == left + 20)
178 unlock valueAmount of valueAsset