diff --git a/calculator.php b/calculator.php index 45e9970..26abeb1 100644 --- a/calculator.php +++ b/calculator.php @@ -1,32 +1,24 @@ \ No newline at end of file +?> diff --git a/explorer.php b/explorer.php deleted file mode 100644 index 4a5a5a2..0000000 --- a/explorer.php +++ /dev/null @@ -1,23 +0,0 @@ -explorer . "getblockcount"); - } - - function getBlockHash($blockHeight) { - return file_get_contents($this->explorer . "getblockhash?index=" . $blockHeight); - } - - function getBlock($blockHash) { - return json_decode(file_get_contents($this->explorer . "getblock?hash=" . $blockHash)); - } - - function getDifficulty($block) { - return $block->difficulty; - } -} -?> \ No newline at end of file diff --git a/index.php b/index.php index 091b885..14842d8 100644 --- a/index.php +++ b/index.php @@ -1,11 +1,11 @@ + - + @@ -17,8 +17,8 @@

A GINcoin income calculator made by @Tiamo#1675 on GINcoin Discord, written in PHP.

Insert your hashrate, and amount of masternodes owned and click "submit"; the program will output an estimated amount of daily coins earned. - Decimal values are supported, for example if you own 25% of a shared Masternode, input 0.25 under "Amount of Masternodes". - Both fields are optional.

+ Decimal values are supported, for example if you own 25% of a shared Masternode, input 0.25 under "Amount of Masternodes". Both fields are optional. + This calculator assumes the network hash over the past 1 hour, and dynamically calculates blocktime based on the last 101 blocks.

The source code is available on Github.

@@ -31,7 +31,8 @@ getNetworkHashPs(30); + $masternode_count = $gincoin->getMasternodeCount(); + $difficulty = $gincoin->getDifficulty(); -/* OLD WAY OF CALCULATING COINS/DAY, SLOW AND LOTS OF CALLS TO GINCOIN BLOCK EXPLORER - * $blockHeight = $explorer->getBlockHeight(); //get current blockheight - * for ($i = $blockHeight; $i > $blockHeight - 30; $i--) { //get the difficulties of the current block, and the previous 29 blocks - * $block = $explorer->getBlock($explorer->getBlockHash($i)); - * $difficulty = $explorer->getDifficulty($block); - * $difficulties[$i] = $difficulty; - * } - * $avg_difficulty = $calculator->averageArray($difficulties); //take the average of the current block, and the previous 29 blocks */ - - $difficulty = round($rpcclient->getDifficulty(), 0); - //NEW WAY TO CALCULATE COINS/DAY WITH GINCOIND getnetworkhashps - $networkHashPs = $rpcclient->getNetworkHashPs(30); - $masternode_count = $rpcclient->getMasternodeCount(); - - $pow_coins = round(($calculator->calculatePoWCoinsByNetworkHashPs($hashrate, $networkHashPs)), 8); - $masternode_coins = round(($calculator->calculateMasternodeCoins($masternode_multiplier, $masternode_count)), 8); - $totalCoins = round(($pow_coins + $masternode_coins), 8); + $calculator = new calculator(); + $pow_coins = round(($calculator->calculatePoWCoinsByNetworkHashPs($hashrate, $networkHashPs, $gincoin->powReward, $gincoin->blocktime)), 2); + $masternode_coins = round(($calculator->calculateMasternodeCoins($masternode_multiplier, $masternode_count, $gincoin->mnReward, $gincoin->blocktime)), 2); + $totalCoins = round(($pow_coins + $masternode_coins), 2); + $ticker = new ticker(); $GINprice = $ticker->getGIN()->last; $pow_coins_worth = round(($pow_coins * $GINprice), 8); $masternode_coins_worth = round(($masternode_coins * $GINprice), 8); $total_coins_worth = round(($pow_coins_worth + $masternode_coins_worth), 8); - echo "

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

"; + echo "

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

"; - echo "

The current difficulty is $difficulty.
"; - echo "The current amount of Masternodes is $masternode_count.

"; + echo "

The calculator assumed a nethash of " . round($networkHashPs/1000000000, 3) . " GHs over the past hour.
"; + echo "The average blocktime over the past 101 blocks was " . round($gincoin->blocktime) . " seconds.
"; + echo "The current amount of Masternodes is $masternode_count.

