Update mine file to PSR-2

This commit is contained in:
pxgamer
2018-05-29 15:46:16 +01:00
parent 28807ef9ca
commit aa3459181e

View File

@@ -1,7 +1,7 @@
<?php
/*
/*
The MIT License (MIT)
Copyright (c) 2018 AroDev
Copyright (c) 2018 AroDev
www.arionum.com
@@ -24,53 +24,60 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
*/
require_once("include/init.inc.php");
$block=new Block();
$acc=new Account();
$block = new Block();
$acc = new Account();
set_time_limit(360);
$q=$_GET['q'];
$q = $_GET['q'];
$ip=san_ip($_SERVER['REMOTE_ADDR']);
$ip=filter_var($ip, FILTER_VALIDATE_IP);
$ip = san_ip($_SERVER['REMOTE_ADDR']);
$ip = filter_var($ip, FILTER_VALIDATE_IP);
// in case of testnet, all IPs are accepted for mining
if($_config['testnet']==false&&!in_array($ip,$_config['allowed_hosts'])&&!empty($ip)&&!in_array('*',$_config['allowed_hosts'])) api_err("unauthorized");
if($q=="info"){
// provides the mining info to the miner
$diff=$block->difficulty();
$current=$block->current();
$res=array("difficulty"=>$diff, "block"=>$current['id'], "height"=>$current['height'], "testnet"=>$_config['testnet']);
api_echo($res);
exit;
} elseif($q=="submitNonce"){
// in case the blocks are syncing, reject all
if($_config['sanity_sync']==1) api_err("sanity-sync");
$nonce = san($_POST['nonce']);
$argon=$_POST['argon'];
$public_key=san($_POST['public_key']);
$private_key=san($_POST['private_key']);
// check if the miner won the block
$result=$block->mine($public_key, $nonce, $argon);
if($result) {
// generate the new block
$res=$block->forge($nonce,$argon, $public_key, $private_key);
if($res){
//if the new block is generated, propagate it to all peers in background
$current=$block->current();
system("php propagate.php block $current[id] > /dev/null 2>&1 &");
api_echo("accepted");
}
}
api_err("rejected");
} else {
api_err("invalid command");
if ($_config['testnet'] == false && !in_array($ip, $_config['allowed_hosts']) && !empty($ip) && !in_array(
'*',
$_config['allowed_hosts']
)) {
api_err("unauthorized");
}
?>
if ($q == "info") {
// provides the mining info to the miner
$diff = $block->difficulty();
$current = $block->current();
$res = [
"difficulty" => $diff,
"block" => $current['id'],
"height" => $current['height'],
"testnet" => $_config['testnet'],
];
api_echo($res);
exit;
} elseif ($q == "submitNonce") {
// in case the blocks are syncing, reject all
if ($_config['sanity_sync'] == 1) {
api_err("sanity-sync");
}
$nonce = san($_POST['nonce']);
$argon = $_POST['argon'];
$public_key = san($_POST['public_key']);
$private_key = san($_POST['private_key']);
// check if the miner won the block
$result = $block->mine($public_key, $nonce, $argon);
if ($result) {
// generate the new block
$res = $block->forge($nonce, $argon, $public_key, $private_key);
if ($res) {
//if the new block is generated, propagate it to all peers in background
$current = $block->current();
system("php propagate.php block $current[id] > /dev/null 2>&1 &");
api_echo("accepted");
}
}
api_err("rejected");
} else {
api_err("invalid command");
}