@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.
Files changed (390) hide show
  1. package/.claude/settings.local.json +10 -0
  2. package/.env.template +22 -0
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
  4. package/.github/ISSUE_TEMPLATE/discussion.md +24 -0
  5. package/.github/pull_request_template.md +22 -0
  6. package/.github/workflows/push.yaml +145 -0
  7. package/.prettierrc +10 -0
  8. package/CHANGELOG.md +280 -0
  9. package/CONTRIBUTING.md +89 -0
  10. package/README.md +43 -0
  11. package/docs/README.md +85 -0
  12. package/docs/client.md +19627 -0
  13. package/docs/monitor.md +953 -0
  14. package/docs/open-rpc/index.html +46 -0
  15. package/docs/services.md +6377 -0
  16. package/docs/setup.md +1268 -0
  17. package/docs/storage.md +5367 -0
  18. package/docs/wallet.md +19626 -0
  19. package/jest.config.ts +25 -0
  20. package/license.md +28 -0
  21. package/out/tsconfig.all.tsbuildinfo +1 -0
  22. package/package.json +63 -0
  23. package/src/CWIStyleWalletManager.ts +1999 -0
  24. package/src/Setup.ts +579 -0
  25. package/src/SetupClient.ts +322 -0
  26. package/src/SetupWallet.ts +108 -0
  27. package/src/SimpleWalletManager.ts +526 -0
  28. package/src/Wallet.ts +1169 -0
  29. package/src/WalletAuthenticationManager.ts +153 -0
  30. package/src/WalletLogger.ts +213 -0
  31. package/src/WalletPermissionsManager.ts +3660 -0
  32. package/src/WalletSettingsManager.ts +114 -0
  33. package/src/__tests/CWIStyleWalletManager.test.d.ts.map +1 -0
  34. package/src/__tests/CWIStyleWalletManager.test.js.map +1 -0
  35. package/src/__tests/CWIStyleWalletManager.test.ts +675 -0
  36. package/src/__tests/WalletPermissionsManager.callbacks.test.ts +323 -0
  37. package/src/__tests/WalletPermissionsManager.checks.test.ts +844 -0
  38. package/src/__tests/WalletPermissionsManager.encryption.test.ts +412 -0
  39. package/src/__tests/WalletPermissionsManager.fixtures.ts +307 -0
  40. package/src/__tests/WalletPermissionsManager.flows.test.ts +462 -0
  41. package/src/__tests/WalletPermissionsManager.initialization.test.ts +300 -0
  42. package/src/__tests/WalletPermissionsManager.pmodules.test.ts +798 -0
  43. package/src/__tests/WalletPermissionsManager.proxying.test.ts +724 -0
  44. package/src/__tests/WalletPermissionsManager.tokens.test.ts +503 -0
  45. package/src/index.all.ts +27 -0
  46. package/src/index.client.ts +25 -0
  47. package/src/index.mobile.ts +21 -0
  48. package/src/index.ts +1 -0
  49. package/src/monitor/Monitor.ts +412 -0
  50. package/src/monitor/MonitorDaemon.ts +188 -0
  51. package/src/monitor/README.md +3 -0
  52. package/src/monitor/__test/MonitorDaemon.man.test.ts +45 -0
  53. package/src/monitor/tasks/TaskCheckForProofs.ts +243 -0
  54. package/src/monitor/tasks/TaskCheckNoSends.ts +73 -0
  55. package/src/monitor/tasks/TaskClock.ts +33 -0
  56. package/src/monitor/tasks/TaskFailAbandoned.ts +54 -0
  57. package/src/monitor/tasks/TaskMonitorCallHistory.ts +26 -0
  58. package/src/monitor/tasks/TaskNewHeader.ts +93 -0
  59. package/src/monitor/tasks/TaskPurge.ts +68 -0
  60. package/src/monitor/tasks/TaskReorg.ts +89 -0
  61. package/src/monitor/tasks/TaskReviewStatus.ts +48 -0
  62. package/src/monitor/tasks/TaskSendWaiting.ts +122 -0
  63. package/src/monitor/tasks/TaskSyncWhenIdle.ts +26 -0
  64. package/src/monitor/tasks/TaskUnFail.ts +151 -0
  65. package/src/monitor/tasks/WalletMonitorTask.ts +47 -0
  66. package/src/sdk/CertOpsWallet.ts +18 -0
  67. package/src/sdk/PrivilegedKeyManager.ts +372 -0
  68. package/src/sdk/README.md +13 -0
  69. package/src/sdk/WERR_errors.ts +234 -0
  70. package/src/sdk/WalletError.ts +170 -0
  71. package/src/sdk/WalletErrorFromJson.ts +80 -0
  72. package/src/sdk/WalletServices.interfaces.ts +700 -0
  73. package/src/sdk/WalletSigner.interfaces.ts +11 -0
  74. package/src/sdk/WalletStorage.interfaces.ts +606 -0
  75. package/src/sdk/__test/CertificateLifeCycle.test.ts +131 -0
  76. package/src/sdk/__test/PrivilegedKeyManager.test.ts +738 -0
  77. package/src/sdk/__test/WalletError.test.ts +318 -0
  78. package/src/sdk/__test/validationHelpers.test.ts +21 -0
  79. package/src/sdk/index.ts +10 -0
  80. package/src/sdk/types.ts +226 -0
  81. package/src/services/README.md +11 -0
  82. package/src/services/ServiceCollection.ts +248 -0
  83. package/src/services/Services.ts +603 -0
  84. package/src/services/__tests/ARC.man.test.ts +123 -0
  85. package/src/services/__tests/ARC.timeout.man.test.ts +79 -0
  86. package/src/services/__tests/ArcGorillaPool.man.test.ts +108 -0
  87. package/src/services/__tests/arcServices.test.ts +8 -0
  88. package/src/services/__tests/bitrails.test.ts +56 -0
  89. package/src/services/__tests/getMerklePath.test.ts +15 -0
  90. package/src/services/__tests/getRawTx.test.ts +13 -0
  91. package/src/services/__tests/postBeef.test.ts +104 -0
  92. package/src/services/__tests/verifyBeef.test.ts +50 -0
  93. package/src/services/chaintracker/BHServiceClient.ts +212 -0
  94. package/src/services/chaintracker/ChaintracksChainTracker.ts +71 -0
  95. package/src/services/chaintracker/__tests/ChaintracksChainTracker.test.ts +33 -0
  96. package/src/services/chaintracker/__tests/ChaintracksServiceClient.test.ts +29 -0
  97. package/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.ts +72 -0
  98. package/src/services/chaintracker/chaintracks/Api/BulkIngestorApi.ts +83 -0
  99. package/src/services/chaintracker/chaintracks/Api/BulkStorageApi.ts +92 -0
  100. package/src/services/chaintracker/chaintracks/Api/ChaintracksApi.ts +64 -0
  101. package/src/services/chaintracker/chaintracks/Api/ChaintracksClientApi.ts +189 -0
  102. package/src/services/chaintracker/chaintracks/Api/ChaintracksFetchApi.ts +18 -0
  103. package/src/services/chaintracker/chaintracks/Api/ChaintracksFsApi.ts +58 -0
  104. package/src/services/chaintracker/chaintracks/Api/ChaintracksStorageApi.ts +386 -0
  105. package/src/services/chaintracker/chaintracks/Api/LiveIngestorApi.ts +25 -0
  106. package/src/services/chaintracker/chaintracks/Chaintracks.ts +609 -0
  107. package/src/services/chaintracker/chaintracks/ChaintracksService.ts +199 -0
  108. package/src/services/chaintracker/chaintracks/ChaintracksServiceClient.ts +154 -0
  109. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.ts +176 -0
  110. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.ts +174 -0
  111. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDNBabbage.ts +18 -0
  112. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.ts +113 -0
  113. package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainWs.ts +81 -0
  114. package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.ts +86 -0
  115. package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorTeranodeP2P.ts +59 -0
  116. package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.ts +104 -0
  117. package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainWs.ts +66 -0
  118. package/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.ts +566 -0
  119. package/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.ts +219 -0
  120. package/src/services/chaintracker/chaintracks/Ingest/__tests/BulkIngestorCDNBabbage.test.ts +54 -0
  121. package/src/services/chaintracker/chaintracks/Ingest/__tests/LiveIngestorWhatsOnChainPoll.test.ts +33 -0
  122. package/src/services/chaintracker/chaintracks/Ingest/__tests/WhatsOnChainServices.test.ts +124 -0
  123. package/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.ts +92 -0
  124. package/src/services/chaintracker/chaintracks/Storage/ChaintracksKnexMigrations.ts +104 -0
  125. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.ts +382 -0
  126. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.ts +574 -0
  127. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.ts +438 -0
  128. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageMemory.ts +29 -0
  129. package/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.ts +304 -0
  130. package/src/services/chaintracker/chaintracks/Storage/__tests/ChaintracksStorageIdb.test.ts +102 -0
  131. package/src/services/chaintracker/chaintracks/Storage/__tests/ChaintracksStorageKnex.test.ts +45 -0
  132. package/src/services/chaintracker/chaintracks/__tests/Chaintracks.test.ts +77 -0
  133. package/src/services/chaintracker/chaintracks/__tests/ChaintracksClientApi.test.ts +192 -0
  134. package/src/services/chaintracker/chaintracks/__tests/LocalCdnServer.ts +75 -0
  135. package/src/services/chaintracker/chaintracks/__tests/createIdbChaintracks.test.ts +62 -0
  136. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNetBlockHeaders.json +1 -0
  137. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_0.headers +0 -0
  138. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_1.headers +0 -0
  139. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_2.headers +0 -0
  140. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest349/mainNet_3.headers +0 -0
  141. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNetBlockHeaders.json +1 -0
  142. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_0.headers +0 -0
  143. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_1.headers +0 -0
  144. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_2.headers +0 -0
  145. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest379/mainNet_3.headers +0 -0
  146. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNetBlockHeaders.json +1 -0
  147. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_0.headers +0 -0
  148. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_1.headers +0 -0
  149. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_2.headers +0 -0
  150. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest399/mainNet_3.headers +0 -0
  151. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNetBlockHeaders.json +1 -0
  152. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_0.headers +0 -0
  153. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_1.headers +0 -0
  154. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_2.headers +0 -0
  155. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_3.headers +0 -0
  156. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest402/mainNet_4.headers +0 -0
  157. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNetBlockHeaders.json +1 -0
  158. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_0.headers +0 -0
  159. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_1.headers +0 -0
  160. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_2.headers +0 -0
  161. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_3.headers +0 -0
  162. package/src/services/chaintracker/chaintracks/__tests/data/cdnTest499/mainNet_4.headers +0 -0
  163. package/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.ts +92 -0
  164. package/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.ts +111 -0
  165. package/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.ts +91 -0
  166. package/src/services/chaintracker/chaintracks/createIdbChaintracks.ts +60 -0
  167. package/src/services/chaintracker/chaintracks/createKnexChaintracks.ts +65 -0
  168. package/src/services/chaintracker/chaintracks/createNoDbChaintracks.ts +60 -0
  169. package/src/services/chaintracker/chaintracks/index.all.ts +12 -0
  170. package/src/services/chaintracker/chaintracks/index.client.ts +4 -0
  171. package/src/services/chaintracker/chaintracks/index.mobile.ts +37 -0
  172. package/src/services/chaintracker/chaintracks/util/BulkFileDataManager.ts +975 -0
  173. package/src/services/chaintracker/chaintracks/util/BulkFileDataReader.ts +60 -0
  174. package/src/services/chaintracker/chaintracks/util/BulkFilesReader.ts +336 -0
  175. package/src/services/chaintracker/chaintracks/util/BulkHeaderFile.ts +247 -0
  176. package/src/services/chaintracker/chaintracks/util/ChaintracksFetch.ts +69 -0
  177. package/src/services/chaintracker/chaintracks/util/ChaintracksFs.ts +141 -0
  178. package/src/services/chaintracker/chaintracks/util/HeightRange.ts +153 -0
  179. package/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.ts +76 -0
  180. package/src/services/chaintracker/chaintracks/util/__tests/BulkFileDataManager.test.ts +304 -0
  181. package/src/services/chaintracker/chaintracks/util/__tests/ChaintracksFetch.test.ts +60 -0
  182. package/src/services/chaintracker/chaintracks/util/__tests/HeightRange.test.ts +67 -0
  183. package/src/services/chaintracker/chaintracks/util/__tests/SingleWriterMultiReaderLock.test.ts +49 -0
  184. package/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.ts +573 -0
  185. package/src/services/chaintracker/chaintracks/util/dirtyHashes.ts +29 -0
  186. package/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.ts +432 -0
  187. package/src/services/chaintracker/index.all.ts +4 -0
  188. package/src/services/chaintracker/index.client.ts +4 -0
  189. package/src/services/chaintracker/index.mobile.ts +4 -0
  190. package/src/services/createDefaultWalletServicesOptions.ts +77 -0
  191. package/src/services/index.ts +1 -0
  192. package/src/services/processingErrors/arcSuccessError.json +76 -0
  193. package/src/services/providers/ARC.ts +350 -0
  194. package/src/services/providers/Bitails.ts +256 -0
  195. package/src/services/providers/SdkWhatsOnChain.ts +83 -0
  196. package/src/services/providers/WhatsOnChain.ts +883 -0
  197. package/src/services/providers/__tests/WhatsOnChain.test.ts +242 -0
  198. package/src/services/providers/__tests/exchangeRates.test.ts +18 -0
  199. package/src/services/providers/exchangeRates.ts +265 -0
  200. package/src/services/providers/getBeefForTxid.ts +369 -0
  201. package/src/signer/README.md +5 -0
  202. package/src/signer/WalletSigner.ts +17 -0
  203. package/src/signer/methods/acquireDirectCertificate.ts +52 -0
  204. package/src/signer/methods/buildSignableTransaction.ts +183 -0
  205. package/src/signer/methods/completeSignedTransaction.ts +117 -0
  206. package/src/signer/methods/createAction.ts +172 -0
  207. package/src/signer/methods/internalizeAction.ts +106 -0
  208. package/src/signer/methods/proveCertificate.ts +43 -0
  209. package/src/signer/methods/signAction.ts +54 -0
  210. package/src/storage/README.md +14 -0
  211. package/src/storage/StorageIdb.ts +2304 -0
  212. package/src/storage/StorageKnex.ts +1425 -0
  213. package/src/storage/StorageProvider.ts +810 -0
  214. package/src/storage/StorageReader.ts +194 -0
  215. package/src/storage/StorageReaderWriter.ts +432 -0
  216. package/src/storage/StorageSyncReader.ts +34 -0
  217. package/src/storage/WalletStorageManager.ts +943 -0
  218. package/src/storage/__test/StorageIdb.test.ts +43 -0
  219. package/src/storage/__test/WalletStorageManager.test.ts +275 -0
  220. package/src/storage/__test/adminStats.man.test.ts +89 -0
  221. package/src/storage/__test/getBeefForTransaction.test.ts +385 -0
  222. package/src/storage/index.all.ts +11 -0
  223. package/src/storage/index.client.ts +7 -0
  224. package/src/storage/index.mobile.ts +6 -0
  225. package/src/storage/methods/ListActionsSpecOp.ts +70 -0
  226. package/src/storage/methods/ListOutputsSpecOp.ts +129 -0
  227. package/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.ts +1057 -0
  228. package/src/storage/methods/__test/GenerateChange/randomValsUsed1.ts +20 -0
  229. package/src/storage/methods/__test/offsetKey.test.ts +274 -0
  230. package/src/storage/methods/attemptToPostReqsToNetwork.ts +389 -0
  231. package/src/storage/methods/createAction.ts +947 -0
  232. package/src/storage/methods/generateChange.ts +556 -0
  233. package/src/storage/methods/getBeefForTransaction.ts +139 -0
  234. package/src/storage/methods/getSyncChunk.ts +293 -0
  235. package/src/storage/methods/internalizeAction.ts +562 -0
  236. package/src/storage/methods/listActionsIdb.ts +183 -0
  237. package/src/storage/methods/listActionsKnex.ts +226 -0
  238. package/src/storage/methods/listCertificates.ts +73 -0
  239. package/src/storage/methods/listOutputsIdb.ts +203 -0
  240. package/src/storage/methods/listOutputsKnex.ts +263 -0
  241. package/src/storage/methods/offsetKey.ts +89 -0
  242. package/src/storage/methods/processAction.ts +420 -0
  243. package/src/storage/methods/purgeData.ts +251 -0
  244. package/src/storage/methods/purgeDataIdb.ts +10 -0
  245. package/src/storage/methods/reviewStatus.ts +101 -0
  246. package/src/storage/methods/reviewStatusIdb.ts +43 -0
  247. package/src/storage/methods/utils.Buffer.ts +33 -0
  248. package/src/storage/methods/utils.ts +56 -0
  249. package/src/storage/remoting/StorageClient.ts +567 -0
  250. package/src/storage/remoting/StorageMobile.ts +544 -0
  251. package/src/storage/remoting/StorageServer.ts +291 -0
  252. package/src/storage/remoting/__test/StorageClient.test.ts +113 -0
  253. package/src/storage/schema/KnexMigrations.ts +489 -0
  254. package/src/storage/schema/StorageIdbSchema.ts +150 -0
  255. package/src/storage/schema/entities/EntityBase.ts +210 -0
  256. package/src/storage/schema/entities/EntityCertificate.ts +188 -0
  257. package/src/storage/schema/entities/EntityCertificateField.ts +136 -0
  258. package/src/storage/schema/entities/EntityCommission.ts +148 -0
  259. package/src/storage/schema/entities/EntityOutput.ts +290 -0
  260. package/src/storage/schema/entities/EntityOutputBasket.ts +153 -0
  261. package/src/storage/schema/entities/EntityOutputTag.ts +121 -0
  262. package/src/storage/schema/entities/EntityOutputTagMap.ts +123 -0
  263. package/src/storage/schema/entities/EntityProvenTx.ts +319 -0
  264. package/src/storage/schema/entities/EntityProvenTxReq.ts +580 -0
  265. package/src/storage/schema/entities/EntitySyncState.ts +389 -0
  266. package/src/storage/schema/entities/EntityTransaction.ts +306 -0
  267. package/src/storage/schema/entities/EntityTxLabel.ts +121 -0
  268. package/src/storage/schema/entities/EntityTxLabelMap.ts +123 -0
  269. package/src/storage/schema/entities/EntityUser.ts +112 -0
  270. package/src/storage/schema/entities/MergeEntity.ts +73 -0
  271. package/src/storage/schema/entities/__tests/CertificateFieldTests.test.ts +353 -0
  272. package/src/storage/schema/entities/__tests/CertificateTests.test.ts +354 -0
  273. package/src/storage/schema/entities/__tests/CommissionTests.test.ts +371 -0
  274. package/src/storage/schema/entities/__tests/OutputBasketTests.test.ts +278 -0
  275. package/src/storage/schema/entities/__tests/OutputTagMapTests.test.ts +242 -0
  276. package/src/storage/schema/entities/__tests/OutputTagTests.test.ts +288 -0
  277. package/src/storage/schema/entities/__tests/OutputTests.test.ts +464 -0
  278. package/src/storage/schema/entities/__tests/ProvenTxReqTests.test.ts +340 -0
  279. package/src/storage/schema/entities/__tests/ProvenTxTests.test.ts +504 -0
  280. package/src/storage/schema/entities/__tests/SyncStateTests.test.ts +288 -0
  281. package/src/storage/schema/entities/__tests/TransactionTests.test.ts +604 -0
  282. package/src/storage/schema/entities/__tests/TxLabelMapTests.test.ts +361 -0
  283. package/src/storage/schema/entities/__tests/TxLabelTests.test.ts +198 -0
  284. package/src/storage/schema/entities/__tests/stampLogTests.test.ts +90 -0
  285. package/src/storage/schema/entities/__tests/usersTests.test.ts +340 -0
  286. package/src/storage/schema/entities/index.ts +16 -0
  287. package/src/storage/schema/tables/TableCertificate.ts +21 -0
  288. package/src/storage/schema/tables/TableCertificateField.ts +12 -0
  289. package/src/storage/schema/tables/TableCommission.ts +13 -0
  290. package/src/storage/schema/tables/TableMonitorEvent.ts +9 -0
  291. package/src/storage/schema/tables/TableOutput.ts +64 -0
  292. package/src/storage/schema/tables/TableOutputBasket.ts +12 -0
  293. package/src/storage/schema/tables/TableOutputTag.ts +10 -0
  294. package/src/storage/schema/tables/TableOutputTagMap.ts +9 -0
  295. package/src/storage/schema/tables/TableProvenTx.ts +14 -0
  296. package/src/storage/schema/tables/TableProvenTxReq.ts +65 -0
  297. package/src/storage/schema/tables/TableSettings.ts +17 -0
  298. package/src/storage/schema/tables/TableSyncState.ts +18 -0
  299. package/src/storage/schema/tables/TableTransaction.ts +54 -0
  300. package/src/storage/schema/tables/TableTxLabel.ts +10 -0
  301. package/src/storage/schema/tables/TableTxLabelMap.ts +9 -0
  302. package/src/storage/schema/tables/TableUser.ts +16 -0
  303. package/src/storage/schema/tables/index.ts +16 -0
  304. package/src/storage/sync/StorageMySQLDojoReader.ts +696 -0
  305. package/src/storage/sync/index.ts +1 -0
  306. package/src/utility/Format.ts +133 -0
  307. package/src/utility/README.md +3 -0
  308. package/src/utility/ReaderUint8Array.ts +187 -0
  309. package/src/utility/ScriptTemplateBRC29.ts +73 -0
  310. package/src/utility/__tests/utilityHelpers.noBuffer.test.ts +109 -0
  311. package/src/utility/aggregateResults.ts +68 -0
  312. package/src/utility/identityUtils.ts +159 -0
  313. package/src/utility/index.all.ts +7 -0
  314. package/src/utility/index.client.ts +7 -0
  315. package/src/utility/parseTxScriptOffsets.ts +29 -0
  316. package/src/utility/stampLog.ts +69 -0
  317. package/src/utility/tscProofToMerklePath.ts +48 -0
  318. package/src/utility/utilityHelpers.buffer.ts +34 -0
  319. package/src/utility/utilityHelpers.noBuffer.ts +60 -0
  320. package/src/utility/utilityHelpers.ts +275 -0
  321. package/src/wab-client/WABClient.ts +94 -0
  322. package/src/wab-client/__tests/WABClient.man.test.ts +59 -0
  323. package/src/wab-client/auth-method-interactors/AuthMethodInteractor.ts +47 -0
  324. package/src/wab-client/auth-method-interactors/DevConsoleInteractor.ts +73 -0
  325. package/src/wab-client/auth-method-interactors/PersonaIDInteractor.ts +35 -0
  326. package/src/wab-client/auth-method-interactors/TwilioPhoneInteractor.ts +72 -0
  327. package/syncVersions.js +71 -0
  328. package/test/Wallet/StorageClient/storageClient.man.test.ts +75 -0
  329. package/test/Wallet/action/abortAction.test.ts +47 -0
  330. package/test/Wallet/action/createAction.test.ts +299 -0
  331. package/test/Wallet/action/createAction2.test.ts +1273 -0
  332. package/test/Wallet/action/createActionToGenerateBeefs.man.test.ts +293 -0
  333. package/test/Wallet/action/internalizeAction.a.test.ts +286 -0
  334. package/test/Wallet/action/internalizeAction.test.ts +682 -0
  335. package/test/Wallet/action/relinquishOutput.test.ts +37 -0
  336. package/test/Wallet/certificate/acquireCertificate.test.ts +298 -0
  337. package/test/Wallet/certificate/listCertificates.test.ts +346 -0
  338. package/test/Wallet/construct/Wallet.constructor.test.ts +57 -0
  339. package/test/Wallet/get/getHeaderForHeight.test.ts +82 -0
  340. package/test/Wallet/get/getHeight.test.ts +52 -0
  341. package/test/Wallet/get/getKnownTxids.test.ts +86 -0
  342. package/test/Wallet/get/getNetwork.test.ts +27 -0
  343. package/test/Wallet/get/getVersion.test.ts +27 -0
  344. package/test/Wallet/list/listActions.test.ts +279 -0
  345. package/test/Wallet/list/listActions2.test.ts +1381 -0
  346. package/test/Wallet/list/listCertificates.test.ts +118 -0
  347. package/test/Wallet/list/listOutputs.test.ts +447 -0
  348. package/test/Wallet/live/walletLive.man.test.ts +521 -0
  349. package/test/Wallet/local/localWallet.man.test.ts +93 -0
  350. package/test/Wallet/local/localWallet2.man.test.ts +277 -0
  351. package/test/Wallet/signAction/mountaintop.man.test.ts +130 -0
  352. package/test/Wallet/specOps/specOps.man.test.ts +220 -0
  353. package/test/Wallet/support/janitor.man.test.ts +40 -0
  354. package/test/Wallet/support/operations.man.test.ts +407 -0
  355. package/test/Wallet/support/reqErrorReview.2025.05.06.man.test.ts +347 -0
  356. package/test/Wallet/sync/Wallet.sync.test.ts +215 -0
  357. package/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.ts +203 -0
  358. package/test/Wallet/sync/setActive.test.ts +170 -0
  359. package/test/WalletClient/LocalKVStore.man.test.ts +114 -0
  360. package/test/WalletClient/WERR.man.test.ts +35 -0
  361. package/test/bsv-ts-sdk/LocalKVStore.test.ts +102 -0
  362. package/test/checkDB.ts +57 -0
  363. package/test/checkdb +0 -0
  364. package/test/examples/backup.man.test.ts +59 -0
  365. package/test/examples/pushdrop.test.ts +282 -0
  366. package/test/monitor/Monitor.test.ts +620 -0
  367. package/test/services/Services.test.ts +263 -0
  368. package/test/storage/KnexMigrations.test.ts +86 -0
  369. package/test/storage/StorageMySQLDojoReader.man.test.ts +60 -0
  370. package/test/storage/count.test.ts +177 -0
  371. package/test/storage/find.test.ts +195 -0
  372. package/test/storage/findLegacy.test.ts +67 -0
  373. package/test/storage/idb/allocateChange.test.ts +251 -0
  374. package/test/storage/idb/count.test.ts +158 -0
  375. package/test/storage/idb/find.test.ts +177 -0
  376. package/test/storage/idb/idbSpeed.test.ts +36 -0
  377. package/test/storage/idb/insert.test.ts +268 -0
  378. package/test/storage/idb/transactionAbort.test.ts +108 -0
  379. package/test/storage/idb/update.test.ts +999 -0
  380. package/test/storage/insert.test.ts +278 -0
  381. package/test/storage/update.test.ts +1021 -0
  382. package/test/storage/update2.test.ts +897 -0
  383. package/test/utils/TestUtilsWalletStorage.ts +2526 -0
  384. package/test/utils/localWalletMethods.ts +363 -0
  385. package/test/utils/removeFailedFromDatabase.sql +17 -0
  386. package/ts2md.json +44 -0
  387. package/tsconfig.all.json +31 -0
  388. package/tsconfig.client.json +29 -0
  389. package/tsconfig.json +17 -0
  390. package/tsconfig.mobile.json +28 -0
@@ -0,0 +1,1273 @@
1
+ import chalk from 'chalk'
2
+ import fs from 'fs'
3
+ import path from 'path'
4
+ import {
5
+ AtomicBEEF,
6
+ Beef,
7
+ CreateActionArgs,
8
+ CreateActionResult,
9
+ ListActionsResult,
10
+ MerklePath,
11
+ Transaction,
12
+ TransactionInput,
13
+ TransactionOutput,
14
+ WalletActionInput,
15
+ WalletActionOutput
16
+ } from '@bsv/sdk'
17
+ import { _tu, TestWalletNoSetup } from '../../utils/TestUtilsWalletStorage'
18
+
19
+ const includeTestChaintracks = false
20
+ const noLog = true
21
+ const logFilePath = path.resolve(__dirname, 'createAction2.test.ts')
22
+
23
+ function sanitizeTestName(testName: string): string {
24
+ const cleanTestName = testName.replace(/[^a-zA-Z0-9_]/g, '_')
25
+ return cleanTestName.startsWith('LOG_') ? cleanTestName : `LOG_${cleanTestName}`
26
+ }
27
+
28
+ describe('createAction2 nosend transactions', () => {
29
+ jest.setTimeout(99999999)
30
+
31
+ let ctxs: TestWalletNoSetup[] = []
32
+ const env = _tu.getEnv('test')
33
+ const testName = () => expect.getState().currentTestName ?? 'test'
34
+
35
+ beforeEach(async () => {
36
+ ctxs = []
37
+
38
+ if (env.runMySQL) {
39
+ ctxs.push(await _tu.createLegacyWalletMySQLCopy(testName()))
40
+ }
41
+
42
+ ctxs.push(await _tu.createLegacyWalletSQLiteCopy(testName()))
43
+ })
44
+
45
+ afterEach(async () => {
46
+ for (const { wallet } of ctxs) await wallet.destroy()
47
+ })
48
+
49
+ test('1_transaction with single output checked using toLogString', async () => {
50
+ for (const { wallet } of ctxs) {
51
+ wallet.randomVals = [0.1, 0.2, 0.3, 0.7, 0.8, 0.9]
52
+ const fundingLabel = 'funding transaction for createAction'
53
+ const fundingArgs: CreateActionArgs = {
54
+ outputs: [
55
+ {
56
+ basket: 'funding basket',
57
+ tags: ['funding transaction output', 'test tag'],
58
+ satoshis: 3,
59
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
60
+ outputDescription: 'Funding Output'
61
+ }
62
+ ],
63
+ labels: [
64
+ fundingLabel,
65
+ 'this is an extra long test label that should be truncated at 80 chars when it is displayed'
66
+ ],
67
+ description: 'Funding transaction',
68
+ options: { noSend: true, randomizeOutputs: false }
69
+ }
70
+ const fundingResult: CreateActionResult = await wallet.createAction(fundingArgs)
71
+ expect(fundingResult.tx).toBeDefined()
72
+ const actionsResult = await wallet.listActions({
73
+ labels: [fundingLabel],
74
+ includeInputs: true,
75
+ includeOutputs: true,
76
+ includeInputSourceLockingScripts: true,
77
+ includeInputUnlockingScripts: true,
78
+ includeOutputLockingScripts: true,
79
+ includeLabels: true
80
+ })
81
+ const rl1 = toLogString(fundingResult.tx!, actionsResult)
82
+ expect(rl1.log).toBe(`transactions:3
83
+ txid:30bdac0f5c6491f130820517802ff57e20e5a50c08b5c65e6976627fb82ae930 version:1 lockTime:0 sats:-4 status:nosend
84
+ outgoing:true desc:'Funding transaction' labels:['funding transaction for createaction','this is an extra long test
85
+ label that should be truncated at 80 chars when it is...']
86
+ inputs: 1
87
+ 0: sourceTXID:a3a8fe7f541c1383ff7b975af49b27284ae720af5f2705d8409baaf519190d26.2 sats:913
88
+ lock:(50)76a914f7238871139f4926cbd592a03a737981e558245d88ac
89
+ unlock:(214)483045022100cfef1f6d781af99a1de14efd6f24f2a14234a26097012f27121eb36f4e330c1d0220... seq:4294967295
90
+ outputs: 2
91
+ 0: sats:3 lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac index:0 spendable:true basket:'funding basket'
92
+ desc:'Funding Output' tags:['funding transaction output','test tag']
93
+ 1: sats:909 lock:(50)76a9145947e66cdd43c70fb1780116b79e6f7d96e30e0888ac index:1 spendable:true basket:'default'`)
94
+ }
95
+ })
96
+
97
+ test('2_transaction with multiple outputs checked using toLogString', async () => {
98
+ for (const { wallet } of ctxs) {
99
+ wallet.randomVals = [0.1, 0.2, 0.3, 0.7, 0.8, 0.9]
100
+ const fundingLabel = 'funding transaction for createAction'
101
+ const fundingArgs: CreateActionArgs = {
102
+ outputs: [
103
+ {
104
+ basket: 'funding basket',
105
+ tags: ['funding transaction for createAction', 'test tag'],
106
+ satoshis: 5,
107
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
108
+ outputDescription: 'Funding output'
109
+ },
110
+ {
111
+ basket: 'extra basket',
112
+ tags: ['extra transaction output', 'extra test tag'],
113
+ satoshis: 6,
114
+ lockingScript: '76a914fedcba9876543210fedcba9876543210fedcba88ac',
115
+ outputDescription: 'Extra Output'
116
+ }
117
+ ],
118
+ labels: [fundingLabel, 'this is the extra label'],
119
+ description: 'Funding transaction with multiple outputs',
120
+ options: { noSend: true, randomizeOutputs: false }
121
+ }
122
+ const fundingResult: CreateActionResult = await wallet.createAction(fundingArgs)
123
+ const actionsResult = await wallet.listActions({
124
+ labels: [fundingLabel],
125
+ includeInputs: true,
126
+ includeOutputs: true,
127
+ includeInputSourceLockingScripts: true,
128
+ includeInputUnlockingScripts: true,
129
+ includeOutputLockingScripts: true,
130
+ includeLabels: true
131
+ })
132
+ const rl1 = toLogString(fundingResult.tx!, actionsResult)
133
+ expect(rl1.log).toBe(`transactions:3
134
+ txid:b3848f2cabf5887ec679ca60347a29f6ecad425fda738700265c2f9d22c18ab5 version:1 lockTime:0 sats:-12 status:nosend
135
+ outgoing:true desc:'Funding transaction with multiple outputs' labels:['funding transaction for createaction','this
136
+ is the extra label']
137
+ inputs: 1
138
+ 0: sourceTXID:a3a8fe7f541c1383ff7b975af49b27284ae720af5f2705d8409baaf519190d26.2 sats:913
139
+ lock:(50)76a914f7238871139f4926cbd592a03a737981e558245d88ac
140
+ unlock:(212)473044022079020cc8ea5ee6b3610806286e41567147d4b4b07d16bc1341311e00ce7647b0022034... seq:4294967295
141
+ outputs: 3
142
+ 0: sats:5 lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac index:0 spendable:true basket:'funding basket'
143
+ desc:'Funding output' tags:['funding transaction for createaction','test tag']
144
+ 1: sats:6 lock:(48)76a914fedcba9876543210fedcba9876543210fedcba88ac index:1 spendable:true basket:'extra basket'
145
+ desc:'Extra Output' tags:['extra transaction output','extra test tag']
146
+ 2: sats:901 lock:(50)76a9145947e66cdd43c70fb1780116b79e6f7d96e30e0888ac index:2 spendable:true basket:'default'`)
147
+ }
148
+ })
149
+
150
+ test('3_transaction with explicit change check also uses toLogString on the spend', async () => {
151
+ if (!includeTestChaintracks) return
152
+ for (const { wallet } of ctxs) {
153
+ wallet.randomVals = [0.1, 0.2, 0.3, 0.7, 0.8, 0.9]
154
+ const fundingArgs: CreateActionArgs = {
155
+ outputs: [
156
+ {
157
+ satoshis: 4,
158
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
159
+ outputDescription: 'Funding output'
160
+ }
161
+ ],
162
+ description: 'Funding transaction',
163
+ options: { noSend: true, randomizeOutputs: false }
164
+ }
165
+ const fundingResult: CreateActionResult = await wallet.createAction(fundingArgs)
166
+ expect(fundingResult.tx).toBeDefined()
167
+ expect(fundingResult.noSendChange).toBeDefined()
168
+ expect(fundingResult.noSendChange!.length).toBe(1)
169
+ log(`noSendChange returned:${JSON.stringify(fundingResult.noSendChange, null, 2)}`)
170
+ const outputSatoshis = 2
171
+ const estimatedFee = 1
172
+ const fundingBeef = Beef.fromBinary(fundingResult.tx!)
173
+ expect(fundingBeef).toBeDefined()
174
+ const spendingArgs: CreateActionArgs = {
175
+ inputs: [
176
+ {
177
+ outpoint: `${fundingResult.txid}.0`,
178
+ unlockingScript: '47304402207f2e9a',
179
+ inputDescription: 'desc3'
180
+ }
181
+ ],
182
+ inputBEEF: fundingBeef.toBinary(),
183
+ outputs: [
184
+ {
185
+ satoshis: outputSatoshis,
186
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
187
+ outputDescription: 'First spending Output for check on change '
188
+ }
189
+ ],
190
+ labels: ['spending transaction test'],
191
+ description: 'Explicit check on returned change',
192
+ options: {
193
+ knownTxids: [fundingResult.txid!],
194
+ noSend: true,
195
+ randomizeOutputs: false,
196
+ noSendChange: []
197
+ }
198
+ }
199
+ const spendingResult: CreateActionResult = await wallet.createAction(spendingArgs)
200
+ expect(spendingResult.tx).toBeDefined()
201
+ log(`Spending transaction created:${JSON.stringify(spendingResult, null, 2)}`)
202
+ const spendingActionsResult = await wallet.listActions({
203
+ labels: ['spending transaction test'],
204
+ includeInputs: true,
205
+ includeOutputs: true,
206
+ includeInputSourceLockingScripts: true,
207
+ includeInputUnlockingScripts: true,
208
+ includeOutputLockingScripts: true,
209
+ includeLabels: true
210
+ })
211
+ const totalInputSatoshis = spendingActionsResult.actions[0]?.inputs?.reduce(
212
+ (sum, input) => sum + input.sourceSatoshis,
213
+ 0
214
+ )
215
+ const expectedChange = totalInputSatoshis! - outputSatoshis - estimatedFee
216
+ const outputs = spendingActionsResult.actions[0]?.outputs || []
217
+ const changeOutput = outputs.find(output => output.basket === 'default')
218
+ expect(changeOutput!.satoshis).toBe(expectedChange)
219
+ const actualFee = totalInputSatoshis! - outputSatoshis - expectedChange
220
+ expect(actualFee).toBe(estimatedFee)
221
+ const rl1 = toLogString(spendingResult.tx!, spendingActionsResult)
222
+ expect(rl1.log).toBe(`transactions:5
223
+ txid:afa6713aab0957cf5bb00dee532ad7b895e919a99564ec2016b51cb3d472d87f version:1 lockTime:0 sats:1 status:nosend
224
+ outgoing:true desc:'Explicit check on returned change' labels:['spending transaction test']
225
+ inputs: 2
226
+ 0: sourceTXID:527ffe88f70d5b7de2b8b5ba9966b9c755e7da4de749d4fcd27140a03145a11d.0 sats:995
227
+ lock:(50)76a914ab2b66432503a3681fc5af1502207ca458c8752d88ac
228
+ unlock:(214)483045022100973a84555fa864e08313bda5c88e1991094db7b8d82586c899276155dabcbc9a0220... seq:4294967295
229
+ 1: sourceTXID:70afdc54187a1cdb8e35f7d00e5e111cbf5c43c4dc3f1da2cc44479133c75f9e.0 sats:4 desc:'Funding output'
230
+ lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac unlock:(16)47304402207f2e9a seq:4294967295
231
+ outputs: 2
232
+ 0: sats:2 lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac index:0 spendable:true desc:'First spending
233
+ Output for check on change '
234
+ 1: sats:996 lock:(50)76a9145947e66cdd43c70fb1780116b79e6f7d96e30e0888ac index:1 spendable:true basket:'default'`)
235
+ }
236
+ })
237
+
238
+ test('4_transaction with custom options knownTxids and returnTXIDOnly false uses toLogString', async () => {
239
+ for (const { wallet } of ctxs) {
240
+ wallet.randomVals = [0.1, 0.2, 0.3, 0.7, 0.8, 0.9]
241
+ const fundingOutputSatoshis = 4
242
+ const fundingArgs: CreateActionArgs = {
243
+ outputs: [
244
+ {
245
+ satoshis: fundingOutputSatoshis,
246
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
247
+ outputDescription: 'Funding output'
248
+ }
249
+ ],
250
+ description: 'Funding transaction',
251
+ options: { noSend: true, randomizeOutputs: false }
252
+ }
253
+ const fundingResult: CreateActionResult = await wallet.createAction(fundingArgs)
254
+ expect(fundingResult.tx).toBeDefined()
255
+ const spendingArgs: CreateActionArgs = {
256
+ description: 'Check knownTxids and returnTXIDOnly',
257
+ outputs: [
258
+ {
259
+ satoshis: 4,
260
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
261
+ outputDescription: 'returnTXIDOnly false test'
262
+ }
263
+ ],
264
+ labels: ['custom options test'],
265
+ options: {
266
+ knownTxids: ['tx123', 'tx456'],
267
+ returnTXIDOnly: false,
268
+ noSend: true,
269
+ randomizeOutputs: false
270
+ }
271
+ }
272
+ const spendingResult: CreateActionResult = await wallet.createAction(spendingArgs)
273
+ expect(spendingArgs.options!.knownTxids).toEqual(expect.arrayContaining(['tx123', 'tx456']))
274
+ const spendingActionsResult = await wallet.listActions({
275
+ labels: ['custom options test'],
276
+ includeInputs: true,
277
+ includeOutputs: true,
278
+ includeInputSourceLockingScripts: true,
279
+ includeInputUnlockingScripts: true,
280
+ includeOutputLockingScripts: true,
281
+ includeLabels: true
282
+ })
283
+ const rl1 = toLogString(spendingResult.tx!, spendingActionsResult)
284
+ expect(rl1.log).toBe(`transactions:2
285
+ txid:38ded69627603b30bd1f55eb3f88098dbf74f2ef0ff5e3cfe6a34f97ce2db9c2 version:1 lockTime:0 sats:-5 status:nosend
286
+ outgoing:true desc:'Check knownTxids and returnTXIDOnly' labels:['custom options test']
287
+ inputs: 1
288
+ 0: sourceTXID:527ffe88f70d5b7de2b8b5ba9966b9c755e7da4de749d4fcd27140a03145a11d.0 sats:995
289
+ lock:(50)76a914ab2b66432503a3681fc5af1502207ca458c8752d88ac
290
+ unlock:(212)4730440220113a6f72035a6ddcd6930db7e3f3d5c70486f9aaefb095e6fa3557afa916ec37022054... seq:4294967295
291
+ outputs: 2
292
+ 0: sats:4 lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac index:0 spendable:true desc:'returnTXIDOnly
293
+ false test'
294
+ 1: sats:990 lock:(50)76a9145947e66cdd43c70fb1780116b79e6f7d96e30e0888ac index:1 spendable:true basket:'default'`)
295
+ }
296
+ })
297
+
298
+ test('5_transaction with custom options knownTxids and returnTXIDOnly true', async () => {
299
+ for (const { wallet } of ctxs) {
300
+ wallet.randomVals = [0.1, 0.2, 0.3, 0.7, 0.8, 0.9]
301
+ const fundingOutputSatoshis = 4
302
+ const fundingArgs: CreateActionArgs = {
303
+ outputs: [
304
+ {
305
+ satoshis: fundingOutputSatoshis,
306
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
307
+ outputDescription: 'Funding output'
308
+ }
309
+ ],
310
+ description: 'Funding transaction',
311
+ options: { noSend: true }
312
+ }
313
+ const fundingResult: CreateActionResult = await wallet.createAction(fundingArgs)
314
+ expect(fundingResult.tx).toBeDefined()
315
+ const spendingArgs: CreateActionArgs = {
316
+ description: 'Check knownTxids and returnTXIDOnly',
317
+ outputs: [
318
+ {
319
+ satoshis: 4,
320
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
321
+ outputDescription: 'returnTXIDOnly true test'
322
+ }
323
+ ],
324
+ labels: ['custom options test'],
325
+ options: {
326
+ knownTxids: ['tx123', 'tx456'],
327
+ returnTXIDOnly: true,
328
+ noSend: true
329
+ }
330
+ }
331
+ const spendingResult: CreateActionResult = await wallet.createAction(spendingArgs)
332
+ expect(spendingResult.tx).not.toBeDefined()
333
+ expect(spendingArgs.options!.knownTxids).toEqual(expect.arrayContaining(['tx123', 'tx456']))
334
+ }
335
+ })
336
+
337
+ test('6_transaction with custom options knownTxids check returned BeefParty txids', async () => {
338
+ for (const { wallet } of ctxs) {
339
+ wallet.autoKnownTxids = true
340
+ wallet.randomVals = [0.1, 0.2, 0.3, 0.7, 0.8, 0.9]
341
+ const fundingOutputSatoshis = 4
342
+ const fundingArgs: CreateActionArgs = {
343
+ outputs: [
344
+ {
345
+ satoshis: fundingOutputSatoshis,
346
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
347
+ outputDescription: 'Funding Output'
348
+ }
349
+ ],
350
+ description: 'Funding transaction',
351
+ options: { noSend: true }
352
+ }
353
+ const fundingResult: CreateActionResult = await wallet.createAction(fundingArgs)
354
+ expect(fundingResult.tx).toBeDefined()
355
+ const spendingArgs: CreateActionArgs = {
356
+ description: 'Check knownTxids txids',
357
+ outputs: [
358
+ {
359
+ satoshis: 4,
360
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
361
+ outputDescription: 'Output for check txids'
362
+ }
363
+ ],
364
+ labels: ['custom options test'],
365
+ options: {
366
+ knownTxids: ['tx123', 'tx456'],
367
+ returnTXIDOnly: true,
368
+ noSend: true
369
+ }
370
+ }
371
+ const spendingResult: CreateActionResult = await wallet.createAction(spendingArgs)
372
+ expect(spendingResult).toBeDefined()
373
+ expect(spendingArgs.options!.knownTxids).toEqual(expect.arrayContaining(['tx123', 'tx456']))
374
+ const fundingBeef = Beef.fromBinary(fundingResult.tx!)
375
+ expect(fundingBeef).toBeDefined()
376
+ const BeefPartyTxids = fundingBeef.txs.map(tx => tx.txid)
377
+ const expectedTxids = ['tx123', 'tx456']
378
+ if (spendingArgs.options?.knownTxids) {
379
+ expect(spendingArgs.options!.knownTxids?.sort()).toEqual(expectedTxids.sort())
380
+ }
381
+ }
382
+ })
383
+
384
+ test('7_transaction with custom options knownTxids check returned BeefParty txids with additional spend', async () => {
385
+ for (const { wallet } of ctxs) {
386
+ wallet.autoKnownTxids = true
387
+ wallet.randomVals = [0.1, 0.2, 0.3, 0.7, 0.8, 0.9]
388
+ const fundingOutputSatoshis = 4
389
+ const fundingArgs: CreateActionArgs = {
390
+ outputs: [
391
+ {
392
+ satoshis: fundingOutputSatoshis,
393
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
394
+ outputDescription: 'Funding Output'
395
+ }
396
+ ],
397
+ description: 'Funding transaction',
398
+ options: { noSend: true }
399
+ }
400
+ const fundingResult: CreateActionResult = await wallet.createAction(fundingArgs)
401
+ expect(fundingResult.tx).toBeDefined()
402
+ const spendingArgs: CreateActionArgs = {
403
+ description: 'Check knownTxids txids extra',
404
+ outputs: [
405
+ {
406
+ satoshis: 4,
407
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
408
+ outputDescription: 'Output for check txids extra'
409
+ }
410
+ ],
411
+ options: {
412
+ knownTxids: ['tx123', 'tx456'],
413
+ returnTXIDOnly: false,
414
+ noSend: true
415
+ }
416
+ }
417
+ const spendingResult: CreateActionResult = await wallet.createAction(spendingArgs)
418
+ expect(spendingResult).toBeDefined()
419
+ expect(spendingArgs.options!.knownTxids).toEqual(expect.arrayContaining(['tx123', 'tx456']))
420
+ const fundingBeef = Beef.fromBinary(fundingResult.tx!)
421
+ expect(fundingBeef).toBeDefined()
422
+ const partyBeefTxids = fundingBeef.txs.map(tx => tx.txid)
423
+ const expectedTxids = ['tx123', 'tx456']
424
+ expect(spendingArgs.options!.knownTxids?.sort()).toEqual(expectedTxids.sort())
425
+ const additionalSpendArgs: CreateActionArgs = {
426
+ description: 'Extra spend transaction',
427
+ outputs: [
428
+ {
429
+ satoshis: 4,
430
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
431
+ outputDescription: 'Extra spend output'
432
+ }
433
+ ],
434
+ labels: ['extra spend test'],
435
+ options: {
436
+ knownTxids: spendingArgs.options!.knownTxids,
437
+ returnTXIDOnly: true,
438
+ noSend: true
439
+ }
440
+ }
441
+ const additionalSpendResult: CreateActionResult = await wallet.createAction(additionalSpendArgs)
442
+ expect(additionalSpendResult).toBeDefined()
443
+ const finalBeef = Beef.fromBinary(spendingResult.tx!)
444
+ expect(finalBeef).toBeDefined()
445
+ const finalPartyBeefTxids = finalBeef.txs.map(tx => tx.txid)
446
+ const finalExpectedTxids = [...expectedTxids]
447
+ expect(additionalSpendArgs.options!.knownTxids?.sort()).toEqual(finalExpectedTxids.sort())
448
+ }
449
+ })
450
+
451
+ /* WIP
452
+
453
+ test('8_no-send transaction with zero satoshis output', async () => {
454
+ for (const { wallet, activeStorage: storage } of ctxs) {
455
+ const args: CreateActionArgs = {
456
+ outputs: [
457
+ {
458
+ satoshis: 0,
459
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
460
+ outputDescription: 'Invalid output'
461
+ }
462
+ ],
463
+ description: 'Valid transaction',
464
+ options: {
465
+ returnTXIDOnly: false,
466
+ randomizeOutputs: false,
467
+ noSend: true
468
+ }
469
+ }
470
+ const result: CreateActionResult = await wallet.createAction(args)
471
+ expect(result.tx).toBeDefined()
472
+ expect(result.signableTransaction).toBeUndefined()
473
+ }
474
+ })
475
+
476
+ test('9_no-send transaction without auth (should fail)', async () => {
477
+ for (const { wallet, activeStorage: storage } of ctxs) {
478
+ const args: CreateActionArgs = {
479
+ outputs: [
480
+ {
481
+ satoshis: 5,
482
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
483
+ outputDescription: 'Valid output'
484
+ }
485
+ ],
486
+ description: 'Valid transaction',
487
+ options: {
488
+ returnTXIDOnly: false,
489
+ randomizeOutputs: false,
490
+ noSend: true
491
+ }
492
+ }
493
+ await expect(wallet.createAction(args, undefined)).rejects.toThrow()
494
+ }
495
+ })
496
+
497
+ test('10_no-send transaction with malformed args (invalid destination)', async () => {
498
+ for (const { wallet, activeStorage: storage } of ctxs) {
499
+ const args: CreateActionArgs = {
500
+ outputs: [
501
+ {
502
+ satoshis: 6,
503
+ lockingScript: 'invalid_script',
504
+ outputDescription: 'Valid output'
505
+ }
506
+ ],
507
+ description: 'Valid transaction',
508
+ options: {
509
+ noSend: true
510
+ }
511
+ }
512
+ await expect(wallet.createAction(args)).rejects.toThrow()
513
+ }
514
+ })
515
+
516
+ test('11_transaction with OP_RETURN', async () => {
517
+ for (const { wallet, activeStorage: storage } of ctxs) {
518
+ const args: CreateActionArgs = {
519
+ outputs: [
520
+ {
521
+ satoshis: 0,
522
+ lockingScript: '6a0c48656c6c6f20576f726c64',
523
+ outputDescription: 'OP_RETURN data'
524
+ }
525
+ ],
526
+ description: 'Transaction embedding OP_RETURN data',
527
+ options: { noSend: true }
528
+ }
529
+ const result: CreateActionResult = await wallet.createAction(args)
530
+ expect(result.tx).toBeDefined()
531
+ expect(result.signableTransaction).toBeUndefined()
532
+ }
533
+ })
534
+
535
+ test('12_high fee transaction', async () => {
536
+ for (const { wallet, activeStorage: storage } of ctxs) {
537
+ const args: CreateActionArgs = {
538
+ inputs: [
539
+ {
540
+ outpoint: 'tx4.0',
541
+ unlockingScript: '47304402207f2e9a',
542
+ inputDescription: 'desc4'
543
+ }
544
+ ],
545
+ outputs: [
546
+ {
547
+ satoshis: 950,
548
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
549
+ outputDescription: 'Output D'
550
+ }
551
+ ],
552
+ description:
553
+ 'Transaction that results in high fees (insufficient change)',
554
+ options: { noSend: true }
555
+ }
556
+ await expect(wallet.createAction(args)).rejects.toThrow(
557
+ /WERR_INSUFFICIENT_FUNDS/
558
+ )
559
+ }
560
+ })
561
+
562
+ test('13_zero fee transaction', async () => {
563
+ for (const { wallet, activeStorage: storage } of ctxs) {
564
+ const args: CreateActionArgs = {
565
+ inputs: [
566
+ {
567
+ outpoint: 'tx5.0',
568
+ unlockingScript: '47304402207f2e9a',
569
+ inputDescription: 'desc5'
570
+ }
571
+ ],
572
+ outputs: [
573
+ {
574
+ satoshis: 500,
575
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
576
+ outputDescription: 'Output E'
577
+ }
578
+ ],
579
+ description: 'Zero-fee transaction attempt',
580
+ options: { noSend: true }
581
+ }
582
+ await expect(wallet.createAction(args)).rejects.toThrow(
583
+ /WERR_INSUFFICIENT_FUNDS/
584
+ )
585
+ }
586
+ })
587
+
588
+ test('14_dust transaction', async () => {
589
+ for (const { wallet, activeStorage: storage } of ctxs) {
590
+ const args: CreateActionArgs = {
591
+ outputs: [
592
+ {
593
+ satoshis: 1,
594
+ lockingScript: '76a914abcdef0123456789abcdef0123456789abcdef88ac',
595
+ outputDescription: 'Dust output'
596
+ }
597
+ ],
598
+ description: 'Transaction with dust output',
599
+ options: { noSend: true }
600
+ }
601
+ await expect(wallet.createAction(args)).rejects.toThrow(
602
+ /WERR_INVALID_PARAMETER/
603
+ )
604
+ }
605
+ })
606
+ */
607
+ })
608
+
609
+ // Helper functions
610
+
611
+ function getExpectedLog(testName: string, logFilePath: string): { log: string; logColor: string } | null {
612
+ if (!fs.existsSync(logFilePath)) {
613
+ return null
614
+ }
615
+
616
+ const fileContent = fs.readFileSync(logFilePath, 'utf8')
617
+ const sanitizedTestName = sanitizeTestName(testName)
618
+
619
+ // Use regex to extract the correct log constant
620
+ const logRegex = new RegExp(
621
+ `const\\s+${sanitizedTestName}\\s*=\\s*\\{\\s*log:\\s*['\`]([\\s\\S]*?)['\`]\\s*,\\s*logColor:\\s*['\`]([\\s\\S]*?)['\`]\\s*\\}`,
622
+ 'm'
623
+ )
624
+ const match = fileContent.match(logRegex)
625
+
626
+ if (match) {
627
+ return { log: match[1], logColor: match[2] }
628
+ }
629
+ return null
630
+ }
631
+
632
+ const normalizeVariableParts = (log: string): string => {
633
+ return log
634
+ .replace(/txid:[a-f0-9]{64}/g, 'txid:PLACEHOLDER') // Replace txids
635
+ .replace(/unlock:\(\d+\)(?:483045022100[a-f0-9]{64}0220|[a-f0-9]+)/g, 'unlock:PLACEHOLDER')
636
+ .replace(/lock:\(\d+\)76a914[a-f0-9]{40}/g, 'lock:PLACEHOLDER') // Replace locking script
637
+ .replace(/index:\d+ spendable:/g, 'index:PLACEHOLDER spendable:') // Normalize index
638
+ .trim()
639
+ }
640
+
641
+ /**
642
+ * Appends logs as a constant to a test file.
643
+ * @param {string} testName - The name of the test.
644
+ * @param {{ log: string; logColor: string }} rl - The log data.
645
+ */
646
+ function appendLogsAsConst(testName: string, rl: { log: string; logColor: string }) {
647
+ const normalizedTestName = testName
648
+ .replace(/[^a-zA-Z0-9_ ]/g, '')
649
+ .trim()
650
+ .replace(/\s+/g, '_')
651
+ const sanitizedTestName = sanitizeTestName(normalizedTestName)
652
+ const logFilePath = path.resolve(__dirname, 'createAction2.man.test.ts')
653
+ const logConst = `
654
+ // Auto-generated test log - ${new Date().toISOString()}
655
+ const ${sanitizedTestName} = {
656
+ log: \`${rl.log}\`,
657
+ logColor: \`${rl.logColor}\`
658
+ };
659
+ `.trim()
660
+
661
+ fs.appendFileSync(logFilePath, `\n${logConst}\n`, 'utf8')
662
+ }
663
+
664
+ /**
665
+ * Truncates a string to a maximum length of 80 characters.
666
+ * @param {string} s - The string to truncate.
667
+ * @returns {string} - The truncated string.
668
+ */ const truncate = (s: string) => (s.length > 80 ? s.slice(0, 80) + '...' : s)
669
+
670
+ /**
671
+ * Formats an optional field if it has a defined value.
672
+ * @param {string} fieldName - The name of the field.
673
+ * @param {any} value - The value of the field.
674
+ * @returns {string} - The formatted field string.
675
+ */
676
+ const formatOptionalField = (fieldName: string, value: any) =>
677
+ value !== undefined && value !== null && value !== '' ? ` ${fieldName}:${value}` : ''
678
+
679
+ /**
680
+ * Formats an optional field with quotes if it has a defined value.
681
+ * @param {string} fieldName - The name of the field.
682
+ * @param {any} value - The value of the field.
683
+ * @returns {string} - The formatted field string with quotes.
684
+ */
685
+ const formatOptionalFieldWithQuotes = (fieldName: string, value: any) =>
686
+ value !== undefined && value !== null && value !== '' ? ` ${fieldName}:'${value}'` : ''
687
+
688
+ /**
689
+ * Formats an optional field with color if it has a defined value.
690
+ * @param {string} fieldName - The name of the field.
691
+ * @param {any} value - The value of the field.
692
+ * @param {(val: string) => string} colorFunc - The function to apply color formatting.
693
+ * @returns {string} - The formatted field string with color.
694
+ */
695
+ const formatOptionalFieldWithColor = (fieldName: string, value: any, colorFunc: (val: string) => string) =>
696
+ value !== undefined && value !== null && value !== ''
697
+ ? ` ${chalk.gray(fieldName + ':')}${colorFunc(typeof value === 'string' ? value : String(value))}`
698
+ : ''
699
+
700
+ /**
701
+ * Formats metadata if present.
702
+ * @param {any} metadata - The metadata object.
703
+ * @returns {string} - The formatted metadata string.
704
+ */
705
+ const formatMetadata = (metadata?: any) =>
706
+ metadata && !isEmptyObject(metadata) ? `metadata:${JSON.stringify(metadata)}` : ''
707
+
708
+ /**
709
+ * Formats the Merkle path if present.
710
+ * @param {MerklePath | string} [merklePath] - The Merkle path.
711
+ * @returns {string} - The formatted Merkle path string.
712
+ */
713
+ const formatMerklePath = (merklePath?: MerklePath | string) => (merklePath ? `merklePath:${String(merklePath)}` : '')
714
+
715
+ const MAX_LOG_LINE_LENGTH = 120 // Define in the test
716
+
717
+ /**
718
+ * Wraps a log line to a specified max length.
719
+ * @param {string} text - The text to wrap.
720
+ * @param {number} indent - The indentation level.
721
+ * @param {number} [maxLength=120] - The maximum length of a line.
722
+ * @returns {string} - The wrapped log line.
723
+ */
724
+ const wrapLogLine = (text: string, indent: number, maxLength: number = 120): string => {
725
+ const words = text.trim().split(' ')
726
+ let wrappedText = ' '.repeat(indent)
727
+ let currentLineLength = indent * 2
728
+
729
+ for (const word of words) {
730
+ if (currentLineLength + word.length + 1 > maxLength) {
731
+ wrappedText += '\n' + ' '.repeat(indent) + ' ' + word + ' '
732
+ currentLineLength = indent * 2 + word.length + 1
733
+ } else {
734
+ wrappedText += word + ' '
735
+ currentLineLength += word.length + 1
736
+ }
737
+ }
738
+
739
+ return wrappedText.trimEnd()
740
+ }
741
+
742
+ /**
743
+ * Formats an indented line.
744
+ * @param {number} indent - The indentation level.
745
+ * @param {string} content - The content of the line.
746
+ * @returns {string} - The formatted indented line.
747
+ */
748
+ const formatIndentedLineWithWrap = (indent: number, content: string, maxLength: number = 120) =>
749
+ wrapLogLine(content.trim(), indent, maxLength)
750
+
751
+ /**
752
+ * Formats a list of wallet action inputs for logging.
753
+ * @param {WalletActionInput[]} [inputs] - The list of wallet action inputs.
754
+ * @returns {{ log: string; logColor: string }[]} - An array of formatted log strings and their colorized versions.
755
+ */
756
+ const formatInputs = (inputs: WalletActionInput[]) =>
757
+ inputs && inputs.length > 0
758
+ ? inputs
759
+ .sort((a, b) => a.sourceOutpoint.localeCompare(b.sourceOutpoint))
760
+ .map((input, i) => {
761
+ let line = `${i}: sourceTXID:${input.sourceOutpoint} sats:${input.sourceSatoshis}`
762
+ let color = `${chalk.gray(`${i}:`)} ${chalk.blue(input.sourceOutpoint)} ${chalk.green(`${input.sourceSatoshis} sats`)}`
763
+
764
+ line += formatOptionalFieldWithQuotes('desc', input.inputDescription)
765
+ color += formatOptionalFieldWithColor('desc', input.inputDescription, chalk.white)
766
+
767
+ if (input.sourceLockingScript) {
768
+ line += ` lock:(${input.sourceLockingScript.length})${truncate(input.sourceLockingScript)}`
769
+ color += ` ${chalk.gray('lock:')}(${input.sourceLockingScript.length})${chalk.cyan(truncate(input.sourceLockingScript))}`
770
+ }
771
+
772
+ if (input.unlockingScript) {
773
+ line += ` unlock:(${input.unlockingScript.length})${truncate(input.unlockingScript)}`
774
+ color += ` ${chalk.gray('unlock:')}(${input.unlockingScript.length})${chalk.cyan(truncate(input.unlockingScript))}`
775
+ }
776
+
777
+ line += ` seq:${input.sequenceNumber}`
778
+ color += ` ${chalk.gray('seq:')}${input.sequenceNumber}`
779
+
780
+ return {
781
+ log: formatIndentedLineWithWrap(2, line),
782
+ logColor: formatIndentedLineWithWrap(2, color)
783
+ }
784
+ })
785
+ : [
786
+ {
787
+ log: formatIndentedLineWithWrap(2, 'No inputs'),
788
+ logColor: formatIndentedLineWithWrap(2, chalk.gray('No inputs'))
789
+ }
790
+ ]
791
+
792
+ /**
793
+ * Formats a list of wallet action outputs for logging.
794
+ * @param {WalletActionOutput[]} [outputs] - The list of wallet action outputs.
795
+ * @returns {{ log: string; logColor: string }[]} - An array of formatted log strings and their colorized versions.
796
+ */
797
+ const formatOutputs = (outputs: WalletActionOutput[]) =>
798
+ outputs && outputs.length > 0
799
+ ? outputs
800
+ .sort((a, b) => a.satoshis - b.satoshis)
801
+ .map((output, i) => {
802
+ let line = `${i}: sats:${output.satoshis} lock:(${output.lockingScript?.length || ''})${truncate(output.lockingScript!) ?? 'N/A'}`
803
+ let color = `${chalk.gray(`${i}:`)} ${chalk.green(`${output.satoshis} sats`)} ${chalk.gray('lock:')}(${output.lockingScript?.length || ''})${chalk.cyan(truncate(output.lockingScript!) ?? 'N/A')}`
804
+
805
+ line += formatOptionalField('index', output.outputIndex)
806
+ color += formatOptionalFieldWithColor('index', output.outputIndex, chalk.white)
807
+
808
+ line += formatOptionalField('spendable', output.spendable)
809
+ color += formatOptionalFieldWithColor('spendable', output.spendable, chalk.white)
810
+
811
+ line += formatOptionalFieldWithQuotes('custinst', output.customInstructions)
812
+ color += formatOptionalFieldWithColor('custinst', output.customInstructions, chalk.white)
813
+
814
+ line += formatOptionalFieldWithQuotes('basket', output.basket)
815
+ color += formatOptionalFieldWithColor('basket', output.basket, chalk.white)
816
+
817
+ line += formatOptionalFieldWithQuotes('desc', output.outputDescription)
818
+ color += formatOptionalFieldWithColor('desc', output.outputDescription, chalk.white)
819
+
820
+ if (output.tags?.length) {
821
+ const tagsString = `[${output.tags.map(tag => `'${truncate(tag)}'`).join(',')}]`
822
+ line += ` tags:${tagsString}`
823
+ color += ` ${chalk.gray('tags:')}${chalk.white(tagsString)}`
824
+ }
825
+
826
+ return {
827
+ log: formatIndentedLineWithWrap(2, line),
828
+ logColor: formatIndentedLineWithWrap(2, color)
829
+ }
830
+ })
831
+ : [
832
+ {
833
+ log: formatIndentedLineWithWrap(2, 'No outputs'),
834
+ logColor: formatIndentedLineWithWrap(2, chalk.gray('No outputs'))
835
+ }
836
+ ]
837
+
838
+ /**
839
+ * Formats a list of labels into a string representation.
840
+ * @param {string[]} [labels] - The list of labels.
841
+ * @returns {string} - A formatted string of labels enclosed in brackets.
842
+ */
843
+ const formatLabels = (labels?: string[]) =>
844
+ labels && labels.length > 0 ? `[${labels.map(label => `'${truncate(label)}'`).join(',')}]` : ''
845
+
846
+ /**
847
+ * Generates a formatted log string from an AtomicBEEF object.
848
+ * @param {AtomicBEEF} atomicBeef - The AtomicBEEF object containing transaction data.
849
+ * @param {ListActionsResult} [actionsResult] - The result of listing actions, used for additional transaction metadata.
850
+ * @param {boolean} [showKey=true] - Whether to display key transaction details.
851
+ * @returns {Promise<{ log: string; logColor: string }>} - An object containing the formatted log string and a colorized version.
852
+ */
853
+ export function toLogString(
854
+ atomicBeef: AtomicBEEF,
855
+ actionsResult?: ListActionsResult,
856
+ showKey: boolean = true
857
+ ): { log: string; logColor: string } {
858
+ const BEEF_V1 = 4022206465
859
+
860
+ try {
861
+ const beef = Beef.fromBinary(atomicBeef)
862
+ beef.version = BEEF_V1
863
+
864
+ let log = `transactions:${beef.txs.length}`
865
+ let logColor = chalk.gray(`transactions:${beef.txs.length}`)
866
+
867
+ if (showKey) {
868
+ logColor += ` ${chalk.gray(`key:`)} (${chalk.blue('txid/outpoint')} ${chalk.cyan('script')} ${chalk.green('sats')})`
869
+ }
870
+
871
+ const mainTxid = beef.txs.slice(-1)[0].txid
872
+ const mainTx: Transaction = beef.findAtomicTransaction(mainTxid)!
873
+
874
+ const action = actionsResult?.actions.find(a => a.txid === mainTxid)
875
+
876
+ const labelString = formatLabels(action?.labels)
877
+ const metadataString = formatMetadata(mainTx.metadata)
878
+ const merklePathString = formatMerklePath(mainTx.merklePath)
879
+
880
+ log += `\n${formatIndentedLineWithWrap(1, `txid:${mainTxid} version:${mainTx.version} lockTime:${mainTx.lockTime}${formatOptionalField('sats', action?.satoshis)}${formatOptionalField('status', action?.status)}${formatOptionalField('outgoing', action?.isOutgoing)}${formatOptionalFieldWithQuotes('desc', action?.description)}${metadataString}${merklePathString} labels:${labelString}`)}`
881
+ logColor += `\n${formatIndentedLineWithWrap(
882
+ 1,
883
+ [
884
+ chalk.blue(mainTxid),
885
+ ` ${chalk.gray('version:')}${mainTx.version}`,
886
+ ` ${chalk.gray('lockTime:')}${mainTx.lockTime}`,
887
+ ` ${chalk.green(`${action?.satoshis} sats`)}`,
888
+ formatOptionalFieldWithColor('status', action?.status, chalk.white),
889
+ formatOptionalFieldWithColor('outgoing', action?.isOutgoing, chalk.white),
890
+ formatOptionalFieldWithColor('desc', action?.description, chalk.white),
891
+ metadataString ? chalk.gray(metadataString) : '',
892
+ merklePathString ? chalk.gray(merklePathString) : '',
893
+ ` ${chalk.gray('labels:')}${chalk.white(labelString)}`
894
+ ]
895
+ .filter(Boolean)
896
+ .join('')
897
+ )}`
898
+
899
+ log += `\n${formatIndentedLine(1, `inputs: ${action?.inputs?.length ?? 0}`)}`
900
+ logColor += `\n${formatIndentedLine(1, chalk.gray(`inputs: ${action?.inputs?.length ?? 0}`))}`
901
+
902
+ const sortedInputs = (action?.inputs ?? []).sort((a, b) => a.sourceOutpoint.localeCompare(b.sourceOutpoint))
903
+ const formattedInputs = formatInputs(sortedInputs)
904
+ formattedInputs.forEach(({ log: inputLog, logColor: inputLogColor }) => {
905
+ log += `\n${formatIndentedLine(2, inputLog)}`
906
+ logColor += `\n${formatIndentedLine(2, inputLogColor)}`
907
+ })
908
+
909
+ log += `\n${formatIndentedLineWithWrap(1, `outputs: ${action?.outputs?.length ?? 0}`)}`
910
+ logColor += `\n${formatIndentedLineWithWrap(1, chalk.gray(`outputs: ${action?.outputs?.length ?? 0}`))}`
911
+
912
+ const sortedOutputs = action?.outputs?.slice().sort((a, b) => a.satoshis - b.satoshis)
913
+ const formattedOutputs = formatOutputs(sortedOutputs!)
914
+ formattedOutputs.forEach(({ log: outputLog, logColor: outputLogColor }) => {
915
+ log += `\n${formatIndentedLine(2, outputLog)}`
916
+ logColor += `\n${formatIndentedLine(2, outputLogColor)}`
917
+ })
918
+
919
+ return { log, logColor }
920
+ } catch (error) {
921
+ return {
922
+ log: `Error parsing transaction: ${(error as Error).message}`,
923
+ logColor: chalk.red(`Error parsing transaction: ${(error as Error).message}`)
924
+ }
925
+ }
926
+ }
927
+
928
+ export function createActionResultToTxLogString(
929
+ createActionResult: CreateActionResult,
930
+ actionsResult?: ListActionsResult,
931
+ showKey: boolean = false
932
+ ): { log: string; logColor: string } {
933
+ const BEEF_V1 = 4022206465
934
+
935
+ const beef = Beef.fromBinary(createActionResult?.tx!)
936
+ beef.version = BEEF_V1
937
+ const mainTxid = beef.txs.slice(-1)[0].txid
938
+
939
+ return txToLogString(beef.findAtomicTransaction(mainTxid)!, 0, showKey, actionsResult)
940
+ }
941
+
942
+ const MAX_RECURSION_DEPTH = 3
943
+
944
+ /**
945
+ * Truncates a TXID, replacing the middle 48 characters with '...'.
946
+ * @param {string} txid - The original transaction ID.
947
+ * @returns {string} - The truncated TXID.
948
+ */
949
+ const truncateTxid = (txid: string): string => {
950
+ if (txid.length <= 64) {
951
+ return txid.slice(0, 8) + '...' + txid.slice(-8)
952
+ }
953
+ return txid
954
+ }
955
+
956
+ /**
957
+ * Formats a list of transaction outputs for logging.
958
+ * @param {TransactionOutput[]} [outputs] - The list of transaction outputs.
959
+ * @param {number} indent - The current indentation level.
960
+ * @returns {{ log: string; logColor: string }[]} - A formatted log string array.
961
+ */
962
+ const formatTxOutputs = (outputs: TransactionOutput[], indent: number) =>
963
+ outputs && outputs.length > 0
964
+ ? outputs
965
+ .sort((a, b) => a.satoshis! - b.satoshis!)
966
+ .map((output, i) => {
967
+ let line = formatIndentedLine(
968
+ indent + 4,
969
+ `${i}: lock:(${output.lockingScript.toHex().length || ''})${truncate(output.lockingScript.toHex())}`
970
+ )
971
+ let color = formatIndentedLine(
972
+ indent + 4,
973
+ `${chalk.gray(`${i}:`)} ${chalk.gray('lock:')}(${output.lockingScript.toHex().length || ''})${chalk.cyan(truncate(output.lockingScript.toHex()))}`
974
+ )
975
+
976
+ if (output.satoshis) {
977
+ line += ` sats:${output.satoshis}`
978
+ color += ` ${chalk.green(`${output.satoshis} sats`)}`
979
+ }
980
+
981
+ return { log: line, logColor: color }
982
+ })
983
+ : [
984
+ {
985
+ log: formatIndentedLine(indent + 4, 'No outputs'),
986
+ logColor: formatIndentedLine(indent + 4, chalk.gray('No outputs'))
987
+ }
988
+ ]
989
+
990
+ /**
991
+ * Formats transaction inputs with proper indentation.
992
+ * @param {TransactionInput[]} inputs - The list of transaction inputs.
993
+ * @param {number} indent - The current indentation level.
994
+ * @returns {{ log: string; logColor: string }[]} - A formatted log string array.
995
+ */
996
+ const formatTxInputs = (inputs: TransactionInput[], indent: number) =>
997
+ inputs && inputs.length > 0
998
+ ? inputs
999
+ .sort((a, b) => a.sourceTXID!.localeCompare(b.sourceTXID!))
1000
+ .map((input, i) => {
1001
+ let line = formatIndentedLine(
1002
+ indent + 4,
1003
+ `${i}: sourceTXID:${truncateTxid(input.sourceTXID!)}.${input.sourceOutputIndex}`
1004
+ )
1005
+ let color = formatIndentedLine(
1006
+ indent + 4,
1007
+ `${chalk.gray(`${i}:`)} ${chalk.blue(truncateTxid(input.sourceTXID!))}.${chalk.blue(input.sourceOutputIndex)}`
1008
+ )
1009
+
1010
+ if (input.unlockingScript) {
1011
+ line += `\n${formatIndentedLine(indent + 6, `unlock:(${input.unlockingScript.toHex().length})${truncate(input.unlockingScript.toHex())}`)}`
1012
+ color += `\n${formatIndentedLine(indent + 6, `${chalk.gray('unlock:')}(${input.unlockingScript.toHex().length})${chalk.cyan(truncate(input.unlockingScript.toHex()))}`)}`
1013
+ }
1014
+
1015
+ if (input.sequence) {
1016
+ line += `\n${formatIndentedLine(indent + 6, `seq:${input.sequence}`)}`
1017
+ color += `\n${formatIndentedLine(indent + 6, `${chalk.gray('seq:')}${input.sequence}`)}`
1018
+ }
1019
+
1020
+ if (input.sourceTransaction) {
1021
+ const { log: sourceTxLog, logColor: sourceTxLogColor } = txToLogString(input.sourceTransaction, indent + 6)
1022
+ const sourceTxLogTrimed = sourceTxLog.replace(/\s+Transaction/, 'Transaction')
1023
+ const sourceTxLogColorTrimed = sourceTxLogColor.replace(/\s+Transaction/, 'Transaction')
1024
+ line += `\n${formatIndentedLine(indent + 6, `sourceTx:`)}${sourceTxLogTrimed}`
1025
+ color += `\n${formatIndentedLine(indent + 6, `${chalk.gray('sourceTx:')}`)}${sourceTxLogColorTrimed}`
1026
+ } else {
1027
+ line += `\n${formatIndentedLine(indent + 6, `sourceTx:Transaction [Max Depth Reached]`)}`
1028
+ color += `\n${formatIndentedLine(indent + 6, chalk.gray(`sourceTx:Transaction [Max Depth Reached]`))}`
1029
+ }
1030
+
1031
+ return { log: line, logColor: color }
1032
+ })
1033
+ : [
1034
+ {
1035
+ log: formatIndentedLine(indent + 4, 'No inputs'),
1036
+ logColor: formatIndentedLine(indent + 4, chalk.gray('No inputs'))
1037
+ }
1038
+ ]
1039
+
1040
+ /**
1041
+ * Generates a formatted log string from a Transaction object.
1042
+ * Ensures proper indentation and prevents recursion errors.
1043
+ * @param {Transaction} tx - The Transaction object containing transaction data.
1044
+ * @param {number} indent - The current indentation level.
1045
+ * @param {boolean} [showKey=true] - Whether to display key transaction details.
1046
+ * @param {ListActionsResult} [actionsResult] - The result of listing actions.
1047
+ * @returns {{ log: string; logColor: string }} - A formatted log string and colorized version.
1048
+ */
1049
+ export function txToLogString(
1050
+ tx: Transaction,
1051
+ indent: number = 0,
1052
+ showKey: boolean = false,
1053
+ actionsResult?: ListActionsResult
1054
+ ): { log: string; logColor: string } {
1055
+ try {
1056
+ if (indent / 2 >= MAX_RECURSION_DEPTH) {
1057
+ return {
1058
+ log: formatIndentedLine(indent + 4, 'Transaction [Max Depth Reached]'),
1059
+ logColor: chalk.gray(formatIndentedLine(indent + 4, 'Transaction [Max Depth Reached]'))
1060
+ }
1061
+ }
1062
+ const beef = Beef.fromBinary(tx.toBEEF())
1063
+ const mainTxid = beef.txs.slice(-1)[0].txid
1064
+ const metadataString = formatMetadata(tx.metadata)
1065
+ const merklePathString = formatMerklePath(tx.merklePath)
1066
+ let log = formatIndentedLine(indent, `Transaction:${truncateTxid(mainTxid)}`)
1067
+ let logColor = formatIndentedLine(indent, `${chalk.gray('Transaction:')}${chalk.blue(truncateTxid(mainTxid))}`)
1068
+
1069
+ if (showKey) {
1070
+ logColor += ` ${chalk.gray(`key:`)} (${chalk.blue('txid/outpoint')} ${chalk.cyan('script')} ${chalk.green('sats')})`
1071
+ }
1072
+
1073
+ log += `\n${formatIndentedLine(indent + 2, `version:${tx.version} lockTime:${tx.lockTime}${metadataString}${merklePathString}`)}`
1074
+ logColor += `\n${formatIndentedLine(
1075
+ indent + 2,
1076
+ `${chalk.gray('version:')}${chalk.white(tx.version)} ${chalk.gray('lockTime:')}${chalk.white(tx.lockTime)}` +
1077
+ (metadataString ? chalk.gray(metadataString) : '') +
1078
+ (merklePathString ? chalk.gray(merklePathString) : '')
1079
+ )}`
1080
+
1081
+ log += `\n${formatIndentedLine(indent + 2, `inputs: ${tx?.inputs?.length ?? 0}`)}`
1082
+ logColor += `\n${formatIndentedLine(indent + 2, chalk.gray(`inputs: ${tx?.inputs?.length ?? 0}`))}`
1083
+
1084
+ const sortedInputs = (tx?.inputs ?? []).sort((a, b) => a.sourceTXID!.localeCompare(b.sourceTXID!))
1085
+ const formattedInputs = formatTxInputs(sortedInputs, indent)
1086
+ formattedInputs.forEach(({ log: inputLog, logColor: inputLogColor }) => {
1087
+ log += `\n${inputLog}`
1088
+ logColor += `\n${inputLogColor}`
1089
+ })
1090
+
1091
+ log += `\n${formatIndentedLine(indent + 2, `outputs: ${tx?.outputs?.length ?? 0}`)}`
1092
+ logColor += `\n${formatIndentedLine(indent + 2, chalk.gray(`outputs: ${tx?.outputs?.length ?? 0}`))}`
1093
+
1094
+ const sortedOutputs = tx?.outputs?.slice().sort((a, b) => a.satoshis! - b.satoshis!)
1095
+ const formattedTxOutputs = formatTxOutputs(sortedOutputs, indent)
1096
+ formattedTxOutputs.forEach(({ log: outputLog, logColor: outputLogColor }) => {
1097
+ log += `\n${outputLog}`
1098
+ logColor += `\n${outputLogColor}`
1099
+ })
1100
+
1101
+ return { log, logColor }
1102
+ } catch (error) {
1103
+ return {
1104
+ log: `Error parsing transaction: ${(error as Error).message}`,
1105
+ logColor: chalk.red(`Error parsing transaction: ${(error as Error).message}`)
1106
+ }
1107
+ }
1108
+ }
1109
+
1110
+ /**
1111
+ * Checks if an object is empty.
1112
+ * @param {unknown} obj - The object to check.
1113
+ * @returns {boolean} - Returns true if the object is empty, otherwise false.
1114
+ */
1115
+ export const isEmptyObject = (obj: unknown): boolean => {
1116
+ return !!obj && typeof obj === 'object' && Object.keys(obj).length === 0
1117
+ }
1118
+
1119
+ const formatIndentedLine = (indent: number, content: string) => ' '.repeat(indent * 2) + content.trim() // Trim ensures no accidental double spacing
1120
+
1121
+ function log(s: string) {
1122
+ if (!noLog) console.log(s)
1123
+ //if (!noLog) process.stdout.write(s)
1124
+ }
1125
+
1126
+ function logWarn(s: string) {
1127
+ process.stdout.write(chalk.yellowBright(s))
1128
+ }
1129
+
1130
+ export function numberArrayToHexString(numbers: number[]): string {
1131
+ return numbers.map(num => num.toString(16).padStart(2, '0')).join('')
1132
+ }
1133
+
1134
+ /***Use these to generate the log string ***/
1135
+ //const testName = expect.getState().currentTestName ?? 'Unknown_Test'
1136
+ //appendLogsAsConst(testName, rl1)
1137
+
1138
+ // Auto-generated test log - 2025-02-05T13:04:29.906Z
1139
+ const LOG_createAction_nosend_transactions_1_transaction_with_single_output_checked_using_toLogString = {
1140
+ log: `transactions:3
1141
+ txid:30bdac0f5c6491f130820517802ff57e20e5a50c08b5c65e6976627fb82ae930 version:1 lockTime:0 sats:-4 status:nosend
1142
+ outgoing:true desc:'Funding transaction' labels:['funding transaction for createaction','this is an extra long test
1143
+ label that should be truncated at 80 chars when it is...']
1144
+ inputs: 1
1145
+ 0: sourceTXID:a3a8fe7f541c1383ff7b975af49b27284ae720af5f2705d8409baaf519190d26.2 sats:913
1146
+ lock:(50)76a914f7238871139f4926cbd592a03a737981e558245d88ac
1147
+ unlock:(214)483045022100cfef1f6d781af99a1de14efd6f24f2a14234a26097012f27121eb36f4e330c1d0220... seq:4294967295
1148
+ outputs: 2
1149
+ 0: sats:3 lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac index:0 spendable:true basket:'funding basket'
1150
+ desc:'Funding Output' tags:['funding transaction output','test tag']
1151
+ 1: sats:909 lock:(50)76a9145947e66cdd43c70fb1780116b79e6f7d96e30e0888ac index:1 spendable:true basket:'default'`,
1152
+ logColor: `transactions:3 key: (txid/outpoint script sats)
1153
+ 30bdac0f5c6491f130820517802ff57e20e5a50c08b5c65e6976627fb82ae930 version:1 lockTime:0
1154
+ -4 sats status:nosend outgoing:true desc:Funding
1155
+ transaction labels:['funding transaction for createaction','this is an extra long test label that
1156
+ should be truncated at 80 chars when it is...']
1157
+ inputs: 1
1158
+ 0: a3a8fe7f541c1383ff7b975af49b27284ae720af5f2705d8409baaf519190d26.2 913 sats
1159
+ lock:(50)76a914f7238871139f4926cbd592a03a737981e558245d88ac
1160
+ unlock:(214)483045022100cfef1f6d781af99a1de14efd6f24f2a14234a26097012f27121eb36f4e330c1d0220...
1161
+ seq:4294967295
1162
+ outputs: 2
1163
+ 0: 3 sats lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac
1164
+ index:0 spendable:true basket:funding basket
1165
+ desc:Funding Output tags:['funding transaction output','test tag']
1166
+ 1: 909 sats lock:(50)76a9145947e66cdd43c70fb1780116b79e6f7d96e30e0888ac
1167
+ index:1 spendable:true basket:default`
1168
+ }
1169
+
1170
+ // Auto-generated test log - 2025-02-05T13:46:12.091Z
1171
+ const LOG_createAction_nosend_transactions_2_transaction_with_multiple_outputs_checked_using_toLogString = {
1172
+ log: `transactions:3
1173
+ txid:b3848f2cabf5887ec679ca60347a29f6ecad425fda738700265c2f9d22c18ab5 version:1 lockTime:0 sats:-12 status:nosend
1174
+ outgoing:true desc:'Funding transaction with multiple outputs' labels:['funding transaction for createaction','this
1175
+ is the extra label']
1176
+ inputs: 1
1177
+ 0: sourceTXID:a3a8fe7f541c1383ff7b975af49b27284ae720af5f2705d8409baaf519190d26.2 sats:913
1178
+ lock:(50)76a914f7238871139f4926cbd592a03a737981e558245d88ac
1179
+ unlock:(212)473044022079020cc8ea5ee6b3610806286e41567147d4b4b07d16bc1341311e00ce7647b0022034... seq:4294967295
1180
+ outputs: 3
1181
+ 0: sats:5 lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac index:0 spendable:true basket:'funding basket'
1182
+ desc:'Funding output' tags:['funding transaction for createaction','test tag']
1183
+ 1: sats:6 lock:(48)76a914fedcba9876543210fedcba9876543210fedcba88ac index:1 spendable:true basket:'extra basket'
1184
+ desc:'Extra Output' tags:['extra transaction output','extra test tag']
1185
+ 2: sats:901 lock:(50)76a9145947e66cdd43c70fb1780116b79e6f7d96e30e0888ac index:2 spendable:true basket:'default'`,
1186
+ logColor: `transactions:3 key: (txid/outpoint script sats)
1187
+ b3848f2cabf5887ec679ca60347a29f6ecad425fda738700265c2f9d22c18ab5 version:1 lockTime:0
1188
+ -12 sats status:nosend outgoing:true desc:Funding
1189
+ transaction with multiple outputs labels:['funding transaction for createaction','this is the
1190
+ extra label']
1191
+ inputs: 1
1192
+ 0: a3a8fe7f541c1383ff7b975af49b27284ae720af5f2705d8409baaf519190d26.2 913 sats
1193
+ lock:(50)76a914f7238871139f4926cbd592a03a737981e558245d88ac
1194
+ unlock:(212)473044022079020cc8ea5ee6b3610806286e41567147d4b4b07d16bc1341311e00ce7647b0022034...
1195
+ seq:4294967295
1196
+ outputs: 3
1197
+ 0: 5 sats lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac
1198
+ index:0 spendable:true basket:funding basket
1199
+ desc:Funding output tags:['funding transaction for createaction','test
1200
+ tag']
1201
+ 1: 6 sats lock:(48)76a914fedcba9876543210fedcba9876543210fedcba88ac
1202
+ index:1 spendable:true basket:extra basket
1203
+ desc:Extra Output tags:['extra transaction output','extra test tag']
1204
+ 2: 901 sats lock:(50)76a9145947e66cdd43c70fb1780116b79e6f7d96e30e0888ac
1205
+ index:2 spendable:true basket:default`
1206
+ }
1207
+
1208
+ // Auto-generated test log - 2025-02-05T14:50:57.843Z
1209
+ const LOG_createAction_nosend_transactions_3_transaction_with_explicit_change_check_also_uses_toLogString_on_the_spend =
1210
+ {
1211
+ log: `transactions:5
1212
+ txid:afa6713aab0957cf5bb00dee532ad7b895e919a99564ec2016b51cb3d472d87f version:1 lockTime:0 sats:1 status:nosend
1213
+ outgoing:true desc:'Explicit check on returned change' labels:['spending transaction test']
1214
+ inputs: 2
1215
+ 0: sourceTXID:527ffe88f70d5b7de2b8b5ba9966b9c755e7da4de749d4fcd27140a03145a11d.0 sats:995
1216
+ lock:(50)76a914ab2b66432503a3681fc5af1502207ca458c8752d88ac
1217
+ unlock:(214)483045022100973a84555fa864e08313bda5c88e1991094db7b8d82586c899276155dabcbc9a0220... seq:4294967295
1218
+ 1: sourceTXID:70afdc54187a1cdb8e35f7d00e5e111cbf5c43c4dc3f1da2cc44479133c75f9e.0 sats:4 desc:'Funding output'
1219
+ lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac unlock:(16)47304402207f2e9a seq:4294967295
1220
+ outputs: 2
1221
+ 0: sats:2 lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac index:0 spendable:true desc:'First spending
1222
+ Output for check on change '
1223
+ 1: sats:996 lock:(50)76a9145947e66cdd43c70fb1780116b79e6f7d96e30e0888ac index:1 spendable:true basket:'default'`,
1224
+ logColor: `transactions:5 key: (txid/outpoint script sats)
1225
+ afa6713aab0957cf5bb00dee532ad7b895e919a99564ec2016b51cb3d472d87f version:1 lockTime:0
1226
+ 1 sats status:nosend outgoing:true desc:Explicit
1227
+ check on returned change labels:['spending transaction test']
1228
+ inputs: 2
1229
+ 0: 527ffe88f70d5b7de2b8b5ba9966b9c755e7da4de749d4fcd27140a03145a11d.0 995 sats
1230
+ lock:(50)76a914ab2b66432503a3681fc5af1502207ca458c8752d88ac
1231
+ unlock:(214)483045022100973a84555fa864e08313bda5c88e1991094db7b8d82586c899276155dabcbc9a0220...
1232
+ seq:4294967295
1233
+ 1: 70afdc54187a1cdb8e35f7d00e5e111cbf5c43c4dc3f1da2cc44479133c75f9e.0 4 sats
1234
+ desc:Funding output
1235
+ lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac
1236
+ unlock:(16)47304402207f2e9a seq:4294967295
1237
+ outputs: 2
1238
+ 0: 2 sats lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac
1239
+ index:0 spendable:true desc:First spending Output for check
1240
+ on change 
1241
+ 1: 996 sats lock:(50)76a9145947e66cdd43c70fb1780116b79e6f7d96e30e0888ac
1242
+ index:1 spendable:true basket:default`
1243
+ }
1244
+
1245
+ // Auto-generated test log - 2025-02-05T15:22:24.388Z
1246
+ const LOG_createAction_nosend_transactions_4_transaction_with_custom_options_knownTxids_and_returnTXIDOnly_false_uses_toLogString =
1247
+ {
1248
+ log: `transactions:2
1249
+ txid:38ded69627603b30bd1f55eb3f88098dbf74f2ef0ff5e3cfe6a34f97ce2db9c2 version:1 lockTime:0 sats:-5 status:nosend
1250
+ outgoing:true desc:'Check knownTxids and returnTXIDOnly' labels:['custom options test']
1251
+ inputs: 1
1252
+ 0: sourceTXID:527ffe88f70d5b7de2b8b5ba9966b9c755e7da4de749d4fcd27140a03145a11d.0 sats:995
1253
+ lock:(50)76a914ab2b66432503a3681fc5af1502207ca458c8752d88ac
1254
+ unlock:(212)4730440220113a6f72035a6ddcd6930db7e3f3d5c70486f9aaefb095e6fa3557afa916ec37022054... seq:4294967295
1255
+ outputs: 2
1256
+ 0: sats:4 lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac index:0 spendable:true desc:'returnTXIDOnly
1257
+ false test'
1258
+ 1: sats:990 lock:(50)76a9145947e66cdd43c70fb1780116b79e6f7d96e30e0888ac index:1 spendable:true basket:'default'`,
1259
+ logColor: `transactions:2 key: (txid/outpoint script sats)
1260
+ 38ded69627603b30bd1f55eb3f88098dbf74f2ef0ff5e3cfe6a34f97ce2db9c2 version:1 lockTime:0
1261
+ -5 sats status:nosend outgoing:true desc:Check
1262
+ knownTxids and returnTXIDOnly labels:['custom options test']
1263
+ inputs: 1
1264
+ 0: 527ffe88f70d5b7de2b8b5ba9966b9c755e7da4de749d4fcd27140a03145a11d.0 995 sats
1265
+ lock:(50)76a914ab2b66432503a3681fc5af1502207ca458c8752d88ac
1266
+ unlock:(212)4730440220113a6f72035a6ddcd6930db7e3f3d5c70486f9aaefb095e6fa3557afa916ec37022054...
1267
+ seq:4294967295
1268
+ outputs: 2
1269
+ 0: 4 sats lock:(48)76a914abcdef0123456789abcdef0123456789abcdef88ac
1270
+ index:0 spendable:true desc:returnTXIDOnly false test
1271
+ 1: 990 sats lock:(50)76a9145947e66cdd43c70fb1780116b79e6f7d96e30e0888ac
1272
+ index:1 spendable:true basket:default`
1273
+ }