| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $BOUNCE_FEE = 10000; |
| 9 | $TYPICAL_FEE = 1000; |
| 10 | $REIMBURSEMENT = $BOUNCE_FEE - $TYPICAL_FEE; |
| 11 | }", |
| 12 | "messages": { |
| 13 | "cases": [ |
| 14 | { |
| 15 | "if": "{ trigger.data.owner }", |
| 16 | "init": "{ |
| 17 | $owner = trigger.data.owner otherwise bounce("owner field is missing"); |
| 18 | $period = trigger.data.period otherwise bounce("period field is missing"); |
| 19 | $reference = sha256($owner || $period ); |
| 20 | |
| 21 | if (var[$reference]) bounce("pension plan already exists"); |
| 22 | }", |
| 23 | "messages": [ |
| 24 | { |
| 25 | "app": "payment", |
| 26 | "payload": { |
| 27 | "asset": "base", |
| 28 | "outputs": [ |
| 29 | { |
| 30 | "address": "{trigger.address}", |
| 31 | "amount": "{$REIMBURSEMENT}" |
| 32 | } |
| 33 | ] |
| 34 | } |
| 35 | }, |
| 36 | { |
| 37 | "app": "state", |
| 38 | "state": "{ |
| 39 | var[$reference] = 'requested'; |
| 40 | var[$reference||'.owner'] = $owner; |
| 41 | var[$reference||'.period'] = $period; |
| 42 | response['reference'] = $reference; |
| 43 | response['status'] = var[$reference]; |
| 44 | response['message'] = 'pension plan created'; |
| 45 | }" |
| 46 | } |
| 47 | ] |
| 48 | }, |
| 49 | { |
| 50 | "if": "{ |
| 51 | $deposit = trigger.output[[asset = base]]; |
| 52 | $deposit > $BOUNCE_FEE |
| 53 | }", |
| 54 | "messages": [ |
| 55 | { |
| 56 | "app": "state", |
| 57 | "state": "{ |
| 58 | response['message'] = 'Added ' || $deposit || ' bytes to the private pension plan'; |
| 59 | }" |
| 60 | } |
| 61 | ] |
| 62 | }, |
| 63 | { |
| 64 | "if": "{ trigger.data.action AND trigger.data.action == 'withdraw' AND trigger.address == $owner }", |
| 65 | "init": "{ |
| 66 | $account = trigger.address; |
| 67 | $balance = var[$account] otherwise bounce("No such account"); |
| 68 | $amount = trigger.data.amount otherwise $balance; |
| 69 | |
| 70 | if ($amount > $balance) bounce("Invalid withdrawal amount. Maximum balance is " || $balance); |
| 71 | if ($amount <= 0) bounce("Invalid withdrawal amount. Enter a number greater than zero."); |
| 72 | }", |
| 73 | "messages": [ |
| 74 | { |
| 75 | "app": "payment", |
| 76 | "payload": { |
| 77 | "outputs": [ |
| 78 | { |
| 79 | "address": "{$account}", |
| 80 | "amount": "{$amount}" |
| 81 | }, |
| 82 | { |
| 83 | "address": "{$account}", |
| 84 | "amount": "{$REIMBURSEMENT}" |
| 85 | } |
| 86 | ] |
| 87 | } |
| 88 | }, |
| 89 | { |
| 90 | "app": "state", |
| 91 | "state": "{ |
| 92 | var[$account] -= $amount; |
| 93 | }" |
| 94 | } |
| 95 | ] |
| 96 | }, |
| 97 | { |
| 98 | "init": "{ |
| 99 | bounce("Enter a data field: payer, payee, reference or action"); |
| 100 | }", |
| 101 | "messages": [ |
| 102 | { |
| 103 | "app": "state", |
| 104 | "state": "{ |
| 105 | response['usage'] = 'Enter a data field: payer, payee, reference or action'; |
| 106 | }" |
| 107 | } |
| 108 | ] |
| 109 | } |
| 110 | ] |
| 111 | } |
| 112 | } |
| 113 | ] |