@bsv/overlay 0.1.0-alpha.8 → 0.1.0
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.
- package/dist/cjs/package.json +2 -1
- package/dist/cjs/src/Engine.js +573 -42
- package/dist/cjs/src/Engine.js.map +1 -1
- package/dist/cjs/src/GASP/OverlayGASPRemote.js +96 -0
- package/dist/cjs/src/GASP/OverlayGASPRemote.js.map +1 -0
- package/dist/cjs/src/GASP/OverlayGASPStorage.js +221 -0
- package/dist/cjs/src/GASP/OverlayGASPStorage.js.map +1 -0
- package/dist/cjs/src/SyncConfiguration.js +3 -0
- package/dist/cjs/src/SyncConfiguration.js.map +1 -0
- package/dist/cjs/src/storage/knex/KnexStorage.js +26 -6
- package/dist/cjs/src/storage/knex/KnexStorage.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/Engine.js +575 -42
- package/dist/esm/src/Engine.js.map +1 -1
- package/dist/esm/src/GASP/OverlayGASPRemote.js +93 -0
- package/dist/esm/src/GASP/OverlayGASPRemote.js.map +1 -0
- package/dist/esm/src/GASP/OverlayGASPStorage.js +219 -0
- package/dist/esm/src/GASP/OverlayGASPStorage.js.map +1 -0
- package/dist/esm/src/SyncConfiguration.js +2 -0
- package/dist/esm/src/SyncConfiguration.js.map +1 -0
- package/dist/esm/src/storage/knex/KnexStorage.js +26 -6
- package/dist/esm/src/storage/knex/KnexStorage.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +1 -1
- package/dist/types/mod.d.ts.map +1 -1
- package/dist/types/src/Engine.d.ts +169 -13
- package/dist/types/src/Engine.d.ts.map +1 -1
- package/dist/types/src/GASP/OverlayGASPRemote.d.ts +23 -0
- package/dist/types/src/GASP/OverlayGASPRemote.d.ts.map +1 -0
- package/dist/types/src/GASP/OverlayGASPStorage.d.ts +68 -0
- package/dist/types/src/GASP/OverlayGASPStorage.d.ts.map +1 -0
- package/dist/types/src/SyncConfiguration.d.ts +20 -0
- package/dist/types/src/SyncConfiguration.d.ts.map +1 -0
- package/dist/types/src/TopicManager.d.ts +8 -0
- package/dist/types/src/TopicManager.d.ts.map +1 -1
- package/dist/types/src/storage/Storage.d.ts +7 -0
- package/dist/types/src/storage/Storage.d.ts.map +1 -1
- package/dist/types/src/storage/knex/KnexStorage.d.ts +1 -0
- package/dist/types/src/storage/knex/KnexStorage.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/mod.ts +2 -2
- package/package.json +2 -1
- package/src/Engine.ts +652 -47
- package/src/SyncConfiguration.ts +19 -0
- package/src/TopicManager.ts +6 -0
- package/src/__tests/Engine.test.ts +151 -25
- package/src/__tests/OverlayGASPRemote.test.ts +132 -0
- package/src/__tests/OverlayGASPStorage.test.ts +166 -0
- package/src/storage/Storage.ts +8 -0
- package/src/storage/knex/KnexStorage.ts +34 -5
|
@@ -38,20 +38,49 @@ export class KnexStorage implements Storage {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
async findOutputsForTransaction(txid: string): Promise<Output[]> {
|
|
41
|
-
const
|
|
41
|
+
const outputs = await this.knex('outputs').where({ txid }).select(
|
|
42
42
|
'txid', 'outputIndex', 'outputScript', 'topic', 'satoshis', 'beef', 'outputsConsumed', 'spent', 'consumedBy'
|
|
43
43
|
)
|
|
44
|
-
|
|
44
|
+
|
|
45
|
+
if (outputs === undefined || outputs.length === 0) {
|
|
45
46
|
return []
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
+
|
|
49
|
+
return outputs.map(output => ({
|
|
48
50
|
...output,
|
|
49
51
|
outputScript: [...output.outputScript],
|
|
50
52
|
beef: [...output.beef],
|
|
51
53
|
spent: Boolean(output.spent),
|
|
52
54
|
outputsConsumed: JSON.parse(output.outputsConsumed),
|
|
53
55
|
consumedBy: JSON.parse(output.consumedBy)
|
|
56
|
+
}))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async findUTXOsForTopic(topic: string, since?: number): Promise<Output[]> {
|
|
60
|
+
const query = this.knex('outputs').where({ topic, spent: false })
|
|
61
|
+
|
|
62
|
+
// TODO: Create new migration for outputs that adds either created_at or block height tagging for proven outpoints if necessary.
|
|
63
|
+
// if (since !== undefined) {
|
|
64
|
+
// const sinceDate = new Date(since).toISOString()
|
|
65
|
+
// await query.andWhere('created_at', '>=', sinceDate)
|
|
66
|
+
// }
|
|
67
|
+
|
|
68
|
+
const outputs = await query.select(
|
|
69
|
+
'txid', 'outputIndex', 'outputScript', 'topic', 'satoshis', 'beef', 'outputsConsumed', 'spent', 'consumedBy'
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
if (outputs === undefined || outputs.length === 0) {
|
|
73
|
+
return []
|
|
54
74
|
}
|
|
75
|
+
|
|
76
|
+
return outputs.map(output => ({
|
|
77
|
+
...output,
|
|
78
|
+
outputScript: [...output.outputScript],
|
|
79
|
+
beef: [...output.beef],
|
|
80
|
+
spent: Boolean(output.spent),
|
|
81
|
+
outputsConsumed: JSON.parse(output.outputsConsumed),
|
|
82
|
+
consumedBy: JSON.parse(output.consumedBy)
|
|
83
|
+
}))
|
|
55
84
|
}
|
|
56
85
|
|
|
57
86
|
async deleteOutput(txid: string, outputIndex: number, topic: string): Promise<void> {
|
|
@@ -67,7 +96,7 @@ export class KnexStorage implements Storage {
|
|
|
67
96
|
outputScript: Buffer.from(output.outputScript),
|
|
68
97
|
topic: output.topic,
|
|
69
98
|
satoshis: Number(output.satoshis),
|
|
70
|
-
beef: Buffer.from(
|
|
99
|
+
beef: Buffer.from(output.beef),
|
|
71
100
|
outputsConsumed: JSON.stringify(output.outputsConsumed),
|
|
72
101
|
consumedBy: JSON.stringify(output.consumedBy),
|
|
73
102
|
spent: output.spent
|
|
@@ -95,7 +124,7 @@ export class KnexStorage implements Storage {
|
|
|
95
124
|
txid,
|
|
96
125
|
outputIndex,
|
|
97
126
|
topic
|
|
98
|
-
}).update('beef', beef)
|
|
127
|
+
}).update('beef', Buffer.from(beef))
|
|
99
128
|
}
|
|
100
129
|
|
|
101
130
|
async insertAppliedTransaction(tx: { txid: string, topic: string }): Promise<void> {
|