tx · 7w79SMLQzy6sU9UA4mqF75bPHBW8LhiMLn3htTSkKVLp 3N3nfqFcxXfd3T18V9icDdh58MJ9wQ2k2xx: -0.00700000 Waves 2023.08.05 16:55 [2697375] smart account 3N3nfqFcxXfd3T18V9icDdh58MJ9wQ2k2xx > SELF 0.00000000 Waves
{ "type": 13, "id": "7w79SMLQzy6sU9UA4mqF75bPHBW8LhiMLn3htTSkKVLp", "fee": 700000, "feeAssetId": null, "timestamp": 1691243766344, "version": 2, "chainId": 84, "sender": "3N3nfqFcxXfd3T18V9icDdh58MJ9wQ2k2xx", "senderPublicKey": "UGqkWsCpv7xRVXkQRXyLd6pWPDtYGXmPip7FxSd1pAu", "proofs": [ "MSukrgCURuZHdQ76ZmV5QwmiNothqZvL7c6c53L6aJva4rFftZc4nQhNuWAbJsnPMDdu1i8fAV9txffgJkNxFVr" ], "script": "base64:BgIMCAISBgoEAQEBARIAJwEUa2V5U3Rha2VkRHVja0J5T3duZXIBCW93bmVyQWRkcgkArAICAhJzdGFrZWREdWNrQnlPd25lcl8FCW93bmVyQWRkcgEVa2V5VG91clN0YXRpY0RhdGFCeUlkAQN0SWQJAKwCAgIWJXMlZF9fdG91clN0YXRpY0RhdGFfXwkApAMBBQN0SWQBFmtleVRvdXJEeW5hbWljRGF0YUJ5SWQBA3RJZAkArAICAhclcyVkX190b3VyRHluYW1pY0RhdGFfXwkApAMBBQN0SWQBF2tleUFsbFJlZ2lzdHJhbmRzQnlUb3VyAQN0SWQJAKwCAgIWJXMlZF9fYWxsUmVnaXN0cmFuZHNfXwkApAMBBQN0SWQAE3RTdGF0aWNSZWdpc3RlckNvc3QAAgAMdFN0YXRpY1N0YXJ0AAUACnRTdGF0aWNFbmQABgAOdER5bmFtaWNTdGF0dXMAAQAPdER5bmFtaWNXaW5EdWNrAAIAEXREeW5hbWljV2luUmVzdWx0AAMAFXREeW5hbWljVG90YWxSZWdDb3VudAAEABV0RHluYW1pY1RvdGFsQXR0ZW1wdHMABQAFY2hhaW4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GVhbkVudHJ5AgkBHGtleUlzUmVnaXN0ZXJlZEJ5VG91ckFuZER1Y2sCBQZsYXN0SWQFC2R1Y2tBc3NldElkBgkAzAgCCQELU3RyaW5nRW50cnkCCQEXa2V5QWxsUmVnaXN0cmFuZHNCeVRvdXIBBQZsYXN0SWQJALsJAgkAzQgCBQdyZWdMaXN0BQtkdWNrQXNzZXRJZAIBXwkAzAgCCQELU3RyaW5nRW50cnkCCQEWa2V5VG91ckR5bmFtaWNEYXRhQnlJZAEFBmxhc3RJZAUSdXBkYXRlZER5bmFtaWNEYXRhBQNuaWwFDHByb2xvZ1Jlc3VsdACOCvX4", "height": 2697375, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 84D41qbBENBSPDqhHaLyHpM4x43pTidvbitRrovfyF9V Next: Af8Ya79QSUcKfzfyqHyQrhjgdpXxCb1q9qWUkkmCCmvF Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | func keyStakedDuckByOwner (ownerAddr) = ("stakedDuckByOwner_" + ownerAddr) | |
5 | + | ||
6 | + | ||
7 | + | func keyTourStaticDataById (tId) = ("%s%d__tourStaticData__" + toString(tId)) | |
8 | + | ||
9 | + | ||
10 | + | func keyTourDynamicDataById (tId) = ("%s%d__tourDynamicData__" + toString(tId)) | |
11 | + | ||
12 | + | ||
13 | + | func keyAllRegistrandsByTour (tId) = ("%s%d__allRegistrands__" + toString(tId)) | |
14 | + | ||
15 | + | ||
16 | + | let tStaticRegisterCost = 2 | |
17 | + | ||
18 | + | let tStaticStart = 5 | |
19 | + | ||
20 | + | let tStaticEnd = 6 | |
21 | + | ||
22 | + | let tDynamicStatus = 1 | |
23 | + | ||
24 | + | let tDynamicWinDuck = 2 | |
25 | + | ||
26 | + | let tDynamicWinResult = 3 | |
27 | + | ||
28 | + | let tDynamicTotalRegCount = 4 | |
29 | + | ||
30 | + | let tDynamicTotalAttempts = 5 | |
31 | + | ||
4 | 32 | let chain = take(drop(this.bytes, 1), 1) | |
33 | + | ||
34 | + | let defaultRestAddressStr = match chain { | |
35 | + | case _ => | |
36 | + | if ((base58'2W' == $match0)) | |
37 | + | then "3PQCuvFbvh4LkPUnrnU1z3jnbA1p9m3WNhv" | |
38 | + | else if ((base58'2T' == $match0)) | |
39 | + | then "3MumkGGztCKAXpWDqxkddofqXSUbqQkvSJy" | |
40 | + | else throw("Unknown chain") | |
41 | + | } | |
5 | 42 | ||
6 | 43 | let SEP = "__" | |
7 | 44 | ||
45 | + | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
46 | + | ||
47 | + | ||
48 | + | let IdxCfgStakingDapp = 1 | |
49 | + | ||
50 | + | let IdxCfgWlgDapp = 4 | |
51 | + | ||
52 | + | func keyRestCfg () = "%s__restConfig" | |
53 | + | ||
54 | + | ||
55 | + | func keyRestAddress () = "%s__restAddr" | |
56 | + | ||
57 | + | ||
58 | + | func readRestCfgOrFail (rest) = split_4C(getStringOrFail(rest, keyRestCfg()), SEP) | |
59 | + | ||
60 | + | ||
61 | + | func getContractAddressOrFail (restCfg,idx) = valueOrErrorMessage(addressFromString(restCfg[idx]), ("Rest cfg doesn't contain address at index " + toString(idx))) | |
62 | + | ||
63 | + | ||
64 | + | let restContract = addressFromStringValue(valueOrElse(getString(this, keyRestAddress()), defaultRestAddressStr)) | |
65 | + | ||
66 | + | let restCfg = readRestCfgOrFail(restContract) | |
67 | + | ||
68 | + | let stakingContract = getContractAddressOrFail(restCfg, IdxCfgStakingDapp) | |
69 | + | ||
70 | + | let wlgContract = getContractAddressOrFail(restCfg, IdxCfgWlgDapp) | |
71 | + | ||
72 | + | let wlgAssetIdKey = "wlg_assetId" | |
73 | + | ||
74 | + | let wlgAssetId = valueOrErrorMessage(getBinary(wlgContract, wlgAssetIdKey), "Not initialized yet") | |
75 | + | ||
76 | + | func asInt (v) = match v { | |
77 | + | case n: Int => | |
78 | + | n | |
79 | + | case _ => | |
80 | + | throw("fail to cast into Int") | |
81 | + | } | |
82 | + | ||
83 | + | ||
84 | + | func fixedPoint (val,decimals) = { | |
85 | + | let tenPow = pow(10, 0, decimals, 0, 0, DOWN) | |
86 | + | let lowPart = toString((val % tenPow)) | |
87 | + | let zeroes = drop(toString(tenPow), (1 + size(lowPart))) | |
88 | + | (((toString((val / tenPow)) + ".") + zeroes) + lowPart) | |
89 | + | } | |
90 | + | ||
91 | + | ||
8 | 92 | let MAXTOURNAMENTLENGTH = 432000000 | |
93 | + | ||
94 | + | let HOUR = 3600000 | |
9 | 95 | ||
10 | 96 | let adminsList = [toString(this), match chain { | |
11 | 97 | case _ => | |
16 | 102 | else throw("Unknown chain") | |
17 | 103 | }] | |
18 | 104 | ||
19 | - | let tDynamicStatus = 1 | |
20 | - | ||
21 | 105 | let lastTourIdKey = "%s__lastTourId" | |
22 | 106 | ||
23 | - | func | |
107 | + | func keyLastRegisteredTourByDuck (duckAssetId) = ("%s%s__lastRegisteredTourByDuck__" + duckAssetId) | |
24 | 108 | ||
25 | 109 | ||
26 | - | func | |
110 | + | func keyIsRegisteredByTourAndDuck (tId,duckAssetId) = makeString(["%s%d%s__isRegisteredByTourAndDuck", toString(tId), duckAssetId], SEP) | |
27 | 111 | ||
28 | 112 | ||
29 | 113 | func staticData (txId,registerCost,attemptCost,creationTime,startTime,endTime) = makeString(["%s%d%d%d%d%d", txId, toString(registerCost), toString(attemptCost), toString(creationTime), toString(startTime), toString(endTime)], SEP) | |
30 | 114 | ||
31 | 115 | ||
32 | 116 | func dynamicData (status,winDuck,winResult,totalRegs,totalAttempts) = makeString(["%s%s%d%d%d", status, winDuck, toString(winResult), toString(totalRegs), toString(totalAttempts)], SEP) | |
117 | + | ||
118 | + | ||
119 | + | func prolog () = asInt(invoke(stakingContract, "saveLastTx", nil, nil)) | |
33 | 120 | ||
34 | 121 | ||
35 | 122 | @Callable(i) | |
42 | 129 | let tId = if (isDefined(lastId)) | |
43 | 130 | then { | |
44 | 131 | let lastTourId = value(lastId) | |
45 | - | let dynamic = valueOrErrorMessage(getString(keyTourDynamicDataById(lastTourId)), (("Error reading tournament " + toString(lastTourId)) + " | |
132 | + | let dynamic = valueOrErrorMessage(getString(keyTourDynamicDataById(lastTourId)), (("Error reading tournament " + toString(lastTourId)) + " data")) | |
46 | 133 | let status = split(dynamic, SEP)[tDynamicStatus] | |
47 | 134 | if ((status != "ARCHIVED")) | |
48 | 135 | then throw(("Current tournement is not completed, status=" + status)) | |
60 | 147 | then true | |
61 | 148 | else (0 >= attemptCost)) | |
62 | 149 | then throw(((("Cost should be positive, but passed " + toString(registerCost)) + " and ") + toString(attemptCost))) | |
63 | - | else $Tuple2([IntegerEntry(lastTourIdKey, tId), StringEntry(keyTourStaticDataById(tId), staticData(toBase58String(i.transactionId), registerCost, attemptCost, now, startTime, endTime)), StringEntry(keyTourDynamicDataById(tId), dynamicData("CREATED", "", 0, 0, 0))], 0) | |
150 | + | else $Tuple2([IntegerEntry(lastTourIdKey, tId), StringEntry(keyTourStaticDataById(tId), staticData(toBase58String(i.transactionId), registerCost, attemptCost, now, startTime, endTime)), StringEntry(keyTourDynamicDataById(tId), dynamicData("CREATED", "", 0, 0, 0))], tId) | |
151 | + | } | |
152 | + | } | |
153 | + | ||
154 | + | ||
155 | + | ||
156 | + | @Callable(i) | |
157 | + | func register () = { | |
158 | + | let prologResult = prolog() | |
159 | + | if ((size(i.payments) != 1)) | |
160 | + | then throw("exactly 1 payment must be attached") | |
161 | + | else { | |
162 | + | let pmt = i.payments[0] | |
163 | + | let wlgAmt = pmt.amount | |
164 | + | let pmtAssetId = valueOrErrorMessage(pmt.assetId, "WLGOLD payments only!") | |
165 | + | if ((pmtAssetId != wlgAssetId)) | |
166 | + | then throw("WLGOLD payments only!") | |
167 | + | else { | |
168 | + | let lastId = valueOrErrorMessage(getInteger(lastTourIdKey), "No active tournaments") | |
169 | + | let now = lastBlock.timestamp | |
170 | + | let static = split(valueOrErrorMessage(getString(keyTourStaticDataById(lastId)), (("Error reading tournament " + toString(lastId)) + " data")), SEP) | |
171 | + | let dynamic = split(valueOrErrorMessage(getString(keyTourDynamicDataById(lastId)), (("Error reading tournament " + toString(lastId)) + " data")), SEP) | |
172 | + | let status = dynamic[tDynamicStatus] | |
173 | + | if (!(if (if (if ((status == "CREATED")) | |
174 | + | then (now > parseIntValue(static[tStaticStart])) | |
175 | + | else false) | |
176 | + | then ((parseIntValue(static[tStaticEnd]) - HOUR) > now) | |
177 | + | else false) | |
178 | + | then true | |
179 | + | else if ((status == "INPROGRESS")) | |
180 | + | then ((parseIntValue(static[tStaticEnd]) - HOUR) > now) | |
181 | + | else false)) | |
182 | + | then throw("Cannot register now") | |
183 | + | else { | |
184 | + | let regCost = parseIntValue(static[tStaticRegisterCost]) | |
185 | + | if ((wlgAmt != regCost)) | |
186 | + | then throw((("Need payment of " + fixedPoint(regCost, 8)) + " WLGOLD")) | |
187 | + | else { | |
188 | + | let addr = toString(i.originCaller) | |
189 | + | let duckAssetId = valueOrErrorMessage(getString(stakingContract, keyStakedDuckByOwner(addr)), "You don't have a duck staked") | |
190 | + | let oldRegistrands = valueOrElse(getString(keyAllRegistrandsByTour(lastId)), "") | |
191 | + | let regList = if ((oldRegistrands == "")) | |
192 | + | then nil | |
193 | + | else split_51C(oldRegistrands, "_") | |
194 | + | if (if (valueOrElse(getBoolean(keyIsRegisteredByTourAndDuck(lastId, duckAssetId)), false)) | |
195 | + | then true | |
196 | + | else containsElement(regList, duckAssetId)) | |
197 | + | then throw(((("Your duck " + duckAssetId) + " is already registered at tournament ") + toString(lastId))) | |
198 | + | else { | |
199 | + | let updatedDynamicData = dynamicData("INPROGRESS", dynamic[tDynamicWinDuck], parseIntValue(dynamic[tDynamicWinResult]), (parseIntValue(dynamic[tDynamicTotalRegCount]) + 1), parseIntValue(dynamic[tDynamicTotalAttempts])) | |
200 | + | $Tuple2([IntegerEntry(keyLastRegisteredTourByDuck(duckAssetId), lastId), BooleanEntry(keyIsRegisteredByTourAndDuck(lastId, duckAssetId), true), StringEntry(keyAllRegistrandsByTour(lastId), makeString_11C((regList :+ duckAssetId), "_")), StringEntry(keyTourDynamicDataById(lastId), updatedDynamicData)], prologResult) | |
201 | + | } | |
202 | + | } | |
203 | + | } | |
204 | + | } | |
64 | 205 | } | |
65 | 206 | } | |
66 | 207 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | func keyStakedDuckByOwner (ownerAddr) = ("stakedDuckByOwner_" + ownerAddr) | |
5 | + | ||
6 | + | ||
7 | + | func keyTourStaticDataById (tId) = ("%s%d__tourStaticData__" + toString(tId)) | |
8 | + | ||
9 | + | ||
10 | + | func keyTourDynamicDataById (tId) = ("%s%d__tourDynamicData__" + toString(tId)) | |
11 | + | ||
12 | + | ||
13 | + | func keyAllRegistrandsByTour (tId) = ("%s%d__allRegistrands__" + toString(tId)) | |
14 | + | ||
15 | + | ||
16 | + | let tStaticRegisterCost = 2 | |
17 | + | ||
18 | + | let tStaticStart = 5 | |
19 | + | ||
20 | + | let tStaticEnd = 6 | |
21 | + | ||
22 | + | let tDynamicStatus = 1 | |
23 | + | ||
24 | + | let tDynamicWinDuck = 2 | |
25 | + | ||
26 | + | let tDynamicWinResult = 3 | |
27 | + | ||
28 | + | let tDynamicTotalRegCount = 4 | |
29 | + | ||
30 | + | let tDynamicTotalAttempts = 5 | |
31 | + | ||
4 | 32 | let chain = take(drop(this.bytes, 1), 1) | |
33 | + | ||
34 | + | let defaultRestAddressStr = match chain { | |
35 | + | case _ => | |
36 | + | if ((base58'2W' == $match0)) | |
37 | + | then "3PQCuvFbvh4LkPUnrnU1z3jnbA1p9m3WNhv" | |
38 | + | else if ((base58'2T' == $match0)) | |
39 | + | then "3MumkGGztCKAXpWDqxkddofqXSUbqQkvSJy" | |
40 | + | else throw("Unknown chain") | |
41 | + | } | |
5 | 42 | ||
6 | 43 | let SEP = "__" | |
7 | 44 | ||
45 | + | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
46 | + | ||
47 | + | ||
48 | + | let IdxCfgStakingDapp = 1 | |
49 | + | ||
50 | + | let IdxCfgWlgDapp = 4 | |
51 | + | ||
52 | + | func keyRestCfg () = "%s__restConfig" | |
53 | + | ||
54 | + | ||
55 | + | func keyRestAddress () = "%s__restAddr" | |
56 | + | ||
57 | + | ||
58 | + | func readRestCfgOrFail (rest) = split_4C(getStringOrFail(rest, keyRestCfg()), SEP) | |
59 | + | ||
60 | + | ||
61 | + | func getContractAddressOrFail (restCfg,idx) = valueOrErrorMessage(addressFromString(restCfg[idx]), ("Rest cfg doesn't contain address at index " + toString(idx))) | |
62 | + | ||
63 | + | ||
64 | + | let restContract = addressFromStringValue(valueOrElse(getString(this, keyRestAddress()), defaultRestAddressStr)) | |
65 | + | ||
66 | + | let restCfg = readRestCfgOrFail(restContract) | |
67 | + | ||
68 | + | let stakingContract = getContractAddressOrFail(restCfg, IdxCfgStakingDapp) | |
69 | + | ||
70 | + | let wlgContract = getContractAddressOrFail(restCfg, IdxCfgWlgDapp) | |
71 | + | ||
72 | + | let wlgAssetIdKey = "wlg_assetId" | |
73 | + | ||
74 | + | let wlgAssetId = valueOrErrorMessage(getBinary(wlgContract, wlgAssetIdKey), "Not initialized yet") | |
75 | + | ||
76 | + | func asInt (v) = match v { | |
77 | + | case n: Int => | |
78 | + | n | |
79 | + | case _ => | |
80 | + | throw("fail to cast into Int") | |
81 | + | } | |
82 | + | ||
83 | + | ||
84 | + | func fixedPoint (val,decimals) = { | |
85 | + | let tenPow = pow(10, 0, decimals, 0, 0, DOWN) | |
86 | + | let lowPart = toString((val % tenPow)) | |
87 | + | let zeroes = drop(toString(tenPow), (1 + size(lowPart))) | |
88 | + | (((toString((val / tenPow)) + ".") + zeroes) + lowPart) | |
89 | + | } | |
90 | + | ||
91 | + | ||
8 | 92 | let MAXTOURNAMENTLENGTH = 432000000 | |
93 | + | ||
94 | + | let HOUR = 3600000 | |
9 | 95 | ||
10 | 96 | let adminsList = [toString(this), match chain { | |
11 | 97 | case _ => | |
12 | 98 | if ((base58'2W' == $match0)) | |
13 | 99 | then "3PEe2RELUHCFCBsmSCNcBJ8N3URLVQende7" | |
14 | 100 | else if ((base58'2T' == $match0)) | |
15 | 101 | then "3MtBgJTaLxPB3C7UJD1UE8qjkHthfKvFQYY" | |
16 | 102 | else throw("Unknown chain") | |
17 | 103 | }] | |
18 | 104 | ||
19 | - | let tDynamicStatus = 1 | |
20 | - | ||
21 | 105 | let lastTourIdKey = "%s__lastTourId" | |
22 | 106 | ||
23 | - | func | |
107 | + | func keyLastRegisteredTourByDuck (duckAssetId) = ("%s%s__lastRegisteredTourByDuck__" + duckAssetId) | |
24 | 108 | ||
25 | 109 | ||
26 | - | func | |
110 | + | func keyIsRegisteredByTourAndDuck (tId,duckAssetId) = makeString(["%s%d%s__isRegisteredByTourAndDuck", toString(tId), duckAssetId], SEP) | |
27 | 111 | ||
28 | 112 | ||
29 | 113 | func staticData (txId,registerCost,attemptCost,creationTime,startTime,endTime) = makeString(["%s%d%d%d%d%d", txId, toString(registerCost), toString(attemptCost), toString(creationTime), toString(startTime), toString(endTime)], SEP) | |
30 | 114 | ||
31 | 115 | ||
32 | 116 | func dynamicData (status,winDuck,winResult,totalRegs,totalAttempts) = makeString(["%s%s%d%d%d", status, winDuck, toString(winResult), toString(totalRegs), toString(totalAttempts)], SEP) | |
117 | + | ||
118 | + | ||
119 | + | func prolog () = asInt(invoke(stakingContract, "saveLastTx", nil, nil)) | |
33 | 120 | ||
34 | 121 | ||
35 | 122 | @Callable(i) | |
36 | 123 | func createTournament (startTime,endTime,registerCost,attemptCost) = { | |
37 | 124 | let caller = toString(i.caller) | |
38 | 125 | if (!(containsElement(adminsList, caller))) | |
39 | 126 | then throw("Permission denied") | |
40 | 127 | else { | |
41 | 128 | let lastId = getInteger(lastTourIdKey) | |
42 | 129 | let tId = if (isDefined(lastId)) | |
43 | 130 | then { | |
44 | 131 | let lastTourId = value(lastId) | |
45 | - | let dynamic = valueOrErrorMessage(getString(keyTourDynamicDataById(lastTourId)), (("Error reading tournament " + toString(lastTourId)) + " | |
132 | + | let dynamic = valueOrErrorMessage(getString(keyTourDynamicDataById(lastTourId)), (("Error reading tournament " + toString(lastTourId)) + " data")) | |
46 | 133 | let status = split(dynamic, SEP)[tDynamicStatus] | |
47 | 134 | if ((status != "ARCHIVED")) | |
48 | 135 | then throw(("Current tournement is not completed, status=" + status)) | |
49 | 136 | else (lastTourId + 1) | |
50 | 137 | } | |
51 | 138 | else 1 | |
52 | 139 | let now = lastBlock.timestamp | |
53 | 140 | if ((now > startTime)) | |
54 | 141 | then throw(((("startTime=" + toString(startTime)) + " < creationTime=") + toString(now))) | |
55 | 142 | else if ((startTime > endTime)) | |
56 | 143 | then throw(((("endTime=" + toString(endTime)) + " < startTime=") + toString(startTime))) | |
57 | 144 | else if (((endTime - startTime) > MAXTOURNAMENTLENGTH)) | |
58 | 145 | then throw(((("Tournament period exceeds max: " + toString((endTime - startTime))) + " > ") + toString(MAXTOURNAMENTLENGTH))) | |
59 | 146 | else if (if ((0 >= registerCost)) | |
60 | 147 | then true | |
61 | 148 | else (0 >= attemptCost)) | |
62 | 149 | then throw(((("Cost should be positive, but passed " + toString(registerCost)) + " and ") + toString(attemptCost))) | |
63 | - | else $Tuple2([IntegerEntry(lastTourIdKey, tId), StringEntry(keyTourStaticDataById(tId), staticData(toBase58String(i.transactionId), registerCost, attemptCost, now, startTime, endTime)), StringEntry(keyTourDynamicDataById(tId), dynamicData("CREATED", "", 0, 0, 0))], 0) | |
150 | + | else $Tuple2([IntegerEntry(lastTourIdKey, tId), StringEntry(keyTourStaticDataById(tId), staticData(toBase58String(i.transactionId), registerCost, attemptCost, now, startTime, endTime)), StringEntry(keyTourDynamicDataById(tId), dynamicData("CREATED", "", 0, 0, 0))], tId) | |
151 | + | } | |
152 | + | } | |
153 | + | ||
154 | + | ||
155 | + | ||
156 | + | @Callable(i) | |
157 | + | func register () = { | |
158 | + | let prologResult = prolog() | |
159 | + | if ((size(i.payments) != 1)) | |
160 | + | then throw("exactly 1 payment must be attached") | |
161 | + | else { | |
162 | + | let pmt = i.payments[0] | |
163 | + | let wlgAmt = pmt.amount | |
164 | + | let pmtAssetId = valueOrErrorMessage(pmt.assetId, "WLGOLD payments only!") | |
165 | + | if ((pmtAssetId != wlgAssetId)) | |
166 | + | then throw("WLGOLD payments only!") | |
167 | + | else { | |
168 | + | let lastId = valueOrErrorMessage(getInteger(lastTourIdKey), "No active tournaments") | |
169 | + | let now = lastBlock.timestamp | |
170 | + | let static = split(valueOrErrorMessage(getString(keyTourStaticDataById(lastId)), (("Error reading tournament " + toString(lastId)) + " data")), SEP) | |
171 | + | let dynamic = split(valueOrErrorMessage(getString(keyTourDynamicDataById(lastId)), (("Error reading tournament " + toString(lastId)) + " data")), SEP) | |
172 | + | let status = dynamic[tDynamicStatus] | |
173 | + | if (!(if (if (if ((status == "CREATED")) | |
174 | + | then (now > parseIntValue(static[tStaticStart])) | |
175 | + | else false) | |
176 | + | then ((parseIntValue(static[tStaticEnd]) - HOUR) > now) | |
177 | + | else false) | |
178 | + | then true | |
179 | + | else if ((status == "INPROGRESS")) | |
180 | + | then ((parseIntValue(static[tStaticEnd]) - HOUR) > now) | |
181 | + | else false)) | |
182 | + | then throw("Cannot register now") | |
183 | + | else { | |
184 | + | let regCost = parseIntValue(static[tStaticRegisterCost]) | |
185 | + | if ((wlgAmt != regCost)) | |
186 | + | then throw((("Need payment of " + fixedPoint(regCost, 8)) + " WLGOLD")) | |
187 | + | else { | |
188 | + | let addr = toString(i.originCaller) | |
189 | + | let duckAssetId = valueOrErrorMessage(getString(stakingContract, keyStakedDuckByOwner(addr)), "You don't have a duck staked") | |
190 | + | let oldRegistrands = valueOrElse(getString(keyAllRegistrandsByTour(lastId)), "") | |
191 | + | let regList = if ((oldRegistrands == "")) | |
192 | + | then nil | |
193 | + | else split_51C(oldRegistrands, "_") | |
194 | + | if (if (valueOrElse(getBoolean(keyIsRegisteredByTourAndDuck(lastId, duckAssetId)), false)) | |
195 | + | then true | |
196 | + | else containsElement(regList, duckAssetId)) | |
197 | + | then throw(((("Your duck " + duckAssetId) + " is already registered at tournament ") + toString(lastId))) | |
198 | + | else { | |
199 | + | let updatedDynamicData = dynamicData("INPROGRESS", dynamic[tDynamicWinDuck], parseIntValue(dynamic[tDynamicWinResult]), (parseIntValue(dynamic[tDynamicTotalRegCount]) + 1), parseIntValue(dynamic[tDynamicTotalAttempts])) | |
200 | + | $Tuple2([IntegerEntry(keyLastRegisteredTourByDuck(duckAssetId), lastId), BooleanEntry(keyIsRegisteredByTourAndDuck(lastId, duckAssetId), true), StringEntry(keyAllRegistrandsByTour(lastId), makeString_11C((regList :+ duckAssetId), "_")), StringEntry(keyTourDynamicDataById(lastId), updatedDynamicData)], prologResult) | |
201 | + | } | |
202 | + | } | |
203 | + | } | |
204 | + | } | |
64 | 205 | } | |
65 | 206 | } | |
66 | 207 | ||
67 | 208 |
github/deemru/w8io/169f3d6 43.80 ms ◑