tx · 2snY9xfwD3bJME647kqDUQgquex6pbmBRegfCE8mSCcj 3N9hj5xjfQdmxFKgztzxsQY9FSGSRM2RNTr: -0.05000000 Waves 2019.10.18 23:48 [725961] smart account 3N9hj5xjfQdmxFKgztzxsQY9FSGSRM2RNTr > SELF 0.00000000 Waves
{ "type": 13, "id": "2snY9xfwD3bJME647kqDUQgquex6pbmBRegfCE8mSCcj", "fee": 5000000, "feeAssetId": null, "timestamp": 1571431364876, "version": 1, "sender": "3N9hj5xjfQdmxFKgztzxsQY9FSGSRM2RNTr", "senderPublicKey": "456duGZMs5yvsHurjiNQi2JtHjKtMj4WyRRRcVHzKWrb", "proofs": [ "3t4N2KvMqmUZaGkPAuXEujHkPCX5XhXxvhojnRarD8C8hKyugBL1sqHf1E6cwwHLXnPWKfsaosy6JyKWSzfvuMDB" ], "script": "base64:AAIDAAAAAAAAAA0IARIDCgEIEgQKAggIAAAAEgAAAAAEWUVBUgAAAAAHWPDfwAAAAAAFTU9OVEgJAABpAAAAAgUAAAAEWUVBUgAAAAAAAAAADAAAAAAFQURNSU4CAAAAIzNOQkRnUjhoVTZXODZTc3RuM0VHaWQ4azl1eGtxaUpqeFQ2AAAAAAVUT0tFTgEAAAAgxYrQlOWMQVAQFV8+63OMRt4C+0j9Xrs6Q7YHkRdAWuYAAAAABHdFVVIBAAAAIOwWYQRfe5EhQQY7N/Pn19T489PGDqqAl/OQv9D6FbqZAAAAAANXVlMAAAAAAAX14QAAAAAAC1BSSUNFeEJBU0lDAAAAAAAAAAA8AAAAAA5QUklDRXhBRFZBTkNFRAAAAAAAAAAAMgAAAAAFQkFTSUMCAAAABWJhc2ljAAAAAAhBRFZBTkNFRAIAAAAIYWR2YW5jZWQAAAAABE5PTkUCAAAABG5vbmUBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAAByRtYXRjaDAJAAQaAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQEA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AABHBsYW4FAAAACWlzUmVuZXdhbAAAAAD/6CdP", "chainId": 84, "height": 725961, "spentComplexity": 0 } View: original | compacted Prev: 9WJkscDuER8wciaSGwAzS1qW1Qpz9zDbKZPQFwvVjW4e Next: 4YXsjdkUxU8EwYweskZ2ZMEFVW5ED2hTGsPdPfpZ1ey9 Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let YEAR = 31556952000 | |
5 | + | ||
6 | + | let MONTH = (YEAR / 12) | |
7 | + | ||
8 | + | let ADMIN = "3NBDgR8hU6W86Sstn3EGid8k9uxkqiJjxT6" | |
9 | + | ||
10 | + | let TOKEN = base58'EJ85vmBXWEtV4yHLPRTxex4q4s9mC8jKUhheyjZxwnPw' | |
11 | + | ||
12 | + | let wEUR = base58'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU' | |
13 | + | ||
4 | 14 | let WVS = 100000000 | |
5 | 15 | ||
6 | - | let | |
16 | + | let PRICExBASIC = 60 | |
7 | 17 | ||
8 | - | let | |
18 | + | let PRICExADVANCED = 50 | |
9 | 19 | ||
10 | - | let TOKEN = base58'EJ85vmBXWEtV4yHLPRTxex4q4s9mC8jKUhheyjZxwnPw' | |
20 | + | let BASIC = "basic" | |
21 | + | ||
22 | + | let ADVANCED = "advanced" | |
11 | 23 | ||
12 | 24 | let NONE = "none" | |
13 | 25 | ||
27 | 39 | } | |
28 | 40 | ||
29 | 41 | ||
30 | - | func | |
42 | + | func getKeySubscriptionEnd (addr) = (("member_" + addr) + "_subscription_end") | |
31 | 43 | ||
32 | 44 | ||
33 | - | func | |
45 | + | func getKeyPlan (addr) = (("member_" + addr) + "_plan") | |
34 | 46 | ||
35 | 47 | ||
36 | - | func | |
48 | + | func getTransferSet (account) = TransferSet([ScriptTransfer(account, 1, TOKEN)]) | |
37 | 49 | ||
38 | 50 | ||
39 | - | func getKeyBalance (addr) = (("member_" + addr) + "_balance") | |
51 | + | func getWriteSet (account,period,plan) = WriteSet([DataEntry(getKeySubscriptionEnd(account), (lastBlock.timestamp + period)), DataEntry(getKeyPlan(account), plan)]) | |
52 | + | ||
53 | + | ||
54 | + | func getResult (address,period,plan,isRenewal) = { | |
55 | + | let account = toBase58String(address.bytes) | |
56 | + | if (isRenewal) | |
57 | + | then getWriteSet(account, YEAR, plan) | |
58 | + | else ScriptResult(getWriteSet(account, YEAR, plan), getTransferSet(address)) | |
59 | + | } | |
40 | 60 | ||
41 | 61 | ||
42 | 62 | @Callable(i) | |
43 | - | func subscribe () = { | |
63 | + | func subscribe (plan) = { | |
44 | 64 | let payment = extract(i.payment) | |
45 | - | if ( | |
46 | - | then throw("can use only | |
65 | + | if ((payment.assetId != wEUR)) | |
66 | + | then throw("can use only wEUR token at the moment") | |
47 | 67 | else { | |
48 | 68 | let account = toBase58String(i.caller.bytes) | |
49 | - | let subscriptionTs = getNumberByKey(getKeySubscriptionTs(account)) | |
50 | - | if ((FEE > payment.amount)) | |
51 | - | then throw("payment amount cannot be lowher then subscription fee") | |
52 | - | else if ((subscriptionTs != 0)) | |
53 | - | then throw("Already subscribed") | |
54 | - | else ScriptResult(WriteSet([DataEntry(getKeySubscriptionTs(account), lastBlock.timestamp), DataEntry(getKeyFee(account), FEE), DataEntry(getKeyBalance(account), 0)]), TransferSet([ScriptTransfer(i.caller, 1, TOKEN)])) | |
69 | + | let subscriptionEnd = getNumberByKey(getKeySubscriptionEnd(account)) | |
70 | + | let isRenewal = (subscriptionEnd == 0) | |
71 | + | if ((plan == BASIC)) | |
72 | + | then if ((PRICExBASIC > payment.amount)) | |
73 | + | then throw("unsufficient payment amount for basic plan") | |
74 | + | else getResult(i.caller, YEAR, plan, isRenewal) | |
75 | + | else if ((plan == ADVANCED)) | |
76 | + | then if ((PRICExADVANCED > payment.amount)) | |
77 | + | then throw("unsufficient payment amount for advanced plan") | |
78 | + | else getResult(i.caller, MONTH, plan, isRenewal) | |
79 | + | else throw(("subscription to an unknown plan: " + plan)) | |
55 | 80 | } | |
56 | 81 | } | |
57 | 82 | ||
58 | 83 | ||
59 | 84 | ||
60 | 85 | @Callable(i) | |
61 | - | func renew () = { | |
62 | - | let payment = extract(i.payment) | |
63 | - | if (isDefined(payment.assetId)) | |
64 | - | then throw("can use only WAVES token at the moment") | |
86 | + | func subscribeUser (userAddress,plan) = { | |
87 | + | let account = toBase58String(i.caller.bytes) | |
88 | + | let dAppAccount = toBase58String(this.bytes) | |
89 | + | if (if ((account != ADMIN)) | |
90 | + | then (account != dAppAccount) | |
91 | + | else false) | |
92 | + | then throw("only admins can do that") | |
65 | 93 | else { | |
66 | - | let | |
67 | - | let | |
68 | - | let | |
69 | - | | |
70 | - | | |
71 | - | | |
72 | - | | |
73 | - | | |
94 | + | let subscriptionEnd = getNumberByKey(getKeySubscriptionEnd(userAddress)) | |
95 | + | let isRenewal = (subscriptionEnd == 0) | |
96 | + | let period = if ((plan == BASIC)) | |
97 | + | then YEAR | |
98 | + | else if ((plan == ADVANCED)) | |
99 | + | then MONTH | |
100 | + | else throw(("subscription to an unknown plan: " + plan)) | |
101 | + | getResult(i.caller, period, plan, isRenewal) | |
74 | 102 | } | |
75 | 103 | } | |
76 | 104 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let YEAR = 31556952000 | |
5 | + | ||
6 | + | let MONTH = (YEAR / 12) | |
7 | + | ||
8 | + | let ADMIN = "3NBDgR8hU6W86Sstn3EGid8k9uxkqiJjxT6" | |
9 | + | ||
10 | + | let TOKEN = base58'EJ85vmBXWEtV4yHLPRTxex4q4s9mC8jKUhheyjZxwnPw' | |
11 | + | ||
12 | + | let wEUR = base58'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU' | |
13 | + | ||
4 | 14 | let WVS = 100000000 | |
5 | 15 | ||
6 | - | let | |
16 | + | let PRICExBASIC = 60 | |
7 | 17 | ||
8 | - | let | |
18 | + | let PRICExADVANCED = 50 | |
9 | 19 | ||
10 | - | let TOKEN = base58'EJ85vmBXWEtV4yHLPRTxex4q4s9mC8jKUhheyjZxwnPw' | |
20 | + | let BASIC = "basic" | |
21 | + | ||
22 | + | let ADVANCED = "advanced" | |
11 | 23 | ||
12 | 24 | let NONE = "none" | |
13 | 25 | ||
14 | 26 | func getNumberByKey (key) = match getInteger(this, key) { | |
15 | 27 | case n: Int => | |
16 | 28 | n | |
17 | 29 | case _ => | |
18 | 30 | 0 | |
19 | 31 | } | |
20 | 32 | ||
21 | 33 | ||
22 | 34 | func getStrByKey (key) = match getString(this, key) { | |
23 | 35 | case s: String => | |
24 | 36 | s | |
25 | 37 | case _ => | |
26 | 38 | NONE | |
27 | 39 | } | |
28 | 40 | ||
29 | 41 | ||
30 | - | func | |
42 | + | func getKeySubscriptionEnd (addr) = (("member_" + addr) + "_subscription_end") | |
31 | 43 | ||
32 | 44 | ||
33 | - | func | |
45 | + | func getKeyPlan (addr) = (("member_" + addr) + "_plan") | |
34 | 46 | ||
35 | 47 | ||
36 | - | func | |
48 | + | func getTransferSet (account) = TransferSet([ScriptTransfer(account, 1, TOKEN)]) | |
37 | 49 | ||
38 | 50 | ||
39 | - | func getKeyBalance (addr) = (("member_" + addr) + "_balance") | |
51 | + | func getWriteSet (account,period,plan) = WriteSet([DataEntry(getKeySubscriptionEnd(account), (lastBlock.timestamp + period)), DataEntry(getKeyPlan(account), plan)]) | |
52 | + | ||
53 | + | ||
54 | + | func getResult (address,period,plan,isRenewal) = { | |
55 | + | let account = toBase58String(address.bytes) | |
56 | + | if (isRenewal) | |
57 | + | then getWriteSet(account, YEAR, plan) | |
58 | + | else ScriptResult(getWriteSet(account, YEAR, plan), getTransferSet(address)) | |
59 | + | } | |
40 | 60 | ||
41 | 61 | ||
42 | 62 | @Callable(i) | |
43 | - | func subscribe () = { | |
63 | + | func subscribe (plan) = { | |
44 | 64 | let payment = extract(i.payment) | |
45 | - | if ( | |
46 | - | then throw("can use only | |
65 | + | if ((payment.assetId != wEUR)) | |
66 | + | then throw("can use only wEUR token at the moment") | |
47 | 67 | else { | |
48 | 68 | let account = toBase58String(i.caller.bytes) | |
49 | - | let subscriptionTs = getNumberByKey(getKeySubscriptionTs(account)) | |
50 | - | if ((FEE > payment.amount)) | |
51 | - | then throw("payment amount cannot be lowher then subscription fee") | |
52 | - | else if ((subscriptionTs != 0)) | |
53 | - | then throw("Already subscribed") | |
54 | - | else ScriptResult(WriteSet([DataEntry(getKeySubscriptionTs(account), lastBlock.timestamp), DataEntry(getKeyFee(account), FEE), DataEntry(getKeyBalance(account), 0)]), TransferSet([ScriptTransfer(i.caller, 1, TOKEN)])) | |
69 | + | let subscriptionEnd = getNumberByKey(getKeySubscriptionEnd(account)) | |
70 | + | let isRenewal = (subscriptionEnd == 0) | |
71 | + | if ((plan == BASIC)) | |
72 | + | then if ((PRICExBASIC > payment.amount)) | |
73 | + | then throw("unsufficient payment amount for basic plan") | |
74 | + | else getResult(i.caller, YEAR, plan, isRenewal) | |
75 | + | else if ((plan == ADVANCED)) | |
76 | + | then if ((PRICExADVANCED > payment.amount)) | |
77 | + | then throw("unsufficient payment amount for advanced plan") | |
78 | + | else getResult(i.caller, MONTH, plan, isRenewal) | |
79 | + | else throw(("subscription to an unknown plan: " + plan)) | |
55 | 80 | } | |
56 | 81 | } | |
57 | 82 | ||
58 | 83 | ||
59 | 84 | ||
60 | 85 | @Callable(i) | |
61 | - | func renew () = { | |
62 | - | let payment = extract(i.payment) | |
63 | - | if (isDefined(payment.assetId)) | |
64 | - | then throw("can use only WAVES token at the moment") | |
86 | + | func subscribeUser (userAddress,plan) = { | |
87 | + | let account = toBase58String(i.caller.bytes) | |
88 | + | let dAppAccount = toBase58String(this.bytes) | |
89 | + | if (if ((account != ADMIN)) | |
90 | + | then (account != dAppAccount) | |
91 | + | else false) | |
92 | + | then throw("only admins can do that") | |
65 | 93 | else { | |
66 | - | let | |
67 | - | let | |
68 | - | let | |
69 | - | | |
70 | - | | |
71 | - | | |
72 | - | | |
73 | - | | |
94 | + | let subscriptionEnd = getNumberByKey(getKeySubscriptionEnd(userAddress)) | |
95 | + | let isRenewal = (subscriptionEnd == 0) | |
96 | + | let period = if ((plan == BASIC)) | |
97 | + | then YEAR | |
98 | + | else if ((plan == ADVANCED)) | |
99 | + | then MONTH | |
100 | + | else throw(("subscription to an unknown plan: " + plan)) | |
101 | + | getResult(i.caller, period, plan, isRenewal) | |
74 | 102 | } | |
75 | 103 | } | |
76 | 104 | ||
77 | 105 |
github/deemru/w8io/169f3d6 64.87 ms ◑