Skip to content
This repository was archived by the owner on Sep 4, 2021. It is now read-only.

Commit 8d72678

Browse files
authored
Merge pull request #3 from Padrio/develop
Version 1.0 is finally there
2 parents 1490de1 + c802346 commit 8d72678

35 files changed

Lines changed: 1733 additions & 400 deletions

.gitignore

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
/src/.idea
2-
/Vagrantfile
3-
/.vagrant
4-
1+
# Composer
52
/vendor/
3+
composer.lock
4+
5+
# IDE
6+
/.idea
7+
8+
# For testing purposes
9+
example.php
10+
test.php
11+
12+
# Thanks macOS
13+
.DS_Store

README.md

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# php-electrum-api - Electrum library with no dependencies
1+
# php-electrum-api - Electrum library
22
```
33
Licence: GPL-3.0
44
Author: Pascal Krason <p.krason@padr.io>
5-
Language: PHP 5.6
5+
Language: PHP 5.6-7.1
66
```
7-
Please note, this library is by far not completed and production ready, there are still a lot methods which aren't neither tested or even implemented.
7+
Please note, this library is by far not completed and but can be used in production. Until now i only implemented the most commonly used API-Calls. If you think im missing something, just create an issue or fork the project.
88

99
# Setting up Electrum
1010
First you need to setup a new Electrum wallet. Follow the instructions according to your OS at the [Electrum Download Page](https://electrum.org/#download). After the successfull installation you need to set a rpcport by typing:
@@ -19,9 +19,13 @@ Now we can go ahead and start Electrum in daemon mode:
1919
```
2020
electrum daemon start
2121
```
22+
Since some new version electrum wants you to load your wallet by hand on startup:
23+
```
24+
electrum daemon load_wallet
25+
```
2226

2327
# Requirements
24-
On the PHP side there are not much requirements, you only need atleast PHP 5.6 and the curl-Extension installed. Optional you need [Composer](http://getcomposer.org) to install this library.
28+
On the PHP side there are not much requirements, you only need at least PHP 5.6 and the curl-Extension installed. Then you can go ahead ans it through [Composer](http://getcomposer.org) which will do everything else for you.
2529

2630
# Install
2731
First you need to install [Composer](https://getcomposer.org/doc/00-intro.md), after you accomplished this you can go ahead:
@@ -32,8 +36,56 @@ Then you can simply include the autoloader and begin using the library:
3236
```php
3337
// Include composer autoloader
3438
require_once 'vendor/autoloader.php';
39+
```
40+
41+
# Examples
42+
43+
## Basic example
44+
A very basic useage example. Every API-Call has it's own request-object. You simply create one and execute it.
45+
```php
46+
47+
$method = new \Electrum\Request\Method\Version();
48+
49+
try {
50+
$response = $method->execute();
51+
} catch(\Exception $exception) {
52+
die($exception->getMessage());
53+
}
3554

36-
// Create new instance
37-
$electrum = new \Electrum\Client('http://127.0.0.1/', 7777);
38-
$electrum->getVersion();
55+
$response->getVersion();
3956
```
57+
58+
## Custom Client Configuration
59+
Every Request/Method takes a `Electrum\Client`-instance as parameter which replaces the default one. A custom instance can be usefull if you want to set custom config params like another Hostname or Port.
60+
```php
61+
$client = new \Electrum\Client('http://127.0.0.1', 7777);
62+
$method = new \Electrum\Request\Method\Version($client);
63+
64+
try {
65+
$response = $method->execute();
66+
} catch (\Exception $exception) {
67+
die($exception->getMessage());
68+
}
69+
70+
$response->getVersion();
71+
```
72+
73+
## Advanced exception handling
74+
Dealing with exceptions is easy. You can catch two types of exceptions which indicates whether it's an Request or Response fault.
75+
```php
76+
$method = new \Electrum\Request\Method\Version();
77+
78+
try {
79+
$response = $method->execute();
80+
} catch (\Electrum\Request\Exception\BadRequestException $exception) {
81+
die(sprintf(
82+
'Failed to send request: %s',
83+
$exception->getMessage()
84+
));
85+
} catch(\Electrum\Response\Exception\ElectrumResponseException $exception) {
86+
die(sprintf(
87+
'Electrum-Client failed to respond correctly: %s',
88+
$exception->getMessage()
89+
));
90+
}
91+
```

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"email": "p.krason@padr.io"
1111
}
1212
],
13-
"require": {},
13+
"require": {
14+
"zendframework/zend-hydrator": "^2.2"
15+
},
1416
"autoload": {
1517
"psr-4": {
1618
"Electrum\\": "src"

0 commit comments

Comments
 (0)