Skip to content

Commit

Permalink
Merge pull request #2097 from shubhamkmr04/shubham/wiring-up-endpoints
Browse files Browse the repository at this point in the history
LSPS1 client
  • Loading branch information
kaloudis authored May 24, 2024
2 parents 3ffe334 + e3d1363 commit d367ffb
Show file tree
Hide file tree
Showing 30 changed files with 3,254 additions and 31 deletions.
24 changes: 24 additions & 0 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ import LspExplanationWrappedInvoices from './views/Explanations/LspExplanationWr
import LspExplanationOverview from './views/Explanations/LspExplanationOverview';
import RestoreChannelBackups from './views/Settings/EmbeddedNode/RestoreChannelBackups';

// LSPS1
import LSPS1 from './views/Settings/LSPS1/index';
import LSPS1Settings from './views/Settings/LSPS1/Settings';
import OrdersPane from './views/Settings/LSPS1/OrdersPane';
import Orders from './views/Settings/LSPS1/Order';

import RawTxHex from './views/RawTxHex';

import CustodialWalletWarning from './views/Settings/CustodialWalletWarning';
Expand Down Expand Up @@ -785,6 +791,24 @@ export default class App extends React.PureComponent {
name="TxHex"
component={TxHex}
/>
<Stack.Screen
name="LSPS1"
component={LSPS1}
/>
<Stack.Screen
name="LSPS1Settings"
component={
LSPS1Settings
}
/>
<Stack.Screen
name="OrdersPane"
component={OrdersPane}
/>
<Stack.Screen
name="LSPS1Order"
component={Orders}
/>
</Stack.Navigator>
</NavigationContainer>
</>
Expand Down
26 changes: 26 additions & 0 deletions assets/images/SVG/OlympusAnimated.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/images/SVG/order-list.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions backends/CLightningREST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,6 @@ export default class CLightningREST extends LND {
supportsOnchainBatching = () => false;
supportsChannelBatching = () => false;
isLNDBased = () => false;
supportsLSPS1customMessage = () => false;
supportsLSPS1rest = () => true;
}
2 changes: 2 additions & 0 deletions backends/Eclair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ export default class Eclair {
supportsOnchainBatching = () => false;
supportsChannelBatching = () => false;
isLNDBased = () => false;
supportsLSPS1customMessage = () => false;
supportsLSPS1rest = () => true;
}

const mapInvoice =
Expand Down
9 changes: 8 additions & 1 deletion backends/EmbeddedLND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const {
getNetworkInfo,
queryRoutes,
lookupInvoice,
fundingStateStep
fundingStateStep,
sendCustomMessage,
subscribeCustomMessages
} = lndMobile.index;
const {
channelBalance,
Expand Down Expand Up @@ -68,6 +70,9 @@ export default class EmbeddedLND extends LND {
data.spend_unconfirmed,
data.send_all
);
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 Expand Up @@ -290,4 +295,6 @@ export default class EmbeddedLND extends LND {
supportsOnchainBatching = () => true;
supportsChannelBatching = () => true;
isLNDBased = () => true;
supportsLSPS1customMessage = () => true;
supportsLSPS1rest = () => false;
}
53 changes: 53 additions & 0 deletions backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,57 @@ export default class LND {
spend_unconfirmed: data.spend_unconfirmed,
send_all: data.send_all
});
sendCustomMessage = (data: any) =>
this.postRequest('/v1/custommessage', {
peer: Base64Utils.hexToBase64(data.peer),
type: data.type,
data: Base64Utils.hexToBase64(data.data)
});
subscribeCustomMessages = (onResponse: any, onError: any) => {
const route = '/v1/custommessage/subscribe';
const method = 'GET';

const { host, lndhubUrl, port, macaroonHex, accessToken } =
stores.settingsStore;

const auth = macaroonHex || accessToken;
const headers: any = this.getHeaders(auth, true);
const methodRoute = `${route}?method=${method}`;
const url = this.getURL(host || lndhubUrl, port, methodRoute, true);

const ws: any = new WebSocket(url, null, {
headers
});

ws.addEventListener('open', () => {
// connection opened
console.log('subscribeCustomMessages ws open');
ws.send(JSON.stringify({}));
});

ws.addEventListener('message', (e: any) => {
// a message was received
const data = JSON.parse(e.data);
console.log('subscribeCustomMessagews message', data);
if (data.error) {
onError(data.error);
} else {
onResponse(data);
}
});

ws.addEventListener('error', (e: any) => {
// an error occurred
console.log('subscribeCustomMessages ws err', e);
const certWarning = localeString('backends.LND.wsReq.warning');
onError(e.message ? `${certWarning} (${e.message})` : certWarning);
});

ws.addEventListener('close', () => {
// ws closed
console.log('subscribeCustomMessages ws close');
});
};
getMyNodeInfo = () => this.getRequest('/v1/getinfo');
getInvoices = (data: any) =>
this.getRequest(
Expand Down Expand Up @@ -617,4 +668,6 @@ export default class LND {
supportsOnchainBatching = () => true;
supportsChannelBatching = () => true;
isLNDBased = () => true;
supportsLSPS1customMessage = () => true;
supportsLSPS1rest = () => false;
}
12 changes: 12 additions & 0 deletions backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ export default class LightningNodeConnect {
send_all: data.send_all
})
.then((data: lnrpc.SendCoinsResponse) => snakeize(data));
sendCustomMessage = async (data: any) =>
await this.lnc.lnd.lightning
.sendCustomMessage({
peer: Base64Utils.hexToBase64(data.peer),
type: data.type,
data: Base64Utils.hexToBase64(data.data)
})
.then((data: lnrpc.SendCustomMessageResponse) => snakeize(data));
subscribeCustomMessages = () =>
this.lnc.lnd.lightning.subscribeCustomMessages({});
getMyNodeInfo = async () =>
await this.lnc.lnd.lightning
.getInfo({})
Expand Down Expand Up @@ -477,4 +487,6 @@ export default class LightningNodeConnect {
supportsOnchainBatching = () => true;
supportsChannelBatching = () => true;
isLNDBased = () => true;
supportsLSPS1customMessage = () => true;
supportsLSPS1rest = () => false;
}
2 changes: 2 additions & 0 deletions backends/LndHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,6 @@ export default class LndHub extends LND {
supportsOnchainBatching = () => false;
supportsChannelBatching = () => true;
isLNDBased = () => false;
supportsLSPS1customMessage = () => false;
supportsLSPS1rest = () => false;
}
2 changes: 2 additions & 0 deletions backends/Spark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,6 @@ export default class Spark {
supportsOnchainBatching = () => false;
supportsChannelBatching = () => true;
isLNDBased = () => false;
supportsLSPS1customMessage = () => false;
supportsLSPS1rest = () => true;
}
Loading

0 comments on commit d367ffb

Please sign in to comment.