@bsv/overlay 0.4.1 → 0.4.3

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 (60) hide show
  1. package/dist/cjs/package.json +5 -4
  2. package/dist/cjs/src/Engine.js +18 -8
  3. package/dist/cjs/src/Engine.js.map +1 -1
  4. package/dist/cjs/src/GASP/OverlayGASPRemote.js +8 -4
  5. package/dist/cjs/src/GASP/OverlayGASPRemote.js.map +1 -1
  6. package/dist/cjs/src/GASP/OverlayGASPStorage.js +25 -20
  7. package/dist/cjs/src/GASP/OverlayGASPStorage.js.map +1 -1
  8. package/dist/cjs/src/storage/knex/KnexStorage.js +32 -7
  9. package/dist/cjs/src/storage/knex/KnexStorage.js.map +1 -1
  10. package/dist/cjs/src/storage/knex/all-migrations.js +3 -1
  11. package/dist/cjs/src/storage/knex/all-migrations.js.map +1 -1
  12. package/dist/cjs/src/storage/knex/migrations/2025-06-25-001-gasp-pagination-support.js +43 -0
  13. package/dist/cjs/src/storage/knex/migrations/2025-06-25-001-gasp-pagination-support.js.map +1 -0
  14. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  15. package/dist/esm/src/Engine.js +17 -10
  16. package/dist/esm/src/Engine.js.map +1 -1
  17. package/dist/esm/src/GASP/OverlayGASPRemote.js +2 -1
  18. package/dist/esm/src/GASP/OverlayGASPRemote.js.map +1 -1
  19. package/dist/esm/src/GASP/OverlayGASPStorage.js +15 -14
  20. package/dist/esm/src/GASP/OverlayGASPStorage.js.map +1 -1
  21. package/dist/esm/src/storage/knex/KnexStorage.js +32 -7
  22. package/dist/esm/src/storage/knex/KnexStorage.js.map +1 -1
  23. package/dist/esm/src/storage/knex/all-migrations.js +3 -1
  24. package/dist/esm/src/storage/knex/all-migrations.js.map +1 -1
  25. package/dist/esm/src/storage/knex/migrations/2025-06-25-001-gasp-pagination-support.js +39 -0
  26. package/dist/esm/src/storage/knex/migrations/2025-06-25-001-gasp-pagination-support.js.map +1 -0
  27. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  28. package/dist/types/src/Engine.d.ts.map +1 -1
  29. package/dist/types/src/GASP/OverlayGASPRemote.d.ts +1 -1
  30. package/dist/types/src/GASP/OverlayGASPRemote.d.ts.map +1 -1
  31. package/dist/types/src/GASP/OverlayGASPStorage.d.ts +2 -5
  32. package/dist/types/src/GASP/OverlayGASPStorage.d.ts.map +1 -1
  33. package/dist/types/src/Output.d.ts +1 -0
  34. package/dist/types/src/Output.d.ts.map +1 -1
  35. package/dist/types/src/storage/Storage.d.ts +17 -2
  36. package/dist/types/src/storage/Storage.d.ts.map +1 -1
  37. package/dist/types/src/storage/knex/KnexStorage.d.ts +3 -1
  38. package/dist/types/src/storage/knex/KnexStorage.d.ts.map +1 -1
  39. package/dist/types/src/storage/knex/all-migrations.d.ts.map +1 -1
  40. package/dist/types/src/storage/knex/migrations/2025-06-25-001-gasp-pagination-support.d.ts +4 -0
  41. package/dist/types/src/storage/knex/migrations/2025-06-25-001-gasp-pagination-support.d.ts.map +1 -0
  42. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  43. package/package.json +5 -4
  44. package/src/Engine.ts +20 -11
  45. package/src/GASP/OverlayGASPRemote.ts +3 -2
  46. package/src/GASP/OverlayGASPStorage.ts +17 -16
  47. package/src/Output.ts +1 -0
  48. package/src/__tests/Engine.test.ts +65 -63
  49. package/src/__tests/OverlayGASPRemote.test.ts +1 -1
  50. package/src/__tests/OverlayGASPStorage.test.ts +21 -17
  51. package/src/storage/Storage.ts +19 -2
  52. package/src/storage/knex/KnexStorage.ts +37 -7
  53. package/src/storage/knex/all-migrations.ts +4 -1
  54. package/src/storage/knex/migrations/2025-06-25-001-gasp-pagination-support.ts +46 -0
  55. package/dist/cjs/src/GASP/GASP.js +0 -283
  56. package/dist/cjs/src/GASP/GASP.js.map +0 -1
  57. package/dist/esm/src/GASP/GASP.js +0 -288
  58. package/dist/esm/src/GASP/GASP.js.map +0 -1
  59. package/dist/types/src/GASP/GASP.d.ts +0 -218
  60. package/dist/types/src/GASP/GASP.d.ts.map +0 -1
@@ -34,7 +34,8 @@ export class KnexStorage implements Storage {
34
34
  'outputs.satoshis',
35
35
  'outputs.outputsConsumed',
36
36
  'outputs.spent',
37
- 'outputs.consumedBy'
37
+ 'outputs.consumedBy',
38
+ 'outputs.score'
38
39
  ]
39
40
 
40
41
  if (includeBEEF) {
@@ -72,7 +73,8 @@ export class KnexStorage implements Storage {
72
73
  'outputs.satoshis',
73
74
  'outputs.outputsConsumed',
74
75
  'outputs.spent',
75
- 'outputs.consumedBy'
76
+ 'outputs.consumedBy',
77
+ 'outputs.score'
76
78
  ]
77
79
 
78
80
  if (includeBEEF) {
@@ -97,16 +99,20 @@ export class KnexStorage implements Storage {
97
99
  }))
98
100
  }
99
101
 
100
- async findUTXOsForTopic (topic: string, since?: number, includeBEEF: boolean = false): Promise<Output[]> {
102
+ async findUTXOsForTopic (topic: string, since?: number, limit?: number, includeBEEF: boolean = false): Promise<Output[]> {
101
103
  // Base query to get outputs
102
104
  const query = this.knex('outputs').where({ 'outputs.topic': topic, 'outputs.spent': false })
103
105
 
104
- // If provided, additionally filters UTXOs by block height
106
+ // If provided, additionally filters UTXOs by score
105
107
  if (since !== undefined && since > 0) {
106
108
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
107
- query.andWhere('outputs.blockHeight', '>=', since)
109
+ query.andWhere('outputs.score', '>=', since)
108
110
  }
109
111
 
112
+ // Sort by score
113
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
114
+ query.orderBy('outputs.score', 'asc')
115
+
110
116
  // Select necessary fields from outputs and conditionally include beef from transactions
111
117
  const selectFields = [
112
118
  'outputs.txid',
@@ -116,7 +122,8 @@ export class KnexStorage implements Storage {
116
122
  'outputs.satoshis',
117
123
  'outputs.outputsConsumed',
118
124
  'outputs.spent',
119
- 'outputs.consumedBy'
125
+ 'outputs.consumedBy',
126
+ 'outputs.score'
120
127
  ]
121
128
 
122
129
  if (includeBEEF) {
@@ -125,6 +132,12 @@ export class KnexStorage implements Storage {
125
132
  selectFields.push('transactions.beef')
126
133
  }
127
134
 
135
+ // Apply limit if specified
136
+ if (limit !== undefined && limit > 0) {
137
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
138
+ query.limit(limit)
139
+ }
140
+
128
141
  const outputs = await query.select(selectFields)
129
142
 
130
143
  if (outputs === undefined || outputs.length === 0) {
@@ -165,7 +178,8 @@ export class KnexStorage implements Storage {
165
178
  satoshis: Number(output.satoshis),
166
179
  outputsConsumed: JSON.stringify(output.outputsConsumed),
167
180
  consumedBy: JSON.stringify(output.consumedBy),
168
- spent: output.spent
181
+ spent: output.spent,
182
+ score: output.score
169
183
  })]
170
184
 
171
185
  if (output.beef !== undefined) {
@@ -226,4 +240,20 @@ export class KnexStorage implements Storage {
226
240
 
227
241
  return !!result
228
242
  }
243
+
244
+ async updateLastInteraction (host: string, topic: string, since: number): Promise<void> {
245
+ await this.knex('host_sync_state')
246
+ .insert({ host, topic, since })
247
+ .onConflict(['host', 'topic'])
248
+ .merge({ since })
249
+ }
250
+
251
+ async getLastInteraction (host: string, topic: string): Promise<number> {
252
+ const result = await this.knex('host_sync_state')
253
+ .where({ host, topic })
254
+ .select('since')
255
+ .first()
256
+
257
+ return result ? result.since : 0
258
+ }
229
259
  }
@@ -4,6 +4,8 @@ import { up as addBlockHeightColumnUp, down as addBlockHeightColumnDown } from '
4
4
  import { up as addTransactionsTableUp, down as addTransactionsTableDown } from './migrations/2024-07-17-001-transactions.js'
5
5
  import { up as addedIndexesUp, down as addedIndexesDown } from './migrations/2024-07-18-001-indexes.js'
6
6
  import { up as enlargeUp, down as enlargeDown } from './migrations/2025-05-28-001-enlarge.js'
7
+ import { up as gaspPaginationSupportUp, down as gaspPaginationSupportDown } from './migrations/2025-06-25-001-gasp-pagination-support.js'
8
+
7
9
 
8
10
 
9
11
  /**
@@ -19,7 +21,8 @@ const allMigrations: Migration[] = [
19
21
  { up: addBlockHeightColumnUp, down: addBlockHeightColumnDown },
20
22
  { up: addTransactionsTableUp, down: addTransactionsTableDown },
21
23
  { up: addedIndexesUp, down: addedIndexesDown },
22
- { up: enlargeUp, down: enlargeDown }
24
+ { up: enlargeUp, down: enlargeDown },
25
+ { up: gaspPaginationSupportUp, down: gaspPaginationSupportDown }
23
26
  ]
24
27
 
25
28
  export default allMigrations
@@ -0,0 +1,46 @@
1
+ import type { Knex } from 'knex'
2
+
3
+ export async function up (knex: Knex): Promise<void> {
4
+ // 1. Add score column to outputs table for pagination/sorting
5
+ const hasScoreColumn = await knex.schema.hasColumn('outputs', 'score')
6
+
7
+ if (!hasScoreColumn) {
8
+ // Add new column for score (can be timestamp or any other sorting factor)
9
+ await knex.schema.table('outputs', table => {
10
+ table.float('score').notNullable().defaultTo(0)
11
+ // Create compound index on topic and score for efficient querying
12
+ table.index(['topic', 'score'])
13
+ })
14
+ }
15
+
16
+ // 2. Create host_sync_state table for tracking sync progress per host/topic
17
+ const hostSyncStateExists = await knex.schema.hasTable('host_sync_state')
18
+
19
+ if (!hostSyncStateExists) {
20
+ await knex.schema.createTable('host_sync_state', table => {
21
+ table.string('host').notNullable()
22
+ table.string('topic').notNullable()
23
+ table.bigInteger('since').unsigned().notNullable()
24
+ table.primary(['host', 'topic'])
25
+ table.index('host')
26
+ table.index('topic')
27
+ })
28
+ }
29
+ }
30
+
31
+ export async function down (knex: Knex): Promise<void> {
32
+ // Rollback in reverse order
33
+
34
+ // 1. Drop host_sync_state table
35
+ await knex.schema.dropTableIfExists('host_sync_state')
36
+
37
+ // 2. Remove score column from outputs table
38
+ const hasScoreColumn = await knex.schema.hasColumn('outputs', 'score')
39
+ if (hasScoreColumn) {
40
+ await knex.schema.table('outputs', table => {
41
+ // Drop the compound index on topic and score
42
+ table.dropIndex(['topic', 'score'])
43
+ table.dropColumn('score')
44
+ })
45
+ }
46
+ }
@@ -1,283 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GASP = exports.GASPVersionMismatchError = void 0;
4
- const sdk_1 = require("@bsv/sdk");
5
- class GASPVersionMismatchError extends Error {
6
- constructor(message, currentVersion, foreignVersion) {
7
- super(message);
8
- this.code = 'ERR_GASP_VERSION_MISMATCH';
9
- this.currentVersion = currentVersion;
10
- this.foreignVersion = foreignVersion;
11
- }
12
- }
13
- exports.GASPVersionMismatchError = GASPVersionMismatchError;
14
- /**
15
- * Main class implementing the Graph Aware Sync Protocol.
16
- */
17
- class GASP {
18
- /**
19
- *
20
- * @param storage The GASP Storage interface to use
21
- * @param remote The GASP Remote interface to use
22
- * @param lastInteraction The timestamp when we last interacted with this remote party
23
- * @param logPrefix Optional prefix for log messages
24
- * @param log Whether to log messages
25
- * @param unidirectional Whether to disable the "reply" side and do pull-only
26
- */
27
- constructor(storage, remote, lastInteraction = 0, logPrefix = '[GASP] ', log = false, unidirectional = false) {
28
- this.storage = storage;
29
- this.remote = remote;
30
- this.lastInteraction = lastInteraction;
31
- this.version = 1;
32
- this.logPrefix = logPrefix;
33
- this.log = log;
34
- this.unidirectional = unidirectional;
35
- this.validateTimestamp(this.lastInteraction);
36
- this.logData(`GASP initialized with version: ${this.version}, lastInteraction: ${this.lastInteraction}, unidirectional: ${this.unidirectional}`);
37
- }
38
- logData(...data) {
39
- if (this.log) {
40
- console.log(this.logPrefix, ...data);
41
- }
42
- }
43
- validateTimestamp(timestamp) {
44
- if (typeof timestamp !== 'number' || isNaN(timestamp) || timestamp < 0 || !Number.isInteger(timestamp)) {
45
- throw new Error('Invalid timestamp format');
46
- }
47
- }
48
- /**
49
- * Computes a 36-byte structure from a transaction ID and output index.
50
- * @param txid The transaction ID.
51
- * @param index The output index.
52
- * @returns A string representing the 36-byte structure.
53
- */
54
- compute36ByteStructure(txid, index) {
55
- const result = `${txid}.${index.toString()}`;
56
- this.logData(`Computed 36-byte structure: ${result} from txid: ${txid}, index: ${index}`);
57
- return result;
58
- }
59
- /**
60
- * Deconstructs a 36-byte structure into a transaction ID and output index.
61
- * @param outpoint The 36-byte structure.
62
- * @returns An object containing the transaction ID and output index.
63
- */
64
- deconstruct36ByteStructure(outpoint) {
65
- const [txid, index] = outpoint.split('.');
66
- const result = {
67
- txid,
68
- outputIndex: parseInt(index, 10)
69
- };
70
- this.logData(`Deconstructed 36-byte structure: ${outpoint} into txid: ${txid}, outputIndex: ${result.outputIndex}`);
71
- return result;
72
- }
73
- /**
74
- * Computes the transaction ID for a given transaction.
75
- * @param tx The transaction string.
76
- * @returns The computed transaction ID.
77
- */
78
- computeTXID(tx) {
79
- const txid = sdk_1.Transaction.fromHex(tx).id('hex');
80
- this.logData(`Computed TXID: ${txid} from transaction: ${tx}`);
81
- return txid;
82
- }
83
- /**
84
- * Synchronizes the transaction data between the local and remote participants.
85
- */
86
- async sync() {
87
- this.logData(`Starting sync process. Last interaction timestamp: ${this.lastInteraction}`);
88
- const initialRequest = await this.buildInitialRequest(this.lastInteraction);
89
- const initialResponse = await this.remote.getInitialResponse(initialRequest);
90
- // 1. Pull the remote UTXOs that we don't already have
91
- if (initialResponse.UTXOList.length > 0) {
92
- const foreignUTXOs = await this.storage.findKnownUTXOs(0);
93
- // -- REPLACE Promise.all WITH A FOR LOOP --
94
- const missingUTXOs = initialResponse.UTXOList.filter(x => !foreignUTXOs.some(y => x.txid === y.txid && x.outputIndex === y.outputIndex));
95
- for (const UTXO of missingUTXOs) {
96
- try {
97
- this.logData(`Requesting node for UTXO: ${JSON.stringify(UTXO)}`);
98
- const resolvedNode = await this.remote.requestNode(this.compute36ByteStructure(UTXO.txid, UTXO.outputIndex), UTXO.txid, UTXO.outputIndex, true);
99
- this.logData(`Received unspent graph node from remote: ${JSON.stringify(resolvedNode)}`);
100
- await this.processIncomingNode(resolvedNode);
101
- await this.completeGraph(resolvedNode.graphID);
102
- }
103
- catch (e) {
104
- this.logData(`Error with incoming UTXO ${UTXO.txid}.${UTXO.outputIndex}: ${e.message}`);
105
- }
106
- }
107
- }
108
- // 2. Only do the “reply” half if unidirectional is disabled
109
- if (!this.unidirectional) {
110
- const initialReply = await this.getInitialReply(initialResponse);
111
- this.logData(`Received initial reply: ${JSON.stringify(initialReply)}`);
112
- if (initialReply.UTXOList.length > 0) {
113
- // -- REPLACE Promise.all WITH A FOR LOOP --
114
- for (const UTXO of initialReply.UTXOList) {
115
- try {
116
- this.logData(`Hydrating GASP node for UTXO: ${JSON.stringify(UTXO)}`);
117
- const outgoingNode = await this.storage.hydrateGASPNode(this.compute36ByteStructure(UTXO.txid, UTXO.outputIndex), UTXO.txid, UTXO.outputIndex, true);
118
- this.logData(`Sending unspent graph node for remote: ${JSON.stringify(outgoingNode)}`);
119
- await this.processOutgoingNode(outgoingNode);
120
- }
121
- catch (e) {
122
- this.logData(`Error with outgoing UTXO ${UTXO.txid}.${UTXO.outputIndex}: ${e.message}`);
123
- }
124
- }
125
- }
126
- }
127
- this.logData('Sync completed!');
128
- }
129
- /**
130
- * Builds the initial request for the sync process.
131
- * @returns A promise for the initial request object.
132
- */
133
- async buildInitialRequest(since) {
134
- const request = {
135
- version: this.version,
136
- since
137
- };
138
- this.logData(`Built initial request: ${JSON.stringify(request)}`);
139
- return request;
140
- }
141
- /**
142
- * Builds the initial response based on the received request.
143
- * @param request The initial request object.
144
- * @returns A promise for an initial response
145
- */
146
- async getInitialResponse(request) {
147
- this.logData(`Received initial request: ${JSON.stringify(request)}`);
148
- if (request.version !== this.version) {
149
- const error = new GASPVersionMismatchError(`GASP version mismatch. Current version: ${this.version}, foreign version: ${request.version}`, this.version, request.version);
150
- console.error(`GASP version mismatch error: ${error.message}`);
151
- throw error;
152
- }
153
- this.validateTimestamp(request.since);
154
- const response = {
155
- since: this.lastInteraction,
156
- UTXOList: await this.storage.findKnownUTXOs(request.since)
157
- };
158
- this.logData(`Built initial response: ${JSON.stringify(response)}`);
159
- return response;
160
- }
161
- /**
162
- * Builds the initial reply based on the received response.
163
- * @param response The initial response object.
164
- * @returns A promise for an initial reply
165
- */
166
- async getInitialReply(response) {
167
- this.logData(`Received initial response: ${JSON.stringify(response)}`);
168
- const knownUTXOs = await this.storage.findKnownUTXOs(response.since);
169
- const filteredUTXOs = knownUTXOs.filter(x => !response.UTXOList.some(y => y.txid === x.txid && y.outputIndex === x.outputIndex));
170
- const reply = {
171
- UTXOList: filteredUTXOs
172
- };
173
- this.logData(`Built initial reply: ${JSON.stringify(reply)}`);
174
- return reply;
175
- }
176
- /**
177
- * Provides a requested node to a foreign instance who requested it.
178
- */
179
- async requestNode(graphID, txid, outputIndex, metadata) {
180
- this.logData(`Remote is requesting node with graphID: ${graphID}, txid: ${txid}, outputIndex: ${outputIndex}, metadata: ${metadata}`);
181
- const node = await this.storage.hydrateGASPNode(graphID, txid, outputIndex, metadata);
182
- this.logData(`Returning node: ${JSON.stringify(node)}`);
183
- return node;
184
- }
185
- /**
186
- * Provides a set of inputs we care about after processing a new incoming node.
187
- * Also finalizes or discards a graph if no additional data is requested from the foreign instance.
188
- */
189
- async submitNode(node) {
190
- this.logData(`Remote party is submitting node: ${JSON.stringify(node)}`);
191
- await this.storage.appendToGraph(node);
192
- const requestedInputs = await this.storage.findNeededInputs(node);
193
- this.logData(`Requested inputs: ${JSON.stringify(requestedInputs)}`);
194
- if (!requestedInputs) {
195
- await this.completeGraph(node.graphID);
196
- }
197
- return requestedInputs;
198
- }
199
- /**
200
- * Handles the completion of a newly-synced graph
201
- * @param {string} graphID The ID of the newly-synced graph
202
- */
203
- async completeGraph(graphID) {
204
- this.logData(`Completing newly-synced graph: ${graphID}`);
205
- try {
206
- await this.storage.validateGraphAnchor(graphID);
207
- this.logData(`Graph validated for node: ${graphID}`);
208
- await this.storage.finalizeGraph(graphID);
209
- this.logData(`Graph finalized for node: ${graphID}`);
210
- }
211
- catch (e) {
212
- this.logData(`Error validating graph: ${e.message}. Discarding graph for node: ${graphID}`);
213
- await this.storage.discardGraph(graphID);
214
- }
215
- }
216
- /**
217
- * Processes an incoming node from the remote participant.
218
- * @param node The incoming GASP node.
219
- * @param spentBy The 36-byte structure of the node that spent this one, if applicable.
220
- */
221
- async processIncomingNode(node, spentBy, seenNodes = new Set()) {
222
- const nodeId = `${this.computeTXID(node.rawTx)}.${node.outputIndex}`;
223
- this.logData(`Processing incoming node: ${JSON.stringify(node)}, spentBy: ${spentBy}`);
224
- if (seenNodes.has(nodeId)) {
225
- this.logData(`Node ${nodeId} already processed, skipping.`);
226
- return; // Prevent infinite recursion
227
- }
228
- seenNodes.add(nodeId);
229
- await this.storage.appendToGraph(node, spentBy);
230
- const neededInputs = await this.storage.findNeededInputs(node);
231
- this.logData(`Needed inputs for node ${nodeId}: ${JSON.stringify(neededInputs)}`);
232
- if (neededInputs) {
233
- // -- REPLACE Promise.all WITH A FOR LOOP --
234
- for (const [outpoint, { metadata }] of Object.entries(neededInputs.requestedInputs)) {
235
- const { txid, outputIndex } = this.deconstruct36ByteStructure(outpoint);
236
- this.logData(`Requesting new node for txid: ${txid}, outputIndex: ${outputIndex}, metadata: ${metadata}`);
237
- const newNode = await this.remote.requestNode(node.graphID, txid, outputIndex, metadata);
238
- this.logData(`Received new node: ${JSON.stringify(newNode)}`);
239
- await this.processIncomingNode(newNode, this.compute36ByteStructure(this.computeTXID(node.rawTx), node.outputIndex), seenNodes);
240
- }
241
- }
242
- }
243
- /**
244
- * Processes an outgoing node to the remote participant.
245
- * @param node The outgoing GASP node.
246
- */
247
- async processOutgoingNode(node, seenNodes = new Set()) {
248
- if (this.unidirectional) {
249
- this.logData(`Skipping outgoing node processing in unidirectional mode.`);
250
- return;
251
- }
252
- const nodeId = `${this.computeTXID(node.rawTx)}.${node.outputIndex}`;
253
- this.logData(`Processing outgoing node: ${JSON.stringify(node)}`);
254
- if (seenNodes.has(nodeId)) {
255
- this.logData(`Node ${nodeId} already processed, skipping.`);
256
- return; // Prevent infinite recursion
257
- }
258
- seenNodes.add(nodeId);
259
- // Attempt to submit the node to the remote
260
- const response = await this.remote.submitNode(node);
261
- this.logData(`Received response for submitted node: ${JSON.stringify(response)}`);
262
- if (response) {
263
- // Process each requested input sequentially
264
- for (const [outpoint, { metadata }] of Object.entries(response.requestedInputs)) {
265
- const { txid, outputIndex } = this.deconstruct36ByteStructure(outpoint);
266
- try {
267
- this.logData(`Hydrating node for txid: ${txid}, outputIndex: ${outputIndex}, metadata: ${metadata}`);
268
- const hydratedNode = await this.storage.hydrateGASPNode(node.graphID, txid, outputIndex, metadata);
269
- this.logData(`Hydrated node: ${JSON.stringify(hydratedNode)}`);
270
- await this.processOutgoingNode(hydratedNode, seenNodes);
271
- }
272
- catch (e) {
273
- this.logData(`Error hydrating node: ${e.message}`);
274
- // If we can't send the outgoing node, we just stop.
275
- // The remote won't validate the anchor, and their temporary graph will be discarded.
276
- return;
277
- }
278
- }
279
- }
280
- }
281
- }
282
- exports.GASP = GASP;
283
- //# sourceMappingURL=GASP.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GASP.js","sourceRoot":"","sources":["../../../../src/GASP/GASP.ts"],"names":[],"mappings":";;;AAAA,kCAAsC;AAsHtC,MAAa,wBAAyB,SAAQ,KAAK;IAKjD,YAAY,OAAe,EAAE,cAAsB,EAAE,cAAsB;QACzE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAA;QACvC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACtC,CAAC;CACF;AAXD,4DAWC;AAED;;GAEG;AACH,MAAa,IAAI;IASf;;;;;;;;OAQG;IACH,YACE,OAAoB,EACpB,MAAkB,EAClB,eAAe,GAAG,CAAC,EACnB,SAAS,GAAG,SAAS,EACrB,GAAG,GAAG,KAAK,EACX,cAAc,GAAG,KAAK;QAEtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAA;QAChB,IAAI,CAA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