@bsv/wallet-toolbox 2.6.5 → 2.7.1

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 (215) hide show
  1. package/CHANGELOG.md +77 -8
  2. package/README.md +72 -18
  3. package/docs/action-batch-planning.md +80 -37
  4. package/docs/managed-change-liquidity.md +251 -0
  5. package/out/src/Setup.d.ts +9 -0
  6. package/out/src/Setup.d.ts.map +1 -1
  7. package/out/src/Setup.js +2 -0
  8. package/out/src/Setup.js.map +1 -1
  9. package/out/src/SetupClient.d.ts +3 -0
  10. package/out/src/SetupClient.d.ts.map +1 -1
  11. package/out/src/SetupClient.js +1 -0
  12. package/out/src/SetupClient.js.map +1 -1
  13. package/out/src/SetupWallet.d.ts +3 -0
  14. package/out/src/SetupWallet.d.ts.map +1 -1
  15. package/out/src/Wallet.d.ts +4 -3
  16. package/out/src/Wallet.d.ts.map +1 -1
  17. package/out/src/Wallet.js +4 -3
  18. package/out/src/Wallet.js.map +1 -1
  19. package/out/src/WalletPermissionsManager.d.ts.map +1 -1
  20. package/out/src/WalletPermissionsManager.js +5 -8
  21. package/out/src/WalletPermissionsManager.js.map +1 -1
  22. package/out/src/mockchain/MockServices.d.ts.map +1 -1
  23. package/out/src/mockchain/MockServices.js +2 -6
  24. package/out/src/mockchain/MockServices.js.map +1 -1
  25. package/out/src/monitor/Monitor.d.ts.map +1 -1
  26. package/out/src/monitor/Monitor.js +5 -4
  27. package/out/src/monitor/Monitor.js.map +1 -1
  28. package/out/src/monitor/tasks/TaskArcSSE.d.ts +4 -1
  29. package/out/src/monitor/tasks/TaskArcSSE.d.ts.map +1 -1
  30. package/out/src/monitor/tasks/TaskArcSSE.js +92 -65
  31. package/out/src/monitor/tasks/TaskArcSSE.js.map +1 -1
  32. package/out/src/monitor/tasks/TaskReconcilePendingTransactions.d.ts +27 -0
  33. package/out/src/monitor/tasks/TaskReconcilePendingTransactions.d.ts.map +1 -0
  34. package/out/src/monitor/tasks/TaskReconcilePendingTransactions.js +236 -0
  35. package/out/src/monitor/tasks/TaskReconcilePendingTransactions.js.map +1 -0
  36. package/out/src/monitor/tasks/TaskReviewDoubleSpends.d.ts.map +1 -1
  37. package/out/src/monitor/tasks/TaskReviewDoubleSpends.js +15 -3
  38. package/out/src/monitor/tasks/TaskReviewDoubleSpends.js.map +1 -1
  39. package/out/src/monitor/tasks/TaskReviewUtxos.d.ts +29 -2
  40. package/out/src/monitor/tasks/TaskReviewUtxos.d.ts.map +1 -1
  41. package/out/src/monitor/tasks/TaskReviewUtxos.js +155 -7
  42. package/out/src/monitor/tasks/TaskReviewUtxos.js.map +1 -1
  43. package/out/src/monitor/tasks/index.all.d.ts +1 -0
  44. package/out/src/monitor/tasks/index.all.d.ts.map +1 -1
  45. package/out/src/monitor/tasks/index.all.js +1 -0
  46. package/out/src/monitor/tasks/index.all.js.map +1 -1
  47. package/out/src/sdk/ActionBatch.interfaces.d.ts +19 -0
  48. package/out/src/sdk/ActionBatch.interfaces.d.ts.map +1 -1
  49. package/out/src/sdk/WERR_errors.d.ts +23 -0
  50. package/out/src/sdk/WERR_errors.d.ts.map +1 -1
  51. package/out/src/sdk/WERR_errors.js +44 -1
  52. package/out/src/sdk/WERR_errors.js.map +1 -1
  53. package/out/src/sdk/WalletError.d.ts.map +1 -1
  54. package/out/src/sdk/WalletError.js +7 -21
  55. package/out/src/sdk/WalletError.js.map +1 -1
  56. package/out/src/sdk/WalletErrorFromJson.d.ts.map +1 -1
  57. package/out/src/sdk/WalletErrorFromJson.js +9 -1
  58. package/out/src/sdk/WalletErrorFromJson.js.map +1 -1
  59. package/out/src/sdk/WalletServices.interfaces.d.ts +14 -1
  60. package/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
  61. package/out/src/sdk/WalletStorage.interfaces.d.ts +3 -1
  62. package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
  63. package/out/src/sdk/types.d.ts +3 -2
  64. package/out/src/sdk/types.d.ts.map +1 -1
  65. package/out/src/sdk/types.js +3 -2
  66. package/out/src/sdk/types.js.map +1 -1
  67. package/out/src/services/Services.d.ts.map +1 -1
  68. package/out/src/services/Services.js +73 -15
  69. package/out/src/services/Services.js.map +1 -1
  70. package/out/src/services/classifyOutputUtxo.d.ts +25 -0
  71. package/out/src/services/classifyOutputUtxo.d.ts.map +1 -0
  72. package/out/src/services/classifyOutputUtxo.js +87 -0
  73. package/out/src/services/classifyOutputUtxo.js.map +1 -0
  74. package/out/src/services/createDefaultWalletServicesOptions.d.ts +16 -3
  75. package/out/src/services/createDefaultWalletServicesOptions.d.ts.map +1 -1
  76. package/out/src/services/createDefaultWalletServicesOptions.js +38 -8
  77. package/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
  78. package/out/src/services/providers/ArcSSEClient.d.ts +13 -4
  79. package/out/src/services/providers/ArcSSEClient.d.ts.map +1 -1
  80. package/out/src/services/providers/ArcSSEClient.js +30 -7
  81. package/out/src/services/providers/ArcSSEClient.js.map +1 -1
  82. package/out/src/services/providers/Arcade.d.ts +10 -1
  83. package/out/src/services/providers/Arcade.d.ts.map +1 -1
  84. package/out/src/services/providers/Arcade.js +63 -0
  85. package/out/src/services/providers/Arcade.js.map +1 -1
  86. package/out/src/services/providers/arcadeStatus.d.ts +18 -0
  87. package/out/src/services/providers/arcadeStatus.d.ts.map +1 -0
  88. package/out/src/services/providers/arcadeStatus.js +56 -0
  89. package/out/src/services/providers/arcadeStatus.js.map +1 -0
  90. package/out/src/signer/actionBatch/ActionBatchPlanner.d.ts.map +1 -1
  91. package/out/src/signer/actionBatch/ActionBatchPlanner.js +25 -3
  92. package/out/src/signer/actionBatch/ActionBatchPlanner.js.map +1 -1
  93. package/out/src/signer/actionBatch/ActionBatchWorkspace.d.ts +2 -0
  94. package/out/src/signer/actionBatch/ActionBatchWorkspace.d.ts.map +1 -1
  95. package/out/src/signer/actionBatch/ActionBatchWorkspace.js +135 -16
  96. package/out/src/signer/actionBatch/ActionBatchWorkspace.js.map +1 -1
  97. package/out/src/storage/StorageIdb.d.ts +2 -0
  98. package/out/src/storage/StorageIdb.d.ts.map +1 -1
  99. package/out/src/storage/StorageIdb.js +24 -1
  100. package/out/src/storage/StorageIdb.js.map +1 -1
  101. package/out/src/storage/StorageKnex.d.ts +1 -1
  102. package/out/src/storage/StorageKnex.d.ts.map +1 -1
  103. package/out/src/storage/StorageKnex.js +4 -4
  104. package/out/src/storage/StorageKnex.js.map +1 -1
  105. package/out/src/storage/StorageProvider.d.ts +18 -2
  106. package/out/src/storage/StorageProvider.d.ts.map +1 -1
  107. package/out/src/storage/StorageProvider.js +45 -14
  108. package/out/src/storage/StorageProvider.js.map +1 -1
  109. package/out/src/storage/StorageReaderWriter.d.ts.map +1 -1
  110. package/out/src/storage/StorageReaderWriter.js +3 -2
  111. package/out/src/storage/StorageReaderWriter.js.map +1 -1
  112. package/out/src/storage/WalletStorageManager.d.ts +12 -0
  113. package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
  114. package/out/src/storage/WalletStorageManager.js +22 -2
  115. package/out/src/storage/WalletStorageManager.js.map +1 -1
  116. package/out/src/storage/adminServer/adminServer.d.ts +2 -0
  117. package/out/src/storage/adminServer/adminServer.d.ts.map +1 -1
  118. package/out/src/storage/adminServer/adminServer.js +25 -8
  119. package/out/src/storage/adminServer/adminServer.js.map +1 -1
  120. package/out/src/storage/adminServer/adminUi.d.ts.map +1 -1
  121. package/out/src/storage/adminServer/adminUi.js +32 -9
  122. package/out/src/storage/adminServer/adminUi.js.map +1 -1
  123. package/out/src/storage/adminServer/reviewUtxos.d.ts +27 -0
  124. package/out/src/storage/adminServer/reviewUtxos.d.ts.map +1 -0
  125. package/out/src/storage/adminServer/reviewUtxos.js +62 -0
  126. package/out/src/storage/adminServer/reviewUtxos.js.map +1 -0
  127. package/out/src/storage/index.all.d.ts +1 -0
  128. package/out/src/storage/index.all.d.ts.map +1 -1
  129. package/out/src/storage/index.all.js +1 -0
  130. package/out/src/storage/index.all.js.map +1 -1
  131. package/out/src/storage/index.client.d.ts +1 -0
  132. package/out/src/storage/index.client.d.ts.map +1 -1
  133. package/out/src/storage/index.client.js +1 -0
  134. package/out/src/storage/index.client.js.map +1 -1
  135. package/out/src/storage/index.mobile.d.ts +1 -0
  136. package/out/src/storage/index.mobile.d.ts.map +1 -1
  137. package/out/src/storage/index.mobile.js +1 -0
  138. package/out/src/storage/index.mobile.js.map +1 -1
  139. package/out/src/storage/methods/ListOutputsSpecOp.d.ts.map +1 -1
  140. package/out/src/storage/methods/ListOutputsSpecOp.js +4 -44
  141. package/out/src/storage/methods/ListOutputsSpecOp.js.map +1 -1
  142. package/out/src/storage/methods/actionBatch.d.ts +9 -2
  143. package/out/src/storage/methods/actionBatch.d.ts.map +1 -1
  144. package/out/src/storage/methods/actionBatch.js +258 -66
  145. package/out/src/storage/methods/actionBatch.js.map +1 -1
  146. package/out/src/storage/methods/actionBatchBlobs.js +7 -4
  147. package/out/src/storage/methods/actionBatchBlobs.js.map +1 -1
  148. package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
  149. package/out/src/storage/methods/attemptToPostReqsToNetwork.js +2 -66
  150. package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
  151. package/out/src/storage/methods/availableManagedChange.d.ts +8 -1
  152. package/out/src/storage/methods/availableManagedChange.d.ts.map +1 -1
  153. package/out/src/storage/methods/availableManagedChange.js.map +1 -1
  154. package/out/src/storage/methods/createAction.d.ts.map +1 -1
  155. package/out/src/storage/methods/createAction.js +176 -58
  156. package/out/src/storage/methods/createAction.js.map +1 -1
  157. package/out/src/storage/methods/generateChange.d.ts +13 -1
  158. package/out/src/storage/methods/generateChange.d.ts.map +1 -1
  159. package/out/src/storage/methods/generateChange.js +169 -12
  160. package/out/src/storage/methods/generateChange.js.map +1 -1
  161. package/out/src/storage/methods/listActionsIdb.d.ts.map +1 -1
  162. package/out/src/storage/methods/listActionsIdb.js +4 -0
  163. package/out/src/storage/methods/listActionsIdb.js.map +1 -1
  164. package/out/src/storage/methods/listActionsKnex.d.ts.map +1 -1
  165. package/out/src/storage/methods/listActionsKnex.js +4 -0
  166. package/out/src/storage/methods/listActionsKnex.js.map +1 -1
  167. package/out/src/storage/methods/listOutputsIdb.d.ts.map +1 -1
  168. package/out/src/storage/methods/listOutputsIdb.js +2 -1
  169. package/out/src/storage/methods/listOutputsIdb.js.map +1 -1
  170. package/out/src/storage/methods/managedChangePolicy.d.ts +44 -0
  171. package/out/src/storage/methods/managedChangePolicy.d.ts.map +1 -0
  172. package/out/src/storage/methods/managedChangePolicy.js +58 -0
  173. package/out/src/storage/methods/managedChangePolicy.js.map +1 -0
  174. package/out/src/storage/methods/reconcileFailedTransactionInputs.d.ts +32 -0
  175. package/out/src/storage/methods/reconcileFailedTransactionInputs.d.ts.map +1 -0
  176. package/out/src/storage/methods/reconcileFailedTransactionInputs.js +142 -0
  177. package/out/src/storage/methods/reconcileFailedTransactionInputs.js.map +1 -0
  178. package/out/src/storage/methods/reviewUtxoOutputs.d.ts +37 -0
  179. package/out/src/storage/methods/reviewUtxoOutputs.d.ts.map +1 -0
  180. package/out/src/storage/methods/reviewUtxoOutputs.js +150 -0
  181. package/out/src/storage/methods/reviewUtxoOutputs.js.map +1 -0
  182. package/out/src/storage/portable/index.d.ts.map +1 -1
  183. package/out/src/storage/portable/index.js +4 -2
  184. package/out/src/storage/portable/index.js.map +1 -1
  185. package/out/src/storage/remoting/StorageClientBase.d.ts +2 -1
  186. package/out/src/storage/remoting/StorageClientBase.d.ts.map +1 -1
  187. package/out/src/storage/remoting/StorageClientBase.js +3 -0
  188. package/out/src/storage/remoting/StorageClientBase.js.map +1 -1
  189. package/out/src/storage/remoting/StorageServer.d.ts.map +1 -1
  190. package/out/src/storage/remoting/StorageServer.js +4 -1
  191. package/out/src/storage/remoting/StorageServer.js.map +1 -1
  192. package/out/src/storage/schema/KnexMigrations.d.ts +1 -0
  193. package/out/src/storage/schema/KnexMigrations.d.ts.map +1 -1
  194. package/out/src/storage/schema/KnexMigrations.js +29 -3
  195. package/out/src/storage/schema/KnexMigrations.js.map +1 -1
  196. package/out/src/storage/schema/entities/EntityOutputBasket.d.ts.map +1 -1
  197. package/out/src/storage/schema/entities/EntityOutputBasket.js +5 -2
  198. package/out/src/storage/schema/entities/EntityOutputBasket.js.map +1 -1
  199. package/out/src/utility/brc153ReferenceLabels.d.ts +21 -0
  200. package/out/src/utility/brc153ReferenceLabels.d.ts.map +1 -0
  201. package/out/src/utility/brc153ReferenceLabels.js +45 -0
  202. package/out/src/utility/brc153ReferenceLabels.js.map +1 -0
  203. package/out/src/utility/index.all.d.ts +1 -0
  204. package/out/src/utility/index.all.d.ts.map +1 -1
  205. package/out/src/utility/index.all.js +1 -0
  206. package/out/src/utility/index.all.js.map +1 -1
  207. package/out/src/utility/index.client.d.ts +1 -0
  208. package/out/src/utility/index.client.d.ts.map +1 -1
  209. package/out/src/utility/index.client.js +1 -0
  210. package/out/src/utility/index.client.js.map +1 -1
  211. package/out/src/utility/utilityHelpers.d.ts +1 -1
  212. package/out/src/utility/utilityHelpers.d.ts.map +1 -1
  213. package/out/src/utility/utilityHelpers.js +2 -1
  214. package/out/src/utility/utilityHelpers.js.map +1 -1
  215. package/package.json +3 -3
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_MANAGED_CHANGE_PENDING_COMPARISON_INPUTS = exports.DEFAULT_MANAGED_CHANGE_MIGRATION_INPUTS_PER_ACTION = exports.DEFAULT_MANAGED_CHANGE_MAX_OUTPUTS_PER_ACTION = exports.DEFAULT_MANAGED_CHANGE_MINIMUM_SATOSHIS = exports.DEFAULT_MANAGED_CHANGE_TARGET_UTXOS = exports.LEGACY_MANAGED_CHANGE_MINIMUM_SATOSHIS = void 0;
4
+ exports.isLegacyManagedChangeBasketDefault = isLegacyManagedChangeBasketDefault;
5
+ exports.upgradeLegacyManagedChangeBasketDefault = upgradeLegacyManagedChangeBasketDefault;
6
+ exports.defaultManagedChangePolicy = defaultManagedChangePolicy;
7
+ exports.validateManagedChangePolicy = validateManagedChangePolicy;
8
+ const WERR_errors_1 = require("../../sdk/WERR_errors");
9
+ /** Historical default retained only to identify untouched wallet baskets. */
10
+ exports.LEGACY_MANAGED_CHANGE_MINIMUM_SATOSHIS = 32;
11
+ /**
12
+ * Default liquidity policy for wallet-managed change.
13
+ *
14
+ * The preferred minimum is deliberately much larger than the dust threshold.
15
+ * Dust answers "can this output ever be spent economically?"; this value
16
+ * answers "is this output useful as an independently selectable liquidity
17
+ * unit at contemporary fee rates?".
18
+ */
19
+ exports.DEFAULT_MANAGED_CHANGE_TARGET_UTXOS = 144;
20
+ exports.DEFAULT_MANAGED_CHANGE_MINIMUM_SATOSHIS = 5_000;
21
+ exports.DEFAULT_MANAGED_CHANGE_MAX_OUTPUTS_PER_ACTION = 8;
22
+ exports.DEFAULT_MANAGED_CHANGE_MIGRATION_INPUTS_PER_ACTION = 4;
23
+ exports.DEFAULT_MANAGED_CHANGE_PENDING_COMPARISON_INPUTS = 16;
24
+ /** True only for the exact historical default that is safe to auto-upgrade. */
25
+ function isLegacyManagedChangeBasketDefault(basket) {
26
+ return basket.name === 'default' &&
27
+ basket.numberOfDesiredUTXOs === exports.DEFAULT_MANAGED_CHANGE_TARGET_UTXOS &&
28
+ basket.minimumDesiredUTXOValue === exports.LEGACY_MANAGED_CHANGE_MINIMUM_SATOSHIS;
29
+ }
30
+ /**
31
+ * Normalize a legacy default while retaining every other field and every
32
+ * operator-selected non-default value. Used by migrations, sync, and restore.
33
+ */
34
+ function upgradeLegacyManagedChangeBasketDefault(basket) {
35
+ if (!isLegacyManagedChangeBasketDefault(basket))
36
+ return basket;
37
+ return { ...basket, minimumDesiredUTXOValue: exports.DEFAULT_MANAGED_CHANGE_MINIMUM_SATOSHIS };
38
+ }
39
+ function defaultManagedChangePolicy() {
40
+ return {
41
+ maxOutputsPerAction: exports.DEFAULT_MANAGED_CHANGE_MAX_OUTPUTS_PER_ACTION,
42
+ migrationInputsPerAction: exports.DEFAULT_MANAGED_CHANGE_MIGRATION_INPUTS_PER_ACTION,
43
+ pendingComparisonInputs: exports.DEFAULT_MANAGED_CHANGE_PENDING_COMPARISON_INPUTS
44
+ };
45
+ }
46
+ function validateManagedChangePolicy(options) {
47
+ const policy = { ...defaultManagedChangePolicy(), ...options };
48
+ const validateLimit = (value, name, minimum) => {
49
+ if (value !== -1 && (!Number.isSafeInteger(value) || value < minimum)) {
50
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER(`managedChangePolicy.${name}`, `${minimum === 0 ? 'a non-negative' : 'a positive'} safe integer or -1 for unlimited`);
51
+ }
52
+ };
53
+ validateLimit(policy.maxOutputsPerAction, 'maxOutputsPerAction', 1);
54
+ validateLimit(policy.migrationInputsPerAction, 'migrationInputsPerAction', 0);
55
+ validateLimit(policy.pendingComparisonInputs, 'pendingComparisonInputs', 1);
56
+ return policy;
57
+ }
58
+ //# sourceMappingURL=managedChangePolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managedChangePolicy.js","sourceRoot":"","sources":["../../../../src/storage/methods/managedChangePolicy.ts"],"names":[],"mappings":";;;;;;;AAAA,uDAA8D;AAE9D,6EAA6E;AAChE,QAAA,sCAAsC,GAAG,EAAE,CAAA;AAExD;;;;;;;GAOG;AACU,QAAA,mCAAmC,GAAG,GAAG,CAAA;AACzC,QAAA,uCAAuC,GAAG,KAAK,CAAA;AAC/C,QAAA,6CAA6C,GAAG,CAAC,CAAA;AACjD,QAAA,kDAAkD,GAAG,CAAC,CAAA;AACtD,QAAA,gDAAgD,GAAG,EAAE,CAAA;AAwBlE,+EAA+E;AAC/E,4CACE,MAAmC;IAEnC,OAAO,MAAM,CAAC,IAAI,KAAK,SAAS;QAC9B,MAAM,CAAC,oBAAoB,KAAK,QAAA,mCAAmC;QACnE,MAAM,CAAC,uBAAuB,KAAK,QAAA,sCAAsC,CAAA;AAC7E,CAAC;AAED;;;GAGG;AACH,iDACE,MAAS;IAET,IAAI,CAAC,kCAAkC,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IAC9D,OAAO,EAAE,GAAG,MAAM,EAAE,uBAAuB,EAAE,QAAA,uCAAuC,EAAE,CAAA;AACxF,CAAC;AAED;IACE,OAAO;QACL,mBAAmB,EAAE,QAAA,6CAA6C;QAClE,wBAAwB,EAAE,QAAA,kDAAkD;QAC5E,uBAAuB,EAAE,QAAA,gDAAgD;KAC1E,CAAA;AACH,CAAC;AAED,qCACE,OAAoC;IAEpC,MAAM,MAAM,GAAG,EAAE,GAAG,0BAA0B,EAAE,EAAE,GAAG,OAAO,EAAE,CAAA;IAC9D,MAAM,aAAa,GAAG,CAAC,KAAa,EAAE,IAA+B,EAAE,OAAe,EAAQ,EAAE;QAC9F,IAAI,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,OAAO,CAAC,EAAE,CAAC;YACtE,MAAM,IAAI,oCAAsB,CAC9B,uBAAuB,IAAI,EAAE,EAC7B,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,YAAY,mCAAmC,CACtF,CAAA;QACH,CAAC;IACH,CAAC,CAAA;IACD,aAAa,CAAC,MAAM,CAAC,mBAAmB,EAAE,qBAAqB,EAAE,CAAC,CAAC,CAAA;IACnE,aAAa,CAAC,MAAM,CAAC,wBAAwB,EAAE,0BAA0B,EAAE,CAAC,CAAC,CAAA;IAC7E,aAAa,CAAC,MAAM,CAAC,uBAAuB,EAAE,yBAAyB,EAAE,CAAC,CAAC,CAAA;IAC3E,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { WalletLoggerInterface } from '@bsv/sdk';
2
+ import * as sdk from '../../sdk';
3
+ import { StorageProvider } from '../StorageProvider';
4
+ import { EntityProvenTxReq } from '../schema/entities';
5
+ export interface FailedInputReconciliationResult {
6
+ checked: number;
7
+ staleConfirmed: number;
8
+ staleOutpoints: string[];
9
+ }
10
+ /**
11
+ * Conservatively quarantine every locally-owned input of a transaction after
12
+ * Arcade supplies explicit missing-input/conflict evidence. This path is
13
+ * deliberately independent of explorer or UTXO providers: a positive
14
+ * broadcaster verdict is enough to stop the failed transaction from feeding
15
+ * the same inputs into another action. A later validated mined proof remains
16
+ * able to repair the transaction through the ordinary proof recovery path.
17
+ */
18
+ export declare function quarantineReqInputs(req: EntityProvenTxReq, storage: StorageProvider, trx?: sdk.TrxToken, logger?: WalletLoggerInterface): Promise<FailedInputReconciliationResult>;
19
+ /**
20
+ * Keep only inputs created by a locally terminal parent unavailable after the
21
+ * failed-child transition releases its allocations. Other inputs may still be
22
+ * valid UTXOs and must remain reusable.
23
+ */
24
+ export declare function quarantineReqInputsFromFailedParents(req: EntityProvenTxReq, failedParentTxids: string[], storage: StorageProvider, trx?: sdk.TrxToken, logger?: WalletLoggerInterface): Promise<FailedInputReconciliationResult>;
25
+ /**
26
+ * Ask the configured UTXO-provider collection to classify the request's local
27
+ * inputs and mark only positively confirmed spent outputs unavailable.
28
+ * Provider errors and a collection with no providers are inconclusive and
29
+ * never count as spent.
30
+ */
31
+ export declare function markConfirmedStaleReqInputs(req: EntityProvenTxReq, storage: StorageProvider, services: sdk.WalletServices, trx?: sdk.TrxToken, logger?: WalletLoggerInterface): Promise<FailedInputReconciliationResult>;
32
+ //# sourceMappingURL=reconcileFailedTransactionInputs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconcileFailedTransactionInputs.d.ts","sourceRoot":"","sources":["../../../../src/storage/methods/reconcileFailedTransactionInputs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,KAAK,GAAG,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAStD,MAAM,WAAW,+BAA+B;IAC9C,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,EAAE,MAAM,EAAE,CAAA;CACzB;AA4DD;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,iBAAiB,EACtB,OAAO,EAAE,eAAe,EACxB,GAAG,CAAC,EAAE,GAAG,CAAC,QAAQ,EAClB,MAAM,CAAC,EAAE,qBAAqB,GAC7B,OAAO,CAAC,+BAA+B,CAAC,CAS1C;AAED;;;;GAIG;AACH,wBAAsB,oCAAoC,CACxD,GAAG,EAAE,iBAAiB,EACtB,iBAAiB,EAAE,MAAM,EAAE,EAC3B,OAAO,EAAE,eAAe,EACxB,GAAG,CAAC,EAAE,GAAG,CAAC,QAAQ,EAClB,MAAM,CAAC,EAAE,qBAAqB,GAC7B,OAAO,CAAC,+BAA+B,CAAC,CAY1C;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,iBAAiB,EACtB,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,GAAG,CAAC,cAAc,EAC5B,GAAG,CAAC,EAAE,GAAG,CAAC,QAAQ,EAClB,MAAM,CAAC,EAAE,qBAAqB,GAC7B,OAAO,CAAC,+BAA+B,CAAC,CAuD1C"}
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.quarantineReqInputs = quarantineReqInputs;
4
+ exports.quarantineReqInputsFromFailedParents = quarantineReqInputsFromFailedParents;
5
+ exports.markConfirmedStaleReqInputs = markConfirmedStaleReqInputs;
6
+ const sdk_1 = require("@bsv/sdk");
7
+ const utilityHelpers_1 = require("../../utility/utilityHelpers");
8
+ const classifyOutputUtxo_1 = require("../../services/classifyOutputUtxo");
9
+ async function quarantineLocalInputs(localInputs, storage, trx) {
10
+ const staleOutpoints = new Set();
11
+ for (const { output, outpoint } of localInputs) {
12
+ await storage.updateOutput((0, utilityHelpers_1.verifyId)(output.outputId), { spendable: false }, trx);
13
+ staleOutpoints.add(`${outpoint.txid}.${outpoint.vout}`);
14
+ }
15
+ return {
16
+ checked: localInputs.length,
17
+ staleConfirmed: localInputs.length,
18
+ staleOutpoints: [...staleOutpoints]
19
+ };
20
+ }
21
+ async function findLocalInputs(req, storage, trx) {
22
+ const tx = sdk_1.Transaction.fromBinary(req.rawTx);
23
+ const outpoints = tx.inputs
24
+ .map(input => ({ txid: input.sourceTXID ?? '', vout: input.sourceOutputIndex ?? 0 }))
25
+ .filter(outpoint => outpoint.txid !== '');
26
+ if (outpoints.length === 0)
27
+ return [];
28
+ // A transaction can be internalized by multiple users while the request's
29
+ // notification list is racing. Resolve every local copy by txid so no user's
30
+ // basket retains the same confirmed-stale outpoint.
31
+ const transactions = await storage.findTransactions({
32
+ partial: { txid: req.txid },
33
+ noRawTx: true,
34
+ trx
35
+ });
36
+ const userIds = [...new Set(transactions.map(transaction => transaction.userId))];
37
+ const localInputs = [];
38
+ const localKeys = new Set();
39
+ for (const userId of userIds) {
40
+ const byOutpoint = await storage.findOutputsByOutpoints(userId, outpoints, trx);
41
+ for (const outpoint of outpoints) {
42
+ const output = byOutpoint[`${outpoint.txid}.${outpoint.vout}`];
43
+ const localKey = `${userId}:${outpoint.txid}.${outpoint.vout}`;
44
+ if (output != null && !localKeys.has(localKey)) {
45
+ localKeys.add(localKey);
46
+ localInputs.push({ output, outpoint });
47
+ }
48
+ }
49
+ }
50
+ return localInputs;
51
+ }
52
+ /**
53
+ * Conservatively quarantine every locally-owned input of a transaction after
54
+ * Arcade supplies explicit missing-input/conflict evidence. This path is
55
+ * deliberately independent of explorer or UTXO providers: a positive
56
+ * broadcaster verdict is enough to stop the failed transaction from feeding
57
+ * the same inputs into another action. A later validated mined proof remains
58
+ * able to repair the transaction through the ordinary proof recovery path.
59
+ */
60
+ async function quarantineReqInputs(req, storage, trx, logger) {
61
+ const localInputs = await findLocalInputs(req, storage, trx);
62
+ const result = await quarantineLocalInputs(localInputs, storage, trx);
63
+ if (result.staleConfirmed > 0) {
64
+ logger?.log(`quarantineReqInputs: ${result.staleConfirmed} local input copy/copies quarantined for txid=${req.txid}`);
65
+ }
66
+ return result;
67
+ }
68
+ /**
69
+ * Keep only inputs created by a locally terminal parent unavailable after the
70
+ * failed-child transition releases its allocations. Other inputs may still be
71
+ * valid UTXOs and must remain reusable.
72
+ */
73
+ async function quarantineReqInputsFromFailedParents(req, failedParentTxids, storage, trx, logger) {
74
+ const failedParents = new Set(failedParentTxids);
75
+ const localInputs = (await findLocalInputs(req, storage, trx)).filter(({ outpoint }) => failedParents.has(outpoint.txid));
76
+ const result = await quarantineLocalInputs(localInputs, storage, trx);
77
+ if (result.staleConfirmed > 0) {
78
+ logger?.log(`quarantineReqInputsFromFailedParents: ${result.staleConfirmed} local parent output copy/copies quarantined for txid=${req.txid}`);
79
+ }
80
+ return result;
81
+ }
82
+ /**
83
+ * Ask the configured UTXO-provider collection to classify the request's local
84
+ * inputs and mark only positively confirmed spent outputs unavailable.
85
+ * Provider errors and a collection with no providers are inconclusive and
86
+ * never count as spent.
87
+ */
88
+ async function markConfirmedStaleReqInputs(req, storage, services, trx, logger) {
89
+ const result = { checked: 0, staleConfirmed: 0, staleOutpoints: [] };
90
+ const localInputs = await findLocalInputs(req, storage, trx);
91
+ const verdicts = new Map();
92
+ const uniqueInputs = new Map();
93
+ for (const localInput of localInputs) {
94
+ const key = `${localInput.outpoint.txid}.${localInput.outpoint.vout}`;
95
+ if (!uniqueInputs.has(key))
96
+ uniqueInputs.set(key, localInput);
97
+ }
98
+ await (0, classifyOutputUtxo_1.mapWithConcurrency)([...uniqueInputs.values()], classifyOutputUtxo_1.UTXO_PROVIDER_MAX_CONCURRENCY, async ({ output, outpoint }) => {
99
+ const key = `${outpoint.txid}.${outpoint.vout}`;
100
+ if (output.lockingScript == null) {
101
+ try {
102
+ await storage.validateOutputScript(output, trx);
103
+ }
104
+ catch {
105
+ verdicts.set(key, 'inconclusive');
106
+ return;
107
+ }
108
+ }
109
+ if (output.lockingScript == null) {
110
+ verdicts.set(key, 'inconclusive');
111
+ return;
112
+ }
113
+ const classification = await (0, classifyOutputUtxo_1.classifyOutputUtxo)(services, output);
114
+ let verdict;
115
+ if (classification.verdict === 'unknown')
116
+ verdict = 'inconclusive';
117
+ else if (classification.verdict === 'unspent')
118
+ verdict = 'utxo';
119
+ else
120
+ verdict = 'stale';
121
+ verdicts.set(key, verdict);
122
+ });
123
+ const staleOutpoints = new Set();
124
+ for (const { output, outpoint } of localInputs) {
125
+ const key = `${outpoint.txid}.${outpoint.vout}`;
126
+ const verdict = verdicts.get(key);
127
+ if (verdict == null || verdict === 'inconclusive')
128
+ continue;
129
+ result.checked++;
130
+ if (verdict === 'stale') {
131
+ await storage.updateOutput((0, utilityHelpers_1.verifyId)(output.outputId), { spendable: false }, trx);
132
+ result.staleConfirmed++;
133
+ staleOutpoints.add(key);
134
+ }
135
+ }
136
+ result.staleOutpoints = [...staleOutpoints];
137
+ if (result.staleConfirmed > 0) {
138
+ logger?.log(`markConfirmedStaleReqInputs: ${result.staleConfirmed} of ${result.checked} local input copy/copies confirmed spent for txid=${req.txid}`);
139
+ }
140
+ return result;
141
+ }
142
+ //# sourceMappingURL=reconcileFailedTransactionInputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconcileFailedTransactionInputs.js","sourceRoot":"","sources":["../../../../src/storage/methods/reconcileFailedTransactionInputs.ts"],"names":[],"mappings":";;;;;AAAA,kCAA6D;AAK7D,iEAAuD;AACvD,0EAI0C;AAa1C,KAAK,UAAU,qBAAqB,CAClC,WAAyB,EACzB,OAAwB,EACxB,GAAkB;IAElB,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAA;IACxC,KAAK,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,WAAW,EAAE,CAAC;QAC/C,MAAM,OAAO,CAAC,YAAY,CAAC,IAAA,yBAAQ,EAAC,MAAM,CAAC,QA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Q,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAA;QAC/C,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACjC,IAAI,OAAO,IAAI,IAAI,IAAI,OAAO,KAAK,cAAc;YAAE,SAAQ;QAC3D,MAAM,CAAC,OAAO,EAAE,CAAA;QAChB,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;YACxB,MAAM,OAAO,CAAC,YAAY,CAAC,IAAA,yBAAQ,EAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,GAAG,CAAC,CAAA;YAChF,MAAM,CAAC,cAAc,EAAE,CAAA;YACvB,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IACD,MAAM,CAAC,cAAc,GAAG,CAAC,GAAG,cAAc,CAAC,CAAA;IAC3C,IAAI,MAAM,CAAC,cAAc,GAAG,CAAC,EAAE,CAAC;QAC9B,MAAM,EAAE,GAAG,CACT,gCAAgC,MAAM,CAAC,cAAc,OAAO,MAAM,CAAC,OAAO,qDAAqD,GAAG,CAAC,IAAI,EAAE,CAC1I,CAAA;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { AuthId } from '../../sdk/WalletStorage.interfaces';
2
+ import { type OutputUtxoClassification } from '../../services/classifyOutputUtxo';
3
+ import { StorageProvider } from '../StorageProvider';
4
+ import { TableOutput } from '../schema/tables/TableOutput';
5
+ export declare const UTXO_REVIEW_PROVIDER_TIMEOUT_MSECS = 5000;
6
+ export type UtxoReviewReleaseMode = 'none' | 'atomic' | 'conclusive';
7
+ export interface UtxoReviewClassification {
8
+ output: TableOutput;
9
+ status: OutputUtxoClassification;
10
+ }
11
+ export interface UtxoReviewDiagnostics {
12
+ checked: number;
13
+ confirmedUnspent: number;
14
+ confirmedSpent: number;
15
+ unknown: number;
16
+ confirmedSpentSatoshis: number;
17
+ released: number;
18
+ releasedSatoshis: number;
19
+ providers: string[];
20
+ providerCount: number;
21
+ providersTruncated: boolean;
22
+ }
23
+ export interface ReviewUtxoOutputsResult {
24
+ classifications: UtxoReviewClassification[];
25
+ confirmedSpentOutputs: TableOutput[];
26
+ unknownOutputs: TableOutput[];
27
+ diagnostics: UtxoReviewDiagnostics;
28
+ }
29
+ /**
30
+ * Classify a bounded set of wallet outputs without treating provider failure as
31
+ * proof that an output was spent. Read-only reviews always return their
32
+ * conclusive and unknown partitions. Atomic release requires every verdict to
33
+ * be conclusive; the operator-only conclusive mode releases the positively
34
+ * spent subset while retaining and reporting unknowns.
35
+ */
36
+ export declare function reviewUtxoOutputs(storage: StorageProvider, auth: AuthId, outputs: TableOutput[], releaseMode?: UtxoReviewReleaseMode): Promise<ReviewUtxoOutputsResult>;
37
+ //# sourceMappingURL=reviewUtxoOutputs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviewUtxoOutputs.d.ts","sourceRoot":"","sources":["../../../../src/storage/methods/reviewUtxoOutputs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAA;AAE3D,OAAO,EAGL,KAAK,wBAAwB,EAE9B,MAAM,mCAAmC,CAAA;AAE1C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAI1D,eAAO,MAAM,kCAAkC,OAAQ,CAAA;AAEvD,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,QAAQ,GAAG,YAAY,CAAA;AAEpE,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,WAAW,CAAA;IACnB,MAAM,EAAE,wBAAwB,CAAA;CACjC;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,EAAE,MAAM,CAAA;IACxB,cAAc,EAAE,MAAM,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,sBAAsB,EAAE,MAAM,CAAA;IAC9B,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,kBAAkB,EAAE,OAAO,CAAA;CAC5B;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,EAAE,wBAAwB,EAAE,CAAA;IAC3C,qBAAqB,EAAE,WAAW,EAAE,CAAA;IACpC,cAAc,EAAE,WAAW,EAAE,CAAA;IAC7B,WAAW,EAAE,qBAAqB,CAAA;CACnC;AA8HD;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,WAAW,EAAE,EACtB,WAAW,GAAE,qBAA8B,GAC1C,OAAO,CAAC,uBAAuB,CAAC,CAoClC"}
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UTXO_REVIEW_PROVIDER_TIMEOUT_MSECS = void 0;
4
+ exports.reviewUtxoOutputs = reviewUtxoOutputs;
5
+ const WERR_errors_1 = require("../../sdk/WERR_errors");
6
+ const classifyOutputUtxo_1 = require("../../services/classifyOutputUtxo");
7
+ const utilityHelpers_1 = require("../../utility/utilityHelpers");
8
+ const MAX_AUDIT_PROVIDERS = 8;
9
+ const MAX_PROVIDER_NAME_LENGTH = 128;
10
+ exports.UTXO_REVIEW_PROVIDER_TIMEOUT_MSECS = 5_000;
11
+ function diagnosticsFor(classifications, releasedOutputIds) {
12
+ const allProviders = [
13
+ ...new Set(classifications.map(result => result.status.provider.slice(0, MAX_PROVIDER_NAME_LENGTH)))
14
+ ];
15
+ const providers = allProviders.slice(0, MAX_AUDIT_PROVIDERS);
16
+ const confirmedSpent = classifications.filter(result => result.status.verdict === 'spent');
17
+ const released = confirmedSpent.filter(result => releasedOutputIds.has(result.output.outputId));
18
+ return {
19
+ checked: classifications.length,
20
+ confirmedUnspent: classifications.filter(result => result.status.verdict === 'unspent').length,
21
+ confirmedSpent: confirmedSpent.length,
22
+ unknown: classifications.filter(result => result.status.verdict === 'unknown').length,
23
+ confirmedSpentSatoshis: confirmedSpent.reduce((sum, result) => sum + result.output.satoshis, 0),
24
+ released: released.length,
25
+ releasedSatoshis: released.reduce((sum, result) => sum + result.output.satoshis, 0),
26
+ providers,
27
+ providerCount: allProviders.length,
28
+ providersTruncated: allProviders.length > providers.length
29
+ };
30
+ }
31
+ function auditDetails(diagnostics, userId, releaseMode, reason) {
32
+ return JSON.stringify({
33
+ operation: 'specOpInvalidChange',
34
+ reason,
35
+ releaseMode,
36
+ userId,
37
+ ...diagnostics
38
+ });
39
+ }
40
+ async function classifyCandidates(storage, outputs) {
41
+ const services = storage.getServices();
42
+ const candidates = outputs.filter(output => output.basketId != null);
43
+ return await (0, classifyOutputUtxo_1.mapWithConcurrency)(candidates, classifyOutputUtxo_1.UTXO_PROVIDER_MAX_CONCURRENCY, async (output) => {
44
+ try {
45
+ await storage.validateOutputScript(output);
46
+ }
47
+ catch (error) {
48
+ return {
49
+ output,
50
+ status: {
51
+ verdict: 'unknown',
52
+ provider: '<script-validation-error>',
53
+ error
54
+ }
55
+ };
56
+ }
57
+ let timeout;
58
+ const providerCall = (0, classifyOutputUtxo_1.classifyOutputUtxo)(services, output);
59
+ const timedClassification = new Promise(resolve => {
60
+ timeout = setTimeout(() => resolve({
61
+ verdict: 'unknown',
62
+ provider: '<review-timeout>',
63
+ error: new Error(`UTXO classification exceeded ${exports.UTXO_REVIEW_PROVIDER_TIMEOUT_MSECS}ms`)
64
+ }), exports.UTXO_REVIEW_PROVIDER_TIMEOUT_MSECS);
65
+ });
66
+ try {
67
+ return {
68
+ output,
69
+ status: await Promise.race([providerCall, timedClassification])
70
+ };
71
+ }
72
+ finally {
73
+ if (timeout != null)
74
+ clearTimeout(timeout);
75
+ void providerCall.catch(() => undefined);
76
+ }
77
+ });
78
+ }
79
+ async function releaseConfirmedSpent(storage, auth, classifications, releaseMode) {
80
+ const confirmedSpent = classifications.filter(result => result.status.verdict === 'spent');
81
+ const releasedOutputIds = new Set();
82
+ await storage.transaction(async (trx) => {
83
+ for (const { output } of confirmedSpent) {
84
+ const current = await storage.findOutputById(output.outputId, trx, true);
85
+ if (current == null || current.userId !== auth.userId) {
86
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('outputId', `owned by user ${auth.userId}`);
87
+ }
88
+ if (current.spendable !== true || current.spentBy != null) {
89
+ throw new WERR_errors_1.WERR_INVALID_OPERATION(`Output ${output.outputId} changed state during UTXO review; no outputs were changed.`);
90
+ }
91
+ const updated = await storage.updateOutput((0, utilityHelpers_1.verifyId)(output.outputId), { spendable: false }, trx);
92
+ if (updated !== 1) {
93
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('outputId', `updated exactly once: ${output.outputId}`);
94
+ }
95
+ releasedOutputIds.add(output.outputId);
96
+ }
97
+ const now = new Date();
98
+ const diagnostics = diagnosticsFor(classifications, releasedOutputIds);
99
+ await storage.insertMonitorEvent({
100
+ created_at: now,
101
+ updated_at: now,
102
+ id: 0,
103
+ event: releaseMode === 'atomic' ? 'InvalidChangeRelease' : 'InvalidChangeConclusiveRelease',
104
+ details: auditDetails(diagnostics, auth.userId, releaseMode, 'provider-confirmed-spent')
105
+ }, trx);
106
+ });
107
+ return releasedOutputIds;
108
+ }
109
+ /**
110
+ * Classify a bounded set of wallet outputs without treating provider failure as
111
+ * proof that an output was spent. Read-only reviews always return their
112
+ * conclusive and unknown partitions. Atomic release requires every verdict to
113
+ * be conclusive; the operator-only conclusive mode releases the positively
114
+ * spent subset while retaining and reporting unknowns.
115
+ */
116
+ async function reviewUtxoOutputs(storage, auth, outputs, releaseMode = 'none') {
117
+ const classifications = await classifyCandidates(storage, outputs);
118
+ const confirmedSpentOutputs = classifications
119
+ .filter(result => result.status.verdict === 'spent')
120
+ .map(result => result.output);
121
+ const unknownOutputs = classifications
122
+ .filter(result => result.status.verdict === 'unknown')
123
+ .map(result => result.output);
124
+ if (releaseMode === 'atomic' && unknownOutputs.length > 0) {
125
+ const diagnostics = diagnosticsFor(classifications, new Set());
126
+ const now = new Date();
127
+ await storage.insertMonitorEvent({
128
+ created_at: now,
129
+ updated_at: now,
130
+ id: 0,
131
+ event: 'InvalidChangeReleaseBlocked',
132
+ details: auditDetails(diagnostics, auth.userId, releaseMode, 'inconclusive-provider-result')
133
+ });
134
+ throw new WERR_errors_1.WERR_UTXO_REVIEW_INCONCLUSIVE(diagnostics.checked, diagnostics.confirmedSpent, diagnostics.unknown);
135
+ }
136
+ const releasedOutputIds = releaseMode === 'none'
137
+ ? new Set()
138
+ : await releaseConfirmedSpent(storage, auth, classifications, releaseMode);
139
+ for (const output of confirmedSpentOutputs) {
140
+ if (releasedOutputIds.has(output.outputId))
141
+ output.spendable = false;
142
+ }
143
+ return {
144
+ classifications,
145
+ confirmedSpentOutputs,
146
+ unknownOutputs,
147
+ diagnostics: diagnosticsFor(classifications, releasedOutputIds)
148
+ };
149
+ }
150
+ //# sourceMappingURL=reviewUtxoOutputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviewUtxoOutputs.js","sourceRoot":"","sources":["../../../../src/storage/methods/reviewUtxoOutputs.ts"],"names":[],"mappings":";;;;AACA,uDAAqH;AACrH,0EAK0C;AAC1C,iEAAuD;AAIvD,MAAM,mBAAmB,GAAG,CAAC,CAAA;AAC7B,MAAM,wBAAwB,GAAG,GAAG,CAAA;AACvB,QAAA,kCAAkC,GAAG,KAAK,CAAA;AA6BvD,SAAS,cAAc,CACrB,eAA2C,EAC3C,iBAA8B;IAE9B,MAAM,YAAY,GAAG;QACnB,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,wBAAwB,CAAC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AAM,EAChB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,MAAM,EAAE,CAAC,CA4BnB;AAwCD,wBAAsB,YAAY,CAAE,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAa5G"}
@@ -16,6 +16,7 @@ const AESGCM_1 = require("@bsv/sdk/primitives/AESGCM");
16
16
  const hashWasm_1 = require("../../utility/hashWasm");
17
17
  const EntityBase_1 = require("../schema/entities/EntityBase");
18
18
  const utilityHelpers_1 = require("../../utility/utilityHelpers");
19
+ const managedChangePolicy_1 = require("../methods/managedChangePolicy");
19
20
  const BRC38_TITLE = 'User Wallet Data Format';
20
21
  const BRC39_MAGIC = [0x57, 0x44, 0x41, 0x54]; // WDAT
21
22
  const BRC39_HEADER_LENGTH = 33;
@@ -326,8 +327,9 @@ async function restoreBRC38(storage, data) {
326
327
  await storage.insertUser({ ...data.user }, trx);
327
328
  for (const row of data.provenTxs)
328
329
  await storage.insertProvenTx({ ...row }, trx);
329
- for (const row of data.outputBaskets)
330
- await storage.insertOutputBasket({ ...row }, trx);
330
+ for (const row of data.outputBaskets) {
331
+ await storage.insertOutputBasket((0, managedChangePolicy_1.upgradeLegacyManagedChangeBasketDefault)({ ...row }), trx);
332
+ }
331
333
  for (const row of data.outputTags)
332
334
  await storage.insertOutputTag({ ...row }, trx);
333
335
  for (const row of data.txLabels)