chore: add comments
This commit is contained in:
parent
1eed099059
commit
5c36554b66
@ -171,6 +171,7 @@ export class MetadataController {
|
||||
|
||||
const relays: string[] = []
|
||||
|
||||
// find user's relays
|
||||
if (relaySet.write.length > 0) {
|
||||
relays.push(...relaySet.write)
|
||||
} else {
|
||||
@ -188,19 +189,25 @@ export class MetadataController {
|
||||
|
||||
if (relays.length === 0) return null
|
||||
|
||||
// filter for finding user's first kind 1 event
|
||||
const eventFilter: Filter = {
|
||||
kinds: [kinds.ShortTextNote],
|
||||
authors: [hexKey]
|
||||
}
|
||||
|
||||
const pool = new SimplePool()
|
||||
|
||||
// find user's kind 1 events published on user's relays
|
||||
const events = await pool.querySync(relays, eventFilter)
|
||||
if (events && events.length) {
|
||||
// sort events by created_at time in ascending order
|
||||
events.sort((a, b) => a.created_at - b.created_at)
|
||||
|
||||
// get first ever event published on user's relays
|
||||
const event = events[0]
|
||||
const { created_at } = event
|
||||
|
||||
// initialize job request
|
||||
const jobEventTemplate: EventTemplate = {
|
||||
content: '',
|
||||
created_at: Math.round(Date.now() / 1000),
|
||||
@ -211,6 +218,7 @@ export class MetadataController {
|
||||
]
|
||||
}
|
||||
|
||||
// sign job request event
|
||||
const jobSignedEvent = await this.nostrController.signEvent(
|
||||
jobEventTemplate
|
||||
)
|
||||
@ -221,6 +229,7 @@ export class MetadataController {
|
||||
'wss://relayable.org'
|
||||
]
|
||||
|
||||
// publish job request
|
||||
await this.nostrController.publishEvent(jobSignedEvent, relays)
|
||||
|
||||
console.log('jobSignedEvent :>> ', jobSignedEvent)
|
||||
@ -254,12 +263,14 @@ export class MetadataController {
|
||||
|
||||
await dvmNDK.connect(2000)
|
||||
|
||||
// filter for getting DVM job's result
|
||||
const sub = dvmNDK.subscribe({
|
||||
kinds: [68002 as number],
|
||||
'#e': [jobSignedEvent.id],
|
||||
'#p': [jobSignedEvent.pubkey]
|
||||
})
|
||||
|
||||
// asynchronously get block number from dvm job with 10 seconds timeout
|
||||
const dvmJobResult = await subscribeWithTimeout(sub, 10000)
|
||||
|
||||
return parseInt(dvmJobResult)
|
||||
|
Loading…
Reference in New Issue
Block a user