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

Commit 2ecf426

Browse files
authored
Merge pull request #6 from zorn-v/upstream
Some fixes and new requests
2 parents 21ffd4e + ef76acf commit 2ecf426

7 files changed

Lines changed: 316 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/Model/Wallet/History.php

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
namespace Electrum\Response\Model\Wallet;
4+
5+
use Electrum\Response\ResponseInterface;
6+
7+
/**
8+
* @author zorn-v
9+
*/
10+
class Transaction implements ResponseInterface
11+
{
12+
/**
13+
* @var array
14+
*/
15+
private $input_addresses;
16+
17+
/**
18+
* @var array
19+
*/
20+
private $output_addresses;
21+
22+
/**
23+
* @var string
24+
*/
25+
private $date;
26+
27+
/**
28+
* @var int
29+
*/
30+
private $timestamp;
31+
32+
/**
33+
* @var string
34+
*/
35+
private $value;
36+
37+
/**
38+
* @var string
39+
*/
40+
private $txid;
41+
42+
/**
43+
* @var string
44+
*/
45+
private $label;
46+
47+
/**
48+
* @var int
49+
*/
50+
private $confirmations;
51+
52+
53+
/**
54+
* Get the value of Input Addresses
55+
*
56+
* @return array
57+
*/
58+
public function getInputAddresses()
59+
{
60+
return $this->input_addresses;
61+
}
62+
63+
/**
64+
* Get the value of Output Addresses
65+
*
66+
* @return array
67+
*/
68+
public function getOutputAddresses()
69+
{
70+
return $this->output_addresses;
71+
}
72+
73+
/**
74+
* Get the value of Date
75+
*
76+
* @return string
77+
*/
78+
public function getDate()
79+
{
80+
return $this->date;
81+
}
82+
83+
/**
84+
* Get the value of Timestamp
85+
*
86+
* @return int
87+
*/
88+
public function getTimestamp()
89+
{
90+
return $this->timestamp;
91+
}
92+
93+
/**
94+
* Get the value of Value
95+
*
96+
* @return string
97+
*/
98+
public function getValue()
99+
{
100+
return $this->value;
101+
}
102+
103+
/**
104+
* Get the value of Tx Id
105+
*
106+
* @return string
107+
*/
108+
public function getTxId()
109+
{
110+
return $this->txid;
111+
}
112+
113+
/**
114+
* Get the value of Label
115+
*
116+
* @return string
117+
*/
118+
public function getLabel()
119+
{
120+
return $this->label;
121+
}
122+
123+
/**
124+
* Get the value of Confirmations
125+
*
126+
* @return int
127+
*/
128+
public function getConfirmations()
129+
{
130+
return $this->confirmations;
131+
}
132+
133+
}

src/Response/Traits/Balance.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,12 @@ public function setUnconfirmed($unconfirmed)
5757

5858
return $this;
5959
}
60-
}
60+
61+
/**
62+
* @return float
63+
*/
64+
public function getTotal()
65+
{
66+
return $this->confirmed + $this->unconfirmed;
67+
}
68+
}

0 commit comments

Comments
 (0)