| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "doc_url": "https://raw.githubusercontent.com/jldevelops/free-sender/master/description.json", |
| 5 | "init": "{ |
| 6 | if(array_length(unit[trigger.unit].authors) != 1) |
| 7 | bounce('multi signature not allowed'); |
| 8 | if(trigger.output[[asset!=base]].asset != 'none'){ |
| 9 | $asset = trigger.output[[asset!=base]].asset; |
| 10 | if($asset and $asset == 'ambiguous') |
| 11 | bounce('Only 1 asset per tx'); |
| 12 | } |
| 13 | else |
| 14 | $asset = 'base'; |
| 15 | }", |
| 16 | "messages": { |
| 17 | "cases": [ |
| 18 | { |
| 19 | "if": "{$asset != 'base'}", |
| 20 | "init": "{ |
| 21 | if(!trigger.data.to or !is_valid_address(trigger.data.to)) |
| 22 | bounce('to param invalid'); |
| 23 | $c = unit[trigger.unit].headers_commission + unit[trigger.unit].payload_commission; |
| 24 | if($c > 1000) |
| 25 | $trigger_cost = 1000; |
| 26 | else |
| 27 | $trigger_cost = $c; |
| 28 | }", |
| 29 | "messages": [ |
| 30 | { |
| 31 | "app": "payment", |
| 32 | "payload": { |
| 33 | "asset": "{$asset}", |
| 34 | "outputs": [ |
| 35 | { |
| 36 | "address": "{trigger.data.to}", |
| 37 | "amount": "{trigger.output[[asset=$asset]]}" |
| 38 | } |
| 39 | ] |
| 40 | } |
| 41 | }, |
| 42 | { |
| 43 | "app": "payment", |
| 44 | "payload": { |
| 45 | "asset": "base", |
| 46 | "outputs": [ |
| 47 | { |
| 48 | "address": "{trigger.address}", |
| 49 | "amount": "{trigger.output[[asset=base]]+$trigger_cost}" |
| 50 | } |
| 51 | ] |
| 52 | } |
| 53 | }, |
| 54 | { |
| 55 | "app": "state", |
| 56 | "state": "{ |
| 57 | $tot = unit[response_unit].headers_commission + unit[response_unit].payload_commission + $trigger_cost; |
| 58 | if((balance[base] - trigger.output[[asset=base]]) < $tot) |
| 59 | bounce('out of funds'); |
| 60 | }" |
| 61 | } |
| 62 | ] |
| 63 | }, |
| 64 | { |
| 65 | "messages": [ |
| 66 | { |
| 67 | "app": "state", |
| 68 | "state": "{ |
| 69 | response['message'] = 'thanks for funds'; |
| 70 | }" |
| 71 | } |
| 72 | ] |
| 73 | } |
| 74 | ] |
| 75 | } |
| 76 | } |
| 77 | ] |