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