| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $OWNER = "O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; |
| 6 | $RAAndomore = "MR3GL4JFWF3UTTSN42LRPCPWZSABO7WR"; |
| 7 | |
| 8 | |
| 9 | $HOUR = 3600; |
| 10 | $DAY = 24 * $HOURS; |
| 11 | $ticket_price = 10000; |
| 12 | $round_buying_period = 3 * $DAY; |
| 13 | $round_secret_sharing_period = 1 * $HOUR; |
| 14 | |
| 15 | $hash = trigger.data.sha256_of_secret otherwise trigger.data.h otherwise ""; $got_hash = ($hash!= ""); |
| 16 | $secret = trigger.data.secret otherwise trigger.data.s otherwise ""; $got_secret = ($secret!= ""); |
| 17 | |
| 18 | |
| 19 | $ellapsed_time = (timestamp - var["start_timestamp"]); |
| 20 | $running = var["running"] and ($ellapsed_time < $round_buying_period); |
| 21 | $waiting_secrets = var["waiting_secrets"] and ($ellapsed_time < $round_secret_sharing_period); |
| 22 | |
| 23 | }", |
| 24 | "messages": { |
| 25 | "cases": [ |
| 26 | { |
| 27 | "if": "{ $running and $got_hash }", |
| 28 | "init": "{ |
| 29 | if (trigger.output[[asset=base]]<$ticket_price) bounce ("Ticket price is '"||$ticket_price||"' bytes"); |
| 30 | }", |
| 31 | "messages": [ |
| 32 | { |
| 33 | "app": "state", |
| 34 | "state": "{ |
| 35 | |
| 36 | $count = (var["hash_count"] otherwise 0) +1; |
| 37 | $new_count = ($count!=6)? $count : 1; |
| 38 | var["hash_count"] = $new_count; |
| 39 | var["hash_"||$new_count] = $hash; |
| 40 | |
| 41 | |
| 42 | $player_count = (var["player_count"] otherwise 0) +1; |
| 43 | var["player_"||$player_count||"_a"] = trigger.address; |
| 44 | var["player_"||$player_count||"_h"] = $hash; |
| 45 | var["player_count"] = $player_count; |
| 46 | response['message'] = "entry accepted"; |
| 47 | }" |
| 48 | } |
| 49 | ] |
| 50 | }, |
| 51 | { |
| 52 | "if": "{ $got_secret }", |
| 53 | "init": "{ |
| 54 | }", |
| 55 | "messages": [ |
| 56 | { |
| 57 | "app": "data", |
| 58 | "payload": { |
| 59 | "message": "{$message}", |
| 60 | "pay_id": "{$pay_id}" |
| 61 | } |
| 62 | }, |
| 63 | { |
| 64 | "app": "payment", |
| 65 | "payload": { |
| 66 | "asset": "base", |
| 67 | "outputs": [ |
| 68 | { |
| 69 | "address": "{$address}", |
| 70 | "amount": "{$amount}" |
| 71 | } |
| 72 | ] |
| 73 | } |
| 74 | }, |
| 75 | { |
| 76 | "app": "payment", |
| 77 | "payload": { |
| 78 | "asset": "base", |
| 79 | "outputs": [ |
| 80 | { |
| 81 | "address": "{$address2}", |
| 82 | "amount": "{$amount2}" |
| 83 | } |
| 84 | ] |
| 85 | } |
| 86 | }, |
| 87 | { |
| 88 | "app": "state", |
| 89 | "state": "{ |
| 90 | }" |
| 91 | } |
| 92 | ] |
| 93 | }, |
| 94 | { |
| 95 | "init": "{ |
| 96 | if ($got_hash) |
| 97 | response['message'] = "Draw in process, please try later for the next round, funds returned"; |
| 98 | |
| 99 | if (!$running) |
| 100 | { |
| 101 | |
| 102 | |
| 103 | $best_random = var[$RAAndomore]["last_random_hash"]||timestamp; |
| 104 | $num1 = number_from_seed($best_random, 1, var["player_count"]); |
| 105 | $ad1 = var["player_"||$num1||"_a"]; |
| 106 | $h1 = var["player_"||$num1||"_h"]; |
| 107 | |
| 108 | $num2a= number_from_seed($ad1, 1, var["player_count"]-1); |
| 109 | $num2b = ($num2 != $num1) ? $num2 : $num2 + 1; |
| 110 | $ad2 = var["player_"||$num2b||"_a"]; |
| 111 | $h2 = var["player_"||$num2b||"_h"]; |
| 112 | |
| 113 | $num3 = number_from_seed($ad2, 3, var["player_count"]); |
| 114 | $num3b = ($num3 != $num2) ? $num3 : $num3 - 1; |
| 115 | $num3c = ($num3b != $num1) ? $num3b : $num3b - 1; |
| 116 | $ad3 = var["player_"||$num3c||"_a"]; |
| 117 | $h3 = var["player_"||$num3c||"_h"]; |
| 118 | } |
| 119 | |
| 120 | }", |
| 121 | "messages": [ |
| 122 | { |
| 123 | "app": "data", |
| 124 | "payload": { |
| 125 | "seed": "{sha256(trigger.address||$hash)}" |
| 126 | } |
| 127 | }, |
| 128 | { |
| 129 | "app": "payment", |
| 130 | "payload": { |
| 131 | "outputs": [ |
| 132 | { |
| 133 | "address": "{$RAAndomore}", |
| 134 | "amount": "{1}" |
| 135 | } |
| 136 | ] |
| 137 | } |
| 138 | }, |
| 139 | { |
| 140 | "if": "{$got_hash}", |
| 141 | "app": "payment", |
| 142 | "payload": { |
| 143 | "outputs": [ |
| 144 | { |
| 145 | "address": "{trigger.address}", |
| 146 | "amount": "{1000}" |
| 147 | } |
| 148 | ] |
| 149 | } |
| 150 | }, |
| 151 | { |
| 152 | "if": "{!$running}", |
| 153 | "app": "payment", |
| 154 | "payload": { |
| 155 | "outputs": [ |
| 156 | { |
| 157 | "address": "{trigger.address}", |
| 158 | "amount": "{1000}" |
| 159 | } |
| 160 | ] |
| 161 | } |
| 162 | }, |
| 163 | { |
| 164 | "if": "{!$running}", |
| 165 | "app": "payment", |
| 166 | "payload": { |
| 167 | "outputs": [ |
| 168 | { |
| 169 | "address": "{trigger.address}", |
| 170 | "amount": "{1000}" |
| 171 | } |
| 172 | ] |
| 173 | } |
| 174 | }, |
| 175 | { |
| 176 | "if": "{!$running}", |
| 177 | "app": "payment", |
| 178 | "payload": { |
| 179 | "outputs": [ |
| 180 | { |
| 181 | "address": "{trigger.address}", |
| 182 | "amount": "{trigger.output[[asset=base]]-1000}" |
| 183 | } |
| 184 | ] |
| 185 | } |
| 186 | }, |
| 187 | { |
| 188 | "app": "state", |
| 189 | "state": "{ |
| 190 | var["running"] = $running; |
| 191 | }" |
| 192 | } |
| 193 | ] |
| 194 | } |
| 195 | ] |
| 196 | } |
| 197 | } |
| 198 | ] |