| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "doc_url": "https://devid.org/github.json", |
| 5 | "getters": "{ |
| 6 | $username2address = ($github_username) => var['u2a_'||$github_username]; |
| 7 | $address2username = ($address) => var['a2u_'||$address]; |
| 8 | }", |
| 9 | "init": "{ |
| 10 | $overwrite_delay = 3; |
| 11 | |
| 12 | $attestor = 'OYW2XTDKSNKGSEZ27LMGNOPJSYIXHBHC'; |
| 13 | |
| 14 | |
| 15 | |
| 16 | require(trigger.address == $attestor, "only the attestor can call this AA"); |
| 17 | }", |
| 18 | "messages": { |
| 19 | "cases": [ |
| 20 | { |
| 21 | "if": "{trigger.data.address AND trigger.data.github_username}", |
| 22 | "messages": [ |
| 23 | { |
| 24 | "app": "state", |
| 25 | "state": "{ |
| 26 | $address = trigger.data.address; |
| 27 | $github_username = trigger.data.github_username; |
| 28 | require(is_valid_address($address), "address not valid"); |
| 29 | require(has_only($github_username, '\w-'), "github username not valid"); |
| 30 | |
| 31 | $existing_owner = var['u2a_'||$github_username]; |
| 32 | if ($existing_owner){ |
| 33 | require($existing_owner != $address, "the same owner"); |
| 34 | $pending_varname = 'pending_'||$address||'_'||$github_username; |
| 35 | $pending_ts = var[$pending_varname]; |
| 36 | if (!$pending_ts){ |
| 37 | var[$pending_varname] = timestamp; |
| 38 | response['message'] = "This attestation would overwrite an existing record and can't be activated immediately for security reasons. Please repeat your attestation in "||$overwrite_delay||" days to activate the new owner of this github username."; |
| 39 | return; |
| 40 | } |
| 41 | require(timestamp > $pending_ts + $overwrite_delay * 24 * 3600, "the delay period is still ongoing"); |
| 42 | var[$pending_varname] = false; |
| 43 | |
| 44 | } |
| 45 | var['u2a_'||$github_username] = $address; |
| 46 | var['a2u_'||$address] = $github_username; |
| 47 | response['message'] = $github_username||' => '||$address; |
| 48 | }" |
| 49 | } |
| 50 | ] |
| 51 | }, |
| 52 | { |
| 53 | "if": "{trigger.data.withdraw AND trigger.data.amount}", |
| 54 | "messages": [ |
| 55 | { |
| 56 | "app": "payment", |
| 57 | "payload": { |
| 58 | "asset": "base", |
| 59 | "outputs": [ |
| 60 | { |
| 61 | "address": "{$attestor}", |
| 62 | "amount": "{trigger.data.amount}" |
| 63 | } |
| 64 | ] |
| 65 | } |
| 66 | } |
| 67 | ] |
| 68 | } |
| 69 | ] |
| 70 | } |
| 71 | } |
| 72 | ] |