@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,181 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { lookupDomain } from "@cogcoin/indexer/queries";
|
|
3
|
+
import { createWalletMutationFeeMetadata, saveWalletStatePreservingUnlock, unlockTemporaryBuilderLocks, updateMutationRecord, } from "../common.js";
|
|
4
|
+
import { upsertPendingMutation } from "../journal.js";
|
|
5
|
+
export function reserveLocalDomainRecord(options) {
|
|
6
|
+
const existing = options.state.domains.find((domain) => domain.name === options.domainName) ?? null;
|
|
7
|
+
const domains = options.state.domains.some((domain) => domain.name === options.domainName)
|
|
8
|
+
? options.state.domains.map((domain) => {
|
|
9
|
+
if (domain.name !== options.domainName) {
|
|
10
|
+
return domain;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
...domain,
|
|
14
|
+
currentOwnerScriptPubKeyHex: options.sender.scriptPubKeyHex,
|
|
15
|
+
birthTime: domain.birthTime ?? Math.floor(options.nowUnixMs / 1000),
|
|
16
|
+
};
|
|
17
|
+
})
|
|
18
|
+
: [
|
|
19
|
+
...options.state.domains,
|
|
20
|
+
{
|
|
21
|
+
name: options.domainName,
|
|
22
|
+
domainId: null,
|
|
23
|
+
currentOwnerScriptPubKeyHex: options.sender.scriptPubKeyHex,
|
|
24
|
+
canonicalChainStatus: "unknown",
|
|
25
|
+
foundingMessageText: existing?.foundingMessageText ?? null,
|
|
26
|
+
birthTime: Math.floor(options.nowUnixMs / 1000),
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
return {
|
|
30
|
+
...options.state,
|
|
31
|
+
domains,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function getMutationStatusAfterAcceptance(options) {
|
|
35
|
+
const chainRecord = options.snapshot === null ? null : lookupDomain(options.snapshot.state, options.domainName);
|
|
36
|
+
if (chainRecord === null) {
|
|
37
|
+
return "live";
|
|
38
|
+
}
|
|
39
|
+
return Buffer.from(chainRecord.ownerScriptPubKey).toString("hex") === options.senderScriptPubKeyHex
|
|
40
|
+
? "confirmed"
|
|
41
|
+
: "live";
|
|
42
|
+
}
|
|
43
|
+
export function createRegisterDraftMutation(options) {
|
|
44
|
+
if (options.existing !== null && options.existing !== undefined) {
|
|
45
|
+
return {
|
|
46
|
+
...options.existing,
|
|
47
|
+
registerKind: options.registerKind,
|
|
48
|
+
parentDomainName: options.parentDomainName,
|
|
49
|
+
senderScriptPubKeyHex: options.sender.scriptPubKeyHex,
|
|
50
|
+
senderLocalIndex: options.sender.localIndex,
|
|
51
|
+
status: "draft",
|
|
52
|
+
lastUpdatedAtUnixMs: options.nowUnixMs,
|
|
53
|
+
attemptedTxid: null,
|
|
54
|
+
attemptedWtxid: null,
|
|
55
|
+
...createWalletMutationFeeMetadata(options.feeSelection),
|
|
56
|
+
temporaryBuilderLockedOutpoints: [],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
mutationId: randomBytes(12).toString("hex"),
|
|
61
|
+
kind: "register",
|
|
62
|
+
registerKind: options.registerKind,
|
|
63
|
+
domainName: options.domainName,
|
|
64
|
+
parentDomainName: options.parentDomainName,
|
|
65
|
+
senderScriptPubKeyHex: options.sender.scriptPubKeyHex,
|
|
66
|
+
senderLocalIndex: options.sender.localIndex,
|
|
67
|
+
intentFingerprintHex: options.intentFingerprintHex,
|
|
68
|
+
status: "draft",
|
|
69
|
+
createdAtUnixMs: options.nowUnixMs,
|
|
70
|
+
lastUpdatedAtUnixMs: options.nowUnixMs,
|
|
71
|
+
attemptedTxid: null,
|
|
72
|
+
attemptedWtxid: null,
|
|
73
|
+
...createWalletMutationFeeMetadata(options.feeSelection),
|
|
74
|
+
temporaryBuilderLockedOutpoints: [],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export async function reconcilePendingRegisterMutation(options) {
|
|
78
|
+
if (options.mutation.status === "repair-required") {
|
|
79
|
+
return {
|
|
80
|
+
state: options.state,
|
|
81
|
+
mutation: options.mutation,
|
|
82
|
+
resolution: "repair-required",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const chainDomain = options.context.snapshot === null
|
|
86
|
+
? null
|
|
87
|
+
: lookupDomain(options.context.snapshot.state, options.mutation.domainName);
|
|
88
|
+
if (chainDomain !== null) {
|
|
89
|
+
const chainOwnerHex = Buffer.from(chainDomain.ownerScriptPubKey).toString("hex");
|
|
90
|
+
if (chainOwnerHex !== options.sender.scriptPubKeyHex) {
|
|
91
|
+
const repairMutation = updateMutationRecord(options.mutation, "repair-required", options.nowUnixMs, {
|
|
92
|
+
temporaryBuilderLockedOutpoints: [],
|
|
93
|
+
});
|
|
94
|
+
const nextState = upsertPendingMutation(options.state, repairMutation);
|
|
95
|
+
await saveWalletStatePreservingUnlock({
|
|
96
|
+
state: nextState,
|
|
97
|
+
provider: options.provider,
|
|
98
|
+
nowUnixMs: options.nowUnixMs,
|
|
99
|
+
paths: options.paths,
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
state: nextState,
|
|
103
|
+
mutation: repairMutation,
|
|
104
|
+
resolution: "repair-required",
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
|
|
108
|
+
const confirmedMutation = updateMutationRecord(options.mutation, "confirmed", options.nowUnixMs, {
|
|
109
|
+
temporaryBuilderLockedOutpoints: [],
|
|
110
|
+
});
|
|
111
|
+
const nextState = reserveLocalDomainRecord({
|
|
112
|
+
state: upsertPendingMutation(options.state, confirmedMutation),
|
|
113
|
+
domainName: options.mutation.domainName,
|
|
114
|
+
sender: options.sender,
|
|
115
|
+
nowUnixMs: options.nowUnixMs,
|
|
116
|
+
});
|
|
117
|
+
await saveWalletStatePreservingUnlock({
|
|
118
|
+
state: nextState,
|
|
119
|
+
provider: options.provider,
|
|
120
|
+
nowUnixMs: options.nowUnixMs,
|
|
121
|
+
paths: options.paths,
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
state: nextState,
|
|
125
|
+
mutation: confirmedMutation,
|
|
126
|
+
resolution: "confirmed",
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (options.mutation.attemptedTxid !== null) {
|
|
130
|
+
const mempool = await options.rpc.getRawMempool().catch(() => []);
|
|
131
|
+
if (mempool.includes(options.mutation.attemptedTxid)) {
|
|
132
|
+
await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
|
|
133
|
+
const liveMutation = updateMutationRecord(options.mutation, "live", options.nowUnixMs, {
|
|
134
|
+
temporaryBuilderLockedOutpoints: [],
|
|
135
|
+
});
|
|
136
|
+
const nextState = reserveLocalDomainRecord({
|
|
137
|
+
state: upsertPendingMutation(options.state, liveMutation),
|
|
138
|
+
domainName: options.mutation.domainName,
|
|
139
|
+
sender: options.sender,
|
|
140
|
+
nowUnixMs: options.nowUnixMs,
|
|
141
|
+
});
|
|
142
|
+
await saveWalletStatePreservingUnlock({
|
|
143
|
+
state: nextState,
|
|
144
|
+
provider: options.provider,
|
|
145
|
+
nowUnixMs: options.nowUnixMs,
|
|
146
|
+
paths: options.paths,
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
state: nextState,
|
|
150
|
+
mutation: liveMutation,
|
|
151
|
+
resolution: "live",
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (options.mutation.status === "broadcast-unknown"
|
|
156
|
+
|| options.mutation.status === "live"
|
|
157
|
+
|| options.mutation.status === "draft"
|
|
158
|
+
|| options.mutation.status === "broadcasting") {
|
|
159
|
+
await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
|
|
160
|
+
const canceledMutation = updateMutationRecord(options.mutation, "canceled", options.nowUnixMs, {
|
|
161
|
+
temporaryBuilderLockedOutpoints: [],
|
|
162
|
+
});
|
|
163
|
+
const nextState = upsertPendingMutation(options.state, canceledMutation);
|
|
164
|
+
await saveWalletStatePreservingUnlock({
|
|
165
|
+
state: nextState,
|
|
166
|
+
provider: options.provider,
|
|
167
|
+
nowUnixMs: options.nowUnixMs,
|
|
168
|
+
paths: options.paths,
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
state: nextState,
|
|
172
|
+
mutation: canceledMutation,
|
|
173
|
+
resolution: "not-seen",
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
state: options.state,
|
|
178
|
+
mutation: options.mutation,
|
|
179
|
+
resolution: "continue",
|
|
180
|
+
};
|
|
181
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type RegisterDomainOptions } from "./intent.js";
|
|
2
|
+
import { type RegisterDomainResult } from "./result.js";
|
|
3
|
+
export { extractOpReturnPayloadFromScriptHex } from "./plan.js";
|
|
4
|
+
export type { RegisterDomainOptions } from "./intent.js";
|
|
5
|
+
export type { RegisterDomainResult } from "./result.js";
|
|
6
|
+
export declare function registerDomain(options: RegisterDomainOptions): Promise<RegisterDomainResult>;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { loadBundledGenesisParameters } from "@cogcoin/indexer";
|
|
2
|
+
import { buildWalletMutationTransactionWithReserveFallback, mergeFixedWalletInputs, updateMutationRecord, } from "../common.js";
|
|
3
|
+
import { executeWalletMutationOperation, publishWalletMutation, resolveExistingWalletMutation, } from "../executor.js";
|
|
4
|
+
import { upsertPendingMutation } from "../journal.js";
|
|
5
|
+
import { confirmRootRegistration, confirmSubdomainRegistration, findCompetingRootRegistrationTxids, } from "./confirm.js";
|
|
6
|
+
import { createRegisterDraftMutation, getMutationStatusAfterAcceptance, reconcilePendingRegisterMutation, reserveLocalDomainRecord, } from "./draft.js";
|
|
7
|
+
import { createRegisterOperationFingerprint, normalizeRegisterDomainName, resolveRegisterOperation, } from "./intent.js";
|
|
8
|
+
import { buildRegisterPlan, buildRegisterTransaction, extractOpReturnPayloadFromScriptHex, } from "./plan.js";
|
|
9
|
+
import { createRegisterResult, createRegisterReuseResult, } from "./result.js";
|
|
10
|
+
import { serializeDomainReg } from "../../cogop/index.js";
|
|
11
|
+
export { extractOpReturnPayloadFromScriptHex } from "./plan.js";
|
|
12
|
+
export async function registerDomain(options) {
|
|
13
|
+
if (!options.prompter.isInteractive && options.assumeYes !== true) {
|
|
14
|
+
throw new Error("wallet_register_requires_tty");
|
|
15
|
+
}
|
|
16
|
+
const normalizedDomainName = normalizeRegisterDomainName(options.domainName);
|
|
17
|
+
const execution = await executeWalletMutationOperation({
|
|
18
|
+
...options,
|
|
19
|
+
controlLockPurpose: "wallet-register",
|
|
20
|
+
preemptionReason: "wallet-register",
|
|
21
|
+
async resolveOperation(readContext) {
|
|
22
|
+
return resolveRegisterOperation({
|
|
23
|
+
readContext,
|
|
24
|
+
normalizedDomainName,
|
|
25
|
+
fromIdentity: options.fromIdentity,
|
|
26
|
+
loadGenesisParameters: options.loadGenesisParameters ?? loadBundledGenesisParameters,
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
createIntentFingerprint(operation) {
|
|
30
|
+
return createRegisterOperationFingerprint(operation);
|
|
31
|
+
},
|
|
32
|
+
async resolveExistingMutation({ operation, existingMutation, execution }) {
|
|
33
|
+
if (existingMutation === null) {
|
|
34
|
+
return { state: operation.state, replacementFixedInputs: null, result: null };
|
|
35
|
+
}
|
|
36
|
+
return resolveExistingWalletMutation({
|
|
37
|
+
existingMutation,
|
|
38
|
+
execution,
|
|
39
|
+
repairRequiredErrorCode: "wallet_register_repair_required",
|
|
40
|
+
reconcileExistingMutation: (mutation) => reconcilePendingRegisterMutation({
|
|
41
|
+
state: operation.state,
|
|
42
|
+
mutation,
|
|
43
|
+
provider: execution.provider,
|
|
44
|
+
nowUnixMs: execution.nowUnixMs,
|
|
45
|
+
paths: execution.paths,
|
|
46
|
+
rpc: execution.rpc,
|
|
47
|
+
walletName: execution.walletName,
|
|
48
|
+
context: execution.readContext,
|
|
49
|
+
sender: operation.senderResolution.sender,
|
|
50
|
+
}),
|
|
51
|
+
createReuseResult: ({ mutation, resolution, fees }) => createRegisterReuseResult({
|
|
52
|
+
operation,
|
|
53
|
+
mutation,
|
|
54
|
+
resolution,
|
|
55
|
+
fees,
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
async confirm({ operation, execution }) {
|
|
60
|
+
if (operation.senderResolution.registerKind === "root") {
|
|
61
|
+
const competingRootTxids = await findCompetingRootRegistrationTxids(execution.rpc, operation.normalizedDomainName);
|
|
62
|
+
if (competingRootTxids.length > 0 && !options.forceRace) {
|
|
63
|
+
throw new Error("wallet_register_root_race_detected");
|
|
64
|
+
}
|
|
65
|
+
await confirmRootRegistration(options.prompter, operation.normalizedDomainName, operation.resolvedSummary, competingRootTxids.length > 0, options.assumeYes);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
await confirmSubdomainRegistration(options.prompter, operation.normalizedDomainName, operation.resolvedSummary, options.assumeYes);
|
|
69
|
+
},
|
|
70
|
+
createDraftMutation({ operation, existingMutation, execution, intentFingerprintHex }) {
|
|
71
|
+
return {
|
|
72
|
+
mutation: createRegisterDraftMutation({
|
|
73
|
+
domainName: operation.normalizedDomainName,
|
|
74
|
+
parentDomainName: operation.senderResolution.parentDomainName,
|
|
75
|
+
sender: operation.senderResolution.sender,
|
|
76
|
+
registerKind: operation.senderResolution.registerKind,
|
|
77
|
+
intentFingerprintHex,
|
|
78
|
+
nowUnixMs: execution.nowUnixMs,
|
|
79
|
+
feeSelection: execution.feeSelection,
|
|
80
|
+
existing: existingMutation,
|
|
81
|
+
}),
|
|
82
|
+
prepared: null,
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
async build({ operation, state, execution, replacementFixedInputs }) {
|
|
86
|
+
const plan = buildRegisterPlan({
|
|
87
|
+
context: execution.readContext,
|
|
88
|
+
state,
|
|
89
|
+
allUtxos: await execution.rpc.listUnspent(execution.walletName, 1),
|
|
90
|
+
sender: operation.senderResolution.sender,
|
|
91
|
+
registerKind: operation.senderResolution.registerKind,
|
|
92
|
+
domainName: operation.normalizedDomainName,
|
|
93
|
+
parentDomainName: operation.senderResolution.parentDomainName,
|
|
94
|
+
treasuryAddress: operation.genesis.treasuryAddress,
|
|
95
|
+
treasuryScriptPubKeyHex: Buffer.from(operation.genesis.treasuryScriptPubKey).toString("hex"),
|
|
96
|
+
rootPriceSats: operation.rootPriceSats,
|
|
97
|
+
serializeDomainReg: (domainName) => serializeDomainReg(domainName),
|
|
98
|
+
});
|
|
99
|
+
return buildRegisterTransaction({
|
|
100
|
+
rpc: execution.rpc,
|
|
101
|
+
walletName: execution.walletName,
|
|
102
|
+
state,
|
|
103
|
+
plan: {
|
|
104
|
+
...plan,
|
|
105
|
+
fixedInputs: mergeFixedWalletInputs(plan.fixedInputs, replacementFixedInputs),
|
|
106
|
+
},
|
|
107
|
+
feeRateSatVb: execution.feeSelection.feeRateSatVb,
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
publish({ operation, state, execution, built, mutation }) {
|
|
111
|
+
return publishWalletMutation({
|
|
112
|
+
rpc: execution.rpc,
|
|
113
|
+
walletName: execution.walletName,
|
|
114
|
+
snapshotHeight: execution.readContext.snapshot?.tip?.height ?? null,
|
|
115
|
+
built,
|
|
116
|
+
mutation,
|
|
117
|
+
state,
|
|
118
|
+
provider: execution.provider,
|
|
119
|
+
nowUnixMs: execution.nowUnixMs,
|
|
120
|
+
paths: execution.paths,
|
|
121
|
+
errorPrefix: "wallet_register",
|
|
122
|
+
async afterAccepted({ state: acceptedState, broadcastingMutation, built, nowUnixMs }) {
|
|
123
|
+
const finalStatus = getMutationStatusAfterAcceptance({
|
|
124
|
+
snapshot: execution.readContext.snapshot,
|
|
125
|
+
domainName: operation.normalizedDomainName,
|
|
126
|
+
senderScriptPubKeyHex: operation.senderResolution.sender.scriptPubKeyHex,
|
|
127
|
+
});
|
|
128
|
+
const finalMutation = updateMutationRecord(broadcastingMutation, finalStatus, nowUnixMs, {
|
|
129
|
+
attemptedTxid: built.txid,
|
|
130
|
+
attemptedWtxid: built.wtxid,
|
|
131
|
+
temporaryBuilderLockedOutpoints: [],
|
|
132
|
+
});
|
|
133
|
+
return {
|
|
134
|
+
state: reserveLocalDomainRecord({
|
|
135
|
+
state: upsertPendingMutation(acceptedState, finalMutation),
|
|
136
|
+
domainName: operation.normalizedDomainName,
|
|
137
|
+
sender: operation.senderResolution.sender,
|
|
138
|
+
nowUnixMs,
|
|
139
|
+
}),
|
|
140
|
+
mutation: finalMutation,
|
|
141
|
+
status: finalStatus,
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
createResult({ operation, mutation, built, status, reusedExisting, fees }) {
|
|
147
|
+
return createRegisterResult({
|
|
148
|
+
operation,
|
|
149
|
+
mutation,
|
|
150
|
+
builtTxid: built?.txid ?? null,
|
|
151
|
+
status: status,
|
|
152
|
+
reusedExisting,
|
|
153
|
+
fees,
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
return execution.result;
|
|
158
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { loadBundledGenesisParameters } from "@cogcoin/indexer";
|
|
2
|
+
import { attachOrStartManagedBitcoindService } from "../../../bitcoind/service.js";
|
|
3
|
+
import { createRpcClient } from "../../../bitcoind/node.js";
|
|
4
|
+
import type { WalletPrompter } from "../../lifecycle.js";
|
|
5
|
+
import { openWalletReadContext, type WalletReadContext } from "../../read/index.js";
|
|
6
|
+
import type { WalletRuntimePaths } from "../../runtime.js";
|
|
7
|
+
import type { WalletSecretProvider } from "../../state/provider.js";
|
|
8
|
+
import type { WalletStateV1 } from "../../types.js";
|
|
9
|
+
import { type BuiltWalletMutationTransaction, type MutationSender, type WalletMutationRpcClient } from "../common.js";
|
|
10
|
+
import { type RegisterResolvedSummary } from "./result.js";
|
|
11
|
+
export interface WalletRegisterRpcClient extends WalletMutationRpcClient {
|
|
12
|
+
getBlockchainInfo(): Promise<{
|
|
13
|
+
blocks: number;
|
|
14
|
+
}>;
|
|
15
|
+
sendRawTransaction(hex: string): Promise<string>;
|
|
16
|
+
getRawMempool(): Promise<string[]>;
|
|
17
|
+
getRawTransaction(txid: string, verbose?: boolean): Promise<import("../../../bitcoind/types.js").RpcTransaction>;
|
|
18
|
+
}
|
|
19
|
+
export type BuiltRegisterTransaction = BuiltWalletMutationTransaction;
|
|
20
|
+
export interface RegisterDomainOptions {
|
|
21
|
+
domainName: string;
|
|
22
|
+
fromIdentity?: string | null;
|
|
23
|
+
feeRateSatVb?: number | null;
|
|
24
|
+
dataDir: string;
|
|
25
|
+
databasePath: string;
|
|
26
|
+
forceRace?: boolean;
|
|
27
|
+
provider?: WalletSecretProvider;
|
|
28
|
+
prompter: WalletPrompter;
|
|
29
|
+
assumeYes?: boolean;
|
|
30
|
+
nowUnixMs?: number;
|
|
31
|
+
paths?: WalletRuntimePaths;
|
|
32
|
+
openReadContext?: typeof openWalletReadContext;
|
|
33
|
+
attachService?: typeof attachOrStartManagedBitcoindService;
|
|
34
|
+
rpcFactory?: (config: Parameters<typeof createRpcClient>[0]) => WalletRegisterRpcClient;
|
|
35
|
+
loadGenesisParameters?: typeof loadBundledGenesisParameters;
|
|
36
|
+
}
|
|
37
|
+
export interface ResolvedRegisterSender {
|
|
38
|
+
registerKind: "root" | "subdomain";
|
|
39
|
+
parentDomainName: string | null;
|
|
40
|
+
sender: MutationSender;
|
|
41
|
+
senderSelector: string;
|
|
42
|
+
}
|
|
43
|
+
export interface RegisterMutationOperation {
|
|
44
|
+
state: WalletStateV1;
|
|
45
|
+
normalizedDomainName: string;
|
|
46
|
+
senderResolution: ResolvedRegisterSender;
|
|
47
|
+
rootPriceSats: bigint;
|
|
48
|
+
resolvedSummary: RegisterResolvedSummary;
|
|
49
|
+
genesis: Awaited<ReturnType<typeof loadBundledGenesisParameters>>;
|
|
50
|
+
}
|
|
51
|
+
export declare function normalizeRegisterDomainName(domainName: string): string;
|
|
52
|
+
export declare function resolveRegisterSender(context: WalletReadContext & {
|
|
53
|
+
localState: {
|
|
54
|
+
availability: "ready";
|
|
55
|
+
state: WalletStateV1;
|
|
56
|
+
};
|
|
57
|
+
snapshot: NonNullable<WalletReadContext["snapshot"]>;
|
|
58
|
+
model: NonNullable<WalletReadContext["model"]>;
|
|
59
|
+
}, domainName: string, fromIdentity: string | null | undefined): ResolvedRegisterSender;
|
|
60
|
+
export declare function createRegisterResolvedSummary(options: {
|
|
61
|
+
registerKind: "root" | "subdomain";
|
|
62
|
+
parentDomainName: string | null;
|
|
63
|
+
senderSelector: string;
|
|
64
|
+
sender: MutationSender;
|
|
65
|
+
economicEffectKind: "treasury-payment" | "cog-burn";
|
|
66
|
+
economicEffectAmount: bigint;
|
|
67
|
+
}): RegisterResolvedSummary;
|
|
68
|
+
export declare function resolveRegisterOperation(options: {
|
|
69
|
+
readContext: WalletReadContext;
|
|
70
|
+
normalizedDomainName: string;
|
|
71
|
+
fromIdentity?: string | null;
|
|
72
|
+
loadGenesisParameters?: typeof loadBundledGenesisParameters;
|
|
73
|
+
}): Promise<RegisterMutationOperation>;
|
|
74
|
+
export declare function createRegisterOperationFingerprint(operation: RegisterMutationOperation): string;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { loadBundledGenesisParameters } from "@cogcoin/indexer";
|
|
3
|
+
import { getBalance, getParent, lookupDomain } from "@cogcoin/indexer/queries";
|
|
4
|
+
import { attachOrStartManagedBitcoindService } from "../../../bitcoind/service.js";
|
|
5
|
+
import { createRpcClient } from "../../../bitcoind/node.js";
|
|
6
|
+
import { openWalletReadContext } from "../../read/index.js";
|
|
7
|
+
import { computeRootRegistrationPriceSats, serializeDomainReg } from "../../cogop/index.js";
|
|
8
|
+
import { assertWalletMutationContextReady, createFundingMutationSender, isLocalWalletScript, } from "../common.js";
|
|
9
|
+
import { SUBDOMAIN_REGISTRATION_FEE_COGTOSHI, } from "./result.js";
|
|
10
|
+
function normalizeDomainName(domainName) {
|
|
11
|
+
const normalized = domainName.trim().toLowerCase();
|
|
12
|
+
if (normalized.length === 0) {
|
|
13
|
+
throw new Error("wallet_register_missing_domain");
|
|
14
|
+
}
|
|
15
|
+
serializeDomainReg(normalized);
|
|
16
|
+
return normalized;
|
|
17
|
+
}
|
|
18
|
+
function createRegisterIntentFingerprint(options) {
|
|
19
|
+
return createHash("sha256")
|
|
20
|
+
.update([
|
|
21
|
+
"register",
|
|
22
|
+
options.walletRootId,
|
|
23
|
+
options.domainName,
|
|
24
|
+
options.registerKind,
|
|
25
|
+
options.senderScriptPubKeyHex,
|
|
26
|
+
].join("\n"))
|
|
27
|
+
.digest("hex");
|
|
28
|
+
}
|
|
29
|
+
export function normalizeRegisterDomainName(domainName) {
|
|
30
|
+
return normalizeDomainName(domainName);
|
|
31
|
+
}
|
|
32
|
+
export function resolveRegisterSender(context, domainName, fromIdentity) {
|
|
33
|
+
const state = context.localState.state;
|
|
34
|
+
if (context.model.walletAddress === null) {
|
|
35
|
+
throw new Error("wallet_register_funding_identity_unavailable");
|
|
36
|
+
}
|
|
37
|
+
void fromIdentity;
|
|
38
|
+
if (!domainName.includes("-")) {
|
|
39
|
+
return {
|
|
40
|
+
registerKind: "root",
|
|
41
|
+
parentDomainName: null,
|
|
42
|
+
senderSelector: context.model.walletAddress,
|
|
43
|
+
sender: createFundingMutationSender(state),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const parent = getParent(context.snapshot.state, domainName);
|
|
47
|
+
if (parent === null) {
|
|
48
|
+
throw new Error("wallet_register_parent_not_found");
|
|
49
|
+
}
|
|
50
|
+
if (!parent.domain.anchored) {
|
|
51
|
+
throw new Error("wallet_register_parent_not_anchored");
|
|
52
|
+
}
|
|
53
|
+
const parentDomain = context.model.domains.find((domain) => domain.name === parent.parentName) ?? null;
|
|
54
|
+
if (!isLocalWalletScript(state, parentDomain?.ownerScriptPubKeyHex)) {
|
|
55
|
+
throw new Error("wallet_register_parent_not_locally_controlled");
|
|
56
|
+
}
|
|
57
|
+
if (getBalance(context.snapshot.state, state.funding.scriptPubKeyHex) < SUBDOMAIN_REGISTRATION_FEE_COGTOSHI) {
|
|
58
|
+
throw new Error("wallet_register_insufficient_cog_balance");
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
registerKind: "subdomain",
|
|
62
|
+
parentDomainName: parent.parentName,
|
|
63
|
+
senderSelector: context.model.walletAddress,
|
|
64
|
+
sender: createFundingMutationSender(state),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function createRegisterResolvedSummary(options) {
|
|
68
|
+
return {
|
|
69
|
+
path: options.registerKind,
|
|
70
|
+
parentDomainName: options.parentDomainName,
|
|
71
|
+
sender: {
|
|
72
|
+
selector: options.senderSelector,
|
|
73
|
+
localIndex: options.sender.localIndex,
|
|
74
|
+
scriptPubKeyHex: options.sender.scriptPubKeyHex,
|
|
75
|
+
address: options.sender.address,
|
|
76
|
+
},
|
|
77
|
+
economicEffect: {
|
|
78
|
+
kind: options.economicEffectKind,
|
|
79
|
+
amount: options.economicEffectAmount,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export async function resolveRegisterOperation(options) {
|
|
84
|
+
assertWalletMutationContextReady(options.readContext, "wallet_register");
|
|
85
|
+
const state = options.readContext.localState.state;
|
|
86
|
+
const senderResolution = resolveRegisterSender(options.readContext, options.normalizedDomainName, options.fromIdentity);
|
|
87
|
+
if (lookupDomain(options.readContext.snapshot.state, options.normalizedDomainName) !== null) {
|
|
88
|
+
throw new Error("wallet_register_domain_already_registered");
|
|
89
|
+
}
|
|
90
|
+
if (options.readContext.snapshot.state.consensus.nextDomainId === 0xffff_ffff) {
|
|
91
|
+
throw new Error("wallet_register_next_domain_id_exhausted");
|
|
92
|
+
}
|
|
93
|
+
const rootPriceSats = computeRootRegistrationPriceSats(options.normalizedDomainName);
|
|
94
|
+
const resolvedSummary = createRegisterResolvedSummary({
|
|
95
|
+
registerKind: senderResolution.registerKind,
|
|
96
|
+
parentDomainName: senderResolution.parentDomainName,
|
|
97
|
+
senderSelector: senderResolution.senderSelector,
|
|
98
|
+
sender: senderResolution.sender,
|
|
99
|
+
economicEffectKind: senderResolution.registerKind === "root" ? "treasury-payment" : "cog-burn",
|
|
100
|
+
economicEffectAmount: senderResolution.registerKind === "root" ? rootPriceSats : SUBDOMAIN_REGISTRATION_FEE_COGTOSHI,
|
|
101
|
+
});
|
|
102
|
+
const genesis = await (options.loadGenesisParameters ?? loadBundledGenesisParameters)();
|
|
103
|
+
return {
|
|
104
|
+
state,
|
|
105
|
+
normalizedDomainName: options.normalizedDomainName,
|
|
106
|
+
senderResolution,
|
|
107
|
+
rootPriceSats,
|
|
108
|
+
resolvedSummary,
|
|
109
|
+
genesis,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
export function createRegisterOperationFingerprint(operation) {
|
|
113
|
+
return createRegisterIntentFingerprint({
|
|
114
|
+
walletRootId: operation.state.walletRootId,
|
|
115
|
+
domainName: operation.normalizedDomainName,
|
|
116
|
+
registerKind: operation.senderResolution.registerKind,
|
|
117
|
+
senderScriptPubKeyHex: operation.senderResolution.sender.scriptPubKeyHex,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { RpcDecodedPsbt, RpcListUnspentEntry, RpcWalletCreateFundedPsbtResult } from "../../../bitcoind/types.js";
|
|
2
|
+
import type { WalletReadContext } from "../../read/index.js";
|
|
3
|
+
import type { WalletStateV1 } from "../../types.js";
|
|
4
|
+
import { type FixedWalletInput, type MutationSender } from "../common.js";
|
|
5
|
+
import type { BuiltRegisterTransaction, WalletRegisterRpcClient } from "./intent.js";
|
|
6
|
+
export interface RegisterTransactionPlan {
|
|
7
|
+
registerKind: "root" | "subdomain";
|
|
8
|
+
sender: MutationSender;
|
|
9
|
+
changeAddress: string;
|
|
10
|
+
fixedInputs: FixedWalletInput[];
|
|
11
|
+
outputs: unknown[];
|
|
12
|
+
changePosition: number;
|
|
13
|
+
expectedOpReturnScriptHex: string;
|
|
14
|
+
expectedTreasuryOutputIndex: number | null;
|
|
15
|
+
expectedTreasuryScriptHex: string | null;
|
|
16
|
+
expectedTreasuryValueSats: bigint | null;
|
|
17
|
+
allowedFundingScriptPubKeyHex: string;
|
|
18
|
+
eligibleFundingOutpointKeys: Set<string>;
|
|
19
|
+
}
|
|
20
|
+
export declare function extractOpReturnPayloadFromScriptHex(scriptHex: string): Uint8Array | null;
|
|
21
|
+
export declare function validateFundedDraft(decoded: RpcDecodedPsbt, funded: RpcWalletCreateFundedPsbtResult, plan: RegisterTransactionPlan): void;
|
|
22
|
+
export declare function buildRegisterPlan(options: {
|
|
23
|
+
context: WalletReadContext;
|
|
24
|
+
state: WalletStateV1;
|
|
25
|
+
allUtxos: RpcListUnspentEntry[];
|
|
26
|
+
sender: MutationSender;
|
|
27
|
+
registerKind: "root" | "subdomain";
|
|
28
|
+
domainName: string;
|
|
29
|
+
parentDomainName: string | null;
|
|
30
|
+
treasuryAddress: string;
|
|
31
|
+
treasuryScriptPubKeyHex: string;
|
|
32
|
+
rootPriceSats: bigint;
|
|
33
|
+
serializeDomainReg(domainName: string): {
|
|
34
|
+
opReturnData: Uint8Array;
|
|
35
|
+
};
|
|
36
|
+
}): RegisterTransactionPlan;
|
|
37
|
+
export declare function buildRegisterTransaction(options: {
|
|
38
|
+
rpc: WalletRegisterRpcClient;
|
|
39
|
+
walletName: string;
|
|
40
|
+
state: WalletStateV1;
|
|
41
|
+
plan: RegisterTransactionPlan;
|
|
42
|
+
feeRateSatVb: number;
|
|
43
|
+
}): Promise<BuiltRegisterTransaction>;
|