1 | | - | {-# STDLIB_VERSION 7 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let separator = "__" |
---|
5 | | - | |
---|
6 | | - | let wavesString = "WAVES" |
---|
7 | | - | |
---|
8 | | - | let contractFilename = "meme_im_factory.ride" |
---|
9 | | - | |
---|
10 | | - | let kPriceAsset = "price__asset" |
---|
11 | | - | |
---|
12 | | - | let kShutdown = "shutdown__flag" |
---|
13 | | - | |
---|
14 | | - | let shutdown = valueOrElse(getBoolean(kShutdown), false) |
---|
15 | | - | |
---|
16 | | - | func wrapErr (s) = ((contractFilename + ": ") + s) |
---|
17 | | - | |
---|
18 | | - | |
---|
19 | | - | func throwErr (s) = throw(wrapErr(s)) |
---|
20 | | - | |
---|
21 | | - | |
---|
22 | | - | func validateAddress (address) = isDefined(addressFromString(address)) |
---|
23 | | - | |
---|
24 | | - | |
---|
25 | | - | let kCalculatorAddress = "calculator__address" |
---|
26 | | - | |
---|
27 | | - | let calculatorAddressOption = match getString(this, kCalculatorAddress) { |
---|
28 | | - | case s: String => |
---|
29 | | - | addressFromString(s) |
---|
30 | | - | case _: Unit => |
---|
31 | | - | unit |
---|
32 | | - | case _ => |
---|
33 | | - | throw("Match error") |
---|
34 | | - | } |
---|
35 | | - | |
---|
36 | | - | let calculatorAddress = valueOrErrorMessage(calculatorAddressOption, wrapErr("invalid calculator address")) |
---|
37 | | - | |
---|
38 | | - | func mustAddress (i,address) = if ((i.caller == address)) |
---|
39 | | - | then true |
---|
40 | | - | else throwErr("permission denied") |
---|
41 | | - | |
---|
42 | | - | |
---|
43 | | - | func mustThis (i) = mustAddress(i, this) |
---|
44 | | - | |
---|
45 | | - | |
---|
46 | | - | func mustCalculator (i) = mustAddress(i, calculatorAddress) |
---|
47 | | - | |
---|
48 | | - | |
---|
49 | | - | func parseAssetId (input) = if ((input == wavesString)) |
---|
50 | | - | then unit |
---|
51 | | - | else fromBase58String(input) |
---|
52 | | - | |
---|
53 | | - | |
---|
54 | | - | func assetIdToString (input) = if ((input == unit)) |
---|
55 | | - | then wavesString |
---|
56 | | - | else toBase58String(value(input)) |
---|
57 | | - | |
---|
58 | | - | |
---|
59 | | - | @Callable(i) |
---|
60 | | - | func init (calculatorAddressStr) = { |
---|
61 | | - | let checkCaller = mustThis(i) |
---|
62 | | - | if ((checkCaller == checkCaller)) |
---|
63 | | - | then $Tuple2([StringEntry(kCalculatorAddress, calculatorAddressStr), StringEntry(kPriceAsset, wavesString)], unit) |
---|
64 | | - | else throw("Strict value is not equal to itself.") |
---|
65 | | - | } |
---|
66 | | - | |
---|
67 | | - | |
---|
68 | | - | |
---|
69 | | - | @Callable(i) |
---|
70 | | - | func stringEntry (key,val) = if (if (!(shutdown)) |
---|
71 | | - | then mustCalculator(i) |
---|
72 | | - | else false) |
---|
73 | | - | then $Tuple2([StringEntry(key, val)], key) |
---|
74 | | - | else throwErr("not allowed") |
---|
75 | | - | |
---|
76 | | - | |
---|
77 | | - | |
---|
78 | | - | @Callable(i) |
---|
79 | | - | func integerEntry (key,val) = if (if (!(shutdown)) |
---|
80 | | - | then mustCalculator(i) |
---|
81 | | - | else false) |
---|
82 | | - | then $Tuple2([IntegerEntry(key, val)], key) |
---|
83 | | - | else throwErr("not allowed") |
---|
84 | | - | |
---|
85 | | - | |
---|
86 | | - | |
---|
87 | | - | @Callable(i) |
---|
88 | | - | func booleanEntry (key,val) = if (if (!(shutdown)) |
---|
89 | | - | then mustCalculator(i) |
---|
90 | | - | else false) |
---|
91 | | - | then $Tuple2([BooleanEntry(key, val)], key) |
---|
92 | | - | else throwErr("not allowed") |
---|
93 | | - | |
---|
94 | | - | |
---|
95 | | - | |
---|
96 | | - | @Callable(i) |
---|
97 | | - | func binaryEntry (key,val) = if (if (!(shutdown)) |
---|
98 | | - | then mustCalculator(i) |
---|
99 | | - | else false) |
---|
100 | | - | then $Tuple2([BinaryEntry(key, val)], key) |
---|
101 | | - | else throwErr("not allowed") |
---|
102 | | - | |
---|
103 | | - | |
---|
104 | | - | |
---|
105 | | - | @Callable(i) |
---|
106 | | - | func deleteEntry (key) = if (if (!(shutdown)) |
---|
107 | | - | then mustCalculator(i) |
---|
108 | | - | else false) |
---|
109 | | - | then $Tuple2([DeleteEntry(key)], key) |
---|
110 | | - | else throwErr("not allowed") |
---|
111 | | - | |
---|
112 | | - | |
---|
113 | | - | |
---|
114 | | - | @Callable(i) |
---|
115 | | - | func reissue (assetId,amount,reissuable) = if (if (!(shutdown)) |
---|
116 | | - | then mustCalculator(i) |
---|
117 | | - | else false) |
---|
118 | | - | then $Tuple2([Reissue(assetId, amount, reissuable)], amount) |
---|
119 | | - | else throwErr("not allowed") |
---|
120 | | - | |
---|
121 | | - | |
---|
122 | | - | |
---|
123 | | - | @Callable(i) |
---|
124 | | - | func burn (assetId,amount) = if (if (!(shutdown)) |
---|
125 | | - | then mustCalculator(i) |
---|
126 | | - | else false) |
---|
127 | | - | then $Tuple2([Burn(assetId, amount)], amount) |
---|
128 | | - | else throwErr("not allowed") |
---|
129 | | - | |
---|
130 | | - | |
---|
131 | | - | |
---|
132 | | - | @Callable(i) |
---|
133 | | - | func transferAsset (recipientBytes,amount,assetId) = if (if (!(shutdown)) |
---|
134 | | - | then mustCalculator(i) |
---|
135 | | - | else false) |
---|
136 | | - | then $Tuple2([ScriptTransfer(Address(recipientBytes), amount, assetId)], amount) |
---|
137 | | - | else throwErr("not allowed") |
---|
138 | | - | |
---|
139 | | - | |
---|
140 | | - | |
---|
141 | | - | @Callable(i) |
---|
142 | | - | func transferAssets (recipientBytes,assetsList,amountsList) = if (if (!(shutdown)) |
---|
143 | | - | then mustCalculator(i) |
---|
144 | | - | else false) |
---|
145 | | - | then { |
---|
146 | | - | func addNewTransfer (acc,nextAssetId) = { |
---|
147 | | - | let $t031863210 = acc |
---|
148 | | - | let transfers = $t031863210._1 |
---|
149 | | - | let j = $t031863210._2 |
---|
150 | | - | let newTransfer = ScriptTransfer(Address(recipientBytes), amountsList[j], assetsList[j]) |
---|
151 | | - | let updatedTransfers = (transfers :+ newTransfer) |
---|
152 | | - | $Tuple2(updatedTransfers, (j + 1)) |
---|
153 | | - | } |
---|
154 | | - | |
---|
155 | | - | let $t034363517 = { |
---|
156 | | - | let $l = assetsList |
---|
157 | | - | let $s = size($l) |
---|
158 | | - | let $acc0 = $Tuple2(nil, 0) |
---|
159 | | - | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
160 | | - | then $a |
---|
161 | | - | else addNewTransfer($a, $l[$i]) |
---|
162 | | - | |
---|
163 | | - | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
164 | | - | then $a |
---|
165 | | - | else throw("List size exceeds 10") |
---|
166 | | - | |
---|
167 | | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) |
---|
168 | | - | } |
---|
169 | | - | let assetsTransfers = $t034363517._1 |
---|
170 | | - | let _lastIndex = $t034363517._2 |
---|
171 | | - | $Tuple2(assetsTransfers, unit) |
---|
172 | | - | } |
---|
173 | | - | else throwErr("not allowed") |
---|
174 | | - | |
---|
175 | | - | |
---|
176 | | - | |
---|
177 | | - | @Callable(i) |
---|
178 | | - | func transferWaves (recipientBytes,amount) = if (if (!(shutdown)) |
---|
179 | | - | then mustCalculator(i) |
---|
180 | | - | else false) |
---|
181 | | - | then $Tuple2([ScriptTransfer(Address(recipientBytes), amount, unit)], amount) |
---|
182 | | - | else throwErr("not allowed") |
---|
183 | | - | |
---|
184 | | - | |
---|
185 | | - | |
---|
186 | | - | @Callable(i) |
---|
187 | | - | func call (function,args) = { |
---|
188 | | - | let cleanPayments = if ((i.callerPublicKey == base58'11111111111111111111111111111111')) |
---|
189 | | - | then nil |
---|
190 | | - | else i.payments |
---|
191 | | - | let result = reentrantInvoke(calculatorAddress, function, [i.callerPublicKey, args], cleanPayments) |
---|
192 | | - | $Tuple2(nil, result) |
---|
193 | | - | } |
---|
194 | | - | |
---|
195 | | - | |
---|
| 1 | + | # no script |
---|