| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 11000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $aa_name = "SAAFE"; |
| 9 | $aa_owner = "O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; |
| 10 | $danaa = "M2GL3REJ3TJPHVC4GMCBKQI54NEKRYNH"; |
| 11 | |
| 12 | |
| 13 | $puk = (trigger.data.puk1 AND trigger.data.puk2)? trigger.data.puk1||trigger.data.puk2 : false; |
| 14 | |
| 15 | |
| 16 | $signature = (trigger.data.s1 AND trigger.data.s2)? trigger.data.s1||trigger.data.s2 : false; |
| 17 | |
| 18 | |
| 19 | $received_unbase_asset = trigger.output[[asset!=base]].asset; |
| 20 | $received_asset = ($received_unbase_asset != "none")? $received_unbase_asset : "base"; |
| 21 | $asset = trigger.data.asset otherwise $received_asset; |
| 22 | $asset_nice_name = var[$danaa][$asset] otherwise $asset; |
| 23 | |
| 24 | |
| 25 | $drawer = sha256($puk||'_'||$asset); |
| 26 | |
| 27 | |
| 28 | $dr= "drawer_"||$drawer; |
| 29 | $am = $dr||"_amount"; |
| 30 | $as = $dr||"_asset"; |
| 31 | $pu = $dr||"_private_user"; |
| 32 | $ls = "last_s_"||sha256($puk); |
| 33 | }", |
| 34 | "messages": { |
| 35 | "cases": [ |
| 36 | { |
| 37 | "if": "{ $puk AND !($signature or trigger.data.ad) }", |
| 38 | "messages": [ |
| 39 | { |
| 40 | "app": "state", |
| 41 | "state": "{ |
| 42 | if (!var[$as] and trigger.data.private) |
| 43 | var[$pu] = trigger.address; |
| 44 | var[$am] += trigger.output[[asset=$asset]].amount; |
| 45 | var[$as] = $asset; |
| 46 | response['message'] = var[$am]||' '||$asset_nice_name||' are safe under the puk '||$puk; |
| 47 | }" |
| 48 | } |
| 49 | ] |
| 50 | }, |
| 51 | { |
| 52 | "if": "{ $puk AND $signature AND trigger.data.ad }", |
| 53 | "init": "{ |
| 54 | |
| 55 | if (var[$pu]) |
| 56 | if (var[$pu] != trigger.address) |
| 57 | bounce ("Not allowed to withdraw from this private drawer!"); |
| 58 | |
| 59 | if (!var[$as]) bounce ("puk doesn\'t exists with asset!"||$asset_nice_name); |
| 60 | |
| 61 | if (var[$ls]) |
| 62 | if (var[$ls] == sha256($signature)) |
| 63 | bounce ("Cannot use 2 times the same signature in a row!"); |
| 64 | |
| 65 | if (!is_valid_sig(trigger.data.ad, "-----BEGIN PUBLIC KEY-----"||$puk||"-----END PUBLIC KEY-----", $signature)) bounce ("Wrong signature!"); |
| 66 | |
| 67 | |
| 68 | $old_balance = var[$am]; |
| 69 | $amount = trigger.data.am otherwise $old_balance; |
| 70 | }", |
| 71 | "messages": [ |
| 72 | { |
| 73 | "app": "payment", |
| 74 | "payload": { |
| 75 | "asset": "{$asset}", |
| 76 | "outputs": [ |
| 77 | { |
| 78 | "address": "{trigger.data.ad}", |
| 79 | "amount": "{$amount}" |
| 80 | } |
| 81 | ] |
| 82 | } |
| 83 | }, |
| 84 | { |
| 85 | "app": "state", |
| 86 | "state": "{ |
| 87 | $new_balance = $old_balance - $amount - 1000; |
| 88 | response['message'] = $amount||' of the '||$old_balance||' '||$asset_nice_name||' withdrawn from '||$puk||' to '|| trigger.data.ad; |
| 89 | if ($new_balance < 1000) |
| 90 | { |
| 91 | var[$am] = false; var[$as] = false; var[$pu] = false; |
| 92 | } |
| 93 | else |
| 94 | var[$ls] = sha256($signature); |
| 95 | }" |
| 96 | } |
| 97 | ] |
| 98 | }, |
| 99 | { |
| 100 | "messages": [ |
| 101 | { |
| 102 | "app": "state", |
| 103 | "state": "{ |
| 104 | if(!($puk)) |
| 105 | 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"); |
| 106 | if(!($signature)) |
| 107 | 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'>."); |
| 108 | }" |
| 109 | } |
| 110 | ] |
| 111 | } |
| 112 | ] |
| 113 | } |
| 114 | } |
| 115 | ] |