@bsv/wallet-toolbox 1.6.1 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/docs/client.md +330 -2502
- package/docs/services.md +15 -4
- package/docs/wallet.md +330 -2502
- package/mobile/out/src/services/Services.d.ts.map +1 -1
- package/mobile/out/src/services/Services.js +7 -3
- package/mobile/out/src/services/Services.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js +1 -2
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js +1 -14
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts +1 -0
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js +18 -0
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js +2 -3
- package/mobile/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js.map +1 -1
- package/mobile/out/src/services/createDefaultWalletServicesOptions.js +4 -2
- package/mobile/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
- package/mobile/out/src/signer/methods/internalizeAction.js +2 -2
- package/mobile/out/src/signer/methods/internalizeAction.js.map +1 -1
- package/mobile/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/mobile/out/src/storage/StorageProvider.js +1 -0
- package/mobile/out/src/storage/StorageProvider.js.map +1 -1
- package/mobile/out/src/utility/utilityHelpers.d.ts +2 -0
- package/mobile/out/src/utility/utilityHelpers.d.ts.map +1 -1
- package/mobile/out/src/utility/utilityHelpers.js +7 -0
- package/mobile/out/src/utility/utilityHelpers.js.map +1 -1
- package/mobile/package-lock.json +2 -2
- package/mobile/package.json +1 -1
- package/out/src/services/Services.d.ts.map +1 -1
- package/out/src/services/Services.js +7 -3
- package/out/src/services/Services.js.map +1 -1
- package/out/src/services/chaintracker/__tests/ChaintracksServiceClient.test.js +3 -1
- package/out/src/services/chaintracker/__tests/ChaintracksServiceClient.test.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js +1 -2
- package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js +1 -14
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts +1 -0
- package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js +18 -0
- package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/__tests/ChaintracksClientApi.test.js +24 -15
- package/out/src/services/chaintracker/chaintracks/__tests/ChaintracksClientApi.test.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/__tests/LocalCdnServer.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/__tests/LocalCdnServer.js +9 -2
- package/out/src/services/chaintracker/chaintracks/__tests/LocalCdnServer.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js +2 -3
- package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js.map +1 -1
- package/out/src/services/createDefaultWalletServicesOptions.js +4 -2
- package/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
- package/out/src/signer/methods/internalizeAction.js +2 -2
- package/out/src/signer/methods/internalizeAction.js.map +1 -1
- package/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/out/src/storage/StorageProvider.js +1 -0
- package/out/src/storage/StorageProvider.js.map +1 -1
- package/out/src/storage/__test/getBeefForTransaction.test.js +8 -6
- package/out/src/storage/__test/getBeefForTransaction.test.js.map +1 -1
- package/out/src/utility/Format.js +2 -2
- package/out/src/utility/utilityHelpers.d.ts +2 -0
- package/out/src/utility/utilityHelpers.d.ts.map +1 -1
- package/out/src/utility/utilityHelpers.js +7 -0
- package/out/src/utility/utilityHelpers.js.map +1 -1
- package/out/test/storage/idb/update.test.js +1 -1
- package/out/test/storage/idb/update.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/services/Services.ts +6 -2
- package/src/services/chaintracker/__tests/ChaintracksServiceClient.test.ts +3 -1
- package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.ts +1 -2
- package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.ts +3 -17
- package/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.ts +19 -0
- package/src/services/chaintracker/chaintracks/__tests/ChaintracksClientApi.test.ts +26 -16
- package/src/services/chaintracker/chaintracks/__tests/LocalCdnServer.ts +10 -2
- package/src/services/chaintracker/chaintracks/util/BulkFileDataManager.ts +2 -3
- package/src/services/createDefaultWalletServicesOptions.ts +5 -5
- package/src/signer/methods/internalizeAction.ts +2 -2
- package/src/storage/StorageProvider.ts +1 -0
- package/src/storage/__test/getBeefForTransaction.test.ts +34 -35
- package/src/utility/Format.ts +2 -2
- package/src/utility/utilityHelpers.ts +7 -0
- package/test/storage/idb/update.test.ts +1 -1
- package/mobile/out/src/Setup.d.ts +0 -267
- package/mobile/out/src/Setup.d.ts.map +0 -1
- package/mobile/out/src/Setup.js +0 -408
- package/mobile/out/src/Setup.js.map +0 -1
- package/mobile/out/src/storage/StorageKnex.d.ts +0 -179
- package/mobile/out/src/storage/StorageKnex.d.ts.map +0 -1
- package/mobile/out/src/storage/StorageKnex.js +0 -1215
- package/mobile/out/src/storage/StorageKnex.js.map +0 -1
- package/mobile/out/src/storage/methods/listActionsKnex.d.ts +0 -6
- package/mobile/out/src/storage/methods/listActionsKnex.d.ts.map +0 -1
- package/mobile/out/src/storage/methods/listActionsKnex.js +0 -198
- package/mobile/out/src/storage/methods/listActionsKnex.js.map +0 -1
- package/mobile/out/src/storage/methods/listOutputsKnex.d.ts +0 -6
- package/mobile/out/src/storage/methods/listOutputsKnex.d.ts.map +0 -1
- package/mobile/out/src/storage/methods/listOutputsKnex.js +0 -241
- package/mobile/out/src/storage/methods/listOutputsKnex.js.map +0 -1
- package/mobile/out/src/storage/methods/purgeData.d.ts +0 -4
- package/mobile/out/src/storage/methods/purgeData.d.ts.map +0 -1
- package/mobile/out/src/storage/methods/purgeData.js +0 -207
- package/mobile/out/src/storage/methods/purgeData.js.map +0 -1
- package/mobile/out/src/storage/methods/reviewStatus.d.ts +0 -20
- package/mobile/out/src/storage/methods/reviewStatus.d.ts.map +0 -1
- package/mobile/out/src/storage/methods/reviewStatus.js +0 -84
- package/mobile/out/src/storage/methods/reviewStatus.js.map +0 -1
- package/mobile/out/src/storage/schema/KnexMigrations.d.ts +0 -39
- package/mobile/out/src/storage/schema/KnexMigrations.d.ts.map +0 -1
- package/mobile/out/src/storage/schema/KnexMigrations.js +0 -410
- package/mobile/out/src/storage/schema/KnexMigrations.js.map +0 -1
- package/mobile/out/test/utils/TestUtilsWalletStorage.d.ts +0 -522
- package/mobile/out/test/utils/TestUtilsWalletStorage.d.ts.map +0 -1
- package/mobile/out/test/utils/TestUtilsWalletStorage.js +0 -1956
- package/mobile/out/test/utils/TestUtilsWalletStorage.js.map +0 -1
package/package.json
CHANGED
package/src/services/Services.ts
CHANGED
|
@@ -413,10 +413,14 @@ export class Services implements WalletServices {
|
|
|
413
413
|
async hashToHeader(hash: string): Promise<BlockHeader> {
|
|
414
414
|
const method = async () => {
|
|
415
415
|
const header = await this.options.chaintracks!.findHeaderForBlockHash(hash)
|
|
416
|
-
if (!header) throw new WERR_INVALID_PARAMETER('hash', `valid blockhash '${hash}' on mined chain ${this.chain}`)
|
|
417
416
|
return header
|
|
418
417
|
}
|
|
419
|
-
|
|
418
|
+
let header = await this.invokeChaintracksWithRetry(method)
|
|
419
|
+
if (!header) {
|
|
420
|
+
header = await this.whatsonchain.getBlockHeaderByHash(hash)
|
|
421
|
+
}
|
|
422
|
+
if (!header) throw new WERR_INVALID_PARAMETER('hash', `valid blockhash '${hash}' on mined chain ${this.chain}`)
|
|
423
|
+
return header
|
|
420
424
|
}
|
|
421
425
|
|
|
422
426
|
async getMerklePath(txid: string, useNext?: boolean): Promise<GetMerklePathResult> {
|
|
@@ -23,5 +23,7 @@ describe('ChaintracksServiceClient tests', () => {
|
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
function makeClient(chain: sdk.Chain) {
|
|
26
|
-
|
|
26
|
+
//const chaintracksUrl = `https://npm-registry.babbage.systems:${chain === 'main' ? 8084 : 8083}`
|
|
27
|
+
const chaintracksUrl = `https://${chain}net-chaintracks.babbage.systems`
|
|
28
|
+
return new ChaintracksServiceClient(chain, chaintracksUrl)
|
|
27
29
|
}
|
|
@@ -6,7 +6,6 @@ import { BulkHeaderFileInfo } from '../util/BulkHeaderFile'
|
|
|
6
6
|
import { BulkHeaderFilesInfo } from '../util/BulkHeaderFile'
|
|
7
7
|
import { HeightRange, HeightRanges } from '../util/HeightRange'
|
|
8
8
|
import { ChaintracksFetchApi } from '../Api/ChaintracksFetchApi'
|
|
9
|
-
import { logger } from '../../../../../test/utils/TestUtilsWalletStorage'
|
|
10
9
|
import { WalletError, WERR_INVALID_PARAMETER } from '../../../../sdk'
|
|
11
10
|
import { validateBulkFileData } from '../util/blockHeaderUtilities'
|
|
12
11
|
import { selectBulkHeaderFiles } from '../util/BulkFileDataManager'
|
|
@@ -168,7 +167,7 @@ export class BulkIngestorCDN extends BulkIngestorBase {
|
|
|
168
167
|
for (const u of r.updated) {
|
|
169
168
|
log += ` updated: ${u.fileName}, fileId=${u.fileId}\n`
|
|
170
169
|
}
|
|
171
|
-
|
|
170
|
+
console.log(log)
|
|
172
171
|
|
|
173
172
|
return priorLiveHeaders
|
|
174
173
|
}
|
|
@@ -2,11 +2,10 @@ import { BlockHeader, Chain } from '../../../../sdk'
|
|
|
2
2
|
import { wait } from '../../../../utility/utilityHelpers'
|
|
3
3
|
import { LiveIngestorBase, LiveIngestorBaseOptions } from './LiveIngestorBase'
|
|
4
4
|
import {
|
|
5
|
-
EnqueueHandler,
|
|
6
|
-
ErrorHandler,
|
|
7
5
|
WhatsOnChainServices,
|
|
8
6
|
WhatsOnChainServicesOptions,
|
|
9
|
-
WocGetHeadersHeader
|
|
7
|
+
WocGetHeadersHeader,
|
|
8
|
+
wocGetHeadersHeaderToBlockHeader
|
|
10
9
|
} from './WhatsOnChainServices'
|
|
11
10
|
|
|
12
11
|
export interface LiveIngestorWhatsOnChainOptions extends LiveIngestorBaseOptions, WhatsOnChainServicesOptions {
|
|
@@ -81,20 +80,7 @@ export class LiveIngestorWhatsOnChainPoll extends LiveIngestorBase {
|
|
|
81
80
|
const newHeaders = headers.filter(h => !lastHeaders.some(lh => lh.hash === h.hash))
|
|
82
81
|
|
|
83
82
|
for (const h of newHeaders) {
|
|
84
|
-
const
|
|
85
|
-
if (!h.previousblockhash) {
|
|
86
|
-
h.previousblockhash = '0000000000000000000000000000000000000000000000000000000000000000' // genesis
|
|
87
|
-
}
|
|
88
|
-
const bh: BlockHeader = {
|
|
89
|
-
height: h.height,
|
|
90
|
-
hash: h.hash,
|
|
91
|
-
version: h.version,
|
|
92
|
-
previousHash: h.previousblockhash,
|
|
93
|
-
merkleRoot: h.merkleroot,
|
|
94
|
-
time: h.time,
|
|
95
|
-
bits,
|
|
96
|
-
nonce: h.nonce
|
|
97
|
-
}
|
|
83
|
+
const bh = wocGetHeadersHeaderToBlockHeader(h)
|
|
98
84
|
liveHeaders.unshift(bh)
|
|
99
85
|
}
|
|
100
86
|
|
|
@@ -192,6 +192,25 @@ export interface WocGetHeadersHeader {
|
|
|
192
192
|
num_tx: number
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
export function wocGetHeadersHeaderToBlockHeader(h: WocGetHeadersHeader): BlockHeader {
|
|
196
|
+
const bits: number = typeof h.bits === 'string' ? parseInt(h.bits, 16) : h.bits
|
|
197
|
+
if (!h.previousblockhash) {
|
|
198
|
+
h.previousblockhash = '0000000000000000000000000000000000000000000000000000000000000000' // genesis
|
|
199
|
+
}
|
|
200
|
+
const bh: BlockHeader = {
|
|
201
|
+
height: h.height,
|
|
202
|
+
hash: h.hash,
|
|
203
|
+
version: h.version,
|
|
204
|
+
previousHash: h.previousblockhash,
|
|
205
|
+
merkleRoot: h.merkleroot,
|
|
206
|
+
time: h.time,
|
|
207
|
+
bits,
|
|
208
|
+
nonce: h.nonce
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return bh
|
|
212
|
+
}
|
|
213
|
+
|
|
195
214
|
export interface GetHeaderByteFileLinksResult {
|
|
196
215
|
sourceUrl: string
|
|
197
216
|
fileName: string
|
|
@@ -22,13 +22,14 @@ clientClass = 'Chaintracks'
|
|
|
22
22
|
const includeLocalServiceClient = true
|
|
23
23
|
const includeLocalServiceChaintracks = true
|
|
24
24
|
const includeNpmRegistryClient = true
|
|
25
|
+
const includeGcrTestClient = true
|
|
25
26
|
|
|
26
27
|
describe(`ChaintracksClientApi tests`, () => {
|
|
27
28
|
jest.setTimeout(999999999)
|
|
28
29
|
|
|
29
30
|
const chain: Chain = 'main'
|
|
30
31
|
|
|
31
|
-
const clients: ChaintracksClientApi[] = []
|
|
32
|
+
const clients: { client: ChaintracksClientApi; chain: Chain }[] = []
|
|
32
33
|
|
|
33
34
|
let localService: ChaintracksService
|
|
34
35
|
let localServiceStorage: ChaintracksStorageApi
|
|
@@ -43,19 +44,28 @@ describe(`ChaintracksClientApi tests`, () => {
|
|
|
43
44
|
|
|
44
45
|
if (includeLocalServiceClient) {
|
|
45
46
|
localServiceClient = new ChaintracksServiceClient(chain, `http://localhost:${localService.port}`, {})
|
|
46
|
-
clients.push(localServiceClient)
|
|
47
|
+
clients.push({ client: localServiceClient, chain })
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
if (includeLocalServiceChaintracks) {
|
|
50
|
-
clients.push(localService.chaintracks)
|
|
51
|
+
clients.push({ client: localService.chaintracks, chain })
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
if (includeGcrTestClient) {
|
|
56
|
+
const gcr = new ChaintracksServiceClient('test', `https://testnet-chaintracks.babbage.systems`, {})
|
|
57
|
+
clients.push({ client: gcr, chain: 'test' })
|
|
58
|
+
}
|
|
59
|
+
if (includeGcrTestClient) {
|
|
60
|
+
const gcr = new ChaintracksServiceClient('main', `https://mainnet-chaintracks.babbage.systems`, {})
|
|
61
|
+
clients.push({ client: gcr, chain: 'main' })
|
|
62
|
+
}
|
|
63
|
+
|
|
54
64
|
if (includeNpmRegistryClient) {
|
|
55
|
-
clients.push(makeNpmRegistryClient(chain))
|
|
65
|
+
clients.push({ client: makeNpmRegistryClient(chain), chain })
|
|
56
66
|
}
|
|
57
67
|
|
|
58
|
-
const ft = await clients[0].findChainTipHeader()
|
|
68
|
+
const ft = await clients[0].client.findChainTipHeader()
|
|
59
69
|
if (!ft) throw new Error('No chain tip found')
|
|
60
70
|
firstTip = ft
|
|
61
71
|
})
|
|
@@ -65,30 +75,30 @@ describe(`ChaintracksClientApi tests`, () => {
|
|
|
65
75
|
})
|
|
66
76
|
|
|
67
77
|
test('0 getChain', async () => {
|
|
68
|
-
for (const client of clients) {
|
|
78
|
+
for (const { client, chain } of clients) {
|
|
69
79
|
const gotChain = await client.getChain()
|
|
70
80
|
expect(gotChain).toBe(chain)
|
|
71
81
|
}
|
|
72
82
|
})
|
|
73
83
|
|
|
74
84
|
test('1 getInfo', async () => {
|
|
75
|
-
for (const client of clients) {
|
|
85
|
+
for (const { client, chain } of clients) {
|
|
76
86
|
const gotInfo = await client.getInfo()
|
|
77
87
|
expect(gotInfo.chain).toBe(chain)
|
|
78
88
|
expect(gotInfo.heightBulk).toBeGreaterThan(700000)
|
|
79
|
-
expect(gotInfo.heightLive).toBeGreaterThanOrEqual(firstTip.height)
|
|
89
|
+
expect(gotInfo.heightLive).toBeGreaterThanOrEqual(firstTip.height - 2)
|
|
80
90
|
}
|
|
81
91
|
})
|
|
82
92
|
|
|
83
93
|
test('2 getPresentHeight', async () => {
|
|
84
|
-
for (const client of clients) {
|
|
94
|
+
for (const { client, chain } of clients) {
|
|
85
95
|
const presentHeight = await client.getPresentHeight()
|
|
86
|
-
expect(presentHeight).toBeGreaterThanOrEqual(firstTip.height)
|
|
96
|
+
expect(presentHeight).toBeGreaterThanOrEqual(firstTip.height - 2)
|
|
87
97
|
}
|
|
88
98
|
})
|
|
89
99
|
|
|
90
100
|
test('3 getHeaders', async () => {
|
|
91
|
-
for (const client of clients) {
|
|
101
|
+
for (const { client, chain } of clients) {
|
|
92
102
|
const info = await client.getInfo()
|
|
93
103
|
const h0 = info.heightBulk + 1
|
|
94
104
|
const h1 = info.heightLive || 10
|
|
@@ -113,21 +123,21 @@ describe(`ChaintracksClientApi tests`, () => {
|
|
|
113
123
|
})
|
|
114
124
|
|
|
115
125
|
test('4 findChainTipHeader', async () => {
|
|
116
|
-
for (const client of clients) {
|
|
126
|
+
for (const { client, chain } of clients) {
|
|
117
127
|
const tipHeader = await client.findChainTipHeader()
|
|
118
128
|
expect(tipHeader.height >= firstTip.height).toBe(true)
|
|
119
129
|
}
|
|
120
130
|
})
|
|
121
131
|
|
|
122
132
|
test('5 findChainTipHash', async () => {
|
|
123
|
-
for (const client of clients) {
|
|
133
|
+
for (const { client, chain } of clients) {
|
|
124
134
|
const hash = await client.findChainTipHash()
|
|
125
135
|
expect(hash.length === 64).toBe(true)
|
|
126
136
|
}
|
|
127
137
|
})
|
|
128
138
|
|
|
129
139
|
test('6 findHeaderForHeight', async () => {
|
|
130
|
-
for (const client of clients) {
|
|
140
|
+
for (const { client, chain } of clients) {
|
|
131
141
|
const header0 = await client.findHeaderForHeight(0)
|
|
132
142
|
expect(header0 !== undefined).toBe(true)
|
|
133
143
|
if (header0) {
|
|
@@ -137,13 +147,13 @@ describe(`ChaintracksClientApi tests`, () => {
|
|
|
137
147
|
const header = await client.findHeaderForHeight(firstTip.height)
|
|
138
148
|
expect(header && header.height === firstTip.height).toBe(true)
|
|
139
149
|
|
|
140
|
-
const missing = await client.findHeaderForHeight(
|
|
150
|
+
const missing = await client.findHeaderForHeight(99999999)
|
|
141
151
|
expect(missing === undefined).toBe(true)
|
|
142
152
|
}
|
|
143
153
|
})
|
|
144
154
|
|
|
145
155
|
test('7 addHeader', async () => {
|
|
146
|
-
for (const client of clients) {
|
|
156
|
+
for (const { client, chain } of clients) {
|
|
147
157
|
const t = await client.findChainTipHeader()
|
|
148
158
|
const h: BaseBlockHeader = {
|
|
149
159
|
version: t.version,
|
|
@@ -42,11 +42,19 @@ export class LocalCdnServer {
|
|
|
42
42
|
this.app.get('/download/:filename', (req, res) => {
|
|
43
43
|
const filePath = path.join(this.folder, req.params.filename)
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
// Ensure filePath stays within the allowed folder (prevent directory traversal)
|
|
46
|
+
const resolvedFolder = path.resolve(this.folder)
|
|
47
|
+
const resolvedFilePath = path.resolve(filePath)
|
|
48
|
+
if (!resolvedFilePath.startsWith(resolvedFolder + path.sep)) {
|
|
49
|
+
// Prevent access to files outside the allowed directory
|
|
50
|
+
return res.status(403).json({ error: 'Access denied' })
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!fs.existsSync(resolvedFilePath)) {
|
|
46
54
|
return res.status(404).json({ error: 'File not found' })
|
|
47
55
|
}
|
|
48
56
|
|
|
49
|
-
res.download(
|
|
57
|
+
res.download(resolvedFilePath, err => {
|
|
50
58
|
if (err) {
|
|
51
59
|
res.status(500).json({ error: 'Error downloading file' })
|
|
52
60
|
}
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
} from './blockHeaderUtilities'
|
|
17
17
|
import { ChaintracksStorageBulkFileApi } from '../Api/ChaintracksStorageApi'
|
|
18
18
|
import { ChaintracksFetch } from './ChaintracksFetch'
|
|
19
|
-
import { logger } from '../../../../../test/utils/TestUtilsWalletStorage'
|
|
20
19
|
import { ChaintracksFsApi } from '../Api/ChaintracksFsApi'
|
|
21
20
|
import { SingleWriterMultiReaderLock } from './SingleWriterMultiReaderLock'
|
|
22
21
|
|
|
@@ -110,7 +109,7 @@ export class BulkFileDataManager {
|
|
|
110
109
|
log += ` url: ${url}\n`
|
|
111
110
|
log += ` bulk range before: ${rangeBefore}\n`
|
|
112
111
|
log += ` bulk range after: ${rangeAfter}\n`
|
|
113
|
-
|
|
112
|
+
console.log(log)
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
async setStorage(storage: ChaintracksStorageBulkFileApi): Promise<void> {
|
|
@@ -188,7 +187,7 @@ export class BulkFileDataManager {
|
|
|
188
187
|
}
|
|
189
188
|
}
|
|
190
189
|
}
|
|
191
|
-
|
|
190
|
+
console.log(`BulkFileDataManager.merge:\n${this.toLogString(r)}\n`)
|
|
192
191
|
return r
|
|
193
192
|
}
|
|
194
193
|
|
|
@@ -15,6 +15,9 @@ export function createDefaultWalletServicesOptions(
|
|
|
15
15
|
? 'mainnet_9596de07e92300c6287e4393594ae39c' // no plan
|
|
16
16
|
: 'testnet_0e6cf72133b43ea2d7861da2a38684e3' // personal "starter" key
|
|
17
17
|
|
|
18
|
+
//const chaintracksUrl = `https://npm-registry.babbage.systems:${chain === 'main' ? 8084 : 8083}`
|
|
19
|
+
const chaintracksUrl = `https://${chain}net-chaintracks.babbage.systems`
|
|
20
|
+
|
|
18
21
|
const o: WalletServicesOptions = {
|
|
19
22
|
chain,
|
|
20
23
|
taalApiKey,
|
|
@@ -36,11 +39,8 @@ export function createDefaultWalletServicesOptions(
|
|
|
36
39
|
fiatUpdateMsecs: 1000 * 60 * 60 * 24, // 24 hours
|
|
37
40
|
disableMapiCallback: true, // Rely on WalletMonitor by default.
|
|
38
41
|
exchangeratesapiKey: 'bd539d2ff492bcb5619d5f27726a766f',
|
|
39
|
-
chaintracksFiatExchangeRatesUrl:
|
|
40
|
-
chaintracks: new ChaintracksServiceClient(
|
|
41
|
-
chain,
|
|
42
|
-
`https://npm-registry.babbage.systems:${chain === 'main' ? 8084 : 8083}`
|
|
43
|
-
),
|
|
42
|
+
chaintracksFiatExchangeRatesUrl: `${chaintracksUrl}/getFiatExchangeRates`,
|
|
43
|
+
chaintracks: new ChaintracksServiceClient(chain, chaintracksUrl),
|
|
44
44
|
arcUrl: arcDefaultUrl(chain),
|
|
45
45
|
arcConfig: {
|
|
46
46
|
apiKey: arcApiKey ?? undefined,
|
|
@@ -63,14 +63,14 @@ export async function internalizeAction(
|
|
|
63
63
|
function setupWalletPaymentForOutput(o: InternalizeOutput, dargs: ValidInternalizeActionArgs) {
|
|
64
64
|
const p = o.paymentRemittance
|
|
65
65
|
const output = tx.outputs[o.outputIndex]
|
|
66
|
-
if (!p) throw new WERR_INVALID_PARAMETER('
|
|
66
|
+
if (!p) throw new WERR_INVALID_PARAMETER('paymentRemittance', `valid for protocol ${o.protocol}`)
|
|
67
67
|
|
|
68
68
|
const keyID = `${p.derivationPrefix} ${p.derivationSuffix}`
|
|
69
69
|
|
|
70
70
|
const privKey = wallet.keyDeriver!.derivePrivateKey(brc29ProtocolID, keyID, p.senderIdentityKey)
|
|
71
71
|
const expectedLockScript = new P2PKH().lock(privKey.toAddress())
|
|
72
72
|
if (output.lockingScript.toHex() !== expectedLockScript.toHex())
|
|
73
|
-
throw new WERR_INVALID_PARAMETER('
|
|
73
|
+
throw new WERR_INVALID_PARAMETER('paymentRemittance', `locked by script conforming to BRC-29`)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
function setupBasketInsertionForOutput(o: InternalizeOutput, dargs: ValidInternalizeActionArgs) {
|
|
@@ -103,6 +103,7 @@ export abstract class StorageProvider extends StorageReaderWriter implements Wal
|
|
|
103
103
|
this.feeModel = options.feeModel
|
|
104
104
|
this.commissionPubKeyHex = options.commissionPubKeyHex
|
|
105
105
|
this.commissionSatoshis = options.commissionSatoshis
|
|
106
|
+
this.maxRecursionDepth = 12
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
abstract reviewStatus(args: { agedLimit: Date; trx?: TrxToken }): Promise<{ log: string }>
|
|
@@ -1,32 +1,9 @@
|
|
|
1
1
|
import { Beef, ListActionsResult, ListOutputsResult } from '@bsv/sdk'
|
|
2
|
+
import { WalletError } from '../../sdk/WalletError'
|
|
3
|
+
import { StorageAdminStats, StorageProvider } from '../StorageProvider'
|
|
4
|
+
import { Chain } from '../../sdk/types'
|
|
5
|
+
import { Services } from '../../services/Services'
|
|
2
6
|
import {
|
|
3
|
-
TrxToken,
|
|
4
|
-
PurgeParams,
|
|
5
|
-
PurgeResults,
|
|
6
|
-
ProvenOrRawTx,
|
|
7
|
-
AuthId,
|
|
8
|
-
ValidListActionsArgs,
|
|
9
|
-
ValidListOutputsArgs,
|
|
10
|
-
FindCertificatesArgs,
|
|
11
|
-
FindOutputBasketsArgs,
|
|
12
|
-
FindOutputsArgs,
|
|
13
|
-
FindOutputTagMapsArgs,
|
|
14
|
-
FindProvenTxReqsArgs,
|
|
15
|
-
FindProvenTxsArgs,
|
|
16
|
-
FindTxLabelMapsArgs,
|
|
17
|
-
FindCertificateFieldsArgs,
|
|
18
|
-
FindCommissionsArgs,
|
|
19
|
-
FindMonitorEventsArgs,
|
|
20
|
-
FindOutputTagsArgs,
|
|
21
|
-
FindSyncStatesArgs,
|
|
22
|
-
FindTransactionsArgs,
|
|
23
|
-
FindTxLabelsArgs,
|
|
24
|
-
FindUsersArgs,
|
|
25
|
-
FindForUserSincePagedArgs,
|
|
26
|
-
StorageGetBeefOptions
|
|
27
|
-
} from '../../sdk'
|
|
28
|
-
import {
|
|
29
|
-
StorageProvider,
|
|
30
7
|
TableCertificate,
|
|
31
8
|
TableCertificateField,
|
|
32
9
|
TableCertificateX,
|
|
@@ -43,17 +20,38 @@ import {
|
|
|
43
20
|
TableTransaction,
|
|
44
21
|
TableTxLabel,
|
|
45
22
|
TableTxLabelMap,
|
|
46
|
-
TableUser
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
23
|
+
TableUser
|
|
24
|
+
} from '../schema/tables'
|
|
25
|
+
import {
|
|
26
|
+
AuthId,
|
|
27
|
+
FindCertificateFieldsArgs,
|
|
28
|
+
FindCertificatesArgs,
|
|
29
|
+
FindCommissionsArgs,
|
|
30
|
+
FindForUserSincePagedArgs,
|
|
31
|
+
FindMonitorEventsArgs,
|
|
32
|
+
FindOutputBasketsArgs,
|
|
33
|
+
FindOutputsArgs,
|
|
34
|
+
FindOutputTagMapsArgs,
|
|
35
|
+
FindOutputTagsArgs,
|
|
36
|
+
FindProvenTxReqsArgs,
|
|
37
|
+
FindProvenTxsArgs,
|
|
38
|
+
FindSyncStatesArgs,
|
|
39
|
+
FindTransactionsArgs,
|
|
40
|
+
FindTxLabelMapsArgs,
|
|
41
|
+
FindTxLabelsArgs,
|
|
42
|
+
FindUsersArgs,
|
|
43
|
+
ProvenOrRawTx,
|
|
44
|
+
PurgeParams,
|
|
45
|
+
PurgeResults,
|
|
46
|
+
StorageGetBeefOptions,
|
|
47
|
+
TrxToken
|
|
48
|
+
} from '../../sdk/WalletStorage.interfaces'
|
|
49
|
+
import { ValidListActionsArgs, ValidListOutputsArgs } from '../../sdk/validationHelpers'
|
|
52
50
|
|
|
53
51
|
describe('getBeefForTransaction tests', () => {
|
|
54
52
|
jest.setTimeout(99999999)
|
|
55
53
|
|
|
56
|
-
test('
|
|
54
|
+
test('0 ProtoStorage.getBeefForTxid', async () => {
|
|
57
55
|
const ps = new ProtoStorage('main')
|
|
58
56
|
const beef = await ps.getBeefForTxid('794f836052ad73732a550c38bea3697a722c6a1e54bcbe63735ba79e0d23f623')
|
|
59
57
|
expect(beef.bumps.length > 0)
|
|
@@ -68,7 +66,7 @@ class ProtoStorage extends StorageProvider {
|
|
|
68
66
|
gbo: StorageGetBeefOptions
|
|
69
67
|
whatsOnChainApiKey?: string
|
|
70
68
|
|
|
71
|
-
constructor(chain:
|
|
69
|
+
constructor(chain: Chain) {
|
|
72
70
|
const o = StorageProvider.createStorageBaseOptions(chain)
|
|
73
71
|
super(o)
|
|
74
72
|
const so = Services.createDefaultOptions(chain)
|
|
@@ -80,6 +78,7 @@ class ProtoStorage extends StorageProvider {
|
|
|
80
78
|
ignoreServices: false,
|
|
81
79
|
ignoreStorage: true
|
|
82
80
|
}
|
|
81
|
+
this.maxRecursionDepth = 2
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
async getBeefForTxid(txid: string): Promise<Beef> {
|
package/src/utility/Format.ts
CHANGED
|
@@ -101,7 +101,7 @@ export abstract class Format {
|
|
|
101
101
|
|
|
102
102
|
static toLogStringAdminStats(s: StorageAdminStats): string {
|
|
103
103
|
let log = `StorageAdminStats: ${s.when} ${s.requestedBy}\n`
|
|
104
|
-
log += ` ${al('', 13)} ${ar('Day',
|
|
104
|
+
log += ` ${al('', 13)} ${ar('Day', 18)} ${ar('Month', 18)} ${ar('Total', 18)}\n`
|
|
105
105
|
log += dmt('users', s.usersDay, s.usersMonth, s.usersTotal)
|
|
106
106
|
log += dmt('change sats', sa(s.satoshisDefaultDay), sa(s.satoshisDefaultMonth), sa(s.satoshisDefaultTotal))
|
|
107
107
|
log += dmt('other sats', sa(s.satoshisOtherDay), sa(s.satoshisOtherMonth), sa(s.satoshisOtherTotal))
|
|
@@ -122,7 +122,7 @@ export abstract class Format {
|
|
|
122
122
|
return log
|
|
123
123
|
|
|
124
124
|
function dmt(l: string, d: number | string, m: number | string, t: number | string): string {
|
|
125
|
-
return ` ${al(l, 13)} ${ar(d,
|
|
125
|
+
return ` ${al(l, 13)} ${ar(d, 18)} ${ar(m, 18)} ${ar(t, 18)}\n`
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
}
|
|
@@ -151,9 +151,16 @@ export function verifyOne<T>(results: T[], errorDescrition?: string): T {
|
|
|
151
151
|
|
|
152
152
|
/**
|
|
153
153
|
* Returns an await'able Promise that resolves in the given number of msecs.
|
|
154
|
+
* @param msecs number of milliseconds to wait before resolving the promise.
|
|
155
|
+
* Must be greater than zero and less than 2 minutes (120,000 msecs)
|
|
154
156
|
* @publicbody
|
|
155
157
|
*/
|
|
156
158
|
export function wait(msecs: number): Promise<void> {
|
|
159
|
+
const MIN_WAIT = 0
|
|
160
|
+
const MAX_WAIT = 2 * 60 * 1000 // maximum allowed wait in ms (2 minutes)
|
|
161
|
+
if (typeof msecs !== 'number' || !Number.isFinite(msecs) || isNaN(msecs) || msecs < MIN_WAIT || msecs > MAX_WAIT) {
|
|
162
|
+
throw new WERR_INVALID_PARAMETER('msecs', `a number between ${MIN_WAIT} and ${MAX_WAIT} msecs, not ${msecs}.`)
|
|
163
|
+
}
|
|
157
164
|
return new Promise(resolve => setTimeout(resolve, msecs))
|
|
158
165
|
}
|
|
159
166
|
|
|
@@ -501,7 +501,7 @@ describe('idb update tests', () => {
|
|
|
501
501
|
})
|
|
502
502
|
|
|
503
503
|
test('7a updateTransactionStatus', async () => {
|
|
504
|
-
const { activeStorage: storage } = await _tu.createLegacyWalletSQLiteCopy('
|
|
504
|
+
const { activeStorage: storage } = await _tu.createLegacyWalletSQLiteCopy('idb_updateTransactionStatus7a')
|
|
505
505
|
|
|
506
506
|
let tx = verifyOne(
|
|
507
507
|
await storage.findTransactions({
|