OSDN Git Service

0c132831a6bcc0132d5d89f9a06331f2798b9299
[bytom/equity.git] / compiler / equitytest / FixedLimitProfit
1 contract FixedLimitProfit(assetBill: Asset,
2                           totalAmountBill: Amount,
3                           totalAmountCapital: Amount,
4                           expireBlockHeight: Integer,
5                           additionalBlockHeight: Integer,
6                           banker: Program,
7                           bankerKey: PublicKey) locks capitalAmount of capitalAsset {
8   clause profit(amountBill: Amount, saver: Program) {
9     verify above(expireBlockHeight)
10     define sAmountBill: Integer = amountBill/100000000
11     define sTotalAmountBill: Integer = totalAmountBill/100000000
12     verify sAmountBill > 0 && sTotalAmountBill > 0 && amountBill < totalAmountBill
13     define gain: Integer = totalAmountCapital*sAmountBill/sTotalAmountBill
14     verify gain > 0
15     if gain < capitalAmount {
16       lock amountBill of assetBill with banker
17       lock gain of capitalAsset with saver
18       lock capitalAmount - gain of capitalAsset with FixedLimitProfit(assetBill, totalAmountBill, totalAmountCapital, expireBlockHeight, additionalBlockHeight, banker, bankerKey)
19     } else {
20       lock amountBill of assetBill with banker
21       lock capitalAmount of capitalAsset with saver
22     }
23   }
24   clause cancel(bankerSig: Signature) {
25     verify above(additionalBlockHeight)
26     verify checkTxSig(bankerKey, bankerSig)
27     unlock capitalAmount of capitalAsset
28   }
29 }