| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | |
| 6 | $return_fee = 1000; |
| 7 | $attestor = 'BK54UAWZ6KTI3K7PWH7PRPHVYWTIZZXH'; |
| 8 | $attested_user_id = attestation[[attestors=$attestor, address=trigger.address]].user_id; |
| 9 | if (!$attested_user_id) bounce('Your address is not attested by attestor ' || $attestor || ' yet.'); |
| 10 | $balance_key = 'user_id_'||$attested_user_id||'_balance'; |
| 11 | }", |
| 12 | "messages": { |
| 13 | "cases": [ |
| 14 | { |
| 15 | "if": "{!trigger.data.withdraw}", |
| 16 | "init": "{ |
| 17 | |
| 18 | bounce ("Profile_hash is equal to " || attestation[[attestors=$attestor, address=trigger.address]].profile_hash); |
| 19 | /* if (typeof(parse_date(trigger.data.lock_till)) != "number") bounce("The format of the 'lock_till' field is YYYY-MM-DD."); |
| 20 | if (var[$balance_key] AND parse_date(trigger.data.lock_till) != var[$timestamp_key]) bounce("This address have been already deposited before with 'lock_till' date set to " || timestamp_to_string(var[$timestamp_key], 'date') || ". You can't change the date. To increase the balance of this address make 'lock_till' date the same as before.");*/ |
| 21 | }", |
| 22 | "messages": [ |
| 23 | { |
| 24 | "app": "state", |
| 25 | "state": "{ |
| 26 | /*if (!var[$balance_key]) |
| 27 | var[$timestamp_key] = parse_date(trigger.data.lock_till); |
| 28 | var[$balance_key] = var[$balance_key] + trigger.output[[asset=base]]; |
| 29 | if (var[$timestamp_key] < timestamp) |
| 30 | response['info'] = "You set 'lock_till' date from the past. You can withdraw at any time."; |
| 31 | if (var[$timestamp_key] > timestamp + 1576800000) |
| 32 | response['info'] = "Your 'lock_till' date is set for more than 50 years!"; |
| 33 | response['message'] = "Total balance will be " || var[$balance_key] || " bytes. The bytes will be locked till "|| timestamp_to_string(var[$timestamp_key], 'date') || " 0:00 UTC. You can withdraw your bytes only from the address you made this deposit: " || trigger.address || ". Please make a wallet backup and store it in a safe place.";*/ |
| 34 | }" |
| 35 | } |
| 36 | ] |
| 37 | }, |
| 38 | { |
| 39 | "messages": [ |
| 40 | { |
| 41 | "app": "payment", |
| 42 | "payload": { |
| 43 | "asset": "base", |
| 44 | "outputs": [ |
| 45 | { |
| 46 | "address": "{trigger.address}", |
| 47 | "amount": "{ var[$balance_key] - $return_fee + trigger.output[[asset=base]]}" |
| 48 | } |
| 49 | ] |
| 50 | } |
| 51 | }, |
| 52 | { |
| 53 | "app": "state", |
| 54 | "state": "{ |
| 55 | response['message'] = 'You will receive ' || (var[$balance_key] - $return_fee + trigger.output[[asset=base]]) || ' bytes to your account (' || var[$balance_key] || ' bytes will be released - '|| $return_fee || ' bytes transaction fee + ' || trigger.output[[asset=base]] || ' bytes bounced back)'; |
| 56 | var[$balance_key] = false; |
| 57 | var[$timestamp_key] = false; |
| 58 | }" |
| 59 | } |
| 60 | ] |
| 61 | } |
| 62 | ] |
| 63 | } |
| 64 | } |
| 65 | ] |