tx · EXzUheFWnL8SopRFx29XiqEfy5YWeJ73AR8HJ6GjAqMV 3MsmgWBZKrHwbVbSQiqmStRiFyg5hkfxxa2: -0.00300000 Waves 2022.08.17 11:20 [2188222] smart account 3MsmgWBZKrHwbVbSQiqmStRiFyg5hkfxxa2 > SELF 0.00000000 Waves
{ "type": 13, "id": "EXzUheFWnL8SopRFx29XiqEfy5YWeJ73AR8HJ6GjAqMV", "fee": 300000, "feeAssetId": null, "timestamp": 1660724359821, "version": 2, "chainId": 84, "sender": "3MsmgWBZKrHwbVbSQiqmStRiFyg5hkfxxa2", "senderPublicKey": "9TejtrnvgE7MvzMR4DcLbf3dqUzovyt4BKEmCsqha2z", "proofs": [ "3BmDBNZxwLACGx7NKWHXgQac4s8uZmtH8wBPjkJDff8hHXRttFowKafZxGafC4D8KL8J9WyrHGCovMDmsfMGkJsm" ], "script": "base64:AAIFAAAAAAAAAAcIAhIDCgEIAAAACQAAAAAJaGVpZ2h0RW5kCQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQaAAAAAgUAAAAEdGhpcwIAAAAKaGVpZ2h0X2VuZAIAAAAkaGVpZ2h0X2VuZCBpcyBub3Qgc3BlY2lmaWVkIGluIHN0YXRlAAAAAAxhc3NldHNTdHJpbmcJAQAAABN2YWx1ZU9yRXJyb3JNZXNzYWdlAAAAAgkABB0AAAACBQAAAAR0aGlzAgAAABBhdmFpbGFibGVfYXNzZXRzAgAAACVBc3NldHMgbGlzdCBpcyBub3Qgc3BlY2lmaWVkIGluIHN0YXRlAQAAAAlhc0FueUxpc3QAAAABAAAAA3ZhbAQAAAAHJG1hdGNoMAUAAAADdmFsAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAlMaXN0W0FueV0EAAAACnZhbEFueUx5c3QFAAAAByRtYXRjaDAFAAAACnZhbEFueUx5c3QJAAACAAAAAQIAAAAbZmFpbCB0byBjYXN0IGludG8gTGlzdFtBbnldAQAAAAVhc0ludAAAAAEAAAADdmFsBAA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JLRVkFAAAAEm5ld1VzZXJWb3RpbmdQb3dlcgkABEwAAAACCQEAAAALU3RyaW5nRW50cnkAAAACBQAAABFwcmV2VXNlckNob2ljZUtFWQUAAAANbmV3VXNlckNob2ljZQUAAAADbmlsAAAAAGbnIx0=", "height": 2188222, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 8DhSBHjrM1Ce9718nfVUbWj3hWfGMS51SQ5VoBUpZVHT Next: 313i8e9KiMVPaArpQ9HjvgdzfDhzDqFi9zEKs52w8pJh Full:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let heightEnd = valueOrErrorMessage(getInteger(this, "height_end"), "height_end is not specified in state") | |
5 | 5 | ||
6 | 6 | let assetsString = valueOrErrorMessage(getString(this, "available_assets"), "Assets list is not specified in state") | |
7 | 7 | ||
8 | 8 | func asAnyList (val) = match val { | |
9 | 9 | case valAnyLyst: List[Any] => | |
10 | 10 | valAnyLyst | |
11 | 11 | case _ => | |
12 | 12 | throw("fail to cast into List[Any]") | |
13 | 13 | } | |
14 | 14 | ||
15 | 15 | ||
16 | 16 | func asInt (val) = match val { | |
17 | 17 | case valInt: Int => | |
18 | 18 | valInt | |
19 | 19 | case _ => | |
20 | 20 | throw("fail to cast into Int") | |
21 | 21 | } | |
22 | 22 | ||
23 | 23 | ||
24 | 24 | let nsbtStakingContract = Address(base58'3MuGfNhF98CNBCfthhoJEo6SYUv7zTgkK4J') | |
25 | 25 | ||
26 | 26 | let availableVotes = split(assetsString, ",") | |
27 | 27 | ||
28 | 28 | func keyUserBalance (userAddr) = makeString(["balance", toString(userAddr)], "_") | |
29 | 29 | ||
30 | 30 | ||
31 | 31 | func keyUserVote (userAddr,vote) = makeString(["vote", userAddr, vote], "_") | |
32 | 32 | ||
33 | 33 | ||
34 | 34 | func keyUserLastVote (userAddr) = makeString(["last_vote", userAddr], "_") | |
35 | 35 | ||
36 | 36 | ||
37 | 37 | @Callable(contextObj) | |
38 | 38 | func castVote (newUserChoice) = { | |
39 | 39 | let userAddress = toString(contextObj.caller) | |
40 | 40 | if ((containsElement(availableVotes, newUserChoice) == false)) | |
41 | 41 | then throw("Incorrect vote!") | |
42 | 42 | else if ((height >= heightEnd)) | |
43 | 43 | then throw("vote finished") | |
44 | 44 | else { | |
45 | 45 | let nsbtData = asAnyList(invoke(nsbtStakingContract, "nsbtStakingSYSREADONLY", [userAddress, 0], nil)) | |
46 | 46 | let newUserVotingPower = asInt(nsbtData[0]) | |
47 | 47 | let newTotalByChoiceKEY = makeString(["vote", newUserChoice], "_") | |
48 | 48 | let newTotalByChoiceAmount = valueOrElse(getInteger(this, newTotalByChoiceKEY), 0) | |
49 | 49 | let newUserVotingPowerKEY = keyUserVote(userAddress, newUserChoice) | |
50 | 50 | let prevUserChoiceKEY = keyUserLastVote(userAddress) | |
51 | 51 | let prevUserChoice = valueOrElse(getString(this, prevUserChoiceKEY), newUserChoice) | |
52 | 52 | let prevUserVotingPowerKEY = keyUserVote(userAddress, prevUserChoice) | |
53 | 53 | let prevUserVotingPower = valueOrElse(getInteger(this, prevUserVotingPowerKEY), 0) | |
54 | 54 | let prevTotalByChoiceKEY = makeString(["vote", prevUserChoice], "_") | |
55 | 55 | let prevTotalByChoiceAmount = valueOrElse(getInteger(this, prevTotalByChoiceKEY), 0) | |
56 | 56 | let refreshTotals = if ((prevUserChoice != newUserChoice)) | |
57 | 57 | then [IntegerEntry(prevUserVotingPowerKEY, 0), IntegerEntry(prevTotalByChoiceKEY, (prevTotalByChoiceAmount - prevUserVotingPower)), IntegerEntry(newTotalByChoiceKEY, (newTotalByChoiceAmount + newUserVotingPower))] | |
58 | 58 | else [IntegerEntry(newTotalByChoiceKEY, ((newTotalByChoiceAmount + newUserVotingPower) - prevUserVotingPower))] | |
59 | 59 | (refreshTotals ++ [IntegerEntry(newUserVotingPowerKEY, newUserVotingPower), StringEntry(prevUserChoiceKEY, newUserChoice)]) | |
60 | 60 | } | |
61 | 61 | } | |
62 | 62 | ||
63 | 63 |
github/deemru/w8io/026f985 39.32 ms ◑