| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $aa_name = "SAAFE"; |
| 9 | $aa_owner = "O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; |
| 10 | $danaa = "LLAVLVFN3CPBHTAB62NOIZLAMPABR2YF"; |
| 11 | |
| 12 | |
| 13 | $puk_part1 = trigger.data.puk1 otherwise ""; |
| 14 | $puk_part2 = trigger.data.puk2 otherwise ""; |
| 15 | $puk_part3 = trigger.data.puk3 otherwise ""; |
| 16 | $puk_part4 = trigger.data.puk4 otherwise ""; |
| 17 | $puk = $puk_part1 || $puk_part2|| $puk_part3|| $puk_part4; |
| 18 | $puk_received = ($puk != ""); |
| 19 | |
| 20 | |
| 21 | $s_part1 = trigger.data.s1 otherwise ""; |
| 22 | $s_part2 = trigger.data.s2 otherwise ""; |
| 23 | $s_part3 = trigger.data.s3 otherwise ""; |
| 24 | $s_part4 = trigger.data.s4 otherwise ""; |
| 25 | $signature = $s_part1 || $s_part2|| $s_part3 || $s_part4; |
| 26 | $signature_received = $signature != ""; |
| 27 | |
| 28 | |
| 29 | $received_unbase_asset = trigger.output[[asset!=base]].asset; |
| 30 | $received_asset = ($received_unbase_asset != "none")? $received_unbase_asset : "base"; |
| 31 | $asset = trigger.data.asset otherwise $received_asset; |
| 32 | $asset_nice_name = var[$danaa][$asset||"_shortName"] otherwise $asset; |
| 33 | |
| 34 | |
| 35 | $drawer = sha256($puk||"_"||$asset); |
| 36 | |
| 37 | |
| 38 | $dr = "drawer_"||$drawer; |
| 39 | $am = $dr||"_amount"; |
| 40 | $as = $dr||"_asset"; |
| 41 | $pu = $dr||"_private_user"; |
| 42 | $ls = "last_s_"||sha256($puk); |
| 43 | }", |
| 44 | "messages": { |
| 45 | "cases": [ |
| 46 | { |
| 47 | "if": "{$puk_received and $signature_received and !trigger.data.withdraw_address}", |
| 48 | "init": "{ |
| 49 | |
| 50 | if (!is_valid_sig("safe", $puk, $signature)) |
| 51 | bounce ("The fund cannot be safely store because the signature entered is note recognise as sign message containing the word 'safe' please check the documation !"); |
| 52 | }", |
| 53 | "messages": [ |
| 54 | { |
| 55 | "app": "state", |
| 56 | "state": "{ |
| 57 | if (!var[$as] and trigger.data.private) |
| 58 | var[$pu] = trigger.address; |
| 59 | var[$am] += trigger.output[[asset=$asset]].amount; |
| 60 | var[$as] = $asset; |
| 61 | response['message'] = var[$am]||' '||$asset_nice_name||' are safe under the puk '||$puk; |
| 62 | }" |
| 63 | } |
| 64 | ] |
| 65 | }, |
| 66 | { |
| 67 | "if": "{ $puk_received and $signature_received and trigger.data.withdraw_address }", |
| 68 | "init": "{ |
| 69 | |
| 70 | if (var[$pu]) |
| 71 | if (var[$pu] != trigger.address) |
| 72 | bounce ("Not allowed to withdraw from this private drawer!"); |
| 73 | |
| 74 | if (!var[$as]) bounce ("puk doesn\'t exists with asset!"||$asset_nice_name); |
| 75 | |
| 76 | if (var[$ls]) |
| 77 | if (var[$ls] == sha256($signature)) |
| 78 | bounce ("Cannot use 2 times the same signature in a row!"); |
| 79 | |
| 80 | if (!is_valid_sig(trigger.data.withdraw_address, $puk, $signature)) |
| 81 | bounce ("The 'withdraw address' signed is not the same as the one that was asked to use ! or this signature was not created with private key linked to "||$puk||" !"); |
| 82 | |
| 83 | |
| 84 | $old_balance = var[$am]; |
| 85 | $amount = trigger.data.withdraw_amount otherwise $old_balance; |
| 86 | }", |
| 87 | "messages": [ |
| 88 | { |
| 89 | "app": "payment", |
| 90 | "payload": { |
| 91 | "asset": "{$asset}", |
| 92 | "outputs": [ |
| 93 | { |
| 94 | "address": "{trigger.data.withdraw_address}", |
| 95 | "amount": "{$amount}" |
| 96 | } |
| 97 | ] |
| 98 | } |
| 99 | }, |
| 100 | { |
| 101 | "app": "state", |
| 102 | "state": "{ |
| 103 | $new_balance = $old_balance - $amount; |
| 104 | var[$am] = $new_balance; |
| 105 | response['message'] = $amount||' of the '||$old_balance||' '||$asset_nice_name||' withdrawn from '||$puk||' to '|| trigger.data.withdraw_address; |
| 106 | if ($new_balance < 1000) |
| 107 | { |
| 108 | var[$am] = false; var[$as] = false; var[$pu] = false; |
| 109 | } |
| 110 | else |
| 111 | var[$ls] = sha256($signature); |
| 112 | }" |
| 113 | } |
| 114 | ] |
| 115 | }, |
| 116 | { |
| 117 | "messages": [ |
| 118 | { |
| 119 | "app": "state", |
| 120 | "state": "{ |
| 121 | if(!($puk)) |
| 122 | bounce ("To store or withdraw, you always have to set at least 'puk1' and 'puk2' to the 2 half of the public key, for which you have the related private key"); |
| 123 | if(!($signature)) |
| 124 | bounce ("To withdraw, set the puks fields, as well as an 'ad' field set to the Obyte adresse where you want to receive the funds and a 's1' and 's2' field set to <the 2 half signature of a message containing the address 'ad'>."); |
| 125 | }" |
| 126 | } |
| 127 | ] |
| 128 | } |
| 129 | ] |
| 130 | } |
| 131 | } |
| 132 | ] |