@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,1057 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
|
|
3
|
+
import { Transaction as BsvTransaction, Script } from '@bsv/sdk'
|
|
4
|
+
import { randomValsUsed1 } from './randomValsUsed1'
|
|
5
|
+
import { sdk } from '../../../../index.client'
|
|
6
|
+
import {
|
|
7
|
+
generateChangeSdk,
|
|
8
|
+
GenerateChangeSdkChangeInput,
|
|
9
|
+
generateChangeSdkMakeStorage,
|
|
10
|
+
GenerateChangeSdkParams,
|
|
11
|
+
GenerateChangeSdkResult
|
|
12
|
+
} from '../../generateChange'
|
|
13
|
+
|
|
14
|
+
describe('generateChange tests', () => {
|
|
15
|
+
jest.setTimeout(99999999)
|
|
16
|
+
|
|
17
|
+
test('0 two outputs', async () => {
|
|
18
|
+
const params: GenerateChangeSdkParams = {
|
|
19
|
+
...defParams,
|
|
20
|
+
fixedOutputs: [
|
|
21
|
+
{ satoshis: 1234, lockingScriptLength: 1739091 },
|
|
22
|
+
{ satoshis: 2, lockingScriptLength: 25 }
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
const availableChange: GenerateChangeSdkChangeInput[] = [...defAvailableChange()]
|
|
26
|
+
|
|
27
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
28
|
+
|
|
29
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
30
|
+
expect(JSON.stringify(r)).toBe(
|
|
31
|
+
'{"allocatedChangeInputs":[{"satoshis":6323,"outputId":15005,"spendable":false}],"changeOutputs":[{"satoshis":1608,"lockingScriptLength":25}],"size":1739330,"fee":3479,"satsPerKb":2}'
|
|
32
|
+
)
|
|
33
|
+
expectTransactionSize(params, r)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('0a two outputs exact input', async () => {
|
|
37
|
+
const params: GenerateChangeSdkParams = {
|
|
38
|
+
...defParams,
|
|
39
|
+
fixedOutputs: [
|
|
40
|
+
{ satoshis: 1234, lockingScriptLength: 1739091 },
|
|
41
|
+
{ satoshis: 2, lockingScriptLength: 25 }
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
const availableChange: GenerateChangeSdkChangeInput[] = [...defAvailableChange()]
|
|
45
|
+
availableChange[5].satoshis = 4715
|
|
46
|
+
|
|
47
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
48
|
+
|
|
49
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
50
|
+
expect(JSON.stringify(r)).toBe(
|
|
51
|
+
'{"allocatedChangeInputs":[{"satoshis":4715,"outputId":15027,"spendable":false}],"changeOutputs":[],"size":1739296,"fee":3479,"satsPerKb":2}'
|
|
52
|
+
)
|
|
53
|
+
expectTransactionSize(params, r)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('0b two outputs 666666 200 ', async () => {
|
|
57
|
+
const params: GenerateChangeSdkParams = {
|
|
58
|
+
...defParams,
|
|
59
|
+
fixedOutputs: [
|
|
60
|
+
{ satoshis: 666666, lockingScriptLength: 197 },
|
|
61
|
+
{ satoshis: 200, lockingScriptLength: 25 }
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
const availableChange: GenerateChangeSdkChangeInput[] = [...defAvailableChange()]
|
|
65
|
+
availableChange[5].satoshis = 4715
|
|
66
|
+
|
|
67
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
68
|
+
|
|
69
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
70
|
+
expect(JSON.stringify(r)).toBe(
|
|
71
|
+
'{"allocatedChangeInputs":[{"satoshis":1575097,"outputId":15101,"spendable":false}],"changeOutputs":[{"satoshis":908230,"lockingScriptLength":25}],"size":432,"fee":1,"satsPerKb":2}'
|
|
72
|
+
)
|
|
73
|
+
expectTransactionSize(params, r)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('0c two outputs 666666 200 two change inputs ', async () => {
|
|
77
|
+
const params: GenerateChangeSdkParams = {
|
|
78
|
+
...defParams,
|
|
79
|
+
fixedOutputs: [
|
|
80
|
+
{ satoshis: 666666, lockingScriptLength: 197 },
|
|
81
|
+
{ satoshis: 200, lockingScriptLength: 25 }
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
const availableChange: GenerateChangeSdkChangeInput[] = [
|
|
85
|
+
{ satoshis: 191051, outputId: 14101 },
|
|
86
|
+
{ satoshis: 129470, outputId: 14106 },
|
|
87
|
+
{ satoshis: 273356, outputId: 14110 },
|
|
88
|
+
{ satoshis: 65612, outputId: 14120 },
|
|
89
|
+
{ satoshis: 44778, outputId: 14126 },
|
|
90
|
+
{ satoshis: 58732, outputId: 14141 },
|
|
91
|
+
{ satoshis: 160865, outputId: 14142 },
|
|
92
|
+
{ satoshis: 535280, outputId: 14146 },
|
|
93
|
+
{ satoshis: 1006, outputId: 14177 },
|
|
94
|
+
{ satoshis: 1000, outputId: 14178 }
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
98
|
+
|
|
99
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
100
|
+
expect(JSON.stringify(r)).toBe(
|
|
101
|
+
'{"allocatedChangeInputs":[{"satoshis":535280,"outputId":14146,"spendable":false},{"satoshis":160865,"outputId":14142,"spendable":false}],"changeOutputs":[{"satoshis":29277,"lockingScriptLength":25}],"size":580,"fee":2,"satsPerKb":2}'
|
|
102
|
+
)
|
|
103
|
+
expectTransactionSize(params, r)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('1 two outputs four change outputs', async () => {
|
|
107
|
+
const params: GenerateChangeSdkParams = {
|
|
108
|
+
...defParams,
|
|
109
|
+
fixedOutputs: [
|
|
110
|
+
{ satoshis: 1234, lockingScriptLength: 1739091 },
|
|
111
|
+
{ satoshis: 2, lockingScriptLength: 25 }
|
|
112
|
+
],
|
|
113
|
+
targetNetCount: 4
|
|
114
|
+
}
|
|
115
|
+
const availableChange: GenerateChangeSdkChangeInput[] = [...defAvailableChange()]
|
|
116
|
+
|
|
117
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
118
|
+
|
|
119
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
120
|
+
expect(JSON.stringify(r)).toBe(
|
|
121
|
+
'{"allocatedChangeInputs":[{"satoshis":10735,"outputId":15106,"spendable":false}],"changeOutputs":[{"satoshis":1237,"lockingScriptLength":25},{"satoshis":1334,"lockingScriptLength":25},{"satoshis":1369,"lockingScriptLength":25},{"satoshis":1008,"lockingScriptLength":25},{"satoshis":1072,"lockingScriptLength":25}],"size":1739466,"fee":3479,"satsPerKb":2}'
|
|
122
|
+
)
|
|
123
|
+
expectTransactionSize(params, r)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test('2 WERR_INSUFFICIENT_FUNDS', async () => {
|
|
127
|
+
const params: GenerateChangeSdkParams = {
|
|
128
|
+
...defParams,
|
|
129
|
+
fixedOutputs: [
|
|
130
|
+
{ satoshis: 1234, lockingScriptLength: 1739091 },
|
|
131
|
+
{ satoshis: 2, lockingScriptLength: 25 }
|
|
132
|
+
],
|
|
133
|
+
targetNetCount: 4
|
|
134
|
+
}
|
|
135
|
+
const availableChange: GenerateChangeSdkChangeInput[] = defAvailableChange().slice(1, 4)
|
|
136
|
+
|
|
137
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
138
|
+
|
|
139
|
+
expectToThrowWERR(sdk.WERR_INSUFFICIENT_FUNDS, () =>
|
|
140
|
+
generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
141
|
+
)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
test('2a WERR_INSUFFICIENT_FUNDS no inputs', async () => {
|
|
145
|
+
const params: GenerateChangeSdkParams = {
|
|
146
|
+
...defParams,
|
|
147
|
+
fixedOutputs: [
|
|
148
|
+
{ satoshis: 1234, lockingScriptLength: 1739091 },
|
|
149
|
+
{ satoshis: 2, lockingScriptLength: 25 }
|
|
150
|
+
],
|
|
151
|
+
targetNetCount: 4
|
|
152
|
+
}
|
|
153
|
+
const availableChange: GenerateChangeSdkChangeInput[] = []
|
|
154
|
+
|
|
155
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
156
|
+
|
|
157
|
+
expectToThrowWERR(sdk.WERR_INSUFFICIENT_FUNDS, () =>
|
|
158
|
+
generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
159
|
+
)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test('3 allocate all', async () => {
|
|
163
|
+
const params: GenerateChangeSdkParams = {
|
|
164
|
+
...defParams,
|
|
165
|
+
fixedOutputs: [
|
|
166
|
+
{ satoshis: 1234, lockingScriptLength: 39091 },
|
|
167
|
+
{ satoshis: 2, lockingScriptLength: 25 }
|
|
168
|
+
],
|
|
169
|
+
targetNetCount: 4
|
|
170
|
+
}
|
|
171
|
+
const availableChange: GenerateChangeSdkChangeInput[] = defAvailableChange().slice(1, 4)
|
|
172
|
+
|
|
173
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
174
|
+
|
|
175
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
176
|
+
expect(JSON.stringify(r)).toBe(
|
|
177
|
+
'{"allocatedChangeInputs":[{"satoshis":1004,"outputId":15011,"spendable":false},{"satoshis":1000,"outputId":15017,"spendable":false}],"changeOutputs":[{"satoshis":689,"lockingScriptLength":25}],"size":39476,"fee":79,"satsPerKb":2}'
|
|
178
|
+
)
|
|
179
|
+
expectTransactionSize(params, r)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
test('4 feeModel 5 sat per kb', async () => {
|
|
183
|
+
const params: GenerateChangeSdkParams = {
|
|
184
|
+
...defParams,
|
|
185
|
+
fixedOutputs: [
|
|
186
|
+
{ satoshis: 1234, lockingScriptLength: 39091 },
|
|
187
|
+
{ satoshis: 2, lockingScriptLength: 25 }
|
|
188
|
+
],
|
|
189
|
+
feeModel: { value: 5, model: 'sat/kb' },
|
|
190
|
+
targetNetCount: 4
|
|
191
|
+
}
|
|
192
|
+
const availableChange: GenerateChangeSdkChangeInput[] = defAvailableChange().slice(1, 4)
|
|
193
|
+
|
|
194
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
195
|
+
|
|
196
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
197
|
+
expect(JSON.stringify(r)).toBe(
|
|
198
|
+
'{"allocatedChangeInputs":[{"satoshis":1004,"outputId":15011,"spendable":false},{"satoshis":1000,"outputId":15017,"spendable":false}],"changeOutputs":[{"satoshis":570,"lockingScriptLength":25}],"size":39476,"fee":198,"satsPerKb":5}'
|
|
199
|
+
)
|
|
200
|
+
expectTransactionSize(params, r)
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
test('4a feeModel 1 sat per kb', async () => {
|
|
204
|
+
const params: GenerateChangeSdkParams = {
|
|
205
|
+
...defParams,
|
|
206
|
+
fixedOutputs: [
|
|
207
|
+
{ satoshis: 1234, lockingScriptLength: 39091 },
|
|
208
|
+
{ satoshis: 2, lockingScriptLength: 25 }
|
|
209
|
+
],
|
|
210
|
+
feeModel: { value: 1, model: 'sat/kb' },
|
|
211
|
+
targetNetCount: 4
|
|
212
|
+
}
|
|
213
|
+
const availableChange: GenerateChangeSdkChangeInput[] = defAvailableChange().slice(1, 4)
|
|
214
|
+
|
|
215
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
216
|
+
|
|
217
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
218
|
+
expect(JSON.stringify(r)).toBe(
|
|
219
|
+
'{"allocatedChangeInputs":[{"satoshis":1004,"outputId":15011,"spendable":false},{"satoshis":1000,"outputId":15017,"spendable":false}],"changeOutputs":[{"satoshis":728,"lockingScriptLength":25}],"size":39476,"fee":40,"satsPerKb":1}'
|
|
220
|
+
)
|
|
221
|
+
expectTransactionSize(params, r)
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
test('5 one fixedInput', async () => {
|
|
225
|
+
const params: GenerateChangeSdkParams = {
|
|
226
|
+
...defParams,
|
|
227
|
+
fixedInputs: [{ satoshis: 1234, unlockingScriptLength: 42 }],
|
|
228
|
+
fixedOutputs: [
|
|
229
|
+
{ satoshis: 1234, lockingScriptLength: 1739091 },
|
|
230
|
+
{ satoshis: 2, lockingScriptLength: 25 }
|
|
231
|
+
],
|
|
232
|
+
targetNetCount: 4
|
|
233
|
+
}
|
|
234
|
+
const availableChange: GenerateChangeSdkChangeInput[] = [...defAvailableChange()]
|
|
235
|
+
|
|
236
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
237
|
+
|
|
238
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
239
|
+
expect(JSON.stringify(r)).toBe(
|
|
240
|
+
'{"allocatedChangeInputs":[{"satoshis":10735,"outputId":15106,"spendable":false}],"changeOutputs":[{"satoshis":1526,"lockingScriptLength":25},{"satoshis":1738,"lockingScriptLength":25},{"satoshis":1816,"lockingScriptLength":25},{"satoshis":1016,"lockingScriptLength":25},{"satoshis":1157,"lockingScriptLength":25}],"size":1739549,"fee":3480,"satsPerKb":2}'
|
|
241
|
+
)
|
|
242
|
+
expectTransactionSize(params, r)
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
test('5a one larger fixedInput', async () => {
|
|
246
|
+
const params: GenerateChangeSdkParams = {
|
|
247
|
+
...defParams,
|
|
248
|
+
fixedInputs: [{ satoshis: 1234, unlockingScriptLength: 242 }],
|
|
249
|
+
fixedOutputs: [
|
|
250
|
+
{ satoshis: 1234, lockingScriptLength: 1739091 },
|
|
251
|
+
{ satoshis: 2, lockingScriptLength: 25 }
|
|
252
|
+
],
|
|
253
|
+
targetNetCount: 4
|
|
254
|
+
}
|
|
255
|
+
const availableChange: GenerateChangeSdkChangeInput[] = [...defAvailableChange()]
|
|
256
|
+
|
|
257
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
258
|
+
|
|
259
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
260
|
+
expect(JSON.stringify(r)).toBe(
|
|
261
|
+
'{"allocatedChangeInputs":[{"satoshis":10735,"outputId":15106,"spendable":false}],"changeOutputs":[{"satoshis":1526,"lockingScriptLength":25},{"satoshis":1738,"lockingScriptLength":25},{"satoshis":1816,"lockingScriptLength":25},{"satoshis":1016,"lockingScriptLength":25},{"satoshis":1157,"lockingScriptLength":25}],"size":1739749,"fee":3480,"satsPerKb":2}'
|
|
262
|
+
)
|
|
263
|
+
expectTransactionSize(params, r)
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
test('5b one fixedInput 1001 73', async () => {
|
|
267
|
+
const params: GenerateChangeSdkParams = {
|
|
268
|
+
...defParams,
|
|
269
|
+
fixedInputs: [{ satoshis: 1001, unlockingScriptLength: 73 }]
|
|
270
|
+
}
|
|
271
|
+
const availableChange: GenerateChangeSdkChangeInput[] = [...defAvailableChange()]
|
|
272
|
+
|
|
273
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
274
|
+
|
|
275
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
276
|
+
expect(JSON.stringify(r)).toBe(
|
|
277
|
+
'{"allocatedChangeInputs":[],"changeOutputs":[{"satoshis":1000,"lockingScriptLength":25}],"size":158,"fee":1,"satsPerKb":2}'
|
|
278
|
+
)
|
|
279
|
+
expectTransactionSize(params, r)
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
test('6 no fixedOutputs one fixedInput', async () => {
|
|
283
|
+
const params: GenerateChangeSdkParams = {
|
|
284
|
+
...defParams,
|
|
285
|
+
fixedInputs: [{ satoshis: 1234, unlockingScriptLength: 42 }],
|
|
286
|
+
fixedOutputs: [],
|
|
287
|
+
targetNetCount: 4
|
|
288
|
+
}
|
|
289
|
+
const availableChange: GenerateChangeSdkChangeInput[] = [...defAvailableChange()]
|
|
290
|
+
|
|
291
|
+
const { allocateChangeInput, releaseChangeInput, getLog } = generateChangeSdkMakeStorage(availableChange)
|
|
292
|
+
|
|
293
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
294
|
+
//console.log(getLog())
|
|
295
|
+
expect(JSON.stringify(r)).toBe(
|
|
296
|
+
'{"allocatedChangeInputs":[{"satoshis":6323,"outputId":15005,"spendable":false}],"changeOutputs":[{"satoshis":1597,"lockingScriptLength":25},{"satoshis":1837,"lockingScriptLength":25},{"satoshis":1925,"lockingScriptLength":25},{"satoshis":1019,"lockingScriptLength":25},{"satoshis":1178,"lockingScriptLength":25}],"size":411,"fee":1,"satsPerKb":2}'
|
|
297
|
+
)
|
|
298
|
+
expectTransactionSize(params, r)
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
test('6a no fixedOutputs no fixedInput', async () => {
|
|
302
|
+
const params: GenerateChangeSdkParams = {
|
|
303
|
+
...defParams,
|
|
304
|
+
fixedInputs: [],
|
|
305
|
+
fixedOutputs: [],
|
|
306
|
+
targetNetCount: 4
|
|
307
|
+
}
|
|
308
|
+
const availableChange: GenerateChangeSdkChangeInput[] = [...defAvailableChange()]
|
|
309
|
+
|
|
310
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
311
|
+
|
|
312
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
313
|
+
expect(JSON.stringify(r)).toBe(
|
|
314
|
+
'{"allocatedChangeInputs":[{"satoshis":6323,"outputId":15005,"spendable":false}],"changeOutputs":[{"satoshis":1309,"lockingScriptLength":25},{"satoshis":1433,"lockingScriptLength":25},{"satoshis":1478,"lockingScriptLength":25},{"satoshis":1009,"lockingScriptLength":25},{"satoshis":1093,"lockingScriptLength":25}],"size":328,"fee":1,"satsPerKb":2}'
|
|
315
|
+
)
|
|
316
|
+
expectTransactionSize(params, r)
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
test('7 paramsText4 d4', async () => {
|
|
320
|
+
const params: GenerateChangeSdkParams = {
|
|
321
|
+
...defParams,
|
|
322
|
+
fixedOutputs: [
|
|
323
|
+
{ satoshis: 309000, lockingScriptLength: 198 },
|
|
324
|
+
{ satoshis: 2, lockingScriptLength: 25 }
|
|
325
|
+
]
|
|
326
|
+
}
|
|
327
|
+
const availableChange: GenerateChangeSdkChangeInput[] = [
|
|
328
|
+
{ satoshis: 7130, outputId: 15142 },
|
|
329
|
+
{ satoshis: 474866, outputId: 15332 },
|
|
330
|
+
{ satoshis: 16411, outputId: 15355 },
|
|
331
|
+
{ satoshis: 763632, outputId: 15368 },
|
|
332
|
+
{ satoshis: 18894, outputId: 15371 },
|
|
333
|
+
{ satoshis: 1574590, outputId: 15420 },
|
|
334
|
+
{ satoshis: 43207, outputId: 15480 },
|
|
335
|
+
{ satoshis: 12342, outputId: 15541 },
|
|
336
|
+
{ satoshis: 123453, outputId: 15548 },
|
|
337
|
+
{ satoshis: 7890, outputId: 16020 },
|
|
338
|
+
{ satoshis: 1073, outputId: 16026 }
|
|
339
|
+
]
|
|
340
|
+
|
|
341
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
342
|
+
|
|
343
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
344
|
+
expect(JSON.stringify(r)).toBe(
|
|
345
|
+
'{"allocatedChangeInputs":[{"satoshis":474866,"outputId":15332,"spendable":false}],"changeOutputs":[{"satoshis":165863,"lockingScriptLength":25}],"size":433,"fee":1,"satsPerKb":2}'
|
|
346
|
+
)
|
|
347
|
+
expectTransactionSize(params, r)
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
interface TestCase {
|
|
351
|
+
p: GenerateChangeSdkParams
|
|
352
|
+
availableChange: GenerateChangeSdkChangeInput[]
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const d5: TestCase = {
|
|
356
|
+
p: {
|
|
357
|
+
fixedInputs: [{ satoshis: 1000, unlockingScriptLength: 72 }],
|
|
358
|
+
fixedOutputs: [{ satoshis: 200, lockingScriptLength: 25 }],
|
|
359
|
+
feeModel: { model: 'sat/kb', value: 2 },
|
|
360
|
+
changeInitialSatoshis: 1000,
|
|
361
|
+
changeFirstSatoshis: 285,
|
|
362
|
+
changeLockingScriptLength: 25,
|
|
363
|
+
changeUnlockingScriptLength: 107
|
|
364
|
+
},
|
|
365
|
+
availableChange: [
|
|
366
|
+
{ satoshis: 191051, outputId: 14101 },
|
|
367
|
+
{ satoshis: 273356, outputId: 14110 },
|
|
368
|
+
{ satoshis: 65612, outputId: 14120 },
|
|
369
|
+
{ satoshis: 44778, outputId: 14126 },
|
|
370
|
+
{ satoshis: 58732, outputId: 14141 },
|
|
371
|
+
{ satoshis: 160865, outputId: 14142 },
|
|
372
|
+
{ satoshis: 1006, outputId: 14177 },
|
|
373
|
+
{ satoshis: 1000, outputId: 14178 },
|
|
374
|
+
{ satoshis: 1000, outputId: 14180 },
|
|
375
|
+
{ satoshis: 1000, outputId: 14181 },
|
|
376
|
+
{ satoshis: 1000, outputId: 14183 },
|
|
377
|
+
{ satoshis: 1000, outputId: 14185 },
|
|
378
|
+
{ satoshis: 1000, outputId: 14186 },
|
|
379
|
+
{ satoshis: 1001, outputId: 14188 },
|
|
380
|
+
{ satoshis: 1000, outputId: 14189 },
|
|
381
|
+
{ satoshis: 1000, outputId: 14190 },
|
|
382
|
+
{ satoshis: 1001, outputId: 14192 },
|
|
383
|
+
{ satoshis: 1000, outputId: 14195 },
|
|
384
|
+
{ satoshis: 1000, outputId: 14196 },
|
|
385
|
+
{ satoshis: 1000, outputId: 14197 },
|
|
386
|
+
{ satoshis: 1000, outputId: 14198 },
|
|
387
|
+
{ satoshis: 1000, outputId: 14199 },
|
|
388
|
+
{ satoshis: 1000, outputId: 14200 },
|
|
389
|
+
{ satoshis: 1000, outputId: 14201 },
|
|
390
|
+
{ satoshis: 1000, outputId: 14202 },
|
|
391
|
+
{ satoshis: 1000, outputId: 14203 },
|
|
392
|
+
{ satoshis: 1000, outputId: 14204 },
|
|
393
|
+
{ satoshis: 1000, outputId: 14205 },
|
|
394
|
+
{ satoshis: 1000, outputId: 14206 },
|
|
395
|
+
{ satoshis: 1003, outputId: 14207 },
|
|
396
|
+
{ satoshis: 1001, outputId: 14208 },
|
|
397
|
+
{ satoshis: 1000, outputId: 14209 },
|
|
398
|
+
{ satoshis: 1000, outputId: 14210 },
|
|
399
|
+
{ satoshis: 1006, outputId: 14211 },
|
|
400
|
+
{ satoshis: 1020, outputId: 14212 },
|
|
401
|
+
{ satoshis: 1000, outputId: 14213 },
|
|
402
|
+
{ satoshis: 1000, outputId: 14214 },
|
|
403
|
+
{ satoshis: 1000, outputId: 14215 },
|
|
404
|
+
{ satoshis: 1000, outputId: 14216 },
|
|
405
|
+
{ satoshis: 1002, outputId: 14217 },
|
|
406
|
+
{ satoshis: 1046, outputId: 14218 },
|
|
407
|
+
{ satoshis: 1103, outputId: 14219 },
|
|
408
|
+
{ satoshis: 1001, outputId: 14221 },
|
|
409
|
+
{ satoshis: 1000, outputId: 14222 },
|
|
410
|
+
{ satoshis: 1000, outputId: 14223 },
|
|
411
|
+
{ satoshis: 1000, outputId: 14224 },
|
|
412
|
+
{ satoshis: 31311, outputId: 14321 },
|
|
413
|
+
{ satoshis: 1042, outputId: 14656 },
|
|
414
|
+
{ satoshis: 1099, outputId: 14661 },
|
|
415
|
+
{ satoshis: 1100, outputId: 14675 },
|
|
416
|
+
{ satoshis: 1019, outputId: 14676 },
|
|
417
|
+
{ satoshis: 1040, outputId: 14677 },
|
|
418
|
+
{ satoshis: 1000, outputId: 14679 },
|
|
419
|
+
{ satoshis: 1000, outputId: 14680 },
|
|
420
|
+
{ satoshis: 1001, outputId: 14681 },
|
|
421
|
+
{ satoshis: 1000, outputId: 14682 },
|
|
422
|
+
{ satoshis: 1001, outputId: 14683 },
|
|
423
|
+
{ satoshis: 1002, outputId: 14684 },
|
|
424
|
+
{ satoshis: 1005, outputId: 14685 },
|
|
425
|
+
{ satoshis: 1000, outputId: 14686 },
|
|
426
|
+
{ satoshis: 1007, outputId: 14687 },
|
|
427
|
+
{ satoshis: 1000, outputId: 14802 },
|
|
428
|
+
{ satoshis: 1069, outputId: 14803 },
|
|
429
|
+
{ satoshis: 1231, outputId: 15465 },
|
|
430
|
+
{ satoshis: 2386, outputId: 15468 },
|
|
431
|
+
{ satoshis: 1267, outputId: 15471 },
|
|
432
|
+
{ satoshis: 1283, outputId: 15472 },
|
|
433
|
+
{ satoshis: 1054, outputId: 15473 },
|
|
434
|
+
{ satoshis: 2031, outputId: 15475 },
|
|
435
|
+
{ satoshis: 1065, outputId: 15478 },
|
|
436
|
+
{ satoshis: 1268, outputId: 15479 },
|
|
437
|
+
{ satoshis: 1066, outputId: 15480 },
|
|
438
|
+
{ satoshis: 1065, outputId: 15481 },
|
|
439
|
+
{ satoshis: 1006, outputId: 15482 },
|
|
440
|
+
{ satoshis: 999799, outputId: 16338 },
|
|
441
|
+
{ satoshis: 2021, outputId: 16339 },
|
|
442
|
+
{ satoshis: 666465, outputId: 16340 },
|
|
443
|
+
{ satoshis: 5354, outputId: 16341 },
|
|
444
|
+
{ satoshis: 3132, outputId: 16342 }
|
|
445
|
+
]
|
|
446
|
+
}
|
|
447
|
+
const d6: TestCase = {
|
|
448
|
+
p: {
|
|
449
|
+
fixedInputs: [],
|
|
450
|
+
fixedOutputs: [
|
|
451
|
+
{ satoshis: 500, lockingScriptLength: 436 },
|
|
452
|
+
{ satoshis: 200, lockingScriptLength: 25 }
|
|
453
|
+
],
|
|
454
|
+
feeModel: { model: 'sat/kb', value: 2 },
|
|
455
|
+
changeInitialSatoshis: 1000,
|
|
456
|
+
changeFirstSatoshis: 285,
|
|
457
|
+
changeLockingScriptLength: 25,
|
|
458
|
+
changeUnlockingScriptLength: 107
|
|
459
|
+
},
|
|
460
|
+
availableChange: [
|
|
461
|
+
{ satoshis: 1040, outputId: 16345 },
|
|
462
|
+
{ satoshis: 1000, outputId: 16346 },
|
|
463
|
+
{ satoshis: 1023, outputId: 16348 },
|
|
464
|
+
{ satoshis: 1054, outputId: 16350 },
|
|
465
|
+
{ satoshis: 1118, outputId: 16353 },
|
|
466
|
+
{ satoshis: 1000, outputId: 16354 },
|
|
467
|
+
{ satoshis: 1001, outputId: 16355 },
|
|
468
|
+
{ satoshis: 1000, outputId: 16356 },
|
|
469
|
+
{ satoshis: 1005, outputId: 16360 },
|
|
470
|
+
{ satoshis: 1000, outputId: 16361 },
|
|
471
|
+
{ satoshis: 375235, outputId: 16362 },
|
|
472
|
+
{ satoshis: 1000, outputId: 16363 },
|
|
473
|
+
{ satoshis: 1000, outputId: 16364 },
|
|
474
|
+
{ satoshis: 45658, outputId: 16365 },
|
|
475
|
+
{ satoshis: 286834, outputId: 16367 },
|
|
476
|
+
{ satoshis: 1001, outputId: 16368 },
|
|
477
|
+
{ satoshis: 1001, outputId: 16369 },
|
|
478
|
+
{ satoshis: 57051, outputId: 16370 },
|
|
479
|
+
{ satoshis: 1036, outputId: 16371 },
|
|
480
|
+
{ satoshis: 16508, outputId: 16372 },
|
|
481
|
+
{ satoshis: 1000, outputId: 16373 },
|
|
482
|
+
{ satoshis: 64213, outputId: 16374 },
|
|
483
|
+
{ satoshis: 1000, outputId: 16376 },
|
|
484
|
+
{ satoshis: 1000, outputId: 16377 },
|
|
485
|
+
{ satoshis: 1154, outputId: 16378 },
|
|
486
|
+
{ satoshis: 1000, outputId: 16380 },
|
|
487
|
+
{ satoshis: 1008, outputId: 16381 },
|
|
488
|
+
{ satoshis: 1064, outputId: 16382 },
|
|
489
|
+
{ satoshis: 1234, outputId: 16383 },
|
|
490
|
+
{ satoshis: 119205, outputId: 16395 },
|
|
491
|
+
{ satoshis: 582, outputId: 16397 },
|
|
492
|
+
{ satoshis: 2384, outputId: 16399 },
|
|
493
|
+
{ satoshis: 4391, outputId: 16401 },
|
|
494
|
+
{ satoshis: 600, outputId: 16406 },
|
|
495
|
+
{ satoshis: 2599799, outputId: 16407 }
|
|
496
|
+
]
|
|
497
|
+
}
|
|
498
|
+
const d7: TestCase = {
|
|
499
|
+
p: {
|
|
500
|
+
fixedInputs: [],
|
|
501
|
+
fixedOutputs: [
|
|
502
|
+
{ satoshis: 1570, lockingScriptLength: 25 },
|
|
503
|
+
{ satoshis: 200, lockingScriptLength: 25 }
|
|
504
|
+
],
|
|
505
|
+
feeModel: { model: 'sat/kb', value: 2 },
|
|
506
|
+
changeInitialSatoshis: 1000,
|
|
507
|
+
changeFirstSatoshis: 285,
|
|
508
|
+
changeLockingScriptLength: 25,
|
|
509
|
+
changeUnlockingScriptLength: 107
|
|
510
|
+
},
|
|
511
|
+
availableChange: [
|
|
512
|
+
{ satoshis: 23082, outputId: 14734 },
|
|
513
|
+
{ satoshis: 16496, outputId: 14742 },
|
|
514
|
+
{ satoshis: 270789, outputId: 14744 },
|
|
515
|
+
{ satoshis: 81520, outputId: 14763 },
|
|
516
|
+
{ satoshis: 14759, outputId: 14770 },
|
|
517
|
+
{ satoshis: 390625, outputId: 14774 },
|
|
518
|
+
{ satoshis: 674234, outputId: 14790 },
|
|
519
|
+
{ satoshis: 999799, outputId: 14794 },
|
|
520
|
+
{ satoshis: 1000, outputId: 15583 },
|
|
521
|
+
{ satoshis: 1000, outputId: 15584 },
|
|
522
|
+
{ satoshis: 1000, outputId: 15585 },
|
|
523
|
+
{ satoshis: 1000, outputId: 15586 },
|
|
524
|
+
{ satoshis: 1000, outputId: 15587 },
|
|
525
|
+
{ satoshis: 1000, outputId: 15588 },
|
|
526
|
+
{ satoshis: 1025, outputId: 15589 },
|
|
527
|
+
{ satoshis: 1000, outputId: 15590 },
|
|
528
|
+
{ satoshis: 1000, outputId: 15591 },
|
|
529
|
+
{ satoshis: 1000, outputId: 15593 },
|
|
530
|
+
{ satoshis: 1000, outputId: 15594 },
|
|
531
|
+
{ satoshis: 1000, outputId: 15595 },
|
|
532
|
+
{ satoshis: 1000, outputId: 15596 },
|
|
533
|
+
{ satoshis: 1000, outputId: 15597 },
|
|
534
|
+
{ satoshis: 1316, outputId: 15598 },
|
|
535
|
+
{ satoshis: 1000, outputId: 15599 },
|
|
536
|
+
{ satoshis: 1000, outputId: 15600 },
|
|
537
|
+
{ satoshis: 1000, outputId: 15601 },
|
|
538
|
+
{ satoshis: 1426, outputId: 15602 },
|
|
539
|
+
{ satoshis: 1000, outputId: 15603 },
|
|
540
|
+
{ satoshis: 1000, outputId: 15604 },
|
|
541
|
+
{ satoshis: 1000, outputId: 15605 },
|
|
542
|
+
{ satoshis: 1000, outputId: 15606 },
|
|
543
|
+
{ satoshis: 1000, outputId: 15607 },
|
|
544
|
+
{ satoshis: 1000, outputId: 15608 },
|
|
545
|
+
{ satoshis: 1000, outputId: 15609 },
|
|
546
|
+
{ satoshis: 1004, outputId: 15610 },
|
|
547
|
+
{ satoshis: 1000, outputId: 15611 },
|
|
548
|
+
{ satoshis: 1013, outputId: 15612 },
|
|
549
|
+
{ satoshis: 1001, outputId: 15614 },
|
|
550
|
+
{ satoshis: 1000, outputId: 15615 },
|
|
551
|
+
{ satoshis: 1000, outputId: 15616 },
|
|
552
|
+
{ satoshis: 1000, outputId: 15617 },
|
|
553
|
+
{ satoshis: 1000, outputId: 15618 },
|
|
554
|
+
{ satoshis: 1000, outputId: 15619 },
|
|
555
|
+
{ satoshis: 1006, outputId: 15620 },
|
|
556
|
+
{ satoshis: 1000, outputId: 15621 },
|
|
557
|
+
{ satoshis: 1000, outputId: 15622 },
|
|
558
|
+
{ satoshis: 1000, outputId: 15623 },
|
|
559
|
+
{ satoshis: 1000, outputId: 15624 },
|
|
560
|
+
{ satoshis: 1032, outputId: 15625 },
|
|
561
|
+
{ satoshis: 4571, outputId: 15626 },
|
|
562
|
+
{ satoshis: 1000, outputId: 15628 },
|
|
563
|
+
{ satoshis: 1000, outputId: 15629 },
|
|
564
|
+
{ satoshis: 1087, outputId: 15630 },
|
|
565
|
+
{ satoshis: 1000, outputId: 15631 },
|
|
566
|
+
{ satoshis: 1000, outputId: 15632 },
|
|
567
|
+
{ satoshis: 1001, outputId: 15633 },
|
|
568
|
+
{ satoshis: 1001, outputId: 15634 },
|
|
569
|
+
{ satoshis: 1000, outputId: 15635 },
|
|
570
|
+
{ satoshis: 1000, outputId: 15637 },
|
|
571
|
+
{ satoshis: 1001, outputId: 15638 },
|
|
572
|
+
{ satoshis: 1000, outputId: 15639 },
|
|
573
|
+
{ satoshis: 1000, outputId: 15640 },
|
|
574
|
+
{ satoshis: 1000, outputId: 15641 },
|
|
575
|
+
{ satoshis: 1000, outputId: 15642 },
|
|
576
|
+
{ satoshis: 1000, outputId: 15643 },
|
|
577
|
+
{ satoshis: 1036, outputId: 15644 },
|
|
578
|
+
{ satoshis: 1000, outputId: 15645 },
|
|
579
|
+
{ satoshis: 1000, outputId: 15646 },
|
|
580
|
+
{ satoshis: 1000, outputId: 15647 },
|
|
581
|
+
{ satoshis: 1000, outputId: 15648 },
|
|
582
|
+
{ satoshis: 1001, outputId: 15649 },
|
|
583
|
+
{ satoshis: 1000, outputId: 15650 },
|
|
584
|
+
{ satoshis: 1050, outputId: 15651 },
|
|
585
|
+
{ satoshis: 1273, outputId: 15653 },
|
|
586
|
+
{ satoshis: 1029, outputId: 15654 },
|
|
587
|
+
{ satoshis: 1524, outputId: 15655 },
|
|
588
|
+
{ satoshis: 1817, outputId: 15658 },
|
|
589
|
+
{ satoshis: 1041, outputId: 16409 }
|
|
590
|
+
]
|
|
591
|
+
}
|
|
592
|
+
const d8: TestCase = {
|
|
593
|
+
p: {
|
|
594
|
+
fixedInputs: [],
|
|
595
|
+
fixedOutputs: [
|
|
596
|
+
{ satoshis: 1564, lockingScriptLength: 25 },
|
|
597
|
+
{ satoshis: 200, lockingScriptLength: 25 }
|
|
598
|
+
],
|
|
599
|
+
feeModel: { model: 'sat/kb', value: 2 },
|
|
600
|
+
changeInitialSatoshis: 1000,
|
|
601
|
+
changeFirstSatoshis: 285,
|
|
602
|
+
changeLockingScriptLength: 25,
|
|
603
|
+
changeUnlockingScriptLength: 107
|
|
604
|
+
},
|
|
605
|
+
availableChange: [
|
|
606
|
+
{ satoshis: 23082, outputId: 14734 },
|
|
607
|
+
{ satoshis: 16496, outputId: 14742 },
|
|
608
|
+
{ satoshis: 270789, outputId: 14744 },
|
|
609
|
+
{ satoshis: 81520, outputId: 14763 },
|
|
610
|
+
{ satoshis: 14759, outputId: 14770 },
|
|
611
|
+
{ satoshis: 390625, outputId: 14774 },
|
|
612
|
+
{ satoshis: 674234, outputId: 14790 },
|
|
613
|
+
{ satoshis: 999799, outputId: 14794 },
|
|
614
|
+
{ satoshis: 1000, outputId: 15583 },
|
|
615
|
+
{ satoshis: 1000, outputId: 15584 },
|
|
616
|
+
{ satoshis: 1000, outputId: 15585 },
|
|
617
|
+
{ satoshis: 1000, outputId: 15586 },
|
|
618
|
+
{ satoshis: 1000, outputId: 15587 },
|
|
619
|
+
{ satoshis: 1000, outputId: 15588 },
|
|
620
|
+
{ satoshis: 1025, outputId: 15589 },
|
|
621
|
+
{ satoshis: 1000, outputId: 15590 },
|
|
622
|
+
{ satoshis: 1000, outputId: 15591 },
|
|
623
|
+
{ satoshis: 1000, outputId: 15593 },
|
|
624
|
+
{ satoshis: 1000, outputId: 15594 },
|
|
625
|
+
{ satoshis: 1000, outputId: 15595 },
|
|
626
|
+
{ satoshis: 1000, outputId: 15596 },
|
|
627
|
+
{ satoshis: 1000, outputId: 15597 },
|
|
628
|
+
{ satoshis: 1316, outputId: 15598 },
|
|
629
|
+
{ satoshis: 1000, outputId: 15599 },
|
|
630
|
+
{ satoshis: 1000, outputId: 15600 },
|
|
631
|
+
{ satoshis: 1000, outputId: 15601 },
|
|
632
|
+
{ satoshis: 1426, outputId: 15602 },
|
|
633
|
+
{ satoshis: 1000, outputId: 15603 },
|
|
634
|
+
{ satoshis: 1000, outputId: 15604 },
|
|
635
|
+
{ satoshis: 1000, outputId: 15605 },
|
|
636
|
+
{ satoshis: 1000, outputId: 15606 },
|
|
637
|
+
{ satoshis: 1000, outputId: 15607 },
|
|
638
|
+
{ satoshis: 1000, outputId: 15608 },
|
|
639
|
+
{ satoshis: 1000, outputId: 15609 },
|
|
640
|
+
{ satoshis: 1004, outputId: 15610 },
|
|
641
|
+
{ satoshis: 1000, outputId: 15611 },
|
|
642
|
+
{ satoshis: 1013, outputId: 15612 },
|
|
643
|
+
{ satoshis: 1001, outputId: 15614 },
|
|
644
|
+
{ satoshis: 1000, outputId: 15615 },
|
|
645
|
+
{ satoshis: 1000, outputId: 15616 },
|
|
646
|
+
{ satoshis: 1000, outputId: 15617 },
|
|
647
|
+
{ satoshis: 1000, outputId: 15618 },
|
|
648
|
+
{ satoshis: 1000, outputId: 15619 },
|
|
649
|
+
{ satoshis: 1006, outputId: 15620 },
|
|
650
|
+
{ satoshis: 1000, outputId: 15621 },
|
|
651
|
+
{ satoshis: 1000, outputId: 15622 },
|
|
652
|
+
{ satoshis: 1000, outputId: 15623 },
|
|
653
|
+
{ satoshis: 1000, outputId: 15624 },
|
|
654
|
+
{ satoshis: 1032, outputId: 15625 },
|
|
655
|
+
{ satoshis: 4571, outputId: 15626 },
|
|
656
|
+
{ satoshis: 1000, outputId: 15628 },
|
|
657
|
+
{ satoshis: 1000, outputId: 15629 },
|
|
658
|
+
{ satoshis: 1087, outputId: 15630 },
|
|
659
|
+
{ satoshis: 1000, outputId: 15631 },
|
|
660
|
+
{ satoshis: 1000, outputId: 15632 },
|
|
661
|
+
{ satoshis: 1001, outputId: 15633 },
|
|
662
|
+
{ satoshis: 1001, outputId: 15634 },
|
|
663
|
+
{ satoshis: 1000, outputId: 15635 },
|
|
664
|
+
{ satoshis: 1000, outputId: 15637 },
|
|
665
|
+
{ satoshis: 1001, outputId: 15638 },
|
|
666
|
+
{ satoshis: 1000, outputId: 15639 },
|
|
667
|
+
{ satoshis: 1000, outputId: 15640 },
|
|
668
|
+
{ satoshis: 1000, outputId: 15641 },
|
|
669
|
+
{ satoshis: 1000, outputId: 15642 },
|
|
670
|
+
{ satoshis: 1000, outputId: 15643 },
|
|
671
|
+
{ satoshis: 1036, outputId: 15644 },
|
|
672
|
+
{ satoshis: 1000, outputId: 15645 },
|
|
673
|
+
{ satoshis: 1000, outputId: 15646 },
|
|
674
|
+
{ satoshis: 1000, outputId: 15647 },
|
|
675
|
+
{ satoshis: 1000, outputId: 15648 },
|
|
676
|
+
{ satoshis: 1001, outputId: 15649 },
|
|
677
|
+
{ satoshis: 1000, outputId: 15650 },
|
|
678
|
+
{ satoshis: 1050, outputId: 15651 },
|
|
679
|
+
{ satoshis: 1273, outputId: 15653 },
|
|
680
|
+
{ satoshis: 1029, outputId: 15654 },
|
|
681
|
+
{ satoshis: 1524, outputId: 15655 },
|
|
682
|
+
{ satoshis: 1817, outputId: 15658 },
|
|
683
|
+
{ satoshis: 1041, outputId: 16409 }
|
|
684
|
+
]
|
|
685
|
+
}
|
|
686
|
+
const d9: TestCase = {
|
|
687
|
+
p: {
|
|
688
|
+
fixedInputs: [],
|
|
689
|
+
fixedOutputs: [
|
|
690
|
+
{ satoshis: 1000, lockingScriptLength: 1136 },
|
|
691
|
+
{ satoshis: 200, lockingScriptLength: 25 }
|
|
692
|
+
],
|
|
693
|
+
feeModel: { model: 'sat/kb', value: 2 },
|
|
694
|
+
changeInitialSatoshis: 1000,
|
|
695
|
+
changeFirstSatoshis: 285,
|
|
696
|
+
changeLockingScriptLength: 25,
|
|
697
|
+
changeUnlockingScriptLength: 107
|
|
698
|
+
},
|
|
699
|
+
availableChange: [
|
|
700
|
+
{ satoshis: 23082, outputId: 14734 },
|
|
701
|
+
{ satoshis: 270789, outputId: 14744 },
|
|
702
|
+
{ satoshis: 81520, outputId: 14763 },
|
|
703
|
+
{ satoshis: 14759, outputId: 14770 },
|
|
704
|
+
{ satoshis: 390625, outputId: 14774 },
|
|
705
|
+
{ satoshis: 674234, outputId: 14790 },
|
|
706
|
+
{ satoshis: 999799, outputId: 14794 },
|
|
707
|
+
{ satoshis: 1000, outputId: 15583 },
|
|
708
|
+
{ satoshis: 1000, outputId: 15584 },
|
|
709
|
+
{ satoshis: 1000, outputId: 15585 },
|
|
710
|
+
{ satoshis: 1000, outputId: 15586 },
|
|
711
|
+
{ satoshis: 1000, outputId: 15587 },
|
|
712
|
+
{ satoshis: 1000, outputId: 15588 },
|
|
713
|
+
{ satoshis: 1000, outputId: 15590 },
|
|
714
|
+
{ satoshis: 1000, outputId: 15591 },
|
|
715
|
+
{ satoshis: 1000, outputId: 15593 },
|
|
716
|
+
{ satoshis: 1000, outputId: 15594 },
|
|
717
|
+
{ satoshis: 1000, outputId: 15595 },
|
|
718
|
+
{ satoshis: 1000, outputId: 15596 },
|
|
719
|
+
{ satoshis: 1000, outputId: 15597 },
|
|
720
|
+
{ satoshis: 1000, outputId: 15599 },
|
|
721
|
+
{ satoshis: 1000, outputId: 15600 },
|
|
722
|
+
{ satoshis: 1000, outputId: 15601 },
|
|
723
|
+
{ satoshis: 1000, outputId: 15603 },
|
|
724
|
+
{ satoshis: 1000, outputId: 15604 },
|
|
725
|
+
{ satoshis: 1000, outputId: 15605 },
|
|
726
|
+
{ satoshis: 1000, outputId: 15606 },
|
|
727
|
+
{ satoshis: 1000, outputId: 15607 },
|
|
728
|
+
{ satoshis: 1000, outputId: 15608 },
|
|
729
|
+
{ satoshis: 1000, outputId: 15609 },
|
|
730
|
+
{ satoshis: 1004, outputId: 15610 },
|
|
731
|
+
{ satoshis: 1000, outputId: 15611 },
|
|
732
|
+
{ satoshis: 1001, outputId: 15614 },
|
|
733
|
+
{ satoshis: 1000, outputId: 15615 },
|
|
734
|
+
{ satoshis: 1000, outputId: 15616 },
|
|
735
|
+
{ satoshis: 1000, outputId: 15617 },
|
|
736
|
+
{ satoshis: 1000, outputId: 15618 },
|
|
737
|
+
{ satoshis: 1000, outputId: 15619 },
|
|
738
|
+
{ satoshis: 1006, outputId: 15620 },
|
|
739
|
+
{ satoshis: 1000, outputId: 15621 },
|
|
740
|
+
{ satoshis: 1000, outputId: 15622 },
|
|
741
|
+
{ satoshis: 1000, outputId: 15623 },
|
|
742
|
+
{ satoshis: 1000, outputId: 15624 },
|
|
743
|
+
{ satoshis: 4571, outputId: 15626 },
|
|
744
|
+
{ satoshis: 1000, outputId: 15628 },
|
|
745
|
+
{ satoshis: 1000, outputId: 15629 },
|
|
746
|
+
{ satoshis: 1000, outputId: 15631 },
|
|
747
|
+
{ satoshis: 1000, outputId: 15632 },
|
|
748
|
+
{ satoshis: 1001, outputId: 15633 },
|
|
749
|
+
{ satoshis: 1001, outputId: 15634 },
|
|
750
|
+
{ satoshis: 1000, outputId: 15635 },
|
|
751
|
+
{ satoshis: 1000, outputId: 15637 },
|
|
752
|
+
{ satoshis: 1001, outputId: 15638 },
|
|
753
|
+
{ satoshis: 1000, outputId: 15639 },
|
|
754
|
+
{ satoshis: 1000, outputId: 15640 },
|
|
755
|
+
{ satoshis: 1000, outputId: 15641 },
|
|
756
|
+
{ satoshis: 1000, outputId: 15642 },
|
|
757
|
+
{ satoshis: 1000, outputId: 15643 },
|
|
758
|
+
{ satoshis: 1000, outputId: 15645 },
|
|
759
|
+
{ satoshis: 1000, outputId: 15646 },
|
|
760
|
+
{ satoshis: 1000, outputId: 15647 },
|
|
761
|
+
{ satoshis: 1000, outputId: 15648 },
|
|
762
|
+
{ satoshis: 1001, outputId: 15649 },
|
|
763
|
+
{ satoshis: 1000, outputId: 15650 },
|
|
764
|
+
{ satoshis: 604, outputId: 16421 },
|
|
765
|
+
{ satoshis: 958, outputId: 16429 },
|
|
766
|
+
{ satoshis: 724, outputId: 16431 },
|
|
767
|
+
{ satoshis: 413, outputId: 16433 },
|
|
768
|
+
{ satoshis: 915, outputId: 16439 },
|
|
769
|
+
{ satoshis: 842, outputId: 16441 },
|
|
770
|
+
{ satoshis: 348, outputId: 16451 },
|
|
771
|
+
{ satoshis: 339, outputId: 16453 },
|
|
772
|
+
{ satoshis: 334, outputId: 16455 },
|
|
773
|
+
{ satoshis: 331, outputId: 16457 },
|
|
774
|
+
{ satoshis: 330, outputId: 16459 },
|
|
775
|
+
{ satoshis: 327, outputId: 16461 },
|
|
776
|
+
{ satoshis: 323, outputId: 16463 },
|
|
777
|
+
{ satoshis: 311, outputId: 16465 }
|
|
778
|
+
]
|
|
779
|
+
}
|
|
780
|
+
const d10: TestCase = {
|
|
781
|
+
p: {
|
|
782
|
+
fixedInputs: [],
|
|
783
|
+
fixedOutputs: [
|
|
784
|
+
{ satoshis: 1, lockingScriptLength: 25 },
|
|
785
|
+
{ satoshis: 200, lockingScriptLength: 25 }
|
|
786
|
+
],
|
|
787
|
+
feeModel: { model: 'sat/kb', value: 110 },
|
|
788
|
+
changeInitialSatoshis: 1000,
|
|
789
|
+
changeFirstSatoshis: 285,
|
|
790
|
+
changeLockingScriptLength: 25,
|
|
791
|
+
changeUnlockingScriptLength: 107
|
|
792
|
+
},
|
|
793
|
+
availableChange: [
|
|
794
|
+
{ satoshis: 268076, outputId: 16671 },
|
|
795
|
+
{ satoshis: 2999799, outputId: 16677 },
|
|
796
|
+
{ satoshis: 14030, outputId: 21194 },
|
|
797
|
+
{ satoshis: 100925, outputId: 21224 }
|
|
798
|
+
]
|
|
799
|
+
}
|
|
800
|
+
const d11: TestCase = {
|
|
801
|
+
p: {
|
|
802
|
+
fixedInputs: [],
|
|
803
|
+
fixedOutputs: [
|
|
804
|
+
{ satoshis: 1, lockingScriptLength: 25 },
|
|
805
|
+
{ satoshis: 200, lockingScriptLength: 25 }
|
|
806
|
+
],
|
|
807
|
+
feeModel: { model: 'sat/kb', value: 110 },
|
|
808
|
+
changeInitialSatoshis: 1000,
|
|
809
|
+
changeFirstSatoshis: 285,
|
|
810
|
+
changeLockingScriptLength: 25,
|
|
811
|
+
changeUnlockingScriptLength: 107
|
|
812
|
+
},
|
|
813
|
+
availableChange: [
|
|
814
|
+
{ satoshis: 268076, outputId: 16671 },
|
|
815
|
+
{ satoshis: 2999799, outputId: 16677 },
|
|
816
|
+
{ satoshis: 1396, outputId: 21307 },
|
|
817
|
+
{ satoshis: 1023, outputId: 21308 },
|
|
818
|
+
{ satoshis: 1000, outputId: 21309 },
|
|
819
|
+
{ satoshis: 1000, outputId: 21310 },
|
|
820
|
+
{ satoshis: 1000, outputId: 21311 },
|
|
821
|
+
{ satoshis: 1220, outputId: 21312 },
|
|
822
|
+
{ satoshis: 5573, outputId: 21313 },
|
|
823
|
+
{ satoshis: 1000, outputId: 21314 },
|
|
824
|
+
{ satoshis: 1000, outputId: 21315 },
|
|
825
|
+
{ satoshis: 5926, outputId: 21316 },
|
|
826
|
+
{ satoshis: 30814, outputId: 21317 },
|
|
827
|
+
{ satoshis: 24441, outputId: 21318 },
|
|
828
|
+
{ satoshis: 285, outputId: 21319 },
|
|
829
|
+
{ satoshis: 1325, outputId: 21320 },
|
|
830
|
+
{ satoshis: 1000, outputId: 21321 },
|
|
831
|
+
{ satoshis: 1002, outputId: 21322 },
|
|
832
|
+
{ satoshis: 1000, outputId: 21324 },
|
|
833
|
+
{ satoshis: 1057, outputId: 21325 },
|
|
834
|
+
{ satoshis: 1000, outputId: 21326 },
|
|
835
|
+
{ satoshis: 1159, outputId: 21327 },
|
|
836
|
+
{ satoshis: 1061, outputId: 21328 },
|
|
837
|
+
{ satoshis: 1000, outputId: 21329 },
|
|
838
|
+
{ satoshis: 1000, outputId: 21330 },
|
|
839
|
+
{ satoshis: 1000, outputId: 21331 },
|
|
840
|
+
{ satoshis: 8873, outputId: 21332 },
|
|
841
|
+
{ satoshis: 1001, outputId: 21333 },
|
|
842
|
+
{ satoshis: 1011, outputId: 21334 },
|
|
843
|
+
{ satoshis: 1000, outputId: 21335 },
|
|
844
|
+
{ satoshis: 13699, outputId: 21336 }
|
|
845
|
+
]
|
|
846
|
+
}
|
|
847
|
+
const d12: TestCase = {
|
|
848
|
+
p: {
|
|
849
|
+
fixedInputs: [],
|
|
850
|
+
fixedOutputs: [
|
|
851
|
+
{ satoshis: 1, lockingScriptLength: 25 },
|
|
852
|
+
{ satoshis: 200, lockingScriptLength: 25 }
|
|
853
|
+
],
|
|
854
|
+
feeModel: { model: 'sat/kb', value: 110 },
|
|
855
|
+
changeInitialSatoshis: 1000,
|
|
856
|
+
changeFirstSatoshis: 285,
|
|
857
|
+
changeLockingScriptLength: 25,
|
|
858
|
+
changeUnlockingScriptLength: 107
|
|
859
|
+
},
|
|
860
|
+
availableChange: [
|
|
861
|
+
{ satoshis: 268076, outputId: 16671 },
|
|
862
|
+
{ satoshis: 2999799, outputId: 16677 },
|
|
863
|
+
{ satoshis: 14030, outputId: 21194 },
|
|
864
|
+
{ satoshis: 100925, outputId: 21224 }
|
|
865
|
+
]
|
|
866
|
+
}
|
|
867
|
+
const d13: TestCase = {
|
|
868
|
+
p: {
|
|
869
|
+
fixedInputs: [],
|
|
870
|
+
fixedOutputs: [
|
|
871
|
+
{ satoshis: 500, lockingScriptLength: 194 },
|
|
872
|
+
{ satoshis: 2, lockingScriptLength: 25 }
|
|
873
|
+
],
|
|
874
|
+
feeModel: { model: 'sat/kb', value: 2 },
|
|
875
|
+
changeInitialSatoshis: 1000,
|
|
876
|
+
changeFirstSatoshis: 285,
|
|
877
|
+
changeLockingScriptLength: 25,
|
|
878
|
+
changeUnlockingScriptLength: 107
|
|
879
|
+
},
|
|
880
|
+
availableChange: [
|
|
881
|
+
{ satoshis: 285, outputId: 16190 },
|
|
882
|
+
{ satoshis: 1012, outputId: 18487 },
|
|
883
|
+
{ satoshis: 1013, outputId: 18488 },
|
|
884
|
+
{ satoshis: 1000, outputId: 18489 },
|
|
885
|
+
{ satoshis: 1087, outputId: 18490 },
|
|
886
|
+
{ satoshis: 290, outputId: 18491 },
|
|
887
|
+
{ satoshis: 1034, outputId: 18492 }
|
|
888
|
+
]
|
|
889
|
+
}
|
|
890
|
+
const d14: TestCase = {
|
|
891
|
+
p: {
|
|
892
|
+
fixedInputs: [],
|
|
893
|
+
fixedOutputs: [{ satoshis: 3, lockingScriptLength: 141 }],
|
|
894
|
+
feeModel: { model: 'sat/kb', value: 2 },
|
|
895
|
+
changeInitialSatoshis: 1000,
|
|
896
|
+
changeFirstSatoshis: 285,
|
|
897
|
+
changeLockingScriptLength: 25,
|
|
898
|
+
changeUnlockingScriptLength: 107,
|
|
899
|
+
targetNetCount: 22
|
|
900
|
+
},
|
|
901
|
+
availableChange: [
|
|
902
|
+
{ satoshis: 995, outputId: 16190 },
|
|
903
|
+
{ satoshis: 1000, outputId: 18487 },
|
|
904
|
+
{ satoshis: 1000, outputId: 18488 },
|
|
905
|
+
{ satoshis: 1000, outputId: 18489 },
|
|
906
|
+
{ satoshis: 1000, outputId: 18490 },
|
|
907
|
+
{ satoshis: 1000, outputId: 18491 },
|
|
908
|
+
{ satoshis: 1000, outputId: 18492 },
|
|
909
|
+
{ satoshis: 1000, outputId: 18493 },
|
|
910
|
+
{ satoshis: 1000, outputId: 18494 },
|
|
911
|
+
{ satoshis: 1000, outputId: 18495 },
|
|
912
|
+
{ satoshis: 100, outputId: 18496 }
|
|
913
|
+
]
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
const test8Cases = [
|
|
917
|
+
{
|
|
918
|
+
n: 14,
|
|
919
|
+
d: d14,
|
|
920
|
+
er: '{"allocatedChangeInputs":[{"satoshis":1000,"outputId":18495,"spendable":false}],"changeOutputs":[{"satoshis":996,"lockingScriptLength":25}],"size":342,"fee":1,"satsPerKb":2}'
|
|
921
|
+
},
|
|
922
|
+
{
|
|
923
|
+
n: 13,
|
|
924
|
+
d: d13,
|
|
925
|
+
er: '{"allocatedChangeInputs":[{"satoshis":1000,"outputId":18489,"spendable":false}],"changeOutputs":[{"satoshis":497,"lockingScriptLength":25}],"size":429,"fee":1,"satsPerKb":2}'
|
|
926
|
+
},
|
|
927
|
+
{
|
|
928
|
+
n: 12,
|
|
929
|
+
d: d12,
|
|
930
|
+
er: '{"allocatedChangeInputs":[{"satoshis":14030,"outputId":21194,"spendable":false}],"changeOutputs":[{"satoshis":13800,"lockingScriptLength":25}],"size":260,"fee":29,"satsPerKb":110}'
|
|
931
|
+
},
|
|
932
|
+
{
|
|
933
|
+
n: 11,
|
|
934
|
+
d: d11,
|
|
935
|
+
er: '{"allocatedChangeInputs":[{"satoshis":285,"outputId":21319,"spendable":false},{"satoshis":1000,"outputId":21309,"spendable":false}],"changeOutputs":[{"satoshis":1039,"lockingScriptLength":25}],"size":408,"fee":45,"satsPerKb":110}'
|
|
936
|
+
},
|
|
937
|
+
{
|
|
938
|
+
n: 10,
|
|
939
|
+
d: d10,
|
|
940
|
+
er: '{"allocatedChangeInputs":[{"satoshis":14030,"outputId":21194,"spendable":false}],"changeOutputs":[{"satoshis":13800,"lockingScriptLength":25}],"size":260,"fee":29,"satsPerKb":110}'
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
n: 9,
|
|
944
|
+
d: d9,
|
|
945
|
+
er: '{"allocatedChangeInputs":[{"satoshis":4571,"outputId":15626,"spendable":false}],"changeOutputs":[{"satoshis":3368,"lockingScriptLength":25}],"size":1373,"fee":3,"satsPerKb":2}'
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
n: 8,
|
|
949
|
+
d: d8,
|
|
950
|
+
er: '{"allocatedChangeInputs":[{"satoshis":1817,"outputId":15658,"spendable":false}],"changeOutputs":[{"satoshis":52,"lockingScriptLength":25}],"size":260,"fee":1,"satsPerKb":2}'
|
|
951
|
+
},
|
|
952
|
+
{
|
|
953
|
+
n: 7,
|
|
954
|
+
d: d7,
|
|
955
|
+
er: '{"allocatedChangeInputs":[{"satoshis":1817,"outputId":15658,"spendable":false}],"changeOutputs":[{"satoshis":46,"lockingScriptLength":25}],"size":260,"fee":1,"satsPerKb":2}'
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
n: 6,
|
|
959
|
+
d: d6,
|
|
960
|
+
er: '{"allocatedChangeInputs":[{"satoshis":1000,"outputId":16346,"spendable":false}],"changeOutputs":[{"satoshis":298,"lockingScriptLength":25}],"size":673,"fee":2,"satsPerKb":2}'
|
|
961
|
+
},
|
|
962
|
+
{
|
|
963
|
+
n: 5,
|
|
964
|
+
d: d5,
|
|
965
|
+
er: '{"allocatedChangeInputs":[],"changeOutputs":[{"satoshis":799,"lockingScriptLength":25}],"size":191,"fee":1,"satsPerKb":2}'
|
|
966
|
+
}
|
|
967
|
+
]
|
|
968
|
+
|
|
969
|
+
test('8 paramsText d5 d6 d7 d8 d9 d10 d11 d12 d13 d14', async () => {
|
|
970
|
+
for (const { n, d, er } of test8Cases) {
|
|
971
|
+
const params: GenerateChangeSdkParams = { ...d.p }
|
|
972
|
+
const availableChange: GenerateChangeSdkChangeInput[] = [...d.availableChange]
|
|
973
|
+
|
|
974
|
+
const { allocateChangeInput, releaseChangeInput } = generateChangeSdkMakeStorage(availableChange)
|
|
975
|
+
|
|
976
|
+
const r = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
977
|
+
expect(JSON.stringify(r)).toBe(er)
|
|
978
|
+
expectTransactionSize(params, r)
|
|
979
|
+
}
|
|
980
|
+
})
|
|
981
|
+
})
|
|
982
|
+
|
|
983
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
984
|
+
async function expectToThrowWERR<R>(expectedClass: new (...args: any[]) => any, fn: () => Promise<R>): Promise<void> {
|
|
985
|
+
try {
|
|
986
|
+
await fn()
|
|
987
|
+
} catch (eu: unknown) {
|
|
988
|
+
const e = sdk.WalletError.fromUnknown(eu)
|
|
989
|
+
expect(e.name).toBe(expectedClass.name)
|
|
990
|
+
expect(e.isError).toBe(true)
|
|
991
|
+
return
|
|
992
|
+
}
|
|
993
|
+
throw new Error(`${expectedClass.name} was not thrown`)
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
function makeTransaction(params: GenerateChangeSdkParams, results: GenerateChangeSdkResult): BsvTransaction {
|
|
997
|
+
const tx = new BsvTransaction()
|
|
998
|
+
for (const i of params.fixedInputs) {
|
|
999
|
+
tx.inputs.push({
|
|
1000
|
+
unlockingScript: Script.fromBinary(Array(i.unlockingScriptLength).fill(0)),
|
|
1001
|
+
sourceOutputIndex: 0,
|
|
1002
|
+
sourceTXID: '00'.repeat(32)
|
|
1003
|
+
})
|
|
1004
|
+
}
|
|
1005
|
+
for (const i of results.allocatedChangeInputs) {
|
|
1006
|
+
tx.inputs.push({
|
|
1007
|
+
unlockingScript: Script.fromBinary(Array(params.changeUnlockingScriptLength).fill(0)),
|
|
1008
|
+
sourceOutputIndex: 0,
|
|
1009
|
+
sourceTXID: '00'.repeat(32)
|
|
1010
|
+
})
|
|
1011
|
+
}
|
|
1012
|
+
for (const o of params.fixedOutputs) {
|
|
1013
|
+
tx.outputs.push({
|
|
1014
|
+
lockingScript: Script.fromBinary(Array(o.lockingScriptLength).fill(0)),
|
|
1015
|
+
satoshis: o.satoshis
|
|
1016
|
+
})
|
|
1017
|
+
}
|
|
1018
|
+
for (const o of results.changeOutputs) {
|
|
1019
|
+
tx.outputs.push({
|
|
1020
|
+
lockingScript: Script.fromBinary(Array(o.lockingScriptLength).fill(0)),
|
|
1021
|
+
satoshis: o.satoshis
|
|
1022
|
+
})
|
|
1023
|
+
}
|
|
1024
|
+
return tx
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
function expectTransactionSize(params: GenerateChangeSdkParams, results: GenerateChangeSdkResult) {
|
|
1028
|
+
const tx = makeTransaction(params, results)
|
|
1029
|
+
const size = tx.toBinary().length
|
|
1030
|
+
if (size !== results.size) throw new sdk.WERR_INTERNAL(`expectTransaction actual ${size} expected ${results.size}`)
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
const defParams: GenerateChangeSdkParams = {
|
|
1034
|
+
fixedInputs: [],
|
|
1035
|
+
fixedOutputs: [],
|
|
1036
|
+
feeModel: { model: 'sat/kb', value: 2 },
|
|
1037
|
+
changeInitialSatoshis: 1000,
|
|
1038
|
+
changeFirstSatoshis: 285,
|
|
1039
|
+
changeLockingScriptLength: 25,
|
|
1040
|
+
changeUnlockingScriptLength: 107,
|
|
1041
|
+
randomVals: [...randomValsUsed1]
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
const _defAvailableChange: GenerateChangeSdkChangeInput[] = [
|
|
1045
|
+
{ satoshis: 6323, outputId: 15005 },
|
|
1046
|
+
{ satoshis: 1004, outputId: 15011 },
|
|
1047
|
+
{ satoshis: 1000, outputId: 15013 },
|
|
1048
|
+
{ satoshis: 1000, outputId: 15017 },
|
|
1049
|
+
{ satoshis: 1000, outputId: 15023 },
|
|
1050
|
+
{ satoshis: 1000, outputId: 15027 },
|
|
1051
|
+
{ satoshis: 1000, outputId: 15034 },
|
|
1052
|
+
{ satoshis: 1575097, outputId: 15101 },
|
|
1053
|
+
{ satoshis: 16417, outputId: 15103 },
|
|
1054
|
+
{ satoshis: 3377, outputId: 15104 },
|
|
1055
|
+
{ satoshis: 10735, outputId: 15106 }
|
|
1056
|
+
]
|
|
1057
|
+
const defAvailableChange = (): GenerateChangeSdkChangeInput[] => JSON.parse(JSON.stringify(_defAvailableChange))
|