| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | |
| 6 | |
| 7 | $owner = "O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; |
| 8 | |
| 9 | |
| 10 | $puk = (trigger.data.puk1 AND trigger.data.puk2)? trigger.data.puk1||trigger.data.puk2 : ""; |
| 11 | $b_is_puk_received = $puk_received != ""; |
| 12 | |
| 13 | |
| 14 | $signature_received = (trigger.data.s1 AND trigger.data.s2)? trigger.data.s1||trigger.data.s2 : ""; |
| 15 | $b_is_signature_received = $signature_received != ""; |
| 16 | |
| 17 | $asset = trigger.data.asset otherwise trigger.output[[asset=base]].asset; |
| 18 | $asset_nice_name = ($asset == 'base')? 'bytes' : $asset; |
| 19 | $key = $puk||'_'||$asset; |
| 20 | }", |
| 21 | "messages": { |
| 22 | "cases": [ |
| 23 | { |
| 24 | "if": "{($b_is_puk_received) AND !($b_is_signature_received or trigger.data.ad)}", |
| 25 | "messages": [ |
| 26 | { |
| 27 | "app": "state", |
| 28 | "state": "{ |
| 29 | var[$key] += trigger.output[[asset=$asset]]; |
| 30 | response['message'] = var[$key]||' '||$asset_nice_name||' are safe under the puk '||$puk; |
| 31 | }" |
| 32 | } |
| 33 | ] |
| 34 | }, |
| 35 | { |
| 36 | "if": "{($b_is_puk_received) AND ($b_is_signature_received or trigger.data.ad) }", |
| 37 | "init": "{ |
| 38 | if (!var[$key]) bounce ("puk doesn\'t exists with asset "||$asset_nice_name); |
| 39 | $withdraw_hash= sha256($puk||trigger.data.ad); |
| 40 | if (var[$withdraw_hash]) bounce ("Withdraw address already used with this SAAFE, this is forbidden for safety reasons: the signature for this address has been publicly visible, so anyone could trigger a new withdraw to this address, it could be a problem if the first withdraw was not a full one and the address not one from the owner of the SAAFE."); |
| 41 | if (!is_valid_sig(trigger.data.ad, "-----BEGIN PUBLIC KEY-----"||$puk||"-----END PUBLIC KEY-----", trigger.data.s1||trigger.data.s2)) bounce ("Wrong signature!"); |
| 42 | $old_balance = var[$key]; |
| 43 | $amount = trigger.data.am otherwise var[$key]; |
| 44 | }", |
| 45 | "messages": [ |
| 46 | { |
| 47 | "app": "payment", |
| 48 | "payload": { |
| 49 | "asset": "{$asset}", |
| 50 | "outputs": [ |
| 51 | { |
| 52 | "address": "{trigger.data.ad}", |
| 53 | "amount": "{$amount}" |
| 54 | } |
| 55 | ] |
| 56 | } |
| 57 | }, |
| 58 | { |
| 59 | "app": "state", |
| 60 | "state": "{ |
| 61 | $new_balance = $old_balance - $amount - 1000; |
| 62 | response['message'] = $amount||' of the '||$old_balance||' '||$asset_nice_name||' withdrawn from '||$puk||' to '|| trigger.data.ad; |
| 63 | if ($new_balance < 2000) |
| 64 | var[$key] = false; |
| 65 | else |
| 66 | var[$withdraw_hash] = "used"; |
| 67 | }" |
| 68 | } |
| 69 | ] |
| 70 | }, |
| 71 | { |
| 72 | "messages": [ |
| 73 | { |
| 74 | "app": "state", |
| 75 | "state": "{ |
| 76 | bounce ("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 later, 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'>."); |
| 77 | }" |
| 78 | } |
| 79 | ] |
| 80 | } |
| 81 | ] |
| 82 | } |
| 83 | } |
| 84 | ] |