2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let a = 31556952000 |
---|
5 | | - | |
---|
6 | | - | let b = (a / 12) |
---|
7 | | - | |
---|
8 | | - | let c = "3NBDgR8hU6W86Sstn3EGid8k9uxkqiJjxT6" |
---|
9 | | - | |
---|
10 | | - | let d = base58'EJ85vmBXWEtV4yHLPRTxex4q4s9mC8jKUhheyjZxwnPw' |
---|
11 | | - | |
---|
12 | | - | let e = base58'Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU' |
---|
13 | | - | |
---|
14 | | - | let f = 100000000 |
---|
15 | | - | |
---|
16 | | - | let g = 60 |
---|
17 | | - | |
---|
18 | | - | let h = 50 |
---|
19 | | - | |
---|
20 | | - | let i = "basic" |
---|
21 | | - | |
---|
22 | | - | let j = "advanced" |
---|
23 | | - | |
---|
24 | | - | let k = "none" |
---|
25 | | - | |
---|
26 | | - | func l (m) = { |
---|
27 | | - | let n = getInteger(this, m) |
---|
28 | | - | if ($isInstanceOf(n, "Int")) |
---|
29 | | - | then { |
---|
30 | | - | let o = n |
---|
31 | | - | o |
---|
32 | | - | } |
---|
33 | | - | else 0 |
---|
34 | | - | } |
---|
35 | | - | |
---|
36 | | - | |
---|
37 | | - | func p (m) = { |
---|
38 | | - | let n = getString(this, m) |
---|
39 | | - | if ($isInstanceOf(n, "String")) |
---|
40 | | - | then { |
---|
41 | | - | let q = n |
---|
42 | | - | q |
---|
43 | | - | } |
---|
44 | | - | else k |
---|
45 | | - | } |
---|
46 | | - | |
---|
47 | | - | |
---|
48 | | - | func r (s) = (("member_" + s) + "_subscription_end") |
---|
49 | | - | |
---|
50 | | - | |
---|
51 | | - | func t (s) = (("member_" + s) + "_plan") |
---|
52 | | - | |
---|
53 | | - | |
---|
54 | | - | func u (v) = TransferSet([ScriptTransfer(v, 1, d)]) |
---|
55 | | - | |
---|
56 | | - | |
---|
57 | | - | func w (v,x,y) = WriteSet([DataEntry(r(v), (lastBlock.timestamp + x)), DataEntry(t(v), y)]) |
---|
58 | | - | |
---|
59 | | - | |
---|
60 | | - | func z (A,x,y,B) = { |
---|
61 | | - | let v = toBase58String(A.bytes) |
---|
62 | | - | if (B) |
---|
63 | | - | then w(v, x, y) |
---|
64 | | - | else ScriptResult(w(v, x, y), u(A)) |
---|
65 | | - | } |
---|
66 | | - | |
---|
67 | | - | |
---|
68 | | - | @Callable(C) |
---|
69 | | - | func subscribe (y) = { |
---|
70 | | - | let D = extract(C.payment) |
---|
71 | | - | if ((D.assetId != e)) |
---|
72 | | - | then throw("can use only wEUR token at the moment") |
---|
73 | | - | else { |
---|
74 | | - | let v = toBase58String(C.caller.bytes) |
---|
75 | | - | let E = l(r(v)) |
---|
76 | | - | let B = (E != 0) |
---|
77 | | - | if ((y == i)) |
---|
78 | | - | then if ((g > D.amount)) |
---|
79 | | - | then throw("unsufficient payment amount for basic plan") |
---|
80 | | - | else z(C.caller, a, y, B) |
---|
81 | | - | else if ((y == j)) |
---|
82 | | - | then if ((h > D.amount)) |
---|
83 | | - | then throw("unsufficient payment amount for advanced plan") |
---|
84 | | - | else z(C.caller, b, y, B) |
---|
85 | | - | else throw(("subscription to an unknown plan: " + y)) |
---|
86 | | - | } |
---|
87 | | - | } |
---|
88 | | - | |
---|
89 | | - | |
---|
90 | | - | |
---|
91 | | - | @Callable(C) |
---|
92 | | - | func subscribeUser (F,y) = { |
---|
93 | | - | let v = toBase58String(C.caller.bytes) |
---|
94 | | - | let G = toBase58String(this.bytes) |
---|
95 | | - | if (if ((v != c)) |
---|
96 | | - | then (v != G) |
---|
97 | | - | else false) |
---|
98 | | - | then throw("only admins can do that") |
---|
99 | | - | else { |
---|
100 | | - | let E = l(r(F)) |
---|
101 | | - | let B = (E != 0) |
---|
102 | | - | let x = if ((y == i)) |
---|
103 | | - | then a |
---|
104 | | - | else if ((y == j)) |
---|
105 | | - | then b |
---|
106 | | - | else throw(("subscription to an unknown plan: " + y)) |
---|
107 | | - | z(addressFromStringValue(F), x, y, B) |
---|
108 | | - | } |
---|
109 | | - | } |
---|
110 | | - | |
---|
111 | | - | |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | let dapp = base58'3N9hj5xjfQdmxFKgztzxsQY9FSGSRM2RNTr' |
---|
| 4 | + | let admin = base58'3NBDgR8hU6W86Sstn3EGid8k9uxkqiJjxT6' |
---|
| 5 | + | match tx { |
---|
| 6 | + | case t: InvokeScriptTransaction|SetAssetScriptTransaction|MassTransferTransaction|TransferTransaction => |
---|
| 7 | + | if ((tx.senderPublicKey == dapp)) |
---|
| 8 | + | then true |
---|
| 9 | + | else (tx.senderPublicKey == admin) |
---|
| 10 | + | case _ => |
---|
| 11 | + | false |
---|
| 12 | + | } |
---|