@bopen-io/wallet-toolbox 1.7.18
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/.claude/settings.local.json +10 -0
- package/.env.template +22 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
- package/.github/ISSUE_TEMPLATE/discussion.md +24 -0
- package/.github/pull_request_template.md +22 -0
- package/.github/workflows/push.yaml +145 -0
- package/.prettierrc +10 -0
- package/CHANGELOG.md +280 -0
- package/CONTRIBUTING.md +89 -0
- package/README.md +43 -0
- package/docs/README.md +85 -0
- package/docs/client.md +19627 -0
- package/docs/monitor.md +953 -0
- package/docs/open-rpc/index.html +46 -0
- package/docs/services.md +6377 -0
- package/docs/setup.md +1268 -0
- package/docs/storage.md +5367 -0
- package/docs/wallet.md +19626 -0
- package/jest.config.ts +25 -0
- package/license.md +28 -0
- package/out/tsconfig.all.tsbuildinfo +1 -0
- package/package.json +63 -0
- package/src/CWIStyleWalletManager.ts +1999 -0
- package/src/Setup.ts +579 -0
- package/src/SetupClient.ts +322 -0
- package/src/SetupWallet.ts +108 -0
- package/src/SimpleWalletManager.ts +526 -0
- package/src/Wallet.ts +1169 -0
- package/src/WalletAuthenticationManager.ts +153 -0
- package/src/WalletLogger.ts +213 -0
- package/src/WalletPermissionsManager.ts +3660 -0
- package/src/WalletSettingsManager.ts +114 -0
- package/src/__tests/CWIStyleWalletManager.test.d.ts.map +1 -0
- package/src/__tests/CWIStyleWalletManager.test.js.map +1 -0
- package/src/__tests/CWIStyleWalletManager.test.ts +675 -0
- package/src/__tests/WalletPermissionsManager.callbacks.test.ts +323 -0
- package/src/__tests/WalletPermissionsManager.checks.test.ts +844 -0
- package/src/__tests/WalletPermissionsManager.encryption.test.ts +412 -0
- package/src/__tests/WalletPermissionsManager.fixtures.ts +307 -0
- package/src/__tests/WalletPermissionsManager.flows.test.ts +462 -0
- package/src/__tests/WalletPermissionsManager.initialization.test.ts +300 -0
- package/src/__tests/WalletPermissionsManager.pmodules.test.ts +798 -0
- package/src/__tests/WalletPermissionsManager.proxying.test.ts +724 -0
- package/src/__tests/WalletPermissionsManager.tokens.test.ts +503 -0
- package/src/index.all.ts +27 -0
- package/src/index.client.ts +25 -0
- package/src/index.mobile.ts +21 -0
- package/src/index.ts +1 -0
- package/src/monitor/Monitor.ts +412 -0
- package/src/monitor/MonitorDaemon.ts +188 -0
- package/src/monitor/README.md +3 -0
- package/src/monitor/__test/MonitorDaemon.man.test.ts +45 -0
- package/src/monitor/tasks/TaskCheckForProofs.ts +243 -0
- package/src/monitor/tasks/TaskCheckNoSends.ts +73 -0
- package/src/monitor/tasks/TaskClock.ts +33 -0
- package/src/monitor/tasks/TaskFailAbandoned.ts +54 -0
- package/src/monitor/tasks/TaskMonitorCallHistory.ts +26 -0
- package/src/monitor/tasks/TaskNewHeader.ts +93 -0
- package/src/monitor/tasks/TaskPurge.ts +68 -0
- package/src/monitor/tasks/TaskReorg.ts +89 -0
- package/src/monitor/tasks/TaskReviewStatus.ts +48 -0
- package/src/monitor/tasks/TaskSendWaiting.ts +122 -0
- package/src/monitor/tasks/TaskSyncWhenIdle.ts +26 -0
- package/src/monitor/tasks/TaskUnFail.ts +151 -0
- package/src/monitor/tasks/WalletMonitorTask.ts +47 -0
- package/src/sdk/CertOpsWallet.ts +18 -0
- package/src/sdk/PrivilegedKeyManager.ts +372 -0
- package/src/sdk/README.md +13 -0
- package/src/sdk/WERR_errors.ts +234 -0
- package/src/sdk/WalletError.ts +170 -0
- package/src/sdk/WalletErrorFromJson.ts +80 -0
- package/src/sdk/WalletServices.interfaces.ts +700 -0
- package/src/sdk/WalletSigner.interfaces.ts +11 -0
- package/src/sdk/WalletStorage.interfaces.ts +606 -0
- package/src/sdk/__test/CertificateLifeCycle.test.ts +131 -0
- package/src/sdk/__test/PrivilegedKeyManager.test.ts +738 -0
- package/src/sdk/__test/WalletError.test.ts +318 -0
- package/src/sdk/__test/validationHelpers.test.ts +21 -0
- package/src/sdk/index.ts +10 -0
- package/src/sdk/types.ts +226 -0
- package/src/services/README.md +11 -0
- package/src/services/ServiceCollection.ts +248 -0
- package/src/services/Services.ts +603 -0
- package/src/services/__tests/ARC.man.test.ts +123 -0
- package/src/services/__tests/ARC.timeout.man.test.ts +79 -0
- package/src/services/__tests/ArcGorillaPool.man.test.ts +108 -0
- package/src/services/__tests/arcServices.test.ts +8 -0
- package/src/services/__tests/bitrails.test.ts +56 -0
- package/src/services/__tests/getMerklePath.test.ts +15 -0
- package/src/services/__tests/getRawTx.test.ts +13 -0
- package/src/services/__tests/postBeef.test.ts +104 -0
- package/src/services/__tests/verifyBeef.test.ts +50 -0
- package/src/services/chaintracker/BHServiceClient.ts +212 -0
- package/src/services/chaintracker/ChaintracksChainTracker.ts +71 -0
- package/src/services/chaintracker/__tests/ChaintracksChainTracker.test.ts +33 -0
- package/src/services/chaintracker/__tests/ChaintracksServiceClient.test.ts +29 -0
- package/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.ts +72 -0
- package/src/services/chaintracker/chaintracks/Api/BulkIngestorApi.ts +83 -0
- package/src/services/chaintracker/chaintracks/Api/BulkStorageApi.ts +92 -0
- package/src/services/chaintracker/chaintracks/Api/ChaintracksApi.ts +64 -0
- package/src/services/chaintracker/chaintracks/Api/ChaintracksClientApi.ts +189 -0
- package/src/services/chaintracker/chaintracks/Api/ChaintracksFetchApi.ts +18 -0
- package/src/services/chaintracker/chaintracks/Api/ChaintracksFsApi.ts +58 -0
- package/src/services/chaintracker/chaintracks/Api/ChaintracksStorageApi.ts +386 -0
- package/src/services/chaintracker/chaintracks/Api/LiveIngestorApi.ts +25 -0
- package/src/services/chaintracker/chaintracks/Chaintracks.ts +609 -0
- package/src/services/chaintracker/chaintracks/ChaintracksService.ts +199 -0
- package/src/services/chaintracker/chaintracks/ChaintracksServiceClient.ts +154 -0
- package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.ts +176 -0
- package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.ts +174 -0
- package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDNBabbage.ts +18 -0
- package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.ts +113 -0
- package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainWs.ts +81 -0
- package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.ts +86 -0
- package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorTeranodeP2P.ts +59 -0
- package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.ts +104 -0
- package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainWs.ts +66 -0
- package/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.ts +566 -0
- package/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.ts +219 -0
- package/src/services/chaintracker/chaintracks/Ingest/__tests/BulkIngestorCDNBabbage.test.ts +54 -0
- package/src/services/chaintracker/chaintracks/Ingest/__tests/LiveIngestorWhatsOnChainPoll.test.ts +33 -0
- package/src/services/chaintracker/chaintracks/Ingest/__tests/WhatsOnChainServices.test.ts +124 -0
- package/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.ts +92 -0
- package/src/services/chaintracker/chaintracks/Storage/ChaintracksKnexMigrations.ts +104 -0
- package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.ts +382 -0
- package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.ts +574 -0
- package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.ts +438 -0
- package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageMemory.ts +29 -0
- package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.ts +304 -0
- package/src/services/chaintracker/chaintracks/Storage/__tests/ChaintracksStorageIdb.test.ts +102 -0
- package/src/services/chaintracker/chaintracks/Storage/__tests/ChaintracksStorageKnex.test.ts +45 -0
- package/src/services/chaintracker/chaintracks/__tests/Chaintracks.test.ts +77 -0
- package/src/services/chaintracker/chaintracks/__tests/ChaintracksClientApi.test.ts +192 -0
- package/src/services/chaintracker/chaintracks/__tests/LocalCdnServer.ts +75 -0
- package/src/services/chaintracker/chaintracks/__tests/createIdbChaintracks.test.ts +62 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNetBlockHeaders.json +1 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_0.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_1.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_2.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_3.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNetBlockHeaders.json +1 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_0.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_1.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_2.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_3.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNetBlockHeaders.json +1 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_0.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_1.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_2.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_3.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNetBlockHeaders.json +1 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_0.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_1.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_2.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_3.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_4.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNetBlockHeaders.json +1 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_0.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_1.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_2.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_3.headers +0 -0
- package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_4.headers +0 -0
- package/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.ts +92 -0
- package/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.ts +111 -0
- package/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.ts +91 -0
- package/src/services/chaintracker/chaintracks/createIdbChaintracks.ts +60 -0
- 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 +12 -0
- package/src/services/chaintracker/chaintracks/index.client.ts +4 -0
- package/src/services/chaintracker/chaintracks/index.mobile.ts +37 -0
- package/src/services/chaintracker/chaintracks/util/BulkFileDataManager.ts +975 -0
- package/src/services/chaintracker/chaintracks/util/BulkFileDataReader.ts +60 -0
- package/src/services/chaintracker/chaintracks/util/BulkFilesReader.ts +336 -0
- package/src/services/chaintracker/chaintracks/util/BulkHeaderFile.ts +247 -0
- package/src/services/chaintracker/chaintracks/util/ChaintracksFetch.ts +69 -0
- package/src/services/chaintracker/chaintracks/util/ChaintracksFs.ts +141 -0
- package/src/services/chaintracker/chaintracks/util/HeightRange.ts +153 -0
- package/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.ts +76 -0
- package/src/services/chaintracker/chaintracks/util/__tests/BulkFileDataManager.test.ts +304 -0
- package/src/services/chaintracker/chaintracks/util/__tests/ChaintracksFetch.test.ts +60 -0
- package/src/services/chaintracker/chaintracks/util/__tests/HeightRange.test.ts +67 -0
- package/src/services/chaintracker/chaintracks/util/__tests/SingleWriterMultiReaderLock.test.ts +49 -0
- package/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.ts +573 -0
- package/src/services/chaintracker/chaintracks/util/dirtyHashes.ts +29 -0
- package/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.ts +432 -0
- package/src/services/chaintracker/index.all.ts +4 -0
- package/src/services/chaintracker/index.client.ts +4 -0
- package/src/services/chaintracker/index.mobile.ts +4 -0
- package/src/services/createDefaultWalletServicesOptions.ts +77 -0
- package/src/services/index.ts +1 -0
- package/src/services/processingErrors/arcSuccessError.json +76 -0
- package/src/services/providers/ARC.ts +350 -0
- package/src/services/providers/Bitails.ts +256 -0
- package/src/services/providers/SdkWhatsOnChain.ts +83 -0
- package/src/services/providers/WhatsOnChain.ts +883 -0
- package/src/services/providers/__tests/WhatsOnChain.test.ts +242 -0
- package/src/services/providers/__tests/exchangeRates.test.ts +18 -0
- package/src/services/providers/exchangeRates.ts +265 -0
- package/src/services/providers/getBeefForTxid.ts +369 -0
- package/src/signer/README.md +5 -0
- package/src/signer/WalletSigner.ts +17 -0
- package/src/signer/methods/acquireDirectCertificate.ts +52 -0
- package/src/signer/methods/buildSignableTransaction.ts +183 -0
- package/src/signer/methods/completeSignedTransaction.ts +117 -0
- package/src/signer/methods/createAction.ts +172 -0
- package/src/signer/methods/internalizeAction.ts +106 -0
- package/src/signer/methods/proveCertificate.ts +43 -0
- package/src/signer/methods/signAction.ts +54 -0
- package/src/storage/README.md +14 -0
- package/src/storage/StorageIdb.ts +2304 -0
- package/src/storage/StorageKnex.ts +1425 -0
- package/src/storage/StorageProvider.ts +810 -0
- package/src/storage/StorageReader.ts +194 -0
- package/src/storage/StorageReaderWriter.ts +432 -0
- package/src/storage/StorageSyncReader.ts +34 -0
- package/src/storage/WalletStorageManager.ts +943 -0
- package/src/storage/__test/StorageIdb.test.ts +43 -0
- package/src/storage/__test/WalletStorageManager.test.ts +275 -0
- package/src/storage/__test/adminStats.man.test.ts +89 -0
- package/src/storage/__test/getBeefForTransaction.test.ts +385 -0
- package/src/storage/index.all.ts +11 -0
- package/src/storage/index.client.ts +7 -0
- package/src/storage/index.mobile.ts +6 -0
- package/src/storage/methods/ListActionsSpecOp.ts +70 -0
- package/src/storage/methods/ListOutputsSpecOp.ts +129 -0
- package/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.ts +1057 -0
- package/src/storage/methods/__test/GenerateChange/randomValsUsed1.ts +20 -0
- package/src/storage/methods/__test/offsetKey.test.ts +274 -0
- package/src/storage/methods/attemptToPostReqsToNetwork.ts +389 -0
- package/src/storage/methods/createAction.ts +947 -0
- package/src/storage/methods/generateChange.ts +556 -0
- package/src/storage/methods/getBeefForTransaction.ts +139 -0
- package/src/storage/methods/getSyncChunk.ts +293 -0
- package/src/storage/methods/internalizeAction.ts +562 -0
- package/src/storage/methods/listActionsIdb.ts +183 -0
- package/src/storage/methods/listActionsKnex.ts +226 -0
- package/src/storage/methods/listCertificates.ts +73 -0
- package/src/storage/methods/listOutputsIdb.ts +203 -0
- package/src/storage/methods/listOutputsKnex.ts +263 -0
- package/src/storage/methods/offsetKey.ts +89 -0
- package/src/storage/methods/processAction.ts +420 -0
- package/src/storage/methods/purgeData.ts +251 -0
- package/src/storage/methods/purgeDataIdb.ts +10 -0
- package/src/storage/methods/reviewStatus.ts +101 -0
- package/src/storage/methods/reviewStatusIdb.ts +43 -0
- package/src/storage/methods/utils.Buffer.ts +33 -0
- package/src/storage/methods/utils.ts +56 -0
- package/src/storage/remoting/StorageClient.ts +567 -0
- package/src/storage/remoting/StorageMobile.ts +544 -0
- package/src/storage/remoting/StorageServer.ts +291 -0
- package/src/storage/remoting/__test/StorageClient.test.ts +113 -0
- package/src/storage/schema/KnexMigrations.ts +489 -0
- package/src/storage/schema/StorageIdbSchema.ts +150 -0
- package/src/storage/schema/entities/EntityBase.ts +210 -0
- package/src/storage/schema/entities/EntityCertificate.ts +188 -0
- package/src/storage/schema/entities/EntityCertificateField.ts +136 -0
- package/src/storage/schema/entities/EntityCommission.ts +148 -0
- package/src/storage/schema/entities/EntityOutput.ts +290 -0
- package/src/storage/schema/entities/EntityOutputBasket.ts +153 -0
- package/src/storage/schema/entities/EntityOutputTag.ts +121 -0
- package/src/storage/schema/entities/EntityOutputTagMap.ts +123 -0
- package/src/storage/schema/entities/EntityProvenTx.ts +319 -0
- package/src/storage/schema/entities/EntityProvenTxReq.ts +580 -0
- package/src/storage/schema/entities/EntitySyncState.ts +389 -0
- package/src/storage/schema/entities/EntityTransaction.ts +306 -0
- package/src/storage/schema/entities/EntityTxLabel.ts +121 -0
- package/src/storage/schema/entities/EntityTxLabelMap.ts +123 -0
- package/src/storage/schema/entities/EntityUser.ts +112 -0
- package/src/storage/schema/entities/MergeEntity.ts +73 -0
- package/src/storage/schema/entities/__tests/CertificateFieldTests.test.ts +353 -0
- package/src/storage/schema/entities/__tests/CertificateTests.test.ts +354 -0
- package/src/storage/schema/entities/__tests/CommissionTests.test.ts +371 -0
- package/src/storage/schema/entities/__tests/OutputBasketTests.test.ts +278 -0
- package/src/storage/schema/entities/__tests/OutputTagMapTests.test.ts +242 -0
- package/src/storage/schema/entities/__tests/OutputTagTests.test.ts +288 -0
- package/src/storage/schema/entities/__tests/OutputTests.test.ts +464 -0
- package/src/storage/schema/entities/__tests/ProvenTxReqTests.test.ts +340 -0
- package/src/storage/schema/entities/__tests/ProvenTxTests.test.ts +504 -0
- package/src/storage/schema/entities/__tests/SyncStateTests.test.ts +288 -0
- package/src/storage/schema/entities/__tests/TransactionTests.test.ts +604 -0
- package/src/storage/schema/entities/__tests/TxLabelMapTests.test.ts +361 -0
- package/src/storage/schema/entities/__tests/TxLabelTests.test.ts +198 -0
- package/src/storage/schema/entities/__tests/stampLogTests.test.ts +90 -0
- package/src/storage/schema/entities/__tests/usersTests.test.ts +340 -0
- package/src/storage/schema/entities/index.ts +16 -0
- package/src/storage/schema/tables/TableCertificate.ts +21 -0
- package/src/storage/schema/tables/TableCertificateField.ts +12 -0
- package/src/storage/schema/tables/TableCommission.ts +13 -0
- package/src/storage/schema/tables/TableMonitorEvent.ts +9 -0
- package/src/storage/schema/tables/TableOutput.ts +64 -0
- package/src/storage/schema/tables/TableOutputBasket.ts +12 -0
- package/src/storage/schema/tables/TableOutputTag.ts +10 -0
- package/src/storage/schema/tables/TableOutputTagMap.ts +9 -0
- package/src/storage/schema/tables/TableProvenTx.ts +14 -0
- package/src/storage/schema/tables/TableProvenTxReq.ts +65 -0
- package/src/storage/schema/tables/TableSettings.ts +17 -0
- package/src/storage/schema/tables/TableSyncState.ts +18 -0
- package/src/storage/schema/tables/TableTransaction.ts +54 -0
- package/src/storage/schema/tables/TableTxLabel.ts +10 -0
- package/src/storage/schema/tables/TableTxLabelMap.ts +9 -0
- package/src/storage/schema/tables/TableUser.ts +16 -0
- package/src/storage/schema/tables/index.ts +16 -0
- package/src/storage/sync/StorageMySQLDojoReader.ts +696 -0
- package/src/storage/sync/index.ts +1 -0
- package/src/utility/Format.ts +133 -0
- package/src/utility/README.md +3 -0
- package/src/utility/ReaderUint8Array.ts +187 -0
- package/src/utility/ScriptTemplateBRC29.ts +73 -0
- package/src/utility/__tests/utilityHelpers.noBuffer.test.ts +109 -0
- package/src/utility/aggregateResults.ts +68 -0
- package/src/utility/identityUtils.ts +159 -0
- package/src/utility/index.all.ts +7 -0
- package/src/utility/index.client.ts +7 -0
- package/src/utility/parseTxScriptOffsets.ts +29 -0
- package/src/utility/stampLog.ts +69 -0
- package/src/utility/tscProofToMerklePath.ts +48 -0
- package/src/utility/utilityHelpers.buffer.ts +34 -0
- package/src/utility/utilityHelpers.noBuffer.ts +60 -0
- package/src/utility/utilityHelpers.ts +275 -0
- package/src/wab-client/WABClient.ts +94 -0
- package/src/wab-client/__tests/WABClient.man.test.ts +59 -0
- package/src/wab-client/auth-method-interactors/AuthMethodInteractor.ts +47 -0
- package/src/wab-client/auth-method-interactors/DevConsoleInteractor.ts +73 -0
- package/src/wab-client/auth-method-interactors/PersonaIDInteractor.ts +35 -0
- package/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.ts +72 -0
- package/syncVersions.js +71 -0
- package/test/Wallet/StorageClient/storageClient.man.test.ts +75 -0
- package/test/Wallet/action/abortAction.test.ts +47 -0
- package/test/Wallet/action/createAction.test.ts +299 -0
- package/test/Wallet/action/createAction2.test.ts +1273 -0
- package/test/Wallet/action/createActionToGenerateBeefs.man.test.ts +293 -0
- package/test/Wallet/action/internalizeAction.a.test.ts +286 -0
- package/test/Wallet/action/internalizeAction.test.ts +682 -0
- package/test/Wallet/action/relinquishOutput.test.ts +37 -0
- package/test/Wallet/certificate/acquireCertificate.test.ts +298 -0
- package/test/Wallet/certificate/listCertificates.test.ts +346 -0
- package/test/Wallet/construct/Wallet.constructor.test.ts +57 -0
- package/test/Wallet/get/getHeaderForHeight.test.ts +82 -0
- package/test/Wallet/get/getHeight.test.ts +52 -0
- package/test/Wallet/get/getKnownTxids.test.ts +86 -0
- package/test/Wallet/get/getNetwork.test.ts +27 -0
- package/test/Wallet/get/getVersion.test.ts +27 -0
- package/test/Wallet/list/listActions.test.ts +279 -0
- package/test/Wallet/list/listActions2.test.ts +1381 -0
- package/test/Wallet/list/listCertificates.test.ts +118 -0
- package/test/Wallet/list/listOutputs.test.ts +447 -0
- package/test/Wallet/live/walletLive.man.test.ts +521 -0
- package/test/Wallet/local/localWallet.man.test.ts +93 -0
- package/test/Wallet/local/localWallet2.man.test.ts +277 -0
- package/test/Wallet/signAction/mountaintop.man.test.ts +130 -0
- package/test/Wallet/specOps/specOps.man.test.ts +220 -0
- package/test/Wallet/support/janitor.man.test.ts +40 -0
- package/test/Wallet/support/operations.man.test.ts +407 -0
- package/test/Wallet/support/reqErrorReview.2025.05.06.man.test.ts +347 -0
- package/test/Wallet/sync/Wallet.sync.test.ts +215 -0
- package/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.ts +203 -0
- package/test/Wallet/sync/setActive.test.ts +170 -0
- package/test/WalletClient/LocalKVStore.man.test.ts +114 -0
- package/test/WalletClient/WERR.man.test.ts +35 -0
- package/test/bsv-ts-sdk/LocalKVStore.test.ts +102 -0
- package/test/checkDB.ts +57 -0
- package/test/checkdb +0 -0
- package/test/examples/backup.man.test.ts +59 -0
- package/test/examples/pushdrop.test.ts +282 -0
- package/test/monitor/Monitor.test.ts +620 -0
- package/test/services/Services.test.ts +263 -0
- package/test/storage/KnexMigrations.test.ts +86 -0
- package/test/storage/StorageMySQLDojoReader.man.test.ts +60 -0
- package/test/storage/count.test.ts +177 -0
- package/test/storage/find.test.ts +195 -0
- package/test/storage/findLegacy.test.ts +67 -0
- package/test/storage/idb/allocateChange.test.ts +251 -0
- package/test/storage/idb/count.test.ts +158 -0
- package/test/storage/idb/find.test.ts +177 -0
- package/test/storage/idb/idbSpeed.test.ts +36 -0
- package/test/storage/idb/insert.test.ts +268 -0
- package/test/storage/idb/transactionAbort.test.ts +108 -0
- package/test/storage/idb/update.test.ts +999 -0
- package/test/storage/insert.test.ts +278 -0
- package/test/storage/update.test.ts +1021 -0
- package/test/storage/update2.test.ts +897 -0
- package/test/utils/TestUtilsWalletStorage.ts +2526 -0
- package/test/utils/localWalletMethods.ts +363 -0
- package/test/utils/removeFailedFromDatabase.sql +17 -0
- package/ts2md.json +44 -0
- package/tsconfig.all.json +31 -0
- package/tsconfig.client.json +29 -0
- package/tsconfig.json +17 -0
- package/tsconfig.mobile.json +28 -0
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RequestSyncChunkArgs,
|
|
3
|
+
SyncChunk,
|
|
4
|
+
SyncStatus,
|
|
5
|
+
TrxToken,
|
|
6
|
+
WalletStorageSync
|
|
7
|
+
} from '../../../sdk/WalletStorage.interfaces'
|
|
8
|
+
import { WERR_INVALID_PARAMETER } from '../../../sdk/WERR_errors'
|
|
9
|
+
import { maxDate, verifyId, verifyTruthy } from '../../../utility/utilityHelpers'
|
|
10
|
+
import { TableSettings } from '../tables/TableSettings'
|
|
11
|
+
import { TableSyncState } from '../tables/TableSyncState'
|
|
12
|
+
import { createSyncMap, EntityBase, EntityStorage, EntitySyncMap, SyncError, SyncMap } from './EntityBase'
|
|
13
|
+
import { EntityCertificate } from './EntityCertificate'
|
|
14
|
+
import { EntityCertificateField } from './EntityCertificateField'
|
|
15
|
+
import { EntityCommission } from './EntityCommission'
|
|
16
|
+
import { EntityOutput } from './EntityOutput'
|
|
17
|
+
import { EntityOutputBasket } from './EntityOutputBasket'
|
|
18
|
+
import { EntityOutputTag } from './EntityOutputTag'
|
|
19
|
+
import { EntityOutputTagMap } from './EntityOutputTagMap'
|
|
20
|
+
import { EntityProvenTx } from './EntityProvenTx'
|
|
21
|
+
import { EntityProvenTxReq } from './EntityProvenTxReq'
|
|
22
|
+
import { EntityTransaction } from './EntityTransaction'
|
|
23
|
+
import { EntityTxLabel } from './EntityTxLabel'
|
|
24
|
+
import { EntityTxLabelMap } from './EntityTxLabelMap'
|
|
25
|
+
import { EntityUser } from './EntityUser'
|
|
26
|
+
import { MergeEntity } from './MergeEntity'
|
|
27
|
+
|
|
28
|
+
export class EntitySyncState extends EntityBase<TableSyncState> {
|
|
29
|
+
constructor(api?: TableSyncState) {
|
|
30
|
+
const now = new Date()
|
|
31
|
+
super(
|
|
32
|
+
api || {
|
|
33
|
+
syncStateId: 0,
|
|
34
|
+
created_at: now,
|
|
35
|
+
updated_at: now,
|
|
36
|
+
userId: 0,
|
|
37
|
+
storageIdentityKey: '',
|
|
38
|
+
storageName: '',
|
|
39
|
+
init: false,
|
|
40
|
+
refNum: '',
|
|
41
|
+
status: 'unknown',
|
|
42
|
+
when: undefined,
|
|
43
|
+
errorLocal: undefined,
|
|
44
|
+
errorOther: undefined,
|
|
45
|
+
satoshis: undefined,
|
|
46
|
+
syncMap: JSON.stringify(createSyncMap())
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
this.errorLocal = this.api.errorLocal ? <SyncError>JSON.parse(this.api.errorLocal) : undefined
|
|
50
|
+
this.errorOther = this.api.errorOther ? <SyncError>JSON.parse(this.api.errorOther) : undefined
|
|
51
|
+
this.syncMap = <SyncMap>JSON.parse(this.api.syncMap)
|
|
52
|
+
this.validateSyncMap(this.syncMap)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
validateSyncMap(sm: SyncMap) {
|
|
56
|
+
for (const key of Object.keys(sm)) {
|
|
57
|
+
const esm: EntitySyncMap = sm[key]
|
|
58
|
+
if (typeof esm.maxUpdated_at === 'string') esm.maxUpdated_at = new Date(esm.maxUpdated_at)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static async fromStorage(
|
|
63
|
+
storage: WalletStorageSync,
|
|
64
|
+
userIdentityKey: string,
|
|
65
|
+
remoteSettings: TableSettings
|
|
66
|
+
): Promise<EntitySyncState> {
|
|
67
|
+
const { user } = verifyTruthy(await storage.findOrInsertUser(userIdentityKey))
|
|
68
|
+
let { syncState: api } = verifyTruthy(
|
|
69
|
+
await storage.findOrInsertSyncStateAuth(
|
|
70
|
+
{ userId: user.userId, identityKey: userIdentityKey },
|
|
71
|
+
remoteSettings.storageIdentityKey,
|
|
72
|
+
remoteSettings.storageName
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
if (!api.syncMap || api.syncMap === '{}') api.syncMap = JSON.stringify(createSyncMap())
|
|
76
|
+
const ss = new EntitySyncState(api)
|
|
77
|
+
return ss
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Handles both insert and update based on id value: zero indicates insert.
|
|
82
|
+
* @param storage
|
|
83
|
+
* @param notSyncMap if not new and true, excludes updating syncMap in storage.
|
|
84
|
+
* @param trx
|
|
85
|
+
*/
|
|
86
|
+
async updateStorage(storage: EntityStorage, notSyncMap?: boolean, trx?: TrxToken) {
|
|
87
|
+
this.updated_at = new Date()
|
|
88
|
+
this.updateApi(notSyncMap && this.id > 0)
|
|
89
|
+
if (this.id === 0) {
|
|
90
|
+
await storage.insertSyncState(this.api)
|
|
91
|
+
} else {
|
|
92
|
+
const update: Partial<TableSyncState> = { ...this.api }
|
|
93
|
+
if (notSyncMap) delete update.syncMap
|
|
94
|
+
delete update.created_at
|
|
95
|
+
await storage.updateSyncState(verifyId(this.id), update, trx)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
override updateApi(notSyncMap?: boolean): void {
|
|
100
|
+
this.api.errorLocal = this.apiErrorLocal
|
|
101
|
+
this.api.errorOther = this.apiErrorOther
|
|
102
|
+
if (!notSyncMap) this.api.syncMap = this.apiSyncMap
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Pass through api properties
|
|
106
|
+
set created_at(v: Date) {
|
|
107
|
+
this.api.created_at = v
|
|
108
|
+
}
|
|
109
|
+
get created_at() {
|
|
110
|
+
return this.api.created_at
|
|
111
|
+
}
|
|
112
|
+
set updated_at(v: Date) {
|
|
113
|
+
this.api.updated_at = v
|
|
114
|
+
}
|
|
115
|
+
get updated_at() {
|
|
116
|
+
return this.api.updated_at
|
|
117
|
+
}
|
|
118
|
+
set userId(v: number) {
|
|
119
|
+
this.api.userId = v
|
|
120
|
+
}
|
|
121
|
+
get userId() {
|
|
122
|
+
return this.api.userId
|
|
123
|
+
}
|
|
124
|
+
set storageIdentityKey(v: string) {
|
|
125
|
+
this.api.storageIdentityKey = v
|
|
126
|
+
}
|
|
127
|
+
get storageIdentityKey() {
|
|
128
|
+
return this.api.storageIdentityKey
|
|
129
|
+
}
|
|
130
|
+
set storageName(v: string) {
|
|
131
|
+
this.api.storageName = v
|
|
132
|
+
}
|
|
133
|
+
get storageName() {
|
|
134
|
+
return this.api.storageName
|
|
135
|
+
}
|
|
136
|
+
set init(v: boolean) {
|
|
137
|
+
this.api.init = v
|
|
138
|
+
}
|
|
139
|
+
get init() {
|
|
140
|
+
return this.api.init
|
|
141
|
+
}
|
|
142
|
+
set refNum(v: string) {
|
|
143
|
+
this.api.refNum = v
|
|
144
|
+
}
|
|
145
|
+
get refNum() {
|
|
146
|
+
return this.api.refNum
|
|
147
|
+
}
|
|
148
|
+
set status(v: SyncStatus) {
|
|
149
|
+
this.api.status = v
|
|
150
|
+
}
|
|
151
|
+
get status(): SyncStatus {
|
|
152
|
+
return this.api.status
|
|
153
|
+
}
|
|
154
|
+
set when(v: Date | undefined) {
|
|
155
|
+
this.api.when = v
|
|
156
|
+
}
|
|
157
|
+
get when() {
|
|
158
|
+
return this.api.when
|
|
159
|
+
}
|
|
160
|
+
set satoshis(v: number | undefined) {
|
|
161
|
+
this.api.satoshis = v
|
|
162
|
+
}
|
|
163
|
+
get satoshis() {
|
|
164
|
+
return this.api.satoshis
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
get apiErrorLocal() {
|
|
168
|
+
return this.errorToString(this.errorLocal)
|
|
169
|
+
}
|
|
170
|
+
get apiErrorOther() {
|
|
171
|
+
return this.errorToString(this.errorOther)
|
|
172
|
+
}
|
|
173
|
+
get apiSyncMap() {
|
|
174
|
+
return JSON.stringify(this.syncMap)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
override get id(): number {
|
|
178
|
+
return this.api.syncStateId
|
|
179
|
+
}
|
|
180
|
+
set id(id: number) {
|
|
181
|
+
this.api.syncStateId = id
|
|
182
|
+
}
|
|
183
|
+
override get entityName(): string {
|
|
184
|
+
return 'syncState'
|
|
185
|
+
}
|
|
186
|
+
override get entityTable(): string {
|
|
187
|
+
return 'sync_states'
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static mergeIdMap(fromMap: Record<number, number>, toMap: Record<number, number>) {
|
|
191
|
+
for (const [key, value] of Object.entries(fromMap)) {
|
|
192
|
+
const fromValue = fromMap[key]
|
|
193
|
+
const toValue = toMap[key]
|
|
194
|
+
if (toValue !== undefined && toValue !== fromValue)
|
|
195
|
+
throw new WERR_INVALID_PARAMETER(
|
|
196
|
+
'syncMap',
|
|
197
|
+
`an unmapped id or the same mapped id. ${key} maps to ${toValue} not equal to ${fromValue}`
|
|
198
|
+
)
|
|
199
|
+
if (toValue === undefined) toMap[key] = value
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Merge additions to the syncMap
|
|
204
|
+
* @param iSyncMap
|
|
205
|
+
*/
|
|
206
|
+
mergeSyncMap(iSyncMap: SyncMap) {
|
|
207
|
+
EntitySyncState.mergeIdMap(iSyncMap.provenTx.idMap!, this.syncMap.provenTx.idMap!)
|
|
208
|
+
EntitySyncState.mergeIdMap(iSyncMap.outputBasket.idMap!, this.syncMap.outputBasket.idMap!)
|
|
209
|
+
EntitySyncState.mergeIdMap(iSyncMap.transaction.idMap!, this.syncMap.transaction.idMap!)
|
|
210
|
+
EntitySyncState.mergeIdMap(iSyncMap.provenTxReq.idMap!, this.syncMap.provenTxReq.idMap!)
|
|
211
|
+
EntitySyncState.mergeIdMap(iSyncMap.txLabel.idMap!, this.syncMap.txLabel.idMap!)
|
|
212
|
+
EntitySyncState.mergeIdMap(iSyncMap.output.idMap!, this.syncMap.output.idMap!)
|
|
213
|
+
EntitySyncState.mergeIdMap(iSyncMap.outputTag.idMap!, this.syncMap.outputTag.idMap!)
|
|
214
|
+
EntitySyncState.mergeIdMap(iSyncMap.certificate.idMap!, this.syncMap.certificate.idMap!)
|
|
215
|
+
EntitySyncState.mergeIdMap(iSyncMap.commission.idMap!, this.syncMap.commission.idMap!)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// stringified api properties
|
|
219
|
+
|
|
220
|
+
errorLocal: SyncError | undefined
|
|
221
|
+
errorOther: SyncError | undefined
|
|
222
|
+
syncMap: SyncMap
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Eliminate any properties besides code and description
|
|
226
|
+
*/
|
|
227
|
+
private errorToString(e: SyncError | undefined): string | undefined {
|
|
228
|
+
if (!e) return undefined
|
|
229
|
+
const es: SyncError = {
|
|
230
|
+
code: e.code,
|
|
231
|
+
description: e.description,
|
|
232
|
+
stack: e.stack
|
|
233
|
+
}
|
|
234
|
+
return JSON.stringify(es)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
override equals(ei: TableSyncState, syncMap?: SyncMap | undefined): boolean {
|
|
238
|
+
return false
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
override async mergeNew(storage: EntityStorage, userId: number, syncMap: SyncMap, trx?: TrxToken): Promise<void> {}
|
|
242
|
+
|
|
243
|
+
override async mergeExisting(
|
|
244
|
+
storage: EntityStorage,
|
|
245
|
+
since: Date | undefined,
|
|
246
|
+
ei: TableSyncState,
|
|
247
|
+
syncMap: SyncMap,
|
|
248
|
+
trx?: TrxToken
|
|
249
|
+
): Promise<boolean> {
|
|
250
|
+
return false
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
makeRequestSyncChunkArgs(
|
|
254
|
+
forIdentityKey: string,
|
|
255
|
+
forStorageIdentityKey: string,
|
|
256
|
+
maxRoughSize?: number,
|
|
257
|
+
maxItems?: number
|
|
258
|
+
): RequestSyncChunkArgs {
|
|
259
|
+
const a: RequestSyncChunkArgs = {
|
|
260
|
+
identityKey: forIdentityKey,
|
|
261
|
+
maxRoughSize: maxRoughSize || 10000000,
|
|
262
|
+
maxItems: maxItems || 1000,
|
|
263
|
+
offsets: [],
|
|
264
|
+
since: this.when,
|
|
265
|
+
fromStorageIdentityKey: this.storageIdentityKey,
|
|
266
|
+
toStorageIdentityKey: forStorageIdentityKey
|
|
267
|
+
}
|
|
268
|
+
for (const ess of [
|
|
269
|
+
this.syncMap.provenTx,
|
|
270
|
+
this.syncMap.outputBasket,
|
|
271
|
+
this.syncMap.outputTag,
|
|
272
|
+
this.syncMap.txLabel,
|
|
273
|
+
this.syncMap.transaction,
|
|
274
|
+
this.syncMap.output,
|
|
275
|
+
this.syncMap.txLabelMap,
|
|
276
|
+
this.syncMap.outputTagMap,
|
|
277
|
+
this.syncMap.certificate,
|
|
278
|
+
this.syncMap.certificateField,
|
|
279
|
+
this.syncMap.commission,
|
|
280
|
+
this.syncMap.provenTxReq
|
|
281
|
+
]) {
|
|
282
|
+
if (!ess || !ess.entityName) debugger
|
|
283
|
+
a.offsets.push({ name: ess.entityName, offset: ess.count })
|
|
284
|
+
}
|
|
285
|
+
return a
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
static syncChunkSummary(c: SyncChunk): string {
|
|
289
|
+
let log = ''
|
|
290
|
+
log += `SYNC CHUNK SUMMARY
|
|
291
|
+
from storage: ${c.fromStorageIdentityKey}
|
|
292
|
+
to storage: ${c.toStorageIdentityKey}
|
|
293
|
+
for user: ${c.userIdentityKey}
|
|
294
|
+
`
|
|
295
|
+
if (c.user) log += ` USER activeStorage ${c.user.activeStorage}\n`
|
|
296
|
+
if (!!c.provenTxs) {
|
|
297
|
+
log += ` PROVEN_TXS\n`
|
|
298
|
+
for (const r of c.provenTxs) {
|
|
299
|
+
log += ` ${r.provenTxId} ${r.txid}\n`
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (!!c.provenTxReqs) {
|
|
303
|
+
log += ` PROVEN_TX_REQS\n`
|
|
304
|
+
for (const r of c.provenTxReqs) {
|
|
305
|
+
log += ` ${r.provenTxReqId} ${r.txid} ${r.status} ${r.provenTxId || ''}\n`
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (!!c.transactions) {
|
|
309
|
+
log += ` TRANSACTIONS\n`
|
|
310
|
+
for (const r of c.transactions) {
|
|
311
|
+
log += ` ${r.transactionId} ${r.txid} ${r.status} ${r.provenTxId || ''} sats:${r.satoshis}\n`
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (!!c.outputs) {
|
|
315
|
+
log += ` OUTPUTS\n`
|
|
316
|
+
for (const r of c.outputs) {
|
|
317
|
+
log += ` ${r.outputId} ${r.txid}.${r.vout} ${r.transactionId} ${r.spendable ? 'spendable' : ''} sats:${r.satoshis}\n`
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return log
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
async processSyncChunk(
|
|
324
|
+
writer: EntityStorage,
|
|
325
|
+
args: RequestSyncChunkArgs,
|
|
326
|
+
chunk: SyncChunk
|
|
327
|
+
): Promise<{
|
|
328
|
+
done: boolean
|
|
329
|
+
maxUpdated_at: Date | undefined
|
|
330
|
+
updates: number
|
|
331
|
+
inserts: number
|
|
332
|
+
}> {
|
|
333
|
+
const mes = [
|
|
334
|
+
new MergeEntity(chunk.provenTxs, EntityProvenTx.mergeFind, this.syncMap.provenTx),
|
|
335
|
+
new MergeEntity(chunk.outputBaskets, EntityOutputBasket.mergeFind, this.syncMap.outputBasket),
|
|
336
|
+
new MergeEntity(chunk.outputTags, EntityOutputTag.mergeFind, this.syncMap.outputTag),
|
|
337
|
+
new MergeEntity(chunk.txLabels, EntityTxLabel.mergeFind, this.syncMap.txLabel),
|
|
338
|
+
new MergeEntity(chunk.transactions, EntityTransaction.mergeFind, this.syncMap.transaction),
|
|
339
|
+
new MergeEntity(chunk.outputs, EntityOutput.mergeFind, this.syncMap.output),
|
|
340
|
+
new MergeEntity(chunk.txLabelMaps, EntityTxLabelMap.mergeFind, this.syncMap.txLabelMap),
|
|
341
|
+
new MergeEntity(chunk.outputTagMaps, EntityOutputTagMap.mergeFind, this.syncMap.outputTagMap),
|
|
342
|
+
new MergeEntity(chunk.certificates, EntityCertificate.mergeFind, this.syncMap.certificate),
|
|
343
|
+
new MergeEntity(chunk.certificateFields, EntityCertificateField.mergeFind, this.syncMap.certificateField),
|
|
344
|
+
new MergeEntity(chunk.commissions, EntityCommission.mergeFind, this.syncMap.commission),
|
|
345
|
+
new MergeEntity(chunk.provenTxReqs, EntityProvenTxReq.mergeFind, this.syncMap.provenTxReq)
|
|
346
|
+
]
|
|
347
|
+
|
|
348
|
+
let updates = 0
|
|
349
|
+
let inserts = 0
|
|
350
|
+
let maxUpdated_at: Date | undefined = undefined
|
|
351
|
+
let done = true
|
|
352
|
+
|
|
353
|
+
// Merge User
|
|
354
|
+
if (chunk.user) {
|
|
355
|
+
const ei = chunk.user
|
|
356
|
+
const { found, eo } = await EntityUser.mergeFind(writer, this.userId, ei)
|
|
357
|
+
if (found) {
|
|
358
|
+
if (await eo.mergeExisting(writer, args.since, ei)) {
|
|
359
|
+
maxUpdated_at = maxDate(maxUpdated_at, ei.updated_at)
|
|
360
|
+
updates++
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Merge everything else...
|
|
366
|
+
for (const me of mes) {
|
|
367
|
+
const r = await me.merge(args.since, writer, this.userId, this.syncMap)
|
|
368
|
+
// The counts become the offsets for the next chunk.
|
|
369
|
+
me.esm.count += me.stateArray?.length || 0
|
|
370
|
+
updates += r.updates
|
|
371
|
+
inserts += r.inserts
|
|
372
|
+
maxUpdated_at = maxDate(maxUpdated_at, me.esm.maxUpdated_at)
|
|
373
|
+
// If any entity type either did not report results or if there were at least one, then we aren't done.
|
|
374
|
+
if (me.stateArray === undefined || me.stateArray.length > 0) done = false
|
|
375
|
+
//if (me.stateArray !== undefined && me.stateArray.length > 0)
|
|
376
|
+
// console.log(`merged ${me.stateArray?.length} ${me.esm.entityName} ${r.inserts} inserted, ${r.updates} updated`);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (done) {
|
|
380
|
+
// Next batch starts further in the future with offsets of zero.
|
|
381
|
+
this.when = maxUpdated_at
|
|
382
|
+
for (const me of mes) me.esm.count = 0
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
await this.updateStorage(writer, false)
|
|
386
|
+
|
|
387
|
+
return { done, maxUpdated_at, updates, inserts }
|
|
388
|
+
}
|
|
389
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { TransactionStatus } from '../../../sdk/types'
|
|
2
|
+
import { TrxToken } from '../../../sdk/WalletStorage.interfaces'
|
|
3
|
+
import { optionalArraysEqual, verifyId, verifyOneOrNone } from '../../../utility/utilityHelpers'
|
|
4
|
+
import { TableOutput } from '../tables/TableOutput'
|
|
5
|
+
import { TableTransaction } from '../tables/TableTransaction'
|
|
6
|
+
import { EntityBase, EntityStorage, SyncMap } from './EntityBase'
|
|
7
|
+
import { EntityProvenTx } from './EntityProvenTx'
|
|
8
|
+
import { Transaction as BsvTransaction, TransactionInput } from '@bsv/sdk'
|
|
9
|
+
|
|
10
|
+
export class EntityTransaction extends EntityBase<TableTransaction> {
|
|
11
|
+
/**
|
|
12
|
+
* @returns @bsv/sdk Transaction object from parsed rawTx.
|
|
13
|
+
* If rawTx is undefined, returns undefined.
|
|
14
|
+
*/
|
|
15
|
+
getBsvTx(): BsvTransaction | undefined {
|
|
16
|
+
if (!this.rawTx) return undefined
|
|
17
|
+
return BsvTransaction.fromBinary(this.rawTx)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @returns array of @bsv/sdk TransactionInput objects from parsed rawTx.
|
|
22
|
+
* If rawTx is undefined, an empty array is returned.
|
|
23
|
+
*/
|
|
24
|
+
getBsvTxIns(): TransactionInput[] {
|
|
25
|
+
const tx = this.getBsvTx()
|
|
26
|
+
if (!tx) return []
|
|
27
|
+
return tx.inputs
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns an array of "known" inputs to this transaction which belong to the same userId.
|
|
32
|
+
* Uses both spentBy and rawTx inputs (if available) to locate inputs from among user's outputs.
|
|
33
|
+
* Not all transaction inputs correspond to prior storage outputs.
|
|
34
|
+
*/
|
|
35
|
+
async getInputs(storage: EntityStorage, trx?: TrxToken): Promise<TableOutput[]> {
|
|
36
|
+
const inputs = await storage.findOutputs({
|
|
37
|
+
partial: { userId: this.userId, spentBy: this.id },
|
|
38
|
+
trx
|
|
39
|
+
})
|
|
40
|
+
// Merge "inputs" by spentBy and userId
|
|
41
|
+
for (const input of this.getBsvTxIns()) {
|
|
42
|
+
//console.log(`getInputs of ${this.id}: ${input.txid()} ${input.txOutNum}`)
|
|
43
|
+
const pso = verifyOneOrNone(
|
|
44
|
+
await storage.findOutputs({
|
|
45
|
+
partial: {
|
|
46
|
+
userId: this.userId,
|
|
47
|
+
txid: input.sourceTXID,
|
|
48
|
+
vout: input.sourceOutputIndex
|
|
49
|
+
},
|
|
50
|
+
trx
|
|
51
|
+
})
|
|
52
|
+
)
|
|
53
|
+
if (pso && !inputs.some(i => i.outputId === pso.outputId)) inputs.push(pso)
|
|
54
|
+
}
|
|
55
|
+
return inputs
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
constructor(api?: TableTransaction) {
|
|
59
|
+
const now = new Date()
|
|
60
|
+
super(
|
|
61
|
+
api || {
|
|
62
|
+
transactionId: 0,
|
|
63
|
+
created_at: now,
|
|
64
|
+
updated_at: now,
|
|
65
|
+
userId: 0,
|
|
66
|
+
txid: '',
|
|
67
|
+
status: 'unprocessed',
|
|
68
|
+
reference: '',
|
|
69
|
+
satoshis: 0,
|
|
70
|
+
description: '',
|
|
71
|
+
isOutgoing: false,
|
|
72
|
+
rawTx: undefined,
|
|
73
|
+
inputBEEF: undefined
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
override updateApi(): void {
|
|
79
|
+
/* nothing needed yet... */
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get transactionId() {
|
|
83
|
+
return this.api.transactionId
|
|
84
|
+
}
|
|
85
|
+
set transactionId(v: number) {
|
|
86
|
+
this.api.transactionId = v
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get created_at() {
|
|
90
|
+
return this.api.created_at
|
|
91
|
+
}
|
|
92
|
+
set created_at(v: Date) {
|
|
93
|
+
this.api.created_at = v
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get updated_at() {
|
|
97
|
+
return this.api.updated_at
|
|
98
|
+
}
|
|
99
|
+
set updated_at(v: Date) {
|
|
100
|
+
this.api.updated_at = v
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
get version() {
|
|
104
|
+
return this.api.version
|
|
105
|
+
}
|
|
106
|
+
set version(v: number | undefined) {
|
|
107
|
+
this.api.version = v
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get lockTime() {
|
|
111
|
+
return this.api.lockTime
|
|
112
|
+
}
|
|
113
|
+
set lockTime(v: number | undefined) {
|
|
114
|
+
this.api.lockTime = v
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
get isOutgoing() {
|
|
118
|
+
return this.api.isOutgoing
|
|
119
|
+
}
|
|
120
|
+
set isOutgoing(v: boolean) {
|
|
121
|
+
this.api.isOutgoing = v
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
get status() {
|
|
125
|
+
return this.api.status
|
|
126
|
+
}
|
|
127
|
+
set status(v: TransactionStatus) {
|
|
128
|
+
this.api.status = v
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get userId() {
|
|
132
|
+
return this.api.userId
|
|
133
|
+
}
|
|
134
|
+
set userId(v: number) {
|
|
135
|
+
this.api.userId = v
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get provenTxId() {
|
|
139
|
+
return this.api.provenTxId
|
|
140
|
+
}
|
|
141
|
+
set provenTxId(v: number | undefined) {
|
|
142
|
+
this.api.provenTxId = v
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
get satoshis() {
|
|
146
|
+
return this.api.satoshis
|
|
147
|
+
}
|
|
148
|
+
set satoshis(v: number) {
|
|
149
|
+
this.api.satoshis = v
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
get txid() {
|
|
153
|
+
return this.api.txid
|
|
154
|
+
}
|
|
155
|
+
set txid(v: string | undefined) {
|
|
156
|
+
this.api.txid = v
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
get reference() {
|
|
160
|
+
return this.api.reference
|
|
161
|
+
}
|
|
162
|
+
set reference(v: string) {
|
|
163
|
+
this.api.reference = v
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
get inputBEEF() {
|
|
167
|
+
return this.api.inputBEEF
|
|
168
|
+
}
|
|
169
|
+
set inputBEEF(v: number[] | undefined) {
|
|
170
|
+
this.api.inputBEEF = v
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
get description() {
|
|
174
|
+
return this.api.description
|
|
175
|
+
}
|
|
176
|
+
set description(v: string) {
|
|
177
|
+
this.api.description = v
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
get rawTx() {
|
|
181
|
+
return this.api.rawTx
|
|
182
|
+
}
|
|
183
|
+
set rawTx(v: number[] | undefined) {
|
|
184
|
+
this.api.rawTx = v
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Extended (computed / dependent entity) Properties
|
|
188
|
+
//get labels() { return this.api.labels }
|
|
189
|
+
//set labels(v: string[] | undefined) { this.api.labels = v }
|
|
190
|
+
|
|
191
|
+
override get id(): number {
|
|
192
|
+
return this.api.transactionId
|
|
193
|
+
}
|
|
194
|
+
override set id(v: number) {
|
|
195
|
+
this.api.transactionId = v
|
|
196
|
+
}
|
|
197
|
+
override get entityName(): string {
|
|
198
|
+
return 'transaction'
|
|
199
|
+
}
|
|
200
|
+
override get entityTable(): string {
|
|
201
|
+
return 'transactions'
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
override equals(ei: TableTransaction, syncMap?: SyncMap | undefined): boolean {
|
|
205
|
+
const eo = this.toApi()
|
|
206
|
+
|
|
207
|
+
// Properties that are never updated
|
|
208
|
+
if (
|
|
209
|
+
eo.transactionId !== (syncMap ? syncMap.transaction.idMap[verifyId(ei.transactionId)] : ei.transactionId) ||
|
|
210
|
+
eo.reference !== ei.reference
|
|
211
|
+
)
|
|
212
|
+
return false
|
|
213
|
+
|
|
214
|
+
if (
|
|
215
|
+
eo.version !== ei.version ||
|
|
216
|
+
eo.lockTime !== ei.lockTime ||
|
|
217
|
+
eo.isOutgoing !== ei.isOutgoing ||
|
|
218
|
+
eo.status !== ei.status ||
|
|
219
|
+
eo.satoshis !== ei.satoshis ||
|
|
220
|
+
eo.txid !== ei.txid ||
|
|
221
|
+
eo.description !== ei.description ||
|
|
222
|
+
!optionalArraysEqual(eo.rawTx, ei.rawTx) ||
|
|
223
|
+
!optionalArraysEqual(eo.inputBEEF, ei.inputBEEF)
|
|
224
|
+
)
|
|
225
|
+
return false
|
|
226
|
+
|
|
227
|
+
if (
|
|
228
|
+
!eo.provenTxId !== !ei.provenTxId ||
|
|
229
|
+
(ei.provenTxId && eo.provenTxId !== (syncMap ? syncMap.provenTx.idMap[verifyId(ei.provenTxId)] : ei.provenTxId))
|
|
230
|
+
)
|
|
231
|
+
return false
|
|
232
|
+
|
|
233
|
+
return true
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
static async mergeFind(
|
|
237
|
+
storage: EntityStorage,
|
|
238
|
+
userId: number,
|
|
239
|
+
ei: TableTransaction,
|
|
240
|
+
syncMap: SyncMap,
|
|
241
|
+
trx?: TrxToken
|
|
242
|
+
): Promise<{ found: boolean; eo: EntityTransaction; eiId: number }> {
|
|
243
|
+
const ef = verifyOneOrNone(
|
|
244
|
+
await storage.findTransactions({
|
|
245
|
+
partial: { reference: ei.reference, userId },
|
|
246
|
+
trx
|
|
247
|
+
})
|
|
248
|
+
)
|
|
249
|
+
return {
|
|
250
|
+
found: !!ef,
|
|
251
|
+
eo: new EntityTransaction(ef || { ...ei }),
|
|
252
|
+
eiId: verifyId(ei.transactionId)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
override async mergeNew(storage: EntityStorage, userId: number, syncMap: SyncMap, trx?: TrxToken): Promise<void> {
|
|
257
|
+
if (this.provenTxId) this.provenTxId = syncMap.provenTx.idMap[this.provenTxId]
|
|
258
|
+
this.userId = userId
|
|
259
|
+
this.transactionId = 0
|
|
260
|
+
this.transactionId = await storage.insertTransaction(this.toApi(), trx)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
override async mergeExisting(
|
|
264
|
+
storage: EntityStorage,
|
|
265
|
+
since: Date | undefined,
|
|
266
|
+
ei: TableTransaction,
|
|
267
|
+
syncMap: SyncMap,
|
|
268
|
+
trx?: TrxToken
|
|
269
|
+
): Promise<boolean> {
|
|
270
|
+
let wasMerged = false
|
|
271
|
+
if (ei.updated_at > this.updated_at) {
|
|
272
|
+
// Properties that are never updated:
|
|
273
|
+
// transactionId
|
|
274
|
+
// userId
|
|
275
|
+
// reference
|
|
276
|
+
|
|
277
|
+
// Merged properties
|
|
278
|
+
this.version = ei.version
|
|
279
|
+
this.lockTime = ei.lockTime
|
|
280
|
+
this.isOutgoing = ei.isOutgoing
|
|
281
|
+
this.status = ei.status
|
|
282
|
+
this.provenTxId = ei.provenTxId ? syncMap.provenTx.idMap[ei.provenTxId] : undefined
|
|
283
|
+
this.satoshis = ei.satoshis
|
|
284
|
+
this.txid = ei.txid
|
|
285
|
+
this.description = ei.description
|
|
286
|
+
this.rawTx = ei.rawTx
|
|
287
|
+
this.inputBEEF = ei.inputBEEF
|
|
288
|
+
this.updated_at = new Date(Math.max(ei.updated_at.getTime(), this.updated_at.getTime()))
|
|
289
|
+
await storage.updateTransaction(this.id, this.toApi(), trx)
|
|
290
|
+
wasMerged = true
|
|
291
|
+
}
|
|
292
|
+
return wasMerged
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async getProvenTx(storage: EntityStorage, trx?: TrxToken): Promise<EntityProvenTx | undefined> {
|
|
296
|
+
if (!this.provenTxId) return undefined
|
|
297
|
+
const p = verifyOneOrNone(
|
|
298
|
+
await storage.findProvenTxs({
|
|
299
|
+
partial: { provenTxId: this.provenTxId },
|
|
300
|
+
trx
|
|
301
|
+
})
|
|
302
|
+
)
|
|
303
|
+
if (!p) return undefined
|
|
304
|
+
return new EntityProvenTx(p)
|
|
305
|
+
}
|
|
306
|
+
}
|