function getMNVotes($testnet = false)
{
    if ($testnet) {
        $testnetval = "1";
        $testnetstr = "testnet";
    } else {
        $testnetval = "0";
        $testnetstr = "";
    }
    xecho("Retrieving masternodes votes (testnet={$testnetval}): ");
    $result = dmn_api_get("/masternodes/votes?testnet={$testnetval}", array(), $response);
    if ($response['http_code'] == 200) {
        echo "Fetched...";
        $votes = json_decode($result, true);
        if ($votes === false) {
            echo " Failed to JSON decode!\n";
            die(200);
        } elseif (!is_array($votes) || !array_key_exists('data', $votes) || !is_array($votes['data'])) {
            echo " Incorrect data!\n";
            die(202);
        }
        $votes = $votes['data'];
        echo " OK (" . count($votes) . " entries)\n";
    } else {
        echo "Failed [" . $response['http_code'] . "]\n";
        if ($response['http_code'] != 500) {
            $result = json_decode($result, true);
            if ($result !== false) {
                foreach ($result['messages'] as $num => $msg) {
                    xecho("Error #{$num}: {$msg}\n");
                }
            }
        }
        die(201);
    }
    $votesyea = 0;
    $votesnay = 0;
    $votesabstain = 0;
    $votestotal = 0;
    foreach ($votes as $vote) {
        if ($vote["Vote"] == "Yea") {
            $votesyea += $vote["VoteCount"];
        } elseif ($vote["Vote"] == "Nay") {
            $votesnay += $vote["VoteCount"];
        } else {
            $votesabstain += $vote["VoteCount"];
        }
    }
    $votestotal = $votesyea + $votesnay + $votesabstain;
    xecho("Submitting to RRDtool DB (N:{$votesyea}:{$votesnay}:{$votesabstain}:{$votestotal}): ");
    // rrdtool create mnvotes2.rrd --start 1431101864 DS:Yea:GAUGE:600:U:U DS:Nay:GAUGE:600:U:U DS:Abstain:GAUGE:600:U:U DS:Total:GAUGE:600:U:U RRA:MAX:0.5:1:600 RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797
    if (rrd_update("mnvotes2{$testnetstr}.rrd", ["N:{$votesyea}:{$votesnay}:{$votesabstain}:{$votestotal}"])) {
        echo "OK\n";
    } else {
        echo "Failed\n";
    }
}
                xecho("Error #{$num}: {$msg}\n");
            }
        }
    }
    die(201);
}
for ($x = 0; $x < 2; $x++) {
    if ($x == 0) {
        $display = "mainnet";
        $uname = 'p2pool';
    } else {
        $display = "testnet";
        $uname = 'tp2pool';
    }
    xecho('Retrieving last month block for ' . $display . ': ');
    $result = dmn_api_get('/blocks', array("interval" => "P1M", 'testnet' => $x), $response);
    if ($response['http_code'] == 200) {
        echo "Fetched...";
        $blocks = json_decode($result, true);
        if ($blocks === false) {
            echo " Failed to JSON decode!\n";
            die(200);
        } elseif (!is_array($blocks) || !array_key_exists('data', $blocks) || !is_array($blocks['data']) || !array_key_exists('blocks', $blocks['data']) || !is_array($blocks['data']['blocks'])) {
            echo " Incorrect data!\n";
            die(202);
        }
        $blocks = $blocks['data']['blocks'];
        echo " OK (" . count($blocks) . " entries)\n";
    } else {
        echo "Failed [" . $response['http_code'] . "]\n";
        if ($response['http_code'] != 500) {
    $nodes = $nodes['data'];
    echo " OK (" . count($nodes) . " entries)\n";
} else {
    echo "Failed [" . $response['http_code'] . "]\n";
    if ($response['http_code'] != 500) {
        $result = json_decode($result, true);
        if ($result !== false) {
            foreach ($result['messages'] as $num => $msg) {
                xecho("Error #{$num}: {$msg}\n");
            }
        }
    }
    die(201);
}
xecho('Retrieving last month block: ');
$result = dmn_api_get('/blocks', array("interval" => "P1M"), $response);
if ($response['http_code'] == 200) {
    echo "Fetched...";
    $blocks = json_decode($result, true);
    if ($blocks === false) {
        echo " Failed to JSON decode!\n";
        die(200);
    } elseif (!is_array($blocks) || !array_key_exists('data', $blocks) || !is_array($blocks['data']) || !array_key_exists('blocks', $blocks['data']) || !is_array($blocks['data']['blocks'])) {
        echo " Incorrect data!\n";
        die(202);
    }
    $blocks = $blocks['data']['blocks'];
    echo " OK (" . count($blocks) . " entries)\n";
} else {
    echo "Failed [" . $response['http_code'] . "]\n";
    if ($response['http_code'] != 500) {
     }
     echo " OK (" . count($mnips) . " masternodes)\n";
 } else {
     echo "Failed [" . $response['http_code'] . "]\n";
     if ($response['http_code'] != 500) {
         $result = json_decode($result, true);
         if ($result !== false) {
             foreach ($result['messages'] as $num => $msg) {
                 xecho("Error #{$num}: {$msg}\n");
             }
         }
     }
     die(201);
 }
 xecho('Retrieving MN info (testnet): ');
 $result = dmn_api_get('/masternodes', array("testnet" => 1), $response);
 if ($response['http_code'] == 200) {
     echo "Fetched...";
     $mnlist = json_decode($result, true);
     if ($mnlist === false) {
         echo " Failed to JSON decode!\n";
         die(200);
     } elseif (!is_array($mnlist) || !array_key_exists('data', $mnlist) || !is_array($mnlist['data'])) {
         echo " Incorrect data!\n";
         die(202);
     }
     foreach ($mnlist['data'] as $mnip) {
         $mnips[] = $mnip['MasternodeIP'] . '-' . $mnip['MasternodePort'] . '-1';
     }
     echo " OK (" . count($mnlist['data']) . " masternodes)\n";
 } else {