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