tx · 28foWu6uX7FoP1gvq6VwYKAJ78d4YrAk86Hxg5aHDbqU
3N9D8brsPwA8d2SWKxCKoG15TfAqjtp749H: -0.01400000 Waves
2020.09.16 13:44 [1179724] smart account 3N9D8brsPwA8d2SWKxCKoG15TfAqjtp749H > SELF 0.00000000 Waves
{
"type": 13,
"id": "28foWu6uX7FoP1gvq6VwYKAJ78d4YrAk86Hxg5aHDbqU",
"fee": 1400000,
"feeAssetId": null,
"timestamp": 1600253077054,
"version": 2,
"chainId": 84,
"sender": "3N9D8brsPwA8d2SWKxCKoG15TfAqjtp749H",
"senderPublicKey": "FpA31WAx86gMxdfoFSRBf8HbjDPaHre9SnjfE1rcjTSA",
"proofs": [
"4ZENv2D8gSxrQdf24EFXPs79FKA1dGV6ESaGDSSwJmYiHDjnbjDcfPr75GaWNEZLhEAbnk9KrtUSUxxkRjDURGup"
],
"script": "base64:AAIEAAAAAAAAAAkIAhIDCgEIEgAAAAADAAAAAAZOU0JUaWQJAAJZAAAAAQkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEHQAAAAIFAAAABHRoaXMCAAAABk5TQlRpZAIAAAAgTlNCVGlkIGlzIG5vdCBzcGVjaWZpZWQgaW4gc3RhdGUAAAAACWhlaWdodEVuZAkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEGgAAAAIFAAAABHRoaXMCAAAACmhlaWdodF9lbmQCAAAAJGhlaWdodF9lbmQgaXMgbm90IHNwZWNpZmllZCBpbiBzdGF0ZQEAAAAOa2V5VXNlckJhbGFuY2UAAAABAAAACHVzZXJBZGRyCQAEuQAAAAIJAARMAAAAAgIAAAAHYmFsYW5jZQkABEwAAAACCQAEJQAAAAEFAAAACHVzZXJBZGRyBQAAAANuaWwCAAAAAV8AAAACAAAACmNvbnRleHRPYmoBAAAACGNhc3RWb3RlAAAAAQAAAAR2b3RlBAAAAAh2b2l0ZUtleQkABLkAAAACCQAETAAAAAICAAAABXZvaXRlCQAETAA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2V5CQEAAAAOa2V5VXNlckJhbGFuY2UAAAABCAUAAAAKY29udGV4dE9iagAAAAZjYWxsZXIDCQAAZgAAAAIFAAAACWhlaWdodEVuZAUAAAAGaGVpZ2h0CQAAAgAAAAECAAAAD3ZvdGUgaW4gcHJvY2VzcwQAAAANY2FsbGVyQmFsYW5jZQkBAAAAC3ZhbHVlT3JFbHNlAAAAAgkABBoAAAACBQAAAAR0aGlzBQAAAA51c2VyQmFsYW5jZUtleQAAAAAAAAAAAAMJAABnAAAAAgAAAAAAAAAAAAUAAAANY2FsbGVyQmFsYW5jZQkAAAIAAAABAgAAABBiYWxhbmNlIGlzIGVtcHR5CQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAApjb250ZXh0T2JqAAAABmNhbGxlcgUAAAANY2FsbGVyQmFsYW5jZQUAAAAGTlNCVGlkCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACBQAAAA51c2VyQmFsYW5jZUtleQAAAAAAAAAAAAUAAAADbmlsAAAAAFzqsMs=",
"height": 1179724,
"applicationStatus": "succeeded",
"spentComplexity": 0
}
View: original | compacted
Prev: 7XkBHyiRnVhtGybv7sTvBbdykMC4njL1ZBaYUta5KHQB
Next: 2eCkQw2TszTB2JHCvoNW4Ewc4q5kbeZw6kykvMKMSwWE
Diff:
Old | New | | Differences |
---|
1 | 1 | | {-# STDLIB_VERSION 4 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let NSBTid = fromBase58String(getStringValue(this, "NSBTid")) |
---|
| 4 | + | let NSBTid = fromBase58String(valueOrErrorMessage(getString(this, "NSBTid"), "NSBTid is not specified in state")) |
---|
5 | 5 | | |
---|
6 | | - | let heightEnd = getIntegerValue(this, "height_end") |
---|
| 6 | + | let heightEnd = valueOrErrorMessage(getInteger(this, "height_end"), "height_end is not specified in state") |
---|
| 7 | + | |
---|
| 8 | + | func keyUserBalance (userAddr) = makeString(["balance", toString(userAddr)], "_") |
---|
| 9 | + | |
---|
7 | 10 | | |
---|
8 | 11 | | @Callable(contextObj) |
---|
9 | 12 | | func castVote (vote) = { |
---|
10 | 13 | | let voiteKey = makeString(["voite", vote], "_") |
---|
11 | | - | let userBalanceKey = makeString(["balance", toString(contextObj.caller)], "_") |
---|
| 14 | + | let userBalanceKey = keyUserBalance(contextObj.caller) |
---|
12 | 15 | | let payment = value(contextObj.payments[0]) |
---|
13 | 16 | | let assetIdReceived = payment.assetId |
---|
14 | 17 | | let tokenReceiveAmount = payment.amount |
---|
15 | | - | let voteNumberThis = match getInteger(this, voiteKey) { |
---|
16 | | - | case voteValue: Int => |
---|
17 | | - | voteValue |
---|
18 | | - | case voteValue: Unit => |
---|
19 | | - | 0 |
---|
20 | | - | case _ => |
---|
21 | | - | throw("Match error") |
---|
22 | | - | } |
---|
23 | | - | let contractUserBalance = match getInteger(this, userBalanceKey) { |
---|
24 | | - | case balance: Int => |
---|
25 | | - | balance |
---|
26 | | - | case balance: Unit => |
---|
27 | | - | 0 |
---|
28 | | - | case _ => |
---|
29 | | - | throw("Match error") |
---|
30 | | - | } |
---|
| 18 | + | let voteNumberThis = valueOrElse(getInteger(this, voiteKey), 0) |
---|
| 19 | + | let contractUserBalance = valueOrElse(getInteger(this, userBalanceKey), 0) |
---|
31 | 20 | | if ((assetIdReceived != NSBTid)) |
---|
32 | 21 | | then throw("incorrect assets") |
---|
33 | 22 | | else if ((height >= heightEnd)) |
---|
34 | 23 | | then throw("vote finished") |
---|
35 | | - | else [IntegerEntry(voiteKey, (voteNumberThis + tokenReceiveAmount)), IntegerEntry(userBalanceKey, tokenReceiveAmount)] |
---|
| 24 | + | else [IntegerEntry(voiteKey, (voteNumberThis + tokenReceiveAmount)), IntegerEntry(userBalanceKey, (contractUserBalance + tokenReceiveAmount))] |
---|
36 | 25 | | } |
---|
37 | 26 | | |
---|
38 | 27 | | |
---|
39 | 28 | | |
---|
40 | 29 | | @Callable(contextObj) |
---|
41 | 30 | | func withdraw () = { |
---|
42 | | - | let userBalanceKey = makeString(["balance", toString(contextObj.caller)], "_") |
---|
| 31 | + | let userBalanceKey = keyUserBalance(contextObj.caller) |
---|
43 | 32 | | if ((heightEnd > height)) |
---|
44 | 33 | | then throw("vote in process") |
---|
45 | 34 | | else { |
---|
46 | | - | let callerBalance = getIntegerValue(this, userBalanceKey) |
---|
47 | | - | [ScriptTransfer(contextObj.caller, callerBalance, NSBTid), IntegerEntry(userBalanceKey, 0)] |
---|
| 35 | + | let callerBalance = valueOrElse(getInteger(this, userBalanceKey), 0) |
---|
| 36 | + | if ((0 >= callerBalance)) |
---|
| 37 | + | then throw("balance is empty") |
---|
| 38 | + | else [ScriptTransfer(contextObj.caller, callerBalance, NSBTid), IntegerEntry(userBalanceKey, 0)] |
---|
48 | 39 | | } |
---|
49 | 40 | | } |
---|
50 | 41 | | |
---|
Full:
Old | New | | Differences |
---|
1 | 1 | | {-# STDLIB_VERSION 4 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let NSBTid = fromBase58String(getStringValue(this, "NSBTid")) |
---|
| 4 | + | let NSBTid = fromBase58String(valueOrErrorMessage(getString(this, "NSBTid"), "NSBTid is not specified in state")) |
---|
5 | 5 | | |
---|
6 | | - | let heightEnd = getIntegerValue(this, "height_end") |
---|
| 6 | + | let heightEnd = valueOrErrorMessage(getInteger(this, "height_end"), "height_end is not specified in state") |
---|
| 7 | + | |
---|
| 8 | + | func keyUserBalance (userAddr) = makeString(["balance", toString(userAddr)], "_") |
---|
| 9 | + | |
---|
7 | 10 | | |
---|
8 | 11 | | @Callable(contextObj) |
---|
9 | 12 | | func castVote (vote) = { |
---|
10 | 13 | | let voiteKey = makeString(["voite", vote], "_") |
---|
11 | | - | let userBalanceKey = makeString(["balance", toString(contextObj.caller)], "_") |
---|
| 14 | + | let userBalanceKey = keyUserBalance(contextObj.caller) |
---|
12 | 15 | | let payment = value(contextObj.payments[0]) |
---|
13 | 16 | | let assetIdReceived = payment.assetId |
---|
14 | 17 | | let tokenReceiveAmount = payment.amount |
---|
15 | | - | let voteNumberThis = match getInteger(this, voiteKey) { |
---|
16 | | - | case voteValue: Int => |
---|
17 | | - | voteValue |
---|
18 | | - | case voteValue: Unit => |
---|
19 | | - | 0 |
---|
20 | | - | case _ => |
---|
21 | | - | throw("Match error") |
---|
22 | | - | } |
---|
23 | | - | let contractUserBalance = match getInteger(this, userBalanceKey) { |
---|
24 | | - | case balance: Int => |
---|
25 | | - | balance |
---|
26 | | - | case balance: Unit => |
---|
27 | | - | 0 |
---|
28 | | - | case _ => |
---|
29 | | - | throw("Match error") |
---|
30 | | - | } |
---|
| 18 | + | let voteNumberThis = valueOrElse(getInteger(this, voiteKey), 0) |
---|
| 19 | + | let contractUserBalance = valueOrElse(getInteger(this, userBalanceKey), 0) |
---|
31 | 20 | | if ((assetIdReceived != NSBTid)) |
---|
32 | 21 | | then throw("incorrect assets") |
---|
33 | 22 | | else if ((height >= heightEnd)) |
---|
34 | 23 | | then throw("vote finished") |
---|
35 | | - | else [IntegerEntry(voiteKey, (voteNumberThis + tokenReceiveAmount)), IntegerEntry(userBalanceKey, tokenReceiveAmount)] |
---|
| 24 | + | else [IntegerEntry(voiteKey, (voteNumberThis + tokenReceiveAmount)), IntegerEntry(userBalanceKey, (contractUserBalance + tokenReceiveAmount))] |
---|
36 | 25 | | } |
---|
37 | 26 | | |
---|
38 | 27 | | |
---|
39 | 28 | | |
---|
40 | 29 | | @Callable(contextObj) |
---|
41 | 30 | | func withdraw () = { |
---|
42 | | - | let userBalanceKey = makeString(["balance", toString(contextObj.caller)], "_") |
---|
| 31 | + | let userBalanceKey = keyUserBalance(contextObj.caller) |
---|
43 | 32 | | if ((heightEnd > height)) |
---|
44 | 33 | | then throw("vote in process") |
---|
45 | 34 | | else { |
---|
46 | | - | let callerBalance = getIntegerValue(this, userBalanceKey) |
---|
47 | | - | [ScriptTransfer(contextObj.caller, callerBalance, NSBTid), IntegerEntry(userBalanceKey, 0)] |
---|
| 35 | + | let callerBalance = valueOrElse(getInteger(this, userBalanceKey), 0) |
---|
| 36 | + | if ((0 >= callerBalance)) |
---|
| 37 | + | then throw("balance is empty") |
---|
| 38 | + | else [ScriptTransfer(contextObj.caller, callerBalance, NSBTid), IntegerEntry(userBalanceKey, 0)] |
---|
48 | 39 | | } |
---|
49 | 40 | | } |
---|
50 | 41 | | |
---|
51 | 42 | | |
---|