diff --git a/mine.php b/mine.php index f8b2501..3f3da8b 100755 --- a/mine.php +++ b/mine.php @@ -1,7 +1,7 @@ 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"); +}