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