Skip to content

Commit

Permalink
⚡ Manage nostr-bot certify with lightning address via phoenixd getln…
Browse files Browse the repository at this point in the history
…address #1580
  • Loading branch information
ithiame committed Nov 5, 2024
1 parent 227cb0e commit c77e0ab
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/lib/server/phoenixd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ export async function phoenixdBalance(): Promise<{ balanceSat: number; feeCredit
return await res.json();
}

export async function phoenixdLndAddress(): Promise<string> {
const res = await fetch(`${runtimeConfig.phoenixd.url}/getlnaddress`, {
headers: {
Authorization: `Basic ${Buffer.from(`:${runtimeConfig.phoenixd.password}`).toString(
'base64'
)}`
}
});

return await res.text();
}

export async function phoenixdDetected(url?: string): Promise<boolean> {
return await Promise.race<boolean>([
fetch(`${url || runtimeConfig.phoenixd.url}/getinfo`).then(
Expand Down
3 changes: 2 additions & 1 deletion src/lib/server/runtime-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ const baseConfig = {
phoenixd: {
url: 'http://localhost:9740',
enabled: false,
password: ''
password: '',
lndAddress: ''
},
productActionSettings: {
eShop: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export const actions = {
display_name: runtimeConfig.brandName,
website: ORIGIN,
...(lnAddress && { lud16: `ln@${domainName}` }),
...(!lnAddress &&
runtimeConfig.phoenixd.lndAddress && { lud16: runtimeConfig.phoenixd.lndAddress }),
// about: '',
...(runtimeConfig.logo && { picture: pictureUrl }),
nip05: `_@${domainName}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
phoenixdBalance,
phoenixdDetected,
phoenixdInfo,
phoenixdLndAddress,
phoenixdPayInvoice,
phoenixdSendOnChain
} from '$lib/server/phoenixd.js';
Expand Down Expand Up @@ -76,6 +77,7 @@ export const actions = {
.parse(Object.fromEntries(await event.request.formData()));

runtimeConfig.phoenixd.password = parsed.password;
runtimeConfig.phoenixd.lndAddress = await phoenixdLndAddress();

await collections.runtimeConfig.updateOne(
{ _id: 'phoenixd' },
Expand Down

0 comments on commit c77e0ab

Please sign in to comment.