@bsv/overlay 0.1.7 → 0.1.9
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 -2
- package/dist/cjs/src/Engine.js +185 -496
- package/dist/cjs/src/Engine.js.map +1 -1
- package/dist/cjs/src/GASP/OverlayGASPRemote.js +6 -4
- package/dist/cjs/src/GASP/OverlayGASPRemote.js.map +1 -1
- package/dist/cjs/src/GASP/OverlayGASPStorage.js +152 -77
- package/dist/cjs/src/GASP/OverlayGASPStorage.js.map +1 -1
- package/dist/cjs/src/storage/knex/KnexStorage.js +106 -38
- package/dist/cjs/src/storage/knex/KnexStorage.js.map +1 -1
- package/dist/cjs/src/storage/knex/all-migrations.js +5 -1
- package/dist/cjs/src/storage/knex/all-migrations.js.map +1 -1
- package/dist/cjs/src/storage/knex/migrations/2024-07-17-001-transactions.js +39 -0
- package/dist/cjs/src/storage/knex/migrations/2024-07-17-001-transactions.js.map +1 -0
- package/dist/cjs/src/storage/knex/migrations/2024-07-18-001-indexes.js +34 -0
- package/dist/cjs/src/storage/knex/migrations/2024-07-18-001-indexes.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/Engine.js +183 -495
- package/dist/esm/src/Engine.js.map +1 -1
- package/dist/esm/src/GASP/OverlayGASPRemote.js +7 -4
- package/dist/esm/src/GASP/OverlayGASPRemote.js.map +1 -1
- package/dist/esm/src/GASP/OverlayGASPStorage.js +151 -77
- package/dist/esm/src/GASP/OverlayGASPStorage.js.map +1 -1
- package/dist/esm/src/storage/knex/KnexStorage.js +106 -38
- package/dist/esm/src/storage/knex/KnexStorage.js.map +1 -1
- package/dist/esm/src/storage/knex/all-migrations.js +5 -1
- package/dist/esm/src/storage/knex/all-migrations.js.map +1 -1
- package/dist/esm/src/storage/knex/migrations/2024-07-17-001-transactions.js +34 -0
- package/dist/esm/src/storage/knex/migrations/2024-07-17-001-transactions.js.map +1 -0
- package/dist/esm/src/storage/knex/migrations/2024-07-18-001-indexes.js +29 -0
- package/dist/esm/src/storage/knex/migrations/2024-07-18-001-indexes.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/Engine.d.ts +9 -116
- package/dist/types/src/Engine.d.ts.map +1 -1
- package/dist/types/src/GASP/OverlayGASPRemote.d.ts +3 -2
- package/dist/types/src/GASP/OverlayGASPRemote.d.ts.map +1 -1
- package/dist/types/src/GASP/OverlayGASPStorage.d.ts +29 -3
- package/dist/types/src/GASP/OverlayGASPStorage.d.ts.map +1 -1
- package/dist/types/src/Output.d.ts +2 -2
- package/dist/types/src/Output.d.ts.map +1 -1
- package/dist/types/src/SyncConfiguration.d.ts +1 -1
- package/dist/types/src/SyncConfiguration.d.ts.map +1 -1
- package/dist/types/src/storage/Storage.d.ts +6 -8
- package/dist/types/src/storage/Storage.d.ts.map +1 -1
- package/dist/types/src/storage/knex/KnexStorage.d.ts +4 -4
- package/dist/types/src/storage/knex/KnexStorage.d.ts.map +1 -1
- package/dist/types/src/storage/knex/all-migrations.d.ts.map +1 -1
- package/dist/types/src/storage/knex/migrations/2024-07-17-001-transactions.d.ts +4 -0
- package/dist/types/src/storage/knex/migrations/2024-07-17-001-transactions.d.ts.map +1 -0
- package/dist/types/src/storage/knex/migrations/2024-07-18-001-indexes.d.ts +4 -0
- package/dist/types/src/storage/knex/migrations/2024-07-18-001-indexes.d.ts.map +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/Engine.ts +191 -555
- package/src/GASP/OverlayGASPRemote.ts +107 -0
- package/src/GASP/OverlayGASPStorage.ts +331 -0
- package/src/Output.ts +2 -2
- package/src/SyncConfiguration.ts +1 -1
- package/src/__tests/Engine.test.ts +105 -26
- package/src/__tests/OverlayGASPRemote.test.ts +1 -1
- package/src/__tests/OverlayGASPStorage.test.ts +4 -3
- package/src/storage/Storage.ts +6 -8
- package/src/storage/knex/KnexStorage.ts +119 -41
- package/src/storage/knex/all-migrations.ts +10 -6
- package/src/storage/knex/migrations/2024-07-17-001-transactions.ts +40 -0
- package/src/storage/knex/migrations/2024-07-18-001-indexes.ts +30 -0
- package/dist/cjs/src/GASP.js +0 -275
- package/dist/cjs/src/GASP.js.map +0 -1
- package/dist/cjs/src/SHIPAdvertisement.js +0 -3
- package/dist/cjs/src/SHIPAdvertisement.js.map +0 -1
- package/dist/cjs/src/SLAPAdvertisement.js +0 -3
- package/dist/cjs/src/SLAPAdvertisement.js.map +0 -1
- package/dist/esm/src/GASP.js +0 -279
- package/dist/esm/src/GASP.js.map +0 -1
- package/dist/esm/src/SHIPAdvertisement.js +0 -2
- package/dist/esm/src/SHIPAdvertisement.js.map +0 -1
- package/dist/esm/src/SLAPAdvertisement.js +0 -2
- package/dist/esm/src/SLAPAdvertisement.js.map +0 -1
- package/dist/types/src/GASP.d.ts +0 -215
- package/dist/types/src/GASP.d.ts.map +0 -1
- package/dist/types/src/SHIPAdvertisement.d.ts +0 -9
- package/dist/types/src/SHIPAdvertisement.d.ts.map +0 -1
- package/dist/types/src/SLAPAdvertisement.d.ts +0 -9
- package/dist/types/src/SLAPAdvertisement.d.ts.map +0 -1
|
@@ -5,77 +5,147 @@ class KnexStorage {
|
|
|
5
5
|
constructor(knex) {
|
|
6
6
|
this.knex = knex;
|
|
7
7
|
}
|
|
8
|
-
async findOutput(txid, outputIndex, topic, spent) {
|
|
8
|
+
async findOutput(txid, outputIndex, topic, spent, includeBEEF = false) {
|
|
9
9
|
const search = {
|
|
10
|
-
txid,
|
|
11
|
-
outputIndex
|
|
10
|
+
'outputs.txid': txid,
|
|
11
|
+
'outputs.outputIndex': outputIndex
|
|
12
12
|
};
|
|
13
13
|
if (topic !== undefined)
|
|
14
|
-
search.topic = topic;
|
|
14
|
+
search['outputs.topic'] = topic;
|
|
15
15
|
if (spent !== undefined)
|
|
16
|
-
search.spent = spent;
|
|
17
|
-
|
|
16
|
+
search['outputs.spent'] = spent;
|
|
17
|
+
// Base query to get the output
|
|
18
|
+
const query = this.knex('outputs').where(search);
|
|
19
|
+
// Select necessary fields from outputs and conditionally include beef from transactions
|
|
20
|
+
const selectFields = [
|
|
21
|
+
'outputs.txid',
|
|
22
|
+
'outputs.outputIndex',
|
|
23
|
+
'outputs.outputScript',
|
|
24
|
+
'outputs.topic',
|
|
25
|
+
'outputs.satoshis',
|
|
26
|
+
'outputs.outputsConsumed',
|
|
27
|
+
'outputs.spent',
|
|
28
|
+
'outputs.consumedBy'
|
|
29
|
+
];
|
|
30
|
+
if (includeBEEF) {
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
32
|
+
query.leftJoin('transactions', 'outputs.txid', 'transactions.txid');
|
|
33
|
+
selectFields.push('transactions.beef');
|
|
34
|
+
}
|
|
35
|
+
const output = await query.select(selectFields).first();
|
|
18
36
|
if (output === undefined || output === null) {
|
|
19
37
|
return null;
|
|
20
38
|
}
|
|
21
39
|
return {
|
|
22
40
|
...output,
|
|
23
41
|
outputScript: [...output.outputScript],
|
|
24
|
-
beef: [...output.beef],
|
|
42
|
+
beef: includeBEEF ? (output.beef !== undefined ? [...output.beef] : undefined) : undefined,
|
|
25
43
|
spent: Boolean(output.spent),
|
|
26
44
|
outputsConsumed: JSON.parse(output.outputsConsumed),
|
|
27
45
|
consumedBy: JSON.parse(output.consumedBy)
|
|
28
46
|
};
|
|
29
47
|
}
|
|
30
|
-
async findOutputsForTransaction(txid) {
|
|
31
|
-
|
|
48
|
+
async findOutputsForTransaction(txid, includeBEEF = false) {
|
|
49
|
+
// Base query to get outputs
|
|
50
|
+
const query = this.knex('outputs').where({ 'outputs.txid': txid });
|
|
51
|
+
// Select necessary fields from outputs and conditionally include beef from transactions
|
|
52
|
+
const selectFields = [
|
|
53
|
+
'outputs.txid',
|
|
54
|
+
'outputs.outputIndex',
|
|
55
|
+
'outputs.outputScript',
|
|
56
|
+
'outputs.topic',
|
|
57
|
+
'outputs.satoshis',
|
|
58
|
+
'outputs.outputsConsumed',
|
|
59
|
+
'outputs.spent',
|
|
60
|
+
'outputs.consumedBy'
|
|
61
|
+
];
|
|
62
|
+
if (includeBEEF) {
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
64
|
+
query.leftJoin('transactions', 'outputs.txid', 'transactions.txid');
|
|
65
|
+
selectFields.push('transactions.beef');
|
|
66
|
+
}
|
|
67
|
+
const outputs = await query.select(selectFields);
|
|
32
68
|
if (outputs === undefined || outputs.length === 0) {
|
|
33
69
|
return [];
|
|
34
70
|
}
|
|
35
71
|
return outputs.map(output => ({
|
|
36
72
|
...output,
|
|
37
73
|
outputScript: [...output.outputScript],
|
|
38
|
-
beef: [...output.beef],
|
|
74
|
+
beef: includeBEEF ? (output.beef !== undefined ? [...output.beef] : undefined) : undefined,
|
|
39
75
|
spent: Boolean(output.spent),
|
|
40
76
|
outputsConsumed: JSON.parse(output.outputsConsumed),
|
|
41
77
|
consumedBy: JSON.parse(output.consumedBy)
|
|
42
78
|
}));
|
|
43
79
|
}
|
|
44
|
-
async findUTXOsForTopic(topic, since) {
|
|
45
|
-
|
|
80
|
+
async findUTXOsForTopic(topic, since, includeBEEF = false) {
|
|
81
|
+
// Base query to get outputs
|
|
82
|
+
const query = this.knex('outputs').where({ 'outputs.topic': topic, 'outputs.spent': false });
|
|
46
83
|
// If provided, additionally filters UTXOs by block height
|
|
47
84
|
if (since !== undefined && since > 0) {
|
|
48
|
-
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
86
|
+
query.andWhere('outputs.blockHeight', '>=', since);
|
|
87
|
+
}
|
|
88
|
+
// Select necessary fields from outputs and conditionally include beef from transactions
|
|
89
|
+
const selectFields = [
|
|
90
|
+
'outputs.txid',
|
|
91
|
+
'outputs.outputIndex',
|
|
92
|
+
'outputs.outputScript',
|
|
93
|
+
'outputs.topic',
|
|
94
|
+
'outputs.satoshis',
|
|
95
|
+
'outputs.outputsConsumed',
|
|
96
|
+
'outputs.spent',
|
|
97
|
+
'outputs.consumedBy'
|
|
98
|
+
];
|
|
99
|
+
if (includeBEEF) {
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
101
|
+
query.leftJoin('transactions', 'outputs.txid', 'transactions.txid');
|
|
102
|
+
selectFields.push('transactions.beef');
|
|
49
103
|
}
|
|
50
|
-
const outputs = await query.select(
|
|
104
|
+
const outputs = await query.select(selectFields);
|
|
51
105
|
if (outputs === undefined || outputs.length === 0) {
|
|
52
106
|
return [];
|
|
53
107
|
}
|
|
54
108
|
return outputs.map(output => ({
|
|
55
109
|
...output,
|
|
56
110
|
outputScript: [...output.outputScript],
|
|
57
|
-
beef: [...output.beef],
|
|
111
|
+
beef: includeBEEF ? (output.beef !== undefined ? [...output.beef] : undefined) : undefined,
|
|
58
112
|
spent: Boolean(output.spent),
|
|
59
113
|
outputsConsumed: JSON.parse(output.outputsConsumed),
|
|
60
114
|
consumedBy: JSON.parse(output.consumedBy)
|
|
61
115
|
}));
|
|
62
116
|
}
|
|
63
117
|
async deleteOutput(txid, outputIndex, topic) {
|
|
64
|
-
await this.knex(
|
|
65
|
-
|
|
66
|
-
|
|
118
|
+
await this.knex.transaction(async (trx) => {
|
|
119
|
+
// Delete the specific output
|
|
120
|
+
await trx('outputs').where({ txid, outputIndex }).del();
|
|
121
|
+
// Check how many outputs reference the same transaction
|
|
122
|
+
const remainingOutputs = await trx('outputs').where({ txid }).count('* as count').first();
|
|
123
|
+
if (remainingOutputs !== undefined && Number(remainingOutputs.count) === 0) {
|
|
124
|
+
// If no more outputs reference the transaction, delete the beef
|
|
125
|
+
await trx('transactions').where({ txid }).del();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
67
128
|
}
|
|
68
129
|
async insertOutput(output) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
130
|
+
const insertPromises = [this.knex('outputs').insert({
|
|
131
|
+
txid: output.txid,
|
|
132
|
+
outputIndex: Number(output.outputIndex),
|
|
133
|
+
outputScript: Buffer.from(output.outputScript),
|
|
134
|
+
topic: output.topic,
|
|
135
|
+
satoshis: Number(output.satoshis),
|
|
136
|
+
outputsConsumed: JSON.stringify(output.outputsConsumed),
|
|
137
|
+
consumedBy: JSON.stringify(output.consumedBy),
|
|
138
|
+
spent: output.spent
|
|
139
|
+
})];
|
|
140
|
+
if (output.beef !== undefined) {
|
|
141
|
+
const insertTransactionPromise = this.knex('transactions').insert({
|
|
142
|
+
txid: output.txid,
|
|
143
|
+
beef: Buffer.from(output.beef)
|
|
144
|
+
}).onConflict('txid').ignore();
|
|
145
|
+
insertPromises.push(insertTransactionPromise);
|
|
146
|
+
}
|
|
147
|
+
await this.knex.transaction(async (trx) => {
|
|
148
|
+
await Promise.all(insertPromises.map(promise => promise.transacting(trx)));
|
|
79
149
|
});
|
|
80
150
|
}
|
|
81
151
|
async markUTXOAsSpent(txid, outputIndex, topic) {
|
|
@@ -92,11 +162,9 @@ class KnexStorage {
|
|
|
92
162
|
topic
|
|
93
163
|
}).update('consumedBy', consumedBy);
|
|
94
164
|
}
|
|
95
|
-
async
|
|
96
|
-
await this.knex('
|
|
97
|
-
txid
|
|
98
|
-
outputIndex,
|
|
99
|
-
topic
|
|
165
|
+
async updateTransactionBEEF(txid, beef) {
|
|
166
|
+
await this.knex('transactions').where({
|
|
167
|
+
txid
|
|
100
168
|
}).update('beef', Buffer.from(beef));
|
|
101
169
|
}
|
|
102
170
|
async updateOutputBlockHeight(txid, outputIndex, topic, blockHeight) {
|
|
@@ -113,11 +181,11 @@ class KnexStorage {
|
|
|
113
181
|
});
|
|
114
182
|
}
|
|
115
183
|
async doesAppliedTransactionExist(tx) {
|
|
116
|
-
const
|
|
117
|
-
txid: tx.txid,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return
|
|
184
|
+
const result = await this.knex('applied_transactions')
|
|
185
|
+
.where({ txid: tx.txid, topic: tx.topic })
|
|
186
|
+
.select(this.knex.raw('1'))
|
|
187
|
+
.first();
|
|
188
|
+
return !!result;
|
|
121
189
|
}
|
|
122
190
|
}
|
|
123
191
|
exports.KnexStorage = KnexStorage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnexStorage.js","sourceRoot":"","sources":["../../../../../src/storage/knex/KnexStorage.ts"],"names":[],"mappings":";;;AAIA,MAAa,WAAW;IAGtB,YAAY,IAAU;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAY,EAAE,WAAmB,EAAE,KAAc,EAAE,KAAe;
|
|
1
|
+
{"version":3,"file":"KnexStorage.js","sourceRoot":"","sources":["../../../../../src/storage/knex/KnexStorage.ts"],"names":[],"mappings":";;;AAIA,MAAa,WAAW;IAGtB,YAAY,IAAU;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAY,EAAE,WAAmB,EAAE,KAAc,EAAE,KAAe,EAAE,cAAuB,KAAK;QAC/G,MAAM,MAAM,GAKR;YACF,cAAc,EAAE,IAAI;YACpB,qBAAqB,EAAE,WAAW;SACnC,CAAA;QACD,IAAI,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,eAAe,CAAC,GAAG,KAAK,CAAA;QACxD,IAAI,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,eAAe,CAAC,GAAG,KAAK,CAAA;QAExD,+BAA+B;QAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAEhD,wFAAwF;QACxF,MAAM,YAAY,GAAG;YACnB,cAAc;YACd,qBAAqB;YACrB,sBAAsB;YACtB,eAAe;YACf,kBAAkB;YAClB,yBAAyB;YACzB,eAAe;YACf,oBAAoB;SACrB,CAAA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,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IACtC,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,IAAY,EAAE,WAAmB,EAAE,KAAa,EAAE,WAAmB;QACjG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC;YAC/B,IAAI;YACJ,WAAW;YACX,KAAK;SACN,CAAC,CAAC,MAAM,CAAC,aAAa,EAAE,WAAW,CAAC,CAAA;IACvC,CAAC;IAED,KAAK,CAAC,wBAAwB,CAAC,EAAmC;QAChE,MAAM,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC;YAC7C,IAAI,EAAE,EAAE,CAAC,IAAI;YACb,KAAK,EAAE,EAAE,CAAC,KAAK;SAChB,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,2BAA2B,CAAC,EAAmC;QACnE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC;aACnD,KAAK,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC;aACzC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;aAC1B,KAAK,EAAE,CAAA;QAEV,OAAO,CAAC,CAAC,MAAM,CAAA;IACjB,CAAC;CACF;AAhOD,kCAgOC"}
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const _2024_05_18_001_initial_js_1 = require("./migrations/2024-05-18-001-initial.js");
|
|
4
4
|
const _2024_07_10_001_block_height_js_1 = require("./migrations/2024-07-10-001-block-height.js");
|
|
5
|
+
const _2024_07_17_001_transactions_js_1 = require("./migrations/2024-07-17-001-transactions.js");
|
|
6
|
+
const _2024_07_18_001_indexes_js_1 = require("./migrations/2024-07-18-001-indexes.js");
|
|
5
7
|
const allMigrations = [
|
|
6
8
|
{ up: _2024_05_18_001_initial_js_1.up, down: _2024_05_18_001_initial_js_1.down },
|
|
7
|
-
{ up: _2024_07_10_001_block_height_js_1.up, down: _2024_07_10_001_block_height_js_1.down }
|
|
9
|
+
{ up: _2024_07_10_001_block_height_js_1.up, down: _2024_07_10_001_block_height_js_1.down },
|
|
10
|
+
{ up: _2024_07_17_001_transactions_js_1.up, down: _2024_07_17_001_transactions_js_1.down },
|
|
11
|
+
{ up: _2024_07_18_001_indexes_js_1.up, down: _2024_07_18_001_indexes_js_1.down }
|
|
8
12
|
];
|
|
9
13
|
exports.default = allMigrations;
|
|
10
14
|
//# sourceMappingURL=all-migrations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"all-migrations.js","sourceRoot":"","sources":["../../../../../src/storage/knex/all-migrations.ts"],"names":[],"mappings":";;AACA,uFAAyG;AACzG,iGAA4H;
|
|
1
|
+
{"version":3,"file":"all-migrations.js","sourceRoot":"","sources":["../../../../../src/storage/knex/all-migrations.ts"],"names":[],"mappings":";;AACA,uFAAyG;AACzG,iGAA4H;AAC5H,iGAA4H;AAC5H,uFAAuG;AAUvG,MAAM,aAAa,GAAgB;IACjC,EAAE,EAAE,EAAE,+BAAe,EAAE,IAAI,EAAE,iCAAiB,EAAE;IAChD,EAAE,EAAE,EAAE,oCAAsB,EAAE,IAAI,EAAE,sCAAwB,EAAE;IAC9D,EAAE,EAAE,EAAE,oCAAsB,EAAE,IAAI,EAAE,sCAAwB,EAAE;IAC9D,EAAE,EAAE,EAAE,+BAAc,EAAE,IAAI,EAAE,iCAAgB,EAAE;CAC/C,CAAA;AACD,kBAAe,aAAa,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.down = exports.up = void 0;
|
|
4
|
+
async function up(knex) {
|
|
5
|
+
// Create the new transactions table
|
|
6
|
+
await knex.schema.createTable('transactions', table => {
|
|
7
|
+
table.increments();
|
|
8
|
+
table.specificType('beef', 'longblob');
|
|
9
|
+
table.string('txid', 64).unique();
|
|
10
|
+
});
|
|
11
|
+
// Move data from outputs table to the new transactions table and ensure deduplication
|
|
12
|
+
await knex.raw(`
|
|
13
|
+
INSERT IGNORE INTO transactions (txid, beef)
|
|
14
|
+
SELECT txid, beef
|
|
15
|
+
FROM outputs
|
|
16
|
+
WHERE beef IS NOT NULL
|
|
17
|
+
`);
|
|
18
|
+
// Drop the beef column from the outputs table
|
|
19
|
+
await knex.schema.table('outputs', table => {
|
|
20
|
+
table.dropColumn('beef');
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.up = up;
|
|
24
|
+
async function down(knex) {
|
|
25
|
+
// Add the beef column back to the outputs table
|
|
26
|
+
await knex.schema.table('outputs', table => {
|
|
27
|
+
table.binary('beef');
|
|
28
|
+
});
|
|
29
|
+
// Move data back from the transactions table to the outputs table using a JOIN
|
|
30
|
+
await knex.raw(`
|
|
31
|
+
UPDATE outputs
|
|
32
|
+
JOIN transactions ON outputs.txid = transactions.txid
|
|
33
|
+
SET outputs.beef = transactions.beef
|
|
34
|
+
`);
|
|
35
|
+
// Drop the transactions table
|
|
36
|
+
await knex.schema.dropTable('transactions');
|
|
37
|
+
}
|
|
38
|
+
exports.down = down;
|
|
39
|
+
//# sourceMappingURL=2024-07-17-001-transactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"2024-07-17-001-transactions.js","sourceRoot":"","sources":["../../../../../../src/storage/knex/migrations/2024-07-17-001-transactions.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,EAAE,CAAC,IAAU;IACjC,oCAAoC;IACpC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,cAAc,EAAE,KAAK,CAAC,EAAE;QACpD,KAAK,CAAC,UAAU,EAAE,CAAA;QAClB,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;QACtC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAA;IACnC,CAAC,CAAC,CAAA;IAEF,sFAAsF;IACtF,MAAM,IAAI,CAAC,GAAG,CAAC;;;;;GAKd,CAAC,CAAA;IAEF,8CAA8C;IAC9C,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE;QACzC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAC1B,CAAC,CAAC,CAAA;AACJ,CAAC;AApBD,gBAoBC;AAEM,KAAK,UAAU,IAAI,CAAC,IAAU;IACnC,gDAAgD;IAChD,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE;QACzC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;IAEF,+EAA+E;IAC/E,MAAM,IAAI,CAAC,GAAG,CAAC;;;;GAId,CAAC,CAAA;IAEF,8BAA8B;IAC9B,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;AAC7C,CAAC;AAfD,oBAeC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.down = exports.up = void 0;
|
|
4
|
+
async function up(knex) {
|
|
5
|
+
// Add index for applied_transactions table
|
|
6
|
+
await knex.schema.table('applied_transactions', function (table) {
|
|
7
|
+
table.index(['txid', 'topic'], 'idx_applied_transactions_txid_topic');
|
|
8
|
+
});
|
|
9
|
+
// Add index for transactions table
|
|
10
|
+
await knex.schema.table('transactions', function (table) {
|
|
11
|
+
table.index('txid', 'idx_transactions_txid');
|
|
12
|
+
});
|
|
13
|
+
// Add index for outputs table
|
|
14
|
+
await knex.schema.table('outputs', function (table) {
|
|
15
|
+
table.index(['txid', 'outputIndex', 'topic'], 'idx_outputs_txid_outputIndex_topic');
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.up = up;
|
|
19
|
+
async function down(knex) {
|
|
20
|
+
// Drop index for applied_transactions table
|
|
21
|
+
await knex.schema.table('applied_transactions', function (table) {
|
|
22
|
+
table.dropIndex(['txid', 'topic'], 'idx_applied_transactions_txid_topic');
|
|
23
|
+
});
|
|
24
|
+
// Drop index for transactions table
|
|
25
|
+
await knex.schema.table('transactions', function (table) {
|
|
26
|
+
table.dropIndex('txid', 'idx_transactions_txid');
|
|
27
|
+
});
|
|
28
|
+
// Drop index for outputs table
|
|
29
|
+
await knex.schema.table('outputs', function (table) {
|
|
30
|
+
table.dropIndex(['txid', 'outputIndex', 'topic'], 'idx_outputs_txid_outputIndex_topic');
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.down = down;
|
|
34
|
+
//# sourceMappingURL=2024-07-18-001-indexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"2024-07-18-001-indexes.js","sourceRoot":"","sources":["../../../../../../src/storage/knex/migrations/2024-07-18-001-indexes.ts"],"names":[],"mappings":";;;AACO,KAAK,UAAU,EAAE,CAAC,IAAU;IACjC,2CAA2C;IAC3C,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,UAAU,KAAK;QAC7D,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,qCAAqC,CAAC,CAAA;IACvE,CAAC,CAAC,CAAA;IACF,mCAAmC;IACnC,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU,KAAK;QACrD,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAA;IAC9C,CAAC,CAAC,CAAA;IACF,8BAA8B;IAC9B,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,KAAK;QAChD,KA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