| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | }", |
| 9 | "messages": { |
| 10 | "cases": [ |
| 11 | { |
| 12 | "if": "{ !!trigger.data.store and !trigger.data.request_withdraw and !!trigger.data.hash_of_secret }", |
| 13 | "init": "{ |
| 14 | if (!!var[trigger.data.hash_of_secret]) |
| 15 | bounce ("This hash already exist, choose another secret phrase and hash it"); |
| 16 | }", |
| 17 | "messages": [ |
| 18 | { |
| 19 | "app": "state", |
| 20 | "state": "{ |
| 21 | $non_byte = trigger.output[[asset!=base]].asset; |
| 22 | $asset = ($non_byte != "none") ? $non_byte : "base"; |
| 23 | $amount = trigger.output[[asset=$asset]].amount; |
| 24 | var[trigger.data.hash_of_secret||"_amount"] = $amount; |
| 25 | var[trigger.data.hash_of_secret||"_asset"] = $asset; |
| 26 | response['message'] = "Safely stored, to withdraw later, use 'withdraw = true' + 'hash_of_my_secret = <hash of secret phrase> and wait for messages in payment"; |
| 27 | }" |
| 28 | } |
| 29 | ] |
| 30 | }, |
| 31 | { |
| 32 | "if": "{ !!trigger.data.request_withdraw and !!trigger.data.hash_of_secret }", |
| 33 | "init": "{ |
| 34 | if (!var[trigger.data.hash_of_secret||"_amount"]) |
| 35 | bounce ("This hash do not exist"); |
| 36 | if (!!var[trigger.data.hash_of_secret||"_withdrawer"]) |
| 37 | if (timestamp < var[trigger.data.hash_of_secret||"_Dead_line_timestamp"]) |
| 38 | bounce ("There is a withdraw request in progress"); |
| 39 | |
| 40 | $dead_line = timestamp + 60*60 ; |
| 41 | }", |
| 42 | "messages": [ |
| 43 | { |
| 44 | "app": "data", |
| 45 | "payload": { |
| 46 | "message": "{ "You have until "|| timestamp_to_string($dead_line, 'datetime') ||" to provide the secret key" }" |
| 47 | } |
| 48 | }, |
| 49 | { |
| 50 | "app": "payment", |
| 51 | "payload": { |
| 52 | "asset": "base", |
| 53 | "outputs": [ |
| 54 | { |
| 55 | "address": "{ trigger.initial_address }", |
| 56 | "amount": "{ 5 }" |
| 57 | } |
| 58 | ] |
| 59 | } |
| 60 | }, |
| 61 | { |
| 62 | "app": "state", |
| 63 | "state": "{ |
| 64 | if (!!var[trigger.data.hash_of_secret||"_withdrawer"]) |
| 65 | var[var[trigger.data.hash_of_secret||"_withdrawer"]] = false; |
| 66 | var[trigger.data.hash_of_secret||"_withdrawer"] = trigger.initial_address; |
| 67 | var[trigger.data.hash_of_secret||"_Dead_line_timestamp"] = $dead_line; |
| 68 | var[trigger.initial_address] = trigger.data.hash_of_secret; |
| 69 | response['message'] = "You have until "|| timestamp_to_string($dead_line, 'datetime') ||" to provide the secret key"; |
| 70 | }" |
| 71 | } |
| 72 | ] |
| 73 | }, |
| 74 | { |
| 75 | "if": "{ !!trigger.data.proove_ownership and !!trigger.data.secret_phrase }", |
| 76 | "init": "{ |
| 77 | |
| 78 | if (!var[trigger.initial_address]) |
| 79 | bounce ("Attention!, I'm not ready to receive your secret phrase, don't send it or it can be compromised"); |
| 80 | $hash = var[trigger.initial_address]; |
| 81 | |
| 82 | if (timestamp > var[$hash||"_Dead_line_timestamp"]) |
| 83 | bounce ("Too late! don't send you secret phrase!, use 'withdraw' + 'hash_of_my_secret' again"); |
| 84 | |
| 85 | if (sha256(trigger.data.secret_phrase) != $hash) |
| 86 | bounce ("The secret phrase hash does not match with the one previously given"||$hash||" "||sha256(trigger.data.secret_phrase)); |
| 87 | |
| 88 | $separator_position = index_of(var[$hash], " "); |
| 89 | $withdraw_amount = substring(var[$hash], 0, $separator_position); |
| 90 | $withdraw_asset = substring(var[$hash], $separator_position); |
| 91 | }", |
| 92 | "messages": [ |
| 93 | { |
| 94 | "app": "payment", |
| 95 | "payload": { |
| 96 | "asset": "{ var[$hash||"_asset"] }", |
| 97 | "outputs": [ |
| 98 | { |
| 99 | "address": "{ trigger.initial_address }", |
| 100 | "amount": "{ var[$hash||"_amount"] }" |
| 101 | } |
| 102 | ] |
| 103 | } |
| 104 | }, |
| 105 | { |
| 106 | "app": "state", |
| 107 | "state": "{ |
| 108 | response['message'] = $withdraw_amount || " Funds sent "|| $withdraw_asset; |
| 109 | |
| 110 | var[trigger.initial_address] = false; |
| 111 | var[trigger.initial_address||"_Dead_line_timestamp"] = false; |
| 112 | var[$hash||"_withdrawer"]=false; |
| 113 | var[$hash||"_asset"]=false; |
| 114 | var[$hash||"_amount"]=false; |
| 115 | var[$hash||"_Dead_line_timestamp"]=false; |
| 116 | response['message'] = "Funds sent"; |
| 117 | }" |
| 118 | } |
| 119 | ] |
| 120 | }, |
| 121 | { |
| 122 | "messages": [ |
| 123 | { |
| 124 | "app": "state", |
| 125 | "state": "{ |
| 126 | |
| 127 | if (!!trigger.data.store) |
| 128 | bounce ("Instruction: Add 'hash_of_secret = [(sha255 base64) hash]', to create hash, choose a secret phrase (max length of 1024 char) and pass it through a sha256 hasher that encode in base64."); |
| 129 | if (!!trigger.data.request_withdraw) |
| 130 | bounce ("Instruction: Add 'hash_of_secret = <hash of the secret phrase>."); |
| 131 | if (!!trigger.data.proove_ownership) |
| 132 | bounce ("Instruction: Add 'secret_phrase = <clear secret phrase>."); |
| 133 | |
| 134 | bounce ("Instruction: First choose what to do, 'store=true' to store any Obyte assets funds, 'request_withdraw=true' to initiate a withdraw or 'proove_ownership=true' then follow next instructions"); |
| 135 | }" |
| 136 | } |
| 137 | ] |
| 138 | } |
| 139 | ] |
| 140 | } |
| 141 | } |
| 142 | ] |