tx · 5q7NqzRNaUknEiir5JFQtCPkKaHdz5q1pHMt8r7bUzVx 3MsmgWBZKrHwbVbSQiqmStRiFyg5hkfxxa2: -0.00300000 Waves 2022.08.16 17:08 [2187131] smart account 3MsmgWBZKrHwbVbSQiqmStRiFyg5hkfxxa2 > SELF 0.00000000 Waves
{ "type": 13, "id": "5q7NqzRNaUknEiir5JFQtCPkKaHdz5q1pHMt8r7bUzVx", "fee": 300000, "feeAssetId": null, "timestamp": 1660658891025, "version": 2, "chainId": 84, "sender": "3MsmgWBZKrHwbVbSQiqmStRiFyg5hkfxxa2", "senderPublicKey": "9TejtrnvgE7MvzMR4DcLbf3dqUzovyt4BKEmCsqha2z", "proofs": [ "5PvBHS9RrqeM2AQR5bxKHWver1qTP1d2ZtLkMEnkbfx6nT5RZhPTtwRShgrj2uy4PakkXzUyMymXGAxKzjmZZa2p" ], "script": "base64:AAIFAAAAAAAAAAcIAhIDCgEIAAAACQAAAAAJaGVpZ2h0RW5kCQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQaAAAAAgUAAAAEdGhpcwIAAAAKaGVpZ2h0X2VuZAIAAAAkaGVpZ2h0X2VuZCBpcyBub3Qgc3BlY2lmaWVkIGluIHN0YXRlAAAAAAxhc3NldHNTdHJpbmcJAQAAABN2YWx1ZU9yRXJyb3JNZXNzYWdlAAAAAgkABB0AAAACBQAAAAR0aGlzAgAAABBhdmFpbGFibGVfYXNzZXRzAgAAACVBc3NldHMgbGlzdCBpcyBub3Qgc3BlY2lmaWVkIGluIHN0YXRlAQAAAAlhc0FueUxpc3QAAAABAAAAA3ZhbAQAAAAHJG1hdGNoMAUAAAADdmFsAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAlMaXN0W0FueV0EAAAACnZhbEFueUx5c3QFAAAAByRtYXRjaDAFAAAACnZhbEFueUx5c3QJAAACAAAAAQIAAAAbZmFpbCB0byBjYXN0IGludG8gTGlzdFtBbnldAQAAAAVhc0ludAAAAAEAAAADdm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d2VyS0VZBQAAABJuZXdVc2VyVm90aW5nUG93ZXIJAARMAAAAAgkBAAAAC1N0cmluZ0VudHJ5AAAAAgUAAAARcHJldlVzZXJDaG9pY2VLRVkFAAAADW5ld1VzZXJDaG9pY2UFAAAAA25pbAAAAACsLJ9i", "height": 2187131, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: HaM2bFQuteMT4pz8zqMq3W448jdq8UkiLqNXSj1dmWej Next: HmvHufMZAcVfrfdrQTyhJBEXQRXuSaBsKjYBvFJYxoDC Diff:
Old | New | Differences | |
---|---|---|---|
5 | 5 | ||
6 | 6 | let assetsString = valueOrErrorMessage(getString(this, "available_assets"), "Assets list is not specified in state") | |
7 | 7 | ||
8 | - | func asSwapParamsSTRUCT (val) = match val { | |
9 | - | case struct: (Int, Int, Int, Int, Int) => | |
10 | - | struct | |
8 | + | func asAnyList (val) = match val { | |
9 | + | case valAnyLyst: List[Any] => | |
10 | + | valAnyLyst | |
11 | + | case _ => | |
12 | + | throw("fail to cast into List[Any]") | |
13 | + | } | |
14 | + | ||
15 | + | ||
16 | + | func asInt (val) = match val { | |
17 | + | case valInt: Int => | |
18 | + | valInt | |
11 | 19 | case _ => | |
12 | 20 | throw("fail to cast into Int") | |
13 | 21 | } | |
14 | 22 | ||
15 | 23 | ||
16 | - | let | |
24 | + | let nsbtStakingContract = Address(base58'3MuGfNhF98CNBCfthhoJEo6SYUv7zTgkK4J') | |
17 | 25 | ||
18 | - | let | |
26 | + | let availableVotes = split(assetsString, ",") | |
19 | 27 | ||
20 | 28 | func keyUserBalance (userAddr) = makeString(["balance", toString(userAddr)], "_") | |
21 | 29 | ||
22 | 30 | ||
23 | - | func keyUserVoteKey (userAddr,vote) = makeString(["vote", userAddr, vote], "_") | |
31 | + | func keyUserVote (userAddr,vote) = makeString(["vote", userAddr, vote], "_") | |
32 | + | ||
33 | + | ||
34 | + | func keyUserLastVote (userAddr) = makeString(["last_vote", userAddr], "_") | |
24 | 35 | ||
25 | 36 | ||
26 | 37 | @Callable(contextObj) | |
27 | - | func castVote (vote) = if ((containsElement(assets, vote) == false)) | |
28 | - | then throw("Incorrect vote!") | |
29 | - | else { | |
30 | - | let totalVoteKey = makeString(["vote", vote], "_") | |
31 | - | let userVoteKey = keyUserVoteKey(toString(contextObj.caller), vote) | |
32 | - | let $t011001294 = asSwapParamsSTRUCT(invoke(neutrinoContract, "swapParamsByUserSYSREADONLY", [toString(contextObj.caller), 0], nil)) | |
33 | - | let limitMaxUsdn = $t011001294._1 | |
34 | - | let limitSpent = $t011001294._2 | |
35 | - | let blcks2LmtReset = $t011001294._3 | |
36 | - | let gnsbtAmt = $t011001294._4 | |
37 | - | let gnsbtAmtTotal = $t011001294._5 | |
38 | - | let userVotingAmount = gnsbtAmt | |
39 | - | let voteTotalAmount = valueOrElse(getInteger(this, totalVoteKey), 0) | |
40 | - | let voteByUserAmount = valueOrElse(getInteger(this, userVoteKey), 0) | |
41 | - | if ((height >= heightEnd)) | |
38 | + | func castVote (newUserChoice) = { | |
39 | + | let userAddress = toString(contextObj.caller) | |
40 | + | if ((containsElement(availableVotes, newUserChoice) == false)) | |
41 | + | then throw("Incorrect vote!") | |
42 | + | else if ((height >= heightEnd)) | |
42 | 43 | then throw("vote finished") | |
43 | - | else [IntegerEntry(totalVoteKey, ((voteTotalAmount + userVotingAmount) - voteByUserAmount)), IntegerEntry(userVoteKey, userVotingAmount)] | |
44 | - | } | |
44 | + | else { | |
45 | + | let nsbtData = asAnyList(invoke(nsbtStakingContract, "nsbtStakingSYSREADONLY", [userAddress], nil)) | |
46 | + | let newUserVotingPower = asInt(nsbtData[0]) | |
47 | + | let newTotalByChoiceKEY = makeString(["vote", newUserChoice], "_") | |
48 | + | let newTotalByChoiceAmount = valueOrElse(getInteger(this, newTotalByChoiceKEY), 0) | |
49 | + | let newUserVotingPowerKEY = keyUserVote(userAddress, newUserChoice) | |
50 | + | let prevUserChoiceKEY = keyUserLastVote(userAddress) | |
51 | + | let prevUserChoice = valueOrElse(getString(this, prevUserChoiceKEY), newUserChoice) | |
52 | + | let prevUserVotingPowerKEY = keyUserVote(userAddress, prevUserChoice) | |
53 | + | let prevUserVotingPower = valueOrElse(getInteger(this, prevUserVotingPowerKEY), 0) | |
54 | + | let prevTotalByChoiceKEY = makeString(["vote", prevUserChoice], "_") | |
55 | + | let prevTotalByChoiceAmount = valueOrElse(getInteger(this, prevTotalByChoiceKEY), 0) | |
56 | + | let refreshTotals = if ((prevUserChoice != newUserChoice)) | |
57 | + | then [IntegerEntry(prevUserVotingPowerKEY, 0), IntegerEntry(prevTotalByChoiceKEY, (prevTotalByChoiceAmount - prevUserVotingPower)), IntegerEntry(newTotalByChoiceKEY, (newTotalByChoiceAmount + newUserVotingPower))] | |
58 | + | else [IntegerEntry(newTotalByChoiceKEY, ((newTotalByChoiceAmount + newUserVotingPower) - prevUserVotingPower))] | |
59 | + | (refreshTotals ++ [IntegerEntry(newUserVotingPowerKEY, newUserVotingPower), StringEntry(prevUserChoiceKEY, newUserChoice)]) | |
60 | + | } | |
61 | + | } | |
45 | 62 | ||
46 | 63 |
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 | - | func asSwapParamsSTRUCT (val) = match val { | |
9 | - | case struct: (Int, Int, Int, Int, Int) => | |
10 | - | struct | |
8 | + | func asAnyList (val) = match val { | |
9 | + | case valAnyLyst: List[Any] => | |
10 | + | valAnyLyst | |
11 | + | case _ => | |
12 | + | throw("fail to cast into List[Any]") | |
13 | + | } | |
14 | + | ||
15 | + | ||
16 | + | func asInt (val) = match val { | |
17 | + | case valInt: Int => | |
18 | + | valInt | |
11 | 19 | case _ => | |
12 | 20 | throw("fail to cast into Int") | |
13 | 21 | } | |
14 | 22 | ||
15 | 23 | ||
16 | - | let | |
24 | + | let nsbtStakingContract = Address(base58'3MuGfNhF98CNBCfthhoJEo6SYUv7zTgkK4J') | |
17 | 25 | ||
18 | - | let | |
26 | + | let availableVotes = split(assetsString, ",") | |
19 | 27 | ||
20 | 28 | func keyUserBalance (userAddr) = makeString(["balance", toString(userAddr)], "_") | |
21 | 29 | ||
22 | 30 | ||
23 | - | func keyUserVoteKey (userAddr,vote) = makeString(["vote", userAddr, vote], "_") | |
31 | + | func keyUserVote (userAddr,vote) = makeString(["vote", userAddr, vote], "_") | |
32 | + | ||
33 | + | ||
34 | + | func keyUserLastVote (userAddr) = makeString(["last_vote", userAddr], "_") | |
24 | 35 | ||
25 | 36 | ||
26 | 37 | @Callable(contextObj) | |
27 | - | func castVote (vote) = if ((containsElement(assets, vote) == false)) | |
28 | - | then throw("Incorrect vote!") | |
29 | - | else { | |
30 | - | let totalVoteKey = makeString(["vote", vote], "_") | |
31 | - | let userVoteKey = keyUserVoteKey(toString(contextObj.caller), vote) | |
32 | - | let $t011001294 = asSwapParamsSTRUCT(invoke(neutrinoContract, "swapParamsByUserSYSREADONLY", [toString(contextObj.caller), 0], nil)) | |
33 | - | let limitMaxUsdn = $t011001294._1 | |
34 | - | let limitSpent = $t011001294._2 | |
35 | - | let blcks2LmtReset = $t011001294._3 | |
36 | - | let gnsbtAmt = $t011001294._4 | |
37 | - | let gnsbtAmtTotal = $t011001294._5 | |
38 | - | let userVotingAmount = gnsbtAmt | |
39 | - | let voteTotalAmount = valueOrElse(getInteger(this, totalVoteKey), 0) | |
40 | - | let voteByUserAmount = valueOrElse(getInteger(this, userVoteKey), 0) | |
41 | - | if ((height >= heightEnd)) | |
38 | + | func castVote (newUserChoice) = { | |
39 | + | let userAddress = toString(contextObj.caller) | |
40 | + | if ((containsElement(availableVotes, newUserChoice) == false)) | |
41 | + | then throw("Incorrect vote!") | |
42 | + | else if ((height >= heightEnd)) | |
42 | 43 | then throw("vote finished") | |
43 | - | else [IntegerEntry(totalVoteKey, ((voteTotalAmount + userVotingAmount) - voteByUserAmount)), IntegerEntry(userVoteKey, userVotingAmount)] | |
44 | - | } | |
44 | + | else { | |
45 | + | let nsbtData = asAnyList(invoke(nsbtStakingContract, "nsbtStakingSYSREADONLY", [userAddress], nil)) | |
46 | + | let newUserVotingPower = asInt(nsbtData[0]) | |
47 | + | let newTotalByChoiceKEY = makeString(["vote", newUserChoice], "_") | |
48 | + | let newTotalByChoiceAmount = valueOrElse(getInteger(this, newTotalByChoiceKEY), 0) | |
49 | + | let newUserVotingPowerKEY = keyUserVote(userAddress, newUserChoice) | |
50 | + | let prevUserChoiceKEY = keyUserLastVote(userAddress) | |
51 | + | let prevUserChoice = valueOrElse(getString(this, prevUserChoiceKEY), newUserChoice) | |
52 | + | let prevUserVotingPowerKEY = keyUserVote(userAddress, prevUserChoice) | |
53 | + | let prevUserVotingPower = valueOrElse(getInteger(this, prevUserVotingPowerKEY), 0) | |
54 | + | let prevTotalByChoiceKEY = makeString(["vote", prevUserChoice], "_") | |
55 | + | let prevTotalByChoiceAmount = valueOrElse(getInteger(this, prevTotalByChoiceKEY), 0) | |
56 | + | let refreshTotals = if ((prevUserChoice != newUserChoice)) | |
57 | + | then [IntegerEntry(prevUserVotingPowerKEY, 0), IntegerEntry(prevTotalByChoiceKEY, (prevTotalByChoiceAmount - prevUserVotingPower)), IntegerEntry(newTotalByChoiceKEY, (newTotalByChoiceAmount + newUserVotingPower))] | |
58 | + | else [IntegerEntry(newTotalByChoiceKEY, ((newTotalByChoiceAmount + newUserVotingPower) - prevUserVotingPower))] | |
59 | + | (refreshTotals ++ [IntegerEntry(newUserVotingPowerKEY, newUserVotingPower), StringEntry(prevUserChoiceKEY, newUserChoice)]) | |
60 | + | } | |
61 | + | } | |
45 | 62 | ||
46 | 63 |
github/deemru/w8io/169f3d6 37.65 ms ◑