-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from marcinx/main
Initial Release
- Loading branch information
Showing
8 changed files
with
452 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,65 @@ | ||
# sep6-client-php | ||
PHP based Stellar SEP-6 Client by COINQVEST | ||
# COINQVEST SEP-6 Client (PHP) | ||
|
||
This client communicates with COINQVEST's Stellar [SEP-6](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md) transfer server documented [here](https://www.coinqvest.com/en/sep6-docs). It lets you on- and off-ramp Bitcoin on the Stellar Network. This client is written in PHP but we also provide clients in [different programming languages](https://www.coinqvest.com/en/sep6-docs#clients). | ||
|
||
Read our [stellar.toml](https://www.coinqvest.com/.well-known/stellar.toml) to inspect available COINQVEST assets on the Stellar Network. At the time of writing we support wrapped Bitcoin and Litecoin. | ||
|
||
Requirements | ||
------------ | ||
* PHP >=5.3.0 | ||
* cURL extension for PHP | ||
* OpenSSL extension for PHP | ||
|
||
Installation as Drop-In | ||
----------------------- | ||
Copy the contents of `src` into the include path of your project. | ||
|
||
**Usage Client** | ||
```php | ||
include('SEP6Client.class.php'); | ||
$client = new SEP6Client(); | ||
``` | ||
|
||
## Examples | ||
|
||
**Deposit Bitcoin onto Stellar** | ||
```php | ||
$response = $client->get('/deposit', array( | ||
'asset_code' => 'BTC', | ||
'account' => 'GDONUHZKLSYLDOZWR2TDW25GFXOBWCCKTPK34DLUVSOMFHLGURX6FNU6', | ||
'memo' => 'Sent via SEP-6', | ||
'memo_type' => 'text' | ||
)); | ||
// $response->responseBody -> {"how":"bc1qj633nx575jm28smgcp3mx6n3gh0zg6ndr0ew23","id":"f2118ef4115642870638616a4372","eta":600,"min_amount":"0.00001","max_amount":"100.0000000","extra_info":{}} | ||
``` | ||
|
||
Returns a Bitcoin deposit address alongside some additional context information documented [here](https://www.coinqvest.com/en/sep6-docs#get-deposit). Bitcoin sent to the received deposit address is tokenized onto Stellar and sent to above account. The tokenized Bitcoin can be [sent and received](https://developers.stellar.org/docs/tutorials/send-and-receive-payments) on the Stellar Network, [exchanged](https://developers.stellar.org/docs/encyclopedia/path-payments) for other assets on the SDEX, or be deposited into Stellar's [liquidity pools](https://developers.stellar.org/docs/encyclopedia/liquidity-on-stellar-sdex-liquidity-pools). | ||
|
||
|
||
**Withdraw Bitcoin from Stellar** | ||
```php | ||
$response = $client->get('/withdraw', array( | ||
'asset_code' => 'BTC', | ||
'dest' => 'bc1qj633nx575jm28smgcp3mx6n3gh0zg6ndr0ew23' | ||
)); | ||
// $response->responseBody -> {"account_id":"GCQVEST7KIWV3KOSNDDUJKEPZLBFWKM7DUS4TCLW2VNVPCBGTDRVTEIT","memo_type":"text","memo":"010cdf0a41410d75b2797a6fa38f","id":"010cdf0a41410d75b2797a6fa38f","min_amount":"0.0005000","max_amount":"100.0000000","fee_fixed":0.0002,"fee_percent":0.2,"extra_info":{"message":"An amount above 100.0000000 will take longer to complete"}} | ||
``` | ||
|
||
Returns a Stellar account and memo alongside some additional context information documented [here](https://www.coinqvest.com/en/sep6-docs#get-withdraw). Tokenized Bitcoin sent to the given account is burned on the Stellar Network and released into the Bitcoin address given in the request. | ||
|
||
##Documentation | ||
|
||
Please inspect our [SEP-6 API docs](https://www.coinqvest.com/en/sep6-docs) or email us at service@coinqvest.com if you have questions. | ||
|
||
Support and Feedback | ||
-------------------- | ||
We'd love to hear your feedback. If you have specific problems or bugs with this SDK, please file an issue on GitHub. For general feedback and support requests please email service@coinqvest.com. | ||
|
||
Contributing | ||
------------ | ||
|
||
1. Fork it ( https://github.com/COINQVEST/sep6-client-php/fork ) | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create a new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/php | ||
<?php | ||
include('../src/SEP6Client.class.php'); | ||
|
||
$client = new SEP6Client( | ||
'sep6.coinqvest.com', | ||
'/tmp/coinqvest.log' // an optional log file location | ||
); | ||
|
||
$response = $client->get('/info'); | ||
|
||
echo "HTTP Status Code: " . $response->httpStatusCode . "\n\n"; | ||
echo "Response Body: " . $response->responseBody . "\n\n"; | ||
|
||
//$response = $client->get('/deposit', array( | ||
// 'asset_code' => 'BTC', | ||
// 'account' => 'GDONUHZKLSYLDOZWR2TDW25GFXOBWCCKTPK34DLUVSOMFHLGURX6FNU6', | ||
// 'memo' => 'Sent via SEP-6', | ||
// 'memo_type' => 'text' | ||
//)); | ||
// | ||
//echo "HTTP Status Code: " . $response->httpStatusCode . "\n\n"; | ||
//echo "Response Body: " . $response->responseBody . "\n\n"; | ||
|
||
//$response = $client->get('/withdraw', array( | ||
// 'asset_code' => 'BTC', | ||
// 'dest' => 'bc1qj633nx575jm28smgcp3mx6n3gh0zg6ndr0ew23' | ||
//)); | ||
// | ||
//echo "HTTP Status Code: " . $response->httpStatusCode . "\n\n"; | ||
//echo "Response Body: " . $response->responseBody . "\n\n"; | ||
|
||
|
||
# view response object structure: | ||
# print_r($response); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
<?php | ||
include('SEP6RESTClient.class.php'); | ||
include('SEP6RESTClientResponseObject.class.php'); | ||
include('SEP6LoggingService.class.php'); | ||
|
||
/** | ||
* Class SEP6Client | ||
* | ||
* PHP implementation of a Stellar SEP-6 REST client | ||
* see https://www.coinqvest.com/en/sep6-docs | ||
*/ | ||
class SEP6Client extends SEP6RESTClient { | ||
|
||
/** | ||
* COINQVEST's SEP-6 transfer server | ||
* @var string | ||
*/ | ||
var $transferServer = 'sep6.coinqvest.com'; | ||
|
||
/** | ||
* Used in the HTTP user agent (leave it as is) | ||
* | ||
* @var string | ||
*/ | ||
var $clientName = 'php-stellar-sep6-sdk'; | ||
|
||
/** | ||
* The current version of this SDK, used in the HTTP user agent (leave it as is) | ||
* | ||
* @var string | ||
*/ | ||
var $clientVersion = '1.0.0'; | ||
|
||
/** | ||
* Indicates whether requests and responses should be logged | ||
* This is automatically initialized by the constructor, see below. | ||
* | ||
* @var boolean | ||
*/ | ||
var $enableLogging = false; | ||
|
||
/** | ||
* Specifies the log file to which to write, if any. | ||
* This is initialized by the constructor, see below. | ||
* | ||
* @var string | ||
*/ | ||
var $logFile = null; | ||
|
||
/** | ||
* @param string $transferServer The SEP-6 transfer server | ||
* @param string $logFile Log file location, if any | ||
*/ | ||
public function __construct($transferServer = null, $logFile = null) { | ||
|
||
$this->transferServer = is_null($transferServer) ? $this->transferServer : $transferServer; | ||
|
||
if (!is_null($logFile)) { | ||
$this->logFile = $logFile; | ||
$this->enableLogging = true; | ||
} | ||
|
||
parent::__construct('https', $transferServer, ''); | ||
|
||
} | ||
|
||
/** | ||
* Use this method to communicate with GET endpoints | ||
* | ||
* @param string $endpoint | ||
* @param array $params, a list of GET parameters to be included in the request | ||
* @return SEP6RESTClientResponseObject | ||
*/ | ||
public function get($endpoint = '/', $params = array()) { | ||
|
||
$method = 'GET'; | ||
$response = parent::sendRequest($endpoint, $method, array(), false, $params, array(), $this->buildCustomOptions()); | ||
$this->log("[SEP6Client][get] Request: GET $endpoint Params: " . json_encode($params)); | ||
$this->log("[SEP6Client][get] Response: " . json_encode($response)); | ||
return $response; | ||
|
||
} | ||
|
||
/** | ||
* Use this method to communicate with POST endpoints | ||
* | ||
* @param string $endpoint | ||
* @param array $params, an array representing the JSON payload to include in this request | ||
* @return SEP6RESTClientResponseObject | ||
*/ | ||
public function post($endpoint = '/', $params = array()) { | ||
|
||
$method = 'POST'; | ||
$response = $this->sendRequest($endpoint, $method, $params, true, array(), array(), $this->buildCustomOptions()); | ||
$this->log("[SEP6Client][post] Request: GET $endpoint Params: " . json_encode($params)); | ||
$this->log("[SEP6Client][post] Response: " . json_encode($response)); | ||
return $response; | ||
} | ||
|
||
/** | ||
* Use this method to communicate with DELETE endpoints | ||
* | ||
* @param string $endpoint | ||
* @param array $params, an array representing the JSON payload to include in this request | ||
* @return SEP6RESTClientResponseObject | ||
*/ | ||
public function delete($endpoint = '/', $params = array()) { | ||
|
||
$method = 'DELETE'; | ||
$response = $this->sendRequest($endpoint, $method, $params, true, array(), array(), $this->buildCustomOptions()); | ||
$this->log("[SEP6Client][delete] Request: DELETE $endpoint Params: " . json_encode($params)); | ||
$this->log("[SEP6Client][delete] Response: " . json_encode($response)); | ||
return $response; | ||
|
||
} | ||
|
||
/** | ||
* Use this method to communicate with PUT endpoints | ||
* | ||
* @param string $endpoint | ||
* @param array $params, an array representing the JSON payload to include in this request | ||
* @return SEP6RESTClientResponseObject | ||
*/ | ||
public function put($endpoint = '/', $params = array()) { | ||
|
||
$method = 'PUT'; | ||
$response = $this->sendRequest($endpoint, $method, $params, true, array(), array(), $this->buildCustomOptions()); | ||
$this->log("[SEP6Client][put] Request: PUT $endpoint Params: " . json_encode($params)); | ||
$this->log("[SEP6Client][put] Response: " . json_encode($response)); | ||
return $response; | ||
|
||
} | ||
|
||
/** | ||
* Private class to automatically generate the user agent in the request | ||
* | ||
* @return array | ||
*/ | ||
private function buildCustomOptions() { | ||
|
||
return array(CURLOPT_USERAGENT => $this->clientName . ' ' . $this->clientVersion); | ||
|
||
} | ||
|
||
/** | ||
* Private class to optionally log API request and response | ||
* | ||
* @param $message | ||
*/ | ||
private function log($message) { | ||
|
||
if (!$this->enableLogging) { | ||
return; | ||
} | ||
|
||
SEP6LoggingService::write($message, $this->logFile); | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Class SEP6LoggingService | ||
* | ||
* A logging service | ||
*/ | ||
class SEP6LoggingService { | ||
|
||
/** | ||
* Writes to a log file and prepends current time stamp | ||
* | ||
* @param $message | ||
* @param $logFile | ||
*/ | ||
public static function write($message, $logFile) { | ||
|
||
$type = file_exists($logFile) ? 'a' : 'w'; | ||
$file = fopen($logFile, $type); | ||
if ($file === false) { | ||
return; | ||
} | ||
fputs($file, date('r', time()) . ' ' . $message . PHP_EOL); | ||
fclose($file); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.