Skip to content

Commit d82f875

Browse files
committed
Use available gateways instead of list_gateways
1 parent 207f269 commit d82f875

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

.changeset/shaky-books-cut.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fedimint/core': patch
3+
---
4+
5+
Added select_available_gateay rpc and use it for payments instead of list_gateways

packages/core/src/services/LightningService.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,21 @@ export class LightningService {
7777
)
7878
}
7979

80-
private async _getDefaultGatewayInfo() {
80+
async getAvailableGateway(gateway?: LightningGateway, invoice?: string) {
81+
return await this.client.rpcSingle<LightningGateway | null>(
82+
'ln',
83+
'select_available_gateway',
84+
{
85+
maybe_gateway: gateway ?? null,
86+
maybe_invoice: invoice ?? null,
87+
},
88+
)
89+
}
90+
91+
private async _getDefaultGatewayInfo(invoice?: string) {
8192
await this.updateGatewayCache()
82-
const gateways = await this.listGateways()
83-
return gateways[0]?.info
93+
const gateway = await this.getAvailableGateway(undefined, invoice)
94+
return gateway?.info
8495
}
8596

8697
/** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
@@ -89,7 +100,7 @@ export class LightningService {
89100
gatewayInfo?: GatewayInfo,
90101
extraMeta?: JSONObject,
91102
) {
92-
const gateway = gatewayInfo ?? (await this._getDefaultGatewayInfo())
103+
const gateway = gatewayInfo ?? (await this._getDefaultGatewayInfo(invoice))
93104
return await this.client.rpcSingle<OutgoingLightningPayment>(
94105
'ln',
95106
'pay_bolt11_invoice',

0 commit comments

Comments
 (0)