| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | |
| 9 | $name = "WEAALTH"; |
| 10 | $how_to_claim = "To claim you heritage, enter you signature"; |
| 11 | $how_to_setup = "To setup your testament, use, start+testament name then add + beneficiary + percentage, then finish then fill and later cancel_request"; |
| 12 | $how_to = $how_to_claim||$how_to_setup; |
| 13 | $request_heritage_fee = 50000; |
| 14 | |
| 15 | $HOLLAA = "C6M6BLAM2QTK727RTWA3YHZ4VW5ZIGBF"; |
| 16 | $Shafe = '2W6XFKSHXI5OJRZR7T4LQBFZ2GZ3BZBN'; |
| 17 | $DEFAULT_DELAY_TO_CANCEL = 4 * 7 * 24 * 60 * 60; |
| 18 | }", |
| 19 | "messages": { |
| 20 | "cases": [ |
| 21 | { |
| 22 | "if": "{ !!trigger.data.start and !!trigger.data.testament_name }", |
| 23 | "messages": [ |
| 24 | { |
| 25 | "app": "state", |
| 26 | "state": "{ |
| 27 | |
| 28 | if (!!var[trigger.data.testament_name]) bounce ("This name exist already!"); |
| 29 | |
| 30 | var[trigger.address] = trigger.data.testament_name; |
| 31 | |
| 32 | var[trigger.data.testament_name||"_writter"] = trigger.address; |
| 33 | |
| 34 | var[trigger.data.testament_name||"_balance"] = trigger.output[[asset=base]].amount - 2000; |
| 35 | |
| 36 | response['message'] = 'Testament setup started'; |
| 37 | }" |
| 38 | } |
| 39 | ] |
| 40 | }, |
| 41 | { |
| 42 | "if": "{ !!trigger.data.add and !!trigger.data.beneficiary and !!trigger.data.percentage}", |
| 43 | "init": "{ |
| 44 | $testament_name = var[trigger.address] otherwise trigger.data.testament_name otherwise bounce ($how_to); |
| 45 | if (!trigger.data.hash_of_secret) |
| 46 | bounce ("need 'hash_of_secret'"); |
| 47 | |
| 48 | if (!!var[$testament_name||"_writter"]) |
| 49 | if (trigger.address != var[$testament_name||"_writter"]) |
| 50 | bounce ("Account "||$testament_name||" already exist!"); |
| 51 | |
| 52 | if (!is_integer(trigger.data.percentage)) bounce ("Invalid percentage'!"); |
| 53 | if (trigger.data.percentage>100) bounce ("Invalid percentage'!"); |
| 54 | }", |
| 55 | "messages": [ |
| 56 | { |
| 57 | "app": "data", |
| 58 | "payload": { |
| 59 | "list_name": "{ $testament_name||"_beneficiaries" }", |
| 60 | "add": "{ trigger.data.beneficiary }", |
| 61 | "value": "{ "hash="||trigger.data.hash_of_secret||" %="||trigger.data.percentage }" |
| 62 | } |
| 63 | }, |
| 64 | { |
| 65 | "app": "payment", |
| 66 | "payload": { |
| 67 | "asset": "base", |
| 68 | "outputs": [ |
| 69 | { |
| 70 | "address": "{ $HOLLAA }", |
| 71 | "amount": 1000 |
| 72 | } |
| 73 | ] |
| 74 | } |
| 75 | }, |
| 76 | { |
| 77 | "app": "state", |
| 78 | "state": "{ |
| 79 | var[$testament_name||"_balance"] = trigger.output[[asset=base]].amount - 1000; |
| 80 | response['message'] = 'Beneficiariey added'; |
| 81 | }" |
| 82 | } |
| 83 | ] |
| 84 | }, |
| 85 | { |
| 86 | "if": "{ !!trigger.data.finish_testament }", |
| 87 | "init": "{ |
| 88 | $testament_name = var[trigger.address] otherwise trigger.data.testament_name otherwise bounce ($how_to); |
| 89 | if (!!var[$testament_name||"_writter"]) |
| 90 | if (trigger.address != var[$testament_name||"_writter"]) |
| 91 | bounce ("Account "||$testament_name||" already exist!"); |
| 92 | }", |
| 93 | "messages": [ |
| 94 | { |
| 95 | "app": "state", |
| 96 | "state": "{ |
| 97 | var[trigger.address] = false; |
| 98 | var[$testament_name||"_balance"] = trigger.output[[asset=base]].amount - 1000; |
| 99 | response['message'] = $testament_name||" activated ^^"; |
| 100 | }" |
| 101 | } |
| 102 | ] |
| 103 | }, |
| 104 | { |
| 105 | "if": "{ !!trigger.data.fill }", |
| 106 | "init": "{ |
| 107 | $testament_name = trigger.data.testament_name otherwise bounce ("needs testament name"); |
| 108 | }", |
| 109 | "messages": [ |
| 110 | { |
| 111 | "app": "state", |
| 112 | "state": "{ |
| 113 | var[$testament_name ||"_balance"] += trigger.output[[asset=base]].amount; |
| 114 | |
| 115 | response['message'] = "Testament balance updates ^^"; |
| 116 | }" |
| 117 | } |
| 118 | ] |
| 119 | }, |
| 120 | { |
| 121 | "if": "{ !!trigger.data.cancel_testament }", |
| 122 | "init": "{ |
| 123 | $testament_name = trigger.data.testament_name otherwise bounce ("needs testament name"); |
| 124 | |
| 125 | |
| 126 | if (!!var[$testament_name||"_writter"]) |
| 127 | if (trigger.address != var[$testament_name||"_writter"]) |
| 128 | bounce ("This is possible only from the writter of the testament"); |
| 129 | }", |
| 130 | "messages": [ |
| 131 | { |
| 132 | "app": "payment", |
| 133 | "payload": { |
| 134 | "asset": "base", |
| 135 | "outputs": [ |
| 136 | { |
| 137 | "address": "{ trigger.address }", |
| 138 | "amount": "{ var[$testament_name ||"_balance"] }" |
| 139 | } |
| 140 | ] |
| 141 | } |
| 142 | }, |
| 143 | { |
| 144 | "app": "state", |
| 145 | "state": "{ |
| 146 | var[$testament_name ||"_balance"] =false; |
| 147 | var[$testament_name ||"_writter"] =false; |
| 148 | response['message'] = "Testament cancelled ^^"; |
| 149 | }" |
| 150 | } |
| 151 | ] |
| 152 | }, |
| 153 | { |
| 154 | "if": "{ !!trigger.data.request_heritage and !!trigger.data.beneficiary }", |
| 155 | "init": "{ |
| 156 | $testament_name = trigger.data.testament_name otherwise bounce ($how_to); |
| 157 | |
| 158 | |
| 159 | if (trigger.output[[asset=base]].amount < $request_heritage_fee) |
| 160 | bounce ("Minimum fee for this is "||$request_heritage_fee); |
| 161 | |
| 162 | |
| 163 | if (!var[$testament_name||"_writter"]) |
| 164 | bounce ("Account "||$testament_name||" do NOT exist!"); |
| 165 | |
| 166 | |
| 167 | if (!var[$HOLLAA][$testament_name||"_beneficiaries_"||trigger.data.beneficiary]) |
| 168 | bounce ("Beneficiary do not exist"); |
| 169 | |
| 170 | |
| 171 | if (!!var[$testament_name||"_requester_address"]) |
| 172 | bounce ("Heritage validation already requested, wait for the waiting delay to expire and use 'ask_to_proof_ownership'"); |
| 173 | |
| 174 | |
| 175 | if (!!var[$testament_name||"_validated"]) |
| 176 | bounce ("the testament execution is already validated, you can directly use 'proove_ownership'"); |
| 177 | }", |
| 178 | "messages": [ |
| 179 | { |
| 180 | "app": "data", |
| 181 | "payload": { |
| 182 | "message": "{ trigger.data.beneficiary||" have requested his heritage" }" |
| 183 | } |
| 184 | }, |
| 185 | { |
| 186 | "app": "payment", |
| 187 | "payload": { |
| 188 | "asset": "base", |
| 189 | "outputs": [ |
| 190 | { |
| 191 | "address": "{ var[$testament_name||"_writter"] }", |
| 192 | "amount": 1000 |
| 193 | } |
| 194 | ] |
| 195 | } |
| 196 | }, |
| 197 | { |
| 198 | "app": "state", |
| 199 | "state": "{ |
| 200 | |
| 201 | var[$testament_name||"_requester_address"] = trigger.address; |
| 202 | var[trigger.address||"_requested_time"] = timestamp; |
| 203 | var[trigger.address||"_beneficiary"] = trigger.data.beneficiary; |
| 204 | var[trigger.address||"_testament_name"] = $testament_name; |
| 205 | |
| 206 | var[$testament_name||"_balance"] -= 1000; |
| 207 | response['message'] = "Request validated"; |
| 208 | }" |
| 209 | } |
| 210 | ] |
| 211 | }, |
| 212 | { |
| 213 | "if": "{ !!trigger.data.ask_to_proof_ownership }", |
| 214 | "init": "{ |
| 215 | |
| 216 | if (!var[trigger.address]) |
| 217 | bounce ("You cannot proof ownership before you have requested your heritage and waited for the delay"); |
| 218 | |
| 219 | if (!var[$testament_name||"_validated"]) |
| 220 | { |
| 221 | |
| 222 | $delay_to_cancel = var[var[trigger.address||"_testament_name"]||"_waiting_period"] |
| 223 | otherwise $DEFAULT_DELAY_TO_CANCEL; |
| 224 | $earlier_time = var[trigger.address||"_requested_time"] + $delay_to_cancel; |
| 225 | if (timestamp < $earlier_time) |
| 226 | bounce ("Too early to proof onwership wait for "||timestamp_to_string($earlier_time, 'datetime')); |
| 227 | |
| 228 | $validated=true; |
| 229 | } |
| 230 | |
| 231 | |
| 232 | $beneficiary = var[trigger.address||"_beneficiary"]; |
| 233 | $hash_and_percentage = var[$HOLLAA][$testament_name||"_beneficiaries_"||$beneficiary]; |
| 234 | $separator_pos=index_of($hash_and_percentage, " %="); |
| 235 | $hash = substring($hash_and_percentage, 0, $separator_pos); |
| 236 | |
| 237 | $percentage = json_parse(substring($hash_and_percentage, $separator_pos + 3)); |
| 238 | |
| 239 | $final_balance = var[$testament_name||"_final_heritage_balance"] otherwise var[$testament_name||"_balance"]; |
| 240 | |
| 241 | $heritage_value = round(var[$testament_name||"_balance"] * $percentage / 100) + $request_heritage_fee ; |
| 242 | }", |
| 243 | "messages": [ |
| 244 | { |
| 245 | "app": "data", |
| 246 | "payload": { |
| 247 | "list_name": "{ $testament_name||"_beneficiaries" }", |
| 248 | "remove": "{ var[trigger.address||"_beneficiary"] }", |
| 249 | "store": "{ $percentage||" % of the "||$testament_name||" heritage" }", |
| 250 | "hash_of_secret": "{ $hash }", |
| 251 | "message": "{ "Heritage available by providing your secret to AA: "||$Shafe }" |
| 252 | } |
| 253 | }, |
| 254 | { |
| 255 | "app": "payment", |
| 256 | "payload": { |
| 257 | "asset": "base", |
| 258 | "outputs": [ |
| 259 | { |
| 260 | "address": "{ $HOLLAA }", |
| 261 | "amount": 500 |
| 262 | }, |
| 263 | { |
| 264 | "address": "{ $Shafe }", |
| 265 | "amount": "{ $heritage_value }" |
| 266 | }, |
| 267 | { |
| 268 | "address": "{ trigger.data.withdraw_address }", |
| 269 | "amount": "{ 66 }" |
| 270 | } |
| 271 | ] |
| 272 | } |
| 273 | }, |
| 274 | { |
| 275 | "app": "state", |
| 276 | "state": "{ |
| 277 | if(!!$validated) |
| 278 | { |
| 279 | var[$testament_name||"_validated"] =true; |
| 280 | var[$testament_name||"_final_heritage_balance"] = var[$testament_name||"_balance"]; |
| 281 | } |
| 282 | |
| 283 | var[$testament_name||"_balance"] -= $heritage_value; |
| 284 | response['message'] = 'Heritage withdrawn'; |
| 285 | }" |
| 286 | } |
| 287 | ] |
| 288 | }, |
| 289 | { |
| 290 | "if": "{ !!trigger.data.cancel_request }", |
| 291 | "init": "{ |
| 292 | $testament_name = trigger.data.testament_name otherwise |
| 293 | bounce ("Add 'testament_name'"); |
| 294 | |
| 295 | |
| 296 | if (!var[$testament_name||"_writter"]) |
| 297 | bounce ("Account "||$testament_name||" do NOT exist!"); |
| 298 | |
| 299 | |
| 300 | if (trigger.address != var[$testament_name||"_writter"]) |
| 301 | bounce ("you must be the writter of the will to cancel a request"); |
| 302 | |
| 303 | |
| 304 | if (!!var[$testament_name||"_validated"]) |
| 305 | bounce ("Sorry, too late the heritage has been validated"); |
| 306 | |
| 307 | }", |
| 308 | "messages": [ |
| 309 | { |
| 310 | "app": "state", |
| 311 | "state": "{ |
| 312 | var[$testament_name||"_requester_address"] = false; |
| 313 | var[$requester_address||"_requested_time"] = false; |
| 314 | var[$requester_address||"_beneficiary"] = false; |
| 315 | var[$requester_address||"_testament_name"] = false; |
| 316 | response['message'] = 'Heritage request cancelled'; |
| 317 | }" |
| 318 | } |
| 319 | ] |
| 320 | }, |
| 321 | { |
| 322 | "messages": [ |
| 323 | { |
| 324 | "app": "state", |
| 325 | "state": "{ |
| 326 | bounce ($how_to); |
| 327 | }" |
| 328 | } |
| 329 | ] |
| 330 | } |
| 331 | ] |
| 332 | } |
| 333 | } |
| 334 | ] |