Definition: [
"autonomous agent",
{
"init": "{
$asset = var['asset'];
$destination_aa = 'WF3ZRL72GCTRSDU64GP42S3FB7GBT7XJ';
$team = 'U+EP3OCBJuPdRBVMGM0gBsMAPce+e9LNEvD4iOaLlUM=';
}",
"messages": {
"cases": [
{
"if": "{trigger.data.start AND !$asset}",
"messages": [
{
"app": "asset",
"payload": {
"is_private": false,
"is_transferrable": true,
"auto_destroy": false,
"fixed_denominations": false,
"issued_by_definer_only": false,
"cosigned_by_definer": false,
"spender_attested": false
}
},
{
"app": "state",
"state": "{
var[response_unit || '_status'] = 'open';
var['asset'] = response_unit;
response['asset'] = response_unit;
}"
}
]
},
{
"if": "{trigger.output[[asset=base]] >= 1e100 AND $asset}",
"init": "{
if (var[$destination_aa]['finished'])
bounce('game over');
$amount = trigger.output[[asset=base]] - 1000; // to account for fees we need to respond now and to refund bytes or pay shares later
$total_raised = var['total_raised'] + $amount;
$missing_amount = ceil((balance[$destination_aa][base] + $total_raised)*0.49) - var[$destination_aa]['team_' || $team || '_amount'];
$bDone = ($total_raised > $missing_amount);
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{$asset}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$amount}"
}
]
}
},
{
"if": "{$bDone}",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$destination_aa}",
"amount": "{$total_raised}"
}
]
}
},
{
"if": "{$bDone}",
"app": "data",
"payload": {
"team": "{$team}"
}
},
{
"app": "state",
"state": "{
if ($bDone)
var[$asset || '_status'] = 'raised';
else
var['total_raised'] = $total_raised;
}"
}
]
},
{
"if": "{trigger.output[[asset=var[$destination_aa]['team_' || $team || '_asset']]] AND $asset}",
"messages": [
{
"app": "state",
"state": "{
var[$asset || '_status'] = 'done';
var['asset'] = false;
var['total_raised'] = false;
}"
}
]
},
{
"if": "{$asset AND trigger.output[[asset=$asset]] > 0}",
"init": "{
$amount = trigger.output[[asset=$asset]];
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$amount}"
}
]
}
},
{
"app": "state",
"state": "{
var['total_raised'] -= $amount;
}"
}
]
},
{
"if": "{
$in_asset = trigger.output[[asset!=base]].asset;
var[$in_asset || '_status'] == 'done'
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{var[$destination_aa]['team_' || $team || '_asset']}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{trigger.output[[asset=$in_asset]]}"
}
]
}
}
]
}
]
}
}
]