@cogcoin/client 1.1.5 → 1.1.7

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 (132) hide show
  1. package/README.md +2 -2
  2. package/dist/bitcoind/indexer-daemon.d.ts +3 -7
  3. package/dist/bitcoind/indexer-daemon.js +39 -204
  4. package/dist/bitcoind/managed-runtime/bitcoind-policy.d.ts +16 -0
  5. package/dist/bitcoind/managed-runtime/bitcoind-policy.js +177 -0
  6. package/dist/bitcoind/managed-runtime/bitcoind-runtime.d.ts +20 -0
  7. package/dist/bitcoind/managed-runtime/bitcoind-runtime.js +74 -0
  8. package/dist/bitcoind/managed-runtime/bitcoind-status.d.ts +11 -0
  9. package/dist/bitcoind/managed-runtime/bitcoind-status.js +44 -0
  10. package/dist/bitcoind/managed-runtime/indexer-policy.d.ts +34 -0
  11. package/dist/bitcoind/managed-runtime/indexer-policy.js +200 -0
  12. package/dist/bitcoind/managed-runtime/indexer-runtime.d.ts +15 -0
  13. package/dist/bitcoind/managed-runtime/indexer-runtime.js +82 -0
  14. package/dist/bitcoind/managed-runtime/status.d.ts +11 -0
  15. package/dist/bitcoind/managed-runtime/status.js +59 -0
  16. package/dist/bitcoind/managed-runtime/types.d.ts +77 -0
  17. package/dist/bitcoind/node.d.ts +2 -2
  18. package/dist/bitcoind/node.js +2 -2
  19. package/dist/bitcoind/rpc.d.ts +2 -1
  20. package/dist/bitcoind/rpc.js +53 -3
  21. package/dist/bitcoind/service.d.ts +2 -7
  22. package/dist/bitcoind/service.js +79 -207
  23. package/dist/cli/command-registry.d.ts +1 -1
  24. package/dist/cli/command-registry.js +2 -64
  25. package/dist/cli/commands/client-admin.js +3 -18
  26. package/dist/cli/commands/mining-runtime.js +4 -60
  27. package/dist/cli/commands/wallet-admin.js +6 -6
  28. package/dist/cli/context.js +1 -3
  29. package/dist/cli/mining-json.d.ts +1 -22
  30. package/dist/cli/mining-json.js +0 -23
  31. package/dist/cli/output.js +16 -2
  32. package/dist/cli/parse.js +0 -2
  33. package/dist/cli/preview-json.d.ts +1 -22
  34. package/dist/cli/preview-json.js +0 -19
  35. package/dist/cli/types.d.ts +1 -3
  36. package/dist/cli/wallet-format.js +1 -1
  37. package/dist/cli/workflow-hints.d.ts +1 -2
  38. package/dist/cli/workflow-hints.js +5 -8
  39. package/dist/wallet/lifecycle/access.d.ts +5 -0
  40. package/dist/wallet/lifecycle/access.js +79 -0
  41. package/dist/wallet/lifecycle/context.d.ts +26 -0
  42. package/dist/wallet/lifecycle/context.js +57 -0
  43. package/dist/wallet/lifecycle/managed-core.d.ts +1 -9
  44. package/dist/wallet/lifecycle/managed-core.js +3 -63
  45. package/dist/wallet/lifecycle/repair-bitcoind.d.ts +10 -0
  46. package/dist/wallet/lifecycle/repair-bitcoind.js +142 -0
  47. package/dist/wallet/lifecycle/repair-indexer.d.ts +8 -0
  48. package/dist/wallet/lifecycle/repair-indexer.js +117 -0
  49. package/dist/wallet/lifecycle/repair-mining.d.ts +1 -5
  50. package/dist/wallet/lifecycle/repair-mining.js +5 -39
  51. package/dist/wallet/lifecycle/repair.d.ts +2 -4
  52. package/dist/wallet/lifecycle/repair.js +74 -318
  53. package/dist/wallet/lifecycle/setup-prompts.d.ts +7 -0
  54. package/dist/wallet/lifecycle/setup-prompts.js +88 -0
  55. package/dist/wallet/lifecycle/setup-state.d.ts +26 -0
  56. package/dist/wallet/lifecycle/setup-state.js +159 -0
  57. package/dist/wallet/lifecycle/setup.d.ts +3 -4
  58. package/dist/wallet/lifecycle/setup.js +47 -351
  59. package/dist/wallet/lifecycle/types.d.ts +33 -5
  60. package/dist/wallet/managed-core-wallet.d.ts +2 -0
  61. package/dist/wallet/managed-core-wallet.js +27 -1
  62. package/dist/wallet/mining/candidate.d.ts +1 -0
  63. package/dist/wallet/mining/candidate.js +38 -6
  64. package/dist/wallet/mining/competitiveness.d.ts +1 -0
  65. package/dist/wallet/mining/competitiveness.js +6 -0
  66. package/dist/wallet/mining/cycle.d.ts +2 -0
  67. package/dist/wallet/mining/cycle.js +14 -4
  68. package/dist/wallet/mining/engine-types.d.ts +1 -0
  69. package/dist/wallet/mining/index.d.ts +1 -1
  70. package/dist/wallet/mining/index.js +1 -1
  71. package/dist/wallet/mining/publish.d.ts +3 -0
  72. package/dist/wallet/mining/publish.js +78 -6
  73. package/dist/wallet/mining/runner.d.ts +0 -32
  74. package/dist/wallet/mining/runner.js +59 -104
  75. package/dist/wallet/mining/stop.d.ts +7 -0
  76. package/dist/wallet/mining/stop.js +23 -0
  77. package/dist/wallet/mining/supervisor.d.ts +2 -36
  78. package/dist/wallet/mining/supervisor.js +139 -246
  79. package/dist/wallet/read/context.d.ts +1 -5
  80. package/dist/wallet/read/context.js +20 -379
  81. package/dist/wallet/read/managed-services.d.ts +33 -0
  82. package/dist/wallet/read/managed-services.js +222 -0
  83. package/dist/wallet/state/client-password/bootstrap.d.ts +2 -0
  84. package/dist/wallet/state/client-password/bootstrap.js +3 -0
  85. package/dist/wallet/state/client-password/context.d.ts +10 -0
  86. package/dist/wallet/state/client-password/context.js +46 -0
  87. package/dist/wallet/state/client-password/crypto.d.ts +34 -0
  88. package/dist/wallet/state/client-password/crypto.js +117 -0
  89. package/dist/wallet/state/client-password/files.d.ts +10 -0
  90. package/dist/wallet/state/client-password/files.js +109 -0
  91. package/dist/wallet/state/client-password/legacy-cleanup.d.ts +11 -0
  92. package/dist/wallet/state/client-password/legacy-cleanup.js +338 -0
  93. package/dist/wallet/state/client-password/messages.d.ts +3 -0
  94. package/dist/wallet/state/client-password/messages.js +9 -0
  95. package/dist/wallet/state/client-password/migration.d.ts +4 -0
  96. package/dist/wallet/state/client-password/migration.js +32 -0
  97. package/dist/wallet/state/client-password/prompts.d.ts +12 -0
  98. package/dist/wallet/state/client-password/prompts.js +79 -0
  99. package/dist/wallet/state/client-password/protected-secrets.d.ts +13 -0
  100. package/dist/wallet/state/client-password/protected-secrets.js +90 -0
  101. package/dist/wallet/state/client-password/readiness.d.ts +4 -0
  102. package/dist/wallet/state/client-password/readiness.js +48 -0
  103. package/dist/wallet/state/client-password/references.d.ts +1 -0
  104. package/dist/wallet/state/client-password/references.js +56 -0
  105. package/dist/wallet/state/client-password/rotation.d.ts +6 -0
  106. package/dist/wallet/state/client-password/rotation.js +98 -0
  107. package/dist/wallet/state/client-password/session-policy.d.ts +6 -0
  108. package/dist/wallet/state/client-password/session-policy.js +28 -0
  109. package/dist/wallet/state/client-password/session.d.ts +19 -0
  110. package/dist/wallet/state/client-password/session.js +170 -0
  111. package/dist/wallet/state/client-password/setup.d.ts +8 -0
  112. package/dist/wallet/state/client-password/setup.js +49 -0
  113. package/dist/wallet/state/client-password/types.d.ts +82 -0
  114. package/dist/wallet/state/client-password/types.js +5 -0
  115. package/dist/wallet/state/client-password.d.ts +7 -38
  116. package/dist/wallet/state/client-password.js +52 -937
  117. package/dist/wallet/tx/anchor.js +123 -216
  118. package/dist/wallet/tx/cog.js +294 -489
  119. package/dist/wallet/tx/common.d.ts +2 -0
  120. package/dist/wallet/tx/common.js +2 -0
  121. package/dist/wallet/tx/domain-admin.js +111 -220
  122. package/dist/wallet/tx/domain-market.js +401 -681
  123. package/dist/wallet/tx/executor.d.ts +176 -0
  124. package/dist/wallet/tx/executor.js +302 -0
  125. package/dist/wallet/tx/field.js +109 -215
  126. package/dist/wallet/tx/register.js +158 -269
  127. package/dist/wallet/tx/reputation.js +120 -227
  128. package/package.json +1 -1
  129. package/dist/wallet/mining/worker-main.js +0 -17
  130. package/dist/wallet/state/client-password-agent.d.ts +0 -1
  131. package/dist/wallet/state/client-password-agent.js +0 -211
  132. /package/dist/{wallet/mining/worker-main.d.ts → bitcoind/managed-runtime/types.js} +0 -0
@@ -167,6 +167,8 @@ export declare function buildWalletMutationTransaction<TPlan>(options: {
167
167
  feeRate?: number;
168
168
  availableFundingMinConf?: number;
169
169
  temporarilyUnlockedPolicyOutpoints?: readonly OutpointRecord[];
170
+ recoverManagedCoreWalletLockedOnce?: boolean;
171
+ onManagedCoreWalletLockedRecoveryOutcome?: (outcome: "recovered" | "still-locked") => void;
170
172
  }): Promise<BuiltWalletMutationTransaction>;
171
173
  export declare function fundAndValidateWalletMutationDraft<TPlan>(options: {
172
174
  rpc: WalletMutationRpcClient;
@@ -435,6 +435,8 @@ export async function buildWalletMutationTransaction(options) {
435
435
  walletName: options.walletName,
436
436
  internalPassphrase: options.state.managedCoreWallet.internalPassphrase,
437
437
  timeoutSeconds: MANAGED_CORE_WALLET_UNLOCK_TIMEOUT_SECONDS,
438
+ recoverLockedWalletOnce: options.recoverManagedCoreWalletLockedOnce,
439
+ onLockedWalletRecoveryOutcome: options.onManagedCoreWalletLockedRecoveryOutcome,
438
440
  run: async () => {
439
441
  const signed = await options.rpc.walletProcessPsbt(options.walletName, funded.psbt, true, "DEFAULT");
440
442
  const finalized = await options.rpc.finalizePsbt(signed.psbt, true);
@@ -4,15 +4,15 @@ import { resolve as resolvePath } from "node:path";
4
4
  import { lookupDomain, resolveCanonical } from "@cogcoin/indexer/queries";
5
5
  import { attachOrStartManagedBitcoindService } from "../../bitcoind/service.js";
6
6
  import { createRpcClient } from "../../bitcoind/node.js";
7
- import { acquireFileLock } from "../fs/lock.js";
8
- import { resolveWalletRuntimePathsForTesting } from "../runtime.js";
9
- import { createDefaultWalletSecretProvider, } from "../state/provider.js";
7
+ import {} from "../runtime.js";
8
+ import {} from "../state/provider.js";
10
9
  import { serializeSetCanonical, serializeSetDelegate, serializeSetEndpoint, serializeSetMiner, validateDomainName, } from "../cogop/index.js";
11
10
  import { openWalletReadContext } from "../read/index.js";
12
- import { assertFixedInputPrefixMatches, assertFundingInputsAfterFixedPrefix, assertWalletMutationContextReady, buildWalletMutationTransactionWithReserveFallback, createBuiltWalletMutationFeeSummary, createFundingMutationSender, createWalletMutationFeeMetadata, getDecodedInputScriptPubKeyHex, isLocalWalletScript, isAlreadyAcceptedError, isBroadcastUnknownError, mergeFixedWalletInputs, outpointKey, pauseMiningForWalletMutation, resolvePendingMutationReuseDecision, resolveWalletMutationFeeSelection, saveWalletStatePreservingUnlock, unlockTemporaryBuilderLocks, updateMutationRecord, } from "./common.js";
11
+ import { assertFixedInputPrefixMatches, assertFundingInputsAfterFixedPrefix, assertWalletMutationContextReady, buildWalletMutationTransactionWithReserveFallback, createFundingMutationSender, createWalletMutationFeeMetadata, getDecodedInputScriptPubKeyHex, isLocalWalletScript, mergeFixedWalletInputs, outpointKey, unlockTemporaryBuilderLocks, updateMutationRecord, } from "./common.js";
13
12
  import { confirmYesNo } from "./confirm.js";
13
+ import { executeWalletMutationOperation, persistWalletMutationState, publishWalletMutation, resolveExistingWalletMutation, } from "./executor.js";
14
14
  import { getCanonicalIdentitySelector } from "./identity-selector.js";
15
- import { findPendingMutationByIntent, upsertPendingMutation } from "./journal.js";
15
+ import { upsertPendingMutation } from "./journal.js";
16
16
  import { normalizeBtcTarget } from "./targets.js";
17
17
  function normalizeDomainName(domainName) {
18
18
  const normalized = domainName.trim().toLowerCase();
@@ -184,18 +184,7 @@ function createDraftMutation(options) {
184
184
  };
185
185
  }
186
186
  async function saveUpdatedMutationState(options) {
187
- const nextState = {
188
- ...options.state,
189
- stateRevision: options.state.stateRevision + 1,
190
- lastWrittenAtUnixMs: options.nowUnixMs,
191
- };
192
- await saveWalletStatePreservingUnlock({
193
- state: nextState,
194
- provider: options.provider,
195
- nowUnixMs: options.nowUnixMs,
196
- paths: options.paths,
197
- });
198
- return nextState;
187
+ return persistWalletMutationState(options);
199
188
  }
200
189
  function mutationConfirmedOnChain(mutation, context) {
201
190
  if (context.snapshot === null) {
@@ -415,236 +404,138 @@ async function loadEndpointPayload(source) {
415
404
  }
416
405
  return payload;
417
406
  }
418
- async function sendBuiltTransaction(options) {
419
- let nextState = options.state;
420
- const broadcasting = updateMutationRecord(options.mutation, "broadcasting", options.nowUnixMs, {
421
- attemptedTxid: options.built.txid,
422
- attemptedWtxid: options.built.wtxid,
423
- temporaryBuilderLockedOutpoints: options.built.temporaryBuilderLockedOutpoints,
424
- });
425
- nextState = upsertPendingMutation(nextState, broadcasting);
426
- nextState = await saveUpdatedMutationState({
427
- state: nextState,
428
- provider: options.provider,
429
- nowUnixMs: options.nowUnixMs,
430
- paths: options.paths,
431
- });
432
- if (options.snapshotHeight !== null && options.snapshotHeight !== (await options.rpc.getBlockchainInfo()).blocks) {
433
- await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.built.temporaryBuilderLockedOutpoints);
434
- throw new Error(`${options.errorPrefix}_tip_mismatch`);
435
- }
436
- try {
437
- await options.rpc.sendRawTransaction(options.built.rawHex);
438
- }
439
- catch (error) {
440
- if (!isAlreadyAcceptedError(error)) {
441
- if (isBroadcastUnknownError(error)) {
442
- const unknown = updateMutationRecord(broadcasting, "broadcast-unknown", options.nowUnixMs, {
443
- attemptedTxid: options.built.txid,
444
- attemptedWtxid: options.built.wtxid,
445
- temporaryBuilderLockedOutpoints: options.built.temporaryBuilderLockedOutpoints,
446
- });
447
- nextState = upsertPendingMutation(nextState, unknown);
448
- nextState = await saveUpdatedMutationState({
449
- state: nextState,
450
- provider: options.provider,
451
- nowUnixMs: options.nowUnixMs,
452
- paths: options.paths,
453
- });
454
- throw new Error(`${options.errorPrefix}_broadcast_unknown`);
455
- }
456
- await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.built.temporaryBuilderLockedOutpoints);
457
- const canceled = updateMutationRecord(broadcasting, "canceled", options.nowUnixMs, {
458
- attemptedTxid: options.built.txid,
459
- attemptedWtxid: options.built.wtxid,
460
- temporaryBuilderLockedOutpoints: [],
461
- });
462
- nextState = upsertPendingMutation(nextState, canceled);
463
- nextState = await saveUpdatedMutationState({
464
- state: nextState,
465
- provider: options.provider,
466
- nowUnixMs: options.nowUnixMs,
467
- paths: options.paths,
468
- });
469
- throw error;
470
- }
471
- }
472
- await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.built.temporaryBuilderLockedOutpoints);
473
- const live = updateMutationRecord(broadcasting, "live", options.nowUnixMs, {
474
- attemptedTxid: options.built.txid,
475
- attemptedWtxid: options.built.wtxid,
476
- temporaryBuilderLockedOutpoints: [],
477
- });
478
- nextState = upsertPendingMutation(nextState, live);
479
- nextState = await saveUpdatedMutationState({
480
- state: nextState,
481
- provider: options.provider,
482
- nowUnixMs: options.nowUnixMs,
483
- paths: options.paths,
484
- });
485
- return { state: nextState, mutation: live };
486
- }
487
407
  async function submitDomainAdminMutation(options) {
488
- const provider = options.provider ?? createDefaultWalletSecretProvider();
489
- const nowUnixMs = options.nowUnixMs ?? Date.now();
490
- const paths = options.paths ?? resolveWalletRuntimePathsForTesting();
491
- const controlLock = await acquireFileLock(paths.walletControlLockPath, {
492
- purpose: options.errorPrefix,
493
- walletRootId: null,
494
- });
495
- try {
496
- const miningPreemption = await pauseMiningForWalletMutation({
497
- paths,
498
- reason: options.errorPrefix,
499
- });
500
- const readContext = await (options.openReadContext ?? openWalletReadContext)({
501
- dataDir: options.dataDir,
502
- databasePath: options.databasePath,
503
- secretProvider: provider,
504
- walletControlLockHeld: true,
505
- paths,
506
- });
507
- try {
408
+ const execution = await executeWalletMutationOperation({
409
+ ...options,
410
+ controlLockPurpose: options.errorPrefix,
411
+ preemptionReason: options.errorPrefix,
412
+ async resolveOperation(readContext) {
508
413
  const normalizedDomainName = normalizeDomainName(options.domainName);
509
414
  const operation = resolveAnchoredDomainOperation(readContext, normalizedDomainName, options.errorPrefix, { requireRoot: options.requireRoot });
510
- const resolvedSender = createResolvedDomainAdminSenderSummary(operation.sender, operation.senderSelector);
511
- const payload = await options.createPayload(operation);
512
- const intentFingerprintHex = createIntentFingerprint([
415
+ return {
416
+ ...operation,
417
+ normalizedDomainName,
418
+ resolvedSender: createResolvedDomainAdminSenderSummary(operation.sender, operation.senderSelector),
419
+ payload: await options.createPayload(operation),
420
+ };
421
+ },
422
+ createIntentFingerprint(operation) {
423
+ return createIntentFingerprint([
513
424
  options.kind,
514
425
  operation.state.walletRootId,
515
426
  ...options.intentParts(operation),
516
427
  ]);
517
- const node = await (options.attachService ?? attachOrStartManagedBitcoindService)({
518
- dataDir: options.dataDir,
519
- chain: "main",
520
- startHeight: 0,
521
- walletRootId: operation.state.walletRootId,
522
- });
523
- const rpc = (options.rpcFactory ?? createRpcClient)(node.rpc);
524
- const walletName = operation.state.managedCoreWallet.walletName;
525
- const feeSelection = await resolveWalletMutationFeeSelection({
526
- rpc,
527
- feeRateSatVb: options.feeRateSatVb ?? null,
528
- });
529
- const existingMutation = findPendingMutationByIntent(operation.state, intentFingerprintHex);
530
- let workingState = operation.state;
531
- let replacementFixedInputs = null;
532
- if (existingMutation !== null) {
533
- const reconciled = await reconcilePendingAdminMutation({
428
+ },
429
+ async resolveExistingMutation({ operation, existingMutation, execution }) {
430
+ if (existingMutation === null) {
431
+ return {
534
432
  state: operation.state,
535
- mutation: existingMutation,
536
- provider,
537
- nowUnixMs,
538
- paths,
539
- rpc,
540
- walletName,
541
- context: readContext,
542
- });
543
- workingState = reconciled.state;
544
- if (reconciled.resolution === "confirmed" || reconciled.resolution === "live") {
545
- const reuse = await resolvePendingMutationReuseDecision({
546
- rpc,
547
- walletName,
548
- mutation: reconciled.mutation,
549
- nextFeeSelection: feeSelection,
550
- });
551
- if (reuse.reuseExisting) {
552
- return {
553
- kind: options.kind,
554
- domainName: normalizedDomainName,
555
- txid: reconciled.mutation.attemptedTxid ?? "unknown",
556
- status: reconciled.resolution,
557
- reusedExisting: true,
558
- recipientScriptPubKeyHex: payload.recipientScriptPubKeyHex ?? null,
559
- endpointValueHex: payload.endpointValueHex ?? null,
560
- resolved: {
561
- sender: resolvedSender,
562
- target: payload.resolvedTarget,
563
- effect: payload.resolvedEffect,
564
- },
565
- fees: reuse.fees,
566
- };
567
- }
568
- replacementFixedInputs = reuse.replacementFixedInputs;
569
- }
570
- if (reconciled.resolution === "repair-required") {
571
- throw new Error(`${options.errorPrefix}_repair_required`);
572
- }
433
+ replacementFixedInputs: null,
434
+ result: null,
435
+ };
573
436
  }
574
- await options.confirm(operation);
575
- let nextState = upsertPendingMutation(workingState, createDraftMutation({
576
- kind: options.kind,
577
- domainName: normalizedDomainName,
578
- sender: operation.sender,
579
- intentFingerprintHex,
580
- nowUnixMs,
581
- feeSelection,
582
- recipientScriptPubKeyHex: payload.recipientScriptPubKeyHex ?? null,
583
- endpointValueHex: payload.endpointValueHex ?? null,
584
- existing: existingMutation,
585
- }));
586
- nextState = await saveUpdatedMutationState({
587
- state: nextState,
588
- provider,
589
- nowUnixMs,
590
- paths,
437
+ return resolveExistingWalletMutation({
438
+ existingMutation,
439
+ execution,
440
+ repairRequiredErrorCode: `${options.errorPrefix}_repair_required`,
441
+ reconcileExistingMutation: (mutation) => reconcilePendingAdminMutation({
442
+ state: operation.state,
443
+ mutation,
444
+ provider: execution.provider,
445
+ nowUnixMs: execution.nowUnixMs,
446
+ paths: execution.paths,
447
+ rpc: execution.rpc,
448
+ walletName: execution.walletName,
449
+ context: execution.readContext,
450
+ }),
451
+ createReuseResult: ({ mutation, resolution, fees }) => ({
452
+ kind: options.kind,
453
+ domainName: operation.normalizedDomainName,
454
+ txid: mutation.attemptedTxid ?? "unknown",
455
+ status: resolution,
456
+ reusedExisting: true,
457
+ recipientScriptPubKeyHex: operation.payload.recipientScriptPubKeyHex ?? null,
458
+ endpointValueHex: operation.payload.endpointValueHex ?? null,
459
+ resolved: {
460
+ sender: operation.resolvedSender,
461
+ target: operation.payload.resolvedTarget,
462
+ effect: operation.payload.resolvedEffect,
463
+ },
464
+ fees,
465
+ }),
591
466
  });
467
+ },
468
+ confirm({ operation }) {
469
+ return options.confirm(operation);
470
+ },
471
+ createDraftMutation({ operation, existingMutation, execution, intentFingerprintHex }) {
472
+ return {
473
+ mutation: createDraftMutation({
474
+ kind: options.kind,
475
+ domainName: operation.normalizedDomainName,
476
+ sender: operation.sender,
477
+ intentFingerprintHex,
478
+ nowUnixMs: execution.nowUnixMs,
479
+ feeSelection: execution.feeSelection,
480
+ recipientScriptPubKeyHex: operation.payload.recipientScriptPubKeyHex ?? null,
481
+ endpointValueHex: operation.payload.endpointValueHex ?? null,
482
+ existing: existingMutation,
483
+ }),
484
+ prepared: null,
485
+ };
486
+ },
487
+ async build({ operation, state, execution, replacementFixedInputs }) {
592
488
  const adminPlan = buildPlanForDomainAdminOperation({
593
- state: nextState,
594
- allUtxos: await rpc.listUnspent(walletName, 1),
489
+ state,
490
+ allUtxos: await execution.rpc.listUnspent(execution.walletName, 1),
595
491
  sender: operation.sender,
596
- opReturnData: payload.opReturnData,
492
+ opReturnData: operation.payload.opReturnData,
597
493
  errorPrefix: options.errorPrefix,
598
494
  });
599
- const built = await buildTransaction({
600
- rpc,
601
- walletName,
602
- state: nextState,
495
+ return buildTransaction({
496
+ rpc: execution.rpc,
497
+ walletName: execution.walletName,
498
+ state,
603
499
  plan: {
604
500
  ...adminPlan,
605
501
  fixedInputs: mergeFixedWalletInputs(adminPlan.fixedInputs, replacementFixedInputs),
606
502
  },
607
- feeRateSatVb: feeSelection.feeRateSatVb,
503
+ feeRateSatVb: execution.feeSelection.feeRateSatVb,
608
504
  });
609
- const final = await sendBuiltTransaction({
610
- rpc,
611
- walletName,
612
- snapshotHeight: readContext.snapshot?.tip?.height ?? null,
505
+ },
506
+ publish({ state, execution, built, mutation }) {
507
+ return publishWalletMutation({
508
+ rpc: execution.rpc,
509
+ walletName: execution.walletName,
510
+ snapshotHeight: execution.readContext.snapshot?.tip?.height ?? null,
613
511
  built,
614
- mutation: nextState.pendingMutations.find((mutation) => mutation.intentFingerprintHex === intentFingerprintHex),
615
- state: nextState,
616
- provider,
617
- nowUnixMs,
618
- paths,
512
+ mutation,
513
+ state,
514
+ provider: execution.provider,
515
+ nowUnixMs: execution.nowUnixMs,
516
+ paths: execution.paths,
619
517
  errorPrefix: options.errorPrefix,
620
518
  });
519
+ },
520
+ createResult({ operation, mutation, built, status, reusedExisting, fees }) {
621
521
  return {
622
522
  kind: options.kind,
623
- domainName: normalizedDomainName,
624
- txid: final.mutation.attemptedTxid ?? built.txid,
625
- status: "live",
626
- reusedExisting: false,
627
- recipientScriptPubKeyHex: payload.recipientScriptPubKeyHex ?? null,
628
- endpointValueHex: payload.endpointValueHex ?? null,
523
+ domainName: operation.normalizedDomainName,
524
+ txid: mutation.attemptedTxid ?? built?.txid ?? "unknown",
525
+ status: status,
526
+ reusedExisting,
527
+ recipientScriptPubKeyHex: operation.payload.recipientScriptPubKeyHex ?? null,
528
+ endpointValueHex: operation.payload.endpointValueHex ?? null,
629
529
  resolved: {
630
- sender: resolvedSender,
631
- target: payload.resolvedTarget,
632
- effect: payload.resolvedEffect,
530
+ sender: operation.resolvedSender,
531
+ target: operation.payload.resolvedTarget,
532
+ effect: operation.payload.resolvedEffect,
633
533
  },
634
- fees: createBuiltWalletMutationFeeSummary({
635
- selection: feeSelection,
636
- built,
637
- }),
534
+ fees,
638
535
  };
639
- }
640
- finally {
641
- await readContext.close();
642
- await miningPreemption.release();
643
- }
644
- }
645
- finally {
646
- await controlLock.release();
647
- }
536
+ },
537
+ });
538
+ return execution.result;
648
539
  }
649
540
  export async function setDomainEndpoint(options) {
650
541
  const payloadBytes = await loadEndpointPayload(options.source);