"; } ?> -

Generic formula for calculating Proof-of-Work coins by difficulty: coins_day=(seconds_day/(d*2^32/hashrate))*block_reward, where 2^32 is the average number of shares needed to find a block at a difficulty of 1
- Generic formula for calculating Proof-of-Work coins by nethash: coins_day=(hashrate/nethash)*((seconds_day/block_time)*block_reward)
- Generic formula for calculating Masternode coins: coins_day=(((seconds_day/block_time)*block_rewards)/masternode_count)

-

Tipjar (GIN): GXUQQXBr5i2gKcPaa5SJHqQ9M9G9SgL1X1

- \ No newline at end of file + diff --git a/rpcclient.php b/rpcclient.php index 611ff1f..8ecf0de 100644 --- a/rpcclient.php +++ b/rpcclient.php @@ -15,22 +15,69 @@ * https://en.bitcoin.it/wiki/Bitcoind */ -class rpcclient +class coin //class to communicate with a coin's daemon { - function __construct($rpcuser, $rpcpassword, $url, $port) { //url or ip address - $this->gincoin_client = new RPC\Client("http://".$rpcuser.":".$rpcpassword."@".$url.":".$port); + private $client; + public $blocktime; + public $powReward; + public $mnReward; + + function __construct($rpcuser, $rpcpassword, $ip, $port) { //url or ip address + $this->client = new RPC\Client("http://".$rpcuser.":".$rpcpassword."@".$ip.":".$port); + $this->blocktime = $this->getBlockTime(); + $this->mnReward = $this->getMNReward(); + $this->powReward = $this->getPoWReward(); } function getMasternodeCount() { - return $this->gincoin_client->masternode("count"); + return $this->client->masternode("count", "enabled"); } - function getNetworkHashPs($blocks) { - return $this->gincoin_client->getnetworkhashps($blocks); + function getNetworkHashPs($blocks) { //returns the network's hashrate over the past n blocks + return $this->client->getnetworkhashps($blocks); } function getDifficulty() { - return $this->gincoin_client->getdifficulty(); + return $this->client->getdifficulty(); + } + + function getBlock($hash) { + return $this->client->getblock($hash); + } + + function getBestBlock() { + return $this->client->getblock($this->client->getbestblockhash()); + } + + function getBlockCount() { //returns the latest block index + return $this->client->getblockcount(); + } + + function getBlockHash($index) { + return $this->client->getblockhash($index); + } + + function getRawTransaction($hash) { + return $this->client->getrawtransaction($hash, 1); + } + + private function getBlockTime() { + $bestblock = $this->getBestBlock(); + $block2 = $this->getblock($this->getBlockHash($this->getBlockCount() - 100)); + $timedelta = $bestblock["mediantime"] - $block2["mediantime"]; //the time in seconds that has passed between the best block and the block 100 blocks before the best block + return $timedelta / 101; //returns the average blocktime over the past 101 blocks + } + + private function getMNReward() { + $bestblock = $this->getBestBlock(); + $coinbase = $this->getRawTransaction($bestblock["tx"][0]); //coinbase transaction of the best block + return $coinbase["vout"][0]["value"]; //the 1st output in a coinbase transaction is always the MN reward, here we return the value of that output + } + + private function getPoWReward() { + $bestblock = $this->getBestBlock(); + $coinbase = $this->getRawTransaction($bestblock["tx"][0]); //coinbase transaction of the best block + return $coinbase["vout"][1]["value"]; //the 2nd output in a coinbase transaction is always the PoW reward, here we return the value of that output } } -?> \ No newline at end of file +?> diff --git a/ticker.php b/ticker.php index fa42a31..3723bd2 100644 --- a/ticker.php +++ b/ticker.php @@ -1,17 +1,19 @@ coins = json_decode(file_get_contents($this->tickerurl)); + } + function getGIN() { - $arr = json_decode(file_get_contents($this->ticker)); - - for($i = 0; $i < count($arr); $i++) { - if($arr[$i]->id == "GIN_BTC") { - return $arr[$i]; + for($i = 0; $i <= count($this->coins); $i++) { + if($this->coins[$i]->id == "GIN_BTC") { + return $this->coins[$i]; } } - return null; } } -?> \ No newline at end of file +?>