@cogcoin/client 1.1.8 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/bitcoind/managed-bitcoind-service-config.d.ts +13 -0
- package/dist/bitcoind/managed-bitcoind-service-config.js +165 -0
- package/dist/bitcoind/managed-bitcoind-service-lifecycle.d.ts +28 -0
- package/dist/bitcoind/managed-bitcoind-service-lifecycle.js +290 -0
- package/dist/bitcoind/managed-bitcoind-service-process.d.ts +8 -0
- package/dist/bitcoind/managed-bitcoind-service-process.js +48 -0
- package/dist/bitcoind/managed-bitcoind-service-replica.d.ts +8 -0
- package/dist/bitcoind/managed-bitcoind-service-replica.js +142 -0
- package/dist/bitcoind/managed-bitcoind-service-status.d.ts +42 -0
- package/dist/bitcoind/managed-bitcoind-service-status.js +178 -0
- package/dist/bitcoind/managed-bitcoind-service-types.d.ts +36 -0
- package/dist/bitcoind/managed-bitcoind-service-types.js +1 -0
- package/dist/bitcoind/service.d.ts +7 -63
- package/dist/bitcoind/service.js +7 -797
- package/dist/cli/commands/mining-read.js +1 -1
- package/dist/cli/commands/wallet-mutation/anchor.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/anchor.js +33 -0
- package/dist/cli/commands/wallet-mutation/bitcoin-transfer.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/bitcoin-transfer.js +32 -0
- package/dist/cli/commands/wallet-mutation/cog.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/cog.js +131 -0
- package/dist/cli/commands/wallet-mutation/context.d.ts +3 -0
- package/dist/cli/commands/wallet-mutation/context.js +18 -0
- package/dist/cli/commands/wallet-mutation/domain-admin.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/domain-admin.js +173 -0
- package/dist/cli/commands/wallet-mutation/domain-market.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/domain-market.js +107 -0
- package/dist/cli/commands/wallet-mutation/field.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/field.js +125 -0
- package/dist/cli/commands/wallet-mutation/register.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/register.js +38 -0
- package/dist/cli/commands/wallet-mutation/registry.d.ts +3 -0
- package/dist/cli/commands/wallet-mutation/registry.js +39 -0
- package/dist/cli/commands/wallet-mutation/reputation.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/reputation.js +57 -0
- package/dist/cli/commands/wallet-mutation/types.d.ts +32 -0
- package/dist/cli/commands/wallet-mutation/types.js +1 -0
- package/dist/cli/commands/wallet-mutation.js +13 -765
- package/dist/cli/commands/wallet-read.js +4 -4
- package/dist/cli/mutation-success.d.ts +0 -2
- package/dist/cli/output/classify.d.ts +7 -0
- package/dist/cli/output/classify.js +94 -0
- package/dist/cli/output/render.d.ts +2 -0
- package/dist/cli/output/render.js +13 -0
- package/dist/cli/output/rules/cli-surface.d.ts +2 -0
- package/dist/cli/output/rules/cli-surface.js +110 -0
- package/dist/cli/output/rules/generic.d.ts +2 -0
- package/dist/cli/output/rules/generic.js +13 -0
- package/dist/cli/output/rules/index.d.ts +2 -0
- package/dist/cli/output/rules/index.js +24 -0
- package/dist/cli/output/rules/mining-update.d.ts +2 -0
- package/dist/cli/output/rules/mining-update.js +68 -0
- package/dist/cli/output/rules/services.d.ts +2 -0
- package/dist/cli/output/rules/services.js +110 -0
- package/dist/cli/output/rules/wallet-admin.d.ts +2 -0
- package/dist/cli/output/rules/wallet-admin.js +224 -0
- package/dist/cli/output/rules/wallet-mutations.d.ts +2 -0
- package/dist/cli/output/rules/wallet-mutations.js +274 -0
- package/dist/cli/output/types.d.ts +16 -0
- package/dist/cli/output/types.js +1 -0
- package/dist/cli/output.d.ts +2 -168
- package/dist/cli/output.js +6 -989
- package/dist/cli/pagination.d.ts +15 -0
- package/dist/cli/pagination.js +16 -0
- package/dist/cli/recommendations.d.ts +4 -0
- package/dist/cli/recommendations.js +108 -0
- package/dist/cli/wallet-format/availability.d.ts +5 -0
- package/dist/cli/wallet-format/availability.js +96 -0
- package/dist/cli/wallet-format/balance.d.ts +2 -0
- package/dist/cli/wallet-format/balance.js +162 -0
- package/dist/cli/wallet-format/domains.d.ts +8 -0
- package/dist/cli/wallet-format/domains.js +84 -0
- package/dist/cli/wallet-format/fields.d.ts +6 -0
- package/dist/cli/wallet-format/fields.js +61 -0
- package/dist/cli/wallet-format/identity.d.ts +5 -0
- package/dist/cli/wallet-format/identity.js +19 -0
- package/dist/cli/wallet-format/locks.d.ts +7 -0
- package/dist/cli/wallet-format/locks.js +52 -0
- package/dist/cli/wallet-format/overview.d.ts +2 -0
- package/dist/cli/wallet-format/overview.js +122 -0
- package/dist/cli/wallet-format/pending.d.ts +13 -0
- package/dist/cli/wallet-format/pending.js +101 -0
- package/dist/cli/wallet-format/shared.d.ts +7 -0
- package/dist/cli/wallet-format/shared.js +31 -0
- package/dist/cli/wallet-format/status.d.ts +3 -0
- package/dist/cli/wallet-format/status.js +27 -0
- package/dist/cli/wallet-format.d.ts +8 -30
- package/dist/cli/wallet-format.js +8 -830
- package/dist/cli/wallet-read-helpers.d.ts +6 -0
- package/dist/cli/wallet-read-helpers.js +17 -0
- package/dist/wallet/mining/candidate.d.ts +1 -1
- package/dist/wallet/mining/candidate.js +3 -3
- package/dist/wallet/mining/constants.d.ts +2 -2
- package/dist/wallet/mining/constants.js +2 -2
- package/dist/wallet/mining/engine-types.d.ts +1 -0
- package/dist/wallet/mining/engine-types.js +9 -1
- package/dist/wallet/mining/publish.js +3 -6
- package/dist/wallet/mining/runner.js +30 -18
- package/dist/wallet/mining/sentence-protocol.d.ts +2 -2
- package/dist/wallet/mining/sentences.js +8 -8
- package/dist/wallet/mining/visualizer.js +7 -6
- package/dist/wallet/read/context.d.ts +4 -10
- package/dist/wallet/read/context.js +4 -227
- package/dist/wallet/read/local-state.d.ts +28 -0
- package/dist/wallet/read/local-state.js +233 -0
- package/dist/wallet/read/managed-bitcoind.d.ts +30 -0
- package/dist/wallet/read/managed-bitcoind.js +138 -0
- package/dist/wallet/read/managed-indexer.d.ts +23 -0
- package/dist/wallet/read/managed-indexer.js +87 -0
- package/dist/wallet/read/managed-services.d.ts +6 -21
- package/dist/wallet/read/managed-services.js +23 -196
- package/dist/wallet/tx/anchor/confirm.d.ts +15 -0
- package/dist/wallet/tx/anchor/confirm.js +60 -0
- package/dist/wallet/tx/anchor/draft.d.ts +39 -0
- package/dist/wallet/tx/anchor/draft.js +167 -0
- package/dist/wallet/tx/anchor/index.d.ts +5 -0
- package/dist/wallet/tx/anchor/index.js +148 -0
- package/dist/wallet/tx/anchor/intent.d.ts +61 -0
- package/dist/wallet/tx/anchor/intent.js +101 -0
- package/dist/wallet/tx/anchor/plan.d.ts +3 -0
- package/dist/wallet/tx/anchor/plan.js +18 -0
- package/dist/wallet/tx/anchor/result.d.ts +25 -0
- package/dist/wallet/tx/anchor/result.js +20 -0
- package/dist/wallet/tx/anchor.d.ts +1 -39
- package/dist/wallet/tx/anchor.js +1 -494
- package/dist/wallet/tx/bitcoin-transfer/confirm.d.ts +7 -0
- package/dist/wallet/tx/bitcoin-transfer/confirm.js +11 -0
- package/dist/wallet/tx/bitcoin-transfer/index.d.ts +5 -0
- package/dist/wallet/tx/bitcoin-transfer/index.js +112 -0
- package/dist/wallet/tx/bitcoin-transfer/intent.d.ts +52 -0
- package/dist/wallet/tx/bitcoin-transfer/intent.js +74 -0
- package/dist/wallet/tx/bitcoin-transfer/plan.d.ts +5 -0
- package/dist/wallet/tx/bitcoin-transfer/plan.js +21 -0
- package/dist/wallet/tx/bitcoin-transfer/result.d.ts +19 -0
- package/dist/wallet/tx/bitcoin-transfer/result.js +16 -0
- package/dist/wallet/tx/bitcoin-transfer.d.ts +1 -35
- package/dist/wallet/tx/bitcoin-transfer.js +1 -200
- package/dist/wallet/tx/cog/confirm.d.ts +13 -0
- package/dist/wallet/tx/cog/confirm.js +59 -0
- package/dist/wallet/tx/cog/draft.d.ts +20 -0
- package/dist/wallet/tx/cog/draft.js +114 -0
- package/dist/wallet/tx/cog/index.d.ts +6 -0
- package/dist/wallet/tx/cog/index.js +117 -0
- package/dist/wallet/tx/cog/intent.d.ts +30 -0
- package/dist/wallet/tx/cog/intent.js +169 -0
- package/dist/wallet/tx/cog/plan.d.ts +19 -0
- package/dist/wallet/tx/cog/plan.js +65 -0
- package/dist/wallet/tx/cog/result.d.ts +27 -0
- package/dist/wallet/tx/cog/result.js +28 -0
- package/dist/wallet/tx/cog/types.d.ts +186 -0
- package/dist/wallet/tx/cog/types.js +2 -0
- package/dist/wallet/tx/cog/variants/claim.d.ts +3 -0
- package/dist/wallet/tx/cog/variants/claim.js +92 -0
- package/dist/wallet/tx/cog/variants/lock.d.ts +2 -0
- package/dist/wallet/tx/cog/variants/lock.js +102 -0
- package/dist/wallet/tx/cog/variants/send.d.ts +2 -0
- package/dist/wallet/tx/cog/variants/send.js +77 -0
- package/dist/wallet/tx/cog.d.ts +1 -96
- package/dist/wallet/tx/cog.js +1 -824
- package/dist/wallet/tx/common.d.ts +14 -199
- package/dist/wallet/tx/common.js +10 -493
- package/dist/wallet/tx/domain-admin/confirm.d.ts +17 -0
- package/dist/wallet/tx/domain-admin/confirm.js +58 -0
- package/dist/wallet/tx/domain-admin/draft.d.ts +20 -0
- package/dist/wallet/tx/domain-admin/draft.js +161 -0
- package/dist/wallet/tx/domain-admin/index.d.ts +9 -0
- package/dist/wallet/tx/domain-admin/index.js +150 -0
- package/dist/wallet/tx/domain-admin/intent.d.ts +12 -0
- package/dist/wallet/tx/domain-admin/intent.js +61 -0
- package/dist/wallet/tx/domain-admin/plan.d.ts +19 -0
- package/dist/wallet/tx/domain-admin/plan.js +64 -0
- package/dist/wallet/tx/domain-admin/result.d.ts +19 -0
- package/dist/wallet/tx/domain-admin/result.js +33 -0
- package/dist/wallet/tx/domain-admin/types.d.ts +162 -0
- package/dist/wallet/tx/domain-admin/types.js +1 -0
- package/dist/wallet/tx/domain-admin/variants/canonical.d.ts +2 -0
- package/dist/wallet/tx/domain-admin/variants/canonical.js +22 -0
- package/dist/wallet/tx/domain-admin/variants/delegate.d.ts +3 -0
- package/dist/wallet/tx/domain-admin/variants/delegate.js +60 -0
- package/dist/wallet/tx/domain-admin/variants/endpoint.d.ts +3 -0
- package/dist/wallet/tx/domain-admin/variants/endpoint.js +102 -0
- package/dist/wallet/tx/domain-admin/variants/miner.d.ts +3 -0
- package/dist/wallet/tx/domain-admin/variants/miner.js +59 -0
- package/dist/wallet/tx/domain-admin.d.ts +1 -107
- package/dist/wallet/tx/domain-admin.js +1 -729
- package/dist/wallet/tx/domain-market/confirm.d.ts +6 -0
- package/dist/wallet/tx/domain-market/confirm.js +52 -0
- package/dist/wallet/tx/domain-market/draft.d.ts +43 -0
- package/dist/wallet/tx/domain-market/draft.js +286 -0
- package/dist/wallet/tx/domain-market/index.d.ts +6 -0
- package/dist/wallet/tx/domain-market/index.js +145 -0
- package/dist/wallet/tx/domain-market/intent.d.ts +15 -0
- package/dist/wallet/tx/domain-market/intent.js +131 -0
- package/dist/wallet/tx/domain-market/plan.d.ts +31 -0
- package/dist/wallet/tx/domain-market/plan.js +98 -0
- package/dist/wallet/tx/domain-market/result.d.ts +45 -0
- package/dist/wallet/tx/domain-market/result.js +88 -0
- package/dist/wallet/tx/domain-market/types.d.ts +221 -0
- package/dist/wallet/tx/domain-market/types.js +1 -0
- package/dist/wallet/tx/domain-market/variants/buy.d.ts +2 -0
- package/dist/wallet/tx/domain-market/variants/buy.js +103 -0
- package/dist/wallet/tx/domain-market/variants/sell.d.ts +2 -0
- package/dist/wallet/tx/domain-market/variants/sell.js +91 -0
- package/dist/wallet/tx/domain-market/variants/transfer.d.ts +2 -0
- package/dist/wallet/tx/domain-market/variants/transfer.js +105 -0
- package/dist/wallet/tx/domain-market.d.ts +1 -116
- package/dist/wallet/tx/domain-market.js +1 -1078
- package/dist/wallet/tx/draft-build.d.ts +60 -0
- package/dist/wallet/tx/draft-build.js +127 -0
- package/dist/wallet/tx/executor.d.ts +6 -40
- package/dist/wallet/tx/executor.js +6 -100
- package/dist/wallet/tx/fee.d.ts +30 -0
- package/dist/wallet/tx/fee.js +98 -0
- package/dist/wallet/tx/field/confirm.d.ts +11 -0
- package/dist/wallet/tx/field/confirm.js +19 -0
- package/dist/wallet/tx/field/draft.d.ts +23 -0
- package/dist/wallet/tx/field/draft.js +202 -0
- package/dist/wallet/tx/field/index.d.ts +5 -0
- package/dist/wallet/tx/field/index.js +140 -0
- package/dist/wallet/tx/field/intent.d.ts +5 -0
- package/dist/wallet/tx/field/intent.js +50 -0
- package/dist/wallet/tx/field/plan.d.ts +20 -0
- package/dist/wallet/tx/field/plan.js +65 -0
- package/dist/wallet/tx/field/result.d.ts +29 -0
- package/dist/wallet/tx/field/result.js +103 -0
- package/dist/wallet/tx/field/types.d.ts +163 -0
- package/dist/wallet/tx/field/types.js +1 -0
- package/dist/wallet/tx/field/variants/clear.d.ts +2 -0
- package/dist/wallet/tx/field/variants/clear.js +60 -0
- package/dist/wallet/tx/field/variants/create.d.ts +2 -0
- package/dist/wallet/tx/field/variants/create.js +67 -0
- package/dist/wallet/tx/field/variants/set.d.ts +2 -0
- package/dist/wallet/tx/field/variants/set.js +195 -0
- package/dist/wallet/tx/field.d.ts +1 -95
- package/dist/wallet/tx/field.js +1 -920
- package/dist/wallet/tx/mining-preemption.d.ts +6 -0
- package/dist/wallet/tx/mining-preemption.js +7 -0
- package/dist/wallet/tx/primitives.d.ts +13 -0
- package/dist/wallet/tx/primitives.js +42 -0
- package/dist/wallet/tx/psbt-assert.d.ts +14 -0
- package/dist/wallet/tx/psbt-assert.js +39 -0
- package/dist/wallet/tx/publish.d.ts +37 -0
- package/dist/wallet/tx/publish.js +88 -0
- package/dist/wallet/tx/readiness.d.ts +7 -0
- package/dist/wallet/tx/readiness.js +61 -0
- package/dist/wallet/tx/reconcile.d.ts +24 -0
- package/dist/wallet/tx/reconcile.js +72 -0
- package/dist/wallet/tx/register/confirm.d.ts +6 -0
- package/dist/wallet/tx/register/confirm.js +66 -0
- package/dist/wallet/tx/register/draft.d.ts +42 -0
- package/dist/wallet/tx/register/draft.js +181 -0
- package/dist/wallet/tx/register/index.d.ts +6 -0
- package/dist/wallet/tx/register/index.js +158 -0
- package/dist/wallet/tx/register/intent.d.ts +74 -0
- package/dist/wallet/tx/register/intent.js +119 -0
- package/dist/wallet/tx/register/plan.d.ts +43 -0
- package/dist/wallet/tx/register/plan.js +168 -0
- package/dist/wallet/tx/register/result.d.ts +78 -0
- package/dist/wallet/tx/register/result.js +41 -0
- package/dist/wallet/tx/register.d.ts +1 -70
- package/dist/wallet/tx/register.js +1 -681
- package/dist/wallet/tx/reputation/confirm.d.ts +11 -0
- package/dist/wallet/tx/reputation/confirm.js +51 -0
- package/dist/wallet/tx/reputation/draft.d.ts +20 -0
- package/dist/wallet/tx/reputation/draft.js +130 -0
- package/dist/wallet/tx/reputation/index.d.ts +4 -0
- package/dist/wallet/tx/reputation/index.js +162 -0
- package/dist/wallet/tx/reputation/intent.d.ts +36 -0
- package/dist/wallet/tx/reputation/intent.js +157 -0
- package/dist/wallet/tx/reputation/plan.d.ts +19 -0
- package/dist/wallet/tx/reputation/plan.js +64 -0
- package/dist/wallet/tx/reputation/result.d.ts +21 -0
- package/dist/wallet/tx/reputation/result.js +31 -0
- package/dist/wallet/tx/reputation/types.d.ts +130 -0
- package/dist/wallet/tx/reputation/types.js +1 -0
- package/dist/wallet/tx/reputation.d.ts +1 -74
- package/dist/wallet/tx/reputation.js +1 -556
- package/dist/wallet/tx/signing.d.ts +18 -0
- package/dist/wallet/tx/signing.js +31 -0
- package/dist/wallet/tx/state-persist.d.ts +27 -0
- package/dist/wallet/tx/state-persist.js +54 -0
- package/dist/wallet/tx/types.d.ts +44 -0
- package/dist/wallet/tx/types.js +1 -0
- package/package.json +1 -1
- package/dist/cli/mining-json.d.ts +0 -20
- package/dist/cli/mining-json.js +0 -46
- package/dist/cli/mutation-json.d.ts +0 -325
- package/dist/cli/mutation-json.js +0 -269
- package/dist/cli/mutation-resolved-json.d.ts +0 -117
- package/dist/cli/mutation-resolved-json.js +0 -123
- package/dist/cli/preview-json.d.ts +0 -319
- package/dist/cli/preview-json.js +0 -254
- package/dist/cli/read-json.d.ts +0 -190
- package/dist/cli/read-json.js +0 -627
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { loadBundledGenesisParameters } from "@cogcoin/indexer";
|
|
2
2
|
import { attachOrStartIndexerDaemon, INDEXER_DAEMON_BACKGROUND_FOLLOW_RECOVERY_FAILED, probeIndexerDaemon, readObservedIndexerDaemonStatus, readSnapshotWithRetry, } from "../../bitcoind/indexer-daemon.js";
|
|
3
|
-
import { deriveManagedBitcoindWalletStatus, resolveManagedBitcoindProbeDecision, } from "../../bitcoind/managed-runtime/bitcoind-policy.js";
|
|
4
|
-
import { deriveManagedIndexerWalletStatus, resolveIndexerDaemonProbeDecision, } from "../../bitcoind/managed-runtime/indexer-policy.js";
|
|
5
3
|
import { createRpcClient } from "../../bitcoind/node.js";
|
|
6
|
-
import { resolveCogcoinProcessingStartHeight } from "../../bitcoind/processing-start-height.js";
|
|
7
4
|
import { attachOrStartManagedBitcoindService, probeManagedBitcoindService, } from "../../bitcoind/service.js";
|
|
8
5
|
import { verifyManagedCoreWalletReplica } from "../lifecycle.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const NODE_CATCHING_UP_MESSAGE = "Bitcoin Core is still catching up to headers.";
|
|
6
|
+
import { deriveNodeHealthForTesting, openManagedWalletBitcoindReadState, } from "./managed-bitcoind.js";
|
|
7
|
+
import { openManagedWalletIndexerReadState, } from "./managed-indexer.js";
|
|
12
8
|
const defaultManagedWalletReadServiceDeps = {
|
|
13
9
|
loadBundledGenesisParameters,
|
|
14
10
|
probeManagedBitcoindService,
|
|
@@ -20,203 +16,34 @@ const defaultManagedWalletReadServiceDeps = {
|
|
|
20
16
|
readSnapshotWithRetry,
|
|
21
17
|
readObservedIndexerDaemonStatus,
|
|
22
18
|
};
|
|
23
|
-
function deriveNodeHealth(status, bitcoindHealth) {
|
|
24
|
-
if (bitcoindHealth !== "ready" || status === null || !status.ready) {
|
|
25
|
-
return {
|
|
26
|
-
health: "catching-up",
|
|
27
|
-
message: NODE_CATCHING_UP_MESSAGE,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const headerLead = status.nodeBestHeight !== null && status.nodeHeaderHeight !== null
|
|
31
|
-
? status.nodeHeaderHeight - status.nodeBestHeight
|
|
32
|
-
: null;
|
|
33
|
-
if (headerLead !== null && headerLead > 0) {
|
|
34
|
-
if (headerLead <= TOLERATED_NODE_HEADER_LEAD_BLOCKS) {
|
|
35
|
-
return {
|
|
36
|
-
health: "synced",
|
|
37
|
-
message: TOLERATED_NODE_HEADER_LEAD_MESSAGE,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
health: "catching-up",
|
|
42
|
-
message: NODE_CATCHING_UP_MESSAGE,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
health: "synced",
|
|
47
|
-
message: null,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
export function deriveNodeHealthForTesting(status, bitcoindHealth) {
|
|
51
|
-
return deriveNodeHealth(status, bitcoindHealth);
|
|
52
|
-
}
|
|
53
|
-
async function attachNodeStatus(options, dependencies) {
|
|
54
|
-
try {
|
|
55
|
-
const probe = await dependencies.probeManagedBitcoindService({
|
|
56
|
-
dataDir: options.dataDir,
|
|
57
|
-
chain: "main",
|
|
58
|
-
startHeight: 0,
|
|
59
|
-
walletRootId: options.walletRootId,
|
|
60
|
-
startupTimeoutMs: options.startupTimeoutMs,
|
|
61
|
-
});
|
|
62
|
-
const decision = resolveManagedBitcoindProbeDecision(probe);
|
|
63
|
-
if (decision.action === "reject") {
|
|
64
|
-
return {
|
|
65
|
-
handle: null,
|
|
66
|
-
rpc: null,
|
|
67
|
-
status: null,
|
|
68
|
-
observedStatus: probe.status,
|
|
69
|
-
error: decision.error,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const genesis = await dependencies.loadBundledGenesisParameters();
|
|
73
|
-
const handle = await dependencies.attachOrStartManagedBitcoindService({
|
|
74
|
-
dataDir: options.dataDir,
|
|
75
|
-
chain: "main",
|
|
76
|
-
startHeight: resolveCogcoinProcessingStartHeight(genesis),
|
|
77
|
-
walletRootId: options.walletRootId,
|
|
78
|
-
startupTimeoutMs: options.startupTimeoutMs,
|
|
79
|
-
});
|
|
80
|
-
const rpc = dependencies.createRpcClient(handle.rpc);
|
|
81
|
-
const [chainInfo, serviceStatus] = await Promise.all([
|
|
82
|
-
rpc.getBlockchainInfo(),
|
|
83
|
-
handle.refreshServiceStatus?.(),
|
|
84
|
-
]);
|
|
85
|
-
const status = {
|
|
86
|
-
ready: true,
|
|
87
|
-
chain: chainInfo.chain,
|
|
88
|
-
pid: handle.pid,
|
|
89
|
-
walletRootId: handle.walletRootId ?? null,
|
|
90
|
-
nodeBestHeight: chainInfo.blocks,
|
|
91
|
-
nodeBestHashHex: chainInfo.bestblockhash,
|
|
92
|
-
nodeHeaderHeight: chainInfo.headers,
|
|
93
|
-
serviceUpdatedAtUnixMs: serviceStatus?.updatedAtUnixMs ?? null,
|
|
94
|
-
serviceStatus: serviceStatus ?? null,
|
|
95
|
-
walletReplica: serviceStatus?.walletReplica ?? null,
|
|
96
|
-
walletReplicaMessage: serviceStatus?.walletReplica?.message ?? null,
|
|
97
|
-
};
|
|
98
|
-
return {
|
|
99
|
-
handle,
|
|
100
|
-
rpc,
|
|
101
|
-
status,
|
|
102
|
-
observedStatus: serviceStatus ?? null,
|
|
103
|
-
error: null,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
return {
|
|
108
|
-
handle: null,
|
|
109
|
-
rpc: null,
|
|
110
|
-
status: null,
|
|
111
|
-
observedStatus: null,
|
|
112
|
-
error: error instanceof Error ? error.message : String(error),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
19
|
export async function openManagedWalletReadServiceBundle(options, dependencies = defaultManagedWalletReadServiceDeps) {
|
|
117
|
-
const
|
|
20
|
+
const bitcoindState = await openManagedWalletBitcoindReadState({
|
|
118
21
|
dataDir: options.dataDir,
|
|
119
22
|
walletRootId: options.walletRootId,
|
|
23
|
+
localState: options.localState,
|
|
120
24
|
startupTimeoutMs: options.startupTimeoutMs,
|
|
121
25
|
}, dependencies);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
walletReplica: verifiedReplica,
|
|
129
|
-
walletReplicaMessage: verifiedReplica.message ?? null,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
const bitcoind = deriveManagedBitcoindWalletStatus({
|
|
133
|
-
status: node.observedStatus,
|
|
134
|
-
nodeStatus: node.status,
|
|
135
|
-
startupError: node.error,
|
|
136
|
-
});
|
|
137
|
-
const nodeDerived = deriveNodeHealth(node.status, bitcoind.health);
|
|
138
|
-
let daemonClient = null;
|
|
139
|
-
let daemonStatus = null;
|
|
140
|
-
let observedDaemonStatus = null;
|
|
141
|
-
let snapshot = null;
|
|
142
|
-
let indexerSource = "none";
|
|
143
|
-
let daemonError = null;
|
|
144
|
-
try {
|
|
145
|
-
const probe = await dependencies.probeIndexerDaemon({
|
|
146
|
-
dataDir: options.dataDir,
|
|
147
|
-
walletRootId: options.walletRootId,
|
|
148
|
-
});
|
|
149
|
-
const probeDecision = resolveIndexerDaemonProbeDecision({
|
|
150
|
-
probe,
|
|
151
|
-
expectedBinaryVersion: options.expectedIndexerBinaryVersion,
|
|
152
|
-
});
|
|
153
|
-
if (probeDecision.action !== "reject") {
|
|
154
|
-
await probe.client?.close().catch(() => undefined);
|
|
155
|
-
daemonClient = await dependencies.attachOrStartIndexerDaemon({
|
|
156
|
-
dataDir: options.dataDir,
|
|
157
|
-
databasePath: options.databasePath,
|
|
158
|
-
walletRootId: options.walletRootId,
|
|
159
|
-
startupTimeoutMs: options.startupTimeoutMs,
|
|
160
|
-
ensureBackgroundFollow: true,
|
|
161
|
-
expectedBinaryVersion: options.expectedIndexerBinaryVersion,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
observedDaemonStatus = probe.status;
|
|
166
|
-
indexerSource = probe.status === null ? "none" : "probe";
|
|
167
|
-
daemonError = probeDecision.error;
|
|
168
|
-
}
|
|
169
|
-
if (daemonClient !== null) {
|
|
170
|
-
const lease = await dependencies.readSnapshotWithRetry(daemonClient, options.walletRootId);
|
|
171
|
-
daemonStatus = lease.status;
|
|
172
|
-
observedDaemonStatus = lease.status;
|
|
173
|
-
snapshot = {
|
|
174
|
-
tip: lease.payload.tip,
|
|
175
|
-
state: deserializeIndexerState(Buffer.from(lease.payload.stateBase64, "base64")),
|
|
176
|
-
source: "lease",
|
|
177
|
-
daemonInstanceId: lease.payload.daemonInstanceId,
|
|
178
|
-
snapshotSeq: lease.payload.snapshotSeq,
|
|
179
|
-
openedAtUnixMs: lease.payload.openedAtUnixMs,
|
|
180
|
-
};
|
|
181
|
-
indexerSource = "lease";
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
daemonError = error instanceof Error ? error.message : String(error);
|
|
186
|
-
if (daemonError === INDEXER_DAEMON_BACKGROUND_FOLLOW_RECOVERY_FAILED) {
|
|
187
|
-
await daemonClient?.close().catch(() => undefined);
|
|
188
|
-
await node.handle?.stop().catch(() => undefined);
|
|
189
|
-
throw error;
|
|
190
|
-
}
|
|
191
|
-
if (observedDaemonStatus === null) {
|
|
192
|
-
observedDaemonStatus = await dependencies.readObservedIndexerDaemonStatus({
|
|
193
|
-
dataDir: options.dataDir,
|
|
194
|
-
walletRootId: options.walletRootId,
|
|
195
|
-
}).catch(() => null);
|
|
196
|
-
if (observedDaemonStatus !== null) {
|
|
197
|
-
indexerSource = "status-file";
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const indexer = deriveManagedIndexerWalletStatus({
|
|
202
|
-
daemonStatus,
|
|
203
|
-
observedStatus: observedDaemonStatus,
|
|
204
|
-
snapshot,
|
|
205
|
-
source: indexerSource,
|
|
26
|
+
const indexerState = await openManagedWalletIndexerReadState({
|
|
27
|
+
dataDir: options.dataDir,
|
|
28
|
+
databasePath: options.databasePath,
|
|
29
|
+
walletRootId: options.walletRootId,
|
|
30
|
+
startupTimeoutMs: options.startupTimeoutMs,
|
|
31
|
+
expectedIndexerBinaryVersion: options.expectedIndexerBinaryVersion,
|
|
206
32
|
now: options.now,
|
|
207
|
-
|
|
208
|
-
});
|
|
33
|
+
nodeHandle: bitcoindState.node.handle,
|
|
34
|
+
}, dependencies);
|
|
209
35
|
return {
|
|
210
|
-
node,
|
|
211
|
-
bitcoind,
|
|
212
|
-
nodeHealth:
|
|
213
|
-
nodeMessage:
|
|
214
|
-
daemonClient,
|
|
215
|
-
indexer,
|
|
216
|
-
snapshot,
|
|
36
|
+
node: bitcoindState.node,
|
|
37
|
+
bitcoind: bitcoindState.bitcoind,
|
|
38
|
+
nodeHealth: bitcoindState.nodeHealth,
|
|
39
|
+
nodeMessage: bitcoindState.nodeMessage,
|
|
40
|
+
daemonClient: indexerState.daemonClient,
|
|
41
|
+
indexer: indexerState.indexer,
|
|
42
|
+
snapshot: indexerState.snapshot,
|
|
217
43
|
async close() {
|
|
218
|
-
await daemonClient?.close().catch(() => undefined);
|
|
219
|
-
await node.handle?.stop().catch(() => undefined);
|
|
44
|
+
await indexerState.daemonClient?.close().catch(() => undefined);
|
|
45
|
+
await bitcoindState.node.handle?.stop().catch(() => undefined);
|
|
220
46
|
},
|
|
221
47
|
};
|
|
222
48
|
}
|
|
49
|
+
export { deriveNodeHealthForTesting };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { WalletPrompter } from "../../lifecycle.js";
|
|
2
|
+
export interface AnchorFoundingMessage {
|
|
3
|
+
text: string | null;
|
|
4
|
+
payloadHex: string | null;
|
|
5
|
+
}
|
|
6
|
+
export declare function resolveFoundingMessage(options: {
|
|
7
|
+
foundingMessageText: string | null | undefined;
|
|
8
|
+
promptForFoundingMessageWhenMissing?: boolean;
|
|
9
|
+
prompter: WalletPrompter;
|
|
10
|
+
}): Promise<AnchorFoundingMessage>;
|
|
11
|
+
export declare function confirmDirectAnchor(prompter: WalletPrompter, options: {
|
|
12
|
+
domainName: string;
|
|
13
|
+
walletAddress: string;
|
|
14
|
+
foundingMessageText: string | null;
|
|
15
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { encodeSentence } from "@cogcoin/scoring";
|
|
2
|
+
function encodeFoundingMessage(foundingMessageText) {
|
|
3
|
+
const trimmed = foundingMessageText?.trim() ?? "";
|
|
4
|
+
if (trimmed === "") {
|
|
5
|
+
return Promise.resolve({
|
|
6
|
+
text: null,
|
|
7
|
+
payloadHex: null,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
return encodeSentence(trimmed)
|
|
11
|
+
.then((payload) => ({
|
|
12
|
+
text: trimmed,
|
|
13
|
+
payloadHex: Buffer.from(payload).toString("hex"),
|
|
14
|
+
}))
|
|
15
|
+
.catch((error) => {
|
|
16
|
+
throw new Error(error instanceof Error ? `wallet_anchor_invalid_message_${error.message}` : "wallet_anchor_invalid_message");
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function extractAnchorInvalidMessageReason(error) {
|
|
20
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
21
|
+
if (message === "wallet_anchor_invalid_message") {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
if (!message.startsWith("wallet_anchor_invalid_message_")) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const reason = message.slice("wallet_anchor_invalid_message_".length).trim();
|
|
28
|
+
return reason === "" ? null : reason;
|
|
29
|
+
}
|
|
30
|
+
export async function resolveFoundingMessage(options) {
|
|
31
|
+
if (!options.promptForFoundingMessageWhenMissing || options.foundingMessageText != null) {
|
|
32
|
+
return encodeFoundingMessage(options.foundingMessageText ?? null);
|
|
33
|
+
}
|
|
34
|
+
for (;;) {
|
|
35
|
+
const answer = await options.prompter.prompt("Founding message (optional, press Enter to skip): ");
|
|
36
|
+
try {
|
|
37
|
+
return await encodeFoundingMessage(answer);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
const reason = extractAnchorInvalidMessageReason(error);
|
|
41
|
+
options.prompter.writeLine("Founding message cannot be encoded in canonical Coglex.");
|
|
42
|
+
if (reason !== null) {
|
|
43
|
+
options.prompter.writeLine(`Reason: ${reason}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export async function confirmDirectAnchor(prompter, options) {
|
|
49
|
+
prompter.writeLine(`You are anchoring "${options.domainName}".`);
|
|
50
|
+
prompter.writeLine(`Wallet address: ${options.walletAddress}`);
|
|
51
|
+
prompter.writeLine("Anchoring publishes a standalone DOMAIN_ANCHOR from the local wallet address.");
|
|
52
|
+
if (options.foundingMessageText !== null) {
|
|
53
|
+
prompter.writeLine("The founding message bytes will be public in mempool and on-chain.");
|
|
54
|
+
prompter.writeLine(`Founding message: ${options.foundingMessageText}`);
|
|
55
|
+
}
|
|
56
|
+
const answer = (await prompter.prompt("Type the domain name to continue: ")).trim();
|
|
57
|
+
if (answer !== options.domainName) {
|
|
58
|
+
throw new Error("wallet_anchor_confirmation_rejected");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { WalletRuntimePaths } from "../../runtime.js";
|
|
2
|
+
import type { WalletSecretProvider } from "../../state/provider.js";
|
|
3
|
+
import type { PendingMutationRecord, WalletStateV1 } from "../../types.js";
|
|
4
|
+
import type { WalletReadContext } from "../../read/index.js";
|
|
5
|
+
import { type WalletMutationFeeSelection } from "../common.js";
|
|
6
|
+
import type { AnchorMutationOperation, WalletAnchorRpcClient } from "./intent.js";
|
|
7
|
+
export declare function createDraftAnchorMutation(options: {
|
|
8
|
+
state: WalletStateV1;
|
|
9
|
+
domainName: string;
|
|
10
|
+
intentFingerprintHex: string;
|
|
11
|
+
nowUnixMs: number;
|
|
12
|
+
feeSelection: WalletMutationFeeSelection;
|
|
13
|
+
existing?: PendingMutationRecord | null;
|
|
14
|
+
}): PendingMutationRecord;
|
|
15
|
+
export declare function upsertAnchoredDomainRecord(options: {
|
|
16
|
+
state: WalletStateV1;
|
|
17
|
+
domainName: string;
|
|
18
|
+
domainId: number;
|
|
19
|
+
foundingMessageText: string | null;
|
|
20
|
+
}): WalletStateV1;
|
|
21
|
+
export declare function anchorConfirmedOnSnapshot(options: {
|
|
22
|
+
snapshot: NonNullable<WalletReadContext["snapshot"]>;
|
|
23
|
+
state: WalletStateV1;
|
|
24
|
+
domainName: string;
|
|
25
|
+
}): boolean;
|
|
26
|
+
export declare function reconcilePendingAnchorMutation(options: {
|
|
27
|
+
operation: AnchorMutationOperation;
|
|
28
|
+
mutation: PendingMutationRecord;
|
|
29
|
+
provider: WalletSecretProvider;
|
|
30
|
+
nowUnixMs: number;
|
|
31
|
+
paths: WalletRuntimePaths;
|
|
32
|
+
rpc: WalletAnchorRpcClient;
|
|
33
|
+
walletName: string;
|
|
34
|
+
context: WalletReadContext;
|
|
35
|
+
}): Promise<{
|
|
36
|
+
state: WalletStateV1;
|
|
37
|
+
mutation: PendingMutationRecord;
|
|
38
|
+
resolution: "confirmed" | "live" | "repair-required" | "not-seen" | "continue";
|
|
39
|
+
}>;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { lookupDomain } from "@cogcoin/indexer/queries";
|
|
3
|
+
import { createWalletMutationFeeMetadata, unlockTemporaryBuilderLocks, updateMutationRecord, } from "../common.js";
|
|
4
|
+
import { persistWalletMutationState } from "../executor.js";
|
|
5
|
+
import { upsertPendingMutation } from "../journal.js";
|
|
6
|
+
export function createDraftAnchorMutation(options) {
|
|
7
|
+
const existing = options.existing ?? null;
|
|
8
|
+
if (existing !== null) {
|
|
9
|
+
return {
|
|
10
|
+
...existing,
|
|
11
|
+
kind: "anchor",
|
|
12
|
+
domainName: options.domainName,
|
|
13
|
+
parentDomainName: null,
|
|
14
|
+
senderScriptPubKeyHex: options.state.funding.scriptPubKeyHex,
|
|
15
|
+
senderLocalIndex: 0,
|
|
16
|
+
intentFingerprintHex: options.intentFingerprintHex,
|
|
17
|
+
status: "draft",
|
|
18
|
+
lastUpdatedAtUnixMs: options.nowUnixMs,
|
|
19
|
+
attemptedTxid: null,
|
|
20
|
+
attemptedWtxid: null,
|
|
21
|
+
...createWalletMutationFeeMetadata(options.feeSelection),
|
|
22
|
+
temporaryBuilderLockedOutpoints: [],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
mutationId: randomBytes(12).toString("hex"),
|
|
27
|
+
kind: "anchor",
|
|
28
|
+
domainName: options.domainName,
|
|
29
|
+
parentDomainName: null,
|
|
30
|
+
senderScriptPubKeyHex: options.state.funding.scriptPubKeyHex,
|
|
31
|
+
senderLocalIndex: 0,
|
|
32
|
+
intentFingerprintHex: options.intentFingerprintHex,
|
|
33
|
+
status: "draft",
|
|
34
|
+
createdAtUnixMs: options.nowUnixMs,
|
|
35
|
+
lastUpdatedAtUnixMs: options.nowUnixMs,
|
|
36
|
+
attemptedTxid: null,
|
|
37
|
+
attemptedWtxid: null,
|
|
38
|
+
...createWalletMutationFeeMetadata(options.feeSelection),
|
|
39
|
+
temporaryBuilderLockedOutpoints: [],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function upsertAnchoredDomainRecord(options) {
|
|
43
|
+
const domains = options.state.domains.slice();
|
|
44
|
+
const existingIndex = domains.findIndex((entry) => entry.name === options.domainName);
|
|
45
|
+
const current = existingIndex >= 0 ? domains[existingIndex] : null;
|
|
46
|
+
const nextRecord = {
|
|
47
|
+
name: options.domainName,
|
|
48
|
+
domainId: options.domainId,
|
|
49
|
+
currentOwnerScriptPubKeyHex: options.state.funding.scriptPubKeyHex,
|
|
50
|
+
canonicalChainStatus: "anchored",
|
|
51
|
+
foundingMessageText: options.foundingMessageText ?? current?.foundingMessageText ?? null,
|
|
52
|
+
birthTime: current?.birthTime ?? options.state.lastWrittenAtUnixMs,
|
|
53
|
+
};
|
|
54
|
+
if (existingIndex >= 0) {
|
|
55
|
+
domains[existingIndex] = nextRecord;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
domains.push(nextRecord);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
...options.state,
|
|
62
|
+
domains,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function anchorConfirmedOnSnapshot(options) {
|
|
66
|
+
const chainDomain = lookupDomain(options.snapshot.state, options.domainName);
|
|
67
|
+
if (chainDomain === null || !chainDomain.anchored) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const ownerHex = Buffer.from(chainDomain.ownerScriptPubKey).toString("hex");
|
|
71
|
+
return ownerHex === options.state.funding.scriptPubKeyHex
|
|
72
|
+
|| (options.state.localScriptPubKeyHexes ?? []).includes(ownerHex);
|
|
73
|
+
}
|
|
74
|
+
async function saveState(options) {
|
|
75
|
+
return persistWalletMutationState(options);
|
|
76
|
+
}
|
|
77
|
+
export async function reconcilePendingAnchorMutation(options) {
|
|
78
|
+
if (options.mutation.status === "repair-required") {
|
|
79
|
+
return {
|
|
80
|
+
state: options.operation.state,
|
|
81
|
+
mutation: options.mutation,
|
|
82
|
+
resolution: "repair-required",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (options.context.snapshot !== null && anchorConfirmedOnSnapshot({
|
|
86
|
+
snapshot: options.context.snapshot,
|
|
87
|
+
state: options.operation.state,
|
|
88
|
+
domainName: options.mutation.domainName,
|
|
89
|
+
})) {
|
|
90
|
+
await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
|
|
91
|
+
const confirmedMutation = updateMutationRecord(options.mutation, "confirmed", options.nowUnixMs, {
|
|
92
|
+
temporaryBuilderLockedOutpoints: [],
|
|
93
|
+
});
|
|
94
|
+
const chainDomain = lookupDomain(options.context.snapshot.state, options.mutation.domainName);
|
|
95
|
+
const nextState = upsertAnchoredDomainRecord({
|
|
96
|
+
state: upsertPendingMutation(options.operation.state, confirmedMutation),
|
|
97
|
+
domainName: options.mutation.domainName,
|
|
98
|
+
domainId: chainDomain?.domainId ?? 0,
|
|
99
|
+
foundingMessageText: options.operation.message.text,
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
state: await saveState({
|
|
103
|
+
state: nextState,
|
|
104
|
+
provider: options.provider,
|
|
105
|
+
nowUnixMs: options.nowUnixMs,
|
|
106
|
+
paths: options.paths,
|
|
107
|
+
}),
|
|
108
|
+
mutation: confirmedMutation,
|
|
109
|
+
resolution: "confirmed",
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (options.mutation.attemptedTxid !== null) {
|
|
113
|
+
const mempool = await options.rpc.getRawMempool().catch(() => []);
|
|
114
|
+
if (mempool.includes(options.mutation.attemptedTxid)) {
|
|
115
|
+
await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
|
|
116
|
+
const liveMutation = updateMutationRecord(options.mutation, "live", options.nowUnixMs, {
|
|
117
|
+
temporaryBuilderLockedOutpoints: [],
|
|
118
|
+
});
|
|
119
|
+
const domainId = (options.context.snapshot === null
|
|
120
|
+
? null
|
|
121
|
+
: lookupDomain(options.context.snapshot.state, options.mutation.domainName)?.domainId)
|
|
122
|
+
?? options.operation.state.domains.find((domain) => domain.name === options.mutation.domainName)?.domainId
|
|
123
|
+
?? 0;
|
|
124
|
+
const nextState = upsertAnchoredDomainRecord({
|
|
125
|
+
state: upsertPendingMutation(options.operation.state, liveMutation),
|
|
126
|
+
domainName: options.mutation.domainName,
|
|
127
|
+
domainId,
|
|
128
|
+
foundingMessageText: options.operation.message.text,
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
state: await saveState({
|
|
132
|
+
state: nextState,
|
|
133
|
+
provider: options.provider,
|
|
134
|
+
nowUnixMs: options.nowUnixMs,
|
|
135
|
+
paths: options.paths,
|
|
136
|
+
}),
|
|
137
|
+
mutation: liveMutation,
|
|
138
|
+
resolution: "live",
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (options.mutation.status === "broadcast-unknown"
|
|
143
|
+
|| options.mutation.status === "live"
|
|
144
|
+
|| options.mutation.status === "draft"
|
|
145
|
+
|| options.mutation.status === "broadcasting") {
|
|
146
|
+
await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
|
|
147
|
+
const canceledMutation = updateMutationRecord(options.mutation, "canceled", options.nowUnixMs, {
|
|
148
|
+
temporaryBuilderLockedOutpoints: [],
|
|
149
|
+
});
|
|
150
|
+
const nextState = upsertPendingMutation(options.operation.state, canceledMutation);
|
|
151
|
+
return {
|
|
152
|
+
state: await saveState({
|
|
153
|
+
state: nextState,
|
|
154
|
+
provider: options.provider,
|
|
155
|
+
nowUnixMs: options.nowUnixMs,
|
|
156
|
+
paths: options.paths,
|
|
157
|
+
}),
|
|
158
|
+
mutation: canceledMutation,
|
|
159
|
+
resolution: "not-seen",
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
state: options.operation.state,
|
|
164
|
+
mutation: options.mutation,
|
|
165
|
+
resolution: "continue",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AnchorDomainOptions } from "./intent.js";
|
|
2
|
+
import { type AnchorDomainResult } from "./result.js";
|
|
3
|
+
export type { AnchorDomainOptions } from "./intent.js";
|
|
4
|
+
export type { AnchorDomainResult } from "./result.js";
|
|
5
|
+
export declare function anchorDomain(options: AnchorDomainOptions): Promise<AnchorDomainResult>;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { buildWalletMutationTransactionWithReserveFallback, mergeFixedWalletInputs, updateMutationRecord, } from "../common.js";
|
|
2
|
+
import { executeWalletMutationOperation, publishWalletMutation, resolveExistingWalletMutation, } from "../executor.js";
|
|
3
|
+
import { upsertPendingMutation } from "../journal.js";
|
|
4
|
+
import { confirmDirectAnchor, resolveFoundingMessage } from "./confirm.js";
|
|
5
|
+
import { anchorConfirmedOnSnapshot, createDraftAnchorMutation, reconcilePendingAnchorMutation, upsertAnchoredDomainRecord, } from "./draft.js";
|
|
6
|
+
import { buildDirectAnchorPlan, createAnchorOperationFingerprint, normalizeAnchorDomainName, resolveAnchorOperation, } from "./intent.js";
|
|
7
|
+
import { validateDirectAnchorDraft } from "./plan.js";
|
|
8
|
+
import { createAnchorResult, createAnchorReuseResult, } from "./result.js";
|
|
9
|
+
export async function anchorDomain(options) {
|
|
10
|
+
if (!options.prompter.isInteractive) {
|
|
11
|
+
throw new Error("wallet_anchor_requires_tty");
|
|
12
|
+
}
|
|
13
|
+
const normalizedDomainName = normalizeAnchorDomainName(options.domainName);
|
|
14
|
+
const execution = await executeWalletMutationOperation({
|
|
15
|
+
...options,
|
|
16
|
+
controlLockPurpose: "wallet-anchor",
|
|
17
|
+
preemptionReason: "wallet-anchor",
|
|
18
|
+
async resolveOperation(readContext) {
|
|
19
|
+
const message = await resolveFoundingMessage({
|
|
20
|
+
foundingMessageText: options.foundingMessageText,
|
|
21
|
+
promptForFoundingMessageWhenMissing: options.promptForFoundingMessageWhenMissing,
|
|
22
|
+
prompter: options.prompter,
|
|
23
|
+
});
|
|
24
|
+
return resolveAnchorOperation({
|
|
25
|
+
readContext,
|
|
26
|
+
normalizedDomainName,
|
|
27
|
+
message,
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
createIntentFingerprint(operation) {
|
|
31
|
+
return createAnchorOperationFingerprint(operation);
|
|
32
|
+
},
|
|
33
|
+
async resolveExistingMutation({ operation, existingMutation, execution }) {
|
|
34
|
+
if (existingMutation === null) {
|
|
35
|
+
return { state: operation.state, replacementFixedInputs: null, result: null };
|
|
36
|
+
}
|
|
37
|
+
return resolveExistingWalletMutation({
|
|
38
|
+
existingMutation,
|
|
39
|
+
execution,
|
|
40
|
+
repairRequiredErrorCode: "wallet_anchor_repair_required",
|
|
41
|
+
reconcileExistingMutation: (mutation) => reconcilePendingAnchorMutation({
|
|
42
|
+
operation,
|
|
43
|
+
mutation,
|
|
44
|
+
provider: execution.provider,
|
|
45
|
+
nowUnixMs: execution.nowUnixMs,
|
|
46
|
+
paths: execution.paths,
|
|
47
|
+
rpc: execution.rpc,
|
|
48
|
+
walletName: execution.walletName,
|
|
49
|
+
context: execution.readContext,
|
|
50
|
+
}),
|
|
51
|
+
createReuseResult: ({ mutation, resolution, fees }) => createAnchorReuseResult({
|
|
52
|
+
operation,
|
|
53
|
+
mutation,
|
|
54
|
+
resolution,
|
|
55
|
+
fees,
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
confirm({ operation }) {
|
|
60
|
+
return confirmDirectAnchor(options.prompter, {
|
|
61
|
+
domainName: operation.normalizedDomainName,
|
|
62
|
+
walletAddress: operation.state.funding.address,
|
|
63
|
+
foundingMessageText: operation.message.text,
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
createDraftMutation({ operation, existingMutation, execution, intentFingerprintHex }) {
|
|
67
|
+
return {
|
|
68
|
+
mutation: createDraftAnchorMutation({
|
|
69
|
+
state: operation.state,
|
|
70
|
+
domainName: operation.normalizedDomainName,
|
|
71
|
+
intentFingerprintHex,
|
|
72
|
+
nowUnixMs: execution.nowUnixMs,
|
|
73
|
+
feeSelection: execution.feeSelection,
|
|
74
|
+
existing: existingMutation ?? null,
|
|
75
|
+
}),
|
|
76
|
+
prepared: null,
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
async build({ operation, state, execution, replacementFixedInputs }) {
|
|
80
|
+
const directAnchorPlan = buildDirectAnchorPlan({
|
|
81
|
+
state,
|
|
82
|
+
allUtxos: await execution.rpc.listUnspent(execution.walletName, 1),
|
|
83
|
+
domainId: operation.chainDomain.domainId,
|
|
84
|
+
foundingMessagePayloadHex: operation.message.payloadHex,
|
|
85
|
+
});
|
|
86
|
+
return buildWalletMutationTransactionWithReserveFallback({
|
|
87
|
+
rpc: execution.rpc,
|
|
88
|
+
walletName: execution.walletName,
|
|
89
|
+
state,
|
|
90
|
+
plan: {
|
|
91
|
+
...directAnchorPlan,
|
|
92
|
+
fixedInputs: mergeFixedWalletInputs(directAnchorPlan.fixedInputs, replacementFixedInputs),
|
|
93
|
+
},
|
|
94
|
+
validateFundedDraft: validateDirectAnchorDraft,
|
|
95
|
+
finalizeErrorCode: "wallet_anchor_finalize_failed",
|
|
96
|
+
mempoolRejectPrefix: "wallet_anchor_mempool_rejected",
|
|
97
|
+
feeRate: execution.feeSelection.feeRateSatVb,
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
publish({ operation, state, execution, built, mutation }) {
|
|
101
|
+
return publishWalletMutation({
|
|
102
|
+
rpc: execution.rpc,
|
|
103
|
+
walletName: execution.walletName,
|
|
104
|
+
snapshotHeight: execution.readContext.snapshot?.tip?.height ?? null,
|
|
105
|
+
built,
|
|
106
|
+
mutation,
|
|
107
|
+
state,
|
|
108
|
+
provider: execution.provider,
|
|
109
|
+
nowUnixMs: execution.nowUnixMs,
|
|
110
|
+
paths: execution.paths,
|
|
111
|
+
errorPrefix: "wallet_anchor",
|
|
112
|
+
async afterAccepted({ state: acceptedState, broadcastingMutation, built, nowUnixMs }) {
|
|
113
|
+
const finalStatus = anchorConfirmedOnSnapshot({
|
|
114
|
+
snapshot: execution.readContext.snapshot,
|
|
115
|
+
state: acceptedState,
|
|
116
|
+
domainName: operation.normalizedDomainName,
|
|
117
|
+
}) ? "confirmed" : "live";
|
|
118
|
+
const finalMutation = updateMutationRecord(broadcastingMutation, finalStatus, nowUnixMs, {
|
|
119
|
+
attemptedTxid: built.txid,
|
|
120
|
+
attemptedWtxid: built.wtxid,
|
|
121
|
+
temporaryBuilderLockedOutpoints: [],
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
state: upsertAnchoredDomainRecord({
|
|
125
|
+
state: upsertPendingMutation(acceptedState, finalMutation),
|
|
126
|
+
domainName: operation.normalizedDomainName,
|
|
127
|
+
domainId: operation.chainDomain.domainId,
|
|
128
|
+
foundingMessageText: operation.message.text,
|
|
129
|
+
}),
|
|
130
|
+
mutation: finalMutation,
|
|
131
|
+
status: finalStatus,
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
createResult({ operation, mutation, built, status, reusedExisting, fees }) {
|
|
137
|
+
return createAnchorResult({
|
|
138
|
+
operation,
|
|
139
|
+
mutation,
|
|
140
|
+
builtTxid: built?.txid ?? null,
|
|
141
|
+
status: status,
|
|
142
|
+
reusedExisting,
|
|
143
|
+
fees,
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
return execution.result;
|
|
148
|
+
}
|