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

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