tx · 7zMtizKKWVwmCzdhAoDQDZMLsQtpDkNqCJtBVHZKNYe2
3N88HLHyQgayARc6MXuoJgYJM6Hp9q8AD4X: -0.01000000 Waves
2021.06.25 11:48 [1585676] smart account 3N88HLHyQgayARc6MXuoJgYJM6Hp9q8AD4X > SELF 0.00000000 Waves
{
"type": 13,
"id": "7zMtizKKWVwmCzdhAoDQDZMLsQtpDkNqCJtBVHZKNYe2",
"fee": 1000000,
"feeAssetId": null,
"timestamp": 1624610866721,
"version": 2,
"chainId": 84,
"sender": "3N88HLHyQgayARc6MXuoJgYJM6Hp9q8AD4X",
"senderPublicKey": "7d8ot6oQCGQZb8ATJ6U8KciEiWMyGupkrdYRjcoRfNzs",
"proofs": [
"46AcCxf9EL63EpqSXSZLS8RZ3CbNsHN82P7VychUK17ckZvs9ZK5CtYSe8DqnWf3Ww2kEWFQUm7RUPdcMxAcfAdW"
],
"script": "base64:AAIEAAAAAAAAACAIAhIECgIBCBIECgIBCBIECgIBCBIECgIBCBIECgIBCAAAAAQBAAAACmdldEFzc2V0SUQAAAABAAAABWFzc2V0BAAAAAdhc3NldElEAwkAAAAAAAACBQAAAAVhc3NldAIAAAAAAgAAAAADCQAAAAAAAAIFAAAABWFzc2V0AgAAAARVU0ROAgAAACwzS0ZYQkdHTENqQTVaMkR1VzREcTlmRERySGpKSlAxWkVrYW9halN6dUtzQwkAAAIAAAABAgAAABFVbnN1cHBvcnRlZCBhc3NldAUAAAAHYXNzZXRJRAEAAAAQZ2V0RGVwb3NpdEFtb3VudAAAAAIAAAAJcHVibGljS2V5AAAABWFzc2V0BAAAAAl1c2VkQXNzZXQDCQAAAAAAAAIFAAAABWFzc2V0AgAAAAACAAAABVdBVkVTBQAAAAVhc3NldAQAAAAHYmFsYW5jZQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzCQABLAAAAAIJAAEsAAAAAgkAASwAAAACAgAAAAhkZXBvc2l0XwUAAAAJcHVibGljS2V5AgAAAAFfBQAAAAl1c2V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FpAAAAD2NhbGxlclB1YmxpY0tleQQAAAAKY3VycmVudERlcAkBAAAAEGdldERlcG9zaXRBbW91bnQAAAACBQAAAAlwdWJsaWNLZXkFAAAACXVzZWRBc3NldAMJAABmAAAAAgAAAAAAAAAAAAUAAAAGYW1vdW50CQAAAgAAAAECAAAAHkNhbid0IHdpdGhkcmF3IG5lZ2F0aXZlIGFtb3VudAMDCQAAZgAAAAIFAAAACmN1cnJlbnREZXAAAAAAAAAAAAAJAABnAAAAAgUAAAAKY3VycmVudERlcAUAAAAGYW1vdW50BwkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgkAASwAAAACCQABLAAAAAIJAAEsAAAAAgIAAAAIZGVwb3NpdF8FAAAACXB1YmxpY0tleQIAAAABXwUAAAAJdXNlZEFzc2V0CQAAZQAAAAIFAAAACmN1cnJlbnREZXAFAAAABmFtb3VudAkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADBQAAABR0cmFuc2FjdGlvblB1YmxpY0tleQUAAAAGYW1vdW50CAUAAAABaQAAAApmZWVBc3NldElkBQAAAANuaWwJAAACAAAAAQIAAAATTm90aGluZyB0byB3aXRoZHJhdwAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAAEAAAAByRtYXRjaDAFAAAAAnR4AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAA9EYXRhVHJhbnNhY3Rpb24GAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAABRTZXRTY3JpcHRUcmFuc2FjdGlvbgYG8isTqA==",
"height": 1585676,
"applicationStatus": "succeeded",
"spentComplexity": 0
}
View: original | compacted
Prev: ABqEYGbmUNvS8kZB9cxC4dRR1m4c4VbPf5NV9hpRvzBU
Next: none
Diff:
Old | New | | Differences |
---|
1 | 1 | | {-# STDLIB_VERSION 4 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
| 4 | + | func getAssetID (asset) = { |
---|
| 5 | + | let assetID = if ((asset == "")) |
---|
| 6 | + | then "" |
---|
| 7 | + | else if ((asset == "USDN")) |
---|
| 8 | + | then "3KFXBGGLCjA5Z2DuW4Dq9fDDrHjJJP1ZEkaoajSzuKsC" |
---|
| 9 | + | else throw("Unsupported asset") |
---|
| 10 | + | assetID |
---|
| 11 | + | } |
---|
| 12 | + | |
---|
| 13 | + | |
---|
4 | 14 | | func getDepositAmount (publicKey,asset) = { |
---|
5 | | - | let balance = match getInteger(this, ((("deposit_" + publicKey) + "_") + asset)) { |
---|
| 15 | + | let usedAsset = if ((asset == "")) |
---|
| 16 | + | then "WAVES" |
---|
| 17 | + | else asset |
---|
| 18 | + | let balance = match getInteger(this, ((("deposit_" + publicKey) + "_") + usedAsset)) { |
---|
6 | 19 | | case a: Int => |
---|
7 | 20 | | a |
---|
8 | 21 | | case _ => |
---|
|
13 | 26 | | |
---|
14 | 27 | | |
---|
15 | 28 | | func getBorrowAmount (publicKey,asset) = { |
---|
16 | | - | let balance = match getInteger(this, ((("borrow_" + publicKey) + "_") + asset)) { |
---|
| 29 | + | let usedAsset = if ((asset == "")) |
---|
| 30 | + | then "WAVES" |
---|
| 31 | + | else asset |
---|
| 32 | + | let balance = match getInteger(this, ((("borrow_" + publicKey) + "_") + usedAsset)) { |
---|
17 | 33 | | case a: Int => |
---|
18 | 34 | | a |
---|
19 | 35 | | case _ => |
---|
|
23 | 39 | | } |
---|
24 | 40 | | |
---|
25 | 41 | | |
---|
26 | | - | func getCollateral (publicKey,asset) = if ((asset == "")) |
---|
27 | | - | then { |
---|
28 | | - | let collateral = match getInteger(this, ((("collateral_" + publicKey) + "_Waves") + asset)) { |
---|
29 | | - | case a: Int => |
---|
30 | | - | a |
---|
31 | | - | case _ => |
---|
32 | | - | 0 |
---|
33 | | - | } |
---|
34 | | - | collateral |
---|
35 | | - | } |
---|
36 | | - | else { |
---|
37 | | - | let collateral = match getInteger(this, ((("collateral_" + publicKey) + "_") + asset)) { |
---|
38 | | - | case a: Int => |
---|
39 | | - | a |
---|
40 | | - | case _ => |
---|
41 | | - | 0 |
---|
42 | | - | } |
---|
43 | | - | collateral |
---|
44 | | - | } |
---|
| 42 | + | func getCollateral (publicKey,asset) = { |
---|
| 43 | + | let usedAsset = if ((asset == "")) |
---|
| 44 | + | then "WAVES" |
---|
| 45 | + | else asset |
---|
| 46 | + | let collateral = match getInteger(this, ((("collateral_" + publicKey) + "_") + usedAsset)) { |
---|
| 47 | + | case a: Int => |
---|
| 48 | + | a |
---|
| 49 | + | case _ => |
---|
| 50 | + | 0 |
---|
| 51 | + | } |
---|
| 52 | + | collateral |
---|
| 53 | + | } |
---|
45 | 54 | | |
---|
46 | 55 | | |
---|
47 | 56 | | @Callable(i) |
---|
48 | 57 | | func deposit (amount,asset) = { |
---|
49 | 58 | | let publicKey = toBase58String(i.callerPublicKey) |
---|
50 | | - | let test = if ((asset == "")) |
---|
| 59 | + | let usedAsset = if ((asset == "")) |
---|
51 | 60 | | then "WAVES" |
---|
52 | 61 | | else asset |
---|
53 | | - | let depositAmount = getDepositAmount(publicKey, test) |
---|
| 62 | + | let depositAmount = getDepositAmount(publicKey, usedAsset) |
---|
54 | 63 | | let newDepositAmount = (depositAmount + amount) |
---|
55 | | - | [IntegerEntry(((("deposit_" + publicKey) + "_") + test), newDepositAmount)] |
---|
| 64 | + | [IntegerEntry(((("deposit_" + publicKey) + "_") + usedAsset), newDepositAmount)] |
---|
56 | 65 | | } |
---|
57 | 66 | | |
---|
58 | 67 | | |
---|
59 | 68 | | |
---|
60 | 69 | | @Callable(i) |
---|
61 | 70 | | func depositCollateral (amount,asset) = { |
---|
| 71 | + | let usedAsset = if ((asset == "")) |
---|
| 72 | + | then "WAVES" |
---|
| 73 | + | else asset |
---|
62 | 74 | | let publicKey = toBase58String(i.callerPublicKey) |
---|
63 | | - | let collateralAmount = getCollateral(publicKey, asset) |
---|
| 75 | + | let collateralAmount = getCollateral(publicKey, usedAsset) |
---|
64 | 76 | | let newCollateralAmount = (collateralAmount + amount) |
---|
65 | | - | [IntegerEntry(((("collateral_" + publicKey) + "_") + asset), newCollateralAmount)] |
---|
| 77 | + | if ((0 >= amount)) |
---|
| 78 | + | then throw("Ammount must be bigger than 0") |
---|
| 79 | + | else [IntegerEntry(((("collateral_" + publicKey) + "_") + usedAsset), newCollateralAmount)] |
---|
66 | 80 | | } |
---|
67 | 81 | | |
---|
68 | 82 | | |
---|
69 | 83 | | |
---|
70 | 84 | | @Callable(i) |
---|
71 | 85 | | func borrow (amount,asset) = { |
---|
| 86 | + | let usedAsset = if ((asset == "")) |
---|
| 87 | + | then "WAVES" |
---|
| 88 | + | else asset |
---|
72 | 89 | | let publicKey = toBase58String(i.callerPublicKey) |
---|
73 | | - | let borrowAmount = getBorrowAmount(publicKey, asset) |
---|
74 | | - | let collateral = getCollateral(publicKey, asset) |
---|
| 90 | + | let transactionPublicKey = addressFromPublicKey(i.callerPublicKey) |
---|
| 91 | + | let borrowAmount = getBorrowAmount(publicKey, usedAsset) |
---|
| 92 | + | let collateral = getCollateral(publicKey, usedAsset) |
---|
75 | 93 | | let maxBorrowAmount = ((collateral * 70) / 100) |
---|
76 | 94 | | let newBorrowAmount = (borrowAmount + amount) |
---|
| 95 | + | let usedAssetID = getAssetID(asset) |
---|
77 | 96 | | if ((collateral >= maxBorrowAmount)) |
---|
78 | | - | then [IntegerEntry(((("borrow_" + publicKey) + "_") + asset), newBorrowAmount)] |
---|
| 97 | + | then [IntegerEntry(((("borrow_" + publicKey) + "_") + usedAsset), newBorrowAmount), ScriptTransfer(Address(toBytes(toBase58String(i.callerPublicKey))), amount, toBytes(usedAssetID))] |
---|
79 | 98 | | else throw("Not enough collateral") |
---|
80 | 99 | | } |
---|
81 | 100 | | |
---|
|
83 | 102 | | |
---|
84 | 103 | | @Callable(i) |
---|
85 | 104 | | func repay (amount,asset) = { |
---|
| 105 | + | let usedAsset = if ((asset == "")) |
---|
| 106 | + | then "WAVES" |
---|
| 107 | + | else asset |
---|
86 | 108 | | let publicKey = toBase58String(i.callerPublicKey) |
---|
87 | | - | let currentBorr = getBorrowAmount(publicKey, asset) |
---|
| 109 | + | let currentBorr = getBorrowAmount(publicKey, usedAsset) |
---|
88 | 110 | | if ((currentBorr > 0)) |
---|
89 | | - | then [IntegerEntry(((("borrow_" + publicKey) + "_") + asset), (currentBorr - amount))] |
---|
90 | | - | else throw("Nothing to repay") |
---|
| 111 | + | then [IntegerEntry(((("borrow_" + publicKey) + "_") + usedAsset), (currentBorr - amount))] |
---|
| 112 | + | else [IntegerEntry(((("collateral_" + publicKey) + "_") + usedAsset), amount), throw("Nothing to repay, your Ammount has been deposit as Collateral")] |
---|
91 | 113 | | } |
---|
92 | 114 | | |
---|
93 | 115 | | |
---|
94 | 116 | | |
---|
95 | 117 | | @Callable(i) |
---|
96 | 118 | | func withdraw (amount,asset) = { |
---|
| 119 | + | let usedAsset = if ((asset == "")) |
---|
| 120 | + | then "WAVES" |
---|
| 121 | + | else asset |
---|
97 | 122 | | let publicKey = toBase58String(i.callerPublicKey) |
---|
98 | | - | let currentDep = getDepositAmount(publicKey, asset) |
---|
99 | | - | if ((currentDep > 0)) |
---|
100 | | - | then [IntegerEntry(((("deposit_" + publicKey) + "_") + asset), (currentDep - amount))] |
---|
101 | | - | else throw("Nothing to withdraw") |
---|
| 123 | + | let transactionPublicKey = addressFromPublicKey(i.callerPublicKey) |
---|
| 124 | + | let currentDep = getDepositAmount(publicKey, usedAsset) |
---|
| 125 | + | if ((0 > amount)) |
---|
| 126 | + | then throw("Can't withdraw negative amount") |
---|
| 127 | + | else if (if ((currentDep > 0)) |
---|
| 128 | + | then (currentDep >= amount) |
---|
| 129 | + | else false) |
---|
| 130 | + | then [IntegerEntry(((("deposit_" + publicKey) + "_") + usedAsset), (currentDep - amount)), ScriptTransfer(transactionPublicKey, amount, i.feeAssetId)] |
---|
| 131 | + | else throw("Nothing to withdraw") |
---|
102 | 132 | | } |
---|
103 | 133 | | |
---|
104 | 134 | | |
---|
Full:
Old | New | | Differences |
---|
1 | 1 | | {-# STDLIB_VERSION 4 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
| 4 | + | func getAssetID (asset) = { |
---|
| 5 | + | let assetID = if ((asset == "")) |
---|
| 6 | + | then "" |
---|
| 7 | + | else if ((asset == "USDN")) |
---|
| 8 | + | then "3KFXBGGLCjA5Z2DuW4Dq9fDDrHjJJP1ZEkaoajSzuKsC" |
---|
| 9 | + | else throw("Unsupported asset") |
---|
| 10 | + | assetID |
---|
| 11 | + | } |
---|
| 12 | + | |
---|
| 13 | + | |
---|
4 | 14 | | func getDepositAmount (publicKey,asset) = { |
---|
5 | | - | let balance = match getInteger(this, ((("deposit_" + publicKey) + "_") + asset)) { |
---|
| 15 | + | let usedAsset = if ((asset == "")) |
---|
| 16 | + | then "WAVES" |
---|
| 17 | + | else asset |
---|
| 18 | + | let balance = match getInteger(this, ((("deposit_" + publicKey) + "_") + usedAsset)) { |
---|
6 | 19 | | case a: Int => |
---|
7 | 20 | | a |
---|
8 | 21 | | case _ => |
---|
9 | 22 | | 0 |
---|
10 | 23 | | } |
---|
11 | 24 | | balance |
---|
12 | 25 | | } |
---|
13 | 26 | | |
---|
14 | 27 | | |
---|
15 | 28 | | func getBorrowAmount (publicKey,asset) = { |
---|
16 | | - | let balance = match getInteger(this, ((("borrow_" + publicKey) + "_") + asset)) { |
---|
| 29 | + | let usedAsset = if ((asset == "")) |
---|
| 30 | + | then "WAVES" |
---|
| 31 | + | else asset |
---|
| 32 | + | let balance = match getInteger(this, ((("borrow_" + publicKey) + "_") + usedAsset)) { |
---|
17 | 33 | | case a: Int => |
---|
18 | 34 | | a |
---|
19 | 35 | | case _ => |
---|
20 | 36 | | 0 |
---|
21 | 37 | | } |
---|
22 | 38 | | balance |
---|
23 | 39 | | } |
---|
24 | 40 | | |
---|
25 | 41 | | |
---|
26 | | - | func getCollateral (publicKey,asset) = if ((asset == "")) |
---|
27 | | - | then { |
---|
28 | | - | let collateral = match getInteger(this, ((("collateral_" + publicKey) + "_Waves") + asset)) { |
---|
29 | | - | case a: Int => |
---|
30 | | - | a |
---|
31 | | - | case _ => |
---|
32 | | - | 0 |
---|
33 | | - | } |
---|
34 | | - | collateral |
---|
35 | | - | } |
---|
36 | | - | else { |
---|
37 | | - | let collateral = match getInteger(this, ((("collateral_" + publicKey) + "_") + asset)) { |
---|
38 | | - | case a: Int => |
---|
39 | | - | a |
---|
40 | | - | case _ => |
---|
41 | | - | 0 |
---|
42 | | - | } |
---|
43 | | - | collateral |
---|
44 | | - | } |
---|
| 42 | + | func getCollateral (publicKey,asset) = { |
---|
| 43 | + | let usedAsset = if ((asset == "")) |
---|
| 44 | + | then "WAVES" |
---|
| 45 | + | else asset |
---|
| 46 | + | let collateral = match getInteger(this, ((("collateral_" + publicKey) + "_") + usedAsset)) { |
---|
| 47 | + | case a: Int => |
---|
| 48 | + | a |
---|
| 49 | + | case _ => |
---|
| 50 | + | 0 |
---|
| 51 | + | } |
---|
| 52 | + | collateral |
---|
| 53 | + | } |
---|
45 | 54 | | |
---|
46 | 55 | | |
---|
47 | 56 | | @Callable(i) |
---|
48 | 57 | | func deposit (amount,asset) = { |
---|
49 | 58 | | let publicKey = toBase58String(i.callerPublicKey) |
---|
50 | | - | let test = if ((asset == "")) |
---|
| 59 | + | let usedAsset = if ((asset == "")) |
---|
51 | 60 | | then "WAVES" |
---|
52 | 61 | | else asset |
---|
53 | | - | let depositAmount = getDepositAmount(publicKey, test) |
---|
| 62 | + | let depositAmount = getDepositAmount(publicKey, usedAsset) |
---|
54 | 63 | | let newDepositAmount = (depositAmount + amount) |
---|
55 | | - | [IntegerEntry(((("deposit_" + publicKey) + "_") + test), newDepositAmount)] |
---|
| 64 | + | [IntegerEntry(((("deposit_" + publicKey) + "_") + usedAsset), newDepositAmount)] |
---|
56 | 65 | | } |
---|
57 | 66 | | |
---|
58 | 67 | | |
---|
59 | 68 | | |
---|
60 | 69 | | @Callable(i) |
---|
61 | 70 | | func depositCollateral (amount,asset) = { |
---|
| 71 | + | let usedAsset = if ((asset == "")) |
---|
| 72 | + | then "WAVES" |
---|
| 73 | + | else asset |
---|
62 | 74 | | let publicKey = toBase58String(i.callerPublicKey) |
---|
63 | | - | let collateralAmount = getCollateral(publicKey, asset) |
---|
| 75 | + | let collateralAmount = getCollateral(publicKey, usedAsset) |
---|
64 | 76 | | let newCollateralAmount = (collateralAmount + amount) |
---|
65 | | - | [IntegerEntry(((("collateral_" + publicKey) + "_") + asset), newCollateralAmount)] |
---|
| 77 | + | if ((0 >= amount)) |
---|
| 78 | + | then throw("Ammount must be bigger than 0") |
---|
| 79 | + | else [IntegerEntry(((("collateral_" + publicKey) + "_") + usedAsset), newCollateralAmount)] |
---|
66 | 80 | | } |
---|
67 | 81 | | |
---|
68 | 82 | | |
---|
69 | 83 | | |
---|
70 | 84 | | @Callable(i) |
---|
71 | 85 | | func borrow (amount,asset) = { |
---|
| 86 | + | let usedAsset = if ((asset == "")) |
---|
| 87 | + | then "WAVES" |
---|
| 88 | + | else asset |
---|
72 | 89 | | let publicKey = toBase58String(i.callerPublicKey) |
---|
73 | | - | let borrowAmount = getBorrowAmount(publicKey, asset) |
---|
74 | | - | let collateral = getCollateral(publicKey, asset) |
---|
| 90 | + | let transactionPublicKey = addressFromPublicKey(i.callerPublicKey) |
---|
| 91 | + | let borrowAmount = getBorrowAmount(publicKey, usedAsset) |
---|
| 92 | + | let collateral = getCollateral(publicKey, usedAsset) |
---|
75 | 93 | | let maxBorrowAmount = ((collateral * 70) / 100) |
---|
76 | 94 | | let newBorrowAmount = (borrowAmount + amount) |
---|
| 95 | + | let usedAssetID = getAssetID(asset) |
---|
77 | 96 | | if ((collateral >= maxBorrowAmount)) |
---|
78 | | - | then [IntegerEntry(((("borrow_" + publicKey) + "_") + asset), newBorrowAmount)] |
---|
| 97 | + | then [IntegerEntry(((("borrow_" + publicKey) + "_") + usedAsset), newBorrowAmount), ScriptTransfer(Address(toBytes(toBase58String(i.callerPublicKey))), amount, toBytes(usedAssetID))] |
---|
79 | 98 | | else throw("Not enough collateral") |
---|
80 | 99 | | } |
---|
81 | 100 | | |
---|
82 | 101 | | |
---|
83 | 102 | | |
---|
84 | 103 | | @Callable(i) |
---|
85 | 104 | | func repay (amount,asset) = { |
---|
| 105 | + | let usedAsset = if ((asset == "")) |
---|
| 106 | + | then "WAVES" |
---|
| 107 | + | else asset |
---|
86 | 108 | | let publicKey = toBase58String(i.callerPublicKey) |
---|
87 | | - | let currentBorr = getBorrowAmount(publicKey, asset) |
---|
| 109 | + | let currentBorr = getBorrowAmount(publicKey, usedAsset) |
---|
88 | 110 | | if ((currentBorr > 0)) |
---|
89 | | - | then [IntegerEntry(((("borrow_" + publicKey) + "_") + asset), (currentBorr - amount))] |
---|
90 | | - | else throw("Nothing to repay") |
---|
| 111 | + | then [IntegerEntry(((("borrow_" + publicKey) + "_") + usedAsset), (currentBorr - amount))] |
---|
| 112 | + | else [IntegerEntry(((("collateral_" + publicKey) + "_") + usedAsset), amount), throw("Nothing to repay, your Ammount has been deposit as Collateral")] |
---|
91 | 113 | | } |
---|
92 | 114 | | |
---|
93 | 115 | | |
---|
94 | 116 | | |
---|
95 | 117 | | @Callable(i) |
---|
96 | 118 | | func withdraw (amount,asset) = { |
---|
| 119 | + | let usedAsset = if ((asset == "")) |
---|
| 120 | + | then "WAVES" |
---|
| 121 | + | else asset |
---|
97 | 122 | | let publicKey = toBase58String(i.callerPublicKey) |
---|
98 | | - | let currentDep = getDepositAmount(publicKey, asset) |
---|
99 | | - | if ((currentDep > 0)) |
---|
100 | | - | then [IntegerEntry(((("deposit_" + publicKey) + "_") + asset), (currentDep - amount))] |
---|
101 | | - | else throw("Nothing to withdraw") |
---|
| 123 | + | let transactionPublicKey = addressFromPublicKey(i.callerPublicKey) |
---|
| 124 | + | let currentDep = getDepositAmount(publicKey, usedAsset) |
---|
| 125 | + | if ((0 > amount)) |
---|
| 126 | + | then throw("Can't withdraw negative amount") |
---|
| 127 | + | else if (if ((currentDep > 0)) |
---|
| 128 | + | then (currentDep >= amount) |
---|
| 129 | + | else false) |
---|
| 130 | + | then [IntegerEntry(((("deposit_" + publicKey) + "_") + usedAsset), (currentDep - amount)), ScriptTransfer(transactionPublicKey, amount, i.feeAssetId)] |
---|
| 131 | + | else throw("Nothing to withdraw") |
---|
102 | 132 | | } |
---|
103 | 133 | | |
---|
104 | 134 | | |
---|
105 | 135 | | @Verifier(tx) |
---|
106 | 136 | | func verify () = match tx { |
---|
107 | 137 | | case _: DataTransaction => |
---|
108 | 138 | | true |
---|
109 | 139 | | case _: SetScriptTransaction => |
---|
110 | 140 | | true |
---|
111 | 141 | | case _ => |
---|
112 | 142 | | true |
---|
113 | 143 | | } |
---|
114 | 144 | | |
---|