Definition: [
"autonomous agent",
{
"init": "{
/*
==========================================
OBYTE STACK GAME from Whistling Frogs
==========================================
Written by Crypto Girl on 21 Sep 2019
==========================================
Test version: 0.1
==========================================
Can be used with OBYTE STACK GAME BOT v0.1
===========================================
The object of the game is to win the Stack.
Users make bids. Min bid is 100,000 bytes.
1st bid initiates the Stack.
Each subsequent bid restarts the 5 min timer.
If more than 5 min has passed since the last bid,
the stack is paid out to the previous bidder and
the new stack is initiated with the latest bid.
A commission of 10,000 bytes is charged on each bid.
*/
$now = timestamp ;
$min_bid_amnt = 100000; // 100,000 is about £0.02 to be increaded to £0.50
$bid_amnt = trigger.output[[asset=base]];
$bid_status = ($bid_amnt >= $min_bid_amnt) otherwise false;
if ($bid_status == false)
bounce('Your bid is too small.');
$stack_status = var['stack_status'] otherwise 'not started';
$duration = 300;
$fee = 10000; // 10,000 for now to be replaced with 1% of the pot
$seed_amnt = 10000;
$commission_address = 'B7KF2F5AP6BZLXOE2EGHH6BKZWVNIKWF'; //testnet
$commission_payout_threshold = 10000;
}",
"messages": [
{
"app": "payment",
"if": "{$bid_status == true AND $stack_status == 'running' AND $now > var['period_end']}",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ var['leader'] }",
"amount": "{ var['stack_amnt'] }"
}
]
}
},
{
"app": "payment",
"if": "{ var['commission'] >= $commission_payout_threshold }",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ $commission_address }",
"amount": "{ var['commission'] }"
}
]
}
},
{
"app": "state",
"state": "{
// game not started: valid bid & game not started - initilise game with 1st bid
if ($bid_status AND $stack_status == 'not started') {
var['stack_amnt'] = $bid_amnt - $fee;
var['stack_status'] = '1st bid made';
var['leader'] = trigger.initial_address;
}
// case: 2nd valid bid is made - start timer
if ($bid_status == true AND $stack_status == '1st bid made') {
var['stack_amnt'] += ($bid_amnt - $fee);
var['stack_status'] = 'running';
var['leader'] = trigger.initial_address;
var['period_end'] = timestamp + $duration;
}
// case: game is running
if ($bid_status == true AND $stack_status == 'running' AND $now <= var['period_end']) {
var['stack_amnt'] += ($bid_amnt - $fee);
var['period_end'] = timestamp + $duration;
var['leader'] = trigger.initial_address;
}
// case: game finished // initilise new game with latest bid
if ($bid_status == true AND $stack_status == 'running' AND $now > var['period_end']) {
var['commission'] = balance[base] - $seed_amnt;
var['stack_amnt'] = $bid_amnt - $fee;
var['stack_status'] = '1st bid made';
var['leader'] = trigger.initial_address;
}
}"
}
]
}
]