| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | |
| 9 | $this = { |
| 10 | name: "THAANKS", |
| 11 | owner:"O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ", |
| 12 | use_cases: "Be first to use 'token = <received token>' after the request time and before the acceptable delay to receive the associated reward. To subscribe as an helper and have a chance to be picked up later use: 'subscribe = true'. To unsubscribe use: 'unsubscribe = true'. If your are an AA use at minimum 'ask_help = <true>'.", |
| 13 | how_to: "Use 'ask_help = <true>' with optionaly 'helper = <address>' if you want to propose an helper. Use 'private_mode = true' to force the triggering to be done by the specific helper. If you need to be trigger after a given time, use 'request_time = <timestamp>' and if you want to give a dead line use 'acceptable_delay = <delay in seconds>'. " |
| 14 | }; |
| 15 | |
| 16 | |
| 17 | }", |
| 18 | "messages": { |
| 19 | "cases": [ |
| 20 | { |
| 21 | "if": "{ !!trigger.data.request_tag }", |
| 22 | "init": "{ |
| 23 | $request = json_parse(var[trigger.data.request_tag] otherwise bounce ("Too late or wrong tag")); |
| 24 | if ($request.time > timestamp) bounce ("Too early, try at "||timestamp_to_string($request.time)); |
| 25 | if (!!$request.private and $request.private != trigger.address) bounce ("Private reward!"); |
| 26 | |
| 27 | $is_late = timestamp > $request.deadline; |
| 28 | $reward_destination = $is_late ? $request.aa : trigger.address; |
| 29 | }", |
| 30 | "messages": [ |
| 31 | { |
| 32 | "app": "data", |
| 33 | "payload": { |
| 34 | "tag": "{trigger.data.request_tag}" |
| 35 | } |
| 36 | }, |
| 37 | { |
| 38 | "if": "{ !!$request.asset != "base" }", |
| 39 | "app": "payment", |
| 40 | "payload": { |
| 41 | "asset": "{$request.asset}", |
| 42 | "outputs": [ |
| 43 | { |
| 44 | "address": "{ $reward_destination }", |
| 45 | "amount": "{ $request.amount }" |
| 46 | } |
| 47 | ] |
| 48 | } |
| 49 | }, |
| 50 | { |
| 51 | "app": "payment", |
| 52 | "payload": { |
| 53 | "asset": "base", |
| 54 | "outputs": [ |
| 55 | { |
| 56 | "address": "{ $reward_destination }", |
| 57 | "amount": "{ $request.amount }" |
| 58 | }, |
| 59 | { |
| 60 | "if": "{ !$is_late }", |
| 61 | "address": "{ $request.aa }", |
| 62 | "amount": "{ 1 }" |
| 63 | } |
| 64 | ] |
| 65 | } |
| 66 | }, |
| 67 | { |
| 68 | "app": "state", |
| 69 | "state": "{ |
| 70 | var[trigger.data.request_hash] = false; |
| 71 | response['message'] = $is_late ? "Too late, sorry !" : trigger.address||" has been rewarded ^^"; |
| 72 | }" |
| 73 | } |
| 74 | ] |
| 75 | }, |
| 76 | { |
| 77 | "messages": [ |
| 78 | { |
| 79 | "app": "state", |
| 80 | "state": "{ |
| 81 | $new_request = { |
| 82 | address: trigger.data.address otherwise trigger.address, |
| 83 | time: trigger.data.requested_time otherwise timestamp, |
| 84 | deadline: trigger.data.requested_time + trigger.data.acceptable_delay otherwise 10*24*60*60, |
| 85 | private: trigger.data.trigger_address, |
| 86 | amount: trigger.output[[asset!=base]].amount otherwise trigger.output[[asset=base]].amount-2000, |
| 87 | asset: trigger.output[[asset!=base]].asset != "none"? trigger.output[[asset!=base]].asset: "base", |
| 88 | }; |
| 89 | $tag = trigger.data.tag otherwise sha256($new_request.address||$new_request.time); |
| 90 | var[$tag] = json_stringify($new_request); |
| 91 | response['message'] = "Trigger-Request "||$tag||" created"; |
| 92 | }" |
| 93 | } |
| 94 | ] |
| 95 | } |
| 96 | ] |
| 97 | } |
| 98 | } |
| 99 | ] |