@bsv/wallet-toolbox 1.6.22 → 1.6.24
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/CHANGELOG.md +11 -0
- package/docs/client.md +300 -167
- package/docs/monitor.md +126 -23
- package/docs/services.md +86 -37
- package/docs/wallet.md +300 -167
- package/mobile/out/src/CWIStyleWalletManager.d.ts +1 -0
- package/mobile/out/src/CWIStyleWalletManager.d.ts.map +1 -1
- package/mobile/out/src/CWIStyleWalletManager.js +4 -2
- package/mobile/out/src/CWIStyleWalletManager.js.map +1 -1
- package/mobile/out/src/index.mobile.d.ts +1 -1
- package/mobile/out/src/index.mobile.js +1 -1
- package/mobile/out/src/monitor/Monitor.d.ts +32 -8
- package/mobile/out/src/monitor/Monitor.d.ts.map +1 -1
- package/mobile/out/src/monitor/Monitor.js +59 -28
- package/mobile/out/src/monitor/Monitor.js.map +1 -1
- package/mobile/out/src/monitor/tasks/TaskCheckNoSends.js +2 -1
- package/mobile/out/src/monitor/tasks/TaskCheckNoSends.js.map +1 -1
- package/mobile/out/src/monitor/tasks/TaskClock.js +3 -2
- package/mobile/out/src/monitor/tasks/TaskClock.js.map +1 -1
- package/mobile/out/src/monitor/tasks/TaskMonitorCallHistory.js +2 -1
- package/mobile/out/src/monitor/tasks/TaskMonitorCallHistory.js.map +1 -1
- package/mobile/out/src/monitor/tasks/TaskNewHeader.js +2 -1
- package/mobile/out/src/monitor/tasks/TaskNewHeader.js.map +1 -1
- package/mobile/out/src/monitor/tasks/TaskReorg.d.ts +47 -0
- package/mobile/out/src/monitor/tasks/TaskReorg.d.ts.map +1 -0
- package/mobile/out/src/monitor/tasks/TaskReorg.js +135 -0
- package/mobile/out/src/monitor/tasks/TaskReorg.js.map +1 -0
- package/mobile/out/src/monitor/tasks/TaskSendWaiting.js +2 -1
- package/mobile/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -1
- package/mobile/out/src/monitor/tasks/TaskUnFail.js +2 -1
- package/mobile/out/src/monitor/tasks/TaskUnFail.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Api/ChaintracksClientApi.d.ts +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Api/ChaintracksClientApi.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Api/ChaintracksStorageApi.d.ts +4 -0
- package/mobile/out/src/services/chaintracker/chaintracks/Api/ChaintracksStorageApi.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Chaintracks.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Chaintracks.js +3 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Chaintracks.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.js +4 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.js +3 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.d.ts +5 -0
- package/mobile/out/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.d.ts.map +1 -0
- package/mobile/out/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.js +68 -0
- package/mobile/out/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.js.map +1 -0
- package/mobile/out/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.d.ts +2 -1
- package/mobile/out/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.js +59 -15
- package/mobile/out/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/createIdbChaintracks.d.ts +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/createIdbChaintracks.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/createIdbChaintracks.js +4 -61
- package/mobile/out/src/services/chaintracker/chaintracks/createIdbChaintracks.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.d.ts +13 -0
- package/mobile/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.d.ts.map +1 -0
- package/mobile/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.js +27 -0
- package/mobile/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.js.map +1 -0
- package/mobile/out/src/services/chaintracker/chaintracks/index.client.d.ts +2 -28
- package/mobile/out/src/services/chaintracker/chaintracks/index.client.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/index.client.js +2 -50
- package/mobile/out/src/services/chaintracker/chaintracks/index.client.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/index.mobile.d.ts +30 -0
- package/mobile/out/src/services/chaintracker/chaintracks/index.mobile.d.ts.map +1 -0
- package/mobile/out/src/services/chaintracker/chaintracks/index.mobile.js +68 -0
- package/mobile/out/src/services/chaintracker/chaintracks/index.mobile.js.map +1 -0
- package/mobile/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.js +11 -11
- package/mobile/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.js.map +1 -1
- package/mobile/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/createAction.js.map +1 -1
- package/mobile/package-lock.json +7 -6
- package/mobile/package.json +2 -2
- package/out/src/CWIStyleWalletManager.d.ts +1 -0
- package/out/src/CWIStyleWalletManager.d.ts.map +1 -1
- package/out/src/CWIStyleWalletManager.js +4 -2
- package/out/src/CWIStyleWalletManager.js.map +1 -1
- package/out/src/index.mobile.d.ts +1 -1
- package/out/src/index.mobile.js +1 -1
- package/out/src/monitor/Monitor.d.ts +32 -8
- package/out/src/monitor/Monitor.d.ts.map +1 -1
- package/out/src/monitor/Monitor.js +59 -28
- package/out/src/monitor/Monitor.js.map +1 -1
- package/out/src/monitor/MonitorDaemon.d.ts +2 -0
- package/out/src/monitor/MonitorDaemon.d.ts.map +1 -1
- package/out/src/monitor/MonitorDaemon.js +3 -1
- package/out/src/monitor/MonitorDaemon.js.map +1 -1
- package/out/src/monitor/__test/MonitorDaemon.man.test.js +30 -39
- package/out/src/monitor/__test/MonitorDaemon.man.test.js.map +1 -1
- package/out/src/monitor/tasks/TaskCheckNoSends.js +2 -1
- package/out/src/monitor/tasks/TaskCheckNoSends.js.map +1 -1
- package/out/src/monitor/tasks/TaskClock.js +3 -2
- package/out/src/monitor/tasks/TaskClock.js.map +1 -1
- package/out/src/monitor/tasks/TaskMonitorCallHistory.js +2 -1
- package/out/src/monitor/tasks/TaskMonitorCallHistory.js.map +1 -1
- package/out/src/monitor/tasks/TaskNewHeader.js +2 -1
- package/out/src/monitor/tasks/TaskNewHeader.js.map +1 -1
- package/out/src/monitor/tasks/TaskReorg.d.ts +47 -0
- package/out/src/monitor/tasks/TaskReorg.d.ts.map +1 -0
- package/out/src/monitor/tasks/TaskReorg.js +135 -0
- package/out/src/monitor/tasks/TaskReorg.js.map +1 -0
- package/out/src/monitor/tasks/TaskSendWaiting.js +2 -1
- package/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -1
- package/out/src/monitor/tasks/TaskUnFail.js +2 -1
- package/out/src/monitor/tasks/TaskUnFail.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Api/ChaintracksClientApi.d.ts +1 -1
- package/out/src/services/chaintracker/chaintracks/Api/ChaintracksClientApi.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Api/ChaintracksStorageApi.d.ts +4 -0
- package/out/src/services/chaintracker/chaintracks/Api/ChaintracksStorageApi.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Chaintracks.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Chaintracks.js +3 -1
- package/out/src/services/chaintracker/chaintracks/Chaintracks.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/ChaintracksService.js +1 -1
- package/out/src/services/chaintracker/chaintracks/ChaintracksService.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.js +4 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.js +3 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.js +3 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/__tests/Chaintracks.test.js +1 -1
- package/out/src/services/chaintracker/chaintracks/__tests/Chaintracks.test.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.d.ts +5 -0
- package/out/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.d.ts.map +1 -0
- package/out/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.js +68 -0
- package/out/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.js.map +1 -0
- package/out/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.d.ts +2 -1
- package/out/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.js +66 -22
- package/out/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.d.ts +2 -1
- package/out/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.js +59 -15
- package/out/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createIdbChaintracks.d.ts +1 -1
- package/out/src/services/chaintracker/chaintracks/createIdbChaintracks.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createIdbChaintracks.js +4 -61
- package/out/src/services/chaintracker/chaintracks/createIdbChaintracks.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createKnexChaintracks.d.ts +14 -0
- package/out/src/services/chaintracker/chaintracks/createKnexChaintracks.d.ts.map +1 -0
- package/out/src/services/chaintracker/chaintracks/createKnexChaintracks.js +27 -0
- package/out/src/services/chaintracker/chaintracks/createKnexChaintracks.js.map +1 -0
- package/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.d.ts +13 -0
- package/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.d.ts.map +1 -0
- package/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.js +27 -0
- package/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.js.map +1 -0
- package/out/src/services/chaintracker/chaintracks/index.all.d.ts +1 -0
- package/out/src/services/chaintracker/chaintracks/index.all.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/index.all.js +1 -0
- package/out/src/services/chaintracker/chaintracks/index.all.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/index.client.d.ts +2 -28
- package/out/src/services/chaintracker/chaintracks/index.client.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/index.client.js +2 -50
- package/out/src/services/chaintracker/chaintracks/index.client.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/index.mobile.d.ts +30 -0
- package/out/src/services/chaintracker/chaintracks/index.mobile.d.ts.map +1 -0
- package/out/src/services/chaintracker/chaintracks/index.mobile.js +68 -0
- package/out/src/services/chaintracker/chaintracks/index.mobile.js.map +1 -0
- package/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.js +11 -11
- package/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.js.map +1 -1
- package/out/src/services/chaintracker/index.mobile.d.ts +4 -0
- package/out/src/services/chaintracker/index.mobile.d.ts.map +1 -0
- package/out/src/services/chaintracker/index.mobile.js +20 -0
- package/out/src/services/chaintracker/index.mobile.js.map +1 -0
- package/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/out/src/storage/methods/createAction.js.map +1 -1
- package/out/src/storage/schema/KnexMigrations.d.ts.map +1 -1
- package/out/src/storage/schema/KnexMigrations.js +12 -0
- package/out/src/storage/schema/KnexMigrations.js.map +1 -1
- package/out/test/monitor/Monitor.test.js +32 -29
- package/out/test/monitor/Monitor.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +5 -4
- package/src/CWIStyleWalletManager.ts +14 -4
- package/src/index.mobile.ts +1 -1
- package/src/monitor/Monitor.ts +94 -29
- package/src/monitor/MonitorDaemon.ts +9 -1
- package/src/monitor/__test/MonitorDaemon.man.test.ts +35 -7
- package/src/monitor/tasks/TaskCheckNoSends.ts +1 -1
- package/src/monitor/tasks/TaskClock.ts +2 -2
- package/src/monitor/tasks/TaskMonitorCallHistory.ts +1 -1
- package/src/monitor/tasks/TaskNewHeader.ts +1 -1
- package/src/monitor/tasks/TaskReorg.ts +139 -0
- package/src/monitor/tasks/TaskSendWaiting.ts +3 -3
- package/src/monitor/tasks/TaskUnFail.ts +1 -1
- package/src/services/chaintracker/chaintracks/Api/ChaintracksClientApi.ts +6 -1
- package/src/services/chaintracker/chaintracks/Api/ChaintracksStorageApi.ts +4 -0
- package/src/services/chaintracker/chaintracks/Chaintracks.ts +3 -1
- package/src/services/chaintracker/chaintracks/ChaintracksService.ts +2 -2
- package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.ts +4 -1
- package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.ts +4 -12
- package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.ts +3 -1
- package/src/services/chaintracker/chaintracks/__tests/Chaintracks.test.ts +2 -2
- package/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.ts +92 -0
- package/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.ts +84 -25
- package/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.ts +79 -17
- package/src/services/chaintracker/chaintracks/createIdbChaintracks.ts +11 -64
- package/src/services/chaintracker/chaintracks/createKnexChaintracks.ts +65 -0
- package/src/services/chaintracker/chaintracks/createNoDbChaintracks.ts +60 -0
- package/src/services/chaintracker/chaintracks/index.all.ts +1 -0
- package/src/services/chaintracker/chaintracks/index.client.ts +2 -35
- package/src/services/chaintracker/chaintracks/index.mobile.ts +37 -0
- package/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.ts +11 -11
- package/src/services/chaintracker/index.mobile.ts +4 -0
- package/src/storage/methods/createAction.ts +6 -1
- package/src/storage/schema/KnexMigrations.ts +13 -0
- package/syncVersions.js +71 -0
- package/test/monitor/Monitor.test.ts +21 -16
|
@@ -4,7 +4,7 @@ import { IncomingMessage, Server, ServerResponse } from 'http'
|
|
|
4
4
|
import express, { Request, Response } from 'express'
|
|
5
5
|
import bodyParser from 'body-parser'
|
|
6
6
|
import { Chain } from '../../../sdk/types'
|
|
7
|
-
import {
|
|
7
|
+
import { createDefaultNoDbChaintracksOptions } from './createDefaultNoDbChaintracksOptions'
|
|
8
8
|
import { Services } from '../../Services'
|
|
9
9
|
import { FiatExchangeRates, WERR_INVALID_PARAMETER } from '../../../sdk'
|
|
10
10
|
import { ChaintracksInfoApi } from './Api/ChaintracksClientApi'
|
|
@@ -45,7 +45,7 @@ export class ChaintracksService {
|
|
|
45
45
|
this.options = { ...options }
|
|
46
46
|
this.port = options.port
|
|
47
47
|
this.chain = options.chain
|
|
48
|
-
this.chaintracks = options.chaintracks || new Chaintracks(
|
|
48
|
+
this.chaintracks = options.chaintracks || new Chaintracks(createDefaultNoDbChaintracksOptions(this.chain))
|
|
49
49
|
this.services = options.services || new Services(this.chain)
|
|
50
50
|
// Prevent recursion...
|
|
51
51
|
this.services.updateFiatExchangeRateServices.remove('ChaintracksService')
|
|
@@ -263,7 +263,8 @@ export class ChaintracksStorageIdb extends ChaintracksStorageBase implements Cha
|
|
|
263
263
|
isActiveTip: false,
|
|
264
264
|
reorgDepth: 0,
|
|
265
265
|
priorTip: undefined,
|
|
266
|
-
noTip: false
|
|
266
|
+
noTip: false,
|
|
267
|
+
deactivatedHeaders: []
|
|
267
268
|
}
|
|
268
269
|
|
|
269
270
|
// Check for duplicate
|
|
@@ -359,8 +360,10 @@ export class ChaintracksStorageIdb extends ChaintracksStorageBase implements Cha
|
|
|
359
360
|
}
|
|
360
361
|
|
|
361
362
|
if (activeAncestor.headerId !== oneBack.headerId) {
|
|
363
|
+
// Deactivate reorg'ed headers
|
|
362
364
|
let headerToDeactivate = this.repairStoredLiveHeader(await activeTipIndex.get([1, 1]))!
|
|
363
365
|
while (headerToDeactivate && headerToDeactivate.headerId !== activeAncestor.headerId) {
|
|
366
|
+
r.deactivatedHeaders.push(headerToDeactivate)
|
|
364
367
|
await store.put(this.prepareStoredLiveHeader({ ...headerToDeactivate, isActive: false }))
|
|
365
368
|
headerToDeactivate = this.repairStoredLiveHeader(await store.get(headerToDeactivate.previousHeaderId!))!
|
|
366
369
|
}
|
|
@@ -4,25 +4,15 @@ import { InsertHeaderResult, ChaintracksStorageBaseOptions } from '../Api/Chaint
|
|
|
4
4
|
import { ChaintracksStorageBase } from './ChaintracksStorageBase'
|
|
5
5
|
import { LiveBlockHeader } from '../Api/BlockHeaderApi'
|
|
6
6
|
import { BlockHeader } from '../../../../sdk/WalletServices.interfaces'
|
|
7
|
-
import {
|
|
8
|
-
addWork,
|
|
9
|
-
convertBitsToWork,
|
|
10
|
-
isMoreWork,
|
|
11
|
-
serializeBaseBlockHeader,
|
|
12
|
-
serializeBaseBlockHeaders
|
|
13
|
-
} from '../util/blockHeaderUtilities'
|
|
7
|
+
import { addWork, convertBitsToWork, isMoreWork } from '../util/blockHeaderUtilities'
|
|
14
8
|
import { verifyOneOrNone } from '../../../../utility/utilityHelpers'
|
|
15
9
|
import { DBType } from '../../../../storage/StorageReader'
|
|
16
10
|
import { BulkHeaderFileInfo } from '../util/BulkHeaderFile'
|
|
17
11
|
import { HeightRange } from '../util/HeightRange'
|
|
18
|
-
import { BulkFilesReaderStorage } from '../util/BulkFilesReader'
|
|
19
|
-
import { ChaintracksFetch } from '../util/ChaintracksFetch'
|
|
20
12
|
import { ChaintracksStorageBulkFileApi } from '../Api/ChaintracksStorageApi'
|
|
21
13
|
import { Chain } from '../../../../sdk/types'
|
|
22
14
|
import { WERR_INVALID_OPERATION, WERR_INVALID_PARAMETER } from '../../../../sdk/WERR_errors'
|
|
23
15
|
import { determineDBType } from '../../../../storage/schema/KnexMigrations'
|
|
24
|
-
import { BulkFileDataReader } from '../index.client'
|
|
25
|
-
import { asArray } from '../../../../utility/utilityHelpers.noBuffer'
|
|
26
16
|
|
|
27
17
|
export interface ChaintracksStorageKnexOptions extends ChaintracksStorageBaseOptions {
|
|
28
18
|
/**
|
|
@@ -231,7 +221,8 @@ export class ChaintracksStorageKnex extends ChaintracksStorageBase implements Ch
|
|
|
231
221
|
isActiveTip: false,
|
|
232
222
|
reorgDepth: 0,
|
|
233
223
|
priorTip: undefined,
|
|
234
|
-
noTip: false
|
|
224
|
+
noTip: false,
|
|
225
|
+
deactivatedHeaders: []
|
|
235
226
|
}
|
|
236
227
|
|
|
237
228
|
await this.knex.transaction(async trx => {
|
|
@@ -337,6 +328,7 @@ export class ChaintracksStorageKnex extends ChaintracksStorageBase implements Ch
|
|
|
337
328
|
let [headerToDeactivate] = await trx<LiveBlockHeader>(table).where({ isChainTip: true, isActive: true })
|
|
338
329
|
while (headerToDeactivate.headerId !== activeAncestor.headerId) {
|
|
339
330
|
// Headers are deactivated until we reach the activeAncestor
|
|
331
|
+
r.deactivatedHeaders.push(headerToDeactivate)
|
|
340
332
|
await trx<LiveBlockHeader>(table)
|
|
341
333
|
.where({ headerId: headerToDeactivate.headerId })
|
|
342
334
|
.update({ isActive: false })
|
|
@@ -177,7 +177,8 @@ export class ChaintracksStorageNoDb extends ChaintracksStorageBase {
|
|
|
177
177
|
isActiveTip: false,
|
|
178
178
|
reorgDepth: 0,
|
|
179
179
|
priorTip: undefined,
|
|
180
|
-
noTip: false
|
|
180
|
+
noTip: false,
|
|
181
|
+
deactivatedHeaders: []
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
// Check for duplicate
|
|
@@ -272,6 +273,7 @@ export class ChaintracksStorageNoDb extends ChaintracksStorageBase {
|
|
|
272
273
|
if (activeAncestor.headerId !== oneBack.headerId) {
|
|
273
274
|
let headerToDeactivate = Array.from(data.liveHeaders.values()).find(h => h.isChainTip && h.isActive)
|
|
274
275
|
while (headerToDeactivate && headerToDeactivate.headerId !== activeAncestor.headerId) {
|
|
276
|
+
r.deactivatedHeaders.push(headerToDeactivate)
|
|
275
277
|
data.liveHeaders.set(headerToDeactivate.headerId, { ...headerToDeactivate, isActive: false })
|
|
276
278
|
headerToDeactivate = data.liveHeaders.get(headerToDeactivate.previousHeaderId!)
|
|
277
279
|
}
|
|
@@ -2,7 +2,7 @@ import { createDefaultKnexChaintracksOptions } from '../createDefaultKnexChaintr
|
|
|
2
2
|
import { Chaintracks } from '../Chaintracks'
|
|
3
3
|
import { wait } from '../../../../utility/utilityHelpers'
|
|
4
4
|
import { Chain } from '../../../../sdk'
|
|
5
|
-
import {
|
|
5
|
+
import { createDefaultNoDbChaintracksOptions } from '../createDefaultNoDbChaintracksOptions'
|
|
6
6
|
import { ChaintracksFs } from '../util/ChaintracksFs'
|
|
7
7
|
import { LocalCdnServer } from './LocalCdnServer'
|
|
8
8
|
|
|
@@ -52,7 +52,7 @@ describe('Chaintracks tests', () => {
|
|
|
52
52
|
})
|
|
53
53
|
|
|
54
54
|
async function NoDbBody(chain: Chain, exportHeaders?: boolean) {
|
|
55
|
-
const o =
|
|
55
|
+
const o = createDefaultNoDbChaintracksOptions(chain)
|
|
56
56
|
const c = new Chaintracks(o)
|
|
57
57
|
await c.makeAvailable()
|
|
58
58
|
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Chain } from '../../../sdk'
|
|
2
|
+
import { ChaintracksOptions } from './Api/ChaintracksApi'
|
|
3
|
+
import { Chaintracks } from './Chaintracks'
|
|
4
|
+
import { BulkIngestorCDNBabbage } from './Ingest/BulkIngestorCDNBabbage'
|
|
5
|
+
import { ChaintracksFetch } from './util/ChaintracksFetch'
|
|
6
|
+
import { LiveIngestorWhatsOnChainOptions, LiveIngestorWhatsOnChainPoll } from './Ingest/LiveIngestorWhatsOnChainPoll'
|
|
7
|
+
import { BulkIngestorWhatsOnChainCdn, BulkIngestorWhatsOnChainOptions } from './Ingest/BulkIngestorWhatsOnChainCdn'
|
|
8
|
+
import { ChaintracksFetchApi } from './Api/ChaintracksFetchApi'
|
|
9
|
+
import { ChaintracksStorageIdb, ChaintracksStorageIdbOptions } from './Storage/ChaintracksStorageIdb'
|
|
10
|
+
import { BulkFileDataManager, BulkFileDataManagerOptions } from './util/BulkFileDataManager'
|
|
11
|
+
import { BulkIngestorCDNOptions } from './Ingest/BulkIngestorCDN'
|
|
12
|
+
import { WhatsOnChainServicesOptions } from './Ingest/WhatsOnChainServices'
|
|
13
|
+
|
|
14
|
+
export function createDefaultIdbChaintracksOptions(
|
|
15
|
+
chain: Chain,
|
|
16
|
+
whatsonchainApiKey: string = '',
|
|
17
|
+
maxPerFile: number = 100000,
|
|
18
|
+
maxRetained: number = 2,
|
|
19
|
+
fetch?: ChaintracksFetchApi,
|
|
20
|
+
cdnUrl: string = 'https://cdn.projectbabbage.com/blockheaders/',
|
|
21
|
+
liveHeightThreshold: number = 2000,
|
|
22
|
+
reorgHeightThreshold: number = 400,
|
|
23
|
+
bulkMigrationChunkSize: number = 500,
|
|
24
|
+
batchInsertLimit: number = 400,
|
|
25
|
+
addLiveRecursionLimit: number = 36
|
|
26
|
+
): ChaintracksOptions {
|
|
27
|
+
fetch ||= new ChaintracksFetch()
|
|
28
|
+
|
|
29
|
+
const bfo: BulkFileDataManagerOptions = {
|
|
30
|
+
chain,
|
|
31
|
+
fetch,
|
|
32
|
+
maxPerFile,
|
|
33
|
+
maxRetained,
|
|
34
|
+
fromKnownSourceUrl: cdnUrl
|
|
35
|
+
}
|
|
36
|
+
const bulkFileDataManager = new BulkFileDataManager(bfo)
|
|
37
|
+
|
|
38
|
+
const so: ChaintracksStorageIdbOptions = {
|
|
39
|
+
chain,
|
|
40
|
+
bulkFileDataManager,
|
|
41
|
+
liveHeightThreshold,
|
|
42
|
+
reorgHeightThreshold,
|
|
43
|
+
bulkMigrationChunkSize,
|
|
44
|
+
batchInsertLimit
|
|
45
|
+
}
|
|
46
|
+
const storage = new ChaintracksStorageIdb(so)
|
|
47
|
+
|
|
48
|
+
const co: ChaintracksOptions = {
|
|
49
|
+
chain,
|
|
50
|
+
storage,
|
|
51
|
+
bulkIngestors: [],
|
|
52
|
+
liveIngestors: [],
|
|
53
|
+
addLiveRecursionLimit,
|
|
54
|
+
logging: (...args) => console.log(new Date().toISOString(), ...args),
|
|
55
|
+
readonly: false
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const jsonResource = `${chain}NetBlockHeaders.json`
|
|
59
|
+
|
|
60
|
+
const bulkCdnOptions: BulkIngestorCDNOptions = {
|
|
61
|
+
chain,
|
|
62
|
+
jsonResource,
|
|
63
|
+
fetch,
|
|
64
|
+
cdnUrl,
|
|
65
|
+
maxPerFile
|
|
66
|
+
}
|
|
67
|
+
co.bulkIngestors.push(new BulkIngestorCDNBabbage(bulkCdnOptions))
|
|
68
|
+
|
|
69
|
+
const wocOptions: WhatsOnChainServicesOptions = {
|
|
70
|
+
chain,
|
|
71
|
+
apiKey: whatsonchainApiKey,
|
|
72
|
+
timeout: 30000,
|
|
73
|
+
userAgent: 'BabbageWhatsOnChainServices',
|
|
74
|
+
enableCache: true,
|
|
75
|
+
chainInfoMsecs: 5000
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const bulkOptions: BulkIngestorWhatsOnChainOptions = {
|
|
79
|
+
...wocOptions,
|
|
80
|
+
jsonResource,
|
|
81
|
+
idleWait: 5000
|
|
82
|
+
}
|
|
83
|
+
co.bulkIngestors.push(new BulkIngestorWhatsOnChainCdn(bulkOptions))
|
|
84
|
+
|
|
85
|
+
const liveOptions: LiveIngestorWhatsOnChainOptions = {
|
|
86
|
+
...wocOptions,
|
|
87
|
+
idleWait: 100000
|
|
88
|
+
}
|
|
89
|
+
co.liveIngestors.push(new LiveIngestorWhatsOnChainPoll(liveOptions))
|
|
90
|
+
|
|
91
|
+
return co
|
|
92
|
+
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { Knex, knex as makeKnex } from 'knex'
|
|
2
2
|
import { Chain } from '../../../sdk'
|
|
3
3
|
import { ChaintracksOptions } from './Api/ChaintracksApi'
|
|
4
|
-
import { Chaintracks } from './Chaintracks'
|
|
5
4
|
import { ChaintracksFs } from './util/ChaintracksFs'
|
|
6
|
-
import { ChaintracksStorageKnex } from './Storage/ChaintracksStorageKnex'
|
|
5
|
+
import { ChaintracksStorageKnex, ChaintracksStorageKnexOptions } from './Storage/ChaintracksStorageKnex'
|
|
7
6
|
import { BulkIngestorCDNBabbage } from './Ingest/BulkIngestorCDNBabbage'
|
|
8
7
|
import { ChaintracksFetch } from './util/ChaintracksFetch'
|
|
9
|
-
import { LiveIngestorWhatsOnChainPoll } from './Ingest/LiveIngestorWhatsOnChainPoll'
|
|
10
|
-
import { BulkIngestorWhatsOnChainCdn } from './Ingest/BulkIngestorWhatsOnChainCdn'
|
|
8
|
+
import { LiveIngestorWhatsOnChainOptions, LiveIngestorWhatsOnChainPoll } from './Ingest/LiveIngestorWhatsOnChainPoll'
|
|
9
|
+
import { BulkIngestorWhatsOnChainCdn, BulkIngestorWhatsOnChainOptions } from './Ingest/BulkIngestorWhatsOnChainCdn'
|
|
10
|
+
import { ChaintracksFetchApi } from './Api/ChaintracksFetchApi'
|
|
11
|
+
import { BulkFileDataManager, BulkFileDataManagerOptions } from './util/BulkFileDataManager'
|
|
12
|
+
import { BulkIngestorCDNOptions } from './Ingest/BulkIngestorCDN'
|
|
13
|
+
import { WhatsOnChainServicesOptions } from './Ingest/WhatsOnChainServices'
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
*
|
|
@@ -17,36 +20,92 @@ import { BulkIngestorWhatsOnChainCdn } from './Ingest/BulkIngestorWhatsOnChainCd
|
|
|
17
20
|
*/
|
|
18
21
|
export function createDefaultKnexChaintracksOptions(
|
|
19
22
|
chain: Chain,
|
|
20
|
-
rootFolder
|
|
21
|
-
knexConfig?: Knex.Config
|
|
23
|
+
rootFolder: string = './data/',
|
|
24
|
+
knexConfig?: Knex.Config,
|
|
25
|
+
whatsonchainApiKey: string = '',
|
|
26
|
+
maxPerFile: number = 100000,
|
|
27
|
+
maxRetained: number = 2,
|
|
28
|
+
fetch?: ChaintracksFetchApi,
|
|
29
|
+
cdnUrl: string = 'https://cdn.projectbabbage.com/blockheaders/',
|
|
30
|
+
liveHeightThreshold: number = 2000,
|
|
31
|
+
reorgHeightThreshold: number = 400,
|
|
32
|
+
bulkMigrationChunkSize: number = 500,
|
|
33
|
+
batchInsertLimit: number = 400,
|
|
34
|
+
addLiveRecursionLimit: number = 36
|
|
22
35
|
): ChaintracksOptions {
|
|
23
|
-
|
|
36
|
+
fetch ||= new ChaintracksFetch()
|
|
24
37
|
|
|
25
|
-
const
|
|
38
|
+
const bfo: BulkFileDataManagerOptions = {
|
|
39
|
+
chain,
|
|
40
|
+
fetch,
|
|
41
|
+
maxPerFile,
|
|
42
|
+
maxRetained,
|
|
43
|
+
fromKnownSourceUrl: cdnUrl
|
|
44
|
+
}
|
|
45
|
+
const bulkFileDataManager = new BulkFileDataManager(bfo)
|
|
46
|
+
|
|
47
|
+
if (!knexConfig) {
|
|
48
|
+
knexConfig = {
|
|
49
|
+
client: 'sqlite3',
|
|
50
|
+
connection: { filename: ChaintracksFs.pathJoin(rootFolder, `${chain}Net_chaintracks.sqlite`) },
|
|
51
|
+
useNullAsDefault: true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const knexInstance = makeKnex(knexConfig)
|
|
26
55
|
|
|
27
|
-
const
|
|
28
|
-
|
|
56
|
+
const so: ChaintracksStorageKnexOptions = {
|
|
57
|
+
chain,
|
|
58
|
+
knex: knexInstance,
|
|
59
|
+
bulkFileDataManager,
|
|
60
|
+
liveHeightThreshold,
|
|
61
|
+
reorgHeightThreshold,
|
|
62
|
+
bulkMigrationChunkSize,
|
|
63
|
+
batchInsertLimit
|
|
64
|
+
}
|
|
65
|
+
const storage = new ChaintracksStorageKnex(so)
|
|
29
66
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
67
|
+
const co: ChaintracksOptions = {
|
|
68
|
+
chain,
|
|
69
|
+
storage,
|
|
70
|
+
bulkIngestors: [],
|
|
71
|
+
liveIngestors: [],
|
|
72
|
+
addLiveRecursionLimit,
|
|
73
|
+
logging: (...args) => console.log(new Date().toISOString(), ...args),
|
|
74
|
+
readonly: false
|
|
34
75
|
}
|
|
35
76
|
|
|
36
|
-
const
|
|
77
|
+
const jsonResource = `${chain}NetBlockHeaders.json`
|
|
37
78
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
79
|
+
const bulkCdnOptions: BulkIngestorCDNOptions = {
|
|
80
|
+
chain,
|
|
81
|
+
jsonResource,
|
|
82
|
+
fetch,
|
|
83
|
+
cdnUrl,
|
|
84
|
+
maxPerFile
|
|
85
|
+
}
|
|
86
|
+
co.bulkIngestors.push(new BulkIngestorCDNBabbage(bulkCdnOptions))
|
|
41
87
|
|
|
42
|
-
const
|
|
43
|
-
|
|
88
|
+
const wocOptions: WhatsOnChainServicesOptions = {
|
|
89
|
+
chain,
|
|
90
|
+
apiKey: whatsonchainApiKey,
|
|
91
|
+
timeout: 30000,
|
|
92
|
+
userAgent: 'BabbageWhatsOnChainServices',
|
|
93
|
+
enableCache: true,
|
|
94
|
+
chainInfoMsecs: 5000
|
|
95
|
+
}
|
|
44
96
|
|
|
45
|
-
const
|
|
46
|
-
|
|
97
|
+
const bulkOptions: BulkIngestorWhatsOnChainOptions = {
|
|
98
|
+
...wocOptions,
|
|
99
|
+
jsonResource,
|
|
100
|
+
idleWait: 5000
|
|
101
|
+
}
|
|
102
|
+
co.bulkIngestors.push(new BulkIngestorWhatsOnChainCdn(bulkOptions))
|
|
47
103
|
|
|
48
|
-
const
|
|
49
|
-
|
|
104
|
+
const liveOptions: LiveIngestorWhatsOnChainOptions = {
|
|
105
|
+
...wocOptions,
|
|
106
|
+
idleWait: 100000
|
|
107
|
+
}
|
|
108
|
+
co.liveIngestors.push(new LiveIngestorWhatsOnChainPoll(liveOptions))
|
|
50
109
|
|
|
51
|
-
return
|
|
110
|
+
return co
|
|
52
111
|
}
|
|
@@ -1,29 +1,91 @@
|
|
|
1
1
|
import { Chain } from '../../../sdk'
|
|
2
2
|
import { ChaintracksOptions } from './Api/ChaintracksApi'
|
|
3
|
-
import { Chaintracks } from './Chaintracks'
|
|
4
3
|
import { BulkIngestorCDNBabbage } from './Ingest/BulkIngestorCDNBabbage'
|
|
5
4
|
import { ChaintracksFetch } from './util/ChaintracksFetch'
|
|
6
|
-
import { LiveIngestorWhatsOnChainPoll } from './Ingest/LiveIngestorWhatsOnChainPoll'
|
|
7
|
-
import { BulkIngestorWhatsOnChainCdn } from './Ingest/BulkIngestorWhatsOnChainCdn'
|
|
8
|
-
import { ChaintracksStorageNoDb } from './Storage/ChaintracksStorageNoDb'
|
|
5
|
+
import { LiveIngestorWhatsOnChainOptions, LiveIngestorWhatsOnChainPoll } from './Ingest/LiveIngestorWhatsOnChainPoll'
|
|
6
|
+
import { BulkIngestorWhatsOnChainCdn, BulkIngestorWhatsOnChainOptions } from './Ingest/BulkIngestorWhatsOnChainCdn'
|
|
7
|
+
import { ChaintracksStorageNoDb, ChaintracksStorageNoDbOptions } from './Storage/ChaintracksStorageNoDb'
|
|
8
|
+
import { ChaintracksFetchApi } from './Api/ChaintracksFetchApi'
|
|
9
|
+
import { BulkFileDataManager, BulkFileDataManagerOptions } from './util/BulkFileDataManager'
|
|
10
|
+
import { BulkIngestorCDNOptions } from './Ingest/BulkIngestorCDN'
|
|
11
|
+
import { WhatsOnChainServicesOptions } from './Ingest/WhatsOnChainServices'
|
|
9
12
|
|
|
10
|
-
export function
|
|
11
|
-
|
|
13
|
+
export function createDefaultNoDbChaintracksOptions(
|
|
14
|
+
chain: Chain,
|
|
15
|
+
whatsonchainApiKey: string = '',
|
|
16
|
+
maxPerFile: number = 100000,
|
|
17
|
+
maxRetained: number = 2,
|
|
18
|
+
fetch?: ChaintracksFetchApi,
|
|
19
|
+
cdnUrl: string = 'https://cdn.projectbabbage.com/blockheaders/',
|
|
20
|
+
liveHeightThreshold: number = 2000,
|
|
21
|
+
reorgHeightThreshold: number = 400,
|
|
22
|
+
bulkMigrationChunkSize: number = 500,
|
|
23
|
+
batchInsertLimit: number = 400,
|
|
24
|
+
addLiveRecursionLimit: number = 36
|
|
25
|
+
): ChaintracksOptions {
|
|
26
|
+
fetch ||= new ChaintracksFetch()
|
|
12
27
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
const bfo: BulkFileDataManagerOptions = {
|
|
29
|
+
chain,
|
|
30
|
+
fetch,
|
|
31
|
+
maxPerFile,
|
|
32
|
+
maxRetained,
|
|
33
|
+
fromKnownSourceUrl: cdnUrl
|
|
34
|
+
}
|
|
35
|
+
const bulkFileDataManager = new BulkFileDataManager(bfo)
|
|
16
36
|
|
|
17
|
-
const
|
|
37
|
+
const so: ChaintracksStorageNoDbOptions = {
|
|
38
|
+
chain,
|
|
39
|
+
bulkFileDataManager,
|
|
40
|
+
liveHeightThreshold,
|
|
41
|
+
reorgHeightThreshold,
|
|
42
|
+
bulkMigrationChunkSize,
|
|
43
|
+
batchInsertLimit
|
|
44
|
+
}
|
|
45
|
+
const storage = new ChaintracksStorageNoDb(so)
|
|
18
46
|
|
|
19
|
-
const
|
|
20
|
-
|
|
47
|
+
const co: ChaintracksOptions = {
|
|
48
|
+
chain,
|
|
49
|
+
storage,
|
|
50
|
+
bulkIngestors: [],
|
|
51
|
+
liveIngestors: [],
|
|
52
|
+
addLiveRecursionLimit,
|
|
53
|
+
logging: (...args) => console.log(new Date().toISOString(), ...args),
|
|
54
|
+
readonly: false
|
|
55
|
+
}
|
|
21
56
|
|
|
22
|
-
const
|
|
23
|
-
options.bulkIngestors.push(new BulkIngestorWhatsOnChainCdn(bulkWhatsOnChainOptions))
|
|
57
|
+
const jsonResource = `${chain}NetBlockHeaders.json`
|
|
24
58
|
|
|
25
|
-
const
|
|
26
|
-
|
|
59
|
+
const bulkCdnOptions: BulkIngestorCDNOptions = {
|
|
60
|
+
chain,
|
|
61
|
+
jsonResource,
|
|
62
|
+
fetch,
|
|
63
|
+
cdnUrl,
|
|
64
|
+
maxPerFile
|
|
65
|
+
}
|
|
66
|
+
co.bulkIngestors.push(new BulkIngestorCDNBabbage(bulkCdnOptions))
|
|
27
67
|
|
|
28
|
-
|
|
68
|
+
const wocOptions: WhatsOnChainServicesOptions = {
|
|
69
|
+
chain,
|
|
70
|
+
apiKey: whatsonchainApiKey,
|
|
71
|
+
timeout: 30000,
|
|
72
|
+
userAgent: 'BabbageWhatsOnChainServices',
|
|
73
|
+
enableCache: true,
|
|
74
|
+
chainInfoMsecs: 5000
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const bulkOptions: BulkIngestorWhatsOnChainOptions = {
|
|
78
|
+
...wocOptions,
|
|
79
|
+
jsonResource,
|
|
80
|
+
idleWait: 5000
|
|
81
|
+
}
|
|
82
|
+
co.bulkIngestors.push(new BulkIngestorWhatsOnChainCdn(bulkOptions))
|
|
83
|
+
|
|
84
|
+
const liveOptions: LiveIngestorWhatsOnChainOptions = {
|
|
85
|
+
...wocOptions,
|
|
86
|
+
idleWait: 100000
|
|
87
|
+
}
|
|
88
|
+
co.liveIngestors.push(new LiveIngestorWhatsOnChainPoll(liveOptions))
|
|
89
|
+
|
|
90
|
+
return co
|
|
29
91
|
}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { Chain } from '../../../sdk'
|
|
2
|
-
import { ChaintracksOptions } from './Api/ChaintracksApi'
|
|
3
2
|
import { Chaintracks } from './Chaintracks'
|
|
4
|
-
import { BulkIngestorCDNBabbage } from './Ingest/BulkIngestorCDNBabbage'
|
|
5
3
|
import { ChaintracksFetch } from './util/ChaintracksFetch'
|
|
6
|
-
import { LiveIngestorWhatsOnChainOptions, LiveIngestorWhatsOnChainPoll } from './Ingest/LiveIngestorWhatsOnChainPoll'
|
|
7
|
-
import { BulkIngestorWhatsOnChainCdn, BulkIngestorWhatsOnChainOptions } from './Ingest/BulkIngestorWhatsOnChainCdn'
|
|
8
4
|
import { ChaintracksFetchApi } from './Api/ChaintracksFetchApi'
|
|
9
|
-
import { ChaintracksStorageIdb
|
|
10
|
-
import {
|
|
11
|
-
import { BulkIngestorCDNOptions, WhatsOnChainServicesOptions } from './index.client'
|
|
5
|
+
import { ChaintracksStorageIdb } from './Storage/ChaintracksStorageIdb'
|
|
6
|
+
import { createDefaultIdbChaintracksOptions } from './createDefaultIdbChaintracksOptions'
|
|
12
7
|
|
|
13
8
|
export async function createIdbChaintracks(
|
|
14
9
|
chain: Chain,
|
|
15
|
-
whatsonchainApiKey: string,
|
|
10
|
+
whatsonchainApiKey: string = '',
|
|
16
11
|
maxPerFile: number = 100000,
|
|
17
12
|
maxRetained: number = 2,
|
|
18
13
|
fetch?: ChaintracksFetchApi,
|
|
@@ -33,67 +28,19 @@ export async function createIdbChaintracks(
|
|
|
33
28
|
try {
|
|
34
29
|
fetch ||= new ChaintracksFetch()
|
|
35
30
|
|
|
36
|
-
const
|
|
31
|
+
const co = createDefaultIdbChaintracksOptions(
|
|
37
32
|
chain,
|
|
38
|
-
|
|
33
|
+
whatsonchainApiKey,
|
|
39
34
|
maxPerFile,
|
|
40
35
|
maxRetained,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const bulkFileDataManager = new BulkFileDataManager(bfo)
|
|
44
|
-
|
|
45
|
-
const so: ChaintracksStorageIdbOptions = {
|
|
46
|
-
chain,
|
|
47
|
-
bulkFileDataManager,
|
|
36
|
+
fetch,
|
|
37
|
+
cdnUrl,
|
|
48
38
|
liveHeightThreshold,
|
|
49
39
|
reorgHeightThreshold,
|
|
50
40
|
bulkMigrationChunkSize,
|
|
51
|
-
batchInsertLimit
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const co: ChaintracksOptions = {
|
|
56
|
-
chain,
|
|
57
|
-
storage,
|
|
58
|
-
bulkIngestors: [],
|
|
59
|
-
liveIngestors: [],
|
|
60
|
-
addLiveRecursionLimit,
|
|
61
|
-
logging: (...args) => console.log(new Date().toISOString(), ...args),
|
|
62
|
-
readonly: false
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const jsonResource = `${chain}NetBlockHeaders.json`
|
|
66
|
-
|
|
67
|
-
const bulkCdnOptions: BulkIngestorCDNOptions = {
|
|
68
|
-
chain,
|
|
69
|
-
jsonResource,
|
|
70
|
-
fetch,
|
|
71
|
-
cdnUrl,
|
|
72
|
-
maxPerFile
|
|
73
|
-
}
|
|
74
|
-
co.bulkIngestors.push(new BulkIngestorCDNBabbage(bulkCdnOptions))
|
|
75
|
-
|
|
76
|
-
const wocOptions: WhatsOnChainServicesOptions = {
|
|
77
|
-
chain,
|
|
78
|
-
apiKey: whatsonchainApiKey,
|
|
79
|
-
timeout: 30000,
|
|
80
|
-
userAgent: 'BabbageWhatsOnChainServices',
|
|
81
|
-
enableCache: true,
|
|
82
|
-
chainInfoMsecs: 5000
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const bulkOptions: BulkIngestorWhatsOnChainOptions = {
|
|
86
|
-
...wocOptions,
|
|
87
|
-
jsonResource,
|
|
88
|
-
idleWait: 5000
|
|
89
|
-
}
|
|
90
|
-
co.bulkIngestors.push(new BulkIngestorWhatsOnChainCdn(bulkOptions))
|
|
91
|
-
|
|
92
|
-
const liveOptions: LiveIngestorWhatsOnChainOptions = {
|
|
93
|
-
...wocOptions,
|
|
94
|
-
idleWait: 100000
|
|
95
|
-
}
|
|
96
|
-
co.liveIngestors.push(new LiveIngestorWhatsOnChainPoll(liveOptions))
|
|
41
|
+
batchInsertLimit,
|
|
42
|
+
addLiveRecursionLimit
|
|
43
|
+
)
|
|
97
44
|
|
|
98
45
|
const chaintracks = new Chaintracks(co)
|
|
99
46
|
const available = chaintracks.makeAvailable()
|
|
@@ -102,7 +49,7 @@ export async function createIdbChaintracks(
|
|
|
102
49
|
chain,
|
|
103
50
|
fetch,
|
|
104
51
|
maxPerFile,
|
|
105
|
-
storage,
|
|
52
|
+
storage: co.storage as ChaintracksStorageIdb,
|
|
106
53
|
chaintracks,
|
|
107
54
|
available
|
|
108
55
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Knex, knex as makeKnex } from 'knex'
|
|
2
|
+
import { Chain } from '../../../sdk'
|
|
3
|
+
import { Chaintracks } from './Chaintracks'
|
|
4
|
+
import { ChaintracksFetch } from './util/ChaintracksFetch'
|
|
5
|
+
import { ChaintracksFetchApi } from './Api/ChaintracksFetchApi'
|
|
6
|
+
import { ChaintracksStorageKnex } from './Storage/ChaintracksStorageKnex'
|
|
7
|
+
import { createDefaultKnexChaintracksOptions } from './createDefaultKnexChaintracksOptions'
|
|
8
|
+
|
|
9
|
+
export async function createKnexChaintracks(
|
|
10
|
+
chain: Chain,
|
|
11
|
+
rootFolder: string = './data/',
|
|
12
|
+
knexConfig?: Knex.Config,
|
|
13
|
+
whatsonchainApiKey: string = '',
|
|
14
|
+
maxPerFile: number = 100000,
|
|
15
|
+
maxRetained: number = 2,
|
|
16
|
+
fetch?: ChaintracksFetchApi,
|
|
17
|
+
cdnUrl: string = 'https://cdn.projectbabbage.com/blockheaders/',
|
|
18
|
+
liveHeightThreshold: number = 2000,
|
|
19
|
+
reorgHeightThreshold: number = 400,
|
|
20
|
+
bulkMigrationChunkSize: number = 500,
|
|
21
|
+
batchInsertLimit: number = 400,
|
|
22
|
+
addLiveRecursionLimit: number = 36
|
|
23
|
+
): Promise<{
|
|
24
|
+
chain: Chain
|
|
25
|
+
maxPerFile: number
|
|
26
|
+
fetch: ChaintracksFetchApi
|
|
27
|
+
storage: ChaintracksStorageKnex
|
|
28
|
+
chaintracks: Chaintracks
|
|
29
|
+
available: Promise<void>
|
|
30
|
+
}> {
|
|
31
|
+
try {
|
|
32
|
+
fetch ||= new ChaintracksFetch()
|
|
33
|
+
|
|
34
|
+
const co = createDefaultKnexChaintracksOptions(
|
|
35
|
+
chain,
|
|
36
|
+
rootFolder,
|
|
37
|
+
knexConfig,
|
|
38
|
+
whatsonchainApiKey,
|
|
39
|
+
maxPerFile,
|
|
40
|
+
maxRetained,
|
|
41
|
+
fetch,
|
|
42
|
+
cdnUrl,
|
|
43
|
+
liveHeightThreshold,
|
|
44
|
+
reorgHeightThreshold,
|
|
45
|
+
bulkMigrationChunkSize,
|
|
46
|
+
batchInsertLimit,
|
|
47
|
+
addLiveRecursionLimit
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
const chaintracks = new Chaintracks(co)
|
|
51
|
+
const available = chaintracks.makeAvailable()
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
chain,
|
|
55
|
+
fetch,
|
|
56
|
+
maxPerFile,
|
|
57
|
+
storage: co.storage as ChaintracksStorageKnex,
|
|
58
|
+
chaintracks,
|
|
59
|
+
available
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error('Error setting up Chaintracks with Knex Storage:', error)
|
|
63
|
+
throw error
|
|
64
|
+
}
|
|
65
|
+
}
|