more efficient non rpc validation
This commit is contained in:
parent
d5dd832b91
commit
34eac09175
@ -679,78 +679,33 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||
return $difference;
|
||||
}
|
||||
}
|
||||
|
||||
public function verify_non_rpc($payment_id, $amount, $order_id)
|
||||
{
|
||||
$tools = new NodeTools($this->testnet);
|
||||
$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
|
||||
|
||||
$output_found;
|
||||
$block_index;
|
||||
|
||||
if($block_difference != 0)
|
||||
{
|
||||
if($block_difference >= 2){
|
||||
$this->log->add('[WARNING] Block difference is greater or equal to 2');
|
||||
}
|
||||
|
||||
$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'];
|
||||
if(strlen($txs_from_block[$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; // finish loop
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
if(isset($output_found))
|
||||
{
|
||||
$amount_atomic_units = $amount * 1000000000000;
|
||||
|
||||
if($txs_from_block[$block_index]['payment_id'] == $payment_id && $output_found['amount'] >= $amount_atomic_units)
|
||||
{
|
||||
$this->on_verified($payment_id, $amount_atomic_units, $order_id);
|
||||
}
|
||||
if($txs_from_block_2[$block_index]['payment_id'] == $payment_id && $output_found['amount'] >= $amount_atomic_units)
|
||||
{
|
||||
$this->on_verified($payment_id, $amount_atomic_units, $order_id);
|
||||
}
|
||||
$outputs = $tools->get_outputs($this->address, $this->viewKey);
|
||||
$outs_count = count($outputs);
|
||||
|
||||
$i = 0;
|
||||
$tx_hash;
|
||||
if($outs_count != 0)
|
||||
{
|
||||
while($i < $outs_count )
|
||||
{
|
||||
if($outputs[$i]['payment_id'] == $payment_id)
|
||||
{
|
||||
if($outputs[$i]['amount'] >= $amount_atomic_units)
|
||||
{
|
||||
$this->on_verified($payment_id, $amount_atomic_units, $order_id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user