tx · 9h1uafVJvoW2FUrsSxkAoJFm9Ev218gHdCjjfiaPiATT

3N32QbJF1pDejuzw5FM8unvXQXc5zX87Zb2:  -0.01400000 Waves

2020.11.20 15:54 [1273729] smart account 3N32QbJF1pDejuzw5FM8unvXQXc5zX87Zb2 > SELF 0.00000000 Waves

{ "type": 13, "id": "9h1uafVJvoW2FUrsSxkAoJFm9Ev218gHdCjjfiaPiATT", "fee": 1400000, "feeAssetId": null, "timestamp": 1605876943196, "version": 2, "chainId": 84, "sender": "3N32QbJF1pDejuzw5FM8unvXQXc5zX87Zb2", "senderPublicKey": "2PA1oQvC1quDzHm25JdQxgYwtcgNzQRwiQnxsrZfZkS5", "proofs": [ "55cYywmmCwwYz1ktyZZZTbHgm68JAWWHFaHuesCkBUpqCra1gRHcM7pZp47GNjbVZAuxxRkwmGaXG45Gd8Jqb8wd" ], "script": "base64:AAIEAAAAAAAAAAkIAhIAEgMKAQEAAAACAAAAAAVBU1NFVAEAAAAg4OwO9gENCpf9SP+B5fslNY80EzM1mPg9HV7xNNg/ujEBAAAADmN1cnJlbnRCYWxhbmNlAAAAAQAAAAR1c2VyBAAAAAdiYWxhbmNlCQAEGgAAAAIFAAAABHRoaXMJAAEsAAAAAgIAAAAIZGVwb3NpdF8FAAAABHVzZXIEAAAAByRtYXRjaDAFAAAAB2JhbGFuY2UDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYgUAAAAHJG1hdGNoMAUAAAABYgAAAAAAAAAAAAAAAAIAAAABaQEAAAAHZGVwb3NpdAAAAAAEAAAABHVzZXIJAAJYAAAAAQgIBQAAAAFpAAAABmNhbGxlcgAAAAVieXRlcwQAAAAHcGF5bWVudAkBAAAABXZhbHVlAAAAAQkAAZEAAAACCAUAAAABaQAAAAhwYXltZW50cwAAAAAAAAAAAAMJAABmAAAAAgAAAAAAAAAAAAgFAAAAB3BheW1lbnQAAAAGYW1vdW50CQAAAgAAAAECAAAAElBheW1lbnQgaXMgdG9vIGxvdwMJAQAAAAIhPQAAAAIIBQAAAAdwYXltZW50AAAAB2Fzc2V0SWQFAAAABUFTU0VUCQAAAgAAAAECAAAAFkFzc2V0SWQgaXMgbm90IGNvcnJlY3QJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAAEsAAAAAgIAAAAIZGVwb3NpdF8FAAAABHVzZXIJAABkAAAAAgkBAAAADmN1cnJlbnRCYWxhbmNlAAAAAQUAAAAEdXNlcggFAAAAB3BheW1lbnQAAAAGYW1vdW50BQAAAANuaWwAAAABaQEAAAAId2l0aGRyYXcAAAABAAAABmFtb3VudAQAAAAEdXNlcgkAAlgAAAABCAgFAAAAAWkAAAAGY2FsbGVyAAAABWJ5dGVzBAAAAAdiYWxhbmNlCQEAAAAOY3VycmVudEJhbGFuY2UAAAABBQAAAAR1c2VyAwkAAGYAAAACBQAAAAZhbW91bnQFAAAAB2JhbGFuY2UJAAACAAAAAQIAAAAcUmVxdWVzdGVkIGFtb3VudCBpcyB0b28gaGlnaAkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgkAASwAAAACAgAAAAhkZXBvc2l0XwUAAAAEdXNlcgkAAGUAAAACBQAAAAdiYWxhbmNlBQAAAAZhbW91bnQJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAAAWkAAAAGY2FsbGVyBQAAAAZhbW91bnQFAAAABUFTU0VUBQAAAANuaWwAAAABAAAAAnR4AQAAAAZ2ZXJpZnkAAAAABvrMvLs=", "height": 1273729, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: ARiymX3UWrnkSi8wvRc765vTPH627yW5YEp6kru9ZeUH Next: 2US99PDQTeJDwjuQw1b57iNrLvqQuFxUsKB3VN9z6jPQ Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 4 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let VOTERS = 3
4+let ASSET = base58'G916YXvaQChYqtVv54XZhJdgqsX6DkUACHAcq1fBe9JG'
55
6-let VOTING = "VOTING"
7-
8-let REVEAL = "REVEAL"
9-
10-let FINISHED = "FINISHED"
11-
12-func getCommitsCount () = {
13- let count = getInteger(this, "commits_count")
14- match count {
15- case count: Int =>
16- count
6+func currentBalance (user) = {
7+ let balance = getInteger(this, ("deposit_" + user))
8+ match balance {
9+ case b: Int =>
10+ b
1711 case _ =>
1812 0
1913 }
2014 }
2115
2216
23-func getRevealsCount () = {
24- let count = getInteger(this, "reveals_count")
25- match count {
26- case count: Int =>
27- count
28- case _ =>
29- 0
30- }
31- }
32-
33-
34-func getVotingStatus () = {
35- let status = getString(this, "voting_status")
36- match status {
37- case status: String =>
38- status
39- case _ =>
40- VOTING
41- }
42- }
43-
44-
45-func voteExists (address) = isDefined(getString(this, ("commit_" + address)))
46-
47-
48-func revealExists (address) = isDefined(getString(this, ("reveal_" + address)))
49-
50-
51-func validateVote (address,vote,salt) = {
52- let hash = getString(this, ("commit_" + address))
53- if (!(isDefined(hash)))
54- then false
55- else (toBase58String(sha256(toBytes((vote + salt)))) == hash)
56- }
57-
58-
5917 @Callable(i)
60-func commit (hash) = {
18+func deposit () = {
6119 let user = toBase58String(i.caller.bytes)
62- let commitsCount = getCommitsCount()
63- let nextStatus = if (((commitsCount + 1) == VOTERS))
64- then REVEAL
65- else VOTING
66- if ((commitsCount == VOTERS))
67- then throw("Max number of voters reached")
68- else if (voteExists(user))
69- then throw("User already voted")
70- else if ((getVotingStatus() != VOTING))
71- then throw("Voting is disabled")
72- else [StringEntry(("commit_" + user), hash), IntegerEntry("commits_count", (commitsCount + 1)), StringEntry("voting_status", nextStatus)]
20+ let payment = value(i.payments[0])
21+ if ((0 > payment.amount))
22+ then throw("Payment is too low")
23+ else if ((payment.assetId != ASSET))
24+ then throw("AssetId is not correct")
25+ else [IntegerEntry(("deposit_" + user), (currentBalance(user) + payment.amount))]
7326 }
7427
7528
7629
7730 @Callable(i)
78-func reveal (vote,salt) = {
31+func withdraw (amount) = {
7932 let user = toBase58String(i.caller.bytes)
80- let revealsCount = getRevealsCount()
81- let votingStatus = getVotingStatus()
82- let nextStatus = if (((revealsCount + 1) == VOTERS))
83- then FINISHED
84- else REVEAL
85- if ((votingStatus == VOTING))
86- then throw("Voting has not finished yet")
87- else if ((votingStatus == FINISHED))
88- then throw("Voting is finished")
89- else if (revealExists(user))
90- then throw("You already revealed vote")
91- else if (!(validateVote(user, vote, salt)))
92- then throw("Vote is not valid")
93- else [StringEntry(("reveal_" + user), vote), IntegerEntry("reveals_count", (revealsCount + 1)), StringEntry("voting_status", nextStatus)]
33+ let balance = currentBalance(user)
34+ if ((amount > balance))
35+ then throw("Requested amount is too high")
36+ else [IntegerEntry(("deposit_" + user), (balance - amount)), ScriptTransfer(i.caller, amount, ASSET)]
9437 }
9538
9639
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 4 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let VOTERS = 3
4+let ASSET = base58'G916YXvaQChYqtVv54XZhJdgqsX6DkUACHAcq1fBe9JG'
55
6-let VOTING = "VOTING"
7-
8-let REVEAL = "REVEAL"
9-
10-let FINISHED = "FINISHED"
11-
12-func getCommitsCount () = {
13- let count = getInteger(this, "commits_count")
14- match count {
15- case count: Int =>
16- count
6+func currentBalance (user) = {
7+ let balance = getInteger(this, ("deposit_" + user))
8+ match balance {
9+ case b: Int =>
10+ b
1711 case _ =>
1812 0
1913 }
2014 }
2115
2216
23-func getRevealsCount () = {
24- let count = getInteger(this, "reveals_count")
25- match count {
26- case count: Int =>
27- count
28- case _ =>
29- 0
30- }
31- }
32-
33-
34-func getVotingStatus () = {
35- let status = getString(this, "voting_status")
36- match status {
37- case status: String =>
38- status
39- case _ =>
40- VOTING
41- }
42- }
43-
44-
45-func voteExists (address) = isDefined(getString(this, ("commit_" + address)))
46-
47-
48-func revealExists (address) = isDefined(getString(this, ("reveal_" + address)))
49-
50-
51-func validateVote (address,vote,salt) = {
52- let hash = getString(this, ("commit_" + address))
53- if (!(isDefined(hash)))
54- then false
55- else (toBase58String(sha256(toBytes((vote + salt)))) == hash)
56- }
57-
58-
5917 @Callable(i)
60-func commit (hash) = {
18+func deposit () = {
6119 let user = toBase58String(i.caller.bytes)
62- let commitsCount = getCommitsCount()
63- let nextStatus = if (((commitsCount + 1) == VOTERS))
64- then REVEAL
65- else VOTING
66- if ((commitsCount == VOTERS))
67- then throw("Max number of voters reached")
68- else if (voteExists(user))
69- then throw("User already voted")
70- else if ((getVotingStatus() != VOTING))
71- then throw("Voting is disabled")
72- else [StringEntry(("commit_" + user), hash), IntegerEntry("commits_count", (commitsCount + 1)), StringEntry("voting_status", nextStatus)]
20+ let payment = value(i.payments[0])
21+ if ((0 > payment.amount))
22+ then throw("Payment is too low")
23+ else if ((payment.assetId != ASSET))
24+ then throw("AssetId is not correct")
25+ else [IntegerEntry(("deposit_" + user), (currentBalance(user) + payment.amount))]
7326 }
7427
7528
7629
7730 @Callable(i)
78-func reveal (vote,salt) = {
31+func withdraw (amount) = {
7932 let user = toBase58String(i.caller.bytes)
80- let revealsCount = getRevealsCount()
81- let votingStatus = getVotingStatus()
82- let nextStatus = if (((revealsCount + 1) == VOTERS))
83- then FINISHED
84- else REVEAL
85- if ((votingStatus == VOTING))
86- then throw("Voting has not finished yet")
87- else if ((votingStatus == FINISHED))
88- then throw("Voting is finished")
89- else if (revealExists(user))
90- then throw("You already revealed vote")
91- else if (!(validateVote(user, vote, salt)))
92- then throw("Vote is not valid")
93- else [StringEntry(("reveal_" + user), vote), IntegerEntry("reveals_count", (revealsCount + 1)), StringEntry("voting_status", nextStatus)]
33+ let balance = currentBalance(user)
34+ if ((amount > balance))
35+ then throw("Requested amount is too high")
36+ else [IntegerEntry(("deposit_" + user), (balance - amount)), ScriptTransfer(i.caller, amount, ASSET)]
9437 }
9538
9639
9740 @Verifier(tx)
9841 func verify () = true
9942

github/deemru/w8io/169f3d6 
24.48 ms