tx · hfYMM1FSDQjeCJZDK3yLH6kefENk7H7ZrdfsnSBraSP 3MwGdE779Vhf4bkn8UbqQqEQwos38KtWhsn: -0.01400000 Waves 2019.06.26 15:47 [559110] smart account 3MwGdE779Vhf4bkn8UbqQqEQwos38KtWhsn > SELF 0.00000000 Waves
{ "type": 13, "id": "hfYMM1FSDQjeCJZDK3yLH6kefENk7H7ZrdfsnSBraSP", "fee": 1400000, "feeAssetId": null, "timestamp": 1561553337387, "version": 1, "sender": "3MwGdE779Vhf4bkn8UbqQqEQwos38KtWhsn", "senderPublicKey": "H4suXc6RCHTrdq9J8rbqDw6qw4Rcc1QXgy8Zj19AqRSh", "proofs": [ "5JYfhpPpyP9aMAn8Dyd6XadkuRdA2G9XmBWdBxQvdnXTc4K38YkM8BW2tNnNKaVmB1QxNoBT7gR6vR9mbbtmhLNv" ], "script": "base64:AAIDAAAAAAAAAAAAAAARAAAAAAV3YXZlcwAAAAAABfXhAAAAAAAFZW1wdHkBAAAAAAAAAAAIaGFzaFNpemUAAAAAAAAAACAAAAAAB2tleVNpemUAAAAAAAAAACAAAAAACGxvbmdTaXplAAAAAAAAAAAIAAAAAAxmaWdodFRpbWVvdXQAAAAAAAAAAGQAAAAACm1vdmVzQ291bnQAAAAAAAAAAAMAAAAABHJvY2sBAAAAAQAAAAAABXBhcGVyAQAAAAEBAAAAAAhzY2lzc29ycwEAAAABAgEAAAADZ2V0AAAAAgAAAAVieXRlcwAAAAVpbmRleAkAAMkAAAACCQAAygAAAAIFAAAABWJ5dGVzBQAAAAVpbmRleAAAAAAAAAAAAQEAAAALZ2V0QmluYXJ5T3IAAAACAAAAA2tleQAAAAdkZWZhdWx0AwkBAAAACWlzRGVmaW5lZAAAAAEJAAQcAAAAAgUAAAAEdGhpcwUAAAADa2V5CQEAAAARQGV4dHJOYXRpdmUoMTA1MikAAAACBQAAAAR0aGlzBQAAAANrZXkFAAAAB2RlZmF1bHQBAAAAC2lzVmFsaWRNb3ZlAAAAAQAAAARtb3Z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AgUAAAAJZmlnaHREYXRhBQAAAAhoYXNoU2l6ZQUAAAAIbG9uZ1NpemUDCQAAZgAAAAIFAAAADGZpZ2h0VGltZW91dAkAAGUAAAACBQAAAAZoZWlnaHQFAAAAAWgJAAACAAAAAQIAAAAvUGxheWVyMSBzdGlsbCBoYXMgYSB0aW1lIHRvIGNvbXBsZXRlIHRoZSBmaWdodC4EAAAAC3AyUHVibGljS2V5CQEAAAAOdGFrZVJpZ2h0Qnl0ZXMAAAACCQEAAAAOZHJvcFJpZ2h0Qnl0ZXMAAAACBQAAAAlmaWdodERhdGEFAAAACm1vdmVzQ291bnQFAAAAB2tleVNpemUJAQAAAAxTY3JpcHRSZXN1bHQAAAACCQEAAAAIV3JpdGVTZXQAAAABCQAETAAAAAIJAQAAAAVzdG9yZQAAAAIFAAAAB2ZpZ2h0SWQFAAAAC3AyUHVibGljS2V5BQAAAANuaWwJAQAAAAtUcmFuc2ZlclNldAAAAAEJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwkBAAAAFGFkZHJlc3NGcm9tUHVibGljS2V5AAAAAQUAAAALcDJQdWJsaWNLZXkJAABoAAAAAgAAAAAAAAAAAgUAAAAFd2F2ZXMFAAAABHVuaXQFAAAAA25pbAAAAABIUx1T", "chainId": 84, "height": 559110, "spentComplexity": 0 } View: original | compacted Prev: FBRAnf31t8SZrBoUExHKKPmEQKtMS7CnBKKqfWMewuuF Next: 5gsdprFtzrKQ2xP4eRbY4Z1mPkPf8UnBnyV337HmAa7h Diff:
Old | New | Differences | |
---|---|---|---|
15 | 15 | ||
16 | 16 | let movesCount = 3 | |
17 | 17 | ||
18 | - | let rock = 1 | |
18 | + | let rock = base58'1' | |
19 | 19 | ||
20 | - | let paper = 2 | |
20 | + | let paper = base58'2' | |
21 | 21 | ||
22 | - | let scissors = 3 | |
22 | + | let scissors = base58'3' | |
23 | 23 | ||
24 | - | func get (bytes,index) = | |
24 | + | func get (bytes,index) = take(drop(bytes, index), 1) | |
25 | 25 | ||
26 | 26 | ||
27 | 27 | func getBinaryOr (key,default) = if (isDefined(getBinary(this, key))) | |
73 | 73 | ||
74 | 74 | ||
75 | 75 | @Callable(i) | |
76 | - | func create (movesHash) = if (!(isDefined(i.payment))) | |
77 | - | then throw("Create call should be payed with 1 WAVE.") | |
78 | - | else { | |
79 | - | let p = extract(i.payment) | |
80 | - | if (isDefined(p.assetId)) | |
81 | - | then throw("Payment should be in WAVES.") | |
82 | - | else if ((p.amount != (1 * waves))) | |
83 | - | then throw("Amount should be 1 WAVE.") | |
84 | - | else if ((size(movesHash) != hashSize)) | |
85 | - | then throw("Invalid moves.") | |
86 | - | else WriteSet([store(((toBase58String(i.callerPublicKey) + "_") + toBase58String(i.transactionId)), movesHash)]) | |
87 | - | } | |
76 | + | func create (movesHash) = { | |
77 | + | let p = extract(i.payment) | |
78 | + | if (isDefined(p.assetId)) | |
79 | + | then throw("Payment should be in WAVES.") | |
80 | + | else if ((p.amount != (1 * waves))) | |
81 | + | then throw("Amount should be 1 WAVE.") | |
82 | + | else if ((size(movesHash) != hashSize)) | |
83 | + | then throw("Invalid moves.") | |
84 | + | else WriteSet([store(((toBase58String(i.callerPublicKey) + "_") + toBase58String(i.transactionId)), movesHash)]) | |
85 | + | } | |
88 | 86 | ||
89 | 87 | ||
90 | 88 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let waves = 100000000 | |
5 | 5 | ||
6 | 6 | let empty = base58'' | |
7 | 7 | ||
8 | 8 | let hashSize = 32 | |
9 | 9 | ||
10 | 10 | let keySize = 32 | |
11 | 11 | ||
12 | 12 | let longSize = 8 | |
13 | 13 | ||
14 | 14 | let fightTimeout = 100 | |
15 | 15 | ||
16 | 16 | let movesCount = 3 | |
17 | 17 | ||
18 | - | let rock = 1 | |
18 | + | let rock = base58'1' | |
19 | 19 | ||
20 | - | let paper = 2 | |
20 | + | let paper = base58'2' | |
21 | 21 | ||
22 | - | let scissors = 3 | |
22 | + | let scissors = base58'3' | |
23 | 23 | ||
24 | - | func get (bytes,index) = | |
24 | + | func get (bytes,index) = take(drop(bytes, index), 1) | |
25 | 25 | ||
26 | 26 | ||
27 | 27 | func getBinaryOr (key,default) = if (isDefined(getBinary(this, key))) | |
28 | 28 | then getBinaryValue(this, key) | |
29 | 29 | else default | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | func isValidMove (move) = if (if ((move == rock)) | |
33 | 33 | then true | |
34 | 34 | else (move == paper)) | |
35 | 35 | then true | |
36 | 36 | else (move == scissors) | |
37 | 37 | ||
38 | 38 | ||
39 | 39 | func isValidMoves (moves) = if (if (if ((size(moves) >= movesCount)) | |
40 | 40 | then isValidMove(get(moves, 0)) | |
41 | 41 | else false) | |
42 | 42 | then isValidMove(get(moves, 1)) | |
43 | 43 | else false) | |
44 | 44 | then isValidMove(get(moves, 2)) | |
45 | 45 | else false | |
46 | 46 | ||
47 | 47 | ||
48 | 48 | func round (p1Moves,p2Moves,round) = { | |
49 | 49 | let m1 = get(p1Moves, round) | |
50 | 50 | let m2 = get(p2Moves, round) | |
51 | 51 | if ((m1 == m2)) | |
52 | 52 | then 0 | |
53 | 53 | else if (if (if (if ((m1 == scissors)) | |
54 | 54 | then (m2 == paper) | |
55 | 55 | else false) | |
56 | 56 | then true | |
57 | 57 | else if ((m1 == rock)) | |
58 | 58 | then (m2 == scissors) | |
59 | 59 | else false) | |
60 | 60 | then true | |
61 | 61 | else if ((m1 == paper)) | |
62 | 62 | then (m2 == rock) | |
63 | 63 | else false) | |
64 | 64 | then -1 | |
65 | 65 | else 1 | |
66 | 66 | } | |
67 | 67 | ||
68 | 68 | ||
69 | 69 | func fight (p1Moves,p2Moves) = ((round(p1Moves, p2Moves, 0) + round(p1Moves, p2Moves, 1)) + round(p1Moves, p2Moves, 2)) | |
70 | 70 | ||
71 | 71 | ||
72 | 72 | func store (fightId,data) = DataEntry(fightId, (getBinaryOr(fightId, empty) + data)) | |
73 | 73 | ||
74 | 74 | ||
75 | 75 | @Callable(i) | |
76 | - | func create (movesHash) = if (!(isDefined(i.payment))) | |
77 | - | then throw("Create call should be payed with 1 WAVE.") | |
78 | - | else { | |
79 | - | let p = extract(i.payment) | |
80 | - | if (isDefined(p.assetId)) | |
81 | - | then throw("Payment should be in WAVES.") | |
82 | - | else if ((p.amount != (1 * waves))) | |
83 | - | then throw("Amount should be 1 WAVE.") | |
84 | - | else if ((size(movesHash) != hashSize)) | |
85 | - | then throw("Invalid moves.") | |
86 | - | else WriteSet([store(((toBase58String(i.callerPublicKey) + "_") + toBase58String(i.transactionId)), movesHash)]) | |
87 | - | } | |
76 | + | func create (movesHash) = { | |
77 | + | let p = extract(i.payment) | |
78 | + | if (isDefined(p.assetId)) | |
79 | + | then throw("Payment should be in WAVES.") | |
80 | + | else if ((p.amount != (1 * waves))) | |
81 | + | then throw("Amount should be 1 WAVE.") | |
82 | + | else if ((size(movesHash) != hashSize)) | |
83 | + | then throw("Invalid moves.") | |
84 | + | else WriteSet([store(((toBase58String(i.callerPublicKey) + "_") + toBase58String(i.transactionId)), movesHash)]) | |
85 | + | } | |
88 | 86 | ||
89 | 87 | ||
90 | 88 | ||
91 | 89 | @Callable(i) | |
92 | 90 | func join (fightId,moves) = { | |
93 | 91 | let p = extract(i.payment) | |
94 | 92 | if (isDefined(p.assetId)) | |
95 | 93 | then throw("Payment should be in WAVES.") | |
96 | 94 | else if ((p.amount != (1 * waves))) | |
97 | 95 | then throw("Amount should be 1 WAVE.") | |
98 | 96 | else if (!(isDefined(getBinary(this, fightId)))) | |
99 | 97 | then throw("Fight is not found.") | |
100 | 98 | else if ((size(getBinaryValue(this, fightId)) != hashSize)) | |
101 | 99 | then throw("Fight is already started.") | |
102 | 100 | else if (!(isValidMoves(moves))) | |
103 | 101 | then throw("Invalid moves.") | |
104 | 102 | else WriteSet([store(fightId, ((toBytes(height) + i.callerPublicKey) + moves))]) | |
105 | 103 | } | |
106 | 104 | ||
107 | 105 | ||
108 | 106 | ||
109 | 107 | @Callable(i) | |
110 | 108 | func complete (fightId,moves) = if (!(isDefined(getBinary(this, fightId)))) | |
111 | 109 | then throw("Fight is not found.") | |
112 | 110 | else { | |
113 | 111 | let fightData = getBinaryValue(this, fightId) | |
114 | 112 | if ((size(fightData) == hashSize)) | |
115 | 113 | then throw("Fight is not started.") | |
116 | 114 | else if ((size(fightData) > (((hashSize + longSize) + keySize) + movesCount))) | |
117 | 115 | then throw("Fight is already finished.") | |
118 | 116 | else { | |
119 | 117 | let hashedMoves = take(getBinaryValue(this, fightId), hashSize) | |
120 | 118 | if (if ((hashedMoves != blake2b256(moves))) | |
121 | 119 | then true | |
122 | 120 | else !(isValidMoves(moves))) | |
123 | 121 | then throw("Invalid moves.") | |
124 | 122 | else { | |
125 | 123 | let p2PublicKey = takeRightBytes(dropRightBytes(fightData, movesCount), keySize) | |
126 | 124 | let r = fight(take(moves, movesCount), takeRightBytes(fightData, movesCount)) | |
127 | 125 | ScriptResult(WriteSet([store(fightId, moves)]), TransferSet(if ((r == 0)) | |
128 | 126 | then [ScriptTransfer(i.caller, (1 * waves), unit), ScriptTransfer(addressFromPublicKey(p2PublicKey), (1 * waves), unit)] | |
129 | 127 | else if ((0 > r)) | |
130 | 128 | then [ScriptTransfer(i.caller, (2 * waves), unit)] | |
131 | 129 | else [ScriptTransfer(addressFromPublicKey(p2PublicKey), (2 * waves), unit)])) | |
132 | 130 | } | |
133 | 131 | } | |
134 | 132 | } | |
135 | 133 | ||
136 | 134 | ||
137 | 135 | ||
138 | 136 | @Callable(i) | |
139 | 137 | func timeout (fightId) = if (!(isDefined(getBinary(this, fightId)))) | |
140 | 138 | then throw("Fight is not found.") | |
141 | 139 | else { | |
142 | 140 | let fightData = getBinaryValue(this, fightId) | |
143 | 141 | if ((size(fightData) == hashSize)) | |
144 | 142 | then throw("Fight is not started.") | |
145 | 143 | else if ((size(fightData) > (((hashSize + longSize) + keySize) + movesCount))) | |
146 | 144 | then throw("Fight is already finished.") | |
147 | 145 | else { | |
148 | 146 | let h = toInt(take(drop(fightData, hashSize), longSize)) | |
149 | 147 | if ((fightTimeout > (height - h))) | |
150 | 148 | then throw("Player1 still has a time to complete the fight.") | |
151 | 149 | else { | |
152 | 150 | let p2PublicKey = takeRightBytes(dropRightBytes(fightData, movesCount), keySize) | |
153 | 151 | ScriptResult(WriteSet([store(fightId, p2PublicKey)]), TransferSet([ScriptTransfer(addressFromPublicKey(p2PublicKey), (2 * waves), unit)])) | |
154 | 152 | } | |
155 | 153 | } | |
156 | 154 | } | |
157 | 155 | ||
158 | 156 |
github/deemru/w8io/026f985 37.03 ms ◑