@bsv/overlay 0.5.4 → 0.6.1

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 (42) hide show
  1. package/dist/cjs/package.json +3 -3
  2. package/dist/cjs/src/Engine.js +9 -7
  3. package/dist/cjs/src/Engine.js.map +1 -1
  4. package/dist/cjs/src/GASP/OverlayGASPStorage.js +89 -44
  5. package/dist/cjs/src/GASP/OverlayGASPStorage.js.map +1 -1
  6. package/dist/cjs/src/storage/knex/KnexStorage.js +23 -18
  7. package/dist/cjs/src/storage/knex/KnexStorage.js.map +1 -1
  8. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  9. package/dist/esm/src/Engine.js +9 -7
  10. package/dist/esm/src/Engine.js.map +1 -1
  11. package/dist/esm/src/GASP/OverlayGASPStorage.js +89 -44
  12. package/dist/esm/src/GASP/OverlayGASPStorage.js.map +1 -1
  13. package/dist/esm/src/storage/knex/KnexStorage.js +23 -18
  14. package/dist/esm/src/storage/knex/KnexStorage.js.map +1 -1
  15. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  16. package/dist/types/src/Engine.d.ts +1 -1
  17. package/dist/types/src/Engine.d.ts.map +1 -1
  18. package/dist/types/src/GASP/OverlayGASPStorage.d.ts +10 -0
  19. package/dist/types/src/GASP/OverlayGASPStorage.d.ts.map +1 -1
  20. package/dist/types/src/TopicManager.d.ts +1 -1
  21. package/dist/types/src/TopicManager.d.ts.map +1 -1
  22. package/dist/types/src/storage/knex/KnexStorage.d.ts.map +1 -1
  23. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  24. package/docs/API.md +16 -503
  25. package/docs/README.md +9 -3
  26. package/docs/Synchronization.md +203 -0
  27. package/docs/concepts/00-overview.md +85 -0
  28. package/docs/concepts/01-best-practices.md +202 -0
  29. package/docs/concepts/02-query-performance.md +345 -0
  30. package/docs/concepts/03-database-monitoring.md +211 -0
  31. package/docs/concepts/04-pagination-example.md +186 -0
  32. package/docs/concepts/05-recommendations-summary.md +158 -0
  33. package/docs/concepts/README.md +16 -0
  34. package/docs/examples/README.md +11 -1
  35. package/docs/examples/gs-wip.md +7 -1
  36. package/docs/internal/README.md +8 -1
  37. package/package.json +3 -3
  38. package/src/Engine.ts +10 -7
  39. package/src/GASP/OverlayGASPStorage.ts +105 -49
  40. package/src/TopicManager.ts +6 -1
  41. package/src/__tests/Engine.test.ts +6 -2
  42. package/src/storage/knex/KnexStorage.ts +25 -20
@@ -9,7 +9,12 @@ export interface TopicManager {
9
9
  * Accepts the transaction in BEEF format and an array of those input indices which spend previously-admitted outputs from the same topic.
10
10
  * The transaction's BEEF structure will always contain the transactions associated with previous coins for reference (if any), regardless of whether the current transaction was directly proven.
11
11
  */
12
- identifyAdmissibleOutputs: (beef: number[], previousCoins: number[], offChainValues?: number[]) => Promise<AdmittanceInstructions>
12
+ identifyAdmissibleOutputs: (
13
+ beef: number[],
14
+ previousCoins: number[],
15
+ offChainValues?: number[],
16
+ mode?: 'historical-tx' | 'current-tx' | 'historical-tx-no-spv'
17
+ ) => Promise<AdmittanceInstructions>
13
18
 
14
19
  /**
15
20
  * Identifies and returns the inputs needed to anchor any topical outputs from this transaction to their associated previous history.
@@ -528,12 +528,16 @@ describe('BSV Overlay Services Engine', () => {
528
528
  mockChainTracker
529
529
  )
530
530
 
531
- // Submit the utxo
532
531
  await engine.submit({
533
532
  beef: exampleBeef,
534
533
  topics: ['Hello']
535
534
  })
536
- expect(engine.managers.Hello.identifyAdmissibleOutputs).toHaveBeenCalledWith(exampleBeef, [0], undefined)
535
+ expect(engine.managers.Hello.identifyAdmissibleOutputs).toHaveBeenCalledWith(
536
+ exampleBeef,
537
+ [0],
538
+ undefined,
539
+ 'current-tx'
540
+ )
537
541
  })
538
542
  describe('When previous UTXOs were retained by the topic manager', () => {
539
543
  it('Notifies all lookup services about the output being spent (not deleted, see the comment about this in deleteUTXODeep)', async () => {
@@ -170,28 +170,33 @@ export class KnexStorage implements Storage {
170
170
  }
171
171
 
172
172
  async insertOutput (output: Output): Promise<void> {
173
- const insertPromises = [this.knex('outputs').insert({
174
- txid: output.txid,
175
- outputIndex: Number(output.outputIndex),
176
- outputScript: Buffer.from(output.outputScript),
177
- topic: output.topic,
178
- satoshis: Number(output.satoshis),
179
- outputsConsumed: JSON.stringify(output.outputsConsumed),
180
- consumedBy: JSON.stringify(output.consumedBy),
181
- spent: output.spent,
182
- score: output.score
183
- })]
184
-
185
- if (output.beef !== undefined) {
186
- const insertTransactionPromise = this.knex('transactions').insert({
173
+ await this.knex.transaction(async trx => {
174
+ const existing = await trx('outputs').where({
187
175
  txid: output.txid,
188
- beef: Buffer.from(output.beef)
189
- }).onConflict('txid').ignore()
190
- insertPromises.push(insertTransactionPromise)
191
- }
176
+ outputIndex: Number(output.outputIndex),
177
+ topic: output.topic
178
+ }).first()
179
+
180
+ if (existing === undefined || existing === null) {
181
+ await trx('outputs').insert({
182
+ txid: output.txid,
183
+ outputIndex: Number(output.outputIndex),
184
+ outputScript: Buffer.from(output.outputScript),
185
+ topic: output.topic,
186
+ satoshis: Number(output.satoshis),
187
+ outputsConsumed: JSON.stringify(output.outputsConsumed),
188
+ consumedBy: JSON.stringify(output.consumedBy),
189
+ spent: output.spent,
190
+ score: output.score
191
+ })
192
+ }
192
193
 
193
- await this.knex.transaction(async trx => {
194
- await Promise.all(insertPromises.map(promise => promise.transacting(trx)))
194
+ if (output.beef !== undefined) {
195
+ await trx('transactions').insert({
196
+ txid: output.txid,
197
+ beef: Buffer.from(output.beef)
198
+ }).onConflict('txid').ignore()
199
+ }
195
200
  })
196
201
  }
197
202