tx · 6rZLBkh4zbw5gbdwa2scvGEuW4Exsbhrgt9ryQ7vhTao 3MqLtJ49xFdzpVh8kJoaumrRN9GYXLrScMk: -0.01400000 Waves 2019.08.01 09:54 [611390] smart account 3MqLtJ49xFdzpVh8kJoaumrRN9GYXLrScMk > SELF 0.00000000 Waves
{ "type": 13, "id": "6rZLBkh4zbw5gbdwa2scvGEuW4Exsbhrgt9ryQ7vhTao", "fee": 1400000, "feeAssetId": null, "timestamp": 1564642528947, "version": 1, "sender": "3MqLtJ49xFdzpVh8kJoaumrRN9GYXLrScMk", "senderPublicKey": "5XLU4PwAQXZGmcUD3QtB2pXeV3VBEBp8cvA9NnTiv2mW", "proofs": [ "2wX6JsAZmDDvSozHVzptfswf5rUSMRtTp4SqWFnNke1xTbWd812rauofkYsRewUX4GAumiuWRfxa4HWdQqrWgFJu" ], "script": "base64:AAIDAAAAAAAAAAAAAAAJAAAAAApiZXRBc3NldElkAQAAACAea7QCZF/XAXMBPEnDQ5kqHUHyOfWmXu9KHDHL6zcNNwAAAAAGbWF4RmVlAAAAAAAATEtAAAAAAAZtaW5CZXQAAAAAAABMS0AAAAAAD21pbk1hdGNoTm9taW5hbAAAAAAAAExLQAEAAAAIY2hlY2tGZWUAAAABAAAAAWkDCQAAZgAAAAIIBQAAAAFpAAAAA2ZlZQUAAAAGbWF4RmVlCQAAAgAAAAECAAAAFnVucmVhc29uYWJsZSBsYXJnZSBmZWUDCQEAAAACIT0AAAACCAUAAAABaQAAAApmZWVBc3NldElkBQAAAAR1bml0CQAAAgAAAAECAAAAFGZlZSBtdXN0IGJlIGluIFdBVkVTBgEAAAAIcmVwYXlGZWUAAAADAAAAAWkAAAACd3MAAAAGYW1vdW50AwkBAAAACGNoZWNrRmVlAAAAAQUAAAABaQkBAAAADFNjcmlwdFJlc3VsdAAAAAIFAAAAAndzCQEAAAALVHJhbnNmZXJTZXQAAAABCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAAFpAA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BZ2FpbnN0RGVmZWF0ZWQHCQAAAgAAAAECAAAAF25vIHNpZGUgYXBwcm92ZWQgZGVmZWF0BAAAAAh3aW5uZXJJZAMFAAAADmJldEZvckRlZmVhdGVkBQAAAAxiZXRBZ2FpbnN0SWQFAAAACGJldEZvcklkBAAAAA13aW5uZXJBZGRyZXNzCQAEHQAAAAIFAAAABHRoaXMJAAEsAAAAAgUAAAAId2lubmVySWQCAAAABl9vd25lcgMJAQAAAAIhPQAAAAIFAAAADXdpbm5lckFkZHJlc3MJAAJYAAAAAQgIBQAAAAFpAAAABmNhbGxlcgAAAAVieXRlcwkAAAIAAAABAgAAACtwYXl3aW5uZXIoKSBzaG91bGQgYmUgY2FsbGVkIGJ5IHdpbm5lciBvbmx5BAAAAAZhbW91bnQJAQAAAAdleHRyYWN0AAAAAQkABBoAAAACBQAAAAR0aGlzCQABLAAAAAIFAAAAB21hdGNoSWQCAAAAB19hbW91bnQJAQAAAAhyZXBheUZlZQAAAAMFAAAAAWkJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAAEsAAAAAgUAAAAHbWF0Y2hJZAIAAAAFX3BhaWQFAAAABmFtb3VudAUAAAADbmlsBQAAAAZhbW91bnQAAAAAIDLcVw==", "chainId": 84, "height": 611390, "spentComplexity": 0 } View: original | compacted Prev: J93oV3u4Y7Z3hzJ53iZQVYw8AUF17Waea528bGXZq2DE Next: 6zkAHprgK1GysUenqgLL3jtuUr6Q5tH9FPypZoYcoyPb Diff:
Old | New | Differences | |
---|---|---|---|
99 | 99 | else { | |
100 | 100 | let spendFor = matchNominal | |
101 | 101 | let spendAgainst = ((matchNominal * odds) / 100) | |
102 | - | let newSpentFor = (spendFor + | |
103 | - | let newSpentAgainst = (spendAgainst + | |
102 | + | let newSpentFor = (spendFor + extract(getInteger(this, (betFor + "_spent")))) | |
103 | + | let newSpentAgainst = (spendAgainst + extract(getInteger(this, (betAgainst + "_spent")))) | |
104 | 104 | if ((newSpentFor > extract(getInteger(this, (betFor + "_amount"))))) | |
105 | 105 | then throw("invalid match") | |
106 | 106 | else if ((newSpentAgainst > extract(getInteger(this, (betAgainst + "_amount"))))) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let betAssetId = base58'33kV5hRVtgEGpYqhp9wQn2g9hP1fNWSYGCzzYk1T9Hyg' | |
5 | 5 | ||
6 | 6 | let maxFee = 5000000 | |
7 | 7 | ||
8 | 8 | let minBet = 5000000 | |
9 | 9 | ||
10 | 10 | let minMatchNominal = 5000000 | |
11 | 11 | ||
12 | 12 | func checkFee (i) = if ((i.fee > maxFee)) | |
13 | 13 | then throw("unreasonable large fee") | |
14 | 14 | else if ((i.feeAssetId != unit)) | |
15 | 15 | then throw("fee must be in WAVES") | |
16 | 16 | else true | |
17 | 17 | ||
18 | 18 | ||
19 | 19 | func repayFee (i,ws,amount) = if (checkFee(i)) | |
20 | 20 | then ScriptResult(ws, TransferSet([ScriptTransfer(i.caller, i.fee, unit)])) | |
21 | 21 | else throw("error") | |
22 | 22 | ||
23 | 23 | ||
24 | 24 | func checkOwner (i,betid) = (getString(this, (betid + "_owner")) == toBase58String(i.caller.bytes)) | |
25 | 25 | ||
26 | 26 | ||
27 | 27 | func getUnspent (betid) = (extract(getInteger(this, (betid + "_amount"))) - extract(getInteger(this, (betid + "_spent")))) | |
28 | 28 | ||
29 | 29 | ||
30 | 30 | func isDefeated (betid) = { | |
31 | 31 | let defeatStatus = getInteger(this, (betid + "_defeat")) | |
32 | 32 | if ((defeatStatus == 1)) | |
33 | 33 | then true | |
34 | 34 | else (defeatStatus == 3) | |
35 | 35 | } | |
36 | 36 | ||
37 | 37 | ||
38 | 38 | @Callable(i) | |
39 | 39 | func bet (event,subevent,side,odds) = { | |
40 | 40 | let owner = toBase58String(i.caller.bytes) | |
41 | 41 | let payment = extract(i.payment) | |
42 | 42 | if ((payment.assetId != betAssetId)) | |
43 | 43 | then throw(("bet must be in asset " + toBase58String(betAssetId))) | |
44 | 44 | else if ((minBet > payment.amount)) | |
45 | 45 | then throw(("minimum allowed bet is " + toString(minBet))) | |
46 | 46 | else if (if ((side != "for")) | |
47 | 47 | then (side != "against") | |
48 | 48 | else false) | |
49 | 49 | then throw("unexpected side") | |
50 | 50 | else { | |
51 | 51 | let betid = (((((("bet_" + event) + "_") + toBase58String(i.caller.bytes)) + "_") + take(toBase64String(i.transactionId), 15)) + "_") | |
52 | 52 | let sequenceKey = ((("seq_" + event) + "_") + subevent) | |
53 | 53 | let sequence = match getInteger(this, sequenceKey) { | |
54 | 54 | case prevS: Int => | |
55 | 55 | (prevS + 1) | |
56 | 56 | case _ => | |
57 | 57 | 1 | |
58 | 58 | } | |
59 | 59 | repayFee(i, WriteSet([DataEntry((betid + "owner"), owner), DataEntry((betid + "event"), event), DataEntry((betid + "subevent"), subevent), DataEntry((betid + "side"), side), DataEntry((betid + "odds"), odds), DataEntry((betid + "amount"), payment.amount), DataEntry((betid + "spent"), 0), DataEntry((betid + "timestamp"), lastBlock.timestamp), DataEntry((betid + "sequence"), sequence), DataEntry(sequenceKey, sequence)]), 0) | |
60 | 60 | } | |
61 | 61 | } | |
62 | 62 | ||
63 | 63 | ||
64 | 64 | ||
65 | 65 | @Callable(i) | |
66 | 66 | func cancel (betid) = if (!(checkOwner(i, betid))) | |
67 | 67 | then throw("permission denied") | |
68 | 68 | else { | |
69 | 69 | let amount = extract(getInteger(this, (betid + "_amount"))) | |
70 | 70 | let spent = extract(getInteger(this, (betid + "_spent"))) | |
71 | 71 | let cancelAmount = (amount - spent) | |
72 | 72 | repayFee(i, WriteSet([DataEntry((betid + "_spent"), amount), DataEntry((betid + "_cancel_amount"), cancelAmount)]), cancelAmount) | |
73 | 73 | } | |
74 | 74 | ||
75 | 75 | ||
76 | 76 | ||
77 | 77 | @Callable(i) | |
78 | 78 | func betMatch (betFor,betAgainst) = if ((getString(this, (betFor + "_event")) != getString(this, (betAgainst + "_event")))) | |
79 | 79 | then throw("event id must match") | |
80 | 80 | else if ((getString(this, (betFor + "_subevent")) != getString(this, (betAgainst + "_subevent")))) | |
81 | 81 | then throw("subevent id must match") | |
82 | 82 | else if ((getString(this, (betFor + "_side")) != "for")) | |
83 | 83 | then throw("invalid *for* bet") | |
84 | 84 | else if ((getString(this, (betAgainst + "_side")) != "against")) | |
85 | 85 | then throw("invalid *against* bet") | |
86 | 86 | else { | |
87 | 87 | let eventid = extract(getString(this, (betFor + "_event"))) | |
88 | 88 | let matchid = (((((((("match_" + betFor) + "_") + betAgainst) + "_") + eventid) + "_") + toBase58String(i.transactionId)) + "_") | |
89 | 89 | let odds = extract(getInteger(this, (betFor + "_odds"))) | |
90 | 90 | let unspentFor = getUnspent(betFor) | |
91 | 91 | let unspentAgainst = getUnspent(betAgainst) | |
92 | 92 | let maxForNominal = unspentFor | |
93 | 93 | let maxAgainstNominal = ((unspentAgainst * 100) / odds) | |
94 | 94 | let matchNominal = if ((maxForNominal > maxAgainstNominal)) | |
95 | 95 | then maxAgainstNominal | |
96 | 96 | else maxForNominal | |
97 | 97 | if ((minMatchNominal > matchNominal)) | |
98 | 98 | then throw("match nominal too low") | |
99 | 99 | else { | |
100 | 100 | let spendFor = matchNominal | |
101 | 101 | let spendAgainst = ((matchNominal * odds) / 100) | |
102 | - | let newSpentFor = (spendFor + | |
103 | - | let newSpentAgainst = (spendAgainst + | |
102 | + | let newSpentFor = (spendFor + extract(getInteger(this, (betFor + "_spent")))) | |
103 | + | let newSpentAgainst = (spendAgainst + extract(getInteger(this, (betAgainst + "_spent")))) | |
104 | 104 | if ((newSpentFor > extract(getInteger(this, (betFor + "_amount"))))) | |
105 | 105 | then throw("invalid match") | |
106 | 106 | else if ((newSpentAgainst > extract(getInteger(this, (betAgainst + "_amount"))))) | |
107 | 107 | then throw("invalid match") | |
108 | 108 | else repayFee(i, WriteSet([DataEntry((matchid + "amount"), (spendFor + spendAgainst)), DataEntry((matchid + "for"), betFor), DataEntry((matchid + "against"), betAgainst), DataEntry((betFor + "_spent"), newSpentFor), DataEntry((betAgainst + "_spent"), newSpentAgainst)]), 0) | |
109 | 109 | } | |
110 | 110 | } | |
111 | 111 | ||
112 | 112 | ||
113 | 113 | ||
114 | 114 | @Callable(i) | |
115 | 115 | func approveDefeat (betId,defeat) = if (if (isDefined(getInteger(this, (betId + "_defeat")))) | |
116 | 116 | then (defeat == 2) | |
117 | 117 | else false) | |
118 | 118 | then throw("can't dispute after approve") | |
119 | 119 | else repayFee(i, WriteSet([DataEntry((betId + "_defeat"), defeat)]), 0) | |
120 | 120 | ||
121 | 121 | ||
122 | 122 | ||
123 | 123 | @Callable(i) | |
124 | 124 | func payWinner (matchId) = if (isDefined(getInteger(this, (matchId + "_paid")))) | |
125 | 125 | then throw("already paid") | |
126 | 126 | else { | |
127 | 127 | let betForId = extract(getString(this, (matchId + "_for"))) | |
128 | 128 | let betAgainstId = extract(getString(this, (matchId + "_against"))) | |
129 | 129 | let betForDefeated = isDefeated(betForId) | |
130 | 130 | let betAgainstDefeated = isDefeated(betAgainstId) | |
131 | 131 | if (if (!(betForDefeated)) | |
132 | 132 | then !(betAgainstDefeated) | |
133 | 133 | else false) | |
134 | 134 | then throw("no side approved defeat") | |
135 | 135 | else { | |
136 | 136 | let winnerId = if (betForDefeated) | |
137 | 137 | then betAgainstId | |
138 | 138 | else betForId | |
139 | 139 | let winnerAddress = getString(this, (winnerId + "_owner")) | |
140 | 140 | if ((winnerAddress != toBase58String(i.caller.bytes))) | |
141 | 141 | then throw("paywinner() should be called by winner only") | |
142 | 142 | else { | |
143 | 143 | let amount = extract(getInteger(this, (matchId + "_amount"))) | |
144 | 144 | repayFee(i, WriteSet([DataEntry((matchId + "_paid"), amount)]), amount) | |
145 | 145 | } | |
146 | 146 | } | |
147 | 147 | } | |
148 | 148 | ||
149 | 149 |
github/deemru/w8io/169f3d6 33.72 ms ◑