From 3e9b4acd4867bb6515a152f11507a739fea421f7 Mon Sep 17 00:00:00 2001 From: cryptochangements34 Date: Wed, 24 Jan 2018 16:35:49 -0600 Subject: [PATCH 1/3] add get_mempool_txs --- monero/library.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/monero/library.php b/monero/library.php index 774a6a1..a859f64 100644 --- a/monero/library.php +++ b/monero/library.php @@ -377,4 +377,18 @@ class NodeTools } + function get_mempool_txs() + { + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_URL => 'https://xmrchain.net/api/mempool', + )); + $resp = curl_exec($curl); + curl_close($curl); + $array = json_decode($resp, true); + return $array; + } + } From fa49096c1531419483de9be6468a85a7b8508838 Mon Sep 17 00:00:00 2001 From: cryptochangements34 Date: Wed, 24 Jan 2018 16:37:33 -0600 Subject: [PATCH 2/3] add optional 0-conf txs Add the option to search the mempool for unconfirmed transactions for quicker payments --- monero/include/monero_payments.php | 59 ++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/monero/include/monero_payments.php b/monero/include/monero_payments.php index 352caa1..ce8343f 100644 --- a/monero/include/monero_payments.php +++ b/monero/include/monero_payments.php @@ -13,6 +13,7 @@ class Monero_Gateway extends WC_Payment_Gateway private $confirmed = false; private $monero_daemon; private $non_rpc = false; + private $zero_cofirm = false; function __construct() { @@ -33,6 +34,7 @@ class Monero_Gateway extends WC_Payment_Gateway $this->address = $this->get_option('monero_address'); $this->viewKey = $this->get_option('viewKey'); $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_rpc = $this->get_option('use_rpc'); @@ -45,7 +47,10 @@ class Monero_Gateway extends WC_Payment_Gateway { $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: // $this->title = $this->get_option('title' ); $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'), '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( 'title' => __(' 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"; - $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) { echo "

We are waiting for your transaction to be confirmed

"; @@ -628,7 +645,7 @@ class Monero_Gateway extends WC_Payment_Gateway if(isset($output_found)) { $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); } @@ -637,6 +654,42 @@ class Monero_Gateway extends WC_Payment_Gateway } 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() { From 7259659dad0e7dddf0de69b3ca83772c87a00a1a Mon Sep 17 00:00:00 2001 From: cryptochangements34 Date: Wed, 24 Jan 2018 16:44:08 -0600 Subject: [PATCH 3/3] font colors --- monero/include/monero_payments.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monero/include/monero_payments.php b/monero/include/monero_payments.php index ce8343f..24a089c 100644 --- a/monero/include/monero_payments.php +++ b/monero/include/monero_payments.php @@ -332,11 +332,11 @@ class Monero_Gateway extends WC_Payment_Gateway } if($this->confirmed == false) { - echo "

We are waiting for your transaction to be confirmed

"; + echo "

We are waiting for your transaction to be confirmed

"; } if($this->confirmed) { - echo "

Your transaction has been successfully confirmed!

"; + echo "

Your transaction has been successfully confirmed!

"; } echo "