1717use LightningSale \LndClient \Model \ChannelGraph ;
1818use LightningSale \LndClient \Model \GetInfoResponse ;
1919use LightningSale \LndClient \Model \CloseStatusUpdate ;
20- use LightningSale \LndClient \Model \SendResponse ;
2120use LightningSale \LndClient \Model \PendingChannelResponse ;
2221use LightningSale \LndClient \Model \ChannelPoint ;
22+ use LightningSale \LndClient \Model \SendCoinsResponse ;
2323use LightningSale \LndClient \Model \Transaction ;
2424use LightningSale \LndClient \Model \WalletBalanceResponse ;
2525use Psr \Log \LoggerInterface ;
@@ -44,43 +44,44 @@ public function __construct(\GuzzleHttp\Client $client, LoggerInterface $logger)
4444 private function post (string $ uri , $ json ): array
4545 {
4646 try {
47- $ tmpData = json_encode ( $ json) ;
47+ $ tmpData = $ json ;
4848 if (isset ($ tmpData ['password ' ]))
49- $ tmpData ['password ' ] = "*** PASSWORD *** " ;
50- $ this ->logger ->debug ("LndClient Request (post) " , [
49+ $ tmpData ['password ' ] = '*** PASSWORD *** ' ;
50+
51+ $ this ->logger ->debug ('LndClient Request (post) ' , [
5152 'uri ' => $ uri ,
5253 'json ' => $ tmpData
5354 ]);
5455 $ response = $ this ->httpClient ->post ($ uri , ['json ' => $ json ]);
5556 $ body = \GuzzleHttp \json_decode ($ response ->getBody (), true );
5657 return $ body ;
5758 } catch (BadResponseException $ exception ) {
58- $ this ->logger ->critical (" LndClient Error " , ['exception ' => $ exception ]);
59+ $ this ->logger ->critical (' LndClient Error ' , ['exception ' => $ exception ]);
5960 throw LndException::fromGuzzle ($ exception );
6061 }
6162 }
6263
6364 private function get (string $ uri , array $ queryParams = []): array
6465 {
6566 try {
66- $ this ->logger ->info (" LndClient Request (Get) " , ['uri ' => $ uri ]);
67+ $ this ->logger ->info (' LndClient Request (Get) ' , ['uri ' => $ uri ]);
6768 $ response = $ this ->httpClient ->get ($ uri , ['query ' => $ queryParams ]);
6869 $ body = \GuzzleHttp \json_decode ($ response ->getBody (), true );
6970 return $ body ;
7071 } catch (BadResponseException $ exception ) {
71- $ this ->logger ->critical (" LndClient Error " , ['exception ' => $ exception ]);
72+ $ this ->logger ->critical (' LndClient Error ' , ['exception ' => $ exception ]);
7273 throw LndException::fromGuzzle ($ exception );
7374 }
7475 }
7576
7677 private function delete (string $ uri , array $ queryParams = []){
7778 try {
78- $ this ->logger ->info (" LndClient Request (Delete) " , ['uri ' => $ uri ]);
79+ $ this ->logger ->info (' LndClient Request (Delete) ' , ['uri ' => $ uri ]);
7980 $ response = $ this ->httpClient ->delete ($ uri ,['query ' => $ queryParams ]);
8081 $ body = \GuzzleHttp \json_decode ($ response ->getBody (), true );
8182 return $ body ;
8283 } catch (BadResponseException $ exception ) {
83- $ this ->logger ->critical (" LndClient Error " , ['exception ' => $ exception ]);
84+ $ this ->logger ->critical (' LndClient Error ' , ['exception ' => $ exception ]);
8485 throw LndException::fromGuzzle ($ exception );
8586 }
8687 }
@@ -144,7 +145,7 @@ public function openChannel(string $nodePubkey, string $amount, string $pushSat
144145 return ChannelPoint::fromResponse ($ body );
145146 }
146147
147- public function closeChannel (string $ fundingTxid , string $ outputIndex , bool $ force = false , ? int $ targetConf = 5 ,? int $ satPrByte = null ): CloseStatusUpdate
148+ public function closeChannel (string $ fundingTxid , string $ outputIndex , ? bool $ force = false , ? int $ targetConf = 5 ,? int $ satPrByte = null ): CloseStatusUpdate
148149 {
149150 $ url = '/v1/channels/{funding_txid}/{output_index} ' ;
150151 $ url = str_replace ('{funding_txid} ' , urlencode ($ fundingTxid ), $ url );
@@ -154,7 +155,7 @@ public function closeChannel(string $fundingTxid, string $outputIndex, bool $for
154155 if ($ force ) $ query ['force ' ] = $ force ;
155156 if ($ targetConf && !$ satPrByte ) $ query ['target_conf ' ] = $ targetConf ;
156157 if (!$ targetConf && $ satPrByte ) $ query ['sat_per_byte ' ] = $ satPrByte ;
157- if ($ targetConf && $ satPrByte ) throw new LndException ("You must specify either 'targetConf' or 'satPrByte', not both! " );
158+ if ($ targetConf && $ satPrByte ) throw new LndException ("You must specify either 'targetConf' or 'satPrByte', not both! " , LndException:: INVALID_PARAMETER_TARGET_CONF );
158159
159160 $ body = $ this ->delete ($ url , $ query );
160161 return CloseStatusUpdate::fromResponse ($ body );
@@ -247,17 +248,13 @@ public function addInvoice(string $memo, string $value, $expiry = 3600): AddInvo
247248 /** @return Invoice[] */
248249 public function listInvoices (bool $ pendingOnly = false ): array
249250 {
250- $ url = '/v1/invoices/{pending_only} ' ;
251- $ url = str_replace ('{pending_only} ' , $ pendingOnly ? 'true ' : 'false ' , $ url );
252-
253- $ body = $ this ->get ($ url );
251+ $ body = $ this ->get ('/v1/invoices ' , ['pending_only ' => $ pendingOnly ]);
254252 return array_map (function ($ f ) {return Invoice::fromResponse ($ f );}, $ body ['invoices ' ] ?? []);
255253 }
256254
257- public function lookupInvoice (string $ rHashStr ): Invoice
255+ public function lookupInvoice (string $ rHash ): Invoice
258256 {
259- $ url = '/v1/invoices/{r_hash_str} ' ;
260- $ url = str_replace ('{r_hash_str} ' , urlencode ($ rHashStr ), $ url );
257+ $ url = '/v1/invoice/ ' . base64_encode ($ rHash );
261258
262259 $ body = $ this ->get ($ url );
263260 return Invoice::fromResponse ($ body );
0 commit comments