OGXLA66UZRHHKRSUV576CC5WCADMT6UH
[
"autonomous agent",
{
"init": "{
$id = trigger.data.id;
}",
"messages": {
"cases": [
{
"if": "{trigger.data.register AND $id}",
"init": "{
if (var['owner' || $id])
bounce('thing ' || $id || ' already registered');
if (trigger.data.sell){
$price = trigger.data.price;
if (!$price || !($price > 0) || round($price) != $price)
bounce('please set a positive integer price');
}
}",
"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'] = 'registered' || (trigger.data.sell AND trigger.data.price ? ' and put on sale for ' || 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('thing ' || $id || ' is not yours');
if (!(trigger.data.price > 0) OR round(trigger.data.price) != trigger.data.price)
bounce('please set an integer positive price');
}",
"messages": [
{
"app": "state",
"state": "{
var['price' || $id] = trigger.data.price;
response['message'] = 'on sale for ' || trigger.data.price;
}"
}
]
},
{
"if": "{$id AND trigger.data.withdraw_from_sale}",
"init": "{
$owner = var['owner' || $id];
if (!$owner OR $owner != trigger.address)
bounce('thing ' || $id || ' is not yours');
}",
"messages": [
{
"app": "state",
"state": "{
var['price_' || $id] = false; // no-price means not on sale
response['message'] = 'withdrawn from sale';
}"
}
]
},
{
"if": "{$id AND trigger.data.buy}",
"init": "{
$owner = var['owner' || $id];
if (!$owner)
bounce('no such thing: ' || $id);
if ($owner == trigger.address)
bounce('thing ' || $id || ' is already yours');
$price = var['price' || $id];
if (!$price)
bounce('thing ' || $id || ' is not on sale');
$amount = trigger.output[[asset=base]];
if ($amount < $price)
bounce("the thing's price is " || $price || ", you sent only " || $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; // new owner
var['price' || $id] = false; // not on sale any more
response['message'] = 'sold to ' || trigger.address;
}"
}
]
}
]
}
}
]
Show transactions in assets:
No transactions found, it may be worth changing the filter
Unit ID
Date
From
Direction
To
Amount