goback();
$PoS = ($coin->algo == 'PoS'); // or if 'stake' key is present in 'getinfo' method
$remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
$reserved1 = dboscalar("SELECT SUM(balance) FROM accounts WHERE coinid={$coin->id}");
$reserved1 = altcoinvaluetoa($reserved1);
$balance = altcoinvaluetoa($coin->balance);
$owed = dboscalar("SELECT SUM(E.amount) AS owed FROM earnings E ".
"LEFT JOIN blocks B ON E.blockid = B.id ".
"WHERE E.status!=2 AND E.coinid={$coin->id} "//."AND B.category NOT IN ('stake','generated')"
);
$owed_btc = bitcoinvaluetoa($owed*$coin->price);
$owed = altcoinvaluetoa($owed);
$symbol = $coin->symbol;
if (!empty($coin->symbol2)) $symbol = $coin->symbol2;
echo "
";
if (YAAMP_ALLOW_EXCHANGE) {
$reserved2 = bitcoinvaluetoa(dboscalar("SELECT SUM(amount*price) FROM earnings
WHERE status!=2 AND userid IN (SELECT id FROM accounts WHERE coinid={$coin->id})"));
echo "Earnings $reserved2 BTC, ";
}
echo "Balance (db) $balance $symbol";
echo ", Owed ".CHtml::link($owed, "/site/earning?id=".$coin->id)." $symbol ($owed_btc BTC)";
echo ", ".CHtml::link($reserved1, "/site/payments?id=".$coin->id)." $symbol cleared
";
//////////////////////////////////////////////////////////////////////////////////////
$list = getdbolist('db_markets', "coinid=$coin->id order by price desc");
echo "
";
echo "";
echo "";
echo "Name | ";
echo "Price | ";
echo "Price2 | ";
echo "Sent | ";
echo "Traded | ";
echo "Late | ";
echo "Deposit | ";
echo "Message | ";
echo "
";
echo "";
$bestmarket = getBestMarket($coin);
foreach($list as $market)
{
$marketurl = '#';
$price = bitcoinvaluetoa($market->price);
$price2 = bitcoinvaluetoa($market->price2);
$marketurl = getMarketUrl($coin, $market->name);
if($bestmarket && $market->id == $bestmarket->id)
echo "";
else
echo "
";
echo "$market->name | ";
echo "$price | ";
echo "$price2 | ";
$sent = datetoa2($market->lastsent);
$traded = datetoa2($market->lasttraded);
$late = $market->lastsent > $market->lasttraded ? 'late': '';
echo ''.(empty($sent) ? "" : "$sent ago").' | ';
echo ''.(empty($traded) ? "" : "$traded ago").' | ';
echo ''.$late.' | ';
echo '';
if (!empty($market->deposit_address)) {
$name = CJavaScript::encode($market->name);
$addr = CJavaScript::encode($market->deposit_address);
echo CHtml::link(
YAAMP_ALLOW_EXCHANGE ? "sell" : "send",
"javascript:;", array(
'onclick'=>"return showSellAmountDialog({$market->id}, $name, $addr);"
)
);
echo ' '.$market->deposit_address;
}
echo ' edit';
echo ' x';
echo ' | ';
echo "$market->message | ";
echo "
";
}
echo "
";
//////////////////////////////////////////////////////////////////////////////////////
$info = $remote->getinfo();
if (!empty($info)) {
$stake = isset($info['stake'])? $info['stake']: '';
if ($stake !== '') $PoS = true;
}
echo "";
//showTableSorter('maintable');
echo "";
echo "";
echo " | ";
echo " | ";
echo "Name | ";
echo "Symbol | ";
echo "Algo | ";
echo "Difficulty | ";
echo "Blocks | ";
echo "Balance | ";
echo "BTC | ";
if ($PoS) echo "Stake | ";
echo "Conns | ";
echo "Price | ";
echo "Reward | ";
echo "Index * | ";
echo "
";
echo "";
echo "";
echo " | ";
if($coin->enable)
echo "[ + ] | ";
else
echo "[ ] | ";
echo ''.$coin->name.' | ';
echo ''.$coin->symbol.' | ';
echo ''.$coin->algo.' | ';
if(!$info)
{
echo "ERROR $remote->error | ";
echo "
";
return;
}
$errors = isset($info['errors'])? $info['errors']: '';
$balance = isset($info['balance'])? $info['balance']: '';
$txfee = isset($info['paytxfee'])? $info['paytxfee']: '';
$connections = isset($info['connections'])? CHtml::link($info['connections'],'/site/peers?id='.$coin->id): '';
$blocks = isset($info['blocks'])? $info['blocks']: '';
echo ''.round_difficulty($coin->difficulty).' | ';
if(!empty($errors))
echo "$blocks | ";
else
echo "$blocks | ";
echo ''.altcoinvaluetoa($balance).' | ';
$btc = bitcoinvaluetoa($balance*$coin->price);
echo "$btc | ";
if ($PoS) echo ''.$stake.' | ';
echo "$connections | ";
echo ''.bitcoinvaluetoa($coin->price).' | ';
echo ''.$coin->reward.' | ';
$index = '';
if($coin->difficulty)
$index = round($coin->reward * $coin->price / $coin->difficulty * 10000, 3);
echo ''.$index.' | ';
echo '';
echo '';
echo '
';
//////////////////////////////////////////////////////////////////////////////////////
// last week
$list_since = arraySafeVal($_GET,'since',time()-(7*24*3600));
$maxrows = arraySafeVal($_GET,'rows', 15);
$maxrows = min($maxrows, 2500);
echo <<
tr.ssrow.orphan { color: darkred; }
Time |
Category |
Amount |
Height |
Difficulty |
Confirm |
Address |
Tx(s) |
end;
$account = '';
if ($coin->symbol == 'DCR') $account = '*';
$txs = $remote->listtransactions($account, 2500);
if (empty($txs)) {
if (!empty($remote->error)) {
echo "RPC Error: {$remote->error}";
}
// retry...
$txs = $remote->listtransactions($account, 200);
}
$txs_array = array(); $lastday = '';
if (!empty($txs)) {
// to hide truncated days sums
$tx = reset($txs);
if (count($txs) == 2500)
$lastday = strftime('%F', $tx['time']);
if (!empty($txs)) foreach($txs as $tx)
{
if (intval($tx['time']) > $list_since)
$txs_array[] = $tx;
}
krsort($txs_array);
}
// filter useless decred spent transactions
if ($coin->symbol == 'DCR') {
$prev_tx = array(); $lastday = '';
foreach($txs_array as $key => $tx)
{
$prev_txid = arraySafeVal($prev_tx,"txid");
$category = $tx['category'];
if ($category == 'send' && arraySafeVal($tx,'generated')) {
$txs_array[$key]['category'] = 'spent';
}
else if ($category == 'send' && $prev_txid === arraySafeVal($tx,"txid")) {
// if txid is the same as the last income... it's not a real "send"
if ($prev_tx['amount'] == 0 - $tx['amount'])
$txs_array[$key]['category'] = 'spent';
}
else if ($category == 'send' && $tx['amount'] == -0) {
// vote accepted (listed twice ? in listtransactions)
if ($tx['vout'] > 0)
$category = 'spent';
else if (arraySafeVal($tx,"confirmations") >= 256)
$category = 'receive';
else
$category = 'stake';
$txs_array[$key]['category'] = $category;
if ($tx['vout'] == 0) {
// won ticket value
$t = $remote->getrawtransaction($tx['txid'], 1);
if ($t && isset($t['vin'][0])) {
$txs_array[$key]['amount'] = $t['vin'][0]['amountin'] * 0.00000001;
}
}
}
else if ($category == 'receive') {
$prev_tx = $tx;
}
// for truncated day sums
if ($lastday == '' && count($txs) == 2500)
$lastday = strftime('%F', $tx['time']);
}
ksort($txs_array); // reversed order
}
$rows = 0;
foreach($txs_array as $tx)
{
$category = $tx['category'];
if ($category == 'spent') continue;
$block = null;
if(isset($tx['blockhash']))
$block = $remote->getblock($tx['blockhash']);
echo '';
$d = datetoa2($tx['time']);
echo ''.$d.' | ';
echo ''.$category.' | ';
echo ''.$tx['amount'].' | ';
if($block) {
echo ''.$block['height'].' | '.round_difficulty($block['difficulty']).' | ';
} else
echo ' | | ';
if(isset($tx['confirmations']))
echo ''.$tx['confirmations'].' | ';
else
echo ' | ';
echo '';
if(isset($tx['address']))
{
$address = $tx['address'];
$exists = dboscalar("SELECT count(*) AS nb FROM accounts WHERE username=:address", array(':address'=>$address));
if ($exists)
echo CHtml::link($address, '/?address='.$address);
else
echo $address.' ';
}
echo ' | ';
echo '';
if(!empty($block)) {
$txid = arraySafeVal($tx, 'txid');
$label = substr($txid, 0, 7);
echo CHtml::link($label, '/explorer?id='.$coin->id.'&txid='.$txid, array('target'=>'_blank'));
echo ' ('.count($block['tx']).')';
}
echo ' | ';
echo '
';
$rows++;
if ($rows >= $maxrows) break;
}
echo '
';
//////////////////////////////////////////////////////////////////////////////////////
echo <<
Day |
Category |
Sum |
BTC |
end;
$sums = array();
foreach($txs_array as $tx)
{
$day = strftime('%F', $tx['time']); // YYYY-MM-DD
if ($day == $lastday) break; // do not show truncated days
$category = $tx['category'];
if ($category == 'spent') continue;
$key = $day.' '.$category;
$sums[$key] = arraySafeVal($sums, $key) + $tx['amount'];
}
foreach($sums as $key => $amount)
{
$keys = explode(' ', $key);
$day = substr($keys[0], 5); // remove year
$category = $keys[1];
echo '';
echo ''.$day.' | ';
echo ''.$category.' | ';
echo ''.$amount.' | ';
echo ''.bitcoinvaluetoa($coin->price * $amount).' | ';
echo '
';
}
if (empty($sums)) {
echo '';
echo 'No activity during the last 7 days | ';
echo '
';
}
echo '
';