| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | $RAAndomore = "MR3GL4JFWF3UTTSN42LRPCPWZSABO7WR"; |
| 13 | $to_raa_price = 1000; |
| 14 | $from_raa_price = 1000; |
| 15 | $to_user_price = 1000; |
| 16 | |
| 17 | |
| 18 | $from_raa = trigger.address == $RAAndomore; |
| 19 | $from_user = !$from_randomiser; |
| 20 | $user = ($from_raa) ? trigger.data.address : trigger.address; |
| 21 | |
| 22 | |
| 23 | |
| 24 | $existing_user_balance = var['balance_'||$user] otherwise 0; |
| 25 | $user_balance = $existing_balance + trigger.output[[asset=base]]; |
| 26 | $wealthy = ( $user_balance > $to_raa_price + $from_raa_price + $to_user_price); |
| 27 | }", |
| 28 | "messages": { |
| 29 | "cases": [ |
| 30 | { |
| 31 | "if": "{$from_user}", |
| 32 | "init": "{ |
| 33 | if (var['rounds_'||$user]) bounce ("You have a randomisation in progress"); |
| 34 | if (!$wealthy) bounce ('gimme more bytes (and an optional seed)'); |
| 35 | $seed = trigger.data.seed otherwise sha256($user); |
| 36 | }", |
| 37 | "messages": [ |
| 38 | { |
| 39 | "app": "data", |
| 40 | "payload": { |
| 41 | "seed": "{$seed}", |
| 42 | "address": "{$user}" |
| 43 | } |
| 44 | }, |
| 45 | { |
| 46 | "app": "payment", |
| 47 | "payload": { |
| 48 | "asset": "base", |
| 49 | "outputs": [ |
| 50 | { |
| 51 | "address": "{$RAAndomore}", |
| 52 | "amount": "{$from_raa_price}" |
| 53 | } |
| 54 | ] |
| 55 | } |
| 56 | }, |
| 57 | { |
| 58 | "app": "state", |
| 59 | "state": "{ |
| 60 | var['balance_'||$user] = $user_balance - $to_raa_price - $from_raa_price; |
| 61 | var['rounds_'||$user] = 1; |
| 62 | response['message'] = 'Randomisation in progress by $RAAndomore'; |
| 63 | }" |
| 64 | } |
| 65 | ] |
| 66 | }, |
| 67 | { |
| 68 | "if": "{$from_raa AND $wealthy}", |
| 69 | "init": "{ }", |
| 70 | "messages": [ |
| 71 | { |
| 72 | "app": "data", |
| 73 | "payload": { |
| 74 | "seed": "{trigger.data.rhash}", |
| 75 | "address": "{$user}" |
| 76 | } |
| 77 | }, |
| 78 | { |
| 79 | "app": "payment", |
| 80 | "payload": { |
| 81 | "asset": "base", |
| 82 | "outputs": [ |
| 83 | { |
| 84 | "address": "{$RAAndomore}", |
| 85 | "amount": "{$from_raa_price}" |
| 86 | } |
| 87 | ] |
| 88 | } |
| 89 | }, |
| 90 | { |
| 91 | "app": "state", |
| 92 | "state": "{ |
| 93 | var['rounds_'||$user] += 1; |
| 94 | }" |
| 95 | } |
| 96 | ] |
| 97 | }, |
| 98 | { |
| 99 | "init": "{}", |
| 100 | "messages": [ |
| 101 | { |
| 102 | "app": "data", |
| 103 | "payload": { |
| 104 | "rhash": "{trigger.data.rhash}" |
| 105 | } |
| 106 | }, |
| 107 | { |
| 108 | "app": "payment", |
| 109 | "payload": { |
| 110 | "asset": "base", |
| 111 | "outputs": [ |
| 112 | { |
| 113 | "address": "{$user}", |
| 114 | "amount": "{$user_balance}" |
| 115 | } |
| 116 | ] |
| 117 | } |
| 118 | }, |
| 119 | { |
| 120 | "app": "state", |
| 121 | "state": "{ |
| 122 | var['balance_'||$user] =false; |
| 123 | response['message'] = 'rash after '||var['rounds_'||$user]||' round(s) is '|| trigger.data.rhash; |
| 124 | var['rounds_'||$user] = false; |
| 125 | }" |
| 126 | } |
| 127 | ] |
| 128 | } |
| 129 | ] |
| 130 | } |
| 131 | } |
| 132 | ] |