OSDN Git Service

cp code from bytom repo
[bytom/equity.git] / compiler / equitytest / equitytest.go
1 package equitytest
2
3 const TrivialLock = `
4 contract TrivialLock() locks locked {
5   clause trivialUnlock() {
6     unlock locked
7   }
8 }
9 `
10
11 const LockWithPublicKey = `
12 contract LockWithPublicKey(publicKey: PublicKey) locks locked {
13   clause unlockWithSig(sig: Signature) {
14     verify checkTxSig(publicKey, sig)
15     unlock locked
16   }
17 }
18 `
19
20 const LockWithPKHash = `
21 contract LockWithPublicKeyHash(pubKeyHash: Hash) locks value {
22   clause spend(pubKey: PublicKey, sig: Signature) {
23     verify sha3(pubKey) == pubKeyHash
24     verify checkTxSig(pubKey, sig)
25     unlock value
26   }
27 }
28 `
29
30 const LockWith2of3Keys = `
31 contract LockWith3Keys(pubkey1, pubkey2, pubkey3: PublicKey) locks locked {
32   clause unlockWith2Sigs(sig1, sig2: Signature) {
33     verify checkTxMultiSig([pubkey1, pubkey2, pubkey3], [sig1, sig2])
34     unlock locked
35   }
36 }
37 `
38
39 const LockToOutput = `
40 contract LockToOutput(address: Program) locks locked {
41   clause relock() {
42     lock locked with address
43   }
44 }
45 `
46
47 const TradeOffer = `
48 contract TradeOffer(requestedAsset: Asset, requestedAmount: Amount, sellerProgram: Program, sellerKey: PublicKey) locks offered {
49   clause trade() requires payment: requestedAmount of requestedAsset {
50     lock payment with sellerProgram
51     unlock offered
52   }
53   clause cancel(sellerSig: Signature) {
54     verify checkTxSig(sellerKey, sellerSig)
55     lock offered with sellerProgram
56   }
57 }
58 `
59
60 const EscrowedTransfer = `
61 contract EscrowedTransfer(agent: PublicKey, sender: Program, recipient: Program) locks value {
62   clause approve(sig: Signature) {
63     verify checkTxSig(agent, sig)
64     lock value with recipient
65   }
66   clause reject(sig: Signature) {
67     verify checkTxSig(agent, sig)
68     lock value with sender
69   }
70 }
71 `
72
73 const CollateralizedLoan = `
74 contract CollateralizedLoan(balanceAsset: Asset, balanceAmount: Amount, finalHeight: Integer, lender: Program, borrower: Program) locks collateral {
75   clause repay() requires payment: balanceAmount of balanceAsset {
76     lock payment with lender
77     lock collateral with borrower
78   }
79   clause default() {
80     verify above(finalHeight)
81     lock collateral with lender
82   }
83 }
84 `
85
86 const RevealPreimage = `
87 contract RevealPreimage(hash: Hash) locks value {
88   clause reveal(string: String) {
89     verify sha3(string) == hash
90     unlock value
91   }
92 }
93 `
94
95 const PriceChanger = `
96 contract PriceChanger(askAmount: Amount, askAsset: Asset, sellerKey: PublicKey, sellerProg: Program) locks offered {
97   clause changePrice(newAmount: Amount, newAsset: Asset, sig: Signature) {
98     verify checkTxSig(sellerKey, sig)
99     lock offered with PriceChanger(newAmount, newAsset, sellerKey, sellerProg)
100   }
101   clause redeem() requires payment: askAmount of askAsset {
102     lock payment with sellerProg
103     unlock offered
104   }
105 }
106 `
107
108 const CallOptionWithSettlement = `
109 contract CallOptionWithSettlement(strikePrice: Amount,
110                     strikeCurrency: Asset,
111                     sellerProgram: Program,
112                     sellerKey: PublicKey,
113                     buyerKey: PublicKey,
114                     finalHeight: Integer) locks underlying {
115   clause exercise(buyerSig: Signature)
116                  requires payment: strikePrice of strikeCurrency {
117     verify below(finalHeight)
118     verify checkTxSig(buyerKey, buyerSig)
119     lock payment with sellerProgram
120     unlock underlying
121   }
122   clause expire() {
123     verify above(finalHeight)
124     lock underlying with sellerProgram
125   }
126   clause settle(sellerSig: Signature, buyerSig: Signature) {
127     verify checkTxSig(sellerKey, sellerSig)
128     verify checkTxSig(buyerKey, buyerSig)
129     unlock underlying
130   }
131 }
132 `
133
134 const OneTwo = `
135 contract Two(b, c: Program, expirationHeight: Integer) locks value {
136   clause redeem() {
137     verify below(expirationHeight)
138     lock value with b
139   }
140   clause default() {
141     verify above(expirationHeight)
142     lock value with c
143   }
144 }
145 contract One(a, b, c: Program, switchHeight, blockHeight: Integer) locks value {
146   clause redeem() {
147     verify below(switchHeight)
148     lock value with a
149   }
150   clause switch() {
151     verify above(switchHeight)
152     lock value with Two(b, c, blockHeight)
153   }
154 }
155 `