[
"autonomous agent",
{
"doc_url": "https://raw.githubusercontent.com/jldevelops/daily-draw-aa/master/description.json",
"getters": "{
$ENTRY = => 10000;
$ORACLE = => 'FOPUBEUPBC6YLIQDLKL6EW775BMV7YOH';
$FEED_NAME = => 'bitcoin_hash';
$winnerPot = => 10000000;
$triggerPot = => var['tickets_sold'] * $ENTRY();
$actualWinner = => var['tickets_sold'] > 1 ? number_from_seed(data_feed[[oracles=$ORACLE(), feed_name=$FEED_NAME()]],var['tickets_sold']-1) : 0;
$isWinnerTicket = $ti => var['amount_'||$ti[0]] ? (($ti[1]+0) <= var['winner_'||$ti[0]] AND ($ti[2]+0) > var['winner_'||$ti[0]]) : false;
$now = => timestamp_to_string(timestamp, 'date');
$day = => var['today'] ? var['today'] : $now();
$isTriggerAvailable = => $now() != $day() AND var['tickets_sold'] > 0;
}",
"init": "{
$getUserId = => {
$user_id = attestation[[attestors='I2ADHGP4HL6J37NQAD73J7E5SKFIXJOT', address=trigger.address, ifnone=false]].user_id;
if(!$user_id)
bounce('you must do real name attestation first');
return $user_id;
};
if(trigger.output[[asset!=base]].asset != 'none')
bounce('no asset');
}",
"messages": {
"cases": [
{
"if": "{trigger.data.buy and trigger.output[[asset=base]] == 10000}",
"init": "{
if($isTriggerAvailable())
bounce('trigger available, send trigger = 1 to earn '||$triggerPot()||' bytes');
$user_id = $getUserId();
$ticket = var[$user_id];
if($ticket AND $ticket == $day())
bounce('You are already registered');
}",
"messages": [
{
"app": "state",
"state": "{
if(!var['today'] OR (var['tickets_sold'] == 0 AND $now() != $day()))
var['today'] = $now();
var[$user_id] = $day();
if(!var['tickets_sold']) var['tickets_sold'] = 0;
var[$day()||'_'||var['tickets_sold']] = trigger.address;
var['tickets_sold'] += 1;
response['message'] = 'Address registered for today\'s draw';
}"
}
]
},
{
"if": "{trigger.data.trigger and trigger.output[[asset=base]] == 10000}",
"init": "{
$user_id = $getUserId();
$winner_addr = var[$day()||'_'||$actualWinner()];
if(!$isTriggerAvailable())
bounce('no trigger available');
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$triggerPot() + trigger.output[[asset=base]]}"
}
]
}
},
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$winner_addr}",
"amount": "{$winnerPot()}"
}
]
}
},
{
"app": "state",
"state": "{
$d = $day();
var['today'] = $now();
var['tickets_sold'] = 0;
response['message'] = 'Winner address '||$d||': '||$winner_addr;
}"
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
response['message'] = 'Daily AA draw, send buy = 1 to buy a ticket or trigger = 1 to trigger draw when utc day changes';
}"
}
]
}
]
}
}
]