| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $OWNER = "O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; |
| 9 | $DANAA = "LLAVLVFN3CPBHTAB62NOIZLAMPABR2YF"; |
| 10 | $i = trigger.data; |
| 11 | }", |
| 12 | "messages": { |
| 13 | "cases": [ |
| 14 | { |
| 15 | "if": "{ !!$i.help}", |
| 16 | "init": "{ |
| 17 | $aa = trigger.address; |
| 18 | |
| 19 | $non_bytes = trigger.output[[asset!=base]]; $bytes = trigger.output[[asset=base]]; |
| 20 | |
| 21 | $reward = $non_bytes.amount otherwise $bytes.amount otherwise 0; |
| 22 | $reward_asset = $non_bytes.asset != "none" ? $non_bytes.asset : "base"; |
| 23 | $asset_nice_name = var[$DANAA][$reward_asset||"_shortName"] otherwise $reward_asset; |
| 24 | |
| 25 | $time = $i.time otherwise ($i.delay) ? timestamp : false; |
| 26 | |
| 27 | |
| 28 | $m_reward = "Get "||$reward||" "||$asset_nice_name||" if you are first to reply to me"; |
| 29 | $m_time = (!!$time) ? " at "||timestamp_to_string($time, 'datetime') : ""; |
| 30 | $m_delay = (!!$i.delay) ? " (delay max = "||$i.delay ||")" : ""; |
| 31 | |
| 32 | |
| 33 | if (!$i.helper) |
| 34 | { |
| 35 | $good_guys_count = var["good_guys_count"] otherwise 0; |
| 36 | if ($good_guys_count == 0 ) bounce ("No 'helper' registered !"); |
| 37 | $helper = var["good_guys_"||number_from_seed(timestamp,1,$good_guys_count)]; |
| 38 | $key = $aa; |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | $helper = $i.helper; |
| 43 | $key = $i.private ? sha256($i.helper||"_"||$aa) : $aa; |
| 44 | } |
| 45 | }", |
| 46 | "messages": [ |
| 47 | { |
| 48 | "app": "data", |
| 49 | "payload": { |
| 50 | "message": "{ $m_reward||$m_time||$m_delay||$asset_nice_name||" with data: 'aa' = < helped_aa >" }", |
| 51 | "me": "{this_address}", |
| 52 | "helped_aa": "{$aa}" |
| 53 | } |
| 54 | }, |
| 55 | { |
| 56 | "app": "payment", |
| 57 | "payload": { |
| 58 | "asset": "base", |
| 59 | "outputs": [ |
| 60 | { |
| 61 | "address": "{ $helper }", |
| 62 | "amount": "{ 1000 }" |
| 63 | } |
| 64 | ] |
| 65 | } |
| 66 | }, |
| 67 | { |
| 68 | "app": "state", |
| 69 | "state": "{ |
| 70 | var[$key||"_reward"] = $reward; var[$key||"_asset"] = $reward_asset; |
| 71 | var[$key||"_time"] = $time; var[$key||"_delay"] = $i.delay; |
| 72 | response['message'] = $helper||" has been asked for help ^^"; |
| 73 | }" |
| 74 | } |
| 75 | ] |
| 76 | }, |
| 77 | { |
| 78 | "if": "{ !!$i.aa }", |
| 79 | "init": "{ |
| 80 | $helper = trigger.address; $aa = $i.aa; |
| 81 | |
| 82 | |
| 83 | $key = !!var[$aa||"_reward"] ? $aa : sha256($helper||"_"||$aa); |
| 84 | if (!var[$key||"_reward"]) |
| 85 | bounce ("Reward not available, you have been overtaken or you specified the wrong 'aa'!"); |
| 86 | |
| 87 | |
| 88 | if (!!var[$key||"_time"]) if (var[$key||"_time"] > timestamp) |
| 89 | bounce ("Too early, try in "||(var[$key||"_time"] - timestamp)); |
| 90 | |
| 91 | |
| 92 | if (!!var[$key||"_delay"]) if (var[$key||"_time"] + var[$key||"_delay"] > timestamp) |
| 93 | bounce ("Too late, sorry !"); |
| 94 | |
| 95 | |
| 96 | $bytes = trigger.output[[asset=base]].amount - 2000; |
| 97 | $reward_in_bytes = var[$key||"_asset"] == "base" ? var[$key||"_reward"] + $bytes: $bytes; |
| 98 | $reward_in_other = var[$key||"_asset"] != "base" ? var[$key||"_reward"] : false; |
| 99 | }", |
| 100 | "messages": [ |
| 101 | { |
| 102 | "app": "data", |
| 103 | "payload": { |
| 104 | "help_from": "{ $helper }" |
| 105 | } |
| 106 | }, |
| 107 | { |
| 108 | "if": "{ !!$reward_in_other }", |
| 109 | "app": "payment", |
| 110 | "payload": { |
| 111 | "asset": "{ var[$key||"_asset"] }", |
| 112 | "outputs": [ |
| 113 | { |
| 114 | "address": "{ $helper }", |
| 115 | "amount": "{ $reward_in_other }" |
| 116 | } |
| 117 | ] |
| 118 | } |
| 119 | }, |
| 120 | { |
| 121 | "app": "payment", |
| 122 | "payload": { |
| 123 | "asset": "base", |
| 124 | "outputs": [ |
| 125 | { |
| 126 | "address": "{ $helper }", |
| 127 | "amount": "{ $reward_in_bytes }" |
| 128 | }, |
| 129 | { |
| 130 | "address": "{ $aa }", |
| 131 | "amount": "{ 1000 }" |
| 132 | } |
| 133 | ] |
| 134 | } |
| 135 | }, |
| 136 | { |
| 137 | "app": "state", |
| 138 | "state": "{ |
| 139 | var[$key||"_reward"] = false; var[$key||"_asset"] = false; |
| 140 | var[$key||"_time"] = false; var[$key||"_delay"] = false; |
| 141 | response['message'] = trigger.address||" has been rewarded ^^"; |
| 142 | }" |
| 143 | } |
| 144 | ] |
| 145 | }, |
| 146 | { |
| 147 | "if": "{ $i.subscribe}", |
| 148 | "init": "{ |
| 149 | $helper = trigger.address; |
| 150 | if (var[$helper]) bounce ("You are motivated, but once is enough!"); |
| 151 | }", |
| 152 | "messages": [ |
| 153 | { |
| 154 | "app": "payment", |
| 155 | "payload": { |
| 156 | "asset": "base", |
| 157 | "outputs": [ |
| 158 | { |
| 159 | "address": "{ $helper }", |
| 160 | "amount": "{ $bytes.amount - 1000 }" |
| 161 | } |
| 162 | ] |
| 163 | } |
| 164 | }, |
| 165 | { |
| 166 | "app": "state", |
| 167 | "state": "{ |
| 168 | var["good_guys_count"] += 1; |
| 169 | var[$helper] = var["good_guys_count"]; var["good_guys_"||var["good_guys_count"]] = $helper; |
| 170 | response['message'] = "Subscribed"; |
| 171 | }" |
| 172 | } |
| 173 | ] |
| 174 | }, |
| 175 | { |
| 176 | "if": "{ $i.unsubscribe }", |
| 177 | "init": "{ |
| 178 | $helper = trigger.address; |
| 179 | if (!(var[$helper])) bounce ("You were not subscribed at the first place !"); |
| 180 | }", |
| 181 | "messages": [ |
| 182 | { |
| 183 | "app": "state", |
| 184 | "state": "{ |
| 185 | var["good_guys_count"] -=1; $good_guy_number = var[$helper]; |
| 186 | var["good_guys_"||$good_guy_number] = false; var[$helper] = false; |
| 187 | response['message'] = "Unsubscribed"; |
| 188 | }" |
| 189 | } |
| 190 | ] |
| 191 | }, |
| 192 | { |
| 193 | "messages": [ |
| 194 | { |
| 195 | "app": "state", |
| 196 | "state": "{ |
| 197 | bounce ("Input not expected, please read the doc at https://github.com/pascalSAINVITU/THAANKS"); |
| 198 | }" |
| 199 | } |
| 200 | ] |
| 201 | } |
| 202 | ] |
| 203 | } |
| 204 | } |
| 205 | ] |