@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,580 @@
|
|
|
1
|
+
import { ProvenTxReqStatus, ProvenTxReqTerminalStatus, ReqHistoryNote } from '../../../sdk/types'
|
|
2
|
+
import { TrxToken } from '../../../sdk/WalletStorage.interfaces'
|
|
3
|
+
import { WERR_INTERNAL, WERR_INVALID_PARAMETER } from '../../../sdk/WERR_errors'
|
|
4
|
+
import { arraysEqual, verifyId, verifyOne, verifyOneOrNone } from '../../../utility/utilityHelpers'
|
|
5
|
+
import { StorageProvider } from '../../StorageProvider'
|
|
6
|
+
import { WalletStorageManager } from '../../WalletStorageManager'
|
|
7
|
+
import { TableProvenTxReq, TableProvenTxReqDynamics } from '../tables/TableProvenTxReq'
|
|
8
|
+
import { EntityBase, EntityStorage, SyncMap } from './EntityBase'
|
|
9
|
+
|
|
10
|
+
export class EntityProvenTxReq extends EntityBase<TableProvenTxReq> {
|
|
11
|
+
static async fromStorageTxid(
|
|
12
|
+
storage: EntityStorage,
|
|
13
|
+
txid: string,
|
|
14
|
+
trx?: TrxToken
|
|
15
|
+
): Promise<EntityProvenTxReq | undefined> {
|
|
16
|
+
const reqApi = verifyOneOrNone(await storage.findProvenTxReqs({ partial: { txid }, trx }))
|
|
17
|
+
if (!reqApi) return undefined
|
|
18
|
+
return new EntityProvenTxReq(reqApi)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static async fromStorageId(storage: EntityStorage, id: number, trx?: TrxToken): Promise<EntityProvenTxReq> {
|
|
22
|
+
const reqApi = verifyOneOrNone(await storage.findProvenTxReqs({ partial: { provenTxReqId: id }, trx }))
|
|
23
|
+
if (!reqApi) throw new WERR_INTERNAL(`proven_tx_reqs with id ${id} is missing.`)
|
|
24
|
+
return new EntityProvenTxReq(reqApi)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static fromTxid(txid: string, rawTx: number[], inputBEEF?: number[]): EntityProvenTxReq {
|
|
28
|
+
const now = new Date()
|
|
29
|
+
return new EntityProvenTxReq({
|
|
30
|
+
provenTxReqId: 0,
|
|
31
|
+
created_at: now,
|
|
32
|
+
updated_at: now,
|
|
33
|
+
txid,
|
|
34
|
+
inputBEEF,
|
|
35
|
+
rawTx,
|
|
36
|
+
status: 'unknown',
|
|
37
|
+
history: '{}',
|
|
38
|
+
notify: '{}',
|
|
39
|
+
attempts: 0,
|
|
40
|
+
notified: false
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
history: ProvenTxReqHistory
|
|
45
|
+
notify: ProvenTxReqNotify
|
|
46
|
+
|
|
47
|
+
packApiHistory() {
|
|
48
|
+
this.api.history = JSON.stringify(this.history)
|
|
49
|
+
}
|
|
50
|
+
packApiNotify() {
|
|
51
|
+
this.api.notify = JSON.stringify(this.notify)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
unpackApiHistory() {
|
|
55
|
+
this.history = JSON.parse(this.api.history)
|
|
56
|
+
}
|
|
57
|
+
unpackApiNotify() {
|
|
58
|
+
this.notify = JSON.parse(this.api.notify)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get apiHistory(): string {
|
|
62
|
+
this.packApiHistory()
|
|
63
|
+
return this.api.history
|
|
64
|
+
}
|
|
65
|
+
get apiNotify(): string {
|
|
66
|
+
this.packApiNotify()
|
|
67
|
+
return this.api.notify
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
set apiHistory(v: string) {
|
|
71
|
+
this.api.history = v
|
|
72
|
+
this.unpackApiHistory()
|
|
73
|
+
}
|
|
74
|
+
set apiNotify(v: string) {
|
|
75
|
+
this.api.notify = v
|
|
76
|
+
this.unpackApiNotify()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
updateApi(): void {
|
|
80
|
+
this.packApiHistory()
|
|
81
|
+
this.packApiNotify()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
unpackApi(): void {
|
|
85
|
+
this.unpackApiHistory()
|
|
86
|
+
this.unpackApiNotify()
|
|
87
|
+
if (this.notify.transactionIds) {
|
|
88
|
+
// Cleanup null values and duplicates.
|
|
89
|
+
const transactionIds: number[] = []
|
|
90
|
+
for (const id of this.notify.transactionIds) {
|
|
91
|
+
if (Number.isInteger(id) && !transactionIds.some(txid => txid === id)) transactionIds.push(id)
|
|
92
|
+
}
|
|
93
|
+
this.notify.transactionIds = transactionIds
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async refreshFromStorage(storage: EntityStorage | WalletStorageManager, trx?: TrxToken): Promise<void> {
|
|
98
|
+
const newApi = verifyOne(await storage.findProvenTxReqs({ partial: { provenTxReqId: this.id }, trx }))
|
|
99
|
+
this.api = newApi
|
|
100
|
+
this.unpackApi()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
constructor(api?: TableProvenTxReq) {
|
|
104
|
+
const now = new Date()
|
|
105
|
+
super(
|
|
106
|
+
api || {
|
|
107
|
+
provenTxReqId: 0,
|
|
108
|
+
created_at: now,
|
|
109
|
+
updated_at: now,
|
|
110
|
+
txid: '',
|
|
111
|
+
rawTx: [],
|
|
112
|
+
history: '',
|
|
113
|
+
notify: '',
|
|
114
|
+
attempts: 0,
|
|
115
|
+
status: 'unknown',
|
|
116
|
+
notified: false
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
this.history = {}
|
|
120
|
+
this.notify = {}
|
|
121
|
+
this.unpackApi()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Returns history to only what followed since date.
|
|
126
|
+
*/
|
|
127
|
+
historySince(since: Date): ProvenTxReqHistory {
|
|
128
|
+
const fh: ProvenTxReqHistory = { notes: [] }
|
|
129
|
+
const filter = since.toISOString()
|
|
130
|
+
const notes = this.history.notes
|
|
131
|
+
if (notes && fh.notes) {
|
|
132
|
+
for (const note of notes) if (note.when && note.when > filter) fh.notes.push(note)
|
|
133
|
+
}
|
|
134
|
+
return fh
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
historyPretty(since?: Date, indent = 0): string {
|
|
138
|
+
const h = since ? this.historySince(since) : { ...this.history }
|
|
139
|
+
if (!h.notes) return ''
|
|
140
|
+
const whenLimit = since ? since.toISOString() : undefined
|
|
141
|
+
let log = ''
|
|
142
|
+
for (const note of h.notes) {
|
|
143
|
+
if (whenLimit && note.when && note.when < whenLimit) continue
|
|
144
|
+
log += this.prettyNote(note) + '\n'
|
|
145
|
+
}
|
|
146
|
+
return log
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
prettyNote(note: ReqHistoryNote): string {
|
|
150
|
+
let log = `${note.when}: ${note.what}`
|
|
151
|
+
for (const [key, val] of Object.entries(note)) {
|
|
152
|
+
if (key !== 'when' && key !== 'what') {
|
|
153
|
+
if (typeof val === 'string') log += ' ' + key + ':`' + val + '`'
|
|
154
|
+
else log += ' ' + key + ':' + val
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return log
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
getHistorySummary(): ProvenTxReqHistorySummaryApi {
|
|
161
|
+
const summary: ProvenTxReqHistorySummaryApi = {
|
|
162
|
+
setToCompleted: false,
|
|
163
|
+
setToUnmined: false,
|
|
164
|
+
setToCallback: false,
|
|
165
|
+
setToDoubleSpend: false,
|
|
166
|
+
setToSending: false,
|
|
167
|
+
setToUnconfirmed: false
|
|
168
|
+
}
|
|
169
|
+
const h = this.history
|
|
170
|
+
if (h.notes) {
|
|
171
|
+
for (const note of h.notes) {
|
|
172
|
+
this.parseHistoryNote(note, summary)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return summary
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
parseHistoryNote(note: ReqHistoryNote, summary?: ProvenTxReqHistorySummaryApi): string {
|
|
179
|
+
const c = summary || {
|
|
180
|
+
setToCompleted: false,
|
|
181
|
+
setToUnmined: false,
|
|
182
|
+
setToCallback: false,
|
|
183
|
+
setToDoubleSpend: false,
|
|
184
|
+
setToSending: false,
|
|
185
|
+
setToUnconfirmed: false
|
|
186
|
+
}
|
|
187
|
+
let n = this.prettyNote(note)
|
|
188
|
+
try {
|
|
189
|
+
switch (note.what) {
|
|
190
|
+
case 'status':
|
|
191
|
+
{
|
|
192
|
+
const status = <ProvenTxReqStatus>note.status_now
|
|
193
|
+
switch (status) {
|
|
194
|
+
case 'completed':
|
|
195
|
+
c.setToCompleted = true
|
|
196
|
+
break
|
|
197
|
+
case 'unmined':
|
|
198
|
+
c.setToUnmined = true
|
|
199
|
+
break
|
|
200
|
+
case 'callback':
|
|
201
|
+
c.setToCallback = true
|
|
202
|
+
break
|
|
203
|
+
case 'doubleSpend':
|
|
204
|
+
c.setToDoubleSpend = true
|
|
205
|
+
break
|
|
206
|
+
case 'sending':
|
|
207
|
+
c.setToSending = true
|
|
208
|
+
break
|
|
209
|
+
case 'unconfirmed':
|
|
210
|
+
c.setToUnconfirmed = true
|
|
211
|
+
break
|
|
212
|
+
default:
|
|
213
|
+
break
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
break
|
|
217
|
+
default:
|
|
218
|
+
break
|
|
219
|
+
}
|
|
220
|
+
} catch {
|
|
221
|
+
/** */
|
|
222
|
+
}
|
|
223
|
+
return n
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
addNotifyTransactionId(id: number) {
|
|
227
|
+
if (!Number.isInteger(id)) throw new WERR_INVALID_PARAMETER('id', 'integer')
|
|
228
|
+
const s = new Set(this.notify.transactionIds || [])
|
|
229
|
+
s.add(id)
|
|
230
|
+
this.notify.transactionIds = [...s].sort((a, b) => (a > b ? 1 : a < b ? -1 : 0))
|
|
231
|
+
this.notified = false
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Adds a note to history.
|
|
236
|
+
* Notes with identical property values to an existing note are ignored.
|
|
237
|
+
* @param note Note to add
|
|
238
|
+
* @param noDupes if true, only newest note with same `what` value is retained.
|
|
239
|
+
*/
|
|
240
|
+
addHistoryNote(note: ReqHistoryNote, noDupes?: boolean) {
|
|
241
|
+
if (!this.history.notes) this.history.notes = []
|
|
242
|
+
if (!note.when) note.when = new Date().toISOString()
|
|
243
|
+
if (noDupes) {
|
|
244
|
+
// Remove any existing notes with same 'what' value and either no 'when' or an earlier 'when'
|
|
245
|
+
this.history.notes = this.history.notes!.filter(n => n.what !== note.what || (n.when && n.when > note.when!))
|
|
246
|
+
}
|
|
247
|
+
let addNote = true
|
|
248
|
+
for (const n of this.history.notes) {
|
|
249
|
+
let isEqual = true
|
|
250
|
+
for (const [k, v] of Object.entries(n)) {
|
|
251
|
+
if (v !== note[k]) {
|
|
252
|
+
isEqual = false
|
|
253
|
+
break
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (isEqual) addNote = false
|
|
257
|
+
if (!addNote) break
|
|
258
|
+
}
|
|
259
|
+
if (addNote) {
|
|
260
|
+
this.history.notes.push(note as ReqHistoryNote)
|
|
261
|
+
const k = (n: ReqHistoryNote): string => {
|
|
262
|
+
return `${n.when} ${n.what}`
|
|
263
|
+
}
|
|
264
|
+
this.history.notes.sort((a, b) => (k(a) < k(b) ? -1 : k(a) > k(b) ? 1 : 0))
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Updates database record with current state of this EntityUser
|
|
270
|
+
|
|
271
|
+
* @param storage
|
|
272
|
+
* @param trx
|
|
273
|
+
*/
|
|
274
|
+
async updateStorage(storage: EntityStorage, trx?: TrxToken) {
|
|
275
|
+
this.updated_at = new Date()
|
|
276
|
+
this.updateApi()
|
|
277
|
+
if (this.id === 0) {
|
|
278
|
+
await storage.insertProvenTxReq(this.api)
|
|
279
|
+
}
|
|
280
|
+
const update: Partial<TableProvenTxReq> = { ...this.api }
|
|
281
|
+
await storage.updateProvenTxReq(this.id, update, trx)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Update storage with changes to non-static properties:
|
|
286
|
+
* updated_at
|
|
287
|
+
* provenTxId
|
|
288
|
+
* status
|
|
289
|
+
* history
|
|
290
|
+
* notify
|
|
291
|
+
* notified
|
|
292
|
+
* attempts
|
|
293
|
+
* batch
|
|
294
|
+
*
|
|
295
|
+
* @param storage
|
|
296
|
+
* @param trx
|
|
297
|
+
*/
|
|
298
|
+
async updateStorageDynamicProperties(storage: WalletStorageManager | StorageProvider, trx?: TrxToken) {
|
|
299
|
+
this.updated_at = new Date()
|
|
300
|
+
this.updateApi()
|
|
301
|
+
const update: Partial<TableProvenTxReqDynamics> = {
|
|
302
|
+
updated_at: this.api.updated_at,
|
|
303
|
+
provenTxId: this.api.provenTxId,
|
|
304
|
+
status: this.api.status,
|
|
305
|
+
history: this.api.history,
|
|
306
|
+
notify: this.api.notify,
|
|
307
|
+
notified: this.api.notified,
|
|
308
|
+
attempts: this.api.attempts,
|
|
309
|
+
batch: this.api.batch
|
|
310
|
+
}
|
|
311
|
+
if (storage.isStorageProvider()) {
|
|
312
|
+
const sp = storage as StorageProvider
|
|
313
|
+
await sp.updateProvenTxReqDynamics(this.id, update, trx)
|
|
314
|
+
} else {
|
|
315
|
+
const wsm = storage as WalletStorageManager
|
|
316
|
+
await wsm.runAsStorageProvider(async sp => {
|
|
317
|
+
await sp.updateProvenTxReqDynamics(this.id, update, trx)
|
|
318
|
+
})
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async insertOrMerge(storage: EntityStorage, trx?: TrxToken): Promise<EntityProvenTxReq> {
|
|
323
|
+
const req = await storage.transaction<EntityProvenTxReq>(async trx => {
|
|
324
|
+
let reqApi0 = this.toApi()
|
|
325
|
+
const { req: reqApi1, isNew } = await storage.findOrInsertProvenTxReq(reqApi0, trx)
|
|
326
|
+
if (isNew) {
|
|
327
|
+
return new EntityProvenTxReq(reqApi1)
|
|
328
|
+
} else {
|
|
329
|
+
const req = new EntityProvenTxReq(reqApi1)
|
|
330
|
+
req.mergeNotifyTransactionIds(reqApi0)
|
|
331
|
+
req.mergeHistory(reqApi0, undefined, true)
|
|
332
|
+
await req.updateStorage(storage, trx)
|
|
333
|
+
return req
|
|
334
|
+
}
|
|
335
|
+
}, trx)
|
|
336
|
+
return req
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* See `ProvenTxReqStatusApi`
|
|
341
|
+
*/
|
|
342
|
+
get status() {
|
|
343
|
+
return this.api.status
|
|
344
|
+
}
|
|
345
|
+
set status(v: ProvenTxReqStatus) {
|
|
346
|
+
if (v !== this.api.status) {
|
|
347
|
+
this.addHistoryNote({ what: 'status', status_was: this.api.status, status_now: v })
|
|
348
|
+
this.api.status = v
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
get provenTxReqId() {
|
|
352
|
+
return this.api.provenTxReqId
|
|
353
|
+
}
|
|
354
|
+
set provenTxReqId(v: number) {
|
|
355
|
+
this.api.provenTxReqId = v
|
|
356
|
+
}
|
|
357
|
+
get created_at() {
|
|
358
|
+
return this.api.created_at
|
|
359
|
+
}
|
|
360
|
+
set created_at(v: Date) {
|
|
361
|
+
this.api.created_at = v
|
|
362
|
+
}
|
|
363
|
+
get updated_at() {
|
|
364
|
+
return this.api.updated_at
|
|
365
|
+
}
|
|
366
|
+
set updated_at(v: Date) {
|
|
367
|
+
this.api.updated_at = v
|
|
368
|
+
}
|
|
369
|
+
get txid() {
|
|
370
|
+
return this.api.txid
|
|
371
|
+
}
|
|
372
|
+
set txid(v: string) {
|
|
373
|
+
this.api.txid = v
|
|
374
|
+
}
|
|
375
|
+
get inputBEEF() {
|
|
376
|
+
return this.api.inputBEEF
|
|
377
|
+
}
|
|
378
|
+
set inputBEEF(v: number[] | undefined) {
|
|
379
|
+
this.api.inputBEEF = v
|
|
380
|
+
}
|
|
381
|
+
get rawTx() {
|
|
382
|
+
return this.api.rawTx
|
|
383
|
+
}
|
|
384
|
+
set rawTx(v: number[]) {
|
|
385
|
+
this.api.rawTx = v
|
|
386
|
+
}
|
|
387
|
+
get attempts() {
|
|
388
|
+
return this.api.attempts
|
|
389
|
+
}
|
|
390
|
+
set attempts(v: number) {
|
|
391
|
+
this.api.attempts = v
|
|
392
|
+
}
|
|
393
|
+
get provenTxId() {
|
|
394
|
+
return this.api.provenTxId
|
|
395
|
+
}
|
|
396
|
+
set provenTxId(v: number | undefined) {
|
|
397
|
+
this.api.provenTxId = v
|
|
398
|
+
}
|
|
399
|
+
get notified() {
|
|
400
|
+
return this.api.notified
|
|
401
|
+
}
|
|
402
|
+
set notified(v: boolean) {
|
|
403
|
+
this.api.notified = v
|
|
404
|
+
}
|
|
405
|
+
get batch() {
|
|
406
|
+
return this.api.batch
|
|
407
|
+
}
|
|
408
|
+
set batch(v: string | undefined) {
|
|
409
|
+
this.api.batch = v
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
override get id() {
|
|
413
|
+
return this.api.provenTxReqId
|
|
414
|
+
}
|
|
415
|
+
override set id(v: number) {
|
|
416
|
+
this.api.provenTxReqId = v
|
|
417
|
+
}
|
|
418
|
+
override get entityName(): string {
|
|
419
|
+
return 'provenTxReq'
|
|
420
|
+
}
|
|
421
|
+
override get entityTable(): string {
|
|
422
|
+
return 'proven_tx_reqs'
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* 'convergent' equality must satisfy (A sync B) equals (B sync A)
|
|
427
|
+
*/
|
|
428
|
+
override equals(ei: TableProvenTxReq, syncMap?: SyncMap | undefined): boolean {
|
|
429
|
+
const eo = this.toApi()
|
|
430
|
+
if (
|
|
431
|
+
eo.txid != ei.txid ||
|
|
432
|
+
!arraysEqual(eo.rawTx, ei.rawTx) ||
|
|
433
|
+
(!eo.inputBEEF && ei.inputBEEF) ||
|
|
434
|
+
(eo.inputBEEF && !ei.inputBEEF) ||
|
|
435
|
+
(eo.inputBEEF && ei.inputBEEF && !arraysEqual(eo.inputBEEF, ei.inputBEEF)) ||
|
|
436
|
+
eo.batch != ei.batch
|
|
437
|
+
)
|
|
438
|
+
return false
|
|
439
|
+
if (syncMap) {
|
|
440
|
+
if (
|
|
441
|
+
// attempts doesn't matter for convergent equality
|
|
442
|
+
// history doesn't matter for convergent equality
|
|
443
|
+
// only local transactionIds matter, that cared about this txid in sorted order
|
|
444
|
+
eo.provenTxReqId !== syncMap.provenTxReq.idMap[verifyId(ei.provenTxReqId)] ||
|
|
445
|
+
(!eo.provenTxId && ei.provenTxId) ||
|
|
446
|
+
(eo.provenTxId && !ei.provenTxId) ||
|
|
447
|
+
(ei.provenTxId && eo.provenTxId !== syncMap.provenTx.idMap[ei.provenTxId])
|
|
448
|
+
// || eo.created_at !== minDate(ei.created_at, eo.created_at)
|
|
449
|
+
// || eo.updated_at !== maxDate(ei.updated_at, eo.updated_at)
|
|
450
|
+
)
|
|
451
|
+
return false
|
|
452
|
+
} else {
|
|
453
|
+
if (
|
|
454
|
+
eo.attempts != ei.attempts ||
|
|
455
|
+
eo.history != ei.history ||
|
|
456
|
+
eo.notify != ei.notify ||
|
|
457
|
+
eo.provenTxReqId !== ei.provenTxReqId ||
|
|
458
|
+
eo.provenTxId !== ei.provenTxId
|
|
459
|
+
// || eo.created_at !== ei.created_at
|
|
460
|
+
// || eo.updated_at !== ei.updated_at
|
|
461
|
+
)
|
|
462
|
+
return false
|
|
463
|
+
}
|
|
464
|
+
return true
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
static async mergeFind(
|
|
468
|
+
storage: EntityStorage,
|
|
469
|
+
userId: number,
|
|
470
|
+
ei: TableProvenTxReq,
|
|
471
|
+
syncMap: SyncMap,
|
|
472
|
+
trx?: TrxToken
|
|
473
|
+
): Promise<{ found: boolean; eo: EntityProvenTxReq; eiId: number }> {
|
|
474
|
+
const ef = verifyOneOrNone(await storage.findProvenTxReqs({ partial: { txid: ei.txid }, trx }))
|
|
475
|
+
return {
|
|
476
|
+
found: !!ef,
|
|
477
|
+
eo: new EntityProvenTxReq(ef || { ...ei }),
|
|
478
|
+
eiId: verifyId(ei.provenTxReqId)
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
mapNotifyTransactionIds(syncMap: SyncMap): void {
|
|
483
|
+
// Map external notification transaction ids to local ids
|
|
484
|
+
const externalIds = this.notify.transactionIds || []
|
|
485
|
+
this.notify.transactionIds = []
|
|
486
|
+
for (const transactionId of externalIds) {
|
|
487
|
+
const localTxId: number | undefined = syncMap.transaction.idMap[transactionId]
|
|
488
|
+
if (localTxId) {
|
|
489
|
+
this.addNotifyTransactionId(localTxId)
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
mergeNotifyTransactionIds(ei: TableProvenTxReq, syncMap?: SyncMap): void {
|
|
495
|
+
// Map external notification transaction ids to local ids and merge them if they exist.
|
|
496
|
+
const eie = new EntityProvenTxReq(ei)
|
|
497
|
+
if (eie.notify.transactionIds) {
|
|
498
|
+
this.notify.transactionIds ||= []
|
|
499
|
+
for (const transactionId of eie.notify.transactionIds) {
|
|
500
|
+
const localTxId: number | undefined = syncMap ? syncMap.transaction.idMap[transactionId] : transactionId
|
|
501
|
+
if (localTxId) {
|
|
502
|
+
this.addNotifyTransactionId(localTxId)
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
509
|
+
mergeHistory(ei: TableProvenTxReq, syncMap?: SyncMap, noDupes?: boolean): void {
|
|
510
|
+
const eie = new EntityProvenTxReq(ei)
|
|
511
|
+
if (eie.history.notes) {
|
|
512
|
+
for (const note of eie.history.notes) {
|
|
513
|
+
this.addHistoryNote(note)
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
static isTerminalStatus(status: ProvenTxReqStatus): boolean {
|
|
519
|
+
return ProvenTxReqTerminalStatus.some(s => s === status)
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
override async mergeNew(storage: EntityStorage, userId: number, syncMap: SyncMap, trx?: TrxToken): Promise<void> {
|
|
523
|
+
if (this.provenTxId) this.provenTxId = syncMap.provenTx.idMap[this.provenTxId]
|
|
524
|
+
this.mapNotifyTransactionIds(syncMap)
|
|
525
|
+
this.provenTxReqId = 0
|
|
526
|
+
this.provenTxReqId = await storage.insertProvenTxReq(this.toApi(), trx)
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* When merging `ProvenTxReq`, care is taken to avoid short-cirtuiting notification: `status` must not transition to `completed` without
|
|
531
|
+
* passing through `notifying`. Thus a full convergent merge passes through these sequence steps:
|
|
532
|
+
* 1. Remote storage completes before local storage.
|
|
533
|
+
* 2. The remotely completed req and ProvenTx sync to local storage.
|
|
534
|
+
* 3. The local storage transitions to `notifying`, after merging the remote attempts and history.
|
|
535
|
+
* 4. The local storage notifies, transitioning to `completed`.
|
|
536
|
+
* 5. Having been updated, the local req, but not ProvenTx sync to remote storage, but do not merge because the earlier `completed` wins.
|
|
537
|
+
* 6. Convergent equality is achieved (completing work - history and attempts are equal)
|
|
538
|
+
*
|
|
539
|
+
* On terminal failure: `doubleSpend` trumps `invalid` as it contains more data.
|
|
540
|
+
*/
|
|
541
|
+
override async mergeExisting(
|
|
542
|
+
storage: EntityStorage,
|
|
543
|
+
since: Date | undefined,
|
|
544
|
+
ei: TableProvenTxReq,
|
|
545
|
+
syncMap: SyncMap,
|
|
546
|
+
trx?: TrxToken
|
|
547
|
+
): Promise<boolean> {
|
|
548
|
+
if (!this.batch && ei.batch) this.batch = ei.batch
|
|
549
|
+
else if (this.batch && ei.batch && this.batch !== ei.batch)
|
|
550
|
+
throw new WERR_INTERNAL('ProvenTxReq merge batch not equal.')
|
|
551
|
+
|
|
552
|
+
this.mergeHistory(ei, syncMap, true)
|
|
553
|
+
this.mergeNotifyTransactionIds(ei, syncMap)
|
|
554
|
+
|
|
555
|
+
this.updated_at = new Date(Math.max(ei.updated_at.getTime(), this.updated_at.getTime()))
|
|
556
|
+
await storage.updateProvenTxReq(this.id, this.toApi(), trx)
|
|
557
|
+
return false
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
export interface ProvenTxReqHistorySummaryApi {
|
|
562
|
+
setToCompleted: boolean
|
|
563
|
+
setToCallback: boolean
|
|
564
|
+
setToUnmined: boolean
|
|
565
|
+
setToDoubleSpend: boolean
|
|
566
|
+
setToSending: boolean
|
|
567
|
+
setToUnconfirmed: boolean
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
export interface ProvenTxReqHistory {
|
|
571
|
+
/**
|
|
572
|
+
* Keys are Date().toISOString()
|
|
573
|
+
* Values are a description of what happened.
|
|
574
|
+
*/
|
|
575
|
+
notes?: ReqHistoryNote[]
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
export interface ProvenTxReqNotify {
|
|
579
|
+
transactionIds?: number[]
|
|
580
|
+
}
|