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

Commit 21a877b

Browse files
authored
Merge pull request #21 from habrauser/new_methods
Added new classes CreateWallet, ListWallets, LoadWallets
2 parents 19ea81c + 528b612 commit 21a877b

File tree

8 files changed

+195
-13
lines changed

8 files changed

+195
-13
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,58 @@ try {
6060
$response->getVersion();
6161
```
6262

63+
## Create new wallet
64+
65+
Create default wallet:
66+
```php
67+
$client = new \Electrum\Client('http://127.0.0.1', 7777, 0, 'user', 'password');
68+
$wallet = new \Electrum\Request\Method\Wallet\CreateWallet($client);
69+
$response = $wallet->execute();
70+
```
71+
72+
This code is similar to the command:
73+
```bash
74+
$ electrum create
75+
```
76+
77+
You can also create more wallets with custom names specifying flag of the new wallet.
78+
```php
79+
$client = new \Electrum\Client('http://127.0.0.1', 7777, 0, 'user', 'password');
80+
$wallet = new \Electrum\Request\Method\Wallet\CreateWallet($client);
81+
$response = $wallet->execute(['wallet_path' => '~/.electrum/wallets/your_wallet']);
82+
```
83+
84+
This code is similar to the command:
85+
```bash
86+
$ electrum create -w ~/.electrum/wallets/your_wallet
87+
```
88+
89+
Response will be:
90+
```php
91+
[
92+
'seed' => 'wallet seed',
93+
'path' => 'path where wallet file is stored',
94+
'msg' => 'Please keep your seed in a safe place; if you lose it, you will not be able to restore your wallet.',
95+
];
96+
```
97+
98+
## Load wallet
99+
100+
```php
101+
$client = new \Electrum\Client('http://127.0.0.1', 7777, 0, 'user', 'password');
102+
$load_wallet = new \Electrum\Request\Method\Wallet\LoadWallet($client);
103+
$load_wallet->execute(['wallet_path' => '~/.electrum/wallets/your_wallet']);
104+
````
105+
106+
## List wallets
107+
108+
Get list of all loaded wallets:
109+
```php
110+
$client = new \Electrum\Client('http://127.0.0.1', 7777, 0, 'user', 'password');
111+
$list_wallets = new \Electrum\Request\Method\Wallet\ListWallets($client);
112+
$list_wallets->execute();
113+
```
114+
63115
## Get new address
64116
```php
65117
$client = new \Electrum\Client('http://127.0.0.1', 7777, 0, 'user', 'password');
@@ -68,6 +120,15 @@ $response->getVersion();
68120
echo $tx->getAddress();
69121
```
70122

123+
## Create new address for wallet
124+
125+
```php
126+
$client = new \Electrum\Client('http://127.0.0.1', 7777, 0, 'user', 'password');
127+
$newAddress = new \Electrum\Request\Method\Address\CreateNewAddress($client);
128+
$newAddress->execute(['wallet' => '~/.electrum/wallets/your_wallet']);
129+
```
130+
131+
71132
## Make a new Payment
72133
```php
73134
$client = new \Electrum\Client('http://127.0.0.1', 7777, 0, 'user', 'password');
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
4+
namespace Electrum\Request\Method\Address;
5+
6+
7+
use Electrum\Request\AbstractMethod;
8+
use Electrum\Request\MethodInterface;
9+
10+
/**
11+
* Generating new address if you need more
12+
* @original_author Pascal Krason <[email protected]>
13+
*/
14+
class CreateNewAddress extends AbstractMethod implements MethodInterface
15+
{
16+
17+
/**
18+
* @var string
19+
*/
20+
private $method = 'createnewaddress';
21+
22+
/**
23+
* @param array $attributes
24+
* @return object
25+
* @throws \Electrum\Request\Exception\BadRequestException
26+
* @throws \Electrum\Response\Exception\ElectrumResponseException
27+
*/
28+
public function execute(array $attributes = [])
29+
{
30+
return $this->getClient()->execute($this->method, $attributes);
31+
}
32+
}

src/Request/Method/Payment/AddRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ class AddRequest extends AbstractMethod implements MethodInterface
1717
/**
1818
* @var string
1919
*/
20-
private $method = 'addrequest';
20+
private $method = 'add_request';
2121

2222
/**
2323
* Bitcoin amount to request
24-
* @var int
24+
* @var float
2525
*/
2626
private $amount = 0;
2727

@@ -64,15 +64,15 @@ public function setMethod($method)
6464
}
6565

6666
/**
67-
* @return int
67+
* @return float
6868
*/
6969
public function getAmount()
7070
{
7171
return $this->amount;
7272
}
7373

7474
/**
75-
* @param int $amount
75+
* @param float $amount
7676
*
7777
* @return AddRequest
7878
*/

src/Request/Method/Payment/Broadcast.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Electrum\Request\AbstractMethod;
66
use Electrum\Request\MethodInterface;
7-
use Electrum\Response\Exception\ElectrumResponseException;
7+
use Electrum\Response\Model\Payment\PaymentRequest;
88

99
/**
1010
* Return a payment request.
@@ -26,8 +26,7 @@ class Broadcast extends AbstractMethod implements MethodInterface
2626

2727
/**
2828
* @param array $optional
29-
*
30-
* @return PaymentRequestResponse|null
29+
* @return mixed
3130
* @throws \Electrum\Request\Exception\BadRequestException
3231
* @throws \Electrum\Response\Exception\ElectrumResponseException
3332
*/

src/Request/Method/Payment/PayTo.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,16 @@ class PayTo extends AbstractMethod implements MethodInterface
3131

3232
/**
3333
* @param array $optional
34-
*
35-
* @return PaymentRequestResponse|null
34+
* @return mixed
35+
* @throws ElectrumResponseException
3636
* @throws \Electrum\Request\Exception\BadRequestException
37-
* @throws \Electrum\Response\Exception\ElectrumResponseException
3837
*/
3938
public function execute(array $optional = [])
4039
{
41-
$data = $this->getClient()->execute($this->method, array_merge([
40+
return $this->getClient()->execute($this->method, array_merge([
4241
'destination' => $this->getDestination(),
4342
'amount' => $this->getAmount()
4443
], $optional));
45-
46-
return $data['hex'];
4744
}
4845

4946
/**
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Electrum\Request\Method\Wallet;
4+
5+
use Electrum\Request\AbstractMethod;
6+
use Electrum\Request\MethodInterface;
7+
8+
/**
9+
* Return newly created wallet
10+
* @original_author Pascal Krason <[email protected]>
11+
*/
12+
class CreateWallet extends AbstractMethod implements MethodInterface
13+
{
14+
15+
/**
16+
* @var string
17+
*/
18+
private $method = 'create';
19+
20+
/**
21+
* @param array $attributes
22+
* @return object
23+
* @throws \Electrum\Request\Exception\BadRequestException
24+
* @throws \Electrum\Response\Exception\ElectrumResponseException
25+
*/
26+
public function execute(array $attributes = [])
27+
{
28+
return $this->getClient()->execute($this->method, $attributes);
29+
}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
4+
namespace Electrum\Request\Method\Wallet;
5+
6+
7+
use Electrum\Request\AbstractMethod;
8+
use Electrum\Request\MethodInterface;
9+
10+
/**
11+
* Return all loaded wallets
12+
* @original_author Pascal Krason <[email protected]>
13+
*/
14+
class ListWallets extends AbstractMethod implements MethodInterface
15+
{
16+
17+
/**
18+
* @var string
19+
*/
20+
private $method = 'list_wallets';
21+
22+
/**
23+
* @return object
24+
* @throws \Electrum\Request\Exception\BadRequestException
25+
* @throws \Electrum\Response\Exception\ElectrumResponseException
26+
*/
27+
public function execute()
28+
{
29+
return $this->getClient()->execute($this->method);
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
4+
namespace Electrum\Request\Method\Wallet;
5+
6+
7+
use Electrum\Request\AbstractMethod;
8+
use Electrum\Request\MethodInterface;
9+
10+
/**
11+
* Load wallet
12+
* @original_author Pascal Krason <[email protected]>
13+
*/
14+
class LoadWallet extends AbstractMethod implements MethodInterface
15+
{
16+
17+
/**
18+
* @var string
19+
*/
20+
private $method = 'load_wallet';
21+
22+
/**
23+
* @param array $attributes
24+
* @return object
25+
* @throws \Electrum\Request\Exception\BadRequestException
26+
* @throws \Electrum\Response\Exception\ElectrumResponseException
27+
*/
28+
public function execute(array $attributes = [])
29+
{
30+
return $this->getClient()->execute($this->method, $attributes);
31+
}
32+
}

0 commit comments

Comments
 (0)