예제 #1
0
파일: api.php 프로젝트: prusso/wizstats
    foreach ($hashrate_info["intervals"] as $interval) {
        $hashrate_info_for_interval = $hashrate_info[$interval];
        $interval_name = $hashrate_info_for_interval["interval_name"];
        $hashrate = $hashrate_info_for_interval["hashrate"];
        $shares = $hashrate_info_for_interval["shares"];
        $output["av" . $interval] = array("numeric" => sprintf("%.0F", $hashrate), "pretty" => prettyHashrate($hashrate), "share_count" => sprintf("%u", $shares), "name" => $interval_name);
    }
    $data["output"] = $output;
    echo ws_api_encode($data);
    exit;
}
if ($cmd == "getuserstat") {
    $link = pg_pconnect("dbname={$psqldb} user={$psqluser} password='******' host={$psqlhost}");
    if (isset($_GET["username"])) {
        $givenuser = $_GET["username"];
        $bits = hex2bits(\Bitcoin::addressToHash160($givenuser));
        $user_id = get_user_id_from_address($link, $givenuser);
        if (!$user_id) {
            ws_api_error("{$cmd}: Username {$givenuser} not found in database.");
        }
    } else {
        ws_api_error("{$cmd}: No valid user id specified");
    }
    $data["output"] = \wizstats\userstat\getBalanceForUser($link, $user_id, $givenuser);
    echo ws_api_encode($data);
    exit;
}
if ($cmd == "getblocks") {
    if (isset($_GET["limit"]) && is_numeric($_GET["limit"])) {
        $limit = pg_escape_string($_GET["limit"]);
        if ($limit < 0) {
예제 #2
0
$insertvalues = "";
$paidinsertvalues = "";
$ucount = 0;
foreach ($balj as $key => $val) {
    $mbal = isset($val['balance']) ? $val['balance'] : 0;
    $mep = isset($val['everpaid']) ? $val['everpaid'] : 0;
    $mec = isset($val['credit']) ? $val['credit'] : 0;
    $mbal++;
    $mbal--;
    $mep++;
    $mep--;
    $mec++;
    $mec--;
    if ($key != "") {
        # convert address to bits to find the user...
        $bits = hex2bits(\Bitcoin::addressToHash160($key));
        if ($bits != "") {
            $lastdata[$bits][0] = $mbal;
            $lastdata[$bits][1] = $mep;
            $lastdata[$bits][2] = $mec;
        }
    }
}
$sql = "select distinct on (user_id) user_id,time,username,keyhash,everpaid,credit,balance from {$psqlschema}.stats_balances left join users on user_id=users.id where server={$serverid} and time > NOW()-'1 week'::interval order by user_id, time desc;";
$result = pg_exec($link, $sql);
$numrows = pg_numrows($result);
for ($ri = 0; $ri < $numrows; $ri++) {
    $row = pg_fetch_array($result, $ri);
    $user_id = $row["user_id"];
    if (!$user_id) {
        print "Error: Invalid user_id {$user_id} " . $row["keyhash"] . " - " . $row["username"] . "!\n";