mirror of
https://git.wownero.com/wownero/wownerowp.git
synced 2024-08-15 01:03:16 +00:00
Dont miss blocks
Set a cookie for the last seen block so that one is not missed in the case that two blocks are mined in a very short period of time.
This commit is contained in:
parent
460f4f6c75
commit
0b15e31672
1 changed files with 44 additions and 3 deletions
|
@ -623,17 +623,57 @@ class Monero_Gateway extends WC_Payment_Gateway
|
|||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function last_block_seen($height) // sometimes 2 blocks are mined within a few seconds of eacher. Make sure we don't miss one
|
||||
{
|
||||
if (!isset($_COOKIE['last_seen_block']))
|
||||
{
|
||||
setcookie('last_seen_block', $height, time() + 2700);
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
$cookie_block = $_COOKIE['last_seen_block'];
|
||||
$difference = $height - $cookie_block;
|
||||
setcookie('last_seen_block', $height, time() + 2700);
|
||||
return $difference;
|
||||
}
|
||||
}
|
||||
public function verify_non_rpc($payment_id, $amount, $order_id)
|
||||
{
|
||||
$tools = new NodeTools();
|
||||
$bc_height = $tools->get_last_block_height();
|
||||
|
||||
$block_difference = $this->last_block_seen($bc_height);
|
||||
|
||||
$txs_from_block = $tools->get_txs_from_block($bc_height);
|
||||
$tx_count = count($txs_from_block) - 1; // The tx at index 0 is a coinbase tx so it can be ignored
|
||||
|
||||
$i = 1;
|
||||
$output_found;
|
||||
$block_index;
|
||||
|
||||
if($difference != 0)
|
||||
{
|
||||
$txs_from_block_2 = $tools->get_txs_from_block($bc_height - 1);
|
||||
$tx_count_2 = count($txs_from_block_2) - 1;
|
||||
|
||||
$i = 1;
|
||||
while($i <= $tx_count_2)
|
||||
{
|
||||
$tx_hash = $txs_from_block_2[$i]['tx_hash'];
|
||||
if(strlen($txs_from_block_2[$i]['payment_id']) != 0)
|
||||
{
|
||||
$result = $tools->check_tx($tx_hash, $this->address, $this->viewKey);
|
||||
if($result)
|
||||
{
|
||||
$output_found = $result;
|
||||
$block_index = $i;
|
||||
$i = $tx_count_2; // finish loop
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$i = 1;
|
||||
while($i <= $tx_count)
|
||||
{
|
||||
$tx_hash = $txs_from_block[$i]['tx_hash'];
|
||||
|
@ -649,6 +689,7 @@ class Monero_Gateway extends WC_Payment_Gateway
|
|||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
if(isset($output_found))
|
||||
{
|
||||
$amount_atomic_units = $amount * 1000000000000;
|
||||
|
|
Loading…
Reference in a new issue