OSDN Git Service

deposit contract FixedLimitCollect and FixedLimitProfit (#28)
authoroysheng <33340252+oysheng@users.noreply.github.com>
Tue, 11 Dec 2018 05:57:43 +0000 (13:57 +0800)
committerPaladz <yzhu101@uottawa.ca>
Tue, 11 Dec 2018 05:57:43 +0000 (13:57 +0800)
compiler/equitytest/FixedLimitCollect [new file with mode: 0644]
compiler/equitytest/FixedLimitProfit [new file with mode: 0644]
compiler/equitytest/equity_test.go

diff --git a/compiler/equitytest/FixedLimitCollect b/compiler/equitytest/FixedLimitCollect
new file mode 100644 (file)
index 0000000..6bef9b6
--- /dev/null
@@ -0,0 +1,33 @@
+import "./FixedLimitProfit"
+
+contract FixedLimitCollect(assetDeposited: Asset,
+                           totalAmountBill: Amount,
+                           totalAmountCapital: Amount,
+                           dueBlockHeight: Integer,
+                           expireBlockHeight: Integer,
+                           additionalBlockHeight: Integer,
+                           banker: Program,
+                           bankerKey: PublicKey) locks billAmount of billAsset {
+  clause collect(amountDeposited: Amount, saver: Program) {
+    verify below(dueBlockHeight)
+    verify amountDeposited/100000000 > 0 && amountDeposited <= billAmount && totalAmountBill <= totalAmountCapital
+    define sAmountDeposited: Integer = amountDeposited/100000000
+    define sTotalAmountBill: Integer = totalAmountBill/100000000
+    verify sAmountDeposited > 0 && sTotalAmountBill > 0
+    define gain: Integer = totalAmountCapital*sAmountDeposited/sTotalAmountBill
+    verify gain > 0
+    if amountDeposited < billAmount {
+      lock amountDeposited of assetDeposited with FixedLimitProfit(billAsset, totalAmountBill, totalAmountCapital, expireBlockHeight, additionalBlockHeight, banker, bankerKey)
+      lock amountDeposited of billAsset with saver
+      lock billAmount-amountDeposited of billAsset with FixedLimitCollect(assetDeposited, totalAmountBill, totalAmountCapital, dueBlockHeight, expireBlockHeight, additionalBlockHeight, banker, bankerKey)
+    } else {
+      lock amountDeposited of assetDeposited with FixedLimitProfit(billAsset, totalAmountBill, totalAmountCapital, expireBlockHeight, additionalBlockHeight, banker, bankerKey)
+      lock billAmount of billAsset with saver
+    }
+  }
+  clause cancel(bankerSig: Signature) {
+    verify above(dueBlockHeight)
+    verify checkTxSig(bankerKey, bankerSig)
+    unlock billAmount of billAsset
+  }
+}
diff --git a/compiler/equitytest/FixedLimitProfit b/compiler/equitytest/FixedLimitProfit
new file mode 100644 (file)
index 0000000..0c13283
--- /dev/null
@@ -0,0 +1,29 @@
+contract FixedLimitProfit(assetBill: Asset,
+                          totalAmountBill: Amount,
+                          totalAmountCapital: Amount,
+                          expireBlockHeight: Integer,
+                          additionalBlockHeight: Integer,
+                          banker: Program,
+                          bankerKey: PublicKey) locks capitalAmount of capitalAsset {
+  clause profit(amountBill: Amount, saver: Program) {
+    verify above(expireBlockHeight)
+    define sAmountBill: Integer = amountBill/100000000
+    define sTotalAmountBill: Integer = totalAmountBill/100000000
+    verify sAmountBill > 0 && sTotalAmountBill > 0 && amountBill < totalAmountBill
+    define gain: Integer = totalAmountCapital*sAmountBill/sTotalAmountBill
+    verify gain > 0
+    if gain < capitalAmount {
+      lock amountBill of assetBill with banker
+      lock gain of capitalAsset with saver
+      lock capitalAmount - gain of capitalAsset with FixedLimitProfit(assetBill, totalAmountBill, totalAmountCapital, expireBlockHeight, additionalBlockHeight, banker, bankerKey)
+    } else {
+      lock amountBill of assetBill with banker
+      lock capitalAmount of capitalAsset with saver
+    }
+  }
+  clause cancel(bankerSig: Signature) {
+    verify above(additionalBlockHeight)
+    verify checkTxSig(bankerKey, bankerSig)
+    unlock capitalAmount of capitalAsset
+  }
+}
index e1e2caa..36b4b65 100644 (file)
@@ -23,6 +23,14 @@ func TestCompileContract(t *testing.T) {
                        "./LoanCollateral",
                        "567a64650000007bcda06900c3537ac2547a5100597989587a89577a89557a89537a8901747e2a557a641f0000007bcda069007b7b51547ac16951c3c251547ac1632a0000007bcd9f6900c3c251567ac189008901c07ec16951c3c251547ac163700000007bcd9f6900c3c251577ac1",
                },
+               {
+                       "./FixedLimitCollect",
+                       "597a64370200005479cda069c35b790400e1f5059600a05c797ba19a53795579a19a695a790400e1f5059653790400e1f505967800a07800a09a6955797b957c9600a069c35b797c9f9161645b010000005b79c2547951005e79895d79895c79895b7989597989587989537a894ca4587a64980000005479cd9f6959790400e1f5059653790400e1f505967800a07800a09a5c7956799f9a6955797b957c967600a069c3787c9f91616481000000005b795479515b79c1695178c2515d79c16952c3527994c251005d79895c79895b79895a79895979895879895779895679890274787e008901c07ec1696393000000005b795479515b79c16951c3c2515d79c16963a4000000557acd9f69577a577aae7cac890274787e008901c07ec169515b79c2515d79c16952c35c7994c251005d79895c79895b79895a79895979895879895779895679895579890274787e008901c07ec1696332020000005b79c2547951005e79895d79895c79895b7989597989587989537a894ca4587a64980000005479cd9f6959790400e1f5059653790400e1f505967800a07800a09a5c7956799f9a6955797b957c967600a069c3787c9f91616481000000005b795479515b79c1695178c2515d79c16952c3527994c251005d79895c79895b79895a79895979895879895779895679890274787e008901c07ec1696393000000005b795479515b79c16951c3c2515d79c16963a4000000557acd9f69577a577aae7cac890274787e008901c07ec16951c3c2515d79c1696343020000547acd9f69587a587aae7cac",
+               },
+               {
+                       "./FixedLimitProfit",
+                       "587a64980000005479cd9f6959790400e1f5059653790400e1f505967800a07800a09a5c7956799f9a6955797b957c967600a069c3787c9f91616481000000005b795479515b79c1695178c2515d79c16952c3527994c251005d79895c79895b79895a79895979895879895779895679890274787e008901c07ec1696393000000005b795479515b79c16951c3c2515d79c16963a4000000557acd9f69577a577aae7cac",
+               },
        }
 
        for _, c := range cases {