Merge remote-tracking branch 'origin/main' into gossip-model

This commit is contained in:
2023-06-13 10:05:53 +01:00
40 changed files with 604 additions and 151 deletions

View File

@ -325,6 +325,7 @@ export interface InvoiceDetails {
descriptionHash?: string;
paymentHash?: string;
expired: boolean;
pr: string;
}
export function decodeInvoice(pr: string): InvoiceDetails | undefined {
@ -343,6 +344,7 @@ export function decodeInvoice(pr: string): InvoiceDetails | undefined {
const descriptionHashSection = parsed.sections.find(a => a.name === "description_hash")?.value;
const paymentHashSection = parsed.sections.find(a => a.name === "payment_hash")?.value;
const ret = {
pr,
amount: amount,
expire: timestamp && expire ? timestamp + expire : undefined,
timestamp: timestamp,
@ -510,3 +512,15 @@ export function sanitizeRelayUrl(url: string) {
// ignore
}
}
export function kvToObject<T>(o: string, sep?: string) {
return Object.fromEntries(
o.split(sep ?? ",").map(v => {
const match = v.trim().match(/^(\w+)="(.*)"$/);
if (match) {
return [match[1], match[2]];
}
return [];
})
) as T;
}