@ocap/indexdb-sqlite 1.29.5
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/README.md +84 -0
- package/esm/_virtual/rolldown_runtime.mjs +21 -0
- package/esm/db/base.d.mts +76 -0
- package/esm/db/base.mjs +666 -0
- package/esm/db/index.d.mts +80 -0
- package/esm/db/index.mjs +551 -0
- package/esm/index.d.mts +3 -0
- package/esm/index.mjs +8 -0
- package/esm/interfaces.d.mts +328 -0
- package/esm/interfaces.mjs +1 -0
- package/esm/kysely.d.mts +43 -0
- package/esm/kysely.mjs +62 -0
- package/esm/migrations/001-genesis.d.mts +14 -0
- package/esm/migrations/001-genesis.mjs +107 -0
- package/esm/migrations/index.d.mts +16 -0
- package/esm/migrations/index.mjs +44 -0
- package/esm/package.mjs +70 -0
- package/esm/table/base.d.mts +107 -0
- package/esm/table/base.mjs +262 -0
- package/esm/table/transaction.d.mts +18 -0
- package/esm/table/transaction.mjs +22 -0
- package/lib/_virtual/rolldown_runtime.cjs +43 -0
- package/lib/db/base.cjs +670 -0
- package/lib/db/base.d.cts +76 -0
- package/lib/db/index.cjs +552 -0
- package/lib/db/index.d.cts +80 -0
- package/lib/index.cjs +10 -0
- package/lib/index.d.cts +3 -0
- package/lib/interfaces.cjs +0 -0
- package/lib/interfaces.d.cts +328 -0
- package/lib/kysely.cjs +63 -0
- package/lib/kysely.d.cts +43 -0
- package/lib/migrations/001-genesis.cjs +114 -0
- package/lib/migrations/001-genesis.d.cts +14 -0
- package/lib/migrations/index.cjs +46 -0
- package/lib/migrations/index.d.cts +16 -0
- package/lib/package.cjs +76 -0
- package/lib/table/base.cjs +265 -0
- package/lib/table/base.d.cts +107 -0
- package/lib/table/transaction.cjs +24 -0
- package/lib/table/transaction.d.cts +18 -0
- package/package.json +75 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Database } from "../interfaces.cjs";
|
|
2
|
+
import { BaseIndexDB } from "@ocap/indexdb";
|
|
3
|
+
import { IIndexDB, IIndexTable, IListAccountsResult, IListAssetsResult, IListDelegationsResult, IListFactoriesResult, IListRollupBlocksResult, IListRollupValidatorsResult, IListRollupsResult, IListStakesResult, IListTokenFactoriesResult, IListTokensResult, IListTransactionsResult, IndexTableTypeMap, TRequestListAssets, TRequestListDelegations, TRequestListFactories, TRequestListRollupBlocks, TRequestListRollupValidators, TRequestListRollups, TRequestListStakes, TRequestListTokenFactories, TRequestListTokens, TRequestListTopAccounts, TRequestListTransactions } from "@ocap/types";
|
|
4
|
+
import { Kysely } from "kysely";
|
|
5
|
+
|
|
6
|
+
//#region src/db/base.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Base SQLite IndexDB implementation
|
|
10
|
+
* Contains all the list methods with SQL-based filtering
|
|
11
|
+
*/
|
|
12
|
+
declare class SqliteBaseIndexDB extends BaseIndexDB implements IIndexDB {
|
|
13
|
+
protected db: Kysely<Database>;
|
|
14
|
+
tx: IIndexTable<IndexTableTypeMap['tx']>;
|
|
15
|
+
account: IIndexTable<IndexTableTypeMap['account']>;
|
|
16
|
+
asset: IIndexTable<IndexTableTypeMap['asset']>;
|
|
17
|
+
token: IIndexTable<IndexTableTypeMap['token']>;
|
|
18
|
+
factory: IIndexTable<IndexTableTypeMap['factory']>;
|
|
19
|
+
stake: IIndexTable<IndexTableTypeMap['stake']>;
|
|
20
|
+
delegation: IIndexTable<IndexTableTypeMap['delegation']>;
|
|
21
|
+
rollup: IIndexTable<IndexTableTypeMap['rollup']>;
|
|
22
|
+
rollupBlock: IIndexTable<IndexTableTypeMap['rollupBlock']>;
|
|
23
|
+
rollupValidator: IIndexTable<IndexTableTypeMap['rollupValidator']>;
|
|
24
|
+
tokenDistribution: IIndexTable<IndexTableTypeMap['tokenDistribution']>;
|
|
25
|
+
tokenFactory: IIndexTable<IndexTableTypeMap['tokenFactory']>;
|
|
26
|
+
/**
|
|
27
|
+
* List transactions with filtering and pagination
|
|
28
|
+
*/
|
|
29
|
+
listTransactions(params?: Partial<TRequestListTransactions>): Promise<IListTransactionsResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Get related addresses for account migration tracking
|
|
32
|
+
*/
|
|
33
|
+
getRelatedAddresses(address: string): Promise<string[]>;
|
|
34
|
+
/**
|
|
35
|
+
* List assets with filtering and pagination
|
|
36
|
+
*/
|
|
37
|
+
listAssets(params?: Partial<TRequestListAssets>): Promise<IListAssetsResult>;
|
|
38
|
+
/**
|
|
39
|
+
* List top accounts by token balance
|
|
40
|
+
*/
|
|
41
|
+
listTopAccounts(params?: Partial<TRequestListTopAccounts>): Promise<IListAccountsResult>;
|
|
42
|
+
/**
|
|
43
|
+
* List tokens with filtering and pagination
|
|
44
|
+
*/
|
|
45
|
+
listTokens(params?: Partial<TRequestListTokens>): Promise<IListTokensResult>;
|
|
46
|
+
/**
|
|
47
|
+
* List token factories (bonding curve)
|
|
48
|
+
*/
|
|
49
|
+
listTokenFactories(params?: Partial<TRequestListTokenFactories>): Promise<IListTokenFactoriesResult>;
|
|
50
|
+
/**
|
|
51
|
+
* List asset factories
|
|
52
|
+
*/
|
|
53
|
+
listFactories(params?: Partial<TRequestListFactories>): Promise<IListFactoriesResult>;
|
|
54
|
+
/**
|
|
55
|
+
* List stakes
|
|
56
|
+
*/
|
|
57
|
+
listStakes(params?: Partial<TRequestListStakes>): Promise<IListStakesResult>;
|
|
58
|
+
/**
|
|
59
|
+
* List rollups
|
|
60
|
+
*/
|
|
61
|
+
listRollups(params?: Partial<TRequestListRollups>): Promise<IListRollupsResult>;
|
|
62
|
+
/**
|
|
63
|
+
* List rollup blocks
|
|
64
|
+
*/
|
|
65
|
+
listRollupBlocks(params?: Partial<TRequestListRollupBlocks>): Promise<IListRollupBlocksResult>;
|
|
66
|
+
/**
|
|
67
|
+
* List rollup validators
|
|
68
|
+
*/
|
|
69
|
+
listRollupValidators(params?: Partial<TRequestListRollupValidators>): Promise<IListRollupValidatorsResult>;
|
|
70
|
+
/**
|
|
71
|
+
* List delegations
|
|
72
|
+
*/
|
|
73
|
+
listDelegations(params?: Partial<TRequestListDelegations>): Promise<IListDelegationsResult>;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { SqliteBaseIndexDB as default };
|
package/lib/db/index.cjs
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_kysely = require('../kysely.cjs');
|
|
3
|
+
const require_migrations_index = require('../migrations/index.cjs');
|
|
4
|
+
const require_table_base = require('../table/base.cjs');
|
|
5
|
+
const require_table_transaction = require('../table/transaction.cjs');
|
|
6
|
+
const require_db_base = require('./base.cjs');
|
|
7
|
+
const require_package = require('../package.cjs');
|
|
8
|
+
|
|
9
|
+
//#region src/db/index.ts
|
|
10
|
+
const { name, version } = require_package.default;
|
|
11
|
+
/**
|
|
12
|
+
* SQLite IndexDB Implementation
|
|
13
|
+
* Uses SQLite via Kysely as the storage backend for indexed blockchain data
|
|
14
|
+
*/
|
|
15
|
+
var SqliteIndexDB = class extends require_db_base.default {
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instance of SqliteIndexDB
|
|
18
|
+
*
|
|
19
|
+
* @param config - SQLite configuration (defaults to in-memory)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // In-memory database for testing
|
|
24
|
+
* const db = new SqliteIndexDB();
|
|
25
|
+
* await db.initialize();
|
|
26
|
+
*
|
|
27
|
+
* // File-based database for production
|
|
28
|
+
* const db = new SqliteIndexDB({ filename: './data/index.sqlite' });
|
|
29
|
+
* await db.initialize();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
constructor(config = { filename: ":memory:" }) {
|
|
33
|
+
super();
|
|
34
|
+
this.initialized = false;
|
|
35
|
+
this.name = name;
|
|
36
|
+
this.version = version;
|
|
37
|
+
this.config = config;
|
|
38
|
+
this.initSync();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Synchronous initialization
|
|
42
|
+
* Called from constructor for immediate table availability
|
|
43
|
+
*/
|
|
44
|
+
initSync() {
|
|
45
|
+
this.db = require_kysely.createKysely(this.config);
|
|
46
|
+
this.tx = new require_table_transaction.default({
|
|
47
|
+
name: "tx",
|
|
48
|
+
uniqIndex: "hash",
|
|
49
|
+
db: this.db,
|
|
50
|
+
schema: {
|
|
51
|
+
jsonFields: [
|
|
52
|
+
"receipts",
|
|
53
|
+
"tx",
|
|
54
|
+
"accounts",
|
|
55
|
+
"assets",
|
|
56
|
+
"tokens",
|
|
57
|
+
"tokenSymbols",
|
|
58
|
+
"factories",
|
|
59
|
+
"rollups",
|
|
60
|
+
"stakes",
|
|
61
|
+
"delegations",
|
|
62
|
+
"tokenFactories",
|
|
63
|
+
"data"
|
|
64
|
+
],
|
|
65
|
+
booleanFields: [
|
|
66
|
+
"receiptsVerified",
|
|
67
|
+
"finalized",
|
|
68
|
+
"valid"
|
|
69
|
+
],
|
|
70
|
+
columnMapping: { index: "index_" },
|
|
71
|
+
knownColumns: [
|
|
72
|
+
"hash",
|
|
73
|
+
"code",
|
|
74
|
+
"height",
|
|
75
|
+
"index",
|
|
76
|
+
"receipts",
|
|
77
|
+
"receiptsVerified",
|
|
78
|
+
"receiver",
|
|
79
|
+
"sender",
|
|
80
|
+
"time",
|
|
81
|
+
"tx",
|
|
82
|
+
"type",
|
|
83
|
+
"finalized",
|
|
84
|
+
"valid",
|
|
85
|
+
"accounts",
|
|
86
|
+
"assets",
|
|
87
|
+
"tokens",
|
|
88
|
+
"tokenSymbols",
|
|
89
|
+
"factories",
|
|
90
|
+
"rollups",
|
|
91
|
+
"stakes",
|
|
92
|
+
"delegations",
|
|
93
|
+
"tokenFactories",
|
|
94
|
+
"genesisTime",
|
|
95
|
+
"renaissanceTime",
|
|
96
|
+
"data"
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
this.account = new require_table_base.default({
|
|
101
|
+
name: "account",
|
|
102
|
+
uniqIndex: "address",
|
|
103
|
+
db: this.db,
|
|
104
|
+
schema: {
|
|
105
|
+
jsonFields: [
|
|
106
|
+
"stake",
|
|
107
|
+
"tokens",
|
|
108
|
+
"data"
|
|
109
|
+
],
|
|
110
|
+
numericFields: { balance: "balanceNum" },
|
|
111
|
+
knownColumns: [
|
|
112
|
+
"address",
|
|
113
|
+
"balance",
|
|
114
|
+
"gasBalance",
|
|
115
|
+
"moniker",
|
|
116
|
+
"pk",
|
|
117
|
+
"nonce",
|
|
118
|
+
"numTxs",
|
|
119
|
+
"numAssets",
|
|
120
|
+
"issuer",
|
|
121
|
+
"migratedTo",
|
|
122
|
+
"migratedFrom",
|
|
123
|
+
"stake",
|
|
124
|
+
"tokens",
|
|
125
|
+
"data",
|
|
126
|
+
"genesisTime",
|
|
127
|
+
"renaissanceTime"
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
this.asset = new require_table_base.default({
|
|
132
|
+
name: "asset",
|
|
133
|
+
uniqIndex: "address",
|
|
134
|
+
db: this.db,
|
|
135
|
+
schema: {
|
|
136
|
+
jsonFields: [
|
|
137
|
+
"display",
|
|
138
|
+
"tags",
|
|
139
|
+
"stake",
|
|
140
|
+
"data"
|
|
141
|
+
],
|
|
142
|
+
booleanFields: ["readonly", "transferrable"],
|
|
143
|
+
knownColumns: [
|
|
144
|
+
"address",
|
|
145
|
+
"owner",
|
|
146
|
+
"moniker",
|
|
147
|
+
"readonly",
|
|
148
|
+
"transferrable",
|
|
149
|
+
"issuer",
|
|
150
|
+
"parent",
|
|
151
|
+
"ttl",
|
|
152
|
+
"consumedTime",
|
|
153
|
+
"endpoint",
|
|
154
|
+
"display",
|
|
155
|
+
"tags",
|
|
156
|
+
"stake",
|
|
157
|
+
"data",
|
|
158
|
+
"genesisTime",
|
|
159
|
+
"renaissanceTime"
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
this.token = new require_table_base.default({
|
|
164
|
+
name: "token",
|
|
165
|
+
uniqIndex: "address",
|
|
166
|
+
db: this.db,
|
|
167
|
+
schema: {
|
|
168
|
+
jsonFields: [
|
|
169
|
+
"foreignToken",
|
|
170
|
+
"metadata",
|
|
171
|
+
"spenders",
|
|
172
|
+
"minters",
|
|
173
|
+
"data"
|
|
174
|
+
],
|
|
175
|
+
numericFields: { totalSupply: "totalSupplyNum" },
|
|
176
|
+
knownColumns: [
|
|
177
|
+
"address",
|
|
178
|
+
"symbol",
|
|
179
|
+
"name",
|
|
180
|
+
"decimal",
|
|
181
|
+
"unit",
|
|
182
|
+
"description",
|
|
183
|
+
"icon",
|
|
184
|
+
"totalSupply",
|
|
185
|
+
"initialSupply",
|
|
186
|
+
"maxTotalSupply",
|
|
187
|
+
"foreignToken",
|
|
188
|
+
"issuer",
|
|
189
|
+
"website",
|
|
190
|
+
"metadata",
|
|
191
|
+
"tokenFactoryAddress",
|
|
192
|
+
"spenders",
|
|
193
|
+
"minters",
|
|
194
|
+
"type",
|
|
195
|
+
"data",
|
|
196
|
+
"genesisTime",
|
|
197
|
+
"renaissanceTime"
|
|
198
|
+
]
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
this.factory = new require_table_base.default({
|
|
202
|
+
name: "factory",
|
|
203
|
+
uniqIndex: "address",
|
|
204
|
+
db: this.db,
|
|
205
|
+
schema: {
|
|
206
|
+
jsonFields: [
|
|
207
|
+
"trustedIssuers",
|
|
208
|
+
"tokens",
|
|
209
|
+
"input",
|
|
210
|
+
"output",
|
|
211
|
+
"display",
|
|
212
|
+
"hooks",
|
|
213
|
+
"data"
|
|
214
|
+
],
|
|
215
|
+
columnMapping: { limit: "limit_" },
|
|
216
|
+
knownColumns: [
|
|
217
|
+
"address",
|
|
218
|
+
"owner",
|
|
219
|
+
"name",
|
|
220
|
+
"description",
|
|
221
|
+
"settlement",
|
|
222
|
+
"limit",
|
|
223
|
+
"trustedIssuers",
|
|
224
|
+
"tokens",
|
|
225
|
+
"numMinted",
|
|
226
|
+
"lastSettlement",
|
|
227
|
+
"input",
|
|
228
|
+
"output",
|
|
229
|
+
"display",
|
|
230
|
+
"hooks",
|
|
231
|
+
"data",
|
|
232
|
+
"genesisTime",
|
|
233
|
+
"renaissanceTime"
|
|
234
|
+
]
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
this.tokenFactory = new require_table_base.default({
|
|
238
|
+
name: "tokenFactory",
|
|
239
|
+
uniqIndex: "address",
|
|
240
|
+
db: this.db,
|
|
241
|
+
schema: {
|
|
242
|
+
jsonFields: [
|
|
243
|
+
"curve",
|
|
244
|
+
"token",
|
|
245
|
+
"reserveToken",
|
|
246
|
+
"input",
|
|
247
|
+
"output",
|
|
248
|
+
"data"
|
|
249
|
+
],
|
|
250
|
+
numericFields: {
|
|
251
|
+
reserveBalance: "reserveBalanceNum",
|
|
252
|
+
currentSupply: "currentSupplyNum"
|
|
253
|
+
},
|
|
254
|
+
knownColumns: [
|
|
255
|
+
"address",
|
|
256
|
+
"owner",
|
|
257
|
+
"name",
|
|
258
|
+
"description",
|
|
259
|
+
"moniker",
|
|
260
|
+
"status",
|
|
261
|
+
"curve",
|
|
262
|
+
"tokenAddress",
|
|
263
|
+
"reserveAddress",
|
|
264
|
+
"reserveBalance",
|
|
265
|
+
"currentSupply",
|
|
266
|
+
"feeRate",
|
|
267
|
+
"token",
|
|
268
|
+
"reserveToken",
|
|
269
|
+
"input",
|
|
270
|
+
"output",
|
|
271
|
+
"data",
|
|
272
|
+
"genesisTime",
|
|
273
|
+
"renaissanceTime"
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
this.stake = new require_table_base.default({
|
|
278
|
+
name: "stake",
|
|
279
|
+
uniqIndex: "address",
|
|
280
|
+
db: this.db,
|
|
281
|
+
schema: {
|
|
282
|
+
jsonFields: [
|
|
283
|
+
"tokens",
|
|
284
|
+
"revokedTokens",
|
|
285
|
+
"assets",
|
|
286
|
+
"revokedAssets",
|
|
287
|
+
"slashers",
|
|
288
|
+
"data"
|
|
289
|
+
],
|
|
290
|
+
booleanFields: ["revocable"],
|
|
291
|
+
knownColumns: [
|
|
292
|
+
"address",
|
|
293
|
+
"sender",
|
|
294
|
+
"receiver",
|
|
295
|
+
"revocable",
|
|
296
|
+
"tokens",
|
|
297
|
+
"revokedTokens",
|
|
298
|
+
"assets",
|
|
299
|
+
"revokedAssets",
|
|
300
|
+
"slashers",
|
|
301
|
+
"nonce",
|
|
302
|
+
"revokeWaitingPeriod",
|
|
303
|
+
"message",
|
|
304
|
+
"data",
|
|
305
|
+
"genesisTime",
|
|
306
|
+
"renaissanceTime"
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
this.delegation = new require_table_base.default({
|
|
311
|
+
name: "delegation",
|
|
312
|
+
uniqIndex: "address",
|
|
313
|
+
db: this.db,
|
|
314
|
+
schema: {
|
|
315
|
+
jsonFields: [
|
|
316
|
+
"ops",
|
|
317
|
+
"context",
|
|
318
|
+
"data"
|
|
319
|
+
],
|
|
320
|
+
columnMapping: {
|
|
321
|
+
from: "from_",
|
|
322
|
+
to: "to_"
|
|
323
|
+
},
|
|
324
|
+
knownColumns: [
|
|
325
|
+
"address",
|
|
326
|
+
"from",
|
|
327
|
+
"to",
|
|
328
|
+
"ops",
|
|
329
|
+
"context",
|
|
330
|
+
"data",
|
|
331
|
+
"genesisTime",
|
|
332
|
+
"renaissanceTime"
|
|
333
|
+
]
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
this.rollup = new require_table_base.default({
|
|
337
|
+
name: "rollup",
|
|
338
|
+
uniqIndex: "address",
|
|
339
|
+
db: this.db,
|
|
340
|
+
schema: {
|
|
341
|
+
jsonFields: [
|
|
342
|
+
"seedValidators",
|
|
343
|
+
"validators",
|
|
344
|
+
"foreignToken",
|
|
345
|
+
"tokenInfo",
|
|
346
|
+
"migrateHistory",
|
|
347
|
+
"vaultHistory",
|
|
348
|
+
"data"
|
|
349
|
+
],
|
|
350
|
+
booleanFields: ["paused", "closed"],
|
|
351
|
+
knownColumns: [
|
|
352
|
+
"address",
|
|
353
|
+
"tokenAddress",
|
|
354
|
+
"vaultAddress",
|
|
355
|
+
"contractAddress",
|
|
356
|
+
"paused",
|
|
357
|
+
"closed",
|
|
358
|
+
"seedValidators",
|
|
359
|
+
"validators",
|
|
360
|
+
"blockHash",
|
|
361
|
+
"issuer",
|
|
362
|
+
"foreignToken",
|
|
363
|
+
"minStakeAmount",
|
|
364
|
+
"maxStakeAmount",
|
|
365
|
+
"minSignerCount",
|
|
366
|
+
"maxSignerCount",
|
|
367
|
+
"minBlockSize",
|
|
368
|
+
"maxBlockSize",
|
|
369
|
+
"minBlockInterval",
|
|
370
|
+
"leaveWaitingPeriod",
|
|
371
|
+
"publishWaitingPeriod",
|
|
372
|
+
"publishSlashRate",
|
|
373
|
+
"tokenInfo",
|
|
374
|
+
"depositFeeRate",
|
|
375
|
+
"withdrawFeeRate",
|
|
376
|
+
"proposerFeeShare",
|
|
377
|
+
"publisherFeeShare",
|
|
378
|
+
"minDepositAmount",
|
|
379
|
+
"minWithdrawAmount",
|
|
380
|
+
"totalDepositAmount",
|
|
381
|
+
"totalWithdrawAmount",
|
|
382
|
+
"migrateHistory",
|
|
383
|
+
"vaultHistory",
|
|
384
|
+
"data",
|
|
385
|
+
"genesisTime",
|
|
386
|
+
"renaissanceTime"
|
|
387
|
+
]
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
this.rollupBlock = new require_table_base.default({
|
|
391
|
+
name: "rollupBlock",
|
|
392
|
+
uniqIndex: "hash",
|
|
393
|
+
db: this.db,
|
|
394
|
+
schema: {
|
|
395
|
+
jsonFields: [
|
|
396
|
+
"signatures",
|
|
397
|
+
"txs",
|
|
398
|
+
"validators",
|
|
399
|
+
"tokenInfo",
|
|
400
|
+
"data"
|
|
401
|
+
],
|
|
402
|
+
booleanFields: ["governance"],
|
|
403
|
+
knownColumns: [
|
|
404
|
+
"hash",
|
|
405
|
+
"rollup",
|
|
406
|
+
"height",
|
|
407
|
+
"merkleRoot",
|
|
408
|
+
"previousHash",
|
|
409
|
+
"txsHash",
|
|
410
|
+
"txs",
|
|
411
|
+
"proposer",
|
|
412
|
+
"signatures",
|
|
413
|
+
"rewardAmount",
|
|
414
|
+
"mintedAmount",
|
|
415
|
+
"burnedAmount",
|
|
416
|
+
"minReward",
|
|
417
|
+
"validators",
|
|
418
|
+
"tokenInfo",
|
|
419
|
+
"governance",
|
|
420
|
+
"data",
|
|
421
|
+
"genesisTime",
|
|
422
|
+
"renaissanceTime"
|
|
423
|
+
]
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
this.rollupValidator = new require_table_base.default({
|
|
427
|
+
name: "rollupValidator",
|
|
428
|
+
uniqIndex: "address",
|
|
429
|
+
db: this.db,
|
|
430
|
+
schema: {
|
|
431
|
+
jsonFields: ["data"],
|
|
432
|
+
knownColumns: [
|
|
433
|
+
"address",
|
|
434
|
+
"rollup",
|
|
435
|
+
"pk",
|
|
436
|
+
"moniker",
|
|
437
|
+
"endpoint",
|
|
438
|
+
"joinTime",
|
|
439
|
+
"leaveTime",
|
|
440
|
+
"genesisTime",
|
|
441
|
+
"renaissanceTime",
|
|
442
|
+
"totalStake",
|
|
443
|
+
"availableStake",
|
|
444
|
+
"revokedStake",
|
|
445
|
+
"totalGain",
|
|
446
|
+
"proposedBlockCount",
|
|
447
|
+
"verifiedBlockCount",
|
|
448
|
+
"latestBlockHeight",
|
|
449
|
+
"latestBlockHash",
|
|
450
|
+
"data"
|
|
451
|
+
]
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
this.tokenDistribution = new require_table_base.default({
|
|
455
|
+
name: "tokenDistribution",
|
|
456
|
+
uniqIndex: "tokenAddress",
|
|
457
|
+
db: this.db,
|
|
458
|
+
schema: {
|
|
459
|
+
jsonFields: ["distribution", "data"],
|
|
460
|
+
knownColumns: [
|
|
461
|
+
"tokenAddress",
|
|
462
|
+
"holders",
|
|
463
|
+
"distribution",
|
|
464
|
+
"stake",
|
|
465
|
+
"gasStake",
|
|
466
|
+
"revokedStake",
|
|
467
|
+
"gas",
|
|
468
|
+
"fee",
|
|
469
|
+
"slashedVault",
|
|
470
|
+
"account",
|
|
471
|
+
"txTime",
|
|
472
|
+
"genesisTime",
|
|
473
|
+
"renaissanceTime",
|
|
474
|
+
"data"
|
|
475
|
+
]
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
this.balance = new require_table_base.default({
|
|
479
|
+
name: "balance",
|
|
480
|
+
uniqIndex: ["address", "tokenAddress"],
|
|
481
|
+
db: this.db,
|
|
482
|
+
schema: {
|
|
483
|
+
jsonFields: ["data"],
|
|
484
|
+
numericFields: { balance: "balanceNum" },
|
|
485
|
+
knownColumns: [
|
|
486
|
+
"address",
|
|
487
|
+
"tokenAddress",
|
|
488
|
+
"balance",
|
|
489
|
+
"data"
|
|
490
|
+
]
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
this.attachReadyListeners();
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Async initialization - runs migrations
|
|
497
|
+
* Call this after constructor to ensure database schema is ready
|
|
498
|
+
*/
|
|
499
|
+
async initialize() {
|
|
500
|
+
if (this.initialized) return;
|
|
501
|
+
await require_migrations_index.runMigrations(this.db);
|
|
502
|
+
this.initialized = true;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Execute multiple operations within a database transaction
|
|
506
|
+
*
|
|
507
|
+
* @param fn - Function receiving Kysely transaction object
|
|
508
|
+
* @returns Result of the transaction function
|
|
509
|
+
*/
|
|
510
|
+
async runAsLambda(fn) {
|
|
511
|
+
return this.db.transaction().execute(fn);
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Reset all tables (for testing)
|
|
515
|
+
*/
|
|
516
|
+
async reset() {
|
|
517
|
+
for (const table of [
|
|
518
|
+
"tx",
|
|
519
|
+
"account",
|
|
520
|
+
"asset",
|
|
521
|
+
"token",
|
|
522
|
+
"factory",
|
|
523
|
+
"tokenFactory",
|
|
524
|
+
"stake",
|
|
525
|
+
"delegation",
|
|
526
|
+
"rollup",
|
|
527
|
+
"rollupBlock",
|
|
528
|
+
"rollupValidator",
|
|
529
|
+
"tokenDistribution",
|
|
530
|
+
"balance"
|
|
531
|
+
]) {
|
|
532
|
+
const tableInstance = this[table];
|
|
533
|
+
if (tableInstance?.reset) await tableInstance.reset();
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Close database connection
|
|
538
|
+
*/
|
|
539
|
+
async close() {
|
|
540
|
+
await this.db.destroy();
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Get the underlying Kysely instance (for advanced operations)
|
|
544
|
+
*/
|
|
545
|
+
getKysely() {
|
|
546
|
+
return this.db;
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
var db_default = SqliteIndexDB;
|
|
550
|
+
|
|
551
|
+
//#endregion
|
|
552
|
+
exports.default = db_default;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Database } from "../interfaces.cjs";
|
|
2
|
+
import SqliteBaseIndexDB from "./base.cjs";
|
|
3
|
+
import { SqliteConfig } from "../kysely.cjs";
|
|
4
|
+
import { IIndexDB, IIndexTable, IndexTableTypeMap } from "@ocap/types";
|
|
5
|
+
import { Kysely, Transaction } from "kysely";
|
|
6
|
+
|
|
7
|
+
//#region src/db/index.d.ts
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* SQLite IndexDB Implementation
|
|
11
|
+
* Uses SQLite via Kysely as the storage backend for indexed blockchain data
|
|
12
|
+
*/
|
|
13
|
+
declare class SqliteIndexDB extends SqliteBaseIndexDB implements IIndexDB {
|
|
14
|
+
name: string;
|
|
15
|
+
version: string;
|
|
16
|
+
protected db: Kysely<Database>;
|
|
17
|
+
private config;
|
|
18
|
+
private initialized;
|
|
19
|
+
tx: IIndexTable<IndexTableTypeMap['tx']>;
|
|
20
|
+
account: IIndexTable<IndexTableTypeMap['account']>;
|
|
21
|
+
asset: IIndexTable<IndexTableTypeMap['asset']>;
|
|
22
|
+
token: IIndexTable<IndexTableTypeMap['token']>;
|
|
23
|
+
factory: IIndexTable<IndexTableTypeMap['factory']>;
|
|
24
|
+
stake: IIndexTable<IndexTableTypeMap['stake']>;
|
|
25
|
+
delegation: IIndexTable<IndexTableTypeMap['delegation']>;
|
|
26
|
+
rollup: IIndexTable<IndexTableTypeMap['rollup']>;
|
|
27
|
+
rollupBlock: IIndexTable<IndexTableTypeMap['rollupBlock']>;
|
|
28
|
+
rollupValidator: IIndexTable<IndexTableTypeMap['rollupValidator']>;
|
|
29
|
+
tokenDistribution: IIndexTable<IndexTableTypeMap['tokenDistribution']>;
|
|
30
|
+
tokenFactory: IIndexTable<IndexTableTypeMap['tokenFactory']>;
|
|
31
|
+
balance: IIndexTable<IndexTableTypeMap['tokenDistribution']>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates an instance of SqliteIndexDB
|
|
34
|
+
*
|
|
35
|
+
* @param config - SQLite configuration (defaults to in-memory)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // In-memory database for testing
|
|
40
|
+
* const db = new SqliteIndexDB();
|
|
41
|
+
* await db.initialize();
|
|
42
|
+
*
|
|
43
|
+
* // File-based database for production
|
|
44
|
+
* const db = new SqliteIndexDB({ filename: './data/index.sqlite' });
|
|
45
|
+
* await db.initialize();
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
constructor(config?: SqliteConfig);
|
|
49
|
+
/**
|
|
50
|
+
* Synchronous initialization
|
|
51
|
+
* Called from constructor for immediate table availability
|
|
52
|
+
*/
|
|
53
|
+
private initSync;
|
|
54
|
+
/**
|
|
55
|
+
* Async initialization - runs migrations
|
|
56
|
+
* Call this after constructor to ensure database schema is ready
|
|
57
|
+
*/
|
|
58
|
+
initialize(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Execute multiple operations within a database transaction
|
|
61
|
+
*
|
|
62
|
+
* @param fn - Function receiving Kysely transaction object
|
|
63
|
+
* @returns Result of the transaction function
|
|
64
|
+
*/
|
|
65
|
+
runAsLambda<T>(fn: (txn: Transaction<Database>) => T | Promise<T>): Promise<T>;
|
|
66
|
+
/**
|
|
67
|
+
* Reset all tables (for testing)
|
|
68
|
+
*/
|
|
69
|
+
reset(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Close database connection
|
|
72
|
+
*/
|
|
73
|
+
close(): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Get the underlying Kysely instance (for advanced operations)
|
|
76
|
+
*/
|
|
77
|
+
getKysely(): Kysely<Database>;
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { SqliteIndexDB as default };
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_db_base = require('./db/base.cjs');
|
|
3
|
+
const require_db_index = require('./db/index.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
var src_default = require_db_index.default;
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.SqliteBaseIndexDB = require_db_base.default;
|
|
10
|
+
exports.default = src_default;
|