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

Commit 180e215

Browse files
author
Pascal Krason
committed
Merge branch 'master' into develop
2 parents 8ff438a + 2ecf426 commit 180e215

9 files changed

Lines changed: 342 additions & 21 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace Electrum\Request\Method\Payment;
4+
5+
use Electrum\Request\AbstractMethod;
6+
use Electrum\Request\MethodInterface;
7+
use Electrum\Response\Exception\ElectrumResponseException;
8+
9+
/**
10+
* Return a payment request.
11+
* @author Pascal Krason <p.krason@padr.io>
12+
*/
13+
class Broadcast extends AbstractMethod implements MethodInterface
14+
{
15+
16+
/**
17+
* @var string
18+
*/
19+
private $method = 'broadcast';
20+
21+
/**
22+
* @var string
23+
* Serialized transaction (hexadecimal)
24+
*/
25+
private $transaction = '';
26+
27+
/**
28+
* @param array $optional
29+
*
30+
* @return PaymentRequestResponse|null
31+
* @throws \Electrum\Request\Exception\BadRequestException
32+
* @throws \Electrum\Response\Exception\ElectrumResponseException
33+
*/
34+
public function execute(array $optional = [])
35+
{
36+
$data = $this->getClient()->execute($this->method, array_merge([
37+
'tx' => $this->getTransaction()
38+
], $optional));
39+
40+
return isset($data[1]) ? $data[1] : null;
41+
}
42+
43+
/**
44+
* Get the value of Transaction
45+
*
46+
* @return string
47+
*/
48+
public function getTransaction()
49+
{
50+
return $this->transaction;
51+
}
52+
53+
/**
54+
* Set the value of Transaction
55+
*
56+
* @param string transaction
57+
*
58+
* @return self
59+
*/
60+
public function setTransaction($transaction)
61+
{
62+
$this->transaction = $transaction;
63+
64+
return $this;
65+
}
66+
67+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
namespace Electrum\Request\Method\Payment;
4+
5+
use Electrum\Request\AbstractMethod;
6+
use Electrum\Request\MethodInterface;
7+
use Electrum\Response\Exception\ElectrumResponseException;
8+
9+
/**
10+
* Return a payment request.
11+
* @author Pascal Krason <p.krason@padr.io>
12+
*/
13+
class PayTo extends AbstractMethod implements MethodInterface
14+
{
15+
16+
/**
17+
* @var string
18+
*/
19+
private $method = 'payto';
20+
21+
/**
22+
* @var string
23+
* '!' for maximum available
24+
*/
25+
private $amount = '!';
26+
27+
/**
28+
* @var string
29+
*/
30+
private $destination = '';
31+
32+
/**
33+
* @param array $optional
34+
*
35+
* @return PaymentRequestResponse|null
36+
* @throws \Electrum\Request\Exception\BadRequestException
37+
* @throws \Electrum\Response\Exception\ElectrumResponseException
38+
*/
39+
public function execute(array $optional = [])
40+
{
41+
$data = $this->getClient()->execute($this->method, array_merge([
42+
'destination' => $this->getDestination(),
43+
'amount' => $this->getAmount()
44+
], $optional));
45+
46+
return $data['hex'];
47+
}
48+
49+
/**
50+
* Get the value of Amount
51+
*
52+
* @return string
53+
*/
54+
public function getAmount()
55+
{
56+
return $this->amount;
57+
}
58+
59+
/**
60+
* Set the value of Amount
61+
*
62+
* @param string amount
63+
*
64+
* @return self
65+
*/
66+
public function setAmount($amount)
67+
{
68+
$this->amount = $amount;
69+
70+
return $this;
71+
}
72+
73+
/**
74+
* Get the value of Destination
75+
*
76+
* @return string
77+
*/
78+
public function getDestination()
79+
{
80+
return $this->destination;
81+
}
82+
83+
/**
84+
* Set the value of Destination
85+
*
86+
* @param string destination
87+
*
88+
* @return self
89+
*/
90+
public function setDestination($destination)
91+
{
92+
$this->destination = $destination;
93+
94+
return $this;
95+
}
96+
97+
}

src/Request/Method/Wallet/GetBalance.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Electrum\Request\Method;
3+
namespace Electrum\Request\Method\Wallet;
44

55
use Electrum\Request\AbstractMethod;
66
use Electrum\Request\MethodInterface;
@@ -30,4 +30,4 @@ public function execute(array $optional = [])
3030
$data = $this->getClient()->execute($this->method, $optional);
3131
return $this->hydrate(new BalanceResponse(), $data);
3232
}
33-
}
33+
}

src/Request/Method/Wallet/GetHistory.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace Electrum\Request\Method;
3+
namespace Electrum\Request\Method\Wallet;
44

55
use Electrum\Request\AbstractMethod;
66
use Electrum\Request\MethodInterface;
7-
use Electrum\Response\Model\Wallet\History as HistoryResponse;
7+
use Electrum\Response\Model\Wallet\Transaction;
88

99
/**
1010
* Wallet history. Returns the transaction history of your wallet.
@@ -28,6 +28,10 @@ class GetHistory extends AbstractMethod implements MethodInterface
2828
public function execute(array $optional = [])
2929
{
3030
$data = $this->getClient()->execute($this->method, $optional);
31-
return $this->hydrate(new HistoryResponse(), $data);
31+
$transactions = [];
32+
foreach ($data as $transaction) {
33+
$transactions[] = $this->hydrate(new Transaction(), $transaction);
34+
}
35+
return $transactions;
3236
}
33-
}
37+
}

src/Response/Hydrator/Payment/PaymentRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function __construct()
2323
'URI' => 'uri',
2424
'exp' => 'expires',
2525
'time' => 'time',
26+
'confirmations' => 'confirmations',
2627
]);
2728

2829
$this->setNamingStrategy($namingStrategy);

src/Response/Model/Payment/PaymentRequest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ class PaymentRequest implements ResponseInterface
7171
*/
7272
private $time = 0;
7373

74+
/**
75+
* @var int
76+
*/
77+
private $confirmations = null;
78+
7479
/**
7580
* Factory method
7681
*
@@ -246,4 +251,24 @@ public function setTime($time)
246251
return $this;
247252
}
248253

254+
/**
255+
* @return int
256+
*/
257+
public function getConfirmations()
258+
{
259+
return $this->confirmations;
260+
}
261+
262+
/**
263+
* @param int $confirmations
264+
*
265+
* @return PaymentRequest
266+
*/
267+
public function setConfirmations($confirmations)
268+
{
269+
$this->confirmations = $confirmations;
270+
271+
return $this;
272+
}
273+
249274
}

src/Response/Model/Wallet/History.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)