@bsv/wallet-toolbox 1.1.60 → 1.1.62
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/.prettierrc +1 -1
- package/docs/client.md +39 -5
- package/docs/services.md +1 -0
- package/docs/setup.md +9 -26
- package/docs/storage.md +35 -0
- package/docs/wallet.md +39 -5
- package/out/src/Setup.d.ts.map +1 -1
- package/out/src/Setup.js +6 -16
- package/out/src/Setup.js.map +1 -1
- package/out/src/Wallet.d.ts.map +1 -1
- package/out/src/Wallet.js +4 -11
- package/out/src/Wallet.js.map +1 -1
- package/out/src/monitor/Monitor.d.ts.map +1 -1
- package/out/src/monitor/Monitor.js.map +1 -1
- package/out/src/monitor/MonitorDaemon.d.ts.map +1 -1
- package/out/src/monitor/MonitorDaemon.js +1 -3
- package/out/src/monitor/MonitorDaemon.js.map +1 -1
- package/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskCheckForProofs.js +2 -10
- package/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -1
- package/out/src/monitor/tasks/TaskClock.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskClock.js +1 -1
- package/out/src/monitor/tasks/TaskClock.js.map +1 -1
- package/out/src/monitor/tasks/TaskFailAbandoned.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskFailAbandoned.js.map +1 -1
- package/out/src/monitor/tasks/TaskNewHeader.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskNewHeader.js +1 -2
- package/out/src/monitor/tasks/TaskNewHeader.js.map +1 -1
- package/out/src/monitor/tasks/TaskPurge.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskPurge.js +1 -2
- package/out/src/monitor/tasks/TaskPurge.js.map +1 -1
- package/out/src/monitor/tasks/TaskReviewStatus.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskReviewStatus.js +1 -2
- package/out/src/monitor/tasks/TaskReviewStatus.js.map +1 -1
- package/out/src/monitor/tasks/TaskSendWaiting.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -1
- package/out/src/sdk/CertOps.d.ts.map +1 -1
- package/out/src/sdk/CertOps.js +4 -12
- package/out/src/sdk/CertOps.js.map +1 -1
- package/out/src/sdk/PrivilegedKeyManager.d.ts.map +1 -1
- package/out/src/sdk/PrivilegedKeyManager.js.map +1 -1
- package/out/src/sdk/WERR_errors.d.ts.map +1 -1
- package/out/src/sdk/WERR_errors.js.map +1 -1
- package/out/src/sdk/WalletError.d.ts.map +1 -1
- package/out/src/sdk/WalletError.js +1 -4
- package/out/src/sdk/WalletError.js.map +1 -1
- package/out/src/sdk/WalletServices.interfaces.d.ts +2 -0
- package/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
- package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
- package/out/src/sdk/__test/CertificateLifeCycle.test.js +1 -3
- package/out/src/sdk/__test/CertificateLifeCycle.test.js.map +1 -1
- package/out/src/sdk/__test/PrivilegedKeyManager.test.js +13 -26
- package/out/src/sdk/__test/PrivilegedKeyManager.test.js.map +1 -1
- package/out/src/sdk/types.d.ts.map +1 -1
- package/out/src/sdk/types.js +2 -10
- package/out/src/sdk/types.js.map +1 -1
- package/out/src/sdk/validationHelpers.d.ts.map +1 -1
- package/out/src/sdk/validationHelpers.js +5 -12
- package/out/src/sdk/validationHelpers.js.map +1 -1
- package/out/src/services/Services.d.ts +1 -0
- package/out/src/services/Services.d.ts.map +1 -1
- package/out/src/services/Services.js +29 -38
- package/out/src/services/Services.js.map +1 -1
- package/out/src/services/__tests/ARC.test.js +9 -0
- package/out/src/services/__tests/ARC.test.js.map +1 -1
- package/out/src/services/__tests/bitrails.test.js.map +1 -1
- package/out/src/services/__tests/getMerklePath.test.js.map +1 -1
- package/out/src/services/__tests/getRawTx.test.js.map +1 -1
- package/out/src/services/__tests/verifyBeef.test.js +2 -1
- package/out/src/services/__tests/verifyBeef.test.js.map +1 -1
- package/out/src/services/chaintracker/ChaintracksChainTracker.d.ts.map +1 -1
- package/out/src/services/chaintracker/ChaintracksChainTracker.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js +1 -3
- package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js.map +1 -1
- package/out/src/services/createDefaultWalletServicesOptions.d.ts.map +1 -1
- package/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
- package/out/src/services/providers/ARC.d.ts.map +1 -1
- package/out/src/services/providers/ARC.js +2 -3
- package/out/src/services/providers/ARC.js.map +1 -1
- package/out/src/services/providers/Bitails.d.ts.map +1 -1
- package/out/src/services/providers/Bitails.js +62 -134
- package/out/src/services/providers/Bitails.js.map +1 -1
- package/out/src/services/providers/SdkWhatsOnChain.d.ts.map +1 -1
- package/out/src/services/providers/SdkWhatsOnChain.js.map +1 -1
- package/out/src/services/providers/WhatsOnChain.d.ts.map +1 -1
- package/out/src/services/providers/WhatsOnChain.js +6 -21
- package/out/src/services/providers/WhatsOnChain.js.map +1 -1
- package/out/src/services/providers/__tests/WhatsOnChain.test.js +1 -2
- package/out/src/services/providers/__tests/WhatsOnChain.test.js.map +1 -1
- package/out/src/services/providers/echangeRates.d.ts.map +1 -1
- package/out/src/services/providers/echangeRates.js.map +1 -1
- package/out/src/signer/WalletSigner.d.ts.map +1 -1
- package/out/src/signer/WalletSigner.js.map +1 -1
- package/out/src/signer/methods/acquireDirectCertificate.d.ts.map +1 -1
- package/out/src/signer/methods/acquireDirectCertificate.js +1 -3
- package/out/src/signer/methods/acquireDirectCertificate.js.map +1 -1
- package/out/src/signer/methods/buildSignableTransaction.d.ts.map +1 -1
- package/out/src/signer/methods/buildSignableTransaction.js +3 -11
- package/out/src/signer/methods/buildSignableTransaction.js.map +1 -1
- package/out/src/signer/methods/createAction.d.ts.map +1 -1
- package/out/src/signer/methods/createAction.js +3 -10
- package/out/src/signer/methods/createAction.js.map +1 -1
- package/out/src/signer/methods/internalizeAction.d.ts.map +1 -1
- package/out/src/signer/methods/internalizeAction.js.map +1 -1
- package/out/src/signer/methods/proveCertificate.d.ts.map +1 -1
- package/out/src/signer/methods/proveCertificate.js.map +1 -1
- package/out/src/signer/methods/signAction.d.ts.map +1 -1
- package/out/src/signer/methods/signAction.js +2 -7
- package/out/src/signer/methods/signAction.js.map +1 -1
- package/out/src/storage/StorageKnex.d.ts.map +1 -1
- package/out/src/storage/StorageKnex.js +15 -44
- package/out/src/storage/StorageKnex.js.map +1 -1
- package/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/out/src/storage/StorageProvider.js +9 -34
- package/out/src/storage/StorageProvider.js.map +1 -1
- package/out/src/storage/StorageReader.d.ts.map +1 -1
- package/out/src/storage/StorageReader.js.map +1 -1
- package/out/src/storage/StorageReaderWriter.d.ts.map +1 -1
- package/out/src/storage/StorageReaderWriter.js.map +1 -1
- package/out/src/storage/StorageSyncReader.d.ts.map +1 -1
- package/out/src/storage/StorageSyncReader.js.map +1 -1
- package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/out/src/storage/WalletStorageManager.js +5 -10
- package/out/src/storage/WalletStorageManager.js.map +1 -1
- package/out/src/storage/__test/WalletStorageManager.test.js +2 -8
- package/out/src/storage/__test/WalletStorageManager.test.js.map +1 -1
- package/out/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.js +10 -30
- package/out/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.js.map +1 -1
- package/out/src/storage/methods/__test/GenerateChange/randomValsUsed1.d.ts.map +1 -1
- package/out/src/storage/methods/__test/GenerateChange/randomValsUsed1.js +17 -28
- package/out/src/storage/methods/__test/GenerateChange/randomValsUsed1.js.map +1 -1
- package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
- package/out/src/storage/methods/attemptToPostReqsToNetwork.js +6 -20
- package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
- package/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/out/src/storage/methods/createAction.js +4 -9
- package/out/src/storage/methods/createAction.js.map +1 -1
- package/out/src/storage/methods/generateChange.d.ts.map +1 -1
- package/out/src/storage/methods/generateChange.js +7 -18
- package/out/src/storage/methods/generateChange.js.map +1 -1
- package/out/src/storage/methods/getBeefForTransaction.d.ts.map +1 -1
- package/out/src/storage/methods/getBeefForTransaction.js +1 -3
- package/out/src/storage/methods/getBeefForTransaction.js.map +1 -1
- package/out/src/storage/methods/getSyncChunk.d.ts.map +1 -1
- package/out/src/storage/methods/getSyncChunk.js.map +1 -1
- package/out/src/storage/methods/internalizeAction.d.ts.map +1 -1
- package/out/src/storage/methods/internalizeAction.js +2 -9
- package/out/src/storage/methods/internalizeAction.js.map +1 -1
- package/out/src/storage/methods/listActions.d.ts.map +1 -1
- package/out/src/storage/methods/listActions.js +3 -15
- package/out/src/storage/methods/listActions.js.map +1 -1
- package/out/src/storage/methods/listCertificates.d.ts.map +1 -1
- package/out/src/storage/methods/listCertificates.js.map +1 -1
- package/out/src/storage/methods/listOutputs.d.ts.map +1 -1
- package/out/src/storage/methods/listOutputs.js +5 -12
- package/out/src/storage/methods/listOutputs.js.map +1 -1
- package/out/src/storage/methods/processAction.d.ts.map +1 -1
- package/out/src/storage/methods/processAction.js +4 -10
- package/out/src/storage/methods/processAction.js.map +1 -1
- package/out/src/storage/methods/purgeData.d.ts.map +1 -1
- package/out/src/storage/methods/purgeData.js +8 -32
- package/out/src/storage/methods/purgeData.js.map +1 -1
- package/out/src/storage/methods/reviewStatus.d.ts.map +1 -1
- package/out/src/storage/methods/reviewStatus.js +1 -3
- package/out/src/storage/methods/reviewStatus.js.map +1 -1
- package/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageClient.js +15 -41
- package/out/src/storage/remoting/StorageClient.js.map +1 -1
- package/out/src/storage/remoting/StorageServer.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageServer.js +2 -5
- package/out/src/storage/remoting/StorageServer.js.map +1 -1
- package/out/src/storage/schema/KnexMigrations.d.ts.map +1 -1
- package/out/src/storage/schema/KnexMigrations.js +24 -130
- package/out/src/storage/schema/KnexMigrations.js.map +1 -1
- package/out/src/storage/schema/entities/Certificate.d.ts.map +1 -1
- package/out/src/storage/schema/entities/Certificate.js +1 -1
- package/out/src/storage/schema/entities/Certificate.js.map +1 -1
- package/out/src/storage/schema/entities/CertificateField.d.ts.map +1 -1
- package/out/src/storage/schema/entities/CertificateField.js +2 -5
- package/out/src/storage/schema/entities/CertificateField.js.map +1 -1
- package/out/src/storage/schema/entities/Commission.d.ts.map +1 -1
- package/out/src/storage/schema/entities/Commission.js +2 -5
- package/out/src/storage/schema/entities/Commission.js.map +1 -1
- package/out/src/storage/schema/entities/EntityBase.d.ts.map +1 -1
- package/out/src/storage/schema/entities/EntityBase.js.map +1 -1
- package/out/src/storage/schema/entities/MergeEntity.d.ts.map +1 -1
- package/out/src/storage/schema/entities/MergeEntity.js +14 -9
- package/out/src/storage/schema/entities/MergeEntity.js.map +1 -1
- package/out/src/storage/schema/entities/Output.d.ts.map +1 -1
- package/out/src/storage/schema/entities/Output.js +8 -25
- package/out/src/storage/schema/entities/Output.js.map +1 -1
- package/out/src/storage/schema/entities/OutputBasket.d.ts.map +1 -1
- package/out/src/storage/schema/entities/OutputBasket.js +1 -1
- package/out/src/storage/schema/entities/OutputBasket.js.map +1 -1
- package/out/src/storage/schema/entities/OutputTag.d.ts.map +1 -1
- package/out/src/storage/schema/entities/OutputTag.js +1 -1
- package/out/src/storage/schema/entities/OutputTag.js.map +1 -1
- package/out/src/storage/schema/entities/OutputTagMap.d.ts.map +1 -1
- package/out/src/storage/schema/entities/OutputTagMap.js +3 -7
- package/out/src/storage/schema/entities/OutputTagMap.js.map +1 -1
- package/out/src/storage/schema/entities/ProvenTx.d.ts.map +1 -1
- package/out/src/storage/schema/entities/ProvenTx.js +10 -20
- package/out/src/storage/schema/entities/ProvenTx.js.map +1 -1
- package/out/src/storage/schema/entities/ProvenTxReq.d.ts.map +1 -1
- package/out/src/storage/schema/entities/ProvenTxReq.js +8 -18
- package/out/src/storage/schema/entities/ProvenTxReq.js.map +1 -1
- package/out/src/storage/schema/entities/SyncState.d.ts +1 -0
- package/out/src/storage/schema/entities/SyncState.d.ts.map +1 -1
- package/out/src/storage/schema/entities/SyncState.js +41 -6
- package/out/src/storage/schema/entities/SyncState.js.map +1 -1
- package/out/src/storage/schema/entities/Transaction.d.ts.map +1 -1
- package/out/src/storage/schema/entities/Transaction.js +4 -13
- package/out/src/storage/schema/entities/Transaction.js.map +1 -1
- package/out/src/storage/schema/entities/TxLabel.d.ts.map +1 -1
- package/out/src/storage/schema/entities/TxLabel.js +1 -1
- package/out/src/storage/schema/entities/TxLabel.js.map +1 -1
- package/out/src/storage/schema/entities/TxLabelMap.d.ts.map +1 -1
- package/out/src/storage/schema/entities/TxLabelMap.js +3 -9
- package/out/src/storage/schema/entities/TxLabelMap.js.map +1 -1
- package/out/src/storage/schema/entities/User.d.ts.map +1 -1
- package/out/src/storage/schema/entities/User.js +3 -5
- package/out/src/storage/schema/entities/User.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/CertificateFieldTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/CertificateTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/CommissionTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/OutputBasketTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/OutputTagMapTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/OutputTagTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/OutputTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/ProvenTxReqTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/ProvenTxTests.test.js +1 -2
- package/out/src/storage/schema/entities/__tests/ProvenTxTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/SyncStateTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/TransactionTests.test.js +2 -2
- package/out/src/storage/schema/entities/__tests/TransactionTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/TxLabelMapTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/TxLabelTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/stampLogTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/usersTests.test.js.map +1 -1
- package/out/src/storage/schema/tables/TableSettings.d.ts.map +1 -1
- package/out/src/storage/sync/StorageMySQLDojoReader.d.ts.map +1 -1
- package/out/src/storage/sync/StorageMySQLDojoReader.js +1 -3
- package/out/src/storage/sync/StorageMySQLDojoReader.js.map +1 -1
- package/out/src/utility/ScriptTemplateBRC29.d.ts.map +1 -1
- package/out/src/utility/ScriptTemplateBRC29.js +1 -2
- package/out/src/utility/ScriptTemplateBRC29.js.map +1 -1
- package/out/src/utility/stampLog.d.ts.map +1 -1
- package/out/src/utility/stampLog.js.map +1 -1
- package/out/src/utility/tscProofToMerklePath.d.ts.map +1 -1
- package/out/src/utility/tscProofToMerklePath.js.map +1 -1
- package/out/src/utility/utilityHelpers.buffer.d.ts.map +1 -1
- package/out/src/utility/utilityHelpers.buffer.js.map +1 -1
- package/out/src/utility/utilityHelpers.d.ts.map +1 -1
- package/out/src/utility/utilityHelpers.js +1 -3
- package/out/src/utility/utilityHelpers.js.map +1 -1
- package/out/test/Wallet/StorageClient/storageClient.man.test.js.map +1 -1
- package/out/test/Wallet/action/internalizeAction.a.test.js.map +1 -1
- package/out/test/Wallet/certificate/acquireCertificate.test.js.map +1 -1
- package/out/test/Wallet/certificate/listCertificates.test.js.map +1 -1
- package/out/test/Wallet/get/getHeaderForHeight.test.js +2 -6
- package/out/test/Wallet/get/getHeaderForHeight.test.js.map +1 -1
- package/out/test/Wallet/get/getHeight.test.js.map +1 -1
- package/out/test/Wallet/get/getKnownTxids.test.js.map +1 -1
- package/out/test/Wallet/get/getNetwork.test.js.map +1 -1
- package/out/test/Wallet/get/getVersion.test.js.map +1 -1
- package/out/test/Wallet/live/walletLive.man.test.d.ts.map +1 -1
- package/out/test/Wallet/live/walletLive.man.test.js +3 -9
- package/out/test/Wallet/live/walletLive.man.test.js.map +1 -1
- package/out/test/Wallet/local/localWallet.man.test.d.ts.map +1 -1
- package/out/test/Wallet/local/localWallet.man.test.js +39 -31
- package/out/test/Wallet/local/localWallet.man.test.js.map +1 -1
- package/out/test/Wallet/specOps/specOps.man.test.js +1 -4
- package/out/test/Wallet/specOps/specOps.man.test.js.map +1 -1
- package/out/test/Wallet/support/janitor.man.test.js.map +1 -1
- package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.js.map +1 -1
- package/out/test/Wallet/sync/setActive.test.js +73 -50
- package/out/test/Wallet/sync/setActive.test.js.map +1 -1
- package/out/test/checkDB.d.ts.map +1 -1
- package/out/test/checkDB.js.map +1 -1
- package/out/test/examples/backup.man.test.d.ts.map +1 -1
- package/out/test/examples/backup.man.test.js.map +1 -1
- package/out/test/examples/pushdrop.test.d.ts.map +1 -1
- package/out/test/examples/pushdrop.test.js +5 -4
- package/out/test/examples/pushdrop.test.js.map +1 -1
- package/out/test/monitor/Monitor.test.js.map +1 -1
- package/out/test/services/Services.test.js.map +1 -1
- package/out/test/storage/KnexMigrations.test.js.map +1 -1
- package/out/test/storage/StorageMySQLDojoReader.man.test.js +1 -3
- package/out/test/storage/StorageMySQLDojoReader.man.test.js.map +1 -1
- package/out/test/storage/count.test.js.map +1 -1
- package/out/test/storage/find.test.js +5 -10
- package/out/test/storage/find.test.js.map +1 -1
- package/out/test/storage/findLegacy.test.js.map +1 -1
- package/out/test/storage/insert.test.js.map +1 -1
- package/out/test/storage/update.test.js +7 -19
- package/out/test/storage/update.test.js.map +1 -1
- package/out/test/storage/update2.test.js +22 -24
- package/out/test/storage/update2.test.js.map +1 -1
- package/out/test/utils/TestUtilsWalletStorage.d.ts +3 -1
- package/out/test/utils/TestUtilsWalletStorage.d.ts.map +1 -1
- package/out/test/utils/TestUtilsWalletStorage.js +52 -76
- package/out/test/utils/TestUtilsWalletStorage.js.map +1 -1
- package/out/test/wallet/action/abortAction.test.js.map +1 -1
- package/out/test/wallet/action/createAction.test.js +1 -2
- package/out/test/wallet/action/createAction.test.js.map +1 -1
- package/out/test/wallet/action/createAction2.test.d.ts.map +1 -1
- package/out/test/wallet/action/createAction2.test.js +6 -16
- package/out/test/wallet/action/createAction2.test.js.map +1 -1
- package/out/test/wallet/action/createActionToGenerateBeefs.man.test.js.map +1 -1
- package/out/test/wallet/action/internalizeAction.test.js.map +1 -1
- package/out/test/wallet/action/relinquishOutput.test.js.map +1 -1
- package/out/test/wallet/list/listActions.test.js.map +1 -1
- package/out/test/wallet/list/listActions2.test.js.map +1 -1
- package/out/test/wallet/list/listCertificates.test.js +2 -6
- package/out/test/wallet/list/listCertificates.test.js.map +1 -1
- package/out/test/wallet/list/listOutputs.test.js +2 -10
- package/out/test/wallet/list/listOutputs.test.js.map +1 -1
- package/out/test/wallet/sync/Wallet.sync.test.js +4 -6
- package/out/test/wallet/sync/Wallet.sync.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/Setup.ts +15 -52
- package/src/Wallet.ts +58 -161
- package/src/monitor/Monitor.ts +7 -22
- package/src/monitor/MonitorDaemon.ts +6 -23
- package/src/monitor/tasks/TaskCheckForProofs.ts +4 -23
- package/src/monitor/tasks/TaskClock.ts +1 -3
- package/src/monitor/tasks/TaskFailAbandoned.ts +1 -3
- package/src/monitor/tasks/TaskNewHeader.ts +1 -4
- package/src/monitor/tasks/TaskPurge.ts +1 -2
- package/src/monitor/tasks/TaskReviewStatus.ts +1 -3
- package/src/monitor/tasks/TaskSendWaiting.ts +3 -10
- package/src/sdk/CertOps.ts +31 -103
- package/src/sdk/PrivilegedKeyManager.ts +18 -48
- package/src/sdk/WERR_errors.ts +6 -25
- package/src/sdk/WalletError.ts +5 -21
- package/src/sdk/WalletServices.interfaces.ts +11 -33
- package/src/sdk/WalletStorage.interfaces.ts +25 -91
- package/src/sdk/__test/CertificateLifeCycle.test.ts +9 -27
- package/src/sdk/__test/PrivilegedKeyManager.test.ts +29 -66
- package/src/sdk/types.ts +6 -26
- package/src/sdk/validationHelpers.ts +111 -402
- package/src/services/Services.ts +51 -114
- package/src/services/__tests/ARC.test.ts +14 -1
- package/src/services/__tests/bitrails.test.ts +4 -15
- package/src/services/__tests/getMerklePath.test.ts +1 -2
- package/src/services/__tests/getRawTx.test.ts +1 -3
- package/src/services/__tests/verifyBeef.test.ts +2 -1
- package/src/services/chaintracker/ChaintracksChainTracker.ts +3 -13
- package/src/services/chaintracker/chaintracks/BlockHeaderApi.ts +4 -12
- package/src/services/chaintracker/chaintracks/ChaintracksServiceClient.ts +9 -27
- package/src/services/createDefaultWalletServicesOptions.ts +2 -5
- package/src/services/processingErrors/arcSuccessError.json +76 -0
- package/src/services/providers/ARC.ts +6 -25
- package/src/services/providers/Bitails.ts +61 -159
- package/src/services/providers/SdkWhatsOnChain.ts +4 -17
- package/src/services/providers/WhatsOnChain.ts +31 -100
- package/src/services/providers/__tests/WhatsOnChain.test.ts +5 -15
- package/src/services/providers/echangeRates.ts +7 -22
- package/src/signer/WalletSigner.ts +1 -5
- package/src/signer/methods/acquireDirectCertificate.ts +1 -4
- package/src/signer/methods/buildSignableTransaction.ts +5 -20
- package/src/signer/methods/createAction.ts +15 -54
- package/src/signer/methods/internalizeAction.ts +10 -39
- package/src/signer/methods/proveCertificate.ts +2 -5
- package/src/signer/methods/signAction.ts +9 -39
- package/src/storage/StorageKnex.ts +166 -499
- package/src/storage/StorageProvider.ts +75 -291
- package/src/storage/StorageReader.ts +20 -65
- package/src/storage/StorageReaderWriter.ts +67 -264
- package/src/storage/StorageSyncReader.ts +2 -5
- package/src/storage/WalletStorageManager.ts +33 -108
- package/src/storage/__test/WalletStorageManager.test.ts +6 -23
- package/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.ts +53 -171
- package/src/storage/methods/__test/GenerateChange/randomValsUsed1.ts +17 -28
- package/src/storage/methods/attemptToPostReqsToNetwork.ts +9 -37
- package/src/storage/methods/createAction.ts +45 -181
- package/src/storage/methods/generateChange.ts +33 -114
- package/src/storage/methods/getBeefForTransaction.ts +7 -37
- package/src/storage/methods/getSyncChunk.ts +18 -69
- package/src/storage/methods/internalizeAction.ts +18 -70
- package/src/storage/methods/listActions.ts +6 -23
- package/src/storage/methods/listCertificates.ts +5 -14
- package/src/storage/methods/listOutputs.ts +15 -69
- package/src/storage/methods/processAction.ts +29 -104
- package/src/storage/methods/purgeData.ts +11 -45
- package/src/storage/methods/reviewStatus.ts +3 -9
- package/src/storage/remoting/StorageClient.ts +43 -146
- package/src/storage/remoting/StorageServer.ts +21 -59
- package/src/storage/schema/KnexMigrations.ts +34 -165
- package/src/storage/schema/entities/Certificate.ts +3 -14
- package/src/storage/schema/entities/CertificateField.ts +6 -28
- package/src/storage/schema/entities/Commission.ts +6 -23
- package/src/storage/schema/entities/EntityBase.ts +1 -6
- package/src/storage/schema/entities/MergeEntity.ts +14 -21
- package/src/storage/schema/entities/Output.ts +10 -39
- package/src/storage/schema/entities/OutputBasket.ts +4 -16
- package/src/storage/schema/entities/OutputTag.ts +4 -17
- package/src/storage/schema/entities/OutputTagMap.ts +7 -30
- package/src/storage/schema/entities/ProvenTx.ts +16 -57
- package/src/storage/schema/entities/ProvenTxReq.ts +29 -93
- package/src/storage/schema/entities/SyncState.ts +64 -116
- package/src/storage/schema/entities/Transaction.ts +10 -35
- package/src/storage/schema/entities/TxLabel.ts +4 -17
- package/src/storage/schema/entities/TxLabelMap.ts +6 -28
- package/src/storage/schema/entities/User.ts +8 -31
- package/src/storage/schema/entities/__tests/CertificateFieldTests.test.ts +23 -54
- package/src/storage/schema/entities/__tests/CertificateTests.test.ts +26 -59
- package/src/storage/schema/entities/__tests/CommissionTests.test.ts +2 -11
- package/src/storage/schema/entities/__tests/OutputBasketTests.test.ts +2 -10
- package/src/storage/schema/entities/__tests/OutputTagMapTests.test.ts +2 -10
- package/src/storage/schema/entities/__tests/OutputTagTests.test.ts +1 -4
- package/src/storage/schema/entities/__tests/OutputTests.test.ts +3 -14
- package/src/storage/schema/entities/__tests/ProvenTxReqTests.test.ts +4 -16
- package/src/storage/schema/entities/__tests/ProvenTxTests.test.ts +5 -18
- package/src/storage/schema/entities/__tests/SyncStateTests.test.ts +5 -26
- package/src/storage/schema/entities/__tests/TransactionTests.test.ts +12 -48
- package/src/storage/schema/entities/__tests/TxLabelMapTests.test.ts +4 -22
- package/src/storage/schema/entities/__tests/TxLabelTests.test.ts +2 -10
- package/src/storage/schema/entities/__tests/stampLogTests.test.ts +3 -10
- package/src/storage/schema/entities/__tests/usersTests.test.ts +4 -7
- package/src/storage/schema/tables/TableSettings.ts +1 -3
- package/src/storage/sync/StorageMySQLDojoReader.ts +47 -148
- package/src/utility/ScriptTemplateBRC29.ts +2 -11
- package/src/utility/stampLog.ts +2 -6
- package/src/utility/tscProofToMerklePath.ts +1 -4
- package/src/utility/utilityHelpers.buffer.ts +3 -12
- package/src/utility/utilityHelpers.ts +14 -49
- package/test/Wallet/StorageClient/storageClient.man.test.ts +2 -8
- package/test/Wallet/action/internalizeAction.a.test.ts +8 -23
- package/test/Wallet/certificate/acquireCertificate.test.ts +10 -24
- package/test/Wallet/certificate/listCertificates.test.ts +8 -18
- package/test/Wallet/get/getHeaderForHeight.test.ts +4 -15
- package/test/Wallet/get/getHeight.test.ts +2 -6
- package/test/Wallet/get/getKnownTxids.test.ts +1 -5
- package/test/Wallet/get/getNetwork.test.ts +1 -2
- package/test/Wallet/get/getVersion.test.ts +1 -2
- package/test/Wallet/live/walletLive.man.test.ts +14 -41
- package/test/Wallet/local/localWallet.man.test.ts +45 -102
- package/test/Wallet/specOps/specOps.man.test.ts +4 -13
- package/test/Wallet/support/janitor.man.test.ts +2 -7
- package/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.ts +11 -34
- package/test/Wallet/sync/setActive.test.ts +75 -61
- package/test/checkDB.ts +2 -8
- package/test/examples/backup.man.test.ts +2 -9
- package/test/examples/pushdrop.test.ts +7 -20
- package/test/monitor/Monitor.test.ts +33 -87
- package/test/services/Services.test.ts +8 -19
- package/test/storage/KnexMigrations.test.ts +3 -18
- package/test/storage/StorageMySQLDojoReader.man.test.ts +4 -15
- package/test/storage/count.test.ts +7 -24
- package/test/storage/find.test.ts +7 -29
- package/test/storage/findLegacy.test.ts +2 -5
- package/test/storage/insert.test.ts +3 -19
- package/test/storage/update.test.ts +47 -179
- package/test/storage/update2.test.ts +54 -176
- package/test/utils/TestUtilsWalletStorage.ts +139 -372
- package/test/wallet/action/abortAction.test.ts +4 -12
- package/test/wallet/action/createAction.test.ts +4 -14
- package/test/wallet/action/createAction2.test.ts +74 -208
- package/test/wallet/action/createActionToGenerateBeefs.man.test.ts +8 -11
- package/test/wallet/action/internalizeAction.test.ts +20 -72
- package/test/wallet/action/relinquishOutput.test.ts +3 -9
- package/test/wallet/list/listActions.test.ts +2 -9
- package/test/wallet/list/listActions2.test.ts +8 -34
- package/test/wallet/list/listCertificates.test.ts +5 -16
- package/test/wallet/list/listOutputs.test.ts +15 -54
- package/test/wallet/sync/Wallet.sync.test.ts +18 -49
|
@@ -107,11 +107,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
107
107
|
*/
|
|
108
108
|
_storageProviderLocked: boolean = false
|
|
109
109
|
|
|
110
|
-
constructor(
|
|
111
|
-
identityKey: string,
|
|
112
|
-
active?: sdk.WalletStorageProvider,
|
|
113
|
-
backups?: sdk.WalletStorageProvider[]
|
|
114
|
-
) {
|
|
110
|
+
constructor(identityKey: string, active?: sdk.WalletStorageProvider, backups?: sdk.WalletStorageProvider[]) {
|
|
115
111
|
const stores = [...(backups || [])]
|
|
116
112
|
if (active) stores.unshift(active)
|
|
117
113
|
this._stores = stores.map(s => new ManagedStorage(s))
|
|
@@ -137,8 +133,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
137
133
|
get isActiveEnabled(): boolean {
|
|
138
134
|
return (
|
|
139
135
|
this._active !== undefined &&
|
|
140
|
-
this._active.settings!.storageIdentityKey ===
|
|
141
|
-
this._active.user!.activeStorage &&
|
|
136
|
+
this._active.settings!.storageIdentityKey === this._active.user!.activeStorage &&
|
|
142
137
|
this._conflictingActives !== undefined &&
|
|
143
138
|
this._conflictingActives.length === 0
|
|
144
139
|
)
|
|
@@ -169,10 +164,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
169
164
|
this._conflictingActives = []
|
|
170
165
|
|
|
171
166
|
if (this._stores.length < 1)
|
|
172
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
173
|
-
'active',
|
|
174
|
-
'valid. Must add active storage provider to wallet.'
|
|
175
|
-
)
|
|
167
|
+
throw new sdk.WERR_INVALID_PARAMETER('active', 'valid. Must add active storage provider to wallet.')
|
|
176
168
|
|
|
177
169
|
// Initial backups. conflictingActives will be removed.
|
|
178
170
|
const backups: ManagedStorage[] = []
|
|
@@ -287,11 +279,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
287
279
|
|
|
288
280
|
async getActiveForReader(): Promise<sdk.WalletStorageReader> {
|
|
289
281
|
if (!this.isAvailable()) await this.makeAvailable()
|
|
290
|
-
while (
|
|
291
|
-
this._storageProviderLocked ||
|
|
292
|
-
this._syncLocked ||
|
|
293
|
-
(this._isSingleWriter && this._writerCount > 0)
|
|
294
|
-
) {
|
|
282
|
+
while (this._storageProviderLocked || this._syncLocked || (this._isSingleWriter && this._writerCount > 0)) {
|
|
295
283
|
await wait(100)
|
|
296
284
|
}
|
|
297
285
|
this._readerCount++
|
|
@@ -307,11 +295,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
307
295
|
// Set syncLocked which prevents any new storageProvider, readers or writers...
|
|
308
296
|
this._syncLocked = true
|
|
309
297
|
// Wait for any current storageProvider, readers and writers to complete
|
|
310
|
-
while (
|
|
311
|
-
this._storageProviderLocked ||
|
|
312
|
-
this._readerCount > 0 ||
|
|
313
|
-
this._writerCount > 0
|
|
314
|
-
) {
|
|
298
|
+
while (this._storageProviderLocked || this._readerCount > 0 || this._writerCount > 0) {
|
|
315
299
|
await wait(100)
|
|
316
300
|
}
|
|
317
301
|
// Allow the sync to proceed on the active store.
|
|
@@ -339,9 +323,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
339
323
|
return this.getActive() as unknown as StorageProvider
|
|
340
324
|
}
|
|
341
325
|
|
|
342
|
-
async runAsWriter<R>(
|
|
343
|
-
writer: (active: sdk.WalletStorageWriter) => Promise<R>
|
|
344
|
-
): Promise<R> {
|
|
326
|
+
async runAsWriter<R>(writer: (active: sdk.WalletStorageWriter) => Promise<R>): Promise<R> {
|
|
345
327
|
try {
|
|
346
328
|
const active = await this.getActiveForWriter()
|
|
347
329
|
const r = await writer(active)
|
|
@@ -351,9 +333,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
351
333
|
}
|
|
352
334
|
}
|
|
353
335
|
|
|
354
|
-
async runAsReader<R>(
|
|
355
|
-
reader: (active: sdk.WalletStorageReader) => Promise<R>
|
|
356
|
-
): Promise<R> {
|
|
336
|
+
async runAsReader<R>(reader: (active: sdk.WalletStorageReader) => Promise<R>): Promise<R> {
|
|
357
337
|
try {
|
|
358
338
|
const active = await this.getActiveForReader()
|
|
359
339
|
const r = await reader(active)
|
|
@@ -382,9 +362,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
382
362
|
}
|
|
383
363
|
}
|
|
384
364
|
|
|
385
|
-
async runAsStorageProvider<R>(
|
|
386
|
-
sync: (active: StorageProvider) => Promise<R>
|
|
387
|
-
): Promise<R> {
|
|
365
|
+
async runAsStorageProvider<R>(sync: (active: StorageProvider) => Promise<R>): Promise<R> {
|
|
388
366
|
try {
|
|
389
367
|
const active = await this.getActiveForStorageProvider()
|
|
390
368
|
const r = await sync(active)
|
|
@@ -402,9 +380,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
402
380
|
return this.getActive().isStorageProvider()
|
|
403
381
|
}
|
|
404
382
|
|
|
405
|
-
async addWalletStorageProvider(
|
|
406
|
-
provider: sdk.WalletStorageProvider
|
|
407
|
-
): Promise<void> {
|
|
383
|
+
async addWalletStorageProvider(provider: sdk.WalletStorageProvider): Promise<void> {
|
|
408
384
|
await provider.makeAvailable()
|
|
409
385
|
if (this._services) provider.setServices(this._services)
|
|
410
386
|
this._stores.push(new ManagedStorage(provider))
|
|
@@ -417,8 +393,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
417
393
|
for (const store of this._stores) store.storage.setServices(v)
|
|
418
394
|
}
|
|
419
395
|
getServices(): sdk.WalletServices {
|
|
420
|
-
if (!this._services)
|
|
421
|
-
throw new sdk.WERR_INVALID_OPERATION('Must setServices first.')
|
|
396
|
+
if (!this._services) throw new sdk.WERR_INVALID_OPERATION('Must setServices first.')
|
|
422
397
|
return this._services
|
|
423
398
|
}
|
|
424
399
|
|
|
@@ -426,10 +401,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
426
401
|
return this.getActive().getSettings()
|
|
427
402
|
}
|
|
428
403
|
|
|
429
|
-
async migrate(
|
|
430
|
-
storageName: string,
|
|
431
|
-
storageIdentityKey: string
|
|
432
|
-
): Promise<string> {
|
|
404
|
+
async migrate(storageName: string, storageIdentityKey: string): Promise<string> {
|
|
433
405
|
return await this.runAsWriter(async writer => {
|
|
434
406
|
return writer.migrate(storageName, storageIdentityKey)
|
|
435
407
|
})
|
|
@@ -442,9 +414,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
442
414
|
})
|
|
443
415
|
}
|
|
444
416
|
|
|
445
|
-
async findOrInsertUser(
|
|
446
|
-
identityKey: string
|
|
447
|
-
): Promise<{ user: TableUser; isNew: boolean }> {
|
|
417
|
+
async findOrInsertUser(identityKey: string): Promise<{ user: TableUser; isNew: boolean }> {
|
|
448
418
|
const auth = await this.getAuth()
|
|
449
419
|
if (identityKey != auth.identityKey) throw new sdk.WERR_UNAUTHORIZED()
|
|
450
420
|
|
|
@@ -452,9 +422,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
452
422
|
const r = await writer.findOrInsertUser(identityKey)
|
|
453
423
|
|
|
454
424
|
if (auth.userId && auth.userId !== r.user.userId)
|
|
455
|
-
throw new sdk.WERR_INTERNAL(
|
|
456
|
-
'userId may not change for given identityKey'
|
|
457
|
-
)
|
|
425
|
+
throw new sdk.WERR_INTERNAL('userId may not change for given identityKey')
|
|
458
426
|
this._authId.userId = r.user.userId
|
|
459
427
|
return r
|
|
460
428
|
})
|
|
@@ -467,17 +435,13 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
467
435
|
return await writer.abortAction(auth, args)
|
|
468
436
|
})
|
|
469
437
|
}
|
|
470
|
-
async createAction(
|
|
471
|
-
vargs: sdk.ValidCreateActionArgs
|
|
472
|
-
): Promise<sdk.StorageCreateActionResult> {
|
|
438
|
+
async createAction(vargs: sdk.ValidCreateActionArgs): Promise<sdk.StorageCreateActionResult> {
|
|
473
439
|
return await this.runAsWriter(async writer => {
|
|
474
440
|
const auth = await this.getAuth(true)
|
|
475
441
|
return await writer.createAction(auth, vargs)
|
|
476
442
|
})
|
|
477
443
|
}
|
|
478
|
-
async internalizeAction(
|
|
479
|
-
args: InternalizeActionArgs
|
|
480
|
-
): Promise<InternalizeActionResult> {
|
|
444
|
+
async internalizeAction(args: InternalizeActionArgs): Promise<InternalizeActionResult> {
|
|
481
445
|
sdk.validateInternalizeActionArgs(args)
|
|
482
446
|
return await this.runAsWriter(async writer => {
|
|
483
447
|
const auth = await this.getAuth(true)
|
|
@@ -485,9 +449,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
485
449
|
})
|
|
486
450
|
}
|
|
487
451
|
|
|
488
|
-
async relinquishCertificate(
|
|
489
|
-
args: RelinquishCertificateArgs
|
|
490
|
-
): Promise<number> {
|
|
452
|
+
async relinquishCertificate(args: RelinquishCertificateArgs): Promise<number> {
|
|
491
453
|
sdk.validateRelinquishCertificateArgs(args)
|
|
492
454
|
return await this.runAsWriter(async writer => {
|
|
493
455
|
const auth = await this.getAuth(true)
|
|
@@ -502,9 +464,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
502
464
|
})
|
|
503
465
|
}
|
|
504
466
|
|
|
505
|
-
async processAction(
|
|
506
|
-
args: sdk.StorageProcessActionArgs
|
|
507
|
-
): Promise<sdk.StorageProcessActionResults> {
|
|
467
|
+
async processAction(args: sdk.StorageProcessActionArgs): Promise<sdk.StorageProcessActionResults> {
|
|
508
468
|
return await this.runAsWriter(async writer => {
|
|
509
469
|
const auth = await this.getAuth(true)
|
|
510
470
|
return await writer.processAction(auth, args)
|
|
@@ -517,41 +477,31 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
517
477
|
})
|
|
518
478
|
}
|
|
519
479
|
|
|
520
|
-
async listActions(
|
|
521
|
-
vargs: sdk.ValidListActionsArgs
|
|
522
|
-
): Promise<ListActionsResult> {
|
|
480
|
+
async listActions(vargs: sdk.ValidListActionsArgs): Promise<ListActionsResult> {
|
|
523
481
|
const auth = await this.getAuth()
|
|
524
482
|
return await this.runAsReader(async reader => {
|
|
525
483
|
return await reader.listActions(auth, vargs)
|
|
526
484
|
})
|
|
527
485
|
}
|
|
528
|
-
async listCertificates(
|
|
529
|
-
args: sdk.ValidListCertificatesArgs
|
|
530
|
-
): Promise<ListCertificatesResult> {
|
|
486
|
+
async listCertificates(args: sdk.ValidListCertificatesArgs): Promise<ListCertificatesResult> {
|
|
531
487
|
const auth = await this.getAuth()
|
|
532
488
|
return await this.runAsReader(async reader => {
|
|
533
489
|
return await reader.listCertificates(auth, args)
|
|
534
490
|
})
|
|
535
491
|
}
|
|
536
|
-
async listOutputs(
|
|
537
|
-
vargs: sdk.ValidListOutputsArgs
|
|
538
|
-
): Promise<ListOutputsResult> {
|
|
492
|
+
async listOutputs(vargs: sdk.ValidListOutputsArgs): Promise<ListOutputsResult> {
|
|
539
493
|
const auth = await this.getAuth()
|
|
540
494
|
return await this.runAsReader(async reader => {
|
|
541
495
|
return await reader.listOutputs(auth, vargs)
|
|
542
496
|
})
|
|
543
497
|
}
|
|
544
|
-
async findCertificates(
|
|
545
|
-
args: sdk.FindCertificatesArgs
|
|
546
|
-
): Promise<TableCertificateX[]> {
|
|
498
|
+
async findCertificates(args: sdk.FindCertificatesArgs): Promise<TableCertificateX[]> {
|
|
547
499
|
const auth = await this.getAuth()
|
|
548
500
|
return await this.runAsReader(async reader => {
|
|
549
501
|
return await reader.findCertificatesAuth(auth, args)
|
|
550
502
|
})
|
|
551
503
|
}
|
|
552
|
-
async findOutputBaskets(
|
|
553
|
-
args: sdk.FindOutputBasketsArgs
|
|
554
|
-
): Promise<TableOutputBasket[]> {
|
|
504
|
+
async findOutputBaskets(args: sdk.FindOutputBasketsArgs): Promise<TableOutputBasket[]> {
|
|
555
505
|
const auth = await this.getAuth()
|
|
556
506
|
return await this.runAsReader(async reader => {
|
|
557
507
|
return await reader.findOutputBasketsAuth(auth, args)
|
|
@@ -564,9 +514,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
564
514
|
})
|
|
565
515
|
}
|
|
566
516
|
|
|
567
|
-
async findProvenTxReqs(
|
|
568
|
-
args: sdk.FindProvenTxReqsArgs
|
|
569
|
-
): Promise<TableProvenTxReq[]> {
|
|
517
|
+
async findProvenTxReqs(args: sdk.FindProvenTxReqsArgs): Promise<TableProvenTxReq[]> {
|
|
570
518
|
return await this.runAsReader(async reader => {
|
|
571
519
|
return await reader.findProvenTxReqs(args)
|
|
572
520
|
})
|
|
@@ -595,15 +543,8 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
595
543
|
let i = -1
|
|
596
544
|
for (;;) {
|
|
597
545
|
i++
|
|
598
|
-
const ss = await EntitySyncState.fromStorage(
|
|
599
|
-
|
|
600
|
-
identityKey,
|
|
601
|
-
readerSettings
|
|
602
|
-
)
|
|
603
|
-
const args = ss.makeRequestSyncChunkArgs(
|
|
604
|
-
identityKey,
|
|
605
|
-
writerSettings.storageIdentityKey
|
|
606
|
-
)
|
|
546
|
+
const ss = await EntitySyncState.fromStorage(writer, identityKey, readerSettings)
|
|
547
|
+
const args = ss.makeRequestSyncChunkArgs(identityKey, writerSettings.storageIdentityKey)
|
|
607
548
|
const chunk = await reader.getSyncChunk(args)
|
|
608
549
|
if (chunk.user) {
|
|
609
550
|
// Merging state from a reader cannot update activeStorage
|
|
@@ -644,16 +585,10 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
644
585
|
let i = -1
|
|
645
586
|
for (;;) {
|
|
646
587
|
i++
|
|
647
|
-
const ss = await EntitySyncState.fromStorage(
|
|
648
|
-
|
|
649
|
-
identityKey,
|
|
650
|
-
readerSettings
|
|
651
|
-
)
|
|
652
|
-
const args = ss.makeRequestSyncChunkArgs(
|
|
653
|
-
identityKey,
|
|
654
|
-
writerSettings.storageIdentityKey
|
|
655
|
-
)
|
|
588
|
+
const ss = await EntitySyncState.fromStorage(writer, identityKey, readerSettings)
|
|
589
|
+
const args = ss.makeRequestSyncChunkArgs(identityKey, writerSettings.storageIdentityKey)
|
|
656
590
|
const chunk = await reader.getSyncChunk(args)
|
|
591
|
+
log += EntitySyncState.syncChunkSummary(chunk)
|
|
657
592
|
const r = await writer.processSyncChunk(args, chunk)
|
|
658
593
|
inserts += r.inserts
|
|
659
594
|
updates += r.updates
|
|
@@ -690,9 +625,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
690
625
|
if (!this.isAvailable()) await this.makeAvailable()
|
|
691
626
|
|
|
692
627
|
// Confirm a valid storageIdentityKey: must match one of the _stores.
|
|
693
|
-
const newActiveIndex = this._stores.findIndex(
|
|
694
|
-
s => s.settings!.storageIdentityKey === storageIdentityKey
|
|
695
|
-
)
|
|
628
|
+
const newActiveIndex = this._stores.findIndex(s => s.settings!.storageIdentityKey === storageIdentityKey)
|
|
696
629
|
if (newActiveIndex < 0)
|
|
697
630
|
throw new sdk.WERR_INVALID_PARAMETER(
|
|
698
631
|
'storageIdentityKey',
|
|
@@ -722,8 +655,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
722
655
|
// Remove the new active from conflicting actives and
|
|
723
656
|
// set new active as the conflicting active that matches the target `storageIdentityKey`
|
|
724
657
|
this._conflictingActives = this._conflictingActives!.filter(ca => {
|
|
725
|
-
const isNewActive =
|
|
726
|
-
ca.settings!.storageIdentityKey === storageIdentityKey
|
|
658
|
+
const isNewActive = ca.settings!.storageIdentityKey === storageIdentityKey
|
|
727
659
|
return !isNewActive
|
|
728
660
|
})
|
|
729
661
|
|
|
@@ -746,24 +678,17 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
746
678
|
// Push state merged from all merged actives into newActive to all stores other than the now single active.
|
|
747
679
|
// Otherwise,
|
|
748
680
|
// Push state from current active to all other stores.
|
|
749
|
-
const backupSource =
|
|
750
|
-
this._conflictingActives!.length > 0 ? newActive : this._active!
|
|
681
|
+
const backupSource = this._conflictingActives!.length > 0 ? newActive : this._active!
|
|
751
682
|
|
|
752
683
|
// Update the backupSource's user record with the new activeStorage
|
|
753
684
|
// which will propagate to all other stores in the following backup loop.
|
|
754
|
-
await backupSource.storage.setActive(
|
|
755
|
-
{ identityKey, userId: backupSource.user!.userId },
|
|
756
|
-
storageIdentityKey
|
|
757
|
-
)
|
|
685
|
+
await backupSource.storage.setActive({ identityKey, userId: backupSource.user!.userId }, storageIdentityKey)
|
|
758
686
|
|
|
759
687
|
for (const store of this._stores) {
|
|
760
688
|
// Update cached user.activeStorage of all stores
|
|
761
689
|
store.user!.activeStorage = storageIdentityKey
|
|
762
690
|
|
|
763
|
-
if (
|
|
764
|
-
store.settings!.storageIdentityKey !==
|
|
765
|
-
backupSource.settings!.storageIdentityKey
|
|
766
|
-
) {
|
|
691
|
+
if (store.settings!.storageIdentityKey !== backupSource.settings!.storageIdentityKey) {
|
|
767
692
|
// If this store is not the backupSource store push state from backupSource to this store.
|
|
768
693
|
const stwr = await this.syncToWriter(
|
|
769
694
|
{ identityKey, userId: store.user!.userId, isActive: false },
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import * as bsv from '@bsv/sdk'
|
|
2
2
|
import { StorageKnex, wait, WalletStorageManager } from '../..'
|
|
3
|
-
import {
|
|
4
|
-
_tu,
|
|
5
|
-
TestWalletNoSetup
|
|
6
|
-
} from '../../../test/utils/TestUtilsWalletStorage'
|
|
3
|
+
import { _tu, TestWalletNoSetup } from '../../../test/utils/TestUtilsWalletStorage'
|
|
7
4
|
|
|
8
5
|
import * as dotenv from 'dotenv'
|
|
9
6
|
|
|
@@ -15,13 +12,8 @@ describe('WalletStorageManager tests', () => {
|
|
|
15
12
|
const ctxs: TestWalletNoSetup[] = []
|
|
16
13
|
|
|
17
14
|
beforeAll(async () => {
|
|
18
|
-
if (env.runMySQL)
|
|
19
|
-
|
|
20
|
-
await _tu.createLegacyWalletMySQLCopy('walletStorageManagerTestSource')
|
|
21
|
-
)
|
|
22
|
-
ctxs.push(
|
|
23
|
-
await _tu.createLegacyWalletSQLiteCopy('walletStorageManagerTestSource')
|
|
24
|
-
)
|
|
15
|
+
if (env.runMySQL) ctxs.push(await _tu.createLegacyWalletMySQLCopy('walletStorageManagerTestSource'))
|
|
16
|
+
ctxs.push(await _tu.createLegacyWalletSQLiteCopy('walletStorageManagerTestSource'))
|
|
25
17
|
})
|
|
26
18
|
|
|
27
19
|
afterAll(async () => {
|
|
@@ -105,11 +97,7 @@ describe('WalletStorageManager tests', () => {
|
|
|
105
97
|
let log = ''
|
|
106
98
|
for (const r of result) {
|
|
107
99
|
const overlaps = result.filter(
|
|
108
|
-
r2 =>
|
|
109
|
-
r2.i != r.i &&
|
|
110
|
-
(r2.t != 'reader' || r.t != 'reader') &&
|
|
111
|
-
r.start > r2.start &&
|
|
112
|
-
r.start < r2.end
|
|
100
|
+
r2 => r2.i != r.i && (r2.t != 'reader' || r.t != 'reader') && r.start > r2.start && r.start < r2.end
|
|
113
101
|
)
|
|
114
102
|
if (overlaps.length > 0) {
|
|
115
103
|
log += `${r.i} ${r.t} ${r.start} overlaps:\n`
|
|
@@ -196,11 +184,7 @@ describe('WalletStorageManager tests', () => {
|
|
|
196
184
|
let log = ''
|
|
197
185
|
for (const r of result) {
|
|
198
186
|
const overlaps = result.filter(
|
|
199
|
-
r2 =>
|
|
200
|
-
r2.i != r.i &&
|
|
201
|
-
(r2.t != 'reader' || r.t != 'reader') &&
|
|
202
|
-
r.start > r2.start &&
|
|
203
|
-
r.start < r2.end
|
|
187
|
+
r2 => r2.i != r.i && (r2.t != 'reader' || r.t != 'reader') && r.start > r2.start && r.start < r2.end
|
|
204
188
|
)
|
|
205
189
|
if (overlaps.length > 0) {
|
|
206
190
|
log += `${r.i} ${r.t} ${r.start} overlaps:\n`
|
|
@@ -280,8 +264,7 @@ describe('WalletStorageManager tests', () => {
|
|
|
280
264
|
crs1.push(cr)
|
|
281
265
|
}
|
|
282
266
|
let j = 0
|
|
283
|
-
for (let i = 0; i < maxI; i++)
|
|
284
|
-
promises.push(makeWriter2(fred, crs1[j++], i, result))
|
|
267
|
+
for (let i = 0; i < maxI; i++) promises.push(makeWriter2(fred, crs1[j++], i, result))
|
|
285
268
|
await Promise.all(promises)
|
|
286
269
|
expect(result).toBeTruthy()
|
|
287
270
|
}
|