Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple proxy settings #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .phpintel/32c6f488fc8c1d890e4049723f7f9c65
Binary file not shown.
Binary file added .phpintel/aac47fb228a9bf1f11a06b8e48cababc
Binary file not shown.
Binary file added .phpintel/index
Binary file not shown.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.3"

services:

blockio:
image: paramah/php:7.2
volumes:
- .:/var/www


57 changes: 57 additions & 0 deletions examples/socks5proxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
require_once '../lib/block_io.php';

/* Parse command line arguments */
parse_str(implode('&', array_slice($argv, 1)), $_GET);

/* Our account's credentials for Bitcoin Testnet */
$apiKey = 'YOUR API KEY';
$pin = 'notNeeded';
$version = 2; // the API version
$proxy = 'socks5://user:password@localhost:12345';

$block_io = new BlockIo($apiKey, $pin, $version, $proxy);

$toAddress = $_GET['to_address'];
$paymentExpected = strval($_GET['amount']);
$confidenceThreshold = floatval($_GET['min_confidence']);

print "Monitoring Address for Payments: " . $toAddress . "\n";
print "Amount Expected: " . $paymentExpected . "\n";

/* Look for a new incoming transaction, and let us know when done.
Assumption: The $toAddress is new, and does not have previously received transactions */

while (true) {
// Keep checking for a new transaction, end when there is at least one transaction and its confidence has reached 0.90.
$txs = $block_io->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
}

}

?>
33 changes: 21 additions & 12 deletions lib/block_io.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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; }
Expand Down