bug: catch invalid invoice

This commit is contained in:
Kieran 2023-02-19 14:46:07 +00:00
parent 7a2ba299cb
commit f34e42701f
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
1 changed files with 9 additions and 4 deletions

View File

@ -27,12 +27,17 @@ function getInvoice(zap: TaggedRawEvent) {
console.debug("Invalid zap: ", zap);
return {};
}
const decoded = invoiceDecode(bolt11);
try {
const decoded = invoiceDecode(bolt11);
const amount = decoded.sections.find(section => section.name === "amount")?.value;
const hash = decoded.sections.find(section => section.name === "description_hash")?.value;
const amount = decoded.sections.find(section => section.name === "amount")?.value;
const hash = decoded.sections.find(section => section.name === "description_hash")?.value;
return { amount, hash: hash ? bytesToHex(hash as Uint8Array) : undefined };
return { amount, hash: hash ? bytesToHex(hash as Uint8Array) : undefined };
} catch {
// ignore
}
return {};
}
interface Zapper {