[
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{
if (NOT trigger.data["method"])
bounce("method field is mandatory");
$method = trigger.data["method"];
$owner = var["owner"];
}",
"getters": "{
/*
** Attested profile (or just the address if not found)
*/
$profileOf = $address=>{
$ret = attestation[[attestors=this_address, address=$address, ifseveral='last', type="string"]].data;
return $ret ? json_parse($ret) : {};
};
$licenseExpirationOf = ($user, $license)=>var[$user || "_" || $license];
$artistInfoOf = $artist=>var["artist_" || $artist];
}",
"messages": {
"cases": [
{
"if": "{NOT $owner}",
"messages": [
{
"app": "state",
"state": "{
var["owner"] = "
IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; //Set the Owner to my address
var["helper"] = "
IUU43O7TS2TBYKAPGKUARDZHOTAE275A";
var["locked"] = 0; //Bytes locked in investments are not withdrawable by the Owner
}"
}
]
},
{
"if": "{
trigger.address == $owner
AND ($method == "payout"
OR $method == "transferOwnership"
OR $method == "setHelper"
OR $method == "setAA"
OR $method == "delAA"
OR $method == "setReseller"
OR $method == "delReseller"
OR $method == "unverify")
}",
"messages": {
"cases": [
{
"if": "{$method == "payout"}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}"
}
]
}
}
]
},
{
"if": "{$method == "unverify"}",
"init": "{
if (NOT trigger.data["address"])
bounce("address field is mandatory");
$_ = $profileOf(trigger.data["address"]);
$oldUsername = $_["username"];
$prof = $_ || {verified: false, username: false, isReseller: false};
}",
"messages": [
{
"app": "attestation",
"init": "{
$profileString = json_stringify($prof);
if (length($profileString) > 4096)
bounce("The profile is too long, the user has to remove some fields and retry verification");
}",
"payload": "{
{
address: trigger.data["address"],
profile: {
data: $profileString
}
}
}"
},
{
"app": "state",
"state": "{
var["user_" || $oldUsername] = false; //Free username
}"
}
]
},
{
"if": "{$method == "transferOwnership"}",
"init": "{
if (NOT trigger.data["newOwner"])
bounce("newOwner field is mandatory");
if (NOT is_valid_address(trigger.data["newOwner"]))
bounce("newOwner field is not a valid address");
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}"
}
]
}
},
{
"app": "state",
"state": "{
var["owner"] = trigger.data["newOwner"];//Ownership is transferred
}"
}
]
},
{
"if": "{$method == "setHelper"}",
"init": "{
if (NOT trigger.data["helper"])
bounce("helper field is mandatory");
}",
"messages": [
{
"app": "state",
"state": "{
var["helper"] = trigger.data["helper"];
}"
}
]
},
{
"if": "{trigger.data["method"] == "setAA"}",
"init": "{
if (NOT is_valid_address(trigger.data["AA"]))
bounce("AA is not a valid address");
}",
"messages": [
{
"app": "state",
"state": "{
var["AA_" || trigger.data["AA"]] = true;
}"
}
]
},
{
"if": "{trigger.data["method"] == "delAA"}",
"init": "{
if (NOT var["AA_" || trigger.data["AA"]])
bounce("AA is not a valid address");
}",
"messages": [
{
"app": "state",
"state": "{
var["AA_" || trigger.data["AA"]] = false;
}"
}
]
},
{
"if": "{$method == "setReseller"}",
"init": "{
if (NOT is_valid_address(trigger.data["address"]))
bounce("address is not valid");
$prof = $profileOf(trigger.data["address"]) || {isReseller: true};
$profileString = json_stringify($prof);
if (length($profileString) > 4096)
bounce("The profile is too long, the user has to remove some fields and retry verification");
}",
"messages": [
{
"app": "attestation",
"payload": "{
{
address: trigger.data["address"],
profile: { //Wrapper to be able to query the whole object at once since you can only query attestations by fields
data: $profileString
}
}
}"
}
]
},
{
"if": "{$method == "delReseller"}",
"init": "{
$prof = $profileOf(trigger.data["address"]) || {isReseller: false};
$profileString = json_stringify($prof);
if (length($profileString) > 4096)
bounce("The profile is too long, the user has to remove some fields and retry verification");
}",
"messages": [
{
"app": "attestation",
"payload": "{
{
address: trigger.data["address"],
profile: { //Wrapper to be able to query the whole object at once since you can only query attestations by fields
data: $profileString
}
}
}"
}
]
}
]
}
},
{
"if": "{
(trigger.address == $owner
OR trigger.address == var["helper"])
AND $method == "verifyProfile"
}",
"init": "{
if (NOT trigger.data["address"])
bounce("address field is mandatory");
if (NOT is_valid_address(trigger.data["address"]))
bounce("That address is not valid");
$profileObj = $profileOf(trigger.data["address"]) || {verified: true};
if (NOT $profileObj.username)
bounce("That user has not chosen an username");
}",
"messages": [
{
"app": "attestation",
"payload": "{
{
address: trigger.data["address"],
profile: { //Wrapper to be able to query the whole object at once since you can only query attestations by fields
data: json_stringify($profileObj)
}
}
}"
},
{
"app": "state",
"state": "{
var["user_" || $profileObj.username] = trigger.data["address"]; //Username is now taken
}"
}
]
},
{
"if": "{$method == "PROFILE"}",
"init": "{
$prof = $profileOf(trigger.address);
$oldUsername = $prof.username;
$newUsername = trigger.data["username"] OTHERWISE $oldUsername;
if (NOT $oldUsername){
if (NOT trigger.data["username"])
bounce("username field is mandatory");
}
if (var["user_" || $newUsername]){
if ($oldUsername){
if ($oldUsername != $newUsername){
bounce("username already taken by a verified user");
}
}
}
if (exists(trigger.data["username"]) OR exists(trigger.data["name"]) OR exists(trigger.data["company"]) OR exists(trigger.data["isReseller"]) OR exists(trigger.data["verified"]))
$unverify = true;
else
$unverify = false;
if ($prof)
$profileObj = $prof || trigger.data || {username: $newUsername, verified: NOT $unverify};
else
$profileObj = trigger.data || {username: $newUsername, verified: NOT $unverify};
delete($profileObj, "method");
}",
"messages": [
{
"app": "attestation",
"init": "{
$profileString = json_stringify($profileObj);
if (length($profileString) > 4000)
bounce("Your profile is too big, try removing some fields");
}",
"payload": "{
{ //The user is unverified in this attestation if they call this endpoint after being verified
address: trigger.address,
profile: {
data: $profileString
}
}
}"
},
{
"app": "state",
"state": "{
if ($oldUsername){
if ($oldUsername != $newUsername)
var["user_" || $oldUsername] = false; //Free old username
}
//Do not lock new username here. It will be locked upon verification to prevent username squatting
}"
}
]
},
{
"if": "{$method == "addTime"}",
"init": "{
if (NOT trigger.data["NFT"])
bounce("[AA] NFT field is mandatory");
if (NOT trigger.data["time"])
bounce(["[AA] time field is mandatory"]);
if (NOT var["AA_" || trigger.address])
bounce("You have no power here!");
}",
"messages": [
{
"app": "state",
"state": "{
$key = trigger.initial_address || "_" || trigger.data["NFT"];
$previousExpiry = var[$key];
if (($previousExpiry AND timestamp < $previousExpiry) OR !$previousExpiry) //License is expired or was never purchased, need to reset the ts
var[$key] = timestamp + trigger.data["time"];
else //License is active just push the deadline further
var[$key] += trigger.data["time"];
}"
}
]
}
]
}
}
]