more efficient non rpc validation
This commit is contained in:
parent
d5dd832b91
commit
34eac09175
@ -679,79 +679,34 @@ class Monero_Gateway extends WC_Payment_Gateway
|
|||||||
return $difference;
|
return $difference;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function verify_non_rpc($payment_id, $amount, $order_id)
|
public function verify_non_rpc($payment_id, $amount, $order_id)
|
||||||
{
|
{
|
||||||
$tools = new NodeTools($this->testnet);
|
$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);
|
$amount_atomic_units = $amount * 1000000000000;
|
||||||
$tx_count = count($txs_from_block) - 1; // The tx at index 0 is a coinbase tx so it can be ignored
|
|
||||||
|
$outputs = $tools->get_outputs($this->address, $this->viewKey);
|
||||||
|
$outs_count = count($outputs);
|
||||||
|
|
||||||
$output_found;
|
$i = 0;
|
||||||
$block_index;
|
$tx_hash;
|
||||||
|
if($outs_count != 0)
|
||||||
if($block_difference != 0)
|
|
||||||
{
|
{
|
||||||
if($block_difference >= 2){
|
while($i < $outs_count )
|
||||||
$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($outputs[$i]['payment_id'] == $payment_id)
|
||||||
if(strlen($txs_from_block_2[$i]['payment_id']) != 0)
|
|
||||||
{
|
{
|
||||||
$result = $tools->check_tx($tx_hash, $this->address, $this->viewKey);
|
if($outputs[$i]['amount'] >= $amount_atomic_units)
|
||||||
if($result)
|
|
||||||
{
|
{
|
||||||
$output_found = $result;
|
$this->on_verified($payment_id, $amount_atomic_units, $order_id);
|
||||||
$block_index = $i;
|
return true;
|
||||||
$i = $tx_count_2; // finish loop
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function verify_zero_conf($payment_id, $amount, $order_id)
|
public function verify_zero_conf($payment_id, $amount, $order_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user