@arkade-os/sdk 0.3.12 → 0.4.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +483 -54
- package/dist/cjs/adapters/expo-db.js +35 -0
- package/dist/cjs/asset/assetGroup.js +141 -0
- package/dist/cjs/asset/assetId.js +88 -0
- package/dist/cjs/asset/assetInput.js +204 -0
- package/dist/cjs/asset/assetOutput.js +159 -0
- package/dist/cjs/asset/assetRef.js +82 -0
- package/dist/cjs/asset/index.js +24 -0
- package/dist/cjs/asset/metadata.js +172 -0
- package/dist/cjs/asset/packet.js +164 -0
- package/dist/cjs/asset/types.js +25 -0
- package/dist/cjs/asset/utils.js +105 -0
- package/dist/cjs/contracts/arkcontract.js +148 -0
- package/dist/cjs/contracts/contractManager.js +436 -0
- package/dist/cjs/contracts/contractWatcher.js +567 -0
- package/dist/cjs/contracts/handlers/default.js +85 -0
- package/dist/cjs/contracts/handlers/delegate.js +89 -0
- package/dist/cjs/contracts/handlers/helpers.js +105 -0
- package/dist/cjs/contracts/handlers/index.js +19 -0
- package/dist/cjs/contracts/handlers/registry.js +89 -0
- package/dist/cjs/contracts/handlers/vhtlc.js +193 -0
- package/dist/cjs/contracts/index.js +41 -0
- package/dist/cjs/contracts/types.js +2 -0
- package/dist/cjs/db/manager.js +97 -0
- package/dist/cjs/forfeit.js +12 -8
- package/dist/cjs/identity/index.js +1 -0
- package/dist/cjs/identity/seedIdentity.js +255 -0
- package/dist/cjs/index.js +70 -14
- package/dist/cjs/intent/index.js +28 -2
- package/dist/cjs/providers/ark.js +7 -0
- package/dist/cjs/providers/delegator.js +66 -0
- package/dist/cjs/providers/expoIndexer.js +5 -0
- package/dist/cjs/providers/indexer.js +68 -1
- package/dist/cjs/providers/onchain.js +2 -2
- package/dist/cjs/providers/utils.js +1 -0
- package/dist/cjs/repositories/contractRepository.js +0 -103
- package/dist/cjs/repositories/inMemory/contractRepository.js +55 -0
- package/dist/cjs/repositories/inMemory/walletRepository.js +80 -0
- package/dist/cjs/repositories/index.js +16 -0
- package/dist/cjs/repositories/indexedDB/contractRepository.js +187 -0
- package/dist/cjs/repositories/indexedDB/db.js +57 -0
- package/dist/cjs/repositories/indexedDB/schema.js +159 -0
- package/dist/cjs/repositories/indexedDB/walletRepository.js +338 -0
- package/dist/cjs/repositories/indexedDB/websqlAdapter.js +144 -0
- package/dist/cjs/repositories/migrations/contractRepositoryImpl.js +127 -0
- package/dist/cjs/repositories/migrations/fromStorageAdapter.js +66 -0
- package/dist/cjs/repositories/migrations/walletRepositoryImpl.js +180 -0
- package/dist/cjs/repositories/walletRepository.js +0 -169
- package/dist/cjs/script/base.js +54 -0
- package/dist/cjs/script/delegate.js +49 -0
- package/dist/cjs/storage/asyncStorage.js +4 -1
- package/dist/cjs/storage/fileSystem.js +3 -0
- package/dist/cjs/storage/inMemory.js +3 -0
- package/dist/cjs/storage/indexedDB.js +5 -1
- package/dist/cjs/storage/localStorage.js +3 -0
- package/dist/cjs/utils/arkTransaction.js +16 -0
- package/dist/cjs/utils/transactionHistory.js +50 -0
- package/dist/cjs/utils/txSizeEstimator.js +39 -14
- package/dist/cjs/wallet/asset-manager.js +338 -0
- package/dist/cjs/wallet/asset.js +117 -0
- package/dist/cjs/wallet/batch.js +1 -1
- package/dist/cjs/wallet/delegator.js +235 -0
- package/dist/cjs/wallet/expo/background.js +133 -0
- package/dist/cjs/wallet/expo/index.js +9 -0
- package/dist/cjs/wallet/expo/wallet.js +231 -0
- package/dist/cjs/wallet/onchain.js +57 -12
- package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +568 -0
- package/dist/cjs/wallet/serviceWorker/wallet.js +383 -102
- package/dist/cjs/wallet/unroll.js +7 -2
- package/dist/cjs/wallet/utils.js +60 -0
- package/dist/cjs/wallet/validation.js +151 -0
- package/dist/cjs/wallet/vtxo-manager.js +1 -1
- package/dist/cjs/wallet/wallet.js +702 -260
- package/dist/cjs/worker/browser/service-worker-manager.js +82 -0
- package/dist/cjs/{wallet/serviceWorker → worker/browser}/utils.js +2 -1
- package/dist/cjs/worker/expo/asyncStorageTaskQueue.js +78 -0
- package/dist/cjs/worker/expo/index.js +12 -0
- package/dist/cjs/worker/expo/processors/contractPollProcessor.js +61 -0
- package/dist/cjs/worker/expo/processors/index.js +6 -0
- package/dist/cjs/worker/expo/taskQueue.js +41 -0
- package/dist/cjs/worker/expo/taskRunner.js +57 -0
- package/dist/cjs/worker/messageBus.js +252 -0
- package/dist/esm/adapters/expo-db.js +27 -0
- package/dist/esm/asset/assetGroup.js +137 -0
- package/dist/esm/asset/assetId.js +84 -0
- package/dist/esm/asset/assetInput.js +199 -0
- package/dist/esm/asset/assetOutput.js +154 -0
- package/dist/esm/asset/assetRef.js +78 -0
- package/dist/esm/asset/index.js +8 -0
- package/dist/esm/asset/metadata.js +167 -0
- package/dist/esm/asset/packet.js +159 -0
- package/dist/esm/asset/types.js +22 -0
- package/dist/esm/asset/utils.js +99 -0
- package/dist/esm/contracts/arkcontract.js +141 -0
- package/dist/esm/contracts/contractManager.js +432 -0
- package/dist/esm/contracts/contractWatcher.js +563 -0
- package/dist/esm/contracts/handlers/default.js +82 -0
- package/dist/esm/contracts/handlers/delegate.js +86 -0
- package/dist/esm/contracts/handlers/helpers.js +66 -0
- package/dist/esm/contracts/handlers/index.js +12 -0
- package/dist/esm/contracts/handlers/registry.js +86 -0
- package/dist/esm/contracts/handlers/vhtlc.js +190 -0
- package/dist/esm/contracts/index.js +13 -0
- package/dist/esm/contracts/types.js +1 -0
- package/dist/esm/db/manager.js +92 -0
- package/dist/esm/forfeit.js +11 -8
- package/dist/esm/identity/index.js +1 -0
- package/dist/esm/identity/seedIdentity.js +249 -0
- package/dist/esm/index.js +25 -15
- package/dist/esm/intent/index.js +28 -2
- package/dist/esm/providers/ark.js +7 -0
- package/dist/esm/providers/delegator.js +62 -0
- package/dist/esm/providers/expoIndexer.js +5 -0
- package/dist/esm/providers/indexer.js +68 -1
- package/dist/esm/providers/onchain.js +2 -2
- package/dist/esm/providers/utils.js +1 -0
- package/dist/esm/repositories/contractRepository.js +1 -101
- package/dist/esm/repositories/inMemory/contractRepository.js +51 -0
- package/dist/esm/repositories/inMemory/walletRepository.js +76 -0
- package/dist/esm/repositories/index.js +8 -0
- package/dist/esm/repositories/indexedDB/contractRepository.js +183 -0
- package/dist/esm/repositories/indexedDB/db.js +42 -0
- package/dist/esm/repositories/indexedDB/schema.js +155 -0
- package/dist/esm/repositories/indexedDB/walletRepository.js +334 -0
- package/dist/esm/repositories/indexedDB/websqlAdapter.js +138 -0
- package/dist/esm/repositories/migrations/contractRepositoryImpl.js +121 -0
- package/dist/esm/repositories/migrations/fromStorageAdapter.js +58 -0
- package/dist/esm/repositories/migrations/walletRepositoryImpl.js +176 -0
- package/dist/esm/repositories/walletRepository.js +1 -167
- package/dist/esm/script/base.js +21 -1
- package/dist/esm/script/delegate.js +46 -0
- package/dist/esm/storage/asyncStorage.js +4 -1
- package/dist/esm/storage/fileSystem.js +3 -0
- package/dist/esm/storage/inMemory.js +3 -0
- package/dist/esm/storage/indexedDB.js +5 -1
- package/dist/esm/storage/localStorage.js +3 -0
- package/dist/esm/utils/arkTransaction.js +15 -0
- package/dist/esm/utils/transactionHistory.js +50 -0
- package/dist/esm/utils/txSizeEstimator.js +39 -14
- package/dist/esm/wallet/asset-manager.js +333 -0
- package/dist/esm/wallet/asset.js +111 -0
- package/dist/esm/wallet/batch.js +1 -1
- package/dist/esm/wallet/delegator.js +231 -0
- package/dist/esm/wallet/expo/background.js +128 -0
- package/dist/esm/wallet/expo/index.js +2 -0
- package/dist/esm/wallet/expo/wallet.js +194 -0
- package/dist/esm/wallet/onchain.js +57 -12
- package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +564 -0
- package/dist/esm/wallet/serviceWorker/wallet.js +382 -101
- package/dist/esm/wallet/unroll.js +7 -2
- package/dist/esm/wallet/utils.js +55 -0
- package/dist/esm/wallet/validation.js +139 -0
- package/dist/esm/wallet/vtxo-manager.js +1 -1
- package/dist/esm/wallet/wallet.js +704 -229
- package/dist/esm/worker/browser/service-worker-manager.js +76 -0
- package/dist/esm/{wallet/serviceWorker → worker/browser}/utils.js +2 -1
- package/dist/esm/worker/expo/asyncStorageTaskQueue.js +74 -0
- package/dist/esm/worker/expo/index.js +4 -0
- package/dist/esm/worker/expo/processors/contractPollProcessor.js +58 -0
- package/dist/esm/worker/expo/processors/index.js +1 -0
- package/dist/esm/worker/expo/taskQueue.js +37 -0
- package/dist/esm/worker/expo/taskRunner.js +54 -0
- package/dist/esm/worker/messageBus.js +248 -0
- package/dist/types/adapters/expo-db.d.ts +7 -0
- package/dist/types/asset/assetGroup.d.ts +28 -0
- package/dist/types/asset/assetId.d.ts +19 -0
- package/dist/types/asset/assetInput.d.ts +46 -0
- package/dist/types/asset/assetOutput.d.ts +39 -0
- package/dist/types/asset/assetRef.d.ts +25 -0
- package/dist/types/asset/index.d.ts +8 -0
- package/dist/types/asset/metadata.d.ts +37 -0
- package/dist/types/asset/packet.d.ts +27 -0
- package/dist/types/asset/types.d.ts +18 -0
- package/dist/types/asset/utils.d.ts +21 -0
- package/dist/types/contracts/arkcontract.d.ts +101 -0
- package/dist/types/contracts/contractManager.d.ts +331 -0
- package/dist/types/contracts/contractWatcher.d.ts +192 -0
- package/dist/types/contracts/handlers/default.d.ts +19 -0
- package/dist/types/contracts/handlers/delegate.d.ts +21 -0
- package/dist/types/contracts/handlers/helpers.d.ts +18 -0
- package/dist/types/contracts/handlers/index.d.ts +7 -0
- package/dist/types/contracts/handlers/registry.d.ts +65 -0
- package/dist/types/contracts/handlers/vhtlc.d.ts +32 -0
- package/dist/types/contracts/index.d.ts +14 -0
- package/dist/types/contracts/types.d.ts +222 -0
- package/dist/types/db/manager.d.ts +22 -0
- package/dist/types/forfeit.d.ts +2 -1
- package/dist/types/identity/index.d.ts +1 -0
- package/dist/types/identity/seedIdentity.d.ts +128 -0
- package/dist/types/index.d.ts +21 -12
- package/dist/types/intent/index.d.ts +2 -1
- package/dist/types/providers/ark.d.ts +11 -2
- package/dist/types/providers/delegator.d.ts +29 -0
- package/dist/types/providers/indexer.d.ts +11 -1
- package/dist/types/repositories/contractRepository.d.ts +30 -19
- package/dist/types/repositories/inMemory/contractRepository.d.ts +17 -0
- package/dist/types/repositories/inMemory/walletRepository.d.ts +26 -0
- package/dist/types/repositories/index.d.ts +7 -0
- package/dist/types/repositories/indexedDB/contractRepository.d.ts +21 -0
- package/dist/types/repositories/indexedDB/db.d.ts +56 -0
- package/dist/types/repositories/indexedDB/schema.d.ts +8 -0
- package/dist/types/repositories/indexedDB/walletRepository.d.ts +25 -0
- package/dist/types/repositories/indexedDB/websqlAdapter.d.ts +49 -0
- package/dist/types/repositories/migrations/contractRepositoryImpl.d.ts +24 -0
- package/dist/types/repositories/migrations/fromStorageAdapter.d.ts +19 -0
- package/dist/types/repositories/migrations/walletRepositoryImpl.d.ts +27 -0
- package/dist/types/repositories/walletRepository.d.ts +13 -24
- package/dist/types/script/base.d.ts +1 -0
- package/dist/types/script/delegate.d.ts +36 -0
- package/dist/types/storage/asyncStorage.d.ts +4 -0
- package/dist/types/storage/fileSystem.d.ts +3 -0
- package/dist/types/storage/inMemory.d.ts +3 -0
- package/dist/types/storage/index.d.ts +3 -0
- package/dist/types/storage/indexedDB.d.ts +3 -0
- package/dist/types/storage/localStorage.d.ts +3 -0
- package/dist/types/utils/arkTransaction.d.ts +6 -0
- package/dist/types/utils/txSizeEstimator.d.ts +12 -2
- package/dist/types/wallet/asset-manager.d.ts +78 -0
- package/dist/types/wallet/asset.d.ts +21 -0
- package/dist/types/wallet/batch.d.ts +1 -1
- package/dist/types/wallet/delegator.d.ts +24 -0
- package/dist/types/wallet/expo/background.d.ts +66 -0
- package/dist/types/wallet/expo/index.d.ts +4 -0
- package/dist/types/wallet/expo/wallet.d.ts +97 -0
- package/dist/types/wallet/index.d.ts +75 -2
- package/dist/types/wallet/onchain.d.ts +22 -1
- package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +366 -0
- package/dist/types/wallet/serviceWorker/wallet.d.ts +20 -11
- package/dist/types/wallet/utils.d.ts +13 -1
- package/dist/types/wallet/validation.d.ts +24 -0
- package/dist/types/wallet/wallet.d.ts +111 -17
- package/dist/types/worker/browser/service-worker-manager.d.ts +21 -0
- package/dist/types/{wallet/serviceWorker → worker/browser}/utils.d.ts +2 -1
- package/dist/types/worker/expo/asyncStorageTaskQueue.d.ts +46 -0
- package/dist/types/worker/expo/index.d.ts +7 -0
- package/dist/types/worker/expo/processors/contractPollProcessor.d.ts +14 -0
- package/dist/types/worker/expo/processors/index.d.ts +1 -0
- package/dist/types/worker/expo/taskQueue.d.ts +50 -0
- package/dist/types/worker/expo/taskRunner.d.ts +42 -0
- package/dist/types/worker/messageBus.d.ts +109 -0
- package/package.json +71 -17
- package/dist/cjs/wallet/serviceWorker/request.js +0 -78
- package/dist/cjs/wallet/serviceWorker/response.js +0 -222
- package/dist/cjs/wallet/serviceWorker/worker.js +0 -655
- package/dist/esm/wallet/serviceWorker/request.js +0 -75
- package/dist/esm/wallet/serviceWorker/response.js +0 -219
- package/dist/esm/wallet/serviceWorker/worker.js +0 -651
- package/dist/types/wallet/serviceWorker/request.d.ts +0 -74
- package/dist/types/wallet/serviceWorker/response.d.ts +0 -123
- package/dist/types/wallet/serviceWorker/worker.d.ts +0 -53
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DB_VERSION = exports.LEGACY_STORE_CONTRACT_COLLECTIONS = exports.STORE_CONTRACTS = exports.STORE_WALLET_STATE = exports.STORE_TRANSACTIONS = exports.STORE_UTXOS = exports.STORE_VTXOS = void 0;
|
|
4
|
+
exports.initDatabase = initDatabase;
|
|
5
|
+
// Store names introduced in V2, they are all new to the migration
|
|
6
|
+
exports.STORE_VTXOS = "vtxos";
|
|
7
|
+
exports.STORE_UTXOS = "utxos";
|
|
8
|
+
exports.STORE_TRANSACTIONS = "transactions";
|
|
9
|
+
exports.STORE_WALLET_STATE = "walletState";
|
|
10
|
+
exports.STORE_CONTRACTS = "contracts";
|
|
11
|
+
// @deprecated use only for migrations, this is created in V1
|
|
12
|
+
exports.LEGACY_STORE_CONTRACT_COLLECTIONS = "contractsCollections";
|
|
13
|
+
exports.DB_VERSION = 2;
|
|
14
|
+
function initDatabase(db) {
|
|
15
|
+
// Create wallet stores
|
|
16
|
+
if (!db.objectStoreNames.contains(exports.STORE_VTXOS)) {
|
|
17
|
+
const vtxosStore = db.createObjectStore(exports.STORE_VTXOS, {
|
|
18
|
+
keyPath: ["address", "txid", "vout"],
|
|
19
|
+
});
|
|
20
|
+
if (!vtxosStore.indexNames.contains("address")) {
|
|
21
|
+
vtxosStore.createIndex("address", "address", {
|
|
22
|
+
unique: false,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (!vtxosStore.indexNames.contains("txid")) {
|
|
26
|
+
vtxosStore.createIndex("txid", "txid", { unique: false });
|
|
27
|
+
}
|
|
28
|
+
if (!vtxosStore.indexNames.contains("value")) {
|
|
29
|
+
vtxosStore.createIndex("value", "value", { unique: false });
|
|
30
|
+
}
|
|
31
|
+
if (!vtxosStore.indexNames.contains("status")) {
|
|
32
|
+
vtxosStore.createIndex("status", "status", {
|
|
33
|
+
unique: false,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (!vtxosStore.indexNames.contains("virtualStatus")) {
|
|
37
|
+
vtxosStore.createIndex("virtualStatus", "virtualStatus", {
|
|
38
|
+
unique: false,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (!vtxosStore.indexNames.contains("createdAt")) {
|
|
42
|
+
vtxosStore.createIndex("createdAt", "createdAt", {
|
|
43
|
+
unique: false,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (!vtxosStore.indexNames.contains("isSpent")) {
|
|
47
|
+
vtxosStore.createIndex("isSpent", "isSpent", {
|
|
48
|
+
unique: false,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (!vtxosStore.indexNames.contains("isUnrolled")) {
|
|
52
|
+
vtxosStore.createIndex("isUnrolled", "isUnrolled", {
|
|
53
|
+
unique: false,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (!vtxosStore.indexNames.contains("spentBy")) {
|
|
57
|
+
vtxosStore.createIndex("spentBy", "spentBy", {
|
|
58
|
+
unique: false,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (!vtxosStore.indexNames.contains("settledBy")) {
|
|
62
|
+
vtxosStore.createIndex("settledBy", "settledBy", {
|
|
63
|
+
unique: false,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (!vtxosStore.indexNames.contains("arkTxId")) {
|
|
67
|
+
vtxosStore.createIndex("arkTxId", "arkTxId", {
|
|
68
|
+
unique: false,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!db.objectStoreNames.contains(exports.STORE_UTXOS)) {
|
|
73
|
+
const utxosStore = db.createObjectStore(exports.STORE_UTXOS, {
|
|
74
|
+
keyPath: ["address", "txid", "vout"],
|
|
75
|
+
});
|
|
76
|
+
if (!utxosStore.indexNames.contains("address")) {
|
|
77
|
+
utxosStore.createIndex("address", "address", {
|
|
78
|
+
unique: false,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (!utxosStore.indexNames.contains("txid")) {
|
|
82
|
+
utxosStore.createIndex("txid", "txid", { unique: false });
|
|
83
|
+
}
|
|
84
|
+
if (!utxosStore.indexNames.contains("value")) {
|
|
85
|
+
utxosStore.createIndex("value", "value", { unique: false });
|
|
86
|
+
}
|
|
87
|
+
if (!utxosStore.indexNames.contains("status")) {
|
|
88
|
+
utxosStore.createIndex("status", "status", {
|
|
89
|
+
unique: false,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (!db.objectStoreNames.contains(exports.STORE_TRANSACTIONS)) {
|
|
94
|
+
const transactionsStore = db.createObjectStore(exports.STORE_TRANSACTIONS, {
|
|
95
|
+
keyPath: [
|
|
96
|
+
"address",
|
|
97
|
+
"keyBoardingTxid",
|
|
98
|
+
"keyCommitmentTxid",
|
|
99
|
+
"keyArkTxid",
|
|
100
|
+
],
|
|
101
|
+
});
|
|
102
|
+
if (!transactionsStore.indexNames.contains("address")) {
|
|
103
|
+
transactionsStore.createIndex("address", "address", {
|
|
104
|
+
unique: false,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (!transactionsStore.indexNames.contains("type")) {
|
|
108
|
+
transactionsStore.createIndex("type", "type", {
|
|
109
|
+
unique: false,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (!transactionsStore.indexNames.contains("amount")) {
|
|
113
|
+
transactionsStore.createIndex("amount", "amount", {
|
|
114
|
+
unique: false,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (!transactionsStore.indexNames.contains("settled")) {
|
|
118
|
+
transactionsStore.createIndex("settled", "settled", {
|
|
119
|
+
unique: false,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (!transactionsStore.indexNames.contains("createdAt")) {
|
|
123
|
+
transactionsStore.createIndex("createdAt", "createdAt", {
|
|
124
|
+
unique: false,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (!transactionsStore.indexNames.contains("arkTxid")) {
|
|
128
|
+
transactionsStore.createIndex("arkTxid", "key.arkTxid", {
|
|
129
|
+
unique: false,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!db.objectStoreNames.contains(exports.STORE_WALLET_STATE)) {
|
|
134
|
+
db.createObjectStore(exports.STORE_WALLET_STATE, {
|
|
135
|
+
keyPath: "key",
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
// Create contract stores
|
|
139
|
+
if (!db.objectStoreNames.contains(exports.STORE_CONTRACTS)) {
|
|
140
|
+
const contractsStore = db.createObjectStore(exports.STORE_CONTRACTS, {
|
|
141
|
+
keyPath: "script",
|
|
142
|
+
});
|
|
143
|
+
if (!contractsStore.indexNames.contains("type")) {
|
|
144
|
+
contractsStore.createIndex("type", "type", {
|
|
145
|
+
unique: false,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (!contractsStore.indexNames.contains("state")) {
|
|
149
|
+
contractsStore.createIndex("state", "state", {
|
|
150
|
+
unique: false,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (!db.objectStoreNames.contains(exports.LEGACY_STORE_CONTRACT_COLLECTIONS)) {
|
|
155
|
+
db.createObjectStore(exports.LEGACY_STORE_CONTRACT_COLLECTIONS, {
|
|
156
|
+
keyPath: "key",
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IndexedDBWalletRepository = void 0;
|
|
4
|
+
const db_1 = require("./db");
|
|
5
|
+
const manager_1 = require("../../db/manager");
|
|
6
|
+
const schema_1 = require("./schema");
|
|
7
|
+
const utils_1 = require("../../worker/browser/utils");
|
|
8
|
+
/**
|
|
9
|
+
* IndexedDB-based implementation of WalletRepository.
|
|
10
|
+
*/
|
|
11
|
+
class IndexedDBWalletRepository {
|
|
12
|
+
constructor(dbName = utils_1.DEFAULT_DB_NAME) {
|
|
13
|
+
this.dbName = dbName;
|
|
14
|
+
this.version = 1;
|
|
15
|
+
this.db = null;
|
|
16
|
+
}
|
|
17
|
+
async clear() {
|
|
18
|
+
try {
|
|
19
|
+
const db = await this.getDB();
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const transaction = db.transaction([
|
|
22
|
+
db_1.STORE_VTXOS,
|
|
23
|
+
db_1.STORE_UTXOS,
|
|
24
|
+
db_1.STORE_TRANSACTIONS,
|
|
25
|
+
db_1.STORE_WALLET_STATE,
|
|
26
|
+
], "readwrite");
|
|
27
|
+
const vtxosStore = transaction.objectStore(db_1.STORE_VTXOS);
|
|
28
|
+
const utxosStore = transaction.objectStore(db_1.STORE_UTXOS);
|
|
29
|
+
const transactionsStore = transaction.objectStore(db_1.STORE_TRANSACTIONS);
|
|
30
|
+
const walletStateStore = transaction.objectStore(db_1.STORE_WALLET_STATE);
|
|
31
|
+
const requests = [
|
|
32
|
+
vtxosStore.clear(),
|
|
33
|
+
utxosStore.clear(),
|
|
34
|
+
transactionsStore.clear(),
|
|
35
|
+
walletStateStore.clear(),
|
|
36
|
+
];
|
|
37
|
+
let completed = 0;
|
|
38
|
+
const checkComplete = () => {
|
|
39
|
+
completed++;
|
|
40
|
+
if (completed === requests.length) {
|
|
41
|
+
resolve();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
requests.forEach((request) => {
|
|
45
|
+
request.onsuccess = checkComplete;
|
|
46
|
+
request.onerror = () => reject(request.error);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error("Failed to clear wallet data:", error);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async [Symbol.asyncDispose]() {
|
|
56
|
+
if (!this.db)
|
|
57
|
+
return;
|
|
58
|
+
await (0, manager_1.closeDatabase)(this.dbName);
|
|
59
|
+
this.db = null;
|
|
60
|
+
}
|
|
61
|
+
async getVtxos(address) {
|
|
62
|
+
try {
|
|
63
|
+
const db = await this.getDB();
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
const transaction = db.transaction([db_1.STORE_VTXOS], "readonly");
|
|
66
|
+
const store = transaction.objectStore(db_1.STORE_VTXOS);
|
|
67
|
+
const index = store.index("address");
|
|
68
|
+
const request = index.getAll(address);
|
|
69
|
+
request.onerror = () => reject(request.error);
|
|
70
|
+
request.onsuccess = () => {
|
|
71
|
+
const results = request.result || [];
|
|
72
|
+
const vtxos = results.map(db_1.deserializeVtxo);
|
|
73
|
+
resolve(vtxos);
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error(`Failed to get VTXOs for address ${address}:`, error);
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async saveVtxos(address, vtxos) {
|
|
83
|
+
try {
|
|
84
|
+
const db = await this.getDB();
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const transaction = db.transaction([db_1.STORE_VTXOS], "readwrite");
|
|
87
|
+
const store = transaction.objectStore(db_1.STORE_VTXOS);
|
|
88
|
+
const promises = vtxos.map((vtxo) => {
|
|
89
|
+
return new Promise((resolveItem, rejectItem) => {
|
|
90
|
+
const serialized = (0, db_1.serializeVtxo)(vtxo);
|
|
91
|
+
const item = {
|
|
92
|
+
address,
|
|
93
|
+
...serialized,
|
|
94
|
+
};
|
|
95
|
+
const request = store.put(item);
|
|
96
|
+
request.onerror = () => rejectItem(request.error);
|
|
97
|
+
request.onsuccess = () => resolveItem();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
Promise.all(promises)
|
|
101
|
+
.then(() => resolve())
|
|
102
|
+
.catch(reject);
|
|
103
|
+
transaction.onerror = () => reject(transaction.error);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.error(`Failed to save VTXOs for address ${address}:`, error);
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async deleteVtxos(address) {
|
|
112
|
+
try {
|
|
113
|
+
const db = await this.getDB();
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
const transaction = db.transaction([db_1.STORE_VTXOS], "readwrite");
|
|
116
|
+
const store = transaction.objectStore(db_1.STORE_VTXOS);
|
|
117
|
+
const index = store.index("address");
|
|
118
|
+
const request = index.openCursor(IDBKeyRange.only(address));
|
|
119
|
+
request.onerror = () => reject(request.error);
|
|
120
|
+
request.onsuccess = () => {
|
|
121
|
+
const cursor = request.result;
|
|
122
|
+
if (cursor) {
|
|
123
|
+
cursor.delete();
|
|
124
|
+
cursor.continue();
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
resolve();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
console.error(`Failed to clear VTXOs for address ${address}:`, error);
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async getUtxos(address) {
|
|
138
|
+
try {
|
|
139
|
+
const db = await this.getDB();
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
const transaction = db.transaction([db_1.STORE_UTXOS], "readonly");
|
|
142
|
+
const store = transaction.objectStore(db_1.STORE_UTXOS);
|
|
143
|
+
const index = store.index("address");
|
|
144
|
+
const request = index.getAll(address);
|
|
145
|
+
request.onerror = () => reject(request.error);
|
|
146
|
+
request.onsuccess = () => {
|
|
147
|
+
const results = request.result || [];
|
|
148
|
+
const utxos = results.map(db_1.deserializeUtxo);
|
|
149
|
+
resolve(utxos);
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
console.error(`Failed to get UTXOs for address ${address}:`, error);
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async saveUtxos(address, utxos) {
|
|
159
|
+
try {
|
|
160
|
+
const db = await this.getDB();
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
const transaction = db.transaction([db_1.STORE_UTXOS], "readwrite");
|
|
163
|
+
const store = transaction.objectStore(db_1.STORE_UTXOS);
|
|
164
|
+
const promises = utxos.map((utxo) => {
|
|
165
|
+
return new Promise((resolveItem, rejectItem) => {
|
|
166
|
+
const serialized = (0, db_1.serializeUtxo)(utxo);
|
|
167
|
+
const item = {
|
|
168
|
+
address,
|
|
169
|
+
...serialized,
|
|
170
|
+
};
|
|
171
|
+
const request = store.put(item);
|
|
172
|
+
request.onerror = () => rejectItem(request.error);
|
|
173
|
+
request.onsuccess = () => resolveItem();
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
Promise.all(promises)
|
|
177
|
+
.then(() => resolve())
|
|
178
|
+
.catch(reject);
|
|
179
|
+
transaction.onerror = () => reject(transaction.error);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
console.error(`Failed to save UTXOs for address ${address}:`, error);
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async deleteUtxos(address) {
|
|
188
|
+
try {
|
|
189
|
+
const db = await this.getDB();
|
|
190
|
+
return new Promise((resolve, reject) => {
|
|
191
|
+
const transaction = db.transaction([db_1.STORE_UTXOS], "readwrite");
|
|
192
|
+
const store = transaction.objectStore(db_1.STORE_UTXOS);
|
|
193
|
+
const index = store.index("address");
|
|
194
|
+
const request = index.openCursor(IDBKeyRange.only(address));
|
|
195
|
+
request.onerror = () => reject(request.error);
|
|
196
|
+
request.onsuccess = () => {
|
|
197
|
+
const cursor = request.result;
|
|
198
|
+
if (cursor) {
|
|
199
|
+
cursor.delete();
|
|
200
|
+
cursor.continue();
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
resolve();
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
console.error(`Failed to clear UTXOs for address ${address}:`, error);
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
async getTransactionHistory(address) {
|
|
214
|
+
try {
|
|
215
|
+
const db = await this.getDB();
|
|
216
|
+
return new Promise((resolve, reject) => {
|
|
217
|
+
const transaction = db.transaction([db_1.STORE_TRANSACTIONS], "readonly");
|
|
218
|
+
const store = transaction.objectStore(db_1.STORE_TRANSACTIONS);
|
|
219
|
+
const index = store.index("address");
|
|
220
|
+
const request = index.getAll(address);
|
|
221
|
+
request.onerror = () => reject(request.error);
|
|
222
|
+
request.onsuccess = () => {
|
|
223
|
+
const results = request.result || [];
|
|
224
|
+
resolve(results.sort((a, b) => a.createdAt - b.createdAt));
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
console.error(`Failed to get transaction history for address ${address}:`, error);
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async saveTransactions(address, txs) {
|
|
234
|
+
try {
|
|
235
|
+
const db = await this.getDB();
|
|
236
|
+
return new Promise((resolve, reject) => {
|
|
237
|
+
const transaction = db.transaction([db_1.STORE_TRANSACTIONS], "readwrite");
|
|
238
|
+
const store = transaction.objectStore(db_1.STORE_TRANSACTIONS);
|
|
239
|
+
// Queue all put operations
|
|
240
|
+
txs.forEach((tx) => {
|
|
241
|
+
const item = {
|
|
242
|
+
address,
|
|
243
|
+
...tx,
|
|
244
|
+
keyBoardingTxid: tx.key.boardingTxid,
|
|
245
|
+
keyCommitmentTxid: tx.key.commitmentTxid,
|
|
246
|
+
keyArkTxid: tx.key.arkTxid,
|
|
247
|
+
};
|
|
248
|
+
store.put(item);
|
|
249
|
+
});
|
|
250
|
+
// Handle transaction completion
|
|
251
|
+
transaction.oncomplete = () => resolve();
|
|
252
|
+
transaction.onerror = () => reject(transaction.error);
|
|
253
|
+
transaction.onabort = () => reject(new Error("Transaction aborted"));
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
console.error(`Failed to save transactions for address ${address}:`, error);
|
|
258
|
+
throw error;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async deleteTransactions(address) {
|
|
262
|
+
try {
|
|
263
|
+
const db = await this.getDB();
|
|
264
|
+
return new Promise((resolve, reject) => {
|
|
265
|
+
const transaction = db.transaction([db_1.STORE_TRANSACTIONS], "readwrite");
|
|
266
|
+
const store = transaction.objectStore(db_1.STORE_TRANSACTIONS);
|
|
267
|
+
const index = store.index("address");
|
|
268
|
+
const request = index.openCursor(IDBKeyRange.only(address));
|
|
269
|
+
request.onerror = () => reject(request.error);
|
|
270
|
+
request.onsuccess = () => {
|
|
271
|
+
const cursor = request.result;
|
|
272
|
+
if (cursor) {
|
|
273
|
+
cursor.delete();
|
|
274
|
+
cursor.continue();
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
resolve();
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
console.error(`Failed to clear transactions for address ${address}:`, error);
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
async getWalletState() {
|
|
288
|
+
try {
|
|
289
|
+
const db = await this.getDB();
|
|
290
|
+
return new Promise((resolve, reject) => {
|
|
291
|
+
const transaction = db.transaction([db_1.STORE_WALLET_STATE], "readonly");
|
|
292
|
+
const store = transaction.objectStore(db_1.STORE_WALLET_STATE);
|
|
293
|
+
const request = store.get("state");
|
|
294
|
+
request.onerror = () => reject(request.error);
|
|
295
|
+
request.onsuccess = () => {
|
|
296
|
+
const result = request.result;
|
|
297
|
+
if (result && result.data) {
|
|
298
|
+
resolve(result.data);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
resolve(null);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
console.error("Failed to get wallet state:", error);
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async saveWalletState(state) {
|
|
312
|
+
try {
|
|
313
|
+
const db = await this.getDB();
|
|
314
|
+
return new Promise((resolve, reject) => {
|
|
315
|
+
const transaction = db.transaction([db_1.STORE_WALLET_STATE], "readwrite");
|
|
316
|
+
const store = transaction.objectStore(db_1.STORE_WALLET_STATE);
|
|
317
|
+
const item = {
|
|
318
|
+
key: "state",
|
|
319
|
+
data: state,
|
|
320
|
+
};
|
|
321
|
+
const request = store.put(item);
|
|
322
|
+
request.onerror = () => reject(request.error);
|
|
323
|
+
request.onsuccess = () => resolve();
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
console.error("Failed to save wallet state:", error);
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
async getDB() {
|
|
332
|
+
if (this.db)
|
|
333
|
+
return this.db;
|
|
334
|
+
this.db = await (0, manager_1.openDatabase)(this.dbName, db_1.DB_VERSION, schema_1.initDatabase);
|
|
335
|
+
return this.db;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
exports.IndexedDBWalletRepository = IndexedDBWalletRepository;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* WebSQL adapter over expo-sqlite.
|
|
4
|
+
*
|
|
5
|
+
* Bridges the WebSQL API surface that indexeddbshim expects to the
|
|
6
|
+
* synchronous expo-sqlite driver. Only the subset actually called by
|
|
7
|
+
* the shim is implemented:
|
|
8
|
+
*
|
|
9
|
+
* openDatabase(name, version, displayName, estimatedSize) → WebSQLDatabase
|
|
10
|
+
* db.transaction(cb, errCb?, successCb?)
|
|
11
|
+
* tx.executeSql(sql, args?, successCb?, errorCb?)
|
|
12
|
+
* resultSet = { insertId, rowsAffected, rows: { length, item(i) } }
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.WebSQLDatabase = exports.WebSQLTransaction = void 0;
|
|
16
|
+
exports.openDatabase = openDatabase;
|
|
17
|
+
const expo_sqlite_1 = require("expo-sqlite");
|
|
18
|
+
// ── Database cache ───────────────────────────────────────────────────
|
|
19
|
+
const dbCache = new Map();
|
|
20
|
+
function getSqliteDb(name) {
|
|
21
|
+
let db = dbCache.get(name);
|
|
22
|
+
if (db)
|
|
23
|
+
return { db, created: false };
|
|
24
|
+
db = (0, expo_sqlite_1.openDatabaseSync)(name);
|
|
25
|
+
dbCache.set(name, db);
|
|
26
|
+
return { db, created: true };
|
|
27
|
+
}
|
|
28
|
+
// ── WebSQLTransaction ────────────────────────────────────────────────
|
|
29
|
+
class WebSQLTransaction {
|
|
30
|
+
constructor() {
|
|
31
|
+
/** @internal */
|
|
32
|
+
this._queue = [];
|
|
33
|
+
}
|
|
34
|
+
executeSql(sql, args, successCb, errorCb) {
|
|
35
|
+
this._queue.push({ sql, args: args ?? [], successCb, errorCb });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.WebSQLTransaction = WebSQLTransaction;
|
|
39
|
+
// ── Helpers ──────────────────────────────────────────────────────────
|
|
40
|
+
function isRead(sql) {
|
|
41
|
+
const trimmed = sql.trimStart().toUpperCase();
|
|
42
|
+
return trimmed.startsWith("SELECT") || trimmed.startsWith("PRAGMA");
|
|
43
|
+
}
|
|
44
|
+
function buildResultSet(db, sql, args) {
|
|
45
|
+
if (isRead(sql)) {
|
|
46
|
+
const rows = db.getAllSync(sql, args);
|
|
47
|
+
return {
|
|
48
|
+
insertId: 0,
|
|
49
|
+
rowsAffected: 0,
|
|
50
|
+
rows: {
|
|
51
|
+
length: rows.length,
|
|
52
|
+
item(i) {
|
|
53
|
+
return rows[i];
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const result = db.runSync(sql, args);
|
|
59
|
+
return {
|
|
60
|
+
insertId: result.lastInsertRowId,
|
|
61
|
+
rowsAffected: result.changes,
|
|
62
|
+
rows: {
|
|
63
|
+
length: 0,
|
|
64
|
+
item(_i) {
|
|
65
|
+
return undefined;
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function drainQueue(db, tx) {
|
|
71
|
+
// Process until the queue is empty. Success callbacks may enqueue
|
|
72
|
+
// more statements, so we loop rather than iterate a snapshot.
|
|
73
|
+
while (tx._queue.length > 0) {
|
|
74
|
+
const stmt = tx._queue.shift();
|
|
75
|
+
try {
|
|
76
|
+
const rs = buildResultSet(db, stmt.sql, stmt.args);
|
|
77
|
+
if (stmt.successCb) {
|
|
78
|
+
stmt.successCb(tx, rs);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
const sqlError = {
|
|
83
|
+
code: 0,
|
|
84
|
+
message: err?.message ?? String(err),
|
|
85
|
+
};
|
|
86
|
+
if (stmt.errorCb) {
|
|
87
|
+
const shouldContinue = stmt.errorCb(tx, sqlError);
|
|
88
|
+
if (shouldContinue === true) {
|
|
89
|
+
// Error handler returned true → swallow error and continue
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Abort the transaction
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// ── WebSQLDatabase ───────────────────────────────────────────────────
|
|
99
|
+
class WebSQLDatabase {
|
|
100
|
+
constructor(db, version) {
|
|
101
|
+
this._db = db;
|
|
102
|
+
this.version = version;
|
|
103
|
+
}
|
|
104
|
+
transaction(callback, errorCb, successCb) {
|
|
105
|
+
// WebSQL is async/callback-based. Schedule via macrotask so the
|
|
106
|
+
// caller's subsequent code runs first (matches browser behavior).
|
|
107
|
+
setTimeout(() => {
|
|
108
|
+
const tx = new WebSQLTransaction();
|
|
109
|
+
try {
|
|
110
|
+
// Let the caller enqueue statements
|
|
111
|
+
callback(tx);
|
|
112
|
+
// Execute everything inside a real SQLite transaction
|
|
113
|
+
this._db.withTransactionSync(() => {
|
|
114
|
+
drainQueue(this._db, tx);
|
|
115
|
+
});
|
|
116
|
+
if (successCb)
|
|
117
|
+
successCb();
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
const sqlError = {
|
|
121
|
+
code: 0,
|
|
122
|
+
message: err?.message ?? String(err),
|
|
123
|
+
};
|
|
124
|
+
if (errorCb) {
|
|
125
|
+
errorCb(sqlError);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}, 0);
|
|
129
|
+
}
|
|
130
|
+
readTransaction(callback, errorCb, successCb) {
|
|
131
|
+
// Reads go through the same path — SQLite handles concurrency.
|
|
132
|
+
this.transaction(callback, errorCb, successCb);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.WebSQLDatabase = WebSQLDatabase;
|
|
136
|
+
// ── openDatabase (WebSQL entry point) ────────────────────────────────
|
|
137
|
+
function openDatabase(name, version, _displayName, _estimatedSize, _creationCallback) {
|
|
138
|
+
const { db: sqliteDb, created } = getSqliteDb(name);
|
|
139
|
+
const wsdb = new WebSQLDatabase(sqliteDb, version);
|
|
140
|
+
if (created && _creationCallback) {
|
|
141
|
+
_creationCallback(wsdb);
|
|
142
|
+
}
|
|
143
|
+
return wsdb;
|
|
144
|
+
}
|