mirror of
https://git.wownero.com/wownero/wownerowp.git
synced 2024-08-15 01:03:16 +00:00
add optional 0-conf txs
Add the option to search the mempool for unconfirmed transactions for quicker payments
This commit is contained in:
parent
3e9b4acd48
commit
fa49096c15
1 changed files with 56 additions and 3 deletions
|
@ -13,6 +13,7 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||||
private $confirmed = false;
|
private $confirmed = false;
|
||||||
private $monero_daemon;
|
private $monero_daemon;
|
||||||
private $non_rpc = false;
|
private $non_rpc = false;
|
||||||
|
private $zero_cofirm = false;
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
|
@ -33,6 +34,7 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||||
$this->address = $this->get_option('monero_address');
|
$this->address = $this->get_option('monero_address');
|
||||||
$this->viewKey = $this->get_option('viewKey');
|
$this->viewKey = $this->get_option('viewKey');
|
||||||
$this->discount = $this->get_option('discount');
|
$this->discount = $this->get_option('discount');
|
||||||
|
$this->accept_zero_conf = $this->get_option('zero_conf');
|
||||||
|
|
||||||
$this->use_viewKey = $this->get_option('use_viewKey');
|
$this->use_viewKey = $this->get_option('use_viewKey');
|
||||||
$this->use_rpc = $this->get_option('use_rpc');
|
$this->use_rpc = $this->get_option('use_rpc');
|
||||||
|
@ -45,7 +47,10 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||||
{
|
{
|
||||||
$this->non_rpc = false;
|
$this->non_rpc = false;
|
||||||
}
|
}
|
||||||
|
if($this->accept_zero_conf == 'yes')
|
||||||
|
{
|
||||||
|
$this->zero_confirm = true;
|
||||||
|
}
|
||||||
// After init_settings() is called, you can get the settings and load them into variables, e.g:
|
// After init_settings() is called, you can get the settings and load them into variables, e.g:
|
||||||
// $this->title = $this->get_option('title' );
|
// $this->title = $this->get_option('title' );
|
||||||
$this->init_settings();
|
$this->init_settings();
|
||||||
|
@ -145,6 +150,13 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||||
'description' => __('Check this box if you are using testnet', 'monero_gateway'),
|
'description' => __('Check this box if you are using testnet', 'monero_gateway'),
|
||||||
'default' => 'no'
|
'default' => 'no'
|
||||||
),
|
),
|
||||||
|
'zero_conf' => array(
|
||||||
|
'title' => __(' Accept 0 conf txs', 'monero_gateway'),
|
||||||
|
'label' => __(' Accept 0-confirmation transactions ', 'monero_gateway'),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'description' => __('This is faster but less secure', 'monero_gateway'),
|
||||||
|
'default' => 'no'
|
||||||
|
),
|
||||||
'onion_service' => array(
|
'onion_service' => array(
|
||||||
'title' => __(' SSL warnings ', 'monero_gateway'),
|
'title' => __(' SSL warnings ', 'monero_gateway'),
|
||||||
'label' => __(' Check to Silence SSL warnings', 'monero_gateway'),
|
'label' => __(' Check to Silence SSL warnings', 'monero_gateway'),
|
||||||
|
@ -312,7 +324,12 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||||
}
|
}
|
||||||
$uri = "monero:$address?amount=$amount?payment_id=$payment_id";
|
$uri = "monero:$address?amount=$amount?payment_id=$payment_id";
|
||||||
|
|
||||||
$this->verify_non_rpc($payment_id, $amount_xmr2, $order_id);
|
if($this->zero_confirm){
|
||||||
|
$this->verify_zero_conf($payment_id, $amount, $order_id);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$this->verify_non_rpc($payment_id, $amount_xmr2, $order_id);
|
||||||
|
}
|
||||||
if($this->confirmed == false)
|
if($this->confirmed == false)
|
||||||
{
|
{
|
||||||
echo "<h4> We are waiting for your transaction to be confirmed </h4>";
|
echo "<h4> We are waiting for your transaction to be confirmed </h4>";
|
||||||
|
@ -628,7 +645,7 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||||
if(isset($output_found))
|
if(isset($output_found))
|
||||||
{
|
{
|
||||||
$amount_atomic_units = $amount * 1000000000000;
|
$amount_atomic_units = $amount * 1000000000000;
|
||||||
if($txs_from_block[$block_index]['payment_id'] == $payment_id && $output_found >= $amount)
|
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);
|
$this->on_verified($payment_id, $amount_atomic_units, $order_id);
|
||||||
}
|
}
|
||||||
|
@ -637,6 +654,42 @@ class Monero_Gateway extends WC_Payment_Gateway
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function verify_zero_conf($payment_id, $amount, $order_id)
|
||||||
|
{
|
||||||
|
$tools = new NodeTools();
|
||||||
|
$txs_from_mempool = $tools->get_mempool_txs();;
|
||||||
|
$tx_count = count($txs_from_mempool['data']['txs']);
|
||||||
|
$i = 0;
|
||||||
|
$output_found;
|
||||||
|
|
||||||
|
while($i <= $tx_count)
|
||||||
|
{
|
||||||
|
$tx_hash = $txs_from_mempool['data']['txs'][$i]['tx_hash'];
|
||||||
|
if(strlen($txs_from_mempool['data']['txs'][$i]['payment_id']) != 0)
|
||||||
|
{
|
||||||
|
$result = $tools->check_tx($tx_hash, $this->address, $this->viewKey);
|
||||||
|
if($result)
|
||||||
|
{
|
||||||
|
$output_found = $result;
|
||||||
|
$tx_i = $i;
|
||||||
|
$i = $tx_count; // finish loop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
if(isset($output_found))
|
||||||
|
{
|
||||||
|
$amount_atomic_units = $amount * 1000000000000;
|
||||||
|
if($txs_from_mempool['data']['txs'][$tx_i]['payment_id'] == $payment_id && $output_found['amount'] >= $amount_atomic_units)
|
||||||
|
{
|
||||||
|
$this->on_verified($payment_id, $amount_atomic_units, $order_id);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public function do_ssl_check()
|
public function do_ssl_check()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue