Skip to content

Commit dd0f814

Browse files
authored
Merge pull request #33 from lightninglabs/subscription-requests
api: do not convert subscription requests to GRPC objects
2 parents 21e726b + 115e1d6 commit dd0f814

File tree

4 files changed

+24
-62
lines changed

4 files changed

+24
-62
lines changed

lib/api/lnd/index.ts

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import * as LND from '../../types/generated/lightning_pb';
2-
import * as InvoicesRPC from '../../types/generated/invoicesrpc/invoices_pb';
3-
import * as RouterRPC from '../../types/generated/routerrpc/router_pb';
42

53
import { Lightning } from '../../types/generated/lightning_pb_service';
64
import { WalletUnlocker } from '../../types/generated/walletunlocker_pb_service';
@@ -58,11 +56,9 @@ class LndApi extends BaseApi<LndEvents> {
5856
callback: (data: any) => void,
5957
errCallback?: (data: any) => void
6058
): void => {
61-
const req = new InvoicesRPC.SubscribeSingleInvoiceRequest();
62-
if (request.r_hash) req.setRHash(request.r_hash);
6359
this.subscribe(
6460
Invoices.SubscribeSingleInvoice,
65-
req,
61+
request,
6662
callback,
6763
errCallback
6864
);
@@ -75,34 +71,9 @@ class LndApi extends BaseApi<LndEvents> {
7571
callback: (data: any) => void,
7672
errCallback?: (data: any) => void
7773
): void => {
78-
const chanPoint = new LND.ChannelPoint();
79-
if (
80-
request.channel_point &&
81-
request.channel_point.funding_txid_str
82-
)
83-
chanPoint.setFundingTxidStr(
84-
request.channel_point.funding_txid_str
85-
);
86-
if (
87-
request.channel_point &&
88-
request.channel_point.funding_txid_bytes
89-
)
90-
chanPoint.setFundingTxidBytes(
91-
request.channel_point.funding_txid_bytes
92-
);
93-
chanPoint.setOutputIndex(request.channel_point.output_index);
94-
95-
const req = new LND.CloseChannelRequest();
96-
req.setChannelPoint(chanPoint);
97-
if (request.force) req.setForce(true);
98-
if (request.target_conf) req.setTargetConf(request.target_conf);
99-
if (request.delivery_address)
100-
req.setDeliveryAddress(request.delivery_address);
101-
if (request.sat_per_vbyte)
102-
req.setSatPerVbyte(request.sat_per_vbyte);
10374
this.subscribe(
10475
Lightning.CloseChannel,
105-
req,
76+
request,
10677
callback,
10778
errCallback
10879
);
@@ -114,7 +85,7 @@ class LndApi extends BaseApi<LndEvents> {
11485
): void => {
11586
this.subscribe(
11687
Lightning.SubscribeChannelBackups,
117-
new LND.ChannelBackupSubscription(),
88+
request,
11889
callback,
11990
errCallback
12091
);
@@ -126,7 +97,7 @@ class LndApi extends BaseApi<LndEvents> {
12697
): void => {
12798
this.subscribe(
12899
Lightning.SubscribeChannelEvents,
129-
new LND.ChannelEventSubscription(),
100+
request,
130101
callback,
131102
errCallback
132103
);
@@ -138,7 +109,7 @@ class LndApi extends BaseApi<LndEvents> {
138109
): void => {
139110
this.subscribe(
140111
Lightning.SubscribeChannelGraph,
141-
new LND.GraphTopologySubscription(),
112+
request,
142113
callback,
143114
errCallback
144115
);
@@ -150,7 +121,7 @@ class LndApi extends BaseApi<LndEvents> {
150121
): void => {
151122
this.subscribe(
152123
Lightning.SubscribeCustomMessages,
153-
new LND.SubscribeCustomMessagesRequest(),
124+
request,
154125
callback,
155126
errCallback
156127
);
@@ -160,13 +131,9 @@ class LndApi extends BaseApi<LndEvents> {
160131
callback: (data: any) => void,
161132
errCallback?: (data: any) => void
162133
): void => {
163-
const req = new LND.InvoiceSubscription();
164-
if (request.add_index) req.setAddIndex(request.add_index);
165-
if (request.settle_index)
166-
req.setSettleIndex(request.settle_index);
167134
this.subscribe(
168135
Lightning.SubscribeInvoices,
169-
req,
136+
request,
170137
callback,
171138
errCallback
172139
);
@@ -178,7 +145,7 @@ class LndApi extends BaseApi<LndEvents> {
178145
): void => {
179146
this.subscribe(
180147
Lightning.SubscribePeerEvents,
181-
new LND.PeerEventSubscription(),
148+
request,
182149
callback,
183150
errCallback
184151
);
@@ -188,14 +155,9 @@ class LndApi extends BaseApi<LndEvents> {
188155
callback: (data: any) => void,
189156
errCallback?: (data: any) => void
190157
): void => {
191-
const req = new LND.GetTransactionsRequest();
192-
if (request.start_height)
193-
req.setStartHeight(request.start_height);
194-
if (request.end_height) req.setEndHeight(request.end_height);
195-
if (request.account) req.setAccount(request.account);
196158
this.subscribe(
197159
Lightning.SubscribeTransactions,
198-
req,
160+
request,
199161
callback,
200162
errCallback
201163
);
@@ -208,10 +170,9 @@ class LndApi extends BaseApi<LndEvents> {
208170
callback: (data: any) => void,
209171
errCallback?: (data: any) => void
210172
): void => {
211-
const req = new RouterRPC.SubscribeHtlcEventsRequest();
212173
this.subscribe(
213174
Router.SubscribeHtlcEvents,
214-
req,
175+
request,
215176
callback,
216177
errCallback
217178
);
@@ -236,19 +197,17 @@ class LndApi extends BaseApi<LndEvents> {
236197
connectStreams() {
237198
this.subscribe(
238199
Lightning.SubscribeTransactions,
239-
new LND.GetTransactionsRequest(),
200+
{},
240201
(transaction: any) =>
241202
this.emit('transaction', transaction.toObject())
242203
);
243204
this.subscribe(
244205
Lightning.SubscribeChannelEvents,
245-
new LND.ChannelEventSubscription(),
206+
{},
246207
(channelEvent: any) => this.emit('channel', channelEvent.toObject())
247208
);
248-
this.subscribe(
249-
Lightning.SubscribeInvoices,
250-
new LND.InvoiceSubscription(),
251-
(invoiceEvent: any) => this.emit('invoice', invoiceEvent.toObject())
209+
this.subscribe(Lightning.SubscribeInvoices, {}, (invoiceEvent: any) =>
210+
this.emit('invoice', invoiceEvent.toObject())
252211
);
253212
}
254213

lib/api/loop/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ class LoopApi extends BaseApi<LoopEvents> {
3333
callback: (data: any) => void,
3434
errCallback?: (data: any) => void
3535
): void => {
36-
const req = new LOOP.MonitorRequest();
37-
this.subscribe(SwapClient.Monitor, req, callback, errCallback);
36+
this.subscribe(
37+
SwapClient.Monitor,
38+
request,
39+
callback,
40+
errCallback
41+
);
3842
}
3943
};
4044

@@ -48,7 +52,7 @@ class LoopApi extends BaseApi<LoopEvents> {
4852
connectStreams() {
4953
this.subscribe(
5054
SwapClient.Monitor,
51-
new LOOP.MonitorRequest(),
55+
{},
5256
(swapStatus: any) => this.emit('status', swapStatus.toObject())
5357
);
5458
}

lib/api/pool/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ class PoolApi extends BaseApi<PoolEvents> {
3737
callback: (data: any) => void,
3838
errCallback?: (data: any) => void
3939
): void => {
40-
const req = new HASHMAIL.CipherBoxDesc();
41-
this.subscribe(HashMail.RecvStream, req, callback, errCallback);
40+
this.subscribe(HashMail.RecvStream, request, callback, errCallback);
4241
}
4342
};
4443

lib/lnc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ export default class LNC {
265265
onError?: (res: Error) => void
266266
) {
267267
const method = `${methodDescriptor.service.serviceName}.${methodDescriptor.methodName}`;
268-
log.debug(`${method} request`, request.toObject());
269-
const hackedReq = this.hackRequest(request.toObject());
268+
log.debug(`${method} request`, request);
269+
const hackedReq = this.hackRequest(request || {});
270270
log.debug(`${method} hacked request`, hackedReq);
271271
const reqJSON = JSON.stringify(hackedReq);
272272
this.wasm.wasmClientInvokeRPC(method, reqJSON, (response: string) => {

0 commit comments

Comments
 (0)