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