| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | |
| 9 | $name = "DAG Snapshot for AA"; |
| 10 | |
| 11 | |
| 12 | |
| 13 | }", |
| 14 | "messages": { |
| 15 | "cases": [ |
| 16 | { |
| 17 | "if": "{ !!trigger.data.first_unit_id and !!trigger.data.second_unit_id and !!trigger.data.timestamp }", |
| 18 | "init": "{ |
| 19 | $address = trigger.data.address otherwise trigger.address; |
| 20 | if(!is_valid_address($address)) bounce ("invalid address"); |
| 21 | |
| 22 | $asset = trigger.data.asset otherwise "base"; |
| 23 | |
| 24 | $date_and_time = timestamp_to_string(timestamp); |
| 25 | if(!is_integer(trigger.data.timestamp )) bounce("invalid timestamp"); |
| 26 | |
| 27 | $first_timestamp = unit[trigger.data.second_unit_id].timestamp; |
| 28 | |
| 29 | response['nts'] = 'kGQZkIj3gRclCp2vw9LMg0jVnPKYCebXHxm8XYPxbQ4='; |
| 30 | response['ts'] = unit['kGQZkIj3gRclCp2vw9LMg0jVnPKYCebXHxm8XYPxbQ4='].timestamp; |
| 31 | response['mts'] = trigger.data.first_unit_id; |
| 32 | response['mts'] = unit[trigger.data.first_unit_id].timestamp; |
| 33 | if(!$first_timestamp) bounce ('first_unit not existing'); |
| 34 | if($first_timestamp>trigger.data.timestamp) bounce("first unit should be earlier than "||$date_and_time||"("||$second_timestamp||")"); |
| 35 | |
| 36 | $second_timestamp = unit[trigger.data.second_unit_id].timestamp; |
| 37 | if(!$second_timestamp) bounce ('first_unit not existing'); |
| 38 | if(trigger.data.timestamp>$second_timestamp) bounce("second unit should be older than "||$date_and_time||"("||$second_timestamp||")"); |
| 39 | |
| 40 | $amount_from_first = unit[trigger.data.first_unit_id].messages[[.app='payment', .asset=$asset]].payload.outputs[[.address=$address] ].amount; |
| 41 | if(!$amount_from_first)bounce("asset not existing in first unit"); |
| 42 | |
| 43 | $amount_from_second= unit[trigger.data.second_unit_id].messages[[.app='payment', .asset=$asset]].payload.outputs[[.address=$address] ].amount; |
| 44 | if(!$amount_from_second)bounce("asset not existing in second unit"); |
| 45 | |
| 46 | $prooven_amount = ($amount_from_first<$amount_from_second) ? $amount_from_first : $amount_from_second; |
| 47 | |
| 48 | $id = sha256($address||$asset||trigger.data.timestamp); |
| 49 | if (!!var[$id]) bounce ("proof already existing for "||var[$id]||' '||$asset); |
| 50 | }", |
| 51 | "messages": [ |
| 52 | { |
| 53 | "app": "state", |
| 54 | "state": "{ |
| 55 | var[$id] = $amount; |
| 56 | response["message"] = $amount||' '||$asset||" proof stored"; |
| 57 | }" |
| 58 | } |
| 59 | ] |
| 60 | }, |
| 61 | { |
| 62 | "messages": [ |
| 63 | { |
| 64 | "app": "state", |
| 65 | "state": "{ |
| 66 | bounce ("I need a 'first_unit_id', 'second_unit_id' and 'timestamp', to store the 'hodling amount proof', the timestamp must be include betwwen the timestamp of the first and the second unit."); |
| 67 | }" |
| 68 | } |
| 69 | ] |
| 70 | } |
| 71 | ] |
| 72 | } |
| 73 | } |
| 74 | ] |