[
"autonomous agent",
{
"init": "{
$oracle_address = 'EJC4A7WQGHEZEKW6RLO7F26SAR4LAQBU';
$feed_name = 'ffff';
$comparison = '==';
$expiry_date = '2019-12-27T00:00:00.000Z';
$feed_value = 'vvv';
}",
"messages": {
"cases": [
{
"if": "{
$define_yes = trigger.data.define_yes AND !var['yes_asset'];
$define_no = trigger.data.define_no AND !var['no_asset'];
if ($define_yes AND $define_no)
bounce('Cant define both assets at the same time!');
$define_yes OR $define_no
}",
"messages": [
{
"app": "asset",
"payload": {
"is_private": false,
"is_transferrable": true,
"auto_destroy": false,
"fixed_denominations": false,
"issued_by_definer_only": true,
"cosigned_by_definer": false,
"spender_attested": false
}
},
{
"app": "state",
"state": "{
$asset = $define_yes ? 'yes_asset' : 'no_asset';
var[$asset] = response_unit;
response[$asset] = response_unit;
}"
}
]
},
{
"if": "{trigger.output[[asset=base]] >= 1e5 AND var['yes_asset'] AND var['no_asset']}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{var['yes_asset']}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{ trigger.output[[asset=base]] }"
}
]
}
},
{
"app": "payment",
"payload": {
"asset": "{var['no_asset']}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{ trigger.output[[asset=base]] }"
}
]
}
}
]
},
{
"if": "{exists(trigger.data.winner) AND (trigger.data.winner == 'yes' OR trigger.data.winner == 'no') AND !var['winner']}",
"messages": [
{
"app": "state",
"state": "{
$datafeed_value = data_feed[[oracles=$oracle_address, feed_name=$feed_name]];
if ($comparison == '>')
$datafeed_comparison = $datafeed_value > $feed_value;
else if ($comparison == '<')
$datafeed_comparison = $datafeed_value < $feed_value;
else if ($comparison == '!=')
$datafeed_comparison = $datafeed_value != $feed_value;
else if ($comparison == '==')
$datafeed_comparison = $datafeed_value == $feed_value;
else if ($comparison == '>=')
$datafeed_comparison = $datafeed_value >= $feed_value;
else if ($comparison == '<=')
$datafeed_comparison = $datafeed_value <= $feed_value;
else
bounce('Comparison operator not found');
if (trigger.data.winner == 'yes' AND $datafeed_comparison)
var['winner'] = 'yes';
else if (trigger.data.winner == 'no' AND timestamp > parse_date($expiry_date))
var['winner'] = 'no';
else
bounce('suggested outcome not confirmed');
response['winner'] = trigger.data.winner;
}"
}
]
},
{
"if": "{trigger.output[[asset!=base]] > 1000 AND var['winner'] AND trigger.output[[asset!=base]].asset == var[var['winner'] || '_asset']}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{ trigger.output[[asset!=base]] }"
}
]
}
}
]
}
]
}
}
]