diff --git a/.phpintel/32c6f488fc8c1d890e4049723f7f9c65 b/.phpintel/32c6f488fc8c1d890e4049723f7f9c65 new file mode 100644 index 0000000..febb345 Binary files /dev/null and b/.phpintel/32c6f488fc8c1d890e4049723f7f9c65 differ diff --git a/.phpintel/aac47fb228a9bf1f11a06b8e48cababc b/.phpintel/aac47fb228a9bf1f11a06b8e48cababc new file mode 100644 index 0000000..482c0e3 Binary files /dev/null and b/.phpintel/aac47fb228a9bf1f11a06b8e48cababc differ diff --git a/.phpintel/index b/.phpintel/index new file mode 100644 index 0000000..4a5e2a6 Binary files /dev/null and b/.phpintel/index differ diff --git a/README.md b/README.md index cb36f5f..d4c4c32 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,20 @@ $block_io = new BlockIo($apiKey, $pin, $version); echo "Confirmed Balance: " . $block_io->get_balance()->data->available_balance . "\n"; ``` +Socks5 proxy configure. + +```php +$proxy = 'socks5://user:password@localhost:12345'; +$apiKey = "YOUR API KEY FOR DOGECOIN, BITCOIN, OR LITECOIN"; +$pin = "YOUR SECRET PIN"; +$version = 2; // the API version to use + +$block_io = new BlockIo($apiKey, $pin, $version, $proxy); + +echo "Confirmed Balance: " . $block_io->get_balance()->data->available_balance . "\n"; + +``` + The wrapper abstracts all methods listed at https://block.io/api/php using the same interface names. For example, to get your current account balance: ```php diff --git a/composer.json b/composer.json index 970523a..6eef5ce 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "block_io-php/block_io-php", + "name": "paramah/block_io-php", "license": "MIT", "description": "Block.io is the easiest way to create wallets, send, and accept payments through Bitcoin, Litecoin, and Dogecoin. This is its PHP library.", "keywords": ["block.io", "dogecoin", "bitcoin", "litecoin", "block_io"], diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7b2d4d0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: "3.3" + +services: + + blockio: + image: paramah/php:7.2 + volumes: + - .:/var/www + + diff --git a/examples/socks5proxy.php b/examples/socks5proxy.php new file mode 100644 index 0000000..714e05b --- /dev/null +++ b/examples/socks5proxy.php @@ -0,0 +1,57 @@ +get_transactions(array('addresses' => $toAddress, 'type' => 'received')); + $paymentReceived = "0.0"; // using strings for high precision monetary stuff + +// print_r($txs); + + $txs = $txs->data->txs; + + // iterate over all transactions, check their confidence + foreach($txs as $tx) { + foreach($tx->amounts_received as $amountReceived) + { + if ($amountReceived->recipient == $toAddress) { + print "Amount: " . $amountReceived->amount . " Confidence: " . $tx->confidence . "\n"; + + if ($tx->confidence > $confidenceThreshold) { + $paymentReceived = bcadd($amountReceived->amount, $paymentReceived, 8); + } + } + } + } + + if (bccomp($paymentReceived,$paymentExpected,8) >= 0) { + print "Payment confirmed: " . $paymentReceived . "\n"; + break; + } else { + sleep(1); // sleep for one second and try again + } + +} + +?> diff --git a/lib/block_io.php b/lib/block_io.php index 98d9db2..42276c3 100644 --- a/lib/block_io.php +++ b/lib/block_io.php @@ -27,13 +27,18 @@ class BlockIo private $version; private $withdrawal_methods; private $sweep_methods; + private $proxy = null; - public function __construct($api_key, $pin, $api_version = 2) + public function __construct($api_key, $pin, $api_version = 2, $proxy = null) { // the constructor $this->api_key = $api_key; $this->pin = $pin; $this->version = $api_version; + if(null !== $proxy) { + $this->proxy = $proxy; + } + $this->withdrawal_methods = array("withdraw", "withdraw_from_user", "withdraw_from_users", "withdraw_from_label", "withdraw_from_labels", "withdraw_from_address", "withdraw_from_addresses"); $this->sweep_methods = array("sweep_from_address"); @@ -82,17 +87,21 @@ private function _request($path, $args = array(), $method = 'POST') $addedData .= $pkey . "=" . $pval; } - // Initiate cURL and set headers/options - $ch = curl_init(); - - // If we run windows, make sure the needed pem file is used - if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - $pemfile = dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR . 'cacert.pem'; - if(!file_exists($pemfile)) { - throw new Exception("Needed .pem file not found. Please download the .pem file at http://curl.haxx.se/ca/cacert.pem and save it as " . $pemfile); - } - curl_setopt($ch, CURLOPT_CAINFO, $pemfile); - } + // Initiate cURL and set headers/options + $ch = curl_init(); + + // If we run windows, make sure the needed pem file is used + if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + $pemfile = dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR . 'cacert.pem'; + if(!file_exists($pemfile)) { + throw new Exception("Needed .pem file not found. Please download the .pem file at http://curl.haxx.se/ca/cacert.pem and save it as " . $pemfile); + } + curl_setopt($ch, CURLOPT_CAINFO, $pemfile); + } + + if(null !== $this->proxy) { + curl_setopt($ch, CURLOPT_PROXY, $this->proxy); + } // it's a GET method if ($method == 'GET') { $url .= '&' . $addedData; }