[
"autonomous agent",
{
"getters": "{
$_validateMetadata = $meta=>{
if (NOT $meta.title)
bounce("The NFT metadata lacks a required title field");
if (NOT $meta.ipfs)
bounce("The NFT metadata lacks a required ipfs field");
if (NOT $meta.type)
bounce("The NFT metadata lacks a required type field");
};
$_validateAssetMetadata = $meta=>{
if ($meta.is_private)
bounce("An NFT asset cannot be private");
if ($meta.cosigned_by_definer)
bounce("We cannot accept NFTs with the cosigned_by_definer field since the definer cannot cosign an automated transaction");
if ($meta.fixed_denominations)
bounce("Autonomous agents cannot deal with asset issued with fixed denominations");
if ($meta.spender_attested)
bounce("We do not accept assets defined with the spender_attested option");
if ($meta.transfer_condition)
bounce("We do not accept assets defined with the transfer_condition option");
};
$fetchNFT = $asset => {
$unitInfo = unit[$asset];
if (NOT $unitInfo.messages)
bounce("Bad unit");
$definedBy = $unitInfo.authors[0].authentifiers
? $unitInfo.authors[0].address //Is a person
: unit[$unitInfo.trigger_unit].authors[0].address; //Can be either AA (they can also define NFTs) or a person
$metadata = $unitInfo.messages[[.app='data']].payload;
$_validateMetadata($metadata);
$assetMetadata = $unitInfo.messages[[.app='asset']].payload;
$_validateAssetMetadata($assetMetadata);
return {asset: $assetMetadata, meta: $metadata};
};
}",
"messages": [
{
"if": "{NOT var["a"]}",
"app": "data",
"payload": {
"title": "Untitled",
"author": "{trigger.address}",
"ipfs": "Qmmmsdmjsdjf",
"type": "IMG",
"decimals": 0
}
},
{
"app": "payment",
"payload": {
"outputs": [
{
"address": "{this_address}",
"amount": 1000
}
]
}
},
{
"app": "asset",
"payload": {
"cap": 1,
"is_private": false,
"is_transferrable": true,
"auto_destroy": false,
"fixed_denominations": false,
"issued_by_definer_only": true,
"cosigned_by_definer": false,
"spender_attested": false
}
},
{
"if": "{var["a"]}",
"app": "data",
"payload": {
"nft": "{$fetchNFT(var["a"])}"
}
},
{
"app": "state",
"state": "{
var["a"] = response_unit;
}"
}
]
}
]