@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
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { WalletFieldView, WalletLockView, WalletReadContext } from "../wallet/read/index.js";
|
|
2
|
+
export declare function listVisibleWalletLocks(context: WalletReadContext, options: {
|
|
3
|
+
claimableOnly: boolean;
|
|
4
|
+
reclaimableOnly: boolean;
|
|
5
|
+
}): WalletLockView[] | null;
|
|
6
|
+
export declare function listVisibleDomainFields(context: WalletReadContext, domainName: string): WalletFieldView[] | null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { listDomainFields, listWalletLocks, } from "../wallet/read/index.js";
|
|
2
|
+
export function listVisibleWalletLocks(context, options) {
|
|
3
|
+
const locks = listWalletLocks(context);
|
|
4
|
+
if (locks === null) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
if (options.claimableOnly) {
|
|
8
|
+
return locks.filter((lock) => lock.claimableNow);
|
|
9
|
+
}
|
|
10
|
+
if (options.reclaimableOnly) {
|
|
11
|
+
return locks.filter((lock) => lock.reclaimableNow);
|
|
12
|
+
}
|
|
13
|
+
return locks;
|
|
14
|
+
}
|
|
15
|
+
export function listVisibleDomainFields(context, domainName) {
|
|
16
|
+
return listDomainFields(context, domainName);
|
|
17
|
+
}
|
|
@@ -45,7 +45,7 @@ export declare function buildMiningGenerationRequest(options: {
|
|
|
45
45
|
requiredWords: [string, string, string, string, string];
|
|
46
46
|
}>;
|
|
47
47
|
domainExtraPrompts: Record<string, string>;
|
|
48
|
-
|
|
48
|
+
fallbackInstruction: string | null;
|
|
49
49
|
}): MiningSentenceGenerationRequest;
|
|
50
50
|
export declare function generateCandidatesForDomains(options: {
|
|
51
51
|
rpc: MiningRpcClient;
|
|
@@ -114,13 +114,13 @@ export function buildMiningGenerationRequest(options) {
|
|
|
114
114
|
targetBlockHeight: options.targetBlockHeight,
|
|
115
115
|
referencedBlockHashDisplay: options.referencedBlockHashDisplay,
|
|
116
116
|
generatedAtUnixMs: options.generatedAtUnixMs ?? Date.now(),
|
|
117
|
-
|
|
117
|
+
fallbackInstruction: options.fallbackInstruction,
|
|
118
118
|
limits: createMiningSentenceRequestLimits(),
|
|
119
119
|
rootDomains: options.domains.map((domain) => ({
|
|
120
120
|
domainId: domain.domainId,
|
|
121
121
|
domainName: domain.domainName,
|
|
122
122
|
requiredWords: domain.requiredWords,
|
|
123
|
-
|
|
123
|
+
domainInstruction: options.domainExtraPrompts[domain.domainName.toLowerCase()] ?? null,
|
|
124
124
|
})),
|
|
125
125
|
};
|
|
126
126
|
}
|
|
@@ -193,7 +193,7 @@ export async function generateCandidatesForDomains(options) {
|
|
|
193
193
|
referencedBlockHashDisplay: bestBlockHash,
|
|
194
194
|
domains: rootDomains,
|
|
195
195
|
domainExtraPrompts: clientConfig?.mining.domainExtraPrompts ?? {},
|
|
196
|
-
|
|
196
|
+
fallbackInstruction: clientConfig?.mining.builtIn?.extraPrompt ?? null,
|
|
197
197
|
});
|
|
198
198
|
let generated;
|
|
199
199
|
try {
|
|
@@ -10,8 +10,8 @@ export declare const MINING_LOOP_INTERVAL_MS = 2000;
|
|
|
10
10
|
export declare const MINING_BUILTIN_TIMEOUT_MS = 30000;
|
|
11
11
|
export declare const MINING_SENTENCE_SCHEMA_VERSION: 1;
|
|
12
12
|
export declare const MINING_SENTENCE_MAX_CANDIDATE_SENTENCE_UTF8_BYTES = 512;
|
|
13
|
-
export declare const MINING_SENTENCE_MAX_CANDIDATES_PER_ROOT_DOMAIN =
|
|
14
|
-
export declare const MINING_SENTENCE_MAX_CANDIDATES_TOTAL =
|
|
13
|
+
export declare const MINING_SENTENCE_MAX_CANDIDATES_PER_ROOT_DOMAIN = 25;
|
|
14
|
+
export declare const MINING_SENTENCE_MAX_CANDIDATES_TOTAL = 500;
|
|
15
15
|
export declare const MINING_SENTENCE_TIMEOUT_MS = 30000;
|
|
16
16
|
export declare const MINING_SHUTDOWN_GRACE_MS = 15000;
|
|
17
17
|
export declare const MINING_SETTLEMENT_DUMMY_REWARD = 100n;
|
|
@@ -10,8 +10,8 @@ export const MINING_LOOP_INTERVAL_MS = 2_000;
|
|
|
10
10
|
export const MINING_BUILTIN_TIMEOUT_MS = 30_000;
|
|
11
11
|
export const MINING_SENTENCE_SCHEMA_VERSION = 1;
|
|
12
12
|
export const MINING_SENTENCE_MAX_CANDIDATE_SENTENCE_UTF8_BYTES = 512;
|
|
13
|
-
export const MINING_SENTENCE_MAX_CANDIDATES_PER_ROOT_DOMAIN =
|
|
14
|
-
export const MINING_SENTENCE_MAX_CANDIDATES_TOTAL =
|
|
13
|
+
export const MINING_SENTENCE_MAX_CANDIDATES_PER_ROOT_DOMAIN = 25;
|
|
14
|
+
export const MINING_SENTENCE_MAX_CANDIDATES_TOTAL = 500;
|
|
15
15
|
export const MINING_SENTENCE_TIMEOUT_MS = 30_000;
|
|
16
16
|
export const MINING_SHUTDOWN_GRACE_MS = 15_000;
|
|
17
17
|
export const MINING_SETTLEMENT_DUMMY_REWARD = 100n;
|
|
@@ -88,6 +88,7 @@ export type ReadyMiningReadContext = WalletReadContext & {
|
|
|
88
88
|
snapshot: NonNullable<WalletReadContext["snapshot"]>;
|
|
89
89
|
model: NonNullable<WalletReadContext["model"]>;
|
|
90
90
|
};
|
|
91
|
+
export declare function resolveReadyMiningReadContext(readContext: WalletReadContext): ReadyMiningReadContext | null;
|
|
91
92
|
export interface MiningPublishSkipResult {
|
|
92
93
|
state: WalletStateV1;
|
|
93
94
|
txid: null;
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export function resolveReadyMiningReadContext(readContext) {
|
|
2
|
+
if (readContext.localState.availability !== "ready"
|
|
3
|
+
|| readContext.localState.state === null
|
|
4
|
+
|| readContext.snapshot === null
|
|
5
|
+
|| readContext.model === null) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
return readContext;
|
|
9
|
+
}
|
|
@@ -6,7 +6,7 @@ import { serializeMine } from "../cogop/index.js";
|
|
|
6
6
|
import { openWalletReadContext } from "../read/index.js";
|
|
7
7
|
import { assertFixedInputPrefixMatches, buildWalletMutationTransaction, fundAndValidateWalletMutationDraft, isAlreadyAcceptedError, isBroadcastUnknownError, isInsufficientFundsError, outpointKey as walletMutationOutpointKey, reconcilePersistentPolicyLocks, resolveWalletMutationFeeSelection, saveWalletStatePreservingUnlock, } from "../tx/common.js";
|
|
8
8
|
import { createMiningEventRecord } from "./events.js";
|
|
9
|
-
import {} from "./engine-types.js";
|
|
9
|
+
import { resolveReadyMiningReadContext, } from "./engine-types.js";
|
|
10
10
|
import { cloneMiningState, defaultMiningStatePatch, livePublishTargetsCandidateTip, miningCandidateIsCurrent, resolveSharedMiningConflictOutpoint, } from "./engine-state.js";
|
|
11
11
|
import { deriveMiningWordIndices, numberToSats, resolveBip39WordsFromIndices, } from "./engine-utils.js";
|
|
12
12
|
import { clearMiningPublishState, miningPublishMayStillExist, } from "./state.js";
|
|
@@ -576,13 +576,10 @@ export async function publishCandidate(options) {
|
|
|
576
576
|
});
|
|
577
577
|
try {
|
|
578
578
|
options.throwIfStopping?.();
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|| lockedReadContext.snapshot === null
|
|
582
|
-
|| lockedReadContext.model === null) {
|
|
579
|
+
const readyReadContext = resolveReadyMiningReadContext(lockedReadContext);
|
|
580
|
+
if (readyReadContext === null) {
|
|
583
581
|
return await createStaleCandidateSkipResult(options.fallbackState);
|
|
584
582
|
}
|
|
585
|
-
const readyReadContext = lockedReadContext;
|
|
586
583
|
const refreshedCandidate = refreshMiningCandidateFromCurrentState(readyReadContext, options.candidate);
|
|
587
584
|
if (refreshedCandidate === null) {
|
|
588
585
|
return await createStaleCandidateSkipResult(readyReadContext.localState.state);
|
|
@@ -27,6 +27,7 @@ import { createInsufficientFundsMiningPublishErrorMessage as createInsufficientF
|
|
|
27
27
|
import { runMiningPhaseMachine } from "./cycle.js";
|
|
28
28
|
import { attemptSaveMempool, handleDetectedMiningRuntimeResume, handleRecoverableMiningBitcoindFailure, isRecoverableMiningBitcoindError, refreshAndSaveMiningRuntimeStatus, resetMiningBitcoindRecoveryState, saveStopSnapshot, } from "./lifecycle.js";
|
|
29
29
|
import { compareLexicographically, deriveMiningWordIndices, getBlockRewardCogtoshi, numberToSats, resolveBip39WordsFromIndices, rootDomain, tieBreakHash, } from "./engine-utils.js";
|
|
30
|
+
import { resolveReadyMiningReadContext } from "./engine-types.js";
|
|
30
31
|
import { isMiningGenerationAbortRequested, markMiningGenerationActive, markMiningGenerationInactive, readMiningGenerationActivity, readMiningPreemptionRequest, requestMiningGenerationPreemption, } from "./coordination.js";
|
|
31
32
|
import { clearMiningPublishState, miningPublishIsInMempool, miningPublishMayStillExist, normalizeMiningPublishState, normalizeMiningStateRecord, } from "./state.js";
|
|
32
33
|
import { runForegroundMining as runForegroundMiningSupervisor, } from "./supervisor.js";
|
|
@@ -292,9 +293,20 @@ async function performMiningCycle(options) {
|
|
|
292
293
|
}
|
|
293
294
|
const displaySats = await resolveFundingDisplaySats(effectiveReadContext.localState.state, rpc).catch(() => null);
|
|
294
295
|
syncMiningVisualizerBalances(options.loopState, effectiveReadContext, displaySats);
|
|
295
|
-
|
|
296
|
+
const readyReadContext = resolveReadyMiningReadContext(effectiveReadContext);
|
|
297
|
+
if (readyReadContext === null) {
|
|
296
298
|
clearMiningProviderWait(options.loopState);
|
|
297
299
|
await saveCycleStatus(effectiveReadContext, {
|
|
300
|
+
runMode: options.runMode,
|
|
301
|
+
currentPhase: "waiting-indexer",
|
|
302
|
+
lastError: null,
|
|
303
|
+
note: "Mining is waiting for Bitcoin Core and the indexer to align.",
|
|
304
|
+
});
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (readyReadContext.localState.state.miningState.state === "repair-required") {
|
|
308
|
+
clearMiningProviderWait(options.loopState);
|
|
309
|
+
await saveCycleStatus(readyReadContext, {
|
|
298
310
|
runMode: options.runMode,
|
|
299
311
|
currentPhase: "waiting",
|
|
300
312
|
lastError: null,
|
|
@@ -302,9 +314,9 @@ async function performMiningCycle(options) {
|
|
|
302
314
|
});
|
|
303
315
|
return;
|
|
304
316
|
}
|
|
305
|
-
if (hasBlockingMutation(
|
|
317
|
+
if (hasBlockingMutation(readyReadContext.localState.state)) {
|
|
306
318
|
clearMiningProviderWait(options.loopState);
|
|
307
|
-
const nextState = defaultMiningStatePatch(
|
|
319
|
+
const nextState = defaultMiningStatePatch(readyReadContext.localState.state, {
|
|
308
320
|
state: "paused",
|
|
309
321
|
pauseReason: "wallet-busy",
|
|
310
322
|
});
|
|
@@ -313,15 +325,15 @@ async function performMiningCycle(options) {
|
|
|
313
325
|
provider: options.provider,
|
|
314
326
|
paths: options.paths,
|
|
315
327
|
});
|
|
316
|
-
|
|
317
|
-
...
|
|
328
|
+
const blockedReadContext = {
|
|
329
|
+
...readyReadContext,
|
|
318
330
|
localState: {
|
|
319
|
-
...
|
|
331
|
+
...readyReadContext.localState,
|
|
320
332
|
availability: "ready",
|
|
321
333
|
state: nextState,
|
|
322
334
|
},
|
|
323
335
|
};
|
|
324
|
-
await saveCycleStatus(
|
|
336
|
+
await saveCycleStatus(blockedReadContext, {
|
|
325
337
|
runMode: options.runMode,
|
|
326
338
|
currentPhase: "waiting",
|
|
327
339
|
lastError: null,
|
|
@@ -332,9 +344,9 @@ async function performMiningCycle(options) {
|
|
|
332
344
|
const preemptionRequest = await readMiningPreemptionRequest(options.paths);
|
|
333
345
|
if (preemptionRequest !== null) {
|
|
334
346
|
clearMiningProviderWait(options.loopState);
|
|
335
|
-
const nextState = defaultMiningStatePatch(
|
|
336
|
-
state:
|
|
337
|
-
&&
|
|
347
|
+
const nextState = defaultMiningStatePatch(readyReadContext.localState.state, {
|
|
348
|
+
state: readyReadContext.localState.state.miningState.livePublishInMempool
|
|
349
|
+
&& readyReadContext.localState.state.miningState.state === "paused-stale"
|
|
338
350
|
? "paused-stale"
|
|
339
351
|
: "paused",
|
|
340
352
|
pauseReason: preemptionRequest.reason,
|
|
@@ -345,9 +357,9 @@ async function performMiningCycle(options) {
|
|
|
345
357
|
paths: options.paths,
|
|
346
358
|
});
|
|
347
359
|
await saveCycleStatus({
|
|
348
|
-
...
|
|
360
|
+
...readyReadContext,
|
|
349
361
|
localState: {
|
|
350
|
-
...
|
|
362
|
+
...readyReadContext.localState,
|
|
351
363
|
state: nextState,
|
|
352
364
|
},
|
|
353
365
|
}, {
|
|
@@ -370,10 +382,10 @@ async function performMiningCycle(options) {
|
|
|
370
382
|
network: networkInfo,
|
|
371
383
|
mempool: mempoolInfo,
|
|
372
384
|
});
|
|
373
|
-
clearRecoveredBitcoindError = resetMiningBitcoindRecoveryState(options.loopState,
|
|
385
|
+
clearRecoveredBitcoindError = resetMiningBitcoindRecoveryState(options.loopState, readyReadContext.nodeStatus?.serviceStatus ?? { pid: service.pid });
|
|
374
386
|
if (targetBlockHeight !== null && getBlockRewardCogtoshi(targetBlockHeight) === 0n) {
|
|
375
387
|
clearMiningProviderWait(options.loopState);
|
|
376
|
-
const nextState = defaultMiningStatePatch(
|
|
388
|
+
const nextState = defaultMiningStatePatch(readyReadContext.localState.state, {
|
|
377
389
|
state: "paused",
|
|
378
390
|
pauseReason: "zero-reward",
|
|
379
391
|
});
|
|
@@ -383,9 +395,9 @@ async function performMiningCycle(options) {
|
|
|
383
395
|
paths: options.paths,
|
|
384
396
|
});
|
|
385
397
|
await saveCycleStatus({
|
|
386
|
-
...
|
|
398
|
+
...readyReadContext,
|
|
387
399
|
localState: {
|
|
388
|
-
...
|
|
400
|
+
...readyReadContext.localState,
|
|
389
401
|
state: nextState,
|
|
390
402
|
},
|
|
391
403
|
}, {
|
|
@@ -397,7 +409,7 @@ async function performMiningCycle(options) {
|
|
|
397
409
|
});
|
|
398
410
|
await appendEvent(options.paths, createEvent("publish-skipped-zero-reward", "Skipped mining because the target block reward is zero.", {
|
|
399
411
|
targetBlockHeight,
|
|
400
|
-
referencedBlockHashDisplay:
|
|
412
|
+
referencedBlockHashDisplay: readyReadContext.nodeStatus?.nodeBestHashHex ?? null,
|
|
401
413
|
runId: options.backgroundWorkerRunId,
|
|
402
414
|
}));
|
|
403
415
|
return;
|
|
@@ -409,7 +421,7 @@ async function performMiningCycle(options) {
|
|
|
409
421
|
paths: options.paths,
|
|
410
422
|
runMode: options.runMode,
|
|
411
423
|
backgroundWorkerRunId: options.backgroundWorkerRunId,
|
|
412
|
-
readContext:
|
|
424
|
+
readContext: readyReadContext,
|
|
413
425
|
rpc,
|
|
414
426
|
targetBlockHeight,
|
|
415
427
|
tipKey,
|
|
@@ -5,7 +5,7 @@ export interface MiningSentenceGenerationRequestV1 {
|
|
|
5
5
|
targetBlockHeight: number;
|
|
6
6
|
referencedBlockHashDisplay: string;
|
|
7
7
|
generatedAtUnixMs: number;
|
|
8
|
-
|
|
8
|
+
fallbackInstruction: string | null;
|
|
9
9
|
limits: {
|
|
10
10
|
maxCandidatesPerRootDomain: number;
|
|
11
11
|
maxCandidatesTotal: number;
|
|
@@ -16,7 +16,7 @@ export interface MiningSentenceGenerationRequestV1 {
|
|
|
16
16
|
domainId: number;
|
|
17
17
|
domainName: string;
|
|
18
18
|
requiredWords: [string, string, string, string, string];
|
|
19
|
-
|
|
19
|
+
domainInstruction: string | null;
|
|
20
20
|
}>;
|
|
21
21
|
}
|
|
22
22
|
export interface MiningSentenceCandidateV1 {
|
|
@@ -26,20 +26,20 @@ function createBuiltInProviderTimeoutError(options) {
|
|
|
26
26
|
const unit = seconds === "1" ? "second" : "seconds";
|
|
27
27
|
return new MiningProviderRequestError("unavailable", `The built-in ${providerName} mining provider timed out after ${seconds} ${unit}.`);
|
|
28
28
|
}
|
|
29
|
-
function buildSystemPrompt(
|
|
29
|
+
function buildSystemPrompt(fallbackInstruction) {
|
|
30
30
|
const lines = [
|
|
31
31
|
"You are helping generate candidate Cogcoin mining sentences.",
|
|
32
32
|
"Return only JSON matching the requested response schema.",
|
|
33
33
|
"Every sentence must be a single natural-language sentence.",
|
|
34
34
|
"Do not add commentary, markdown, or code fences.",
|
|
35
35
|
"Do not invent domain IDs or request IDs.",
|
|
36
|
-
"Each rootDomains entry may include
|
|
37
|
-
"If rootDomains[i].
|
|
38
|
-
"If rootDomains[i].
|
|
36
|
+
"Each rootDomains entry may include a domainInstruction that applies only to that domain.",
|
|
37
|
+
"If rootDomains[i].domainInstruction is present, use it only for candidates for that domainId.",
|
|
38
|
+
"If rootDomains[i].domainInstruction is null, fall back to the request-level fallbackInstruction when it is present.",
|
|
39
39
|
"Never apply one domain's prompt to another domain's candidates.",
|
|
40
40
|
];
|
|
41
|
-
if (
|
|
42
|
-
lines.push(`Request-level fallback instruction: ${
|
|
41
|
+
if (fallbackInstruction !== null && fallbackInstruction.trim().length > 0) {
|
|
42
|
+
lines.push(`Request-level fallback instruction: ${fallbackInstruction.trim()}`);
|
|
43
43
|
}
|
|
44
44
|
return lines.join("\n");
|
|
45
45
|
}
|
|
@@ -162,7 +162,7 @@ async function requestBuiltInSentences(options) {
|
|
|
162
162
|
input: [
|
|
163
163
|
{
|
|
164
164
|
role: "system",
|
|
165
|
-
content: buildSystemPrompt(options.request.
|
|
165
|
+
content: buildSystemPrompt(options.request.fallbackInstruction),
|
|
166
166
|
},
|
|
167
167
|
{
|
|
168
168
|
role: "user",
|
|
@@ -209,7 +209,7 @@ async function requestBuiltInSentences(options) {
|
|
|
209
209
|
body: JSON.stringify({
|
|
210
210
|
model,
|
|
211
211
|
max_tokens: 1_200,
|
|
212
|
-
system: buildSystemPrompt(options.request.
|
|
212
|
+
system: buildSystemPrompt(options.request.fallbackInstruction),
|
|
213
213
|
messages: [
|
|
214
214
|
{
|
|
215
215
|
role: "user",
|
|
@@ -64,9 +64,6 @@ function formatRewardCogAmount(value) {
|
|
|
64
64
|
minFractionDigits: 1,
|
|
65
65
|
})} COG`;
|
|
66
66
|
}
|
|
67
|
-
function escapeRegExp(value) {
|
|
68
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
69
|
-
}
|
|
70
67
|
function consumeWrappedLine(text, capacity) {
|
|
71
68
|
const remaining = text.trimStart();
|
|
72
69
|
if (remaining.length <= capacity) {
|
|
@@ -91,12 +88,16 @@ function consumeWrappedLine(text, capacity) {
|
|
|
91
88
|
function highlightRequiredWords(sentence, requiredWords) {
|
|
92
89
|
const uniqueWords = [...new Set(requiredWords
|
|
93
90
|
.map((word) => word.trim().toLowerCase())
|
|
94
|
-
.filter((word) => word.length > 0))]
|
|
91
|
+
.filter((word) => word.length > 0))];
|
|
95
92
|
if (uniqueWords.length === 0) {
|
|
96
93
|
return sentence;
|
|
97
94
|
}
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
return sentence.replace(/[A-Za-z]+/g, (match) => {
|
|
96
|
+
const normalizedToken = match.toLowerCase();
|
|
97
|
+
return uniqueWords.some((word) => normalizedToken.includes(word))
|
|
98
|
+
? match.toUpperCase()
|
|
99
|
+
: match;
|
|
100
|
+
});
|
|
100
101
|
}
|
|
101
102
|
function formatSentenceSlot(prefix, sentence, requiredWords, lineCount) {
|
|
102
103
|
if (sentence === null) {
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
export { readSnapshotWithRetry, } from "../../bitcoind/indexer-daemon.js";
|
|
2
2
|
import { type WalletSecretProvider } from "../state/provider.js";
|
|
3
|
-
import
|
|
3
|
+
import { inspectWalletLocalState } from "./local-state.js";
|
|
4
|
+
import type { WalletReadContext } from "./types.js";
|
|
4
5
|
import type { WalletRuntimePaths } from "../runtime.js";
|
|
5
|
-
declare function inspectWalletLocalState(options?: {
|
|
6
|
-
dataDir?: string;
|
|
7
|
-
secretProvider?: WalletSecretProvider;
|
|
8
|
-
now?: number;
|
|
9
|
-
paths?: WalletRuntimePaths;
|
|
10
|
-
walletControlLockHeld?: boolean;
|
|
11
|
-
}): Promise<WalletLocalStateStatus>;
|
|
12
6
|
export declare function openWalletReadContext(options: {
|
|
13
7
|
dataDir: string;
|
|
14
8
|
databasePath: string;
|
|
@@ -19,4 +13,4 @@ export declare function openWalletReadContext(options: {
|
|
|
19
13
|
now?: number;
|
|
20
14
|
paths?: WalletRuntimePaths;
|
|
21
15
|
}): Promise<WalletReadContext>;
|
|
22
|
-
export { inspectWalletLocalState,
|
|
16
|
+
export { inspectWalletLocalState, };
|
|
@@ -1,236 +1,13 @@
|
|
|
1
|
-
import { access, constants } from "node:fs/promises";
|
|
2
1
|
import { readPackageVersionFromDisk } from "../../package-version.js";
|
|
3
|
-
|
|
4
|
-
import { createRpcClient } from "../../bitcoind/node.js";
|
|
2
|
+
export { readSnapshotWithRetry, } from "../../bitcoind/indexer-daemon.js";
|
|
5
3
|
import { UNINITIALIZED_WALLET_ROOT_ID } from "../../bitcoind/service-paths.js";
|
|
6
|
-
import { attachOrStartManagedBitcoindService } from "../../bitcoind/service.js";
|
|
7
|
-
import {} from "../../bitcoind/types.js";
|
|
8
|
-
import { normalizeWalletStateRecord, persistWalletCoinControlStateIfNeeded } from "../coin-control.js";
|
|
9
|
-
import { persistNormalizedWalletDescriptorStateIfNeeded } from "../descriptor-normalization.js";
|
|
10
4
|
import { inspectMiningControlPlane } from "../mining/index.js";
|
|
11
|
-
import { normalizeMiningStateRecord } from "../mining/state.js";
|
|
12
|
-
import { resolveWalletRootIdFromLocalArtifacts } from "../root-resolution.js";
|
|
13
5
|
import { resolveWalletRuntimePathsForTesting } from "../runtime.js";
|
|
14
|
-
import {
|
|
15
|
-
import { createDefaultWalletSecretProvider, createWalletSecretReference, inspectClientPasswordSetupReadiness, } from "../state/provider.js";
|
|
16
|
-
import { describeClientPasswordLockedMessage, describeClientPasswordMigrationMessage, describeClientPasswordSetupMessage, } from "../state/client-password.js";
|
|
6
|
+
import { createDefaultWalletSecretProvider, } from "../state/provider.js";
|
|
17
7
|
import { openManagedWalletReadServiceBundle } from "./managed-services.js";
|
|
8
|
+
import { inspectWalletLocalState, readFundingSpendableSats } from "./local-state.js";
|
|
18
9
|
import { createWalletReadModel } from "./project.js";
|
|
19
10
|
const DEFAULT_SERVICE_START_TIMEOUT_MS = 60_000;
|
|
20
|
-
function btcAmountToSats(value) {
|
|
21
|
-
return BigInt(Math.round(value * 100_000_000));
|
|
22
|
-
}
|
|
23
|
-
function isSpendableFundingUtxo(entry, fundingScriptPubKeyHex) {
|
|
24
|
-
return entry.scriptPubKey === fundingScriptPubKeyHex
|
|
25
|
-
&& entry.confirmations >= 1
|
|
26
|
-
&& entry.spendable !== false
|
|
27
|
-
&& entry.safe !== false;
|
|
28
|
-
}
|
|
29
|
-
async function pathExists(path) {
|
|
30
|
-
try {
|
|
31
|
-
await access(path, constants.F_OK);
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function isWalletAccessError(error) {
|
|
39
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
40
|
-
return message.startsWith("wallet_secret_missing_")
|
|
41
|
-
|| message.startsWith("wallet_secret_provider_")
|
|
42
|
-
|| message.startsWith("wallet_client_password_")
|
|
43
|
-
|| message === "wallet_state_legacy_envelope_unsupported";
|
|
44
|
-
}
|
|
45
|
-
function describeWalletAccessMessage(options) {
|
|
46
|
-
const message = options.accessError instanceof Error ? options.accessError.message : String(options.accessError ?? "");
|
|
47
|
-
if (message === "wallet_state_legacy_envelope_unsupported") {
|
|
48
|
-
return "Wallet state exists but was created by an older Cogcoin wallet format that this version no longer loads directly.";
|
|
49
|
-
}
|
|
50
|
-
if (message === "wallet_client_password_setup_required") {
|
|
51
|
-
return describeClientPasswordSetupMessage();
|
|
52
|
-
}
|
|
53
|
-
if (message === "wallet_client_password_migration_required") {
|
|
54
|
-
return describeClientPasswordMigrationMessage();
|
|
55
|
-
}
|
|
56
|
-
if (message === "wallet_client_password_locked") {
|
|
57
|
-
return describeClientPasswordLockedMessage();
|
|
58
|
-
}
|
|
59
|
-
if (message.startsWith("wallet_secret_provider_")) {
|
|
60
|
-
return "Wallet state exists but the local secret provider is unavailable.";
|
|
61
|
-
}
|
|
62
|
-
if (message.startsWith("wallet_secret_missing_")) {
|
|
63
|
-
return "Wallet state exists but its local secret-provider material is unavailable.";
|
|
64
|
-
}
|
|
65
|
-
return message.length > 0
|
|
66
|
-
? message
|
|
67
|
-
: "Wallet state exists but could not be loaded from the local secret provider.";
|
|
68
|
-
}
|
|
69
|
-
async function normalizeLoadedWalletStateForRead(options) {
|
|
70
|
-
if (options.dataDir === undefined) {
|
|
71
|
-
return options.loaded;
|
|
72
|
-
}
|
|
73
|
-
const node = await attachOrStartManagedBitcoindService({
|
|
74
|
-
dataDir: options.dataDir,
|
|
75
|
-
chain: "main",
|
|
76
|
-
startHeight: 0,
|
|
77
|
-
walletRootId: options.loaded.state.walletRootId,
|
|
78
|
-
});
|
|
79
|
-
try {
|
|
80
|
-
const access = {
|
|
81
|
-
provider: options.access.provider,
|
|
82
|
-
secretReference: createWalletSecretReference(options.loaded.state.walletRootId),
|
|
83
|
-
};
|
|
84
|
-
const normalized = await persistNormalizedWalletDescriptorStateIfNeeded({
|
|
85
|
-
state: options.loaded.state,
|
|
86
|
-
access,
|
|
87
|
-
paths: options.paths,
|
|
88
|
-
nowUnixMs: options.now,
|
|
89
|
-
replacePrimary: options.loaded.source === "backup",
|
|
90
|
-
rpc: createRpcClient(node.rpc),
|
|
91
|
-
});
|
|
92
|
-
const coinControl = await persistWalletCoinControlStateIfNeeded({
|
|
93
|
-
state: normalized.state,
|
|
94
|
-
access,
|
|
95
|
-
paths: options.paths,
|
|
96
|
-
nowUnixMs: options.now,
|
|
97
|
-
replacePrimary: (normalized.changed ? "primary" : options.loaded.source) === "backup",
|
|
98
|
-
rpc: createRpcClient(node.rpc),
|
|
99
|
-
});
|
|
100
|
-
return {
|
|
101
|
-
source: coinControl.changed ? "primary" : normalized.changed ? "primary" : options.loaded.source,
|
|
102
|
-
state: coinControl.state,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
finally {
|
|
106
|
-
await node.stop?.().catch(() => undefined);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
async function inspectWalletLocalState(options = {}) {
|
|
110
|
-
const paths = options.paths ?? resolveWalletRuntimePathsForTesting();
|
|
111
|
-
const now = options.now ?? Date.now();
|
|
112
|
-
const provider = options.secretProvider ?? createDefaultWalletSecretProvider();
|
|
113
|
-
const [hasPrimaryStateFile, hasBackupStateFile] = await Promise.all([
|
|
114
|
-
pathExists(paths.walletStatePath),
|
|
115
|
-
pathExists(paths.walletStateBackupPath),
|
|
116
|
-
]);
|
|
117
|
-
const clientPasswordReadiness = await inspectClientPasswordSetupReadiness(provider).catch(() => "ready");
|
|
118
|
-
if (!hasPrimaryStateFile && !hasBackupStateFile) {
|
|
119
|
-
return {
|
|
120
|
-
availability: "uninitialized",
|
|
121
|
-
clientPasswordReadiness,
|
|
122
|
-
unlockRequired: false,
|
|
123
|
-
walletRootId: null,
|
|
124
|
-
state: null,
|
|
125
|
-
source: null,
|
|
126
|
-
hasPrimaryStateFile,
|
|
127
|
-
hasBackupStateFile,
|
|
128
|
-
message: "Wallet state has not been initialized yet.",
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
if (clientPasswordReadiness !== "ready") {
|
|
132
|
-
const rawEnvelope = await loadRawWalletStateEnvelope({
|
|
133
|
-
primaryPath: paths.walletStatePath,
|
|
134
|
-
backupPath: paths.walletStateBackupPath,
|
|
135
|
-
}).catch(() => null);
|
|
136
|
-
if (rawEnvelope?.envelope.secretProvider == null) {
|
|
137
|
-
return {
|
|
138
|
-
availability: "local-state-corrupt",
|
|
139
|
-
clientPasswordReadiness: "ready",
|
|
140
|
-
unlockRequired: false,
|
|
141
|
-
walletRootId: extractWalletRootIdHintFromWalletStateEnvelope(rawEnvelope?.envelope ?? null),
|
|
142
|
-
state: null,
|
|
143
|
-
source: null,
|
|
144
|
-
hasPrimaryStateFile,
|
|
145
|
-
hasBackupStateFile,
|
|
146
|
-
message: "Wallet state exists but was created by an older Cogcoin wallet format that this version no longer loads directly.",
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
const resolvedRoot = await resolveWalletRootIdFromLocalArtifacts({
|
|
150
|
-
paths,
|
|
151
|
-
provider,
|
|
152
|
-
}).catch(() => null);
|
|
153
|
-
return {
|
|
154
|
-
availability: "local-state-corrupt",
|
|
155
|
-
clientPasswordReadiness,
|
|
156
|
-
unlockRequired: false,
|
|
157
|
-
walletRootId: resolvedRoot?.walletRootId ?? null,
|
|
158
|
-
state: null,
|
|
159
|
-
source: null,
|
|
160
|
-
hasPrimaryStateFile,
|
|
161
|
-
hasBackupStateFile,
|
|
162
|
-
message: clientPasswordReadiness === "migration-required"
|
|
163
|
-
? describeClientPasswordMigrationMessage()
|
|
164
|
-
: describeClientPasswordSetupMessage(),
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
try {
|
|
168
|
-
const loaded = await loadWalletState({
|
|
169
|
-
primaryPath: paths.walletStatePath,
|
|
170
|
-
backupPath: paths.walletStateBackupPath,
|
|
171
|
-
}, {
|
|
172
|
-
provider,
|
|
173
|
-
});
|
|
174
|
-
const normalized = await normalizeLoadedWalletStateForRead({
|
|
175
|
-
loaded,
|
|
176
|
-
access: { provider },
|
|
177
|
-
dataDir: options.dataDir,
|
|
178
|
-
now,
|
|
179
|
-
paths,
|
|
180
|
-
});
|
|
181
|
-
return {
|
|
182
|
-
availability: "ready",
|
|
183
|
-
clientPasswordReadiness,
|
|
184
|
-
unlockRequired: false,
|
|
185
|
-
walletRootId: normalized.state.walletRootId,
|
|
186
|
-
state: normalizeWalletStateRecord({
|
|
187
|
-
...normalized.state,
|
|
188
|
-
miningState: normalizeMiningStateRecord(normalized.state.miningState),
|
|
189
|
-
}),
|
|
190
|
-
source: normalized.source,
|
|
191
|
-
hasPrimaryStateFile,
|
|
192
|
-
hasBackupStateFile,
|
|
193
|
-
message: null,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
const resolvedRoot = await resolveWalletRootIdFromLocalArtifacts({
|
|
198
|
-
paths,
|
|
199
|
-
provider,
|
|
200
|
-
}).catch(() => null);
|
|
201
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
202
|
-
return {
|
|
203
|
-
availability: "local-state-corrupt",
|
|
204
|
-
clientPasswordReadiness,
|
|
205
|
-
unlockRequired: message === "wallet_client_password_locked",
|
|
206
|
-
walletRootId: resolvedRoot?.walletRootId ?? null,
|
|
207
|
-
state: null,
|
|
208
|
-
source: null,
|
|
209
|
-
hasPrimaryStateFile,
|
|
210
|
-
hasBackupStateFile,
|
|
211
|
-
message: isWalletAccessError(error)
|
|
212
|
-
? describeWalletAccessMessage({ accessError: error })
|
|
213
|
-
: error instanceof Error
|
|
214
|
-
? error.message
|
|
215
|
-
: String(error),
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
async function readFundingSpendableSats(options) {
|
|
220
|
-
if (options.state === null || options.rpc === null) {
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
const state = options.state;
|
|
224
|
-
try {
|
|
225
|
-
const utxos = await options.rpc.listUnspent(state.managedCoreWallet.walletName, 1);
|
|
226
|
-
return utxos.reduce((sum, entry) => isSpendableFundingUtxo(entry, state.funding.scriptPubKeyHex)
|
|
227
|
-
? sum + btcAmountToSats(entry.amount)
|
|
228
|
-
: sum, 0n);
|
|
229
|
-
}
|
|
230
|
-
catch {
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
11
|
export async function openWalletReadContext(options) {
|
|
235
12
|
const expectedIndexerBinaryVersion = options.expectedIndexerBinaryVersion === undefined
|
|
236
13
|
? await readPackageVersionFromDisk()
|
|
@@ -288,4 +65,4 @@ export async function openWalletReadContext(options) {
|
|
|
288
65
|
},
|
|
289
66
|
};
|
|
290
67
|
}
|
|
291
|
-
export { inspectWalletLocalState,
|
|
68
|
+
export { inspectWalletLocalState, };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { attachOrStartManagedBitcoindService } from "../../bitcoind/service.js";
|
|
2
|
+
import { createRpcClient } from "../../bitcoind/node.js";
|
|
3
|
+
import { type WalletRuntimePaths } from "../runtime.js";
|
|
4
|
+
import { type WalletSecretProvider } from "../state/provider.js";
|
|
5
|
+
import type { WalletLocalStateStatus } from "./types.js";
|
|
6
|
+
type WalletLocalStateDeps = {
|
|
7
|
+
attachOrStartManagedBitcoindService: typeof attachOrStartManagedBitcoindService;
|
|
8
|
+
createRpcClient: typeof createRpcClient;
|
|
9
|
+
};
|
|
10
|
+
export declare function inspectWalletLocalStateWithDependencies(options?: {
|
|
11
|
+
dataDir?: string;
|
|
12
|
+
secretProvider?: WalletSecretProvider;
|
|
13
|
+
now?: number;
|
|
14
|
+
paths?: WalletRuntimePaths;
|
|
15
|
+
walletControlLockHeld?: boolean;
|
|
16
|
+
}, dependencies?: WalletLocalStateDeps): Promise<WalletLocalStateStatus>;
|
|
17
|
+
export declare function inspectWalletLocalState(options?: {
|
|
18
|
+
dataDir?: string;
|
|
19
|
+
secretProvider?: WalletSecretProvider;
|
|
20
|
+
now?: number;
|
|
21
|
+
paths?: WalletRuntimePaths;
|
|
22
|
+
walletControlLockHeld?: boolean;
|
|
23
|
+
}): Promise<WalletLocalStateStatus>;
|
|
24
|
+
export declare function readFundingSpendableSats(options: {
|
|
25
|
+
state: WalletLocalStateStatus["state"];
|
|
26
|
+
rpc: ReturnType<typeof createRpcClient> | null;
|
|
27
|
+
}): Promise<bigint | null>;
|
|
28
|
+
export {};
|