Skip to content

Commit

Permalink
Wiring up SubscribeCustomMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamkmr04 committed Mar 28, 2024
1 parent 796d59b commit 005837f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 3 deletions.
4 changes: 3 additions & 1 deletion backends/EmbeddedLND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const {
getNetworkInfo,
queryRoutes,
lookupInvoice,
sendCustomMessage
sendCustomMessage,
subscribeCustomMessages
} = lndMobile.index;
const {
channelBalance,
Expand Down Expand Up @@ -52,6 +53,7 @@ export default class EmbeddedLND extends LND {
);
sendCustomMessage = async (data: any) =>
await sendCustomMessage(data.peer, data.type, data.data);
subscribeCustomMessages = async () => await subscribeCustomMessages();
getMyNodeInfo = async () => await getInfo();
getNetworkInfo = async () => await getNetworkInfo();
getInvoices = async () => await listInvoices();
Expand Down
2 changes: 2 additions & 0 deletions backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ export default class LND {
type: data.type,
data: data.data
});
subscribeCustomMessages = () =>
this.getRequest('/v1/custommessage/subscribe');
getMyNodeInfo = () => this.getRequest('/v1/getinfo');
getInvoices = (data: any) =>
this.getRequest(
Expand Down
6 changes: 6 additions & 0 deletions backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ export default class LightningNodeConnect {
data: data.data
})
.then((data: lnrpc.SendCustomMessageResponse) => snakeize(data));
subscribeCustomMessages = async () =>
await this.lnc.lnd.lightning
.subscribeCustomMessages({})
.then((data: lnrpc.custommessage) => {
snakeize(data);
});
getMyNodeInfo = async () =>
await this.lnc.lnd.lightning
.getInfo({})
Expand Down
1 change: 1 addition & 0 deletions ios/LndMobile/Lnd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ open class Lnd {
"InvoicesCancelInvoice": { bytes, cb in LndmobileInvoicesCancelInvoice(bytes, cb) },
"ConnectPeer": { bytes, cb in LndmobileConnectPeer(bytes, cb) },
"SendCustomMessage": { bytes, cb in LndmobileSendCustomMessage(bytes, cb) },
"SubscribeCustomMessages": { bytes, cb in LndmobileSubscribeCustomMessages(bytes, cb) },
"DecodePayReq": { bytes, cb in LndmobileDecodePayReq(bytes, cb) },
"DescribeGraph": { bytes, cb in LndmobileDescribeGraph(bytes, cb) },
"GetInfo": { bytes, cb in LndmobileGetInfo(bytes, cb) },
Expand Down
7 changes: 5 additions & 2 deletions lndmobile/LndMobileInjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import {
listInvoices,
subscribeChannelGraph,
sendKeysendPaymentV2,
sendCustomMessage
sendCustomMessage,
subscribeCustomMessages
} from './index';
import {
channelBalance,
Expand Down Expand Up @@ -229,6 +230,7 @@ export interface ILndMobileInjections {
type: number | null;
data: Uint8Array | null;
}) => Promise<lnrpc.SendCustomMessageResponse>;
subscribeCustomMessages: () => Promise<lnrpc.CustomMessage>;
};
channel: {
channelBalance: () => Promise<lnrpc.ChannelBalanceResponse>;
Expand Down Expand Up @@ -393,7 +395,8 @@ export default {
listInvoices,
subscribeChannelGraph,
sendKeysendPaymentV2,
sendCustomMessage
sendCustomMessage,
subscribeCustomMessages
},
channel: {
channelBalance,
Expand Down
18 changes: 18 additions & 0 deletions lndmobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,24 @@ export const sendCustomMessage = async (
});
};

/**
* @throws
*/
export const subscribeCustomMessages =
async (): Promise<lnrpc.CustomMessage> => {
const response = await sendCommand<
lnrpc.ISubscribeCustomMessagesRequest,
lnrpc.SubscribeCustomMessagesRequest,
lnrpc.CustomMessage
>({
request: lnrpc.SubscribeCustomMessagesRequest,
response: lnrpc.CustomMessage,
method: 'SubscribeCustomMessages',
options: {}
});
return response;
};

/**
* @throws
*/
Expand Down
2 changes: 2 additions & 0 deletions utils/BackendUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class BackendUtils {
sendCoins = (...args: any[]) => this.call('sendCoins', args);
sendCustomMessage = (...args: any[]) =>
this.call('sendCustomMessage', args);
subscribeCustomMessages = (...args: any[]) =>
this.call('subscribeCustomMessages', args);
getMyNodeInfo = (...args: any[]) => this.call('getMyNodeInfo', args);
getNetworkInfo = (...args: any[]) => this.call('getNetworkInfo', args);
getInvoices = (...args: any[]) => this.call('getInvoices', args);
Expand Down

0 comments on commit 005837f

Please sign in to comment.