7 | | - | func sponsorDeposit (compestart,assetName,compenum) = { |
---|
8 | | - | let compeNum = toString(compenum) |
---|
9 | | - | let compeStart = toString(compestart) |
---|
10 | | - | let pmt = extract(i.payment) |
---|
11 | | - | let paymentId = pmt.assetId |
---|
12 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
13 | | - | let currentAmount = match getInteger(this, (((compeNum + assetName) + compeStart) + currentKey)) { |
---|
14 | | - | case a: Int => |
---|
15 | | - | a |
---|
16 | | - | case _ => |
---|
17 | | - | 0 |
---|
18 | | - | } |
---|
19 | | - | let newAmount = (currentAmount + pmt.amount) |
---|
20 | | - | WriteSet([DataEntry((((compeNum + assetName) + compeStart) + currentKey), newAmount), DataEntry((((compeNum + compeStart) + assetName) + currentKey), compestart)]) |
---|
21 | | - | } |
---|
22 | | - | |
---|
23 | | - | |
---|
24 | | - | |
---|
25 | | - | @Callable(i) |
---|
26 | | - | func sponsorWithdraw (startTimestamp,assetName,compenum,amount,id,nowTimestamp) = { |
---|
27 | | - | let compestart = toString(startTimestamp) |
---|
28 | | - | let compeNum = toString(compenum) |
---|
29 | | - | let assetId = fromBase58String(id) |
---|
30 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
31 | | - | let compeStart = match getInteger(this, (((compeNum + compestart) + assetName) + currentKey)) { |
---|
32 | | - | case a: Int => |
---|
33 | | - | a |
---|
34 | | - | case _ => |
---|
35 | | - | 0 |
---|
36 | | - | } |
---|
37 | | - | let currentAmount = match getInteger(this, (((compeNum + assetName) + compestart) + currentKey)) { |
---|
38 | | - | case a: Int => |
---|
39 | | - | a |
---|
40 | | - | case _ => |
---|
41 | | - | 0 |
---|
42 | | - | } |
---|
43 | | - | let newAmount = (currentAmount - amount) |
---|
44 | | - | if ((nowTimestamp > startTimestamp)) |
---|
45 | | - | then throw("Can't withdraw compe start") |
---|
46 | | - | else if ((0 > amount)) |
---|
47 | | - | then throw("Can't withdraw negative amount") |
---|
48 | | - | else if ((0 > newAmount)) |
---|
49 | | - | then throw("Not enough balance") |
---|
50 | | - | else if ((id == "WAVES")) |
---|
51 | | - | then ScriptResult(WriteSet([DataEntry((((compeNum + assetName) + compestart) + currentKey), newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, unit)])) |
---|
52 | | - | else ScriptResult(WriteSet([DataEntry((((compeNum + assetName) + compestart) + currentKey), newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, assetId)])) |
---|
53 | | - | } |
---|
54 | | - | |
---|
55 | | - | |
---|
56 | | - | |
---|
57 | | - | @Callable(i) |
---|
58 | | - | func paymentDeposit (courseaddress,lockernum,markername) = { |
---|
59 | | - | let lockerNum = toString(lockernum) |
---|
60 | | - | let pmt = extract(i.payment) |
---|
61 | | - | let markerId = pmt.assetId |
---|
62 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
63 | | - | let currentAmount = match getInteger(this, (((("pd_" + markername) + courseaddress) + lockerNum) + currentKey)) { |
---|
64 | | - | case a: Int => |
---|
65 | | - | a |
---|
66 | | - | case _ => |
---|
67 | | - | 0 |
---|
68 | | - | } |
---|
69 | | - | let newAmount = (currentAmount + pmt.amount) |
---|
70 | | - | WriteSet([DataEntry((((("pd_" + markername) + courseaddress) + lockerNum) + currentKey), newAmount), DataEntry((((("pw_" + markername) + courseaddress) + lockerNum) + currentKey), true), DataEntry((((("cw_" + markername) + courseaddress) + lockerNum) + currentKey), false)]) |
---|
71 | | - | } |
---|
72 | | - | |
---|
73 | | - | |
---|
74 | | - | |
---|
75 | | - | @Callable(i) |
---|
76 | | - | func paymentWithdraw (courseaddress,lockernum,markername,markerid,amount) = { |
---|
77 | | - | let lockerNum = toString(lockernum) |
---|
78 | | - | let assetId = fromBase58String(markerid) |
---|
79 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
80 | | - | let paymentWithdraw = match getBoolean(this, (((("pw_" + markername) + courseaddress) + lockerNum) + currentKey)) { |
---|
81 | | - | case a: Boolean => |
---|
82 | | - | a |
---|
83 | | - | case _ => |
---|
84 | | - | 0 |
---|
85 | | - | } |
---|
86 | | - | let currentAmount = match getInteger(this, (((("pd_" + markername) + courseaddress) + lockerNum) + currentKey)) { |
---|
87 | | - | case a: Int => |
---|
88 | | - | a |
---|
89 | | - | case _ => |
---|
90 | | - | 0 |
---|
91 | | - | } |
---|
92 | | - | let newAmount = (currentAmount - amount) |
---|
93 | | - | if ((paymentWithdraw == false)) |
---|
94 | | - | then throw("Can't withdraw") |
---|
95 | | - | else if ((0 > amount)) |
---|
96 | | - | then throw("Can't withdraw negative amount") |
---|
97 | | - | else if ((0 > newAmount)) |
---|
98 | | - | then throw("Not enough balance") |
---|
99 | | - | else if ((markerid == "WAVES")) |
---|
100 | | - | then ScriptResult(WriteSet([DataEntry((((("pd_" + markername) + courseaddress) + lockerNum) + currentKey), newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, unit)])) |
---|
101 | | - | else ScriptResult(WriteSet([DataEntry((((("pd_" + markername) + courseaddress) + lockerNum) + currentKey), newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, assetId)])) |
---|
102 | | - | } |
---|
103 | | - | |
---|
104 | | - | |
---|
105 | | - | |
---|
106 | | - | @Callable(i) |
---|
107 | | - | func golferAuth (courseaddress,lockernum,markername) = { |
---|
108 | | - | let lockerNum = toString(lockernum) |
---|
109 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
110 | | - | WriteSet([DataEntry((((("pw_" + markername) + courseaddress) + lockerNum) + currentKey), false)]) |
---|
111 | | - | } |
---|
112 | | - | |
---|
113 | | - | |
---|
114 | | - | |
---|
115 | | - | @Callable(i) |
---|
116 | | - | func courseAuth (golferaddress,lockernum,markername) = { |
---|
117 | | - | let lockerNum = toString(lockernum) |
---|
118 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
119 | | - | WriteSet([DataEntry((((("cw_" + markername) + currentKey) + lockerNum) + golferaddress), true)]) |
---|
120 | | - | } |
---|
121 | | - | |
---|
122 | | - | |
---|
123 | | - | |
---|
124 | | - | @Callable(i) |
---|
125 | | - | func courseWithdraw (golferaddress,lockernum,markername,markerid,amount) = { |
---|
126 | | - | let lockerNum = toString(lockernum) |
---|
127 | | - | let assetId = fromBase58String(markerid) |
---|
128 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
129 | | - | let paymentWithdraw = match getBoolean(this, (((("pw_" + markername) + currentKey) + lockerNum) + golferaddress)) { |
---|
130 | | - | case a: Boolean => |
---|
131 | | - | a |
---|
132 | | - | case _ => |
---|
133 | | - | 0 |
---|
134 | | - | } |
---|
135 | | - | let courseWithdraw = match getBoolean(this, (((("cw_" + markername) + currentKey) + lockerNum) + golferaddress)) { |
---|
136 | | - | case a: Boolean => |
---|
137 | | - | a |
---|
138 | | - | case _ => |
---|
139 | | - | 0 |
---|
140 | | - | } |
---|
141 | | - | let currentAmount = match getInteger(this, (((("pd_" + markername) + currentKey) + lockerNum) + golferaddress)) { |
---|
142 | | - | case a: Int => |
---|
143 | | - | a |
---|
144 | | - | case _ => |
---|
145 | | - | 0 |
---|
146 | | - | } |
---|
147 | | - | let newAmount = (currentAmount - amount) |
---|
148 | | - | if ((paymentWithdraw == true)) |
---|
149 | | - | then throw("Can't golfer auth") |
---|
150 | | - | else if ((courseWithdraw == false)) |
---|
151 | | - | then throw("Can't golfcourse auth") |
---|
152 | | - | else if ((0 > amount)) |
---|
153 | | - | then throw("Can't withdraw negative amount") |
---|
154 | | - | else if ((0 > newAmount)) |
---|
155 | | - | then throw("Not enough balance") |
---|
156 | | - | else if ((markerid == "WAVES")) |
---|
157 | | - | then ScriptResult(WriteSet([DataEntry((((("pd_" + markername) + currentKey) + lockerNum) + golferaddress), newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, unit)])) |
---|
158 | | - | else ScriptResult(WriteSet([DataEntry((((("pd_" + markername) + currentKey) + lockerNum) + golferaddress), newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, assetId)])) |
---|
| 9 | + | func issueAsset (name,description,amount,decimals,reIssue) = { |
---|
| 10 | + | let pmt = i.payments[0] |
---|
| 11 | + | if ((pmt.assetId != PAR7)) |
---|
| 12 | + | then throw("works with PAR7 only") |
---|
| 13 | + | else { |
---|
| 14 | + | let swapAmount = (pmt.amount * swapRate) |
---|
| 15 | + | let issue = Issue(name, description, amount, decimals, reIssue) |
---|
| 16 | + | let id = calculateAssetId(issue) |
---|
| 17 | + | [issue, ScriptTransfer(i.caller, issue.quantity, id)] |
---|
| 18 | + | } |
---|