4 | | - | let gameNumberKey = "$GAME_NUMBER" |
---|
5 | | - | |
---|
6 | | - | let testKey = "$TEST" |
---|
7 | | - | |
---|
8 | | - | let delayForGame = 2 |
---|
9 | | - | |
---|
10 | | - | let GameStarted = 1 |
---|
11 | | - | |
---|
12 | | - | let GameFinished = 2 |
---|
13 | | - | |
---|
14 | | - | func getGameStatusKey (address,gameId) = (((address + "_") + toString(gameId)) + "_status") |
---|
15 | | - | |
---|
16 | | - | |
---|
17 | | - | func getGameTxIdKey (address,gameId) = (((address + "_") + toString(gameId)) + "_txid") |
---|
18 | | - | |
---|
19 | | - | |
---|
20 | | - | func getGameingFinishHeightKey (address,gameId) = (((address + "_") + toString(gameId)) + "_fh") |
---|
21 | | - | |
---|
22 | | - | |
---|
23 | | - | func getAssetIdKey (address,gameId) = (((address + "_") + toString(gameId)) + "_di") |
---|
24 | | - | |
---|
25 | | - | |
---|
26 | | - | func tryGetInteger (key) = { |
---|
27 | | - | let val = match getInteger(this, key) { |
---|
28 | | - | case b: Int => |
---|
29 | | - | b |
---|
30 | | - | case _ => |
---|
31 | | - | 0 |
---|
32 | | - | } |
---|
33 | | - | val |
---|
34 | | - | } |
---|
35 | | - | |
---|
36 | | - | |
---|
37 | | - | func getRandomNumber (variants,txId,gameingFinishHeight,offset) = { |
---|
38 | | - | let randomSeedBlock = value(blockInfoByHeight((gameingFinishHeight - 1))) |
---|
39 | | - | let randomHash = sha256((txId + value(randomSeedBlock.vrf))) |
---|
40 | | - | (toInt(randomHash, (offset * 8)) % variants) |
---|
41 | | - | } |
---|
42 | | - | |
---|
43 | | - | |
---|
44 | | - | func getRandomName (txId,gameingFinishHeight) = { |
---|
45 | | - | let rand = getRandomNumber(2, txId, gameingFinishHeight, 0) |
---|
46 | | - | if ((rand == 0)) |
---|
47 | | - | then "type1" |
---|
48 | | - | else "type2" |
---|
49 | | - | } |
---|
55 | | - | let gameId = tryGetInteger(gameNumberKey) |
---|
56 | | - | [IntegerEntry(getGameStatusKey(toString(i.caller), gameId), GameStarted), StringEntry(getGameTxIdKey(toString(i.caller), gameId), toBase58String(i.transactionId)), IntegerEntry(getGameingFinishHeightKey(toString(i.caller), gameId), (height + delayForGame)), IntegerEntry(gameNumberKey, (gameId + 1))] |
---|
57 | | - | } |
---|
58 | | - | |
---|
59 | | - | |
---|
60 | | - | |
---|
61 | | - | @Callable(i) |
---|
62 | | - | func finishAssetGaming (gameId) = { |
---|
63 | | - | let gameingStatusKey = getGameStatusKey(toString(i.caller), gameId) |
---|
64 | | - | let finishHeightKey = getGameingFinishHeightKey(toString(i.caller), gameId) |
---|
65 | | - | let assetIdKey = getAssetIdKey(toString(i.caller), gameId) |
---|
66 | | - | let gameTxIdKey = getGameTxIdKey(toString(i.caller), gameId) |
---|
67 | | - | let gameingTxStatus = tryGetInteger(gameingStatusKey) |
---|
68 | | - | let gameingFinishHeight = getIntegerValue(this, finishHeightKey) |
---|
69 | | - | let gameTxId = fromBase58String(getStringValue(this, gameTxIdKey)) |
---|
70 | | - | if ((gameingTxStatus == GameFinished)) |
---|
71 | | - | then { |
---|
72 | | - | let assetId = getStringValue(this, getAssetIdKey(toString(i.caller), gameId)) |
---|
73 | | - | throw(("The asset was gamed and claimed already, here is the folowing: " + assetId)) |
---|
74 | | - | } |
---|
75 | | - | else if ((gameingFinishHeight > height)) |
---|
76 | | - | then throw((((("Gaming is not finished yet " + toString((gameingFinishHeight - height))) + " blocks remaining, it will take around ") + toString((gameingFinishHeight - height))) + " minutes")) |
---|
77 | | - | else { |
---|
78 | | - | let randonName = getRandomName(gameTxId, gameingFinishHeight) |
---|
79 | | - | let asset = Issue(randonName, randonName, 1, 0, false, unit, gameingFinishHeight) |
---|
80 | | - | let assetId = calculateAssetId(asset) |
---|
81 | | - | [IntegerEntry(gameingStatusKey, GameFinished), StringEntry(assetIdKey, toBase58String(assetId)), StringEntry(toBase58String(assetId), assetIdKey), asset, ScriptTransfer(i.caller, 1, assetId)] |
---|
82 | | - | } |
---|
| 9 | + | [StringEntry((toAddress + "asset"), ((toAddress + asset[0]) + asset[1]))] |
---|