tx · DotzstxB6JW7CBfCas71EawsPf2gZWJm1K8RDmoCPYE

3MpdJJV3WyZufiGHRtb7xbY2Vsc2pBFcJYZ:  -0.01400000 Waves

2021.05.13 08:34 [1523495] smart account 3MpdJJV3WyZufiGHRtb7xbY2Vsc2pBFcJYZ > SELF 0.00000000 Waves

{ "type": 13, "id": "DotzstxB6JW7CBfCas71EawsPf2gZWJm1K8RDmoCPYE", "fee": 1400000, "feeAssetId": null, "timestamp": 1620884066461, "version": 1, "sender": "3MpdJJV3WyZufiGHRtb7xbY2Vsc2pBFcJYZ", "senderPublicKey": "ALG9JVGNn9aCL68dbg1AmW6yDQv1b8EDLq99pQS8L1k6", "proofs": [ "qESVjMczdkR6EEnxhV8sM6TAR7wH3ezLshNpU3ENuXLggDkbucqD7uCx3rXRL4xovjVikRttYWzoWDw85XW3oat" ], "script": "base64:AAIEAAAAAAAAAA8IAhIAEgMKAQgSBAoCCAEAAAAWAAAAABNnYW1lTWFzdGVyUHVibGljS2V5AQAAACCKqFcQ1VSNQa7ZONz4ZD59H7wLfuowVwcQ1qI/fK6ACwAAAAAKZGljZU51bWJlcgkABEwAAAACAAAAAAAAAAACCQAETAAAAAIAAAAAAAAAAAMJAARMAAAAAgAAAAAAAAAABAkABEwAAAACAAAAAAAAAAAFCQAETAAAAAIAAAAAAAAAAAYJAARMAAAAAgAAAAAAAAAABwkABEwAAAACAAAAAAAAAAAICQAETAAAAAIAAAAAAAAAAAkJAARMAAAAAgAAAAAAAAAACgkABEwAAAACAAAAAAAAAAALCQAETAAAAAIAAAAAAAAAAAwFAAAAA25pbAAAAAAJZ2FtZVRva2VuAQAAACCvQNOoGbkt3wVk9kpr+yD9dOUY7LBdGNCbLK5MVkSodQAAAAAJUlNBUFVCTElDCQACWwAAAAECAAABkmJhc2U2NDpNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQWpudDJQZE4xUGRqZDoKN3JzWHpiYXBndWNuOWUxWGZmVX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ZXIFAAAAA25pbAkAAAIAAAABAgAAABlMYXN0IGJsb2NrIGRvZXNuJ3QgZXhpc3QuCQAAAgAAAAECAAAAEVNIQSBkb2Vzbid0IGV4aXN0CQAAAgAAAAECAAAAKUdhbWUgZG9lcyBub3QgZXhpc3Qgb3IgaGFzIGFscmVhZHkgZW5kZWQuAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAQAAAAHJG1hdGNoMAUAAAACdHgJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAACAUAAAACdHgAAAAPc2VuZGVyUHVibGljS2V5bxHpMg==", "chainId": 84, "height": 1523495, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: FvBSZcN9ooGY4EL1yyq4uJrD1MiGhYhkkheNRAs4Dwzu Next: FjumHL3NMo3Aj5LJstW9BYVJrF2SZmzhfSDAxi9gr3we Diff:
OldNewDifferences
33 {-# CONTENT_TYPE DAPP #-}
44 let gameMasterPublicKey = base58'ALG9JVGNn9aCL68dbg1AmW6yDQv1b8EDLq99pQS8L1k6'
55
6-let diceNumber = [1, 2, 3, 4, 5, 6, 7, 8]
6+let diceNumber = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
77
88 let gameToken = base58'Co7gTLr7ZJvVKwToLpuZJqmkVecy5uwupYH6qCkKuhc8'
9+
10+let RSAPUBLIC = fromBase64String("base64:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjnt2PdN1Pdjd:
11+7rsXzbapgucn9e1XffUx1o7grAlw8C6NFuv1PPj7KnQ6RtN9xhniLF4xKlc7//TYXd1uHWmx9vu9hjciYX9UMRJnhlZO2q34mxPdcgLDKhJHDN726KI0wHpFQ5dHMyzoMLdWsahFc1Wx/XxroK2Kc1y2JBWN2akRlkxSDcluqbbUcWMyrwG6iWuVlhej5xfcuerg/psK35WGn7SLF29tWuR2x+24nM+BJUsuRG7yBZUhGrYzJk2gvpucRLea6AFRvow7RdyMYAwKFrr6mgQ0VcUw2T750e1oGanY0UdU3NPsKIgvU4Ft4uibMlMMBJvcrsEbDQHfDlwIDAQAB")
912
1013 let GAMESTART = 0
1114
1518
1619 let gameCounterLabel = "G_GAMECOUNTER"
1720
18-let gamePassBetLabel = "B_PASSBETS_"
19-
20-let gameCurrentPointLabal = "G_CurrentPoint_"
21+let gameTotalBetsLabel = "G_TOTALCRAPSBETS"
2122
2223 let lastRolledNumber = 0
2324
2425 func authorizePermission (callerPublicKey) = (callerPublicKey != gameMasterPublicKey)
26+
27+
28+func gameCurrentPointDiceLabel (gameCounter) = (("G_" + toString(gameCounter)) + "_FIRSTPOINT")
29+
30+
31+func gameFirstPointDiceLabel (gameCounter) = (("G_" + toString(gameCounter)) + "_CURRENTPOINT")
2532
2633
2734 func gameStateLabel (gameCounter) = (("G_" + toString(gameCounter)) + "_STATE")
4552 func getCrapGameCounter () = getInteger(this, gameCounterLabel)
4653
4754
48-func getRandomIndexForDice (randomHash) = diceNumber[(toInt(randomHash) % 8)]
55+func getFirstPointDice (gameCounter) = getInteger(this, gameFirstPointDiceLabel(gameCounter))
56+
57+
58+func getCurrentPointDice (gameCounter) = getInteger(this, gameCurrentPointDiceLabel(gameCounter))
4959
5060
5161 @Callable(i)
5565 case counter: Int =>
5666 throw("INIT_ALREADY_DONE")
5767 case _ =>
58-[IntegerEntry(gameCounterLabel, 0)]
68+[IntegerEntry(gameCounterLabel, 0), IntegerEntry(gameTotalBetsLabel, 0)]
5969 }
6070
6171
7282 }
7383
7484
85+
86+@Callable(i)
87+func throwDices (rsaSign,gameNumber) = if (authorizePermission(i.callerPublicKey))
88+ then throw("throwDices_FORBIDDEN")
89+ else match getGameState(gameNumber) {
90+ case state: Int =>
91+ if ((state == GAMEFINISHED))
92+ then throw("Game is finished")
93+ else match getGameSumSha(gameNumber) {
94+ case sumSha: String =>
95+ let sig = fromBase64String(rsaSign)
96+ let rsaSigValid = rsaVerify(SHA256, fromBase58String(sumSha), sig, RSAPUBLIC)
97+ match blockInfoByHeight((lastBlock.height - 1)) {
98+ case previousBlock: BlockInfo =>
99+ let randomHash = sha256((take(sig, 4) + take(previousBlock.generationSignature, 4)))
100+ if (!(rsaSigValid))
101+ then throw("INVALID_RSA_SIGN")
102+ else {
103+ let randNumber = (toInt(randomHash) % 8)
104+ let number = diceNumber[randNumber]
105+ if ((state == GAMESTART))
106+ then [IntegerEntry(gameStateLabel(gameNumber), GAMEINPROGRESS), IntegerEntry(gameFirstPointDiceLabel(gameNumber), number)]
107+ else [IntegerEntry(gameStateLabel(gameNumber), GAMEINPROGRESS), IntegerEntry(gameCurrentPointDiceLabel(gameNumber), number)]
108+ }
109+ case _ =>
110+ throw("Last block doesn't exist.")
111+ }
112+ case _ =>
113+ throw("SHA doesn't exist")
114+ }
115+ case _ =>
116+ throw("Game does not exist or has already ended.")
117+ }
118+
119+
75120 @Verifier(tx)
76121 func verify () = match tx {
77122 case _ =>
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 4 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let gameMasterPublicKey = base58'ALG9JVGNn9aCL68dbg1AmW6yDQv1b8EDLq99pQS8L1k6'
55
6-let diceNumber = [1, 2, 3, 4, 5, 6, 7, 8]
6+let diceNumber = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
77
88 let gameToken = base58'Co7gTLr7ZJvVKwToLpuZJqmkVecy5uwupYH6qCkKuhc8'
9+
10+let RSAPUBLIC = fromBase64String("base64:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjnt2PdN1Pdjd:
11+7rsXzbapgucn9e1XffUx1o7grAlw8C6NFuv1PPj7KnQ6RtN9xhniLF4xKlc7//TYXd1uHWmx9vu9hjciYX9UMRJnhlZO2q34mxPdcgLDKhJHDN726KI0wHpFQ5dHMyzoMLdWsahFc1Wx/XxroK2Kc1y2JBWN2akRlkxSDcluqbbUcWMyrwG6iWuVlhej5xfcuerg/psK35WGn7SLF29tWuR2x+24nM+BJUsuRG7yBZUhGrYzJk2gvpucRLea6AFRvow7RdyMYAwKFrr6mgQ0VcUw2T750e1oGanY0UdU3NPsKIgvU4Ft4uibMlMMBJvcrsEbDQHfDlwIDAQAB")
912
1013 let GAMESTART = 0
1114
1215 let GAMEINPROGRESS = 1
1316
1417 let GAMEFINISHED = 2
1518
1619 let gameCounterLabel = "G_GAMECOUNTER"
1720
18-let gamePassBetLabel = "B_PASSBETS_"
19-
20-let gameCurrentPointLabal = "G_CurrentPoint_"
21+let gameTotalBetsLabel = "G_TOTALCRAPSBETS"
2122
2223 let lastRolledNumber = 0
2324
2425 func authorizePermission (callerPublicKey) = (callerPublicKey != gameMasterPublicKey)
26+
27+
28+func gameCurrentPointDiceLabel (gameCounter) = (("G_" + toString(gameCounter)) + "_FIRSTPOINT")
29+
30+
31+func gameFirstPointDiceLabel (gameCounter) = (("G_" + toString(gameCounter)) + "_CURRENTPOINT")
2532
2633
2734 func gameStateLabel (gameCounter) = (("G_" + toString(gameCounter)) + "_STATE")
2835
2936
3037 func gameSumShaLabel (gameCounter) = (("G_" + toString(gameCounter)) + "_SUMSHA")
3138
3239
3340 func gameStartHeightLabel (gameCounter) = (("G_" + toString(gameCounter)) + "_STARTHEIGHT")
3441
3542
3643 func getGameState (gameCounter) = getInteger(this, gameStateLabel(gameCounter))
3744
3845
3946 func getGameSumSha (gameCounter) = getString(this, gameSumShaLabel(gameCounter))
4047
4148
4249 func getStartHeight (gameCounter) = getInteger(this, gameStartHeightLabel(gameCounter))
4350
4451
4552 func getCrapGameCounter () = getInteger(this, gameCounterLabel)
4653
4754
48-func getRandomIndexForDice (randomHash) = diceNumber[(toInt(randomHash) % 8)]
55+func getFirstPointDice (gameCounter) = getInteger(this, gameFirstPointDiceLabel(gameCounter))
56+
57+
58+func getCurrentPointDice (gameCounter) = getInteger(this, gameCurrentPointDiceLabel(gameCounter))
4959
5060
5161 @Callable(i)
5262 func initGame () = if (authorizePermission(i.callerPublicKey))
5363 then throw("initGame_FORBIDDEN")
5464 else match getCrapGameCounter() {
5565 case counter: Int =>
5666 throw("INIT_ALREADY_DONE")
5767 case _ =>
58-[IntegerEntry(gameCounterLabel, 0)]
68+[IntegerEntry(gameCounterLabel, 0), IntegerEntry(gameTotalBetsLabel, 0)]
5969 }
6070
6171
6272
6373 @Callable(i)
6474 func startGame (randomHash) = if (authorizePermission(i.callerPublicKey))
6575 then throw("startGame_FORBIDDEN")
6676 else match getCrapGameCounter() {
6777 case number: Int =>
6878 let newNumber = (number + 1)
6979 [IntegerEntry(gameCounterLabel, newNumber), IntegerEntry(gameStateLabel(newNumber), 0), IntegerEntry(gameStartHeightLabel(newNumber), lastBlock.height), StringEntry(gameSumShaLabel(newNumber), toBase58String(sha256(fromBase64String(randomHash))))]
7080 case _ =>
7181 throw("INIT_NEED")
7282 }
7383
7484
85+
86+@Callable(i)
87+func throwDices (rsaSign,gameNumber) = if (authorizePermission(i.callerPublicKey))
88+ then throw("throwDices_FORBIDDEN")
89+ else match getGameState(gameNumber) {
90+ case state: Int =>
91+ if ((state == GAMEFINISHED))
92+ then throw("Game is finished")
93+ else match getGameSumSha(gameNumber) {
94+ case sumSha: String =>
95+ let sig = fromBase64String(rsaSign)
96+ let rsaSigValid = rsaVerify(SHA256, fromBase58String(sumSha), sig, RSAPUBLIC)
97+ match blockInfoByHeight((lastBlock.height - 1)) {
98+ case previousBlock: BlockInfo =>
99+ let randomHash = sha256((take(sig, 4) + take(previousBlock.generationSignature, 4)))
100+ if (!(rsaSigValid))
101+ then throw("INVALID_RSA_SIGN")
102+ else {
103+ let randNumber = (toInt(randomHash) % 8)
104+ let number = diceNumber[randNumber]
105+ if ((state == GAMESTART))
106+ then [IntegerEntry(gameStateLabel(gameNumber), GAMEINPROGRESS), IntegerEntry(gameFirstPointDiceLabel(gameNumber), number)]
107+ else [IntegerEntry(gameStateLabel(gameNumber), GAMEINPROGRESS), IntegerEntry(gameCurrentPointDiceLabel(gameNumber), number)]
108+ }
109+ case _ =>
110+ throw("Last block doesn't exist.")
111+ }
112+ case _ =>
113+ throw("SHA doesn't exist")
114+ }
115+ case _ =>
116+ throw("Game does not exist or has already ended.")
117+ }
118+
119+
75120 @Verifier(tx)
76121 func verify () = match tx {
77122 case _ =>
78123 sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
79124 }
80125

github/deemru/w8io/169f3d6 
34.81 ms