diff --git a/scripts/validate_blocks.php b/scripts/validate_blocks.php new file mode 100644 index 00000000..f9b40b30 --- /dev/null +++ b/scripts/validate_blocks.php @@ -0,0 +1,34 @@ +#!/usr/bin/php +can_connect() !== true ) + die("Failed to connect to RPC server\n"); + + echo "Validating blocks in database against coind..\n"; + + // fetch all blocks + $allBlocks = $block->getAll(); + foreach ($allBlocks as $block) + { + try { + $blockInfo = $bitcoin->getblock($block['blockhash']); + } + catch(Exception $e) + { + // don't report orphan blocks. + if($block['confirmations']!= -1 && $e->getMessage() == 'RPC call did not return 200: HTTP error: 500 - JSON Response: [-5] Block not found') + { + echo "Block not found: database-id: $block[id] - height: $block[height].\n"; + } + } + } + + echo "Done..\n"; +?> \ No newline at end of file diff --git a/scripts/validate_users.php b/scripts/validate_users.php new file mode 100644 index 00000000..e188b28f --- /dev/null +++ b/scripts/validate_users.php @@ -0,0 +1,56 @@ +#!/usr/bin/php +getAllAssoc(); + + $mask = "| %6s | %20s | %16s | %10s | %-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 = abs($timeDelta)/60/60/24; + + 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, $lastLogin, $lastLoginInDays, $everLoggedIn ? 'yes' : 'no', + $transactions_exists ? 'yes' : 'no', $confirmedBalance, + $staleAccount ? 'yes' : 'no' ); + } + + echo "Total balance of stale accounts: $totalSavings \n"; +?> \ No newline at end of file