Definition: [
"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) : {};
};
$isRevoked = $nft=>{
$feed = data_feed[[oracles=this_address, feed_name=$nft, ifnone="OK", ifseveral="last", type="string"]];
return $feed == "REVOKED";
};
$artistInfoOf = $artist=>var["artist_" || $artist];
}",
"messages": {
"cases": [
{
"if": "{NOT $owner}",
"messages": [
{
"app": "state",
"state": "{
var["owner"] = "HMFR76BEZXV5T7X4QVWXFKADT73DKS2G";
var["helper"] = "HMFR76BEZXV5T7X4QVWXFKADT73DKS2G";
var["maxRoyalty"] = 40;
}"
}
]
},
{
"if": "{
trigger.address == $owner
AND ($method == "payout"
OR $method == "transferOwnership"
OR $method == "setHelper"
OR $method == "setReseller"
OR $method == "delReseller"
OR $method == "setMaxRoyalty"
OR $method == "unverify")
}",
"messages": {
"cases": [
{
"if": "{$method == "payout"}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}"
}
]
}
}
]
},
{
"if": "{$method == "setMaxRoyalty"}",
"init": "{
if (NOT exists(trigger.data["royalty"]))
bounce("royalty field is mandatory");
if (NOT is_integer(trigger.data["royalty"]))
bounce("royalty must be an integer");
if (trigger.data["royalty"] < 0)
bounce("royalty must be positive");
if (trigger.data["royalty"] > 100)
bounce("royalty cannot be higher than 100%");
}",
"messages": [
{
"app": "state",
"state": "{
var["maxRoyalty"] = trigger.data["royalty"];
}"
}
]
},
{
"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.address == $owner
OR trigger.address == var["helper"])
AND ($method == "verifyProfile"
OR $method == "revoke")
}",
"messages": {
"cases": [
{
"if": "{$method == "revoke"}",
"init": "{
if (NOT trigger.data["NFT"])
bounce("NFT field is mandatory");
$previousValue = data_feed[[oracles=[this_address], feed_name=trigger.data["NFT"], ifnone="OK", ifseveral="last", what="value", type="string"]];
$newValue = $previousValue == "OK" ? "REVOKED" : "OK";
}",
"messages": [
{
"app": "data_feed",
"payload": {
"{trigger.data["NFT"]}": "{$newValue}"
}
}
]
},
{
"if": "{$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
}"
}
]
}
]
}
}
]