From a8058ef2409f04d001dbc0c33de09751e0d1a6a5 Mon Sep 17 00:00:00 2001 From: iTiamo Date: Sun, 27 May 2018 21:27:45 +0200 Subject: [PATCH] add API --- api/getIncome.php | 12 ++++++ api/getNetworkStats.php | 9 ++++ index.php | 30 +++++++++++-- program.php | 63 ---------------------------- calculator.php => src/calculator.php | 4 +- coin.php => src/coin.php | 19 +++++++-- src/income.php | 48 +++++++++++++++++++++ src/networkStats.php | 13 ++++++ ticker.php => src/ticker.php | 6 +-- 9 files changed, 126 insertions(+), 78 deletions(-) create mode 100644 api/getIncome.php create mode 100644 api/getNetworkStats.php delete mode 100644 program.php rename calculator.php => src/calculator.php (99%) rename coin.php => src/coin.php (85%) create mode 100644 src/income.php create mode 100644 src/networkStats.php rename ticker.php => src/ticker.php (92%) diff --git a/api/getIncome.php b/api/getIncome.php new file mode 100644 index 0000000..4eefd2d --- /dev/null +++ b/api/getIncome.php @@ -0,0 +1,12 @@ + $_GET["hashrate"], + "masternodes" => $_GET["masternodes"] +)); + +echo json_encode($income); +?> \ No newline at end of file diff --git a/api/getNetworkStats.php b/api/getNetworkStats.php new file mode 100644 index 0000000..0c1def7 --- /dev/null +++ b/api/getNetworkStats.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/index.php b/index.php index 07f5a7d..73f4478 100644 --- a/index.php +++ b/index.php @@ -35,12 +35,34 @@ $_GET["hashrate"], + "masternodes" => $_GET["masternodes"] + )); + + $networkStats = getNetworkStats($coin); + + $totalCoins = number_format($income["proof-of-work"][$coinTicker] + $income["masternode-rewards"][$coinTicker], 8); + $totalCoinsWorth = number_format($income["proof-of-work"]["BTC"] + $income["masternode-rewards"]["BTC"], 8); + + echo "

You will make an average of {$income["proof-of-work"][$coinTicker]} {$coinTicker} per day by Proof of Work, equal to {$income["proof-of-work"]["BTC"]} BTC.
"; + echo "You will make an average of {$income["masternode-rewards"][$coinTicker]} {$coinTicker} per day by Masternodes, equal to {$income["masternode-rewards"]["BTC"]} BTC.
"; + echo "You will make a total of $totalCoins $coinTicker per day, equal to $totalCoinsWorth BTC.

"; + + echo "

The average network hashrate is " . round($networkStats["network-hashrate"]/1000000000, 3) . " GHs.
"; + echo "The average blocktime is " . round($coin->blocktime) . " seconds.
"; + echo "The current amount of Masternodes is {$networkStats["masternodes"]}.

"; } ?>

Tipjar (GIN): GXUQQXBr5i2gKcPaa5SJHqQ9M9G9SgL1X1

- + \ No newline at end of file diff --git a/program.php b/program.php deleted file mode 100644 index 3989a06..0000000 --- a/program.php +++ /dev/null @@ -1,63 +0,0 @@ -getNetworkHashPs(101); - $netMasternodes = $coin->getMasternodeCount(); - $difficulty = $coin->getDifficulty(); - - $calculator = new calculator(); - $pow_coins = round(($calculator->calculatePoWCoinsByNetworkHashPs($hashrate, $netHashrate, $coin->powReward, $coin->blocktime)), 2); - $masternode_coins = round(($calculator->calculateMasternodeCoins($masternodes, $netMasternodes, $coin->mnReward, $coin->blocktime)), 2); - $totalCoins = round(($pow_coins + $masternode_coins), 2); - - $ticker = new ticker(); - if($ticker->getCryptoBridgeCoin($coin->coinid)) { - $price = $ticker->getCryptoBridgeCoin($coin->coinid)->last; - } else { - $price = $ticker->getGraviexCoin($coin->coinid)->ticker->last; - } - - $pow_coins_worth = round(($pow_coins * $price), 8); - $masternode_coins_worth = round(($masternode_coins * $price), 8); - $total_coins_worth = round(($pow_coins_worth + $masternode_coins_worth), 8); - - echo "

You will make an average of $pow_coins $coin->coinid per day by Proof of Work, equal to $pow_coins_worth BTC.
"; - echo "You will make an average of $masternode_coins $coin->coinid per day by Masternodes, equal to $masternode_coins_worth BTC.
"; - echo "You will make a total of $totalCoins $coin->coinid per day, equal to $total_coins_worth BTC.

"; - - echo "

The average network hashrate is " . round($netHashrate/1000000000, 3) . " GHs.
"; - echo "The average blocktime is " . round($coin->blocktime) . " seconds.
"; - echo "The current amount of Masternodes is $netMasternodes.

"; -} - -?> diff --git a/calculator.php b/src/calculator.php similarity index 99% rename from calculator.php rename to src/calculator.php index a3cdcc5..16bf187 100644 --- a/calculator.php +++ b/src/calculator.php @@ -1,5 +1,4 @@ +?> \ No newline at end of file diff --git a/coin.php b/src/coin.php similarity index 85% rename from coin.php rename to src/coin.php index 67a9656..a10e753 100644 --- a/coin.php +++ b/src/coin.php @@ -1,8 +1,6 @@ + +function getCoin($coinTicker) { + switch($coinTicker) { //gets the coin and instantiates a class to interact with the coin's daemon + case "GIN": + return new coin("GIN", "gincoin", "gincoin", "127.0.0.1", "10112"); + + case "LUCKY": + return new coin("LUCKY", "luckybit", "luckybit", "127.0.0.1", "10113"); + + case "PROTON": + return new coin("PROTON", "protoncoin", "protoncoin", "127.0.0.1", "10114"); + } +} +?> \ No newline at end of file diff --git a/src/income.php b/src/income.php new file mode 100644 index 0000000..7685c3c --- /dev/null +++ b/src/income.php @@ -0,0 +1,48 @@ +getNetworkHashPs(101); + $netMasternodes = $coin->getMasternodeCount(); + $difficulty = $coin->getDifficulty(); + + $calculator = new calculator(); + $pow_coins = number_format(($calculator->calculatePoWCoinsByNetworkHashPs($params["hashrate"], $netHashrate, $coin->powReward, $coin->blocktime)), 8); + $masternode_coins = number_format(($calculator->calculateMasternodeCoins($params["masternodes"], $netMasternodes, $coin->mnReward, $coin->blocktime)), 8); + $totalCoins = number_format(($pow_coins + $masternode_coins), 8); + + $ticker = new ticker(); + if($ticker->getCryptoBridgeCoin($coin->coinid)) { + $price = $ticker->getCryptoBridgeCoin($coin->coinid)->last; + } else { + $price = $ticker->getGraviexCoin($coin->coinid)->ticker->last; + } + + $pow_coins_worth = number_format(($pow_coins * $price), 8); + $masternode_coins_worth = number_format(($masternode_coins * $price), 8); + $total_coins_worth = number_format(($pow_coins_worth + $masternode_coins_worth), 8); + + return array( + "proof-of-work" => array( + $coin->coinid => $pow_coins, + "BTC" => $pow_coins_worth + ), + "masternode-rewards" => array( + $coin->coinid => $masternode_coins, + "BTC" => $masternode_coins_worth + ) + ); +} +?> \ No newline at end of file diff --git a/src/networkStats.php b/src/networkStats.php new file mode 100644 index 0000000..98b37a4 --- /dev/null +++ b/src/networkStats.php @@ -0,0 +1,13 @@ +getNetworkHashPs(101); + $masternodes = $coin->getMasternodeCount(); + $difficulty = $coin->getDifficulty(); + + return array( + "network-hashrate" => $netHashrate, + "masternodes" => $masternodes, + "difficulty" => $difficulty + ); +} +?> \ No newline at end of file diff --git a/ticker.php b/src/ticker.php similarity index 92% rename from ticker.php rename to src/ticker.php index a562d73..76e959a 100644 --- a/ticker.php +++ b/src/ticker.php @@ -1,6 +1,5 @@ graviex . strtolower($id) . "btc.json"), false, stream_context_create($arrContextOptions))); } } - -?> +?> \ No newline at end of file