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/OQv9D6FbqZAAAAAANXVlMAAAAAAAX14QAAAAAAC1BSSUNFeEJBU0lDAAAAAAAAAAA8AAAAAA5QUklDRXhBRFZBTkNFRAAAAAAAAAAAMgAAAAAFQkFTSUMCAAAABWJhc2ljAAAAAAhBRFZBTkNFRAIAAAAIYWR2YW5jZWQAAAAABE5PTkUCAAAABG5vbmUBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAAByRtYXRjaDAJAAQaAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQE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AAABHBsYW4FAAAACWlzUmVuZXdhbAAAAAD/6CdP", "chainId": 84, "height": 725961, "spentComplexity": 0 } View: original | compacted Prev: 9WJkscDuER8wciaSGwAzS1qW1Qpz9zDbKZPQFwvVjW4e Next: 4YXsjdkUxU8EwYweskZ2ZMEFVW5ED2hTGsPdPfpZ1ey9 Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# 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+
414 let WVS = 100000000
515
6-let FEE = (1 * WVS)
16+let PRICExBASIC = 60
717
8-let YEAR = 31556952000
18+let PRICExADVANCED = 50
919
10-let TOKEN = base58'EJ85vmBXWEtV4yHLPRTxex4q4s9mC8jKUhheyjZxwnPw'
20+let BASIC = "basic"
21+
22+let ADVANCED = "advanced"
1123
1224 let NONE = "none"
1325
2739 }
2840
2941
30-func getKeySubscriptionTs (addr) = (("member_" + addr) + "subscription_ts")
42+func getKeySubscriptionEnd (addr) = (("member_" + addr) + "_subscription_end")
3143
3244
33-func getKeyFee (addr) = (("member_" + addr) + "_fee")
45+func getKeyPlan (addr) = (("member_" + addr) + "_plan")
3446
3547
36-func getKeyGroup (addr) = (("member_" + addr) + "_group")
48+func getTransferSet (account) = TransferSet([ScriptTransfer(account, 1, TOKEN)])
3749
3850
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+ }
4060
4161
4262 @Callable(i)
43-func subscribe () = {
63+func subscribe (plan) = {
4464 let payment = extract(i.payment)
45- if (isDefined(payment.assetId))
46- then throw("can use only WAVES token at the moment")
65+ if ((payment.assetId != wEUR))
66+ then throw("can use only wEUR token at the moment")
4767 else {
4868 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))
5580 }
5681 }
5782
5883
5984
6085 @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")
6593 else {
66- let account = toBase58String(i.caller.bytes)
67- let subscriptionTs = getNumberByKey(getKeySubscriptionTs(account))
68- let subscriptionFee = getNumberByKey(getKeyFee(account))
69- if ((subscriptionTs == 0))
70- then throw("subscribe first")
71- else if ((subscriptionFee > payment.amount))
72- then throw("payment amount cannot be lower then renewal fee")
73- else ScriptResult(WriteSet([DataEntry(getKeySubscriptionTs(account), (subscriptionTs + YEAR))]), TransferSet([ScriptTransfer(i.caller, 1, TOKEN)]))
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)
74102 }
75103 }
76104
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# 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+
414 let WVS = 100000000
515
6-let FEE = (1 * WVS)
16+let PRICExBASIC = 60
717
8-let YEAR = 31556952000
18+let PRICExADVANCED = 50
919
10-let TOKEN = base58'EJ85vmBXWEtV4yHLPRTxex4q4s9mC8jKUhheyjZxwnPw'
20+let BASIC = "basic"
21+
22+let ADVANCED = "advanced"
1123
1224 let NONE = "none"
1325
1426 func getNumberByKey (key) = match getInteger(this, key) {
1527 case n: Int =>
1628 n
1729 case _ =>
1830 0
1931 }
2032
2133
2234 func getStrByKey (key) = match getString(this, key) {
2335 case s: String =>
2436 s
2537 case _ =>
2638 NONE
2739 }
2840
2941
30-func getKeySubscriptionTs (addr) = (("member_" + addr) + "subscription_ts")
42+func getKeySubscriptionEnd (addr) = (("member_" + addr) + "_subscription_end")
3143
3244
33-func getKeyFee (addr) = (("member_" + addr) + "_fee")
45+func getKeyPlan (addr) = (("member_" + addr) + "_plan")
3446
3547
36-func getKeyGroup (addr) = (("member_" + addr) + "_group")
48+func getTransferSet (account) = TransferSet([ScriptTransfer(account, 1, TOKEN)])
3749
3850
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+ }
4060
4161
4262 @Callable(i)
43-func subscribe () = {
63+func subscribe (plan) = {
4464 let payment = extract(i.payment)
45- if (isDefined(payment.assetId))
46- then throw("can use only WAVES token at the moment")
65+ if ((payment.assetId != wEUR))
66+ then throw("can use only wEUR token at the moment")
4767 else {
4868 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))
5580 }
5681 }
5782
5883
5984
6085 @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")
6593 else {
66- let account = toBase58String(i.caller.bytes)
67- let subscriptionTs = getNumberByKey(getKeySubscriptionTs(account))
68- let subscriptionFee = getNumberByKey(getKeyFee(account))
69- if ((subscriptionTs == 0))
70- then throw("subscribe first")
71- else if ((subscriptionFee > payment.amount))
72- then throw("payment amount cannot be lower then renewal fee")
73- else ScriptResult(WriteSet([DataEntry(getKeySubscriptionTs(account), (subscriptionTs + YEAR))]), TransferSet([ScriptTransfer(i.caller, 1, TOKEN)]))
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)
74102 }
75103 }
76104
77105

github/deemru/w8io/169f3d6 
64.87 ms