Created
August 31, 2022 09:31
-
-
Save pavanjoshi914/b34487d1078cca99acfe98d53d833c12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// subscribe to the event | |
PubSub.subscribe("ln.sendPayment.success", persistMetadata); | |
// event definition | |
import db from "../db"; | |
const persistMetadata = async (_message, data) => { | |
const host = data.origin.host; | |
const allowance = await db.allowances | |
.where("host") | |
.equalsIgnoreCase(host) | |
.first(); | |
let metadata = data.metadata; | |
let metadataType; | |
let contentUrl; | |
if (data.metadata != undefined) { | |
metadata = JSON.parse(data.metadata); | |
metadataType = metadata.type; | |
contentUrl = metadata.contentUrl; | |
} | |
const paymentResponse = data.response; | |
await db.metadata.add({ | |
host: host, | |
paymentHash: paymentResponse.data.paymentHash, | |
metadata: metadata, | |
allowanceId: allowance?.id, | |
createdAt: Date.now(), | |
type: metadataType, | |
contentUrl: contentUrl | |
}); | |
await db.saveToStorage(); | |
console.info(`Persisted metadata ${metadata}`); | |
return true; | |
}; | |
export { persistMetadata }; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment