| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "getters": "{ |
| 5 | $peek = ($i)=>var[var["tail"] - ($i OTHERWISE 0)]; |
| 6 | $msg_push = ($val)=>[ |
| 7 | { |
| 8 | app: "data", |
| 9 | payload: { |
| 10 | push: $val |
| 11 | } |
| 12 | }, |
| 13 | { |
| 14 | app: "payment", |
| 15 | payload: { |
| 16 | outputs: [ |
| 17 | {address: this_address, amount: length($val)+100} |
| 18 | ] |
| 19 | } |
| 20 | } |
| 21 | ]; |
| 22 | $msg_pop = ()=>[ |
| 23 | { |
| 24 | app: "data", |
| 25 | payload: { |
| 26 | pop: 1 |
| 27 | } |
| 28 | }, |
| 29 | { |
| 30 | app: "payment", |
| 31 | payload: { |
| 32 | outputs: [{address: this_address, amount: 100}] |
| 33 | } |
| 34 | } |
| 35 | ]; |
| 36 | $size = ()=>var["head"]; |
| 37 | $can_push = ($address)=>{ |
| 38 | if (is_aa(params.can_push_controller)) |
| 39 | return params.can_push_controller#4.$can_push($address); |
| 40 | return $address == params.can_push_controller; |
| 41 | }; |
| 42 | $can_pop = ($address)=>{ |
| 43 | if (is_aa(params.can_pop_controller)) |
| 44 | return params.can_pop_controller#4.$can_push($address); |
| 45 | return $address == params.can_pop_controller; |
| 46 | }; |
| 47 | }", |
| 48 | "init": "{ |
| 49 | $MIN_PAYOUT = 10000; |
| 50 | $COLLECTION_ADDRESS = "ZIT3YPDTLGAO7MVO2ONNDMSEYS2VELX6"; |
| 51 | |
| 52 | $head_ptr = var["head"] OTHERWISE 0; |
| 53 | }", |
| 54 | "messages": [ |
| 55 | { |
| 56 | "if": "{(trigger.data.pop OR trigger.data.clear) AND balance["base"] > $MIN_PAYOUT}", |
| 57 | "app": "payment", |
| 58 | "payload": { |
| 59 | "outputs": [ |
| 60 | { |
| 61 | "address": "{$COLLECTION_ADDRESS}" |
| 62 | } |
| 63 | ] |
| 64 | } |
| 65 | }, |
| 66 | { |
| 67 | "app": "state", |
| 68 | "init": "{ |
| 69 | $is_allowed_to_pop = $can_pop(trigger.address); |
| 70 | if (trigger.data.pop){ |
| 71 | require($can_push(trigger.address), "You cannot pop data from this stack"); |
| 72 | $new_head_ptr = max(0, $head_ptr - 1); |
| 73 | } |
| 74 | else if (trigger.data.push){ |
| 75 | require($is_allowed_to_pop, "You cannot push data to this stack"); |
| 76 | $new_head_ptr = $head_ptr + 1; |
| 77 | } |
| 78 | else if (trigger.data.clear){ |
| 79 | require($is_allowed_to_pop, "You cannot clear this stack"); |
| 80 | $new_head_ptr = 0; |
| 81 | } |
| 82 | }", |
| 83 | "state": "{ |
| 84 | if (trigger.data.pop) |
| 85 | var[$head_ptr] = false; |
| 86 | else if (trigger.data.push) |
| 87 | var[$new_head_ptr] = trigger.data.push; |
| 88 | var["head"] = $new_head_ptr; |
| 89 | }" |
| 90 | } |
| 91 | ] |
| 92 | } |
| 93 | ] |