diff --git a/scripts/validate_blocks.php b/scripts/validate_blocks.php new file mode 100644 index 00000000..eed93e43 --- /dev/null +++ b/scripts/validate_blocks.php @@ -0,0 +1,48 @@ +#!/usr/bin/php +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; +?> \ No newline at end of file diff --git a/scripts/validate_users.php b/scripts/validate_users.php new file mode 100644 index 00000000..bc44971c --- /dev/null +++ b/scripts/validate_users.php @@ -0,0 +1,56 @@ +#!/usr/bin/php +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; +?> \ No newline at end of file