| 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 | |
| 14 | $HOLLAA = "C6M6BLAM2QTK727RTWA3YHZ4VW5ZIGBF"; |
| 15 | $SAAFE = "MSUZ5VXI5RBIE734CA4HBNS35ZKI4RYS"; |
| 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.public_key_part_1 and !!trigger.data.public_key_part_2)) |
| 45 | bounce ("need the 2 parts of the public key linked to this beneficiary"); |
| 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": "{ "puk1="||trigger.data.public_key_part_1||" puk2="||trigger.data.public_key_part_2||" %="||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 and !!trigger.data.withdraw_address}", |
| 121 | "init": "{ |
| 122 | $testament_name = trigger.data.testament_name otherwise bounce ($how_to); |
| 123 | |
| 124 | |
| 125 | if (!var[$testament_name||"_writter"]) bounce ("Account "||$testament_name||" do NOT exist!"); |
| 126 | |
| 127 | if (!(!!trigger.data.signature_key_part_1 and !!trigger.data.signature_key_part_2)) |
| 128 | bounce ("need the 2 parts of the 'withdraw address' signature"); |
| 129 | |
| 130 | if (!var[$HOLLAA][trigger.data.beneficiary]) bounce ("Beneficiary do not exist"); |
| 131 | |
| 132 | |
| 133 | if (!var[$HOLLAA][trigger.data.beneficiary]) bounce ("Beneficiary do not exist"); |
| 134 | $beneficiary_info = var[$HOLLAA][trigger.data.beneficiary]; |
| 135 | $puk2_key_word_index = index_of($beneficiary_info, " puk2="); |
| 136 | $percentage_key_word_index = index_of($beneficiary_info, " %="); |
| 137 | $public_key_part_1 = substring($beneficiary_info , 5, $puk2_key_word_index - 5); |
| 138 | $public_key_part_2 = substring($beneficiary_info , $puk2_key_word_index + 6, $percentage_key_word_index); |
| 139 | $public_key = $public_key_part_1||$public_key_part_2; |
| 140 | $percentage = substring($beneficiary_info , $percentage_key_word_index + 3); |
| 141 | $heritage_value = var[$testament_name||"_balance"] * $percentage / 100; |
| 142 | |
| 143 | if (!is_valid_sig(trigger.data.withdraw_address, $public_key, |
| 144 | trigger.data.signature_key_part_1||trigger.data.signature_key_part_2)) |
| 145 | bounce ("wrong signature"); |
| 146 | |
| 147 | |
| 148 | if (!var[trigger.data.beneficiary||"_requested_time"]) |
| 149 | $phase = 1; |
| 150 | else |
| 151 | { |
| 152 | if (var[trigger.data.beneficiary||"_requested_time"]+$DEFAULT_DELAY_TO_CANCEL<timestamp) |
| 153 | bounce ("request already in progress"); |
| 154 | else |
| 155 | $phase = 2; |
| 156 | } |
| 157 | |
| 158 | }", |
| 159 | "messages": [ |
| 160 | { |
| 161 | "if": "{ $phase == 1 }", |
| 162 | "app": "data", |
| 163 | "payload": { |
| 164 | "message": "{ trigger.data.beneficiary||" have requested his heritage" }" |
| 165 | } |
| 166 | }, |
| 167 | { |
| 168 | "if": "{ $phase == 1 }", |
| 169 | "app": "payment", |
| 170 | "payload": { |
| 171 | "asset": "base", |
| 172 | "outputs": [ |
| 173 | { |
| 174 | "address": "{ var[$testament_name||"_writter"] }", |
| 175 | "amount": 1000 |
| 176 | } |
| 177 | ] |
| 178 | } |
| 179 | }, |
| 180 | { |
| 181 | "if": "{ $phase == 2 }", |
| 182 | "app": "data", |
| 183 | "payload": { |
| 184 | "message": "{ "This is your heritage" }" |
| 185 | } |
| 186 | }, |
| 187 | { |
| 188 | "if": "{ $phase == 2 }", |
| 189 | "app": "payment", |
| 190 | "payload": { |
| 191 | "asset": "base", |
| 192 | "outputs": [ |
| 193 | { |
| 194 | "address": "{ trigger.data.withdraw_address }", |
| 195 | "amount": "{ $heritage_value }" |
| 196 | } |
| 197 | ] |
| 198 | } |
| 199 | }, |
| 200 | { |
| 201 | "app": "state", |
| 202 | "state": "{ |
| 203 | if ( $phase == 1 ) |
| 204 | { |
| 205 | var[$testament_name||"_balance"] -= 1000; |
| 206 | response['message'] = "requested validated"; |
| 207 | } |
| 208 | if ( $phase == 2 ) |
| 209 | { |
| 210 | var[$testament_name||"_balance"] -= $heritage_value; |
| 211 | response['message'] = 'Heritage withdrawn'; |
| 212 | } |
| 213 | }" |
| 214 | } |
| 215 | ] |
| 216 | }, |
| 217 | { |
| 218 | "messages": [ |
| 219 | { |
| 220 | "app": "state", |
| 221 | "state": "{ |
| 222 | bounce ($how_to); |
| 223 | }" |
| 224 | } |
| 225 | ] |
| 226 | } |
| 227 | ] |
| 228 | } |
| 229 | } |
| 230 | ] |