fix: processing gift wraps and notifications #193
@ -341,6 +341,12 @@ export const createWrap = (unsignedEvent: UnsignedEvent, receiver: string) => {
|
||||
// Check if the leading zero bits meet the required difficulty
|
||||
if (leadingZeroes >= difficulty) {
|
||||
// Finalize the event (sign it) and return the result
|
||||
console.log(
|
||||
'event OUT: ',
|
||||
unsignedEvent,
|
||||
' for this user ',
|
||||
hexToNpub(receiver)
|
||||
)
|
||||
return finalizeEvent(event, randomKey)
|
||||
}
|
||||
|
||||
@ -526,13 +532,18 @@ export const updateUsersAppData = async (meta: Meta) => {
|
||||
if (existingMeta.modifiedAt < meta.modifiedAt) {
|
||||
sigits[id] = meta
|
||||
isUpdated = true
|
||||
} else {
|
||||
console.log('event NEWER EXISTS', existingMeta, meta)
|
||||
}
|
||||
} else {
|
||||
sigits[id] = meta
|
||||
isUpdated = true
|
||||
}
|
||||
|
||||
if (!isUpdated) return null
|
||||
if (!isUpdated) {
|
||||
console.log('event NOT UPDATED', sigits[id], meta)
|
||||
return null
|
||||
}
|
||||
|
||||
const blossomUrls = [...appData.blossomUrls]
|
||||
|
||||
@ -869,12 +880,13 @@ const processReceivedEvent = async (event: Event, difficulty: number = 5) => {
|
||||
.processedGiftWraps
|
||||
if (processedEvents.includes(event.id)) return
|
||||
|
||||
store.dispatch(updateProcessedGiftWraps([...processedEvents, event.id]))
|
||||
|
||||
// validate PoW
|
||||
// Count the number of leading zero bits in the hash
|
||||
const leadingZeroes = countLeadingZeroes(event.id)
|
||||
if (leadingZeroes < difficulty) return
|
||||
if (leadingZeroes < difficulty) {
|
||||
console.log('processReceivedEvent leading zeroes error')
|
||||
return
|
||||
}
|
||||
|
||||
// decrypt the content of gift wrap event
|
||||
const nostrController = NostrController.getInstance()
|
||||
@ -882,7 +894,6 @@ const processReceivedEvent = async (event: Event, difficulty: number = 5) => {
|
||||
event.pubkey,
|
||||
event.content
|
||||
)
|
||||
|
||||
const internalUnsignedEvent = await parseJson<UnsignedEvent>(decrypted).catch(
|
||||
(err) => {
|
||||
console.log(
|
||||
@ -893,8 +904,21 @@ const processReceivedEvent = async (event: Event, difficulty: number = 5) => {
|
||||
}
|
||||
)
|
||||
|
||||
if (!internalUnsignedEvent || internalUnsignedEvent.kind !== 938) return
|
||||
if (!internalUnsignedEvent || internalUnsignedEvent.kind !== 938) {
|
||||
console.log(
|
||||
'processReceivedEvent missing internal unsigned event, or internal event not sigit kind'
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
console.log(
|
||||
'event IN: ',
|
||||
new Date(internalUnsignedEvent.created_at * 1000),
|
||||
internalUnsignedEvent.kind,
|
||||
internalUnsignedEvent.pubkey,
|
||||
hexToNpub(internalUnsignedEvent.pubkey),
|
||||
internalUnsignedEvent.content
|
||||
)
|
||||
const meta = await parseJson<Meta>(internalUnsignedEvent.content).catch(
|
||||
(err) => {
|
||||
console.log(
|
||||
@ -907,7 +931,8 @@ const processReceivedEvent = async (event: Event, difficulty: number = 5) => {
|
||||
|
||||
if (!meta) return
|
||||
|
||||
updateUsersAppData(meta)
|
||||
await updateUsersAppData(meta)
|
||||
store.dispatch(updateProcessedGiftWraps([...processedEvents, event.id]))
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user