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