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