Merge pull request #1844 from raistlinthewiz/next

Added block and account validation scripts
This commit is contained in:
Sebastian Grewe 2014-03-02 16:57:43 +01:00
commit 9dd94c617b
2 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,48 @@
#!/usr/bin/php
<?php
/* script to validate blocks */
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
if ( $bitcoin->can_connect() !== true )
die("Failed to connect to RPC server". PHP_EOL);
echo "Validating blocks in database against coind..". PHP_EOL;
$mask = "| %6s | %8s | %13s | %20s | %10s |". PHP_EOL;;
printf($mask, 'DB-ID', 'Height', 'Confirmations', 'Time', 'Status');
// fetch all blocks
$allBlocks = $block->getAll();
foreach ($allBlocks as $block)
{
try {
if($block['confirmations']== -1) // mark orphan blocks.
$status = 'ORPHAN';
else
{
$blockInfo = $bitcoin->getblock($block['blockhash']);
$status = 'VALID'; // if the getblock() call didn't throw an exception, it's a valid block then.
}
}
catch(Exception $e)
{
if($e->getMessage() == 'RPC call did not return 200: HTTP error: 500 - JSON Response: [-5] Block not found')
{
$status = 'INVALID';
}
else
{
$status = 'UNKNOWN';
}
}
printf($mask, $block['id'], $block['height'], $block['confirmations'], strftime("%Y-%m-%d %H:%M:%S", $block['time']), $status);
}
echo "Done..". PHP_EOL;
?>

View File

@ -0,0 +1,56 @@
#!/usr/bin/php
<?php
/* script to validate accounts */
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
$timeLimitInDays = 90;
// Fetch all users
$users = $user->getAllAssoc();
$mask = "| %6s | %20s | %16s | %20s | %12.12s | %5s | %5s | %12s | %5s | \n";
printf($mask, 'ID', 'Username', 'LoggedIP', 'Last Login','Days Since', 'Ever', 'Trans', 'Balance','Stale');
$currentTime = time();
$totalSavings = 0;
foreach ($users as $user)
{
$id = $user['id'];
$isAdmin = $user['is_admin'];
$username = $user['username'];
$loggedIp = $user['loggedIp'];
$lastLogin = $user['last_login'];
$coinAddress = $user['coin_address'];
$everLoggedIn = !empty($lastLogin);
$timeDelta = $currentTime - $lastLogin;
$lastLoginInDays = round(abs($timeDelta)/60/60/24, 0);
if($lastLoginInDays < $timeLimitInDays)
continue;
// get transactions summary for the user
$summary = $transaction->getTransactionSummary($id);
$transactions_exists = !empty($summary);
// get balances
$balances = $transaction->getBalance($id);
$confirmedBalance = $balances['confirmed'];
$totalSavings += $confirmedBalance;
$staleAccount = $everLoggedIn == false && $transactions_exists == false;
printf($mask, $id, $username,
$loggedIp, strftime("%Y-%m-%d %H:%M:%S", $lastLogin), $lastLoginInDays, $everLoggedIn ? 'yes' : 'no',
$transactions_exists ? 'yes' : 'no', round($confirmedBalance,8),
$staleAccount ? 'yes' : 'no' );
}
echo "Total balance of stale accounts: $totalSavings" . PHP_EOL;
?>