bug: catch invalid zaps (missing tag)

This commit is contained in:
Kieran 2023-02-16 21:53:44 +00:00
parent 7c6c944c82
commit b11ab51ba8
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
1 changed files with 6 additions and 0 deletions

View File

@ -23,6 +23,10 @@ function findTag(e: TaggedRawEvent, tag: string) {
function getInvoice(zap: TaggedRawEvent) {
const bolt11 = findTag(zap, "bolt11");
if (!bolt11) {
console.debug("Invalid zap: ", zap);
return {};
}
const decoded = invoiceDecode(bolt11);
const amount = decoded.sections.find(section => section.name === "amount")?.value;
@ -66,6 +70,7 @@ export interface ParsedZap {
content: string;
zapper?: HexKey;
valid: boolean;
zapService: HexKey;
}
export function parseZap(zap: TaggedRawEvent): ParsedZap {
@ -81,6 +86,7 @@ export function parseZap(zap: TaggedRawEvent): ParsedZap {
zapper: zapper.pubkey,
content: zap.content,
valid: zapper.isValid,
zapService: zap.pubkey,
};
}