DI4PILJ3KMONCARDWKLVWMATUK2LXVW5
[
"autonomous agent",
{
"init": "{
$id = trigger.data.CH.id.ch;
}",
"messages": {
"cases": [
{
"if": "{trigger.data.register AND $id}",
"init": "{
if (var['owner_' || $id])
bounce('La valeur ' || $id || ' est déjà enregistrée');
if (trigger.data.sell){
$price = trigger.data.price;
if (!$price || !($price > 0) || round($price) != $price)
bounce('Veuillez définir un prix entier positif');
}
}",
"messages": [
{
"app": "state",
"state": "{
var['owner_' || $id] = trigger.address;
if (trigger.data.sell AND trigger.data.price)
var['price_' || $id] = trigger.data.price;
response['message'] = 'Enregistrée' || (trigger.data.sell AND trigger.data.price ? ' et mise en vente à ' || trigger.data.price : '');
}"
}
]
},
{
"if": "{$id AND trigger.data.sell AND trigger.data.price}",
"init": "{
$owner = var['owner_' || $id];
if (!$owner OR $owner != trigger.address)
bounce('La chose ' || $id || ' ne vous appartient pas');
if (!(trigger.data.price > 0) OR round(trigger.data.price) != trigger.data.price)
bounce('Veuillez définir un prix entier positif');
}",
"messages": [
{
"app": "state",
"state": "{
var['price_' || $id] = trigger.data.price;
response['message'] = 'Mise en vente à ' || trigger.data.price;
}"
}
]
},
{
"if": "{$id AND trigger.data.withdraw_from_sale}",
"init": "{
$owner = var['owner_' || $id];
if (!$owner OR $owner != trigger.address)
bounce('La chose ' || $id || ' ne vous appartient pas');
}",
"messages": [
{
"app": "state",
"state": "{
var['price_' || $id] = false; // Pas de prix signifie pas en vente
response['message'] = 'Retirée de la vente';
}"
}
]
},
{
"if": "{$id AND trigger.data.buy}",
"init": "{
$owner = var['owner_' || $id];
if (!$owner)
bounce('La chose ' || $id || ' n\'existe pas');
if ($owner == trigger.address)
bounce('La chose ' || $id || ' est déjà la vôtre');
$price = var['price_' || $id];
if (!$price)
bounce('La chose ' || $id || ' n\'est pas en vente');
$amount = trigger.output[[asset=base]];
if ($amount < $price)
bounce("Le prix de la chose est de " || $price || ", vous avez envoyé seulement " || $amount);
$change = $amount - $price;
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$owner}",
"amount": "{$price}"
},
{
"if": "{$change > 0}",
"address": "{trigger.address}",
"amount": "{$change}"
}
]
}
},
{
"app": "state",
"state": "{
var['owner_' || $id] = trigger.address; // Nouveau propriétaire
var['price_' || $id] = false; // Plus en vente
response['message'] = 'Vendue à ' || trigger.address;
}"
}
]
}
]
}
}
]
Show transactions in assets:
No transactions found, it may be worth changing the filter
Unit ID
Date
From
Direction
To
Amount