|
31 | 31 | (define-constant ERR_USER_NOT_FOUND (err u1009))
|
32 | 32 | (define-constant ERR_INVOICE_ALREADY_PAID (err u1010))
|
33 | 33 | (define-constant ERR_SAVING_INVOICE_DATA (err u1011))
|
| 34 | +(define-constant ERR_INVOICE_NOT_FOUND (err u1012)) |
| 35 | +(define-constant ERR_RECENT_PAYMENT_NOT_FOUND (err u1013)) |
34 | 36 |
|
35 | 37 | ;; data vars
|
36 | 38 | ;;
|
|
40 | 42 | (define-data-var resourceCount uint u0)
|
41 | 43 | (define-data-var invoiceCount uint u0)
|
42 | 44 |
|
| 45 | +;; tracking overall contract revenue |
| 46 | +(define-data-var totalRevenue uint u0) |
| 47 | + |
43 | 48 | ;; payout address, deployer can set
|
44 | 49 | (define-data-var paymentAddress principal DEPLOYER)
|
45 | 50 |
|
|
201 | 206 | (is-eq contract-caller oldAddress)
|
202 | 207 | (try! (is-deployer))
|
203 | 208 | ) ERR_UNAUTHORIZED)
|
| 209 | + ;; print details |
| 210 | + (print { |
| 211 | + notification: "set-payment-address", |
| 212 | + payload: { |
| 213 | + oldAddress: oldAddress, |
| 214 | + newAddress: newAddress, |
| 215 | + txSender: tx-sender, |
| 216 | + contractCaller: contract-caller, |
| 217 | + } |
| 218 | + }) |
204 | 219 | ;; set new payment address
|
205 | 220 | (ok (var-set paymentAddress newAddress))
|
206 | 221 | )
|
|
236 | 251 | ) ERR_SAVING_RESOURCE_DATA)
|
237 | 252 | ;; increment resourceCount
|
238 | 253 | (var-set resourceCount newCount)
|
| 254 | + ;; print details |
| 255 | + (print { |
| 256 | + notification: "add-resource", |
| 257 | + payload: { |
| 258 | + resourceIndex: newCount, |
| 259 | + resourceData: (unwrap! (get-resource newCount) ERR_RESOURCE_NOT_FOUND), |
| 260 | + txSender: tx-sender, |
| 261 | + contractCaller: contract-caller |
| 262 | + } |
| 263 | + }) |
239 | 264 | ;; return new count
|
240 | 265 | (ok newCount)
|
241 | 266 | )
|
|
247 | 272 | (let
|
248 | 273 | (
|
249 | 274 | (resourceData (unwrap! (get-resource index) ERR_RESOURCE_NOT_FOUND))
|
| 275 | + (newStatus (not (get enabled resourceData))) |
250 | 276 | )
|
251 | 277 | ;; verify resource > 0
|
252 | 278 | (asserts! (> index u0) ERR_INVALID_PARAMS)
|
|
256 | 282 | (map-set ResourceData
|
257 | 283 | index
|
258 | 284 | (merge resourceData {
|
259 |
| - enabled: (not (get enabled resourceData)) |
| 285 | + enabled: newStatus |
260 | 286 | })
|
261 | 287 | )
|
262 |
| - ;; print updated resource data |
263 |
| - (print (get-resource index)) |
| 288 | + ;; print details |
| 289 | + (print { |
| 290 | + notification: "toggle-resource", |
| 291 | + payload: { |
| 292 | + resourceIndex: index, |
| 293 | + resourceData: (unwrap! (get-resource index) ERR_RESOURCE_NOT_FOUND), |
| 294 | + txSender: tx-sender, |
| 295 | + contractCaller: contract-caller |
| 296 | + } |
| 297 | + }) |
264 | 298 | ;; return based on set status
|
265 |
| - (ok (not (get enabled resourceData))) |
| 299 | + (ok newStatus) |
266 | 300 | )
|
267 | 301 | )
|
268 | 302 |
|
|
323 | 357 | )
|
324 | 358 | ;; increment counter
|
325 | 359 | (var-set invoiceCount newCount)
|
326 |
| - ;; print updated details |
| 360 | + ;; print details |
327 | 361 | (print {
|
328 |
| - resourceData: (get-resource resourceIndex), |
329 |
| - userData: (get-user-data userIndex) |
| 362 | + notification: "pay-invoice", |
| 363 | + payload: { |
| 364 | + invoiceIndex: newCount, |
| 365 | + invoiceData: (unwrap! (get-invoice newCount) ERR_INVOICE_NOT_FOUND), |
| 366 | + recentPayment: (unwrap! (get-recent-payment resourceIndex userIndex) ERR_RECENT_PAYMENT_NOT_FOUND), |
| 367 | + userIndex: userIndex, |
| 368 | + userData: (unwrap! (get-user-data userIndex) ERR_USER_NOT_FOUND), |
| 369 | + resourceIndex: resourceIndex, |
| 370 | + resourceData: (unwrap! (get-resource resourceIndex) ERR_RESOURCE_NOT_FOUND), |
| 371 | + txSender: tx-sender, |
| 372 | + contractCaller: contract-caller |
| 373 | + } |
330 | 374 | })
|
331 | 375 | ;; make transfer
|
332 | 376 | (if (is-some memo)
|
|
0 commit comments