@bsv/overlay 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/cjs/package.json +2 -2
  2. package/dist/cjs/src/Engine.js +249 -220
  3. package/dist/cjs/src/Engine.js.map +1 -1
  4. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  5. package/dist/esm/src/Engine.js +245 -216
  6. package/dist/esm/src/Engine.js.map +1 -1
  7. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  8. package/dist/types/src/Engine.d.ts.map +1 -1
  9. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  10. package/docs/API.md +2 -2
  11. package/package.json +2 -2
  12. package/src/Engine.ts +243 -218
  13. package/dist/cjs/src/AdmittanceInstructions.js +0 -3
  14. package/dist/cjs/src/AdmittanceInstructions.js.map +0 -1
  15. package/dist/cjs/src/LookupAnswer.js +0 -3
  16. package/dist/cjs/src/LookupAnswer.js.map +0 -1
  17. package/dist/cjs/src/LookupQuestion.js +0 -3
  18. package/dist/cjs/src/LookupQuestion.js.map +0 -1
  19. package/dist/cjs/src/SHIPAdvertisement.js +0 -3
  20. package/dist/cjs/src/SHIPAdvertisement.js.map +0 -1
  21. package/dist/cjs/src/SLAPAdvertisement.js +0 -3
  22. package/dist/cjs/src/SLAPAdvertisement.js.map +0 -1
  23. package/dist/cjs/src/STEAK.js +0 -3
  24. package/dist/cjs/src/STEAK.js.map +0 -1
  25. package/dist/cjs/src/TaggedBEEF.js +0 -3
  26. package/dist/cjs/src/TaggedBEEF.js.map +0 -1
  27. package/dist/esm/src/AdmittanceInstructions.js +0 -2
  28. package/dist/esm/src/AdmittanceInstructions.js.map +0 -1
  29. package/dist/esm/src/LookupAnswer.js +0 -2
  30. package/dist/esm/src/LookupAnswer.js.map +0 -1
  31. package/dist/esm/src/LookupQuestion.js +0 -2
  32. package/dist/esm/src/LookupQuestion.js.map +0 -1
  33. package/dist/esm/src/SHIPAdvertisement.js +0 -2
  34. package/dist/esm/src/SHIPAdvertisement.js.map +0 -1
  35. package/dist/esm/src/SLAPAdvertisement.js +0 -2
  36. package/dist/esm/src/SLAPAdvertisement.js.map +0 -1
  37. package/dist/esm/src/STEAK.js +0 -2
  38. package/dist/esm/src/STEAK.js.map +0 -1
  39. package/dist/esm/src/TaggedBEEF.js +0 -2
  40. package/dist/esm/src/TaggedBEEF.js.map +0 -1
  41. package/dist/types/src/AdmittanceInstructions.d.ts +0 -14
  42. package/dist/types/src/AdmittanceInstructions.d.ts.map +0 -1
  43. package/dist/types/src/LookupAnswer.d.ts +0 -15
  44. package/dist/types/src/LookupAnswer.d.ts.map +0 -1
  45. package/dist/types/src/LookupQuestion.d.ts +0 -15
  46. package/dist/types/src/LookupQuestion.d.ts.map +0 -1
  47. package/dist/types/src/SHIPAdvertisement.d.ts +0 -9
  48. package/dist/types/src/SHIPAdvertisement.d.ts.map +0 -1
  49. package/dist/types/src/SLAPAdvertisement.d.ts +0 -9
  50. package/dist/types/src/SLAPAdvertisement.d.ts.map +0 -1
  51. package/dist/types/src/STEAK.d.ts +0 -10
  52. package/dist/types/src/STEAK.d.ts.map +0 -1
  53. package/dist/types/src/TaggedBEEF.d.ts +0 -11
  54. package/dist/types/src/TaggedBEEF.d.ts.map +0 -1
package/src/Engine.ts CHANGED
@@ -151,124 +151,132 @@ export class Engine {
151
151
 
152
152
  const steak: STEAK = {}
153
153
  const dupeTopics = new Set<string>()
154
+ const failedTopics = new Set<string>()
154
155
 
155
156
  // Parallelize the topic processing
156
- const topicPromises = taggedBEEF.topics.map(async topic => {
157
- if (this.managers[topic] === undefined || this.managers[topic] === null) {
158
- throw new Error(`This server does not support this topic: ${topic}`)
159
- }
157
+ const topicPromises = taggedBEEF.topics.map(async (topic) => {
158
+ try {
159
+ if (this.managers[topic] === undefined || this.managers[topic] === null) {
160
+ throw new Error(`This server does not support this topic: ${topic}`)
161
+ }
160
162
 
161
- // Check for duplicate transactions
162
- this.startTime(`dupCheck_${txid.substring(0, 10)}`)
163
- const dupeCheck = await this.storage.doesAppliedTransactionExist({ txid, topic })
164
- this.endTime(`dupCheck_${txid.substring(0, 10)}`)
163
+ // Check for duplicate transactions
164
+ this.startTime(`dupCheck_${txid.substring(0, 10)}`)
165
+ const dupeCheck = await this.storage.doesAppliedTransactionExist({ txid, topic })
166
+ this.endTime(`dupCheck_${txid.substring(0, 10)}`)
165
167
 
166
- if (dupeCheck) {
167
- dupeTopics.add(topic)
168
- steak[topic] = { outputsToAdmit: [], coinsToRetain: [] }
169
- return
170
- }
168
+ if (dupeCheck) {
169
+ dupeTopics.add(topic)
170
+ steak[topic] = { outputsToAdmit: [], coinsToRetain: [] }
171
+ return
172
+ }
171
173
 
172
- // Identify previous coins admitted to this specific topic
173
- const previousCoins: number[] = []
174
- const outputPromises = tx.inputs.map(async (input, i) => {
175
- const previousTXID = input.sourceTXID !== undefined ? input.sourceTXID : input.sourceTransaction?.id('hex')
176
- if (previousTXID !== undefined) {
177
- // Check if the previous output was admitted to this specific topic
178
- const output = await this.storage.findOutput(previousTXID, input.sourceOutputIndex, topic)
179
- if (output !== undefined && output !== null) {
180
- previousCoins.push(i)
181
- return output
174
+ // Identify previous coins admitted to this specific topic
175
+ const previousCoins: number[] = []
176
+ const outputPromises = tx.inputs.map(async (input, i) => {
177
+ const previousTXID = input.sourceTXID !== undefined ? input.sourceTXID : input.sourceTransaction?.id('hex')
178
+ if (previousTXID !== undefined) {
179
+ // Check if the previous output was admitted to this specific topic
180
+ const output = await this.storage.findOutput(previousTXID, input.sourceOutputIndex, topic)
181
+ if (output !== undefined && output !== null) {
182
+ previousCoins.push(i)
183
+ return output
184
+ }
182
185
  }
183
- }
184
- return null
185
- })
186
+ return null
187
+ })
186
188
 
187
- this.startTime(`previousOutputQuery_${txid.substring(0, 10)}`)
188
- const outputs = await Promise.all(outputPromises)
189
- this.endTime(`previousOutputQuery_${txid.substring(0, 10)}`)
189
+ this.startTime(`previousOutputQuery_${txid.substring(0, 10)}`)
190
+ const outputs = await Promise.all(outputPromises)
191
+ this.endTime(`previousOutputQuery_${txid.substring(0, 10)}`)
190
192
 
191
- const markSpentPromises = outputs.map(async (output) => {
192
- if (output !== undefined && output !== null) {
193
- try {
194
- await this.storage.markUTXOAsSpent(output.txid, output.outputIndex, topic)
195
- await Promise.all(Object.values(this.lookupServices).map(async l => {
196
- try {
197
- if (typeof l.outputSpent === 'function') {
198
- if (l.spendNotificationMode === 'txid') {
199
- await l.outputSpent({
200
- mode: 'txid',
201
- spendingTxid: txid,
202
- txid: output.txid,
203
- outputIndex: output.outputIndex,
204
- topic
205
- })
206
- } else if (l.spendNotificationMode === 'script') {
207
- const inputIndex = tx.inputs.findIndex(i => {
208
- let realSource = i.sourceTXID
209
- if (!realSource) {
210
- realSource = i.sourceTransaction?.id('hex')
193
+ const markSpentPromises = outputs.map(async (output) => {
194
+ if (output !== undefined && output !== null) {
195
+ try {
196
+ await this.storage.markUTXOAsSpent(output.txid, output.outputIndex, topic)
197
+ await Promise.all(Object.values(this.lookupServices).map(async l => {
198
+ try {
199
+ if (typeof l.outputSpent === 'function') {
200
+ if (l.spendNotificationMode === 'txid') {
201
+ await l.outputSpent({
202
+ mode: 'txid',
203
+ spendingTxid: txid,
204
+ txid: output.txid,
205
+ outputIndex: output.outputIndex,
206
+ topic
207
+ })
208
+ } else if (l.spendNotificationMode === 'script') {
209
+ const inputIndex = tx.inputs.findIndex(i => {
210
+ let realSource = i.sourceTXID
211
+ if (!realSource) {
212
+ realSource = i.sourceTransaction?.id('hex')
213
+ }
214
+ return realSource === output.txid && i.sourceOutputIndex === output.outputIndex
215
+ })
216
+ if (inputIndex === -1) {
217
+ throw new Error('Could not find input index')
211
218
  }
212
- return realSource === output.txid && i.sourceOutputIndex === output.outputIndex
213
- })
214
- if (!inputIndex) {
215
- throw new Error('Could not find input index')
219
+ await l.outputSpent({
220
+ mode: 'script',
221
+ spendingTxid: txid,
222
+ inputIndex,
223
+ sequenceNumber: tx.inputs[inputIndex].sequence ?? 0xffffffff,
224
+ unlockingScript: tx.inputs[inputIndex].unlockingScript!,
225
+ txid: output.txid,
226
+ outputIndex: output.outputIndex,
227
+ topic,
228
+ offChainValues
229
+ })
230
+ } else if (l.spendNotificationMode === 'whole-tx') {
231
+ await l.outputSpent({
232
+ mode: 'whole-tx',
233
+ spendingAtomicBEEF: tx.toAtomicBEEF(),
234
+ txid: output.txid,
235
+ outputIndex: output.outputIndex,
236
+ topic,
237
+ offChainValues
238
+ })
239
+ } else { // none
240
+ await l.outputSpent({
241
+ mode: 'none',
242
+ txid: output.txid,
243
+ outputIndex: output.outputIndex,
244
+ topic
245
+ })
216
246
  }
217
- await l.outputSpent({
218
- mode: 'script',
219
- spendingTxid: txid,
220
- inputIndex,
221
- sequenceNumber: tx.inputs[inputIndex].sequence ?? 0xffffffff,
222
- unlockingScript: tx.inputs[inputIndex].unlockingScript!,
223
- txid: output.txid,
224
- outputIndex: output.outputIndex,
225
- topic,
226
- offChainValues
227
- })
228
- } else if (l.spendNotificationMode === 'whole-tx') {
229
- await l.outputSpent({
230
- mode: 'whole-tx',
231
- spendingAtomicBEEF: tx.toAtomicBEEF(),
232
- txid: output.txid,
233
- outputIndex: output.outputIndex,
234
- topic,
235
- offChainValues
236
- })
237
- } else { // none
238
- await l.outputSpent({
239
- mode: 'none',
240
- txid: output.txid,
241
- outputIndex: output.outputIndex,
242
- topic
243
- })
244
247
  }
248
+ } catch (error) {
249
+ this.logger.error('Error in lookup service for outputSpent:', error)
245
250
  }
246
- } catch (error) {
247
- this.logger.error('Error in lookup service for outputSpent:', error)
248
- }
249
- }))
250
- } catch (error) {
251
- this.logger.error('Error marking UTXO as spent:', error)
251
+ }))
252
+ } catch (error) {
253
+ this.logger.error('Error marking UTXO as spent:', error)
254
+ }
252
255
  }
253
- }
254
- })
255
-
256
- let admissibleOutputs: AdmittanceInstructions = { outputsToAdmit: [], coinsToRetain: [] }
257
- // Determine which outputs are admissible for this topic
258
- const admissibleOutputsPromise = (async () => {
259
- try {
260
- this.startTime(`identifyAdmissibleOutputs_${txid.substring(0, 10)}`)
261
- admissibleOutputs = await this.managers[topic].identifyAdmissibleOutputs(taggedBEEF.beef, previousCoins, offChainValues)
262
- this.endTime(`identifyAdmissibleOutputs_${txid.substring(0, 10)}`)
263
- } catch (_) {
264
- steak[topic] = { outputsToAdmit: [], coinsToRetain: [] }
265
- }
266
- })()
256
+ })
267
257
 
268
- // Wait for both tasks to complete
269
- await Promise.all([markSpentPromises, admissibleOutputsPromise])
270
- // Keep track of what outputs were admitted for what topic
271
- steak[topic] = admissibleOutputs
258
+ let admissibleOutputs: AdmittanceInstructions = { outputsToAdmit: [], coinsToRetain: [] }
259
+ // Determine which outputs are admissible for this topic
260
+ const admissibleOutputsPromise = (async () => {
261
+ try {
262
+ this.startTime(`identifyAdmissibleOutputs_${txid.substring(0, 10)}`)
263
+ admissibleOutputs = await this.managers[topic].identifyAdmissibleOutputs(taggedBEEF.beef, previousCoins, offChainValues)
264
+ this.endTime(`identifyAdmissibleOutputs_${txid.substring(0, 10)}`)
265
+ } catch (_) {
266
+ failedTopics.add(topic)
267
+ steak[topic] = { outputsToAdmit: [], coinsToRetain: [] }
268
+ }
269
+ })()
270
+
271
+ // Wait for both tasks to complete
272
+ await Promise.all([...markSpentPromises, admissibleOutputsPromise])
273
+ // Keep track of what outputs were admitted for what topic
274
+ steak[topic] = admissibleOutputs
275
+ } catch (error) {
276
+ this.logger.error('Error processing topic during submit:', error)
277
+ failedTopics.add(topic)
278
+ steak[topic] = { outputsToAdmit: [], coinsToRetain: [] }
279
+ }
272
280
  })
273
281
 
274
282
  await Promise.all(topicPromises)
@@ -276,11 +284,18 @@ export class Engine {
276
284
  // Broadcast the transaction if not historical and broadcaster is configured
277
285
  this.startTime(`broadcast_${txid.substring(0, 10)}`)
278
286
  if (mode !== 'historical-tx' && this.broadcaster !== undefined) {
279
- const response = await this.broadcaster.broadcast(tx)
280
- if (isBroadcastFailure(response) && this.throwOnBroadcastFailure) {
281
- const e = new Error(`Failed to broadcast transaction! Error: ${response.description}`);
282
- (e as any).more = response.more
283
- throw e
287
+ try {
288
+ const response = await this.broadcaster.broadcast(tx)
289
+ if (isBroadcastFailure(response) && this.throwOnBroadcastFailure) {
290
+ const e = new Error(`Failed to broadcast transaction! Error: ${response.description}`)
291
+ ;(e as any).more = response.more
292
+ throw e
293
+ }
294
+ } catch (error) {
295
+ if (this.throwOnBroadcastFailure) {
296
+ throw error
297
+ }
298
+ this.logger.error('Error broadcasting transaction:', error)
284
299
  }
285
300
  }
286
301
  this.endTime(`broadcast_${txid.substring(0, 10)}`)
@@ -295,131 +310,141 @@ export class Engine {
295
310
  if (dupeTopics.has(topic)) {
296
311
  continue
297
312
  }
298
- // Keep track of which outputs to admit, mark as stale, or retain
299
- const admissibleOutputs = steak[topic]
300
- const outputsToAdmit: number[] = admissibleOutputs.outputsToAdmit
301
- const outputsConsumed: Array<{
302
- txid: string
303
- outputIndex: number
304
- }> = []
305
-
306
- const outputsToMarkStale: Array<{
307
- txid: string
308
- previousOutputIndex: number
309
- inputIndex: number
310
- }> = []
313
+ if (failedTopics.has(topic)) {
314
+ continue
315
+ }
316
+ try {
317
+ const admissibleOutputs = steak[topic]
318
+ const outputsToAdmit: number[] = admissibleOutputs.outputsToAdmit
319
+ const outputsConsumed: Array<{
320
+ txid: string
321
+ outputIndex: number
322
+ }> = []
323
+
324
+ const outputsToMarkStale: Array<{
325
+ txid: string
326
+ previousOutputIndex: number
327
+ inputIndex: number
328
+ }> = []
311
329
 
312
330
  // Recompute previousCoins for this topic to use in the update logic
313
- const previousCoins: number[] = []
314
- await Promise.all(tx.inputs.map(async (input, i) => {
315
- const previousTXID = input.sourceTXID !== undefined ? input.sourceTXID : input.sourceTransaction?.id('hex')
316
- if (previousTXID !== undefined) {
317
- const output = await this.storage.findOutput(previousTXID, input.sourceOutputIndex, topic)
318
- if (output !== undefined && output !== null) {
319
- previousCoins.push(i)
331
+ const previousCoins: number[] = []
332
+ await Promise.all(tx.inputs.map(async (input, i) => {
333
+ const previousTXID = input.sourceTXID !== undefined ? input.sourceTXID : input.sourceTransaction?.id('hex')
334
+ if (previousTXID !== undefined) {
335
+ const output = await this.storage.findOutput(previousTXID, input.sourceOutputIndex, topic)
336
+ if (output !== undefined && output !== null) {
337
+ previousCoins.push(i)
338
+ }
320
339
  }
321
- }
322
- }))
340
+ }))
323
341
 
324
342
  // For each of the previous UTXOs for this topic, if the UTXO was not included in the list of UTXOs identified for retention, then it will be marked as stale.
325
- for (const inputIndex of previousCoins) {
326
- const previousTXID = tx.inputs[inputIndex].sourceTXID ?? tx.inputs[inputIndex].sourceTransaction?.id('hex')
327
- if (typeof previousTXID !== 'string') continue
328
- const previousOutputIndex = tx.inputs[inputIndex].sourceOutputIndex
329
- if (!admissibleOutputs.coinsToRetain.includes(inputIndex)) {
330
- outputsToMarkStale.push({
331
- txid: previousTXID,
332
- previousOutputIndex,
333
- inputIndex
334
- })
335
- } else {
336
- outputsConsumed.push({
337
- txid: previousTXID,
338
- outputIndex: previousOutputIndex
339
- })
343
+ for (const inputIndex of previousCoins) {
344
+ const previousTXID = tx.inputs[inputIndex].sourceTXID ?? tx.inputs[inputIndex].sourceTransaction?.id('hex')
345
+ if (typeof previousTXID !== 'string') continue
346
+ const previousOutputIndex = tx.inputs[inputIndex].sourceOutputIndex
347
+ if (!admissibleOutputs.coinsToRetain.includes(inputIndex)) {
348
+ outputsToMarkStale.push({
349
+ txid: previousTXID,
350
+ previousOutputIndex,
351
+ inputIndex
352
+ })
353
+ } else {
354
+ outputsConsumed.push({
355
+ txid: previousTXID,
356
+ outputIndex: previousOutputIndex
357
+ })
358
+ }
340
359
  }
341
- }
342
360
 
343
361
  // Remove stale outputs recursively
344
- this.startTime(`lookForStaleOutputs_${txid.substring(0, 10)}`)
345
- await Promise.all(outputsToMarkStale.map(async coin => {
346
- const output = await this.storage.findOutput(coin.txid, coin.previousOutputIndex, topic)
347
- if (output !== undefined && output !== null) {
348
- await this.deleteUTXODeep(output)
349
- }
350
- }))
351
- this.endTime(`lookForStaleOutputs_${txid.substring(0, 10)}`)
362
+ this.startTime(`lookForStaleOutputs_${txid.substring(0, 10)}`)
363
+ await Promise.all(outputsToMarkStale.map(async coin => {
364
+ const output = await this.storage.findOutput(coin.txid, coin.previousOutputIndex, topic)
365
+ if (output !== undefined && output !== null) {
366
+ await this.deleteUTXODeep(output)
367
+ }
368
+ }))
369
+ this.endTime(`lookForStaleOutputs_${txid.substring(0, 10)}`)
352
370
 
353
371
  // Update the STEAK to indicate which coins were removed
354
- steak[topic].coinsRemoved = outputsToMarkStale.map(x => x.inputIndex)
372
+ steak[topic].coinsRemoved = outputsToMarkStale.map(x => x.inputIndex)
355
373
 
356
374
  // Handle admittance and notification of incoming UTXOs
357
- const newUTXOs: Array<{ txid: string, outputIndex: number }> = []
358
- await Promise.all(outputsToAdmit.map(async outputIndex => {
359
- if (typeof tx.outputs[outputIndex].satoshis !== 'number') return
360
- this.startTime(`insertNewOutput_${txid.substring(0, 10)}`)
361
- await this.storage.insertOutput({
362
- txid,
363
- outputIndex,
364
- outputScript: tx.outputs[outputIndex].lockingScript.toBinary(),
365
- satoshis: tx.outputs[outputIndex].satoshis,
366
- topic,
367
- spent: false,
368
- beef: taggedBEEF.beef,
369
- consumedBy: [],
370
- outputsConsumed,
371
- score: Date.now()
372
- })
373
- this.endTime(`insertNewOutput_${txid.substring(0, 10)}`)
374
- newUTXOs.push({ txid, outputIndex })
375
-
376
- this.startTime(`notifyLookupService${txid.substring(0, 10)}`)
377
- await Promise.all(Object.values(this.lookupServices).map(async l => {
378
- if (l.admissionMode === 'locking-script') {
379
- if (
380
- typeof tx.outputs[outputIndex].lockingScript !== 'object' ||
381
- typeof tx.outputs[outputIndex].satoshis !== 'number'
382
- ) {
383
- return
375
+ const newUTXOs: Array<{ txid: string, outputIndex: number }> = []
376
+ await Promise.all(outputsToAdmit.map(async outputIndex => {
377
+ if (typeof tx.outputs[outputIndex].satoshis !== 'number') return
378
+ this.startTime(`insertNewOutput_${txid.substring(0, 10)}`)
379
+ await this.storage.insertOutput({
380
+ txid,
381
+ outputIndex,
382
+ outputScript: tx.outputs[outputIndex].lockingScript.toBinary(),
383
+ satoshis: tx.outputs[outputIndex].satoshis,
384
+ topic,
385
+ spent: false,
386
+ beef: taggedBEEF.beef,
387
+ consumedBy: [],
388
+ outputsConsumed,
389
+ score: Date.now()
390
+ })
391
+ this.endTime(`insertNewOutput_${txid.substring(0, 10)}`)
392
+ newUTXOs.push({ txid, outputIndex })
393
+
394
+ this.startTime(`notifyLookupService${txid.substring(0, 10)}`)
395
+ await Promise.all(Object.values(this.lookupServices).map(async l => {
396
+ try {
397
+ if (l.admissionMode === 'locking-script') {
398
+ if (
399
+ typeof tx.outputs[outputIndex].lockingScript !== 'object' ||
400
+ typeof tx.outputs[outputIndex].satoshis !== 'number'
401
+ ) {
402
+ return
403
+ }
404
+ await l.outputAdmittedByTopic({
405
+ mode: 'locking-script',
406
+ txid,
407
+ outputIndex,
408
+ lockingScript: tx.outputs[outputIndex].lockingScript,
409
+ satoshis: tx.outputs[outputIndex].satoshis,
410
+ topic,
411
+ offChainValues
412
+ })
413
+ } else {
414
+ await l.outputAdmittedByTopic({
415
+ mode: 'whole-tx',
416
+ atomicBEEF: tx.toAtomicBEEF(),
417
+ outputIndex,
418
+ topic,
419
+ offChainValues
420
+ })
421
+ }
422
+ } catch (error) {
423
+ this.logger.error('Error in lookup service for outputAdmittedByTopic:', error)
384
424
  }
385
- await l.outputAdmittedByTopic({
386
- mode: 'locking-script',
387
- txid,
388
- outputIndex,
389
- lockingScript: tx.outputs[outputIndex].lockingScript,
390
- satoshis: tx.outputs[outputIndex].satoshis,
391
- topic,
392
- offChainValues
393
- })
394
- } else {
395
- await l.outputAdmittedByTopic({
396
- mode: 'whole-tx',
397
- atomicBEEF: tx.toAtomicBEEF(),
398
- outputIndex,
399
- topic,
400
- offChainValues
401
- })
402
- }
425
+ }))
426
+ this.endTime(`notifyLookupService${txid.substring(0, 10)}`)
403
427
  }))
404
- this.endTime(`notifyLookupService${txid.substring(0, 10)}`)
405
- }))
406
428
 
407
- this.startTime(`outputConsumed_${txid.substring(0, 10)}`)
429
+ this.startTime(`outputConsumed_${txid.substring(0, 10)}`)
408
430
  // Update each output consumed to know who consumed it and insert applied transaction in parallel
409
- await Promise.all([
410
- ...outputsConsumed.map(async output => {
411
- const outputToUpdate = await this.storage.findOutput(output.txid, output.outputIndex, topic)
412
- if (outputToUpdate !== undefined && outputToUpdate !== null) {
413
- const newConsumedBy = [...new Set([...newUTXOs, ...outputToUpdate.consumedBy])]
414
- await this.storage.updateConsumedBy(output.txid, output.outputIndex, topic, newConsumedBy)
415
- }
416
- }),
417
- this.storage.insertAppliedTransaction({
418
- txid,
419
- topic
420
- })
421
- ])
422
- this.endTime(`outputConsumed_${txid.substring(0, 10)}`)
431
+ await Promise.all([
432
+ ...outputsConsumed.map(async output => {
433
+ const outputToUpdate = await this.storage.findOutput(output.txid, output.outputIndex, topic)
434
+ if (outputToUpdate !== undefined && outputToUpdate !== null) {
435
+ const newConsumedBy = [...new Set([...newUTXOs, ...outputToUpdate.consumedBy])]
436
+ await this.storage.updateConsumedBy(output.txid, output.outputIndex, topic, newConsumedBy)
437
+ }
438
+ }),
439
+ this.storage.insertAppliedTransaction({
440
+ txid,
441
+ topic
442
+ })
443
+ ])
444
+ this.endTime(`outputConsumed_${txid.substring(0, 10)}`)
445
+ } catch (error) {
446
+ this.logger.error('Error updating storage and notifying lookup services for topic', topic, error)
447
+ }
423
448
  }
424
449
 
425
450
  // If we don't have an advertiser or we are dealing with historical transactions, just return the steak
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=AdmittanceInstructions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AdmittanceInstructions.js","sourceRoot":"","sources":["../../../src/AdmittanceInstructions.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=LookupAnswer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LookupAnswer.js","sourceRoot":"","sources":["../../../src/LookupAnswer.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=LookupQuestion.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LookupQuestion.js","sourceRoot":"","sources":["../../../src/LookupQuestion.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=SHIPAdvertisement.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SHIPAdvertisement.js","sourceRoot":"","sources":["../../../src/SHIPAdvertisement.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=SLAPAdvertisement.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SLAPAdvertisement.js","sourceRoot":"","sources":["../../../src/SLAPAdvertisement.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=STEAK.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"STEAK.js","sourceRoot":"","sources":["../../../src/STEAK.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=TaggedBEEF.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TaggedBEEF.js","sourceRoot":"","sources":["../../../src/TaggedBEEF.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=AdmittanceInstructions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AdmittanceInstructions.js","sourceRoot":"","sources":["../../../src/AdmittanceInstructions.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=LookupAnswer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LookupAnswer.js","sourceRoot":"","sources":["../../../src/LookupAnswer.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=LookupQuestion.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LookupQuestion.js","sourceRoot":"","sources":["../../../src/LookupQuestion.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=SHIPAdvertisement.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SHIPAdvertisement.js","sourceRoot":"","sources":["../../../src/SHIPAdvertisement.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=SLAPAdvertisement.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SLAPAdvertisement.js","sourceRoot":"","sources":["../../../src/SLAPAdvertisement.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=STEAK.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"STEAK.js","sourceRoot":"","sources":["../../../src/STEAK.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=TaggedBEEF.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TaggedBEEF.js","sourceRoot":"","sources":["../../../src/TaggedBEEF.ts"],"names":[],"mappings":""}