@cogcoin/client 1.1.8 → 1.1.9
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/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/sentence-protocol.d.ts +2 -2
- package/dist/wallet/mining/sentences.js +8 -8
- package/dist/wallet/tx/anchor/confirm.d.ts +15 -0
- package/dist/wallet/tx/anchor/confirm.js +60 -0
- package/dist/wallet/tx/anchor/draft.d.ts +39 -0
- package/dist/wallet/tx/anchor/draft.js +167 -0
- package/dist/wallet/tx/anchor/index.d.ts +5 -0
- package/dist/wallet/tx/anchor/index.js +148 -0
- package/dist/wallet/tx/anchor/intent.d.ts +61 -0
- package/dist/wallet/tx/anchor/intent.js +101 -0
- package/dist/wallet/tx/anchor/plan.d.ts +3 -0
- package/dist/wallet/tx/anchor/plan.js +18 -0
- package/dist/wallet/tx/anchor/result.d.ts +25 -0
- package/dist/wallet/tx/anchor/result.js +20 -0
- package/dist/wallet/tx/anchor.d.ts +1 -39
- package/dist/wallet/tx/anchor.js +1 -494
- package/dist/wallet/tx/bitcoin-transfer/confirm.d.ts +7 -0
- package/dist/wallet/tx/bitcoin-transfer/confirm.js +11 -0
- package/dist/wallet/tx/bitcoin-transfer/index.d.ts +5 -0
- package/dist/wallet/tx/bitcoin-transfer/index.js +112 -0
- package/dist/wallet/tx/bitcoin-transfer/intent.d.ts +52 -0
- package/dist/wallet/tx/bitcoin-transfer/intent.js +74 -0
- package/dist/wallet/tx/bitcoin-transfer/plan.d.ts +5 -0
- package/dist/wallet/tx/bitcoin-transfer/plan.js +21 -0
- package/dist/wallet/tx/bitcoin-transfer/result.d.ts +19 -0
- package/dist/wallet/tx/bitcoin-transfer/result.js +16 -0
- package/dist/wallet/tx/bitcoin-transfer.d.ts +1 -35
- package/dist/wallet/tx/bitcoin-transfer.js +1 -200
- package/dist/wallet/tx/cog/confirm.d.ts +13 -0
- package/dist/wallet/tx/cog/confirm.js +59 -0
- package/dist/wallet/tx/cog/draft.d.ts +20 -0
- package/dist/wallet/tx/cog/draft.js +114 -0
- package/dist/wallet/tx/cog/index.d.ts +6 -0
- package/dist/wallet/tx/cog/index.js +117 -0
- package/dist/wallet/tx/cog/intent.d.ts +30 -0
- package/dist/wallet/tx/cog/intent.js +169 -0
- package/dist/wallet/tx/cog/plan.d.ts +19 -0
- package/dist/wallet/tx/cog/plan.js +65 -0
- package/dist/wallet/tx/cog/result.d.ts +27 -0
- package/dist/wallet/tx/cog/result.js +28 -0
- package/dist/wallet/tx/cog/types.d.ts +186 -0
- package/dist/wallet/tx/cog/types.js +2 -0
- package/dist/wallet/tx/cog/variants/claim.d.ts +3 -0
- package/dist/wallet/tx/cog/variants/claim.js +92 -0
- package/dist/wallet/tx/cog/variants/lock.d.ts +2 -0
- package/dist/wallet/tx/cog/variants/lock.js +102 -0
- package/dist/wallet/tx/cog/variants/send.d.ts +2 -0
- package/dist/wallet/tx/cog/variants/send.js +77 -0
- package/dist/wallet/tx/cog.d.ts +1 -96
- package/dist/wallet/tx/cog.js +1 -824
- package/dist/wallet/tx/common.d.ts +14 -199
- package/dist/wallet/tx/common.js +10 -493
- package/dist/wallet/tx/domain-admin/confirm.d.ts +17 -0
- package/dist/wallet/tx/domain-admin/confirm.js +58 -0
- package/dist/wallet/tx/domain-admin/draft.d.ts +20 -0
- package/dist/wallet/tx/domain-admin/draft.js +161 -0
- package/dist/wallet/tx/domain-admin/index.d.ts +9 -0
- package/dist/wallet/tx/domain-admin/index.js +150 -0
- package/dist/wallet/tx/domain-admin/intent.d.ts +12 -0
- package/dist/wallet/tx/domain-admin/intent.js +61 -0
- package/dist/wallet/tx/domain-admin/plan.d.ts +19 -0
- package/dist/wallet/tx/domain-admin/plan.js +64 -0
- package/dist/wallet/tx/domain-admin/result.d.ts +19 -0
- package/dist/wallet/tx/domain-admin/result.js +33 -0
- package/dist/wallet/tx/domain-admin/types.d.ts +162 -0
- package/dist/wallet/tx/domain-admin/types.js +1 -0
- package/dist/wallet/tx/domain-admin/variants/canonical.d.ts +2 -0
- package/dist/wallet/tx/domain-admin/variants/canonical.js +22 -0
- package/dist/wallet/tx/domain-admin/variants/delegate.d.ts +3 -0
- package/dist/wallet/tx/domain-admin/variants/delegate.js +60 -0
- package/dist/wallet/tx/domain-admin/variants/endpoint.d.ts +3 -0
- package/dist/wallet/tx/domain-admin/variants/endpoint.js +102 -0
- package/dist/wallet/tx/domain-admin/variants/miner.d.ts +3 -0
- package/dist/wallet/tx/domain-admin/variants/miner.js +59 -0
- package/dist/wallet/tx/domain-admin.d.ts +1 -107
- package/dist/wallet/tx/domain-admin.js +1 -729
- package/dist/wallet/tx/domain-market/confirm.d.ts +6 -0
- package/dist/wallet/tx/domain-market/confirm.js +52 -0
- package/dist/wallet/tx/domain-market/draft.d.ts +43 -0
- package/dist/wallet/tx/domain-market/draft.js +286 -0
- package/dist/wallet/tx/domain-market/index.d.ts +6 -0
- package/dist/wallet/tx/domain-market/index.js +145 -0
- package/dist/wallet/tx/domain-market/intent.d.ts +15 -0
- package/dist/wallet/tx/domain-market/intent.js +131 -0
- package/dist/wallet/tx/domain-market/plan.d.ts +31 -0
- package/dist/wallet/tx/domain-market/plan.js +98 -0
- package/dist/wallet/tx/domain-market/result.d.ts +45 -0
- package/dist/wallet/tx/domain-market/result.js +88 -0
- package/dist/wallet/tx/domain-market/types.d.ts +221 -0
- package/dist/wallet/tx/domain-market/types.js +1 -0
- package/dist/wallet/tx/domain-market/variants/buy.d.ts +2 -0
- package/dist/wallet/tx/domain-market/variants/buy.js +103 -0
- package/dist/wallet/tx/domain-market/variants/sell.d.ts +2 -0
- package/dist/wallet/tx/domain-market/variants/sell.js +91 -0
- package/dist/wallet/tx/domain-market/variants/transfer.d.ts +2 -0
- package/dist/wallet/tx/domain-market/variants/transfer.js +105 -0
- package/dist/wallet/tx/domain-market.d.ts +1 -116
- package/dist/wallet/tx/domain-market.js +1 -1078
- package/dist/wallet/tx/draft-build.d.ts +60 -0
- package/dist/wallet/tx/draft-build.js +127 -0
- package/dist/wallet/tx/executor.d.ts +6 -40
- package/dist/wallet/tx/executor.js +6 -100
- package/dist/wallet/tx/fee.d.ts +30 -0
- package/dist/wallet/tx/fee.js +98 -0
- package/dist/wallet/tx/field/confirm.d.ts +11 -0
- package/dist/wallet/tx/field/confirm.js +19 -0
- package/dist/wallet/tx/field/draft.d.ts +23 -0
- package/dist/wallet/tx/field/draft.js +202 -0
- package/dist/wallet/tx/field/index.d.ts +5 -0
- package/dist/wallet/tx/field/index.js +140 -0
- package/dist/wallet/tx/field/intent.d.ts +5 -0
- package/dist/wallet/tx/field/intent.js +50 -0
- package/dist/wallet/tx/field/plan.d.ts +20 -0
- package/dist/wallet/tx/field/plan.js +65 -0
- package/dist/wallet/tx/field/result.d.ts +29 -0
- package/dist/wallet/tx/field/result.js +103 -0
- package/dist/wallet/tx/field/types.d.ts +163 -0
- package/dist/wallet/tx/field/types.js +1 -0
- package/dist/wallet/tx/field/variants/clear.d.ts +2 -0
- package/dist/wallet/tx/field/variants/clear.js +60 -0
- package/dist/wallet/tx/field/variants/create.d.ts +2 -0
- package/dist/wallet/tx/field/variants/create.js +67 -0
- package/dist/wallet/tx/field/variants/set.d.ts +2 -0
- package/dist/wallet/tx/field/variants/set.js +195 -0
- package/dist/wallet/tx/field.d.ts +1 -95
- package/dist/wallet/tx/field.js +1 -920
- package/dist/wallet/tx/mining-preemption.d.ts +6 -0
- package/dist/wallet/tx/mining-preemption.js +7 -0
- package/dist/wallet/tx/primitives.d.ts +13 -0
- package/dist/wallet/tx/primitives.js +42 -0
- package/dist/wallet/tx/psbt-assert.d.ts +14 -0
- package/dist/wallet/tx/psbt-assert.js +39 -0
- package/dist/wallet/tx/publish.d.ts +37 -0
- package/dist/wallet/tx/publish.js +88 -0
- package/dist/wallet/tx/readiness.d.ts +7 -0
- package/dist/wallet/tx/readiness.js +61 -0
- package/dist/wallet/tx/reconcile.d.ts +24 -0
- package/dist/wallet/tx/reconcile.js +72 -0
- package/dist/wallet/tx/register/confirm.d.ts +6 -0
- package/dist/wallet/tx/register/confirm.js +66 -0
- package/dist/wallet/tx/register/draft.d.ts +42 -0
- package/dist/wallet/tx/register/draft.js +181 -0
- package/dist/wallet/tx/register/index.d.ts +6 -0
- package/dist/wallet/tx/register/index.js +158 -0
- package/dist/wallet/tx/register/intent.d.ts +74 -0
- package/dist/wallet/tx/register/intent.js +119 -0
- package/dist/wallet/tx/register/plan.d.ts +43 -0
- package/dist/wallet/tx/register/plan.js +168 -0
- package/dist/wallet/tx/register/result.d.ts +78 -0
- package/dist/wallet/tx/register/result.js +41 -0
- package/dist/wallet/tx/register.d.ts +1 -70
- package/dist/wallet/tx/register.js +1 -681
- package/dist/wallet/tx/reputation/confirm.d.ts +11 -0
- package/dist/wallet/tx/reputation/confirm.js +51 -0
- package/dist/wallet/tx/reputation/draft.d.ts +20 -0
- package/dist/wallet/tx/reputation/draft.js +130 -0
- package/dist/wallet/tx/reputation/index.d.ts +4 -0
- package/dist/wallet/tx/reputation/index.js +162 -0
- package/dist/wallet/tx/reputation/intent.d.ts +36 -0
- package/dist/wallet/tx/reputation/intent.js +157 -0
- package/dist/wallet/tx/reputation/plan.d.ts +19 -0
- package/dist/wallet/tx/reputation/plan.js +64 -0
- package/dist/wallet/tx/reputation/result.d.ts +21 -0
- package/dist/wallet/tx/reputation/result.js +31 -0
- package/dist/wallet/tx/reputation/types.d.ts +130 -0
- package/dist/wallet/tx/reputation/types.js +1 -0
- package/dist/wallet/tx/reputation.d.ts +1 -74
- package/dist/wallet/tx/reputation.js +1 -556
- package/dist/wallet/tx/signing.d.ts +18 -0
- package/dist/wallet/tx/signing.js +31 -0
- package/dist/wallet/tx/state-persist.d.ts +27 -0
- package/dist/wallet/tx/state-persist.js +54 -0
- package/dist/wallet/tx/types.d.ts +44 -0
- package/dist/wallet/tx/types.js +1 -0
- package/package.json +1 -1
- package/dist/cli/mining-json.d.ts +0 -20
- package/dist/cli/mining-json.js +0 -46
- package/dist/cli/mutation-json.d.ts +0 -325
- package/dist/cli/mutation-json.js +0 -269
- package/dist/cli/mutation-resolved-json.d.ts +0 -117
- package/dist/cli/mutation-resolved-json.js +0 -123
- package/dist/cli/preview-json.d.ts +0 -319
- package/dist/cli/preview-json.js +0 -254
- package/dist/cli/read-json.d.ts +0 -190
- package/dist/cli/read-json.js +0 -627
|
@@ -1,556 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { encodeSentence } from "@cogcoin/scoring";
|
|
3
|
-
import { getBalance, lookupDomain, } from "@cogcoin/indexer/queries";
|
|
4
|
-
import { attachOrStartManagedBitcoindService } from "../../bitcoind/service.js";
|
|
5
|
-
import { createRpcClient } from "../../bitcoind/node.js";
|
|
6
|
-
import {} from "../runtime.js";
|
|
7
|
-
import {} from "../state/provider.js";
|
|
8
|
-
import { serializeRepCommit, serializeRepRevoke, validateDomainName, } from "../cogop/index.js";
|
|
9
|
-
import { openWalletReadContext } from "../read/index.js";
|
|
10
|
-
import { assertFixedInputPrefixMatches, assertFundingInputsAfterFixedPrefix, assertWalletMutationContextReady, buildWalletMutationTransactionWithReserveFallback, createFundingMutationSender, createWalletMutationFeeMetadata, formatCogAmount, getDecodedInputScriptPubKeyHex, isLocalWalletScript, mergeFixedWalletInputs, outpointKey, unlockTemporaryBuilderLocks, updateMutationRecord, } from "./common.js";
|
|
11
|
-
import { confirmTypedAcknowledgement as confirmSharedTypedAcknowledgement, confirmYesNo as confirmSharedYesNo, } from "./confirm.js";
|
|
12
|
-
import { executeWalletMutationOperation, persistWalletMutationState, publishWalletMutation, resolveExistingWalletMutation, } from "./executor.js";
|
|
13
|
-
import { getCanonicalIdentitySelector } from "./identity-selector.js";
|
|
14
|
-
import { upsertPendingMutation } from "./journal.js";
|
|
15
|
-
function normalizeDomainName(domainName, errorCode) {
|
|
16
|
-
const normalized = domainName.trim().toLowerCase();
|
|
17
|
-
if (normalized.length === 0) {
|
|
18
|
-
throw new Error(errorCode);
|
|
19
|
-
}
|
|
20
|
-
validateDomainName(normalized);
|
|
21
|
-
return normalized;
|
|
22
|
-
}
|
|
23
|
-
function createSupportKey(sourceDomainId, targetDomainId) {
|
|
24
|
-
return `${sourceDomainId}:${targetDomainId}`;
|
|
25
|
-
}
|
|
26
|
-
function encodeOpReturnScript(payload) {
|
|
27
|
-
if (payload.length <= 75) {
|
|
28
|
-
return Buffer.concat([
|
|
29
|
-
Buffer.from([0x6a, payload.length]),
|
|
30
|
-
Buffer.from(payload),
|
|
31
|
-
]).toString("hex");
|
|
32
|
-
}
|
|
33
|
-
return Buffer.concat([
|
|
34
|
-
Buffer.from([0x6a, 0x4c, payload.length]),
|
|
35
|
-
Buffer.from(payload),
|
|
36
|
-
]).toString("hex");
|
|
37
|
-
}
|
|
38
|
-
function satsToBtcNumber(value) {
|
|
39
|
-
return Number(value) / 100_000_000;
|
|
40
|
-
}
|
|
41
|
-
function valueToSats(value) {
|
|
42
|
-
const text = typeof value === "number" ? value.toFixed(8) : value;
|
|
43
|
-
const match = /^(-?)(\d+)(?:\.(\d{0,8}))?$/.exec(text.trim());
|
|
44
|
-
if (match == null) {
|
|
45
|
-
throw new Error(`wallet_reputation_invalid_amount_${text}`);
|
|
46
|
-
}
|
|
47
|
-
const sign = match[1] === "-" ? -1n : 1n;
|
|
48
|
-
const whole = BigInt(match[2] ?? "0");
|
|
49
|
-
const fraction = BigInt((match[3] ?? "").padEnd(8, "0"));
|
|
50
|
-
return sign * ((whole * 100000000n) + fraction);
|
|
51
|
-
}
|
|
52
|
-
function createIntentFingerprint(parts) {
|
|
53
|
-
return createHash("sha256")
|
|
54
|
-
.update(parts.map((part) => String(part)).join("\n"))
|
|
55
|
-
.digest("hex");
|
|
56
|
-
}
|
|
57
|
-
function createResolvedReputationSenderSummary(sender, selector) {
|
|
58
|
-
return {
|
|
59
|
-
selector,
|
|
60
|
-
localIndex: sender.localIndex,
|
|
61
|
-
scriptPubKeyHex: sender.scriptPubKeyHex,
|
|
62
|
-
address: sender.address,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function createResolvedReputationSummary(options) {
|
|
66
|
-
return {
|
|
67
|
-
sender: createResolvedReputationSenderSummary(options.sender, options.senderSelector),
|
|
68
|
-
effect: options.kind === "give"
|
|
69
|
-
? {
|
|
70
|
-
kind: "give-support",
|
|
71
|
-
burnCogtoshi: options.amountCogtoshi.toString(),
|
|
72
|
-
}
|
|
73
|
-
: {
|
|
74
|
-
kind: "revoke-support",
|
|
75
|
-
burnCogtoshi: options.amountCogtoshi.toString(),
|
|
76
|
-
},
|
|
77
|
-
review: {
|
|
78
|
-
included: options.review.payloadHex !== null,
|
|
79
|
-
byteLength: options.review.payload?.length ?? null,
|
|
80
|
-
},
|
|
81
|
-
selfStake: options.selfStake,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function describeReputationEffect(effect) {
|
|
85
|
-
if (effect.kind === "give-support") {
|
|
86
|
-
return `burn ${effect.burnCogtoshi} cogtoshi to publish support`;
|
|
87
|
-
}
|
|
88
|
-
return `revoke visible support with no refund of the previously burned ${effect.burnCogtoshi} cogtoshi`;
|
|
89
|
-
}
|
|
90
|
-
function describeReputationReview(review) {
|
|
91
|
-
if (!review.included || review.byteLength === null) {
|
|
92
|
-
return "none";
|
|
93
|
-
}
|
|
94
|
-
return `included (${review.byteLength} bytes)`;
|
|
95
|
-
}
|
|
96
|
-
function resolveReputationOperation(context, sourceDomainName, targetDomainName, errorPrefix) {
|
|
97
|
-
assertWalletMutationContextReady(context, errorPrefix);
|
|
98
|
-
const sourceDomain = lookupDomain(context.snapshot.state, sourceDomainName);
|
|
99
|
-
if (sourceDomain === null) {
|
|
100
|
-
throw new Error(`${errorPrefix}_source_domain_not_found`);
|
|
101
|
-
}
|
|
102
|
-
if (!sourceDomain.anchored) {
|
|
103
|
-
throw new Error(`${errorPrefix}_source_domain_not_anchored`);
|
|
104
|
-
}
|
|
105
|
-
const targetDomain = lookupDomain(context.snapshot.state, targetDomainName);
|
|
106
|
-
if (targetDomain === null) {
|
|
107
|
-
throw new Error(`${errorPrefix}_target_domain_not_found`);
|
|
108
|
-
}
|
|
109
|
-
if (!targetDomain.anchored) {
|
|
110
|
-
throw new Error(`${errorPrefix}_target_domain_not_anchored`);
|
|
111
|
-
}
|
|
112
|
-
const ownerHex = Buffer.from(sourceDomain.ownerScriptPubKey).toString("hex");
|
|
113
|
-
if (ownerHex !== context.localState.state.funding.scriptPubKeyHex || context.model.walletAddress == null) {
|
|
114
|
-
throw new Error(`${errorPrefix}_source_owner_not_locally_controlled`);
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
readContext: context,
|
|
118
|
-
state: context.localState.state,
|
|
119
|
-
sender: createFundingMutationSender(context.localState.state),
|
|
120
|
-
senderSelector: context.model.walletAddress,
|
|
121
|
-
sourceDomain,
|
|
122
|
-
targetDomain,
|
|
123
|
-
availableBalanceCogtoshi: getBalance(context.snapshot.state, sourceDomain.ownerScriptPubKey),
|
|
124
|
-
currentNetSupportCogtoshi: context.snapshot.state.consensus.supportByPair.get(createSupportKey(sourceDomain.domainId, targetDomain.domainId)) ?? 0n,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function buildPlanForReputationOperation(options) {
|
|
128
|
-
const fundingUtxos = options.allUtxos.filter((entry) => entry.scriptPubKey === options.state.funding.scriptPubKeyHex
|
|
129
|
-
&& entry.confirmations >= 1
|
|
130
|
-
&& entry.spendable !== false
|
|
131
|
-
&& entry.safe !== false);
|
|
132
|
-
return {
|
|
133
|
-
sender: options.sender,
|
|
134
|
-
changeAddress: options.state.funding.address,
|
|
135
|
-
fixedInputs: [],
|
|
136
|
-
outputs: [{ data: Buffer.from(options.opReturnData).toString("hex") }],
|
|
137
|
-
changePosition: 1,
|
|
138
|
-
expectedOpReturnScriptHex: encodeOpReturnScript(options.opReturnData),
|
|
139
|
-
allowedFundingScriptPubKeyHex: options.state.funding.scriptPubKeyHex,
|
|
140
|
-
eligibleFundingOutpointKeys: new Set(fundingUtxos.map((entry) => outpointKey({ txid: entry.txid, vout: entry.vout }))),
|
|
141
|
-
errorPrefix: options.errorPrefix,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
function validateFundedDraft(decoded, funded, plan) {
|
|
145
|
-
const inputs = decoded.tx.vin;
|
|
146
|
-
const outputs = decoded.tx.vout;
|
|
147
|
-
if (inputs.length === 0) {
|
|
148
|
-
throw new Error(`${plan.errorPrefix}_missing_sender_input`);
|
|
149
|
-
}
|
|
150
|
-
if (outputs[0]?.scriptPubKey?.hex !== plan.expectedOpReturnScriptHex) {
|
|
151
|
-
throw new Error(`${plan.errorPrefix}_opreturn_mismatch`);
|
|
152
|
-
}
|
|
153
|
-
if (funded.changepos === -1) {
|
|
154
|
-
if (outputs.length !== 1) {
|
|
155
|
-
throw new Error(`${plan.errorPrefix}_unexpected_output_count`);
|
|
156
|
-
}
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
if (funded.changepos !== plan.changePosition || outputs.length !== 2) {
|
|
160
|
-
throw new Error(`${plan.errorPrefix}_change_position_mismatch`);
|
|
161
|
-
}
|
|
162
|
-
if (outputs[funded.changepos]?.scriptPubKey?.hex !== plan.allowedFundingScriptPubKeyHex) {
|
|
163
|
-
throw new Error(`${plan.errorPrefix}_change_output_mismatch`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
async function buildTransaction(options) {
|
|
167
|
-
return buildWalletMutationTransactionWithReserveFallback({
|
|
168
|
-
rpc: options.rpc,
|
|
169
|
-
walletName: options.walletName,
|
|
170
|
-
state: options.state,
|
|
171
|
-
plan: options.plan,
|
|
172
|
-
validateFundedDraft,
|
|
173
|
-
finalizeErrorCode: `${options.plan.errorPrefix}_finalize_failed`,
|
|
174
|
-
mempoolRejectPrefix: `${options.plan.errorPrefix}_mempool_rejected`,
|
|
175
|
-
feeRate: options.feeRateSatVb,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
function createDraftMutation(options) {
|
|
179
|
-
if (options.existing !== null && options.existing !== undefined) {
|
|
180
|
-
return {
|
|
181
|
-
...options.existing,
|
|
182
|
-
kind: options.kind,
|
|
183
|
-
domainName: options.sourceDomainName,
|
|
184
|
-
senderScriptPubKeyHex: options.sender.scriptPubKeyHex,
|
|
185
|
-
senderLocalIndex: options.sender.localIndex,
|
|
186
|
-
recipientDomainName: options.targetDomainName,
|
|
187
|
-
amountCogtoshi: options.amountCogtoshi,
|
|
188
|
-
reviewPayloadHex: options.reviewPayloadHex,
|
|
189
|
-
status: "draft",
|
|
190
|
-
lastUpdatedAtUnixMs: options.nowUnixMs,
|
|
191
|
-
attemptedTxid: null,
|
|
192
|
-
attemptedWtxid: null,
|
|
193
|
-
...createWalletMutationFeeMetadata(options.feeSelection),
|
|
194
|
-
temporaryBuilderLockedOutpoints: [],
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
return {
|
|
198
|
-
mutationId: randomBytes(12).toString("hex"),
|
|
199
|
-
kind: options.kind,
|
|
200
|
-
domainName: options.sourceDomainName,
|
|
201
|
-
parentDomainName: null,
|
|
202
|
-
senderScriptPubKeyHex: options.sender.scriptPubKeyHex,
|
|
203
|
-
senderLocalIndex: options.sender.localIndex,
|
|
204
|
-
amountCogtoshi: options.amountCogtoshi,
|
|
205
|
-
recipientDomainName: options.targetDomainName,
|
|
206
|
-
reviewPayloadHex: options.reviewPayloadHex,
|
|
207
|
-
intentFingerprintHex: options.intentFingerprintHex,
|
|
208
|
-
status: "draft",
|
|
209
|
-
createdAtUnixMs: options.nowUnixMs,
|
|
210
|
-
lastUpdatedAtUnixMs: options.nowUnixMs,
|
|
211
|
-
attemptedTxid: null,
|
|
212
|
-
attemptedWtxid: null,
|
|
213
|
-
...createWalletMutationFeeMetadata(options.feeSelection),
|
|
214
|
-
temporaryBuilderLockedOutpoints: [],
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
async function saveUpdatedMutationState(options) {
|
|
218
|
-
return persistWalletMutationState(options);
|
|
219
|
-
}
|
|
220
|
-
function mutationNeedsRepair(mutation, context) {
|
|
221
|
-
if (context.snapshot === null || mutation.recipientDomainName == null) {
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
const sourceDomain = lookupDomain(context.snapshot.state, mutation.domainName);
|
|
225
|
-
const targetDomain = lookupDomain(context.snapshot.state, mutation.recipientDomainName);
|
|
226
|
-
if (sourceDomain === null || targetDomain === null) {
|
|
227
|
-
return true;
|
|
228
|
-
}
|
|
229
|
-
return !sourceDomain.anchored
|
|
230
|
-
|| !targetDomain.anchored
|
|
231
|
-
|| Buffer.from(sourceDomain.ownerScriptPubKey).toString("hex") !== mutation.senderScriptPubKeyHex;
|
|
232
|
-
}
|
|
233
|
-
async function reconcilePendingReputationMutation(options) {
|
|
234
|
-
if (options.mutation.status === "confirmed" || options.mutation.status === "live") {
|
|
235
|
-
return {
|
|
236
|
-
state: options.state,
|
|
237
|
-
mutation: options.mutation,
|
|
238
|
-
resolution: options.mutation.status,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
if (options.mutation.status === "repair-required") {
|
|
242
|
-
return {
|
|
243
|
-
state: options.state,
|
|
244
|
-
mutation: options.mutation,
|
|
245
|
-
resolution: "repair-required",
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
const walletTx = options.mutation.attemptedTxid === null
|
|
249
|
-
? null
|
|
250
|
-
: await options.rpc.getTransaction(options.walletName, options.mutation.attemptedTxid).catch(() => null);
|
|
251
|
-
if (walletTx !== null) {
|
|
252
|
-
await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
|
|
253
|
-
const status = walletTx.confirmations > 0 ? "confirmed" : "live";
|
|
254
|
-
const nextMutation = updateMutationRecord(options.mutation, status, options.nowUnixMs, {
|
|
255
|
-
temporaryBuilderLockedOutpoints: [],
|
|
256
|
-
});
|
|
257
|
-
let nextState = upsertPendingMutation(options.state, nextMutation);
|
|
258
|
-
nextState = await saveUpdatedMutationState({
|
|
259
|
-
state: nextState,
|
|
260
|
-
provider: options.provider,
|
|
261
|
-
nowUnixMs: options.nowUnixMs,
|
|
262
|
-
paths: options.paths,
|
|
263
|
-
});
|
|
264
|
-
return {
|
|
265
|
-
state: nextState,
|
|
266
|
-
mutation: nextMutation,
|
|
267
|
-
resolution: status,
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
if (mutationNeedsRepair(options.mutation, options.context)) {
|
|
271
|
-
await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
|
|
272
|
-
const repair = updateMutationRecord(options.mutation, "repair-required", options.nowUnixMs, {
|
|
273
|
-
temporaryBuilderLockedOutpoints: [],
|
|
274
|
-
});
|
|
275
|
-
let nextState = upsertPendingMutation(options.state, repair);
|
|
276
|
-
nextState = await saveUpdatedMutationState({
|
|
277
|
-
state: nextState,
|
|
278
|
-
provider: options.provider,
|
|
279
|
-
nowUnixMs: options.nowUnixMs,
|
|
280
|
-
paths: options.paths,
|
|
281
|
-
});
|
|
282
|
-
return { state: nextState, mutation: repair, resolution: "repair-required" };
|
|
283
|
-
}
|
|
284
|
-
if (options.mutation.status === "broadcast-unknown"
|
|
285
|
-
|| options.mutation.status === "draft"
|
|
286
|
-
|| options.mutation.status === "broadcasting") {
|
|
287
|
-
await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
|
|
288
|
-
const canceled = updateMutationRecord(options.mutation, "canceled", options.nowUnixMs, {
|
|
289
|
-
temporaryBuilderLockedOutpoints: [],
|
|
290
|
-
});
|
|
291
|
-
let nextState = upsertPendingMutation(options.state, canceled);
|
|
292
|
-
nextState = await saveUpdatedMutationState({
|
|
293
|
-
state: nextState,
|
|
294
|
-
provider: options.provider,
|
|
295
|
-
nowUnixMs: options.nowUnixMs,
|
|
296
|
-
paths: options.paths,
|
|
297
|
-
});
|
|
298
|
-
return { state: nextState, mutation: canceled, resolution: "not-seen" };
|
|
299
|
-
}
|
|
300
|
-
return {
|
|
301
|
-
state: options.state,
|
|
302
|
-
mutation: options.mutation,
|
|
303
|
-
resolution: "continue",
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
async function confirmYesNo(prompter, message, errorCode, options) {
|
|
307
|
-
await confirmSharedYesNo(prompter, message, {
|
|
308
|
-
assumeYes: options.assumeYes,
|
|
309
|
-
errorCode,
|
|
310
|
-
requiresTtyErrorCode: options.requiresTtyErrorCode,
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
async function confirmTyped(prompter, expected, prompt, errorCode, options) {
|
|
314
|
-
await confirmSharedTypedAcknowledgement(prompter, {
|
|
315
|
-
assumeYes: options.assumeYes,
|
|
316
|
-
expected,
|
|
317
|
-
prompt,
|
|
318
|
-
errorCode,
|
|
319
|
-
requiresTtyErrorCode: options.requiresTtyErrorCode,
|
|
320
|
-
typedAckRequiredErrorCode: options.typedAckRequiredErrorCode,
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
async function confirmReputationMutation(prompter, options) {
|
|
324
|
-
prompter.writeLine(`${options.kind === "give" ? "Giving" : "Revoking"} reputation from "${options.sourceDomainName}" to "${options.targetDomainName}".`);
|
|
325
|
-
prompter.writeLine(`Resolved sender: ${options.resolved.sender.selector} (${options.resolved.sender.address})`);
|
|
326
|
-
prompter.writeLine(`Burn amount: ${formatCogAmount(options.amountCogtoshi)}`);
|
|
327
|
-
prompter.writeLine(`Effect: ${describeReputationEffect(options.resolved.effect)}.`);
|
|
328
|
-
prompter.writeLine(`Review: ${describeReputationReview(options.resolved.review)}.`);
|
|
329
|
-
if (options.reviewText !== null) {
|
|
330
|
-
prompter.writeLine("Warning: review text will be encoded and published publicly in the mempool and on-chain.");
|
|
331
|
-
}
|
|
332
|
-
if (options.kind === "give" && options.resolved.selfStake) {
|
|
333
|
-
prompter.writeLine("Self-stake: yes.");
|
|
334
|
-
prompter.writeLine("Warning: this is self-stake.");
|
|
335
|
-
prompter.writeLine("Self-stake is irrevocable and cannot later be revoked.");
|
|
336
|
-
await confirmTyped(prompter, options.sourceDomainName, `Type ${options.sourceDomainName} to continue: `, "wallet_rep_give_confirmation_rejected", {
|
|
337
|
-
assumeYes: options.assumeYes,
|
|
338
|
-
requiresTtyErrorCode: "wallet_rep_give_requires_tty",
|
|
339
|
-
typedAckRequiredErrorCode: "wallet_rep_give_typed_ack_required",
|
|
340
|
-
});
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
await confirmYesNo(prompter, options.kind === "give"
|
|
344
|
-
? "This burns COG to publish a reputation commitment."
|
|
345
|
-
: "This revokes visible support but the burned COG is not refunded.", options.kind === "give"
|
|
346
|
-
? "wallet_rep_give_confirmation_rejected"
|
|
347
|
-
: "wallet_rep_revoke_confirmation_rejected", {
|
|
348
|
-
assumeYes: options.assumeYes,
|
|
349
|
-
requiresTtyErrorCode: options.kind === "give"
|
|
350
|
-
? "wallet_rep_give_requires_tty"
|
|
351
|
-
: "wallet_rep_revoke_requires_tty",
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
async function encodeReviewText(reviewText, errorPrefix) {
|
|
355
|
-
const trimmed = reviewText?.trim() ?? "";
|
|
356
|
-
if (trimmed === "") {
|
|
357
|
-
return {
|
|
358
|
-
text: null,
|
|
359
|
-
payload: undefined,
|
|
360
|
-
payloadHex: null,
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
return encodeSentence(trimmed)
|
|
364
|
-
.then((payload) => ({
|
|
365
|
-
text: trimmed,
|
|
366
|
-
payload,
|
|
367
|
-
payloadHex: Buffer.from(payload).toString("hex"),
|
|
368
|
-
}))
|
|
369
|
-
.catch((error) => {
|
|
370
|
-
throw new Error(error instanceof Error ? `${errorPrefix}_invalid_review_${error.message}` : `${errorPrefix}_invalid_review`);
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
async function submitReputationMutation(options) {
|
|
374
|
-
if (!options.prompter.isInteractive && options.assumeYes !== true) {
|
|
375
|
-
throw new Error(`${options.errorPrefix}_requires_tty`);
|
|
376
|
-
}
|
|
377
|
-
if (options.amountCogtoshi <= 0n) {
|
|
378
|
-
throw new Error(`${options.errorPrefix}_invalid_amount`);
|
|
379
|
-
}
|
|
380
|
-
const execution = await executeWalletMutationOperation({
|
|
381
|
-
...options,
|
|
382
|
-
controlLockPurpose: options.errorPrefix,
|
|
383
|
-
preemptionReason: options.errorPrefix,
|
|
384
|
-
async resolveOperation(readContext) {
|
|
385
|
-
const normalizedSourceDomainName = normalizeDomainName(options.sourceDomainName, `${options.errorPrefix}_missing_source_domain`);
|
|
386
|
-
const normalizedTargetDomainName = normalizeDomainName(options.targetDomainName, `${options.errorPrefix}_missing_target_domain`);
|
|
387
|
-
const operation = resolveReputationOperation(readContext, normalizedSourceDomainName, normalizedTargetDomainName, options.errorPrefix);
|
|
388
|
-
if (operation.availableBalanceCogtoshi < options.amountCogtoshi) {
|
|
389
|
-
throw new Error(`${options.errorPrefix}_insufficient_cog_balance`);
|
|
390
|
-
}
|
|
391
|
-
if (options.kind === "rep-revoke") {
|
|
392
|
-
if (operation.sourceDomain.domainId === operation.targetDomain.domainId) {
|
|
393
|
-
throw new Error(`${options.errorPrefix}_self_revoke_not_allowed`);
|
|
394
|
-
}
|
|
395
|
-
if (options.amountCogtoshi > operation.currentNetSupportCogtoshi) {
|
|
396
|
-
throw new Error(`${options.errorPrefix}_amount_exceeds_net_support`);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
const review = await encodeReviewText(options.reviewText, options.errorPrefix);
|
|
400
|
-
const selfStake = operation.sourceDomain.domainId === operation.targetDomain.domainId;
|
|
401
|
-
return {
|
|
402
|
-
...operation,
|
|
403
|
-
normalizedSourceDomainName,
|
|
404
|
-
normalizedTargetDomainName,
|
|
405
|
-
review,
|
|
406
|
-
resolved: createResolvedReputationSummary({
|
|
407
|
-
kind: options.kind === "rep-give" ? "give" : "revoke",
|
|
408
|
-
sender: operation.sender,
|
|
409
|
-
senderSelector: operation.senderSelector,
|
|
410
|
-
amountCogtoshi: options.amountCogtoshi,
|
|
411
|
-
review,
|
|
412
|
-
selfStake,
|
|
413
|
-
}),
|
|
414
|
-
};
|
|
415
|
-
},
|
|
416
|
-
createIntentFingerprint(operation) {
|
|
417
|
-
return createIntentFingerprint([
|
|
418
|
-
options.kind,
|
|
419
|
-
operation.state.walletRootId,
|
|
420
|
-
operation.sourceDomain.name,
|
|
421
|
-
operation.targetDomain.name,
|
|
422
|
-
options.amountCogtoshi,
|
|
423
|
-
operation.review.payloadHex ?? "",
|
|
424
|
-
]);
|
|
425
|
-
},
|
|
426
|
-
async resolveExistingMutation({ operation, existingMutation, execution }) {
|
|
427
|
-
if (existingMutation === null) {
|
|
428
|
-
return {
|
|
429
|
-
state: operation.state,
|
|
430
|
-
replacementFixedInputs: null,
|
|
431
|
-
result: null,
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
return resolveExistingWalletMutation({
|
|
435
|
-
existingMutation,
|
|
436
|
-
execution,
|
|
437
|
-
repairRequiredErrorCode: `${options.errorPrefix}_repair_required`,
|
|
438
|
-
reconcileExistingMutation: (mutation) => reconcilePendingReputationMutation({
|
|
439
|
-
state: operation.state,
|
|
440
|
-
mutation,
|
|
441
|
-
provider: execution.provider,
|
|
442
|
-
nowUnixMs: execution.nowUnixMs,
|
|
443
|
-
paths: execution.paths,
|
|
444
|
-
rpc: execution.rpc,
|
|
445
|
-
walletName: execution.walletName,
|
|
446
|
-
context: execution.readContext,
|
|
447
|
-
}),
|
|
448
|
-
createReuseResult: ({ mutation, resolution, fees }) => ({
|
|
449
|
-
kind: options.kind === "rep-give" ? "give" : "revoke",
|
|
450
|
-
sourceDomainName: operation.normalizedSourceDomainName,
|
|
451
|
-
targetDomainName: operation.normalizedTargetDomainName,
|
|
452
|
-
amountCogtoshi: options.amountCogtoshi,
|
|
453
|
-
txid: mutation.attemptedTxid ?? "unknown",
|
|
454
|
-
status: resolution,
|
|
455
|
-
reusedExisting: true,
|
|
456
|
-
reviewIncluded: operation.review.payloadHex !== null,
|
|
457
|
-
resolved: operation.resolved,
|
|
458
|
-
fees,
|
|
459
|
-
}),
|
|
460
|
-
});
|
|
461
|
-
},
|
|
462
|
-
async confirm({ operation }) {
|
|
463
|
-
await confirmReputationMutation(options.prompter, {
|
|
464
|
-
kind: options.kind === "rep-give" ? "give" : "revoke",
|
|
465
|
-
sourceDomainName: operation.normalizedSourceDomainName,
|
|
466
|
-
targetDomainName: operation.normalizedTargetDomainName,
|
|
467
|
-
amountCogtoshi: options.amountCogtoshi,
|
|
468
|
-
reviewText: operation.review.text,
|
|
469
|
-
resolved: operation.resolved,
|
|
470
|
-
assumeYes: options.assumeYes,
|
|
471
|
-
});
|
|
472
|
-
},
|
|
473
|
-
createDraftMutation({ operation, existingMutation, execution, intentFingerprintHex }) {
|
|
474
|
-
return {
|
|
475
|
-
mutation: createDraftMutation({
|
|
476
|
-
kind: options.kind,
|
|
477
|
-
sourceDomainName: operation.normalizedSourceDomainName,
|
|
478
|
-
targetDomainName: operation.normalizedTargetDomainName,
|
|
479
|
-
amountCogtoshi: options.amountCogtoshi,
|
|
480
|
-
sender: operation.sender,
|
|
481
|
-
intentFingerprintHex,
|
|
482
|
-
nowUnixMs: execution.nowUnixMs,
|
|
483
|
-
reviewPayloadHex: operation.review.payloadHex,
|
|
484
|
-
feeSelection: execution.feeSelection,
|
|
485
|
-
existing: existingMutation,
|
|
486
|
-
}),
|
|
487
|
-
prepared: null,
|
|
488
|
-
};
|
|
489
|
-
},
|
|
490
|
-
async build({ operation, state, execution, replacementFixedInputs }) {
|
|
491
|
-
const opReturnData = options.kind === "rep-give"
|
|
492
|
-
? serializeRepCommit(operation.sourceDomain.domainId, operation.targetDomain.domainId, options.amountCogtoshi, operation.review.payload).opReturnData
|
|
493
|
-
: serializeRepRevoke(operation.sourceDomain.domainId, operation.targetDomain.domainId, options.amountCogtoshi, operation.review.payload).opReturnData;
|
|
494
|
-
const reputationPlan = buildPlanForReputationOperation({
|
|
495
|
-
state,
|
|
496
|
-
allUtxos: await execution.rpc.listUnspent(execution.walletName, 1),
|
|
497
|
-
sender: operation.sender,
|
|
498
|
-
opReturnData,
|
|
499
|
-
errorPrefix: options.errorPrefix,
|
|
500
|
-
});
|
|
501
|
-
return buildTransaction({
|
|
502
|
-
rpc: execution.rpc,
|
|
503
|
-
walletName: execution.walletName,
|
|
504
|
-
state,
|
|
505
|
-
plan: {
|
|
506
|
-
...reputationPlan,
|
|
507
|
-
fixedInputs: mergeFixedWalletInputs(reputationPlan.fixedInputs, replacementFixedInputs),
|
|
508
|
-
},
|
|
509
|
-
feeRateSatVb: execution.feeSelection.feeRateSatVb,
|
|
510
|
-
});
|
|
511
|
-
},
|
|
512
|
-
publish({ state, execution, built, mutation }) {
|
|
513
|
-
return publishWalletMutation({
|
|
514
|
-
rpc: execution.rpc,
|
|
515
|
-
walletName: execution.walletName,
|
|
516
|
-
snapshotHeight: execution.readContext.snapshot?.tip?.height ?? null,
|
|
517
|
-
built,
|
|
518
|
-
mutation,
|
|
519
|
-
state,
|
|
520
|
-
provider: execution.provider,
|
|
521
|
-
nowUnixMs: execution.nowUnixMs,
|
|
522
|
-
paths: execution.paths,
|
|
523
|
-
errorPrefix: options.errorPrefix,
|
|
524
|
-
});
|
|
525
|
-
},
|
|
526
|
-
createResult({ operation, mutation, built, status, reusedExisting, fees }) {
|
|
527
|
-
return {
|
|
528
|
-
kind: options.kind === "rep-give" ? "give" : "revoke",
|
|
529
|
-
sourceDomainName: operation.normalizedSourceDomainName,
|
|
530
|
-
targetDomainName: operation.normalizedTargetDomainName,
|
|
531
|
-
amountCogtoshi: options.amountCogtoshi,
|
|
532
|
-
txid: mutation.attemptedTxid ?? built?.txid ?? "unknown",
|
|
533
|
-
status: status,
|
|
534
|
-
reusedExisting,
|
|
535
|
-
reviewIncluded: operation.review.payloadHex !== null,
|
|
536
|
-
resolved: operation.resolved,
|
|
537
|
-
fees,
|
|
538
|
-
};
|
|
539
|
-
},
|
|
540
|
-
});
|
|
541
|
-
return execution.result;
|
|
542
|
-
}
|
|
543
|
-
export async function giveReputation(options) {
|
|
544
|
-
return submitReputationMutation({
|
|
545
|
-
...options,
|
|
546
|
-
kind: "rep-give",
|
|
547
|
-
errorPrefix: "wallet_rep_give",
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
export async function revokeReputation(options) {
|
|
551
|
-
return submitReputationMutation({
|
|
552
|
-
...options,
|
|
553
|
-
kind: "rep-revoke",
|
|
554
|
-
errorPrefix: "wallet_rep_revoke",
|
|
555
|
-
});
|
|
556
|
-
}
|
|
1
|
+
export * from "./reputation/index.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RpcFinalizePsbtResult, RpcTransaction, RpcWalletProcessPsbtResult } from "../../bitcoind/types.js";
|
|
2
|
+
import type { WalletStateV1 } from "../types.js";
|
|
3
|
+
import type { WalletMutationRpcClient } from "./types.js";
|
|
4
|
+
export declare function signAndFinalizeWalletMutation(options: {
|
|
5
|
+
rpc: WalletMutationRpcClient;
|
|
6
|
+
walletName: string;
|
|
7
|
+
state: WalletStateV1;
|
|
8
|
+
psbt: string;
|
|
9
|
+
finalizeErrorCode: string;
|
|
10
|
+
mempoolRejectPrefix: string;
|
|
11
|
+
recoverManagedCoreWalletLockedOnce?: boolean;
|
|
12
|
+
onManagedCoreWalletLockedRecoveryOutcome?: (outcome: "recovered" | "still-locked") => void;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
signed: RpcWalletProcessPsbtResult;
|
|
15
|
+
finalized: RpcFinalizePsbtResult;
|
|
16
|
+
rawHex: string;
|
|
17
|
+
decodedRaw: RpcTransaction;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MANAGED_CORE_WALLET_UNLOCK_TIMEOUT_SECONDS, withUnlockedManagedCoreWallet, } from "../managed-core-wallet.js";
|
|
2
|
+
export async function signAndFinalizeWalletMutation(options) {
|
|
3
|
+
return withUnlockedManagedCoreWallet({
|
|
4
|
+
rpc: options.rpc,
|
|
5
|
+
walletName: options.walletName,
|
|
6
|
+
internalPassphrase: options.state.managedCoreWallet.internalPassphrase,
|
|
7
|
+
timeoutSeconds: MANAGED_CORE_WALLET_UNLOCK_TIMEOUT_SECONDS,
|
|
8
|
+
recoverLockedWalletOnce: options.recoverManagedCoreWalletLockedOnce,
|
|
9
|
+
onLockedWalletRecoveryOutcome: options.onManagedCoreWalletLockedRecoveryOutcome,
|
|
10
|
+
run: async () => {
|
|
11
|
+
const signed = await options.rpc.walletProcessPsbt(options.walletName, options.psbt, true, "DEFAULT");
|
|
12
|
+
const finalized = await options.rpc.finalizePsbt(signed.psbt, true);
|
|
13
|
+
if (!finalized.complete || finalized.hex == null) {
|
|
14
|
+
throw new Error(options.finalizeErrorCode);
|
|
15
|
+
}
|
|
16
|
+
const rawHex = finalized.hex;
|
|
17
|
+
const decodedRaw = await options.rpc.decodeRawTransaction(rawHex);
|
|
18
|
+
const mempoolResult = await options.rpc.testMempoolAccept([rawHex]);
|
|
19
|
+
const accepted = mempoolResult[0];
|
|
20
|
+
if (accepted == null || !accepted.allowed) {
|
|
21
|
+
throw new Error(`${options.mempoolRejectPrefix}_${accepted?.["reject-reason"] ?? "unknown"}`);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
signed,
|
|
25
|
+
finalized,
|
|
26
|
+
rawHex,
|
|
27
|
+
decodedRaw,
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RpcLockedUnspent } from "../../bitcoind/types.js";
|
|
2
|
+
import { type WalletSecretProvider } from "../state/provider.js";
|
|
3
|
+
import type { OutpointRecord, PendingMutationRecord, PendingMutationStatus, WalletStateV1 } from "../types.js";
|
|
4
|
+
import type { WalletRuntimePaths } from "../runtime.js";
|
|
5
|
+
import type { WalletMutationFeeSelectionSource } from "./fee.js";
|
|
6
|
+
import type { WalletMutationRpcClient } from "./types.js";
|
|
7
|
+
export declare function saveWalletStatePreservingUnlock(options: {
|
|
8
|
+
state: WalletStateV1;
|
|
9
|
+
provider: WalletSecretProvider;
|
|
10
|
+
nowUnixMs?: number;
|
|
11
|
+
paths: WalletRuntimePaths;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
export declare function updateMutationRecord(mutation: PendingMutationRecord, status: PendingMutationStatus, nowUnixMs: number, options?: {
|
|
14
|
+
attemptedTxid?: string | null;
|
|
15
|
+
attemptedWtxid?: string | null;
|
|
16
|
+
temporaryBuilderLockedOutpoints?: OutpointRecord[];
|
|
17
|
+
selectedFeeRateSatVb?: number | null;
|
|
18
|
+
feeSelectionSource?: WalletMutationFeeSelectionSource | null;
|
|
19
|
+
}): PendingMutationRecord;
|
|
20
|
+
export declare function unlockTemporaryBuilderLocks(rpc: Pick<WalletMutationRpcClient, "lockUnspent">, walletName: string, outpoints: OutpointRecord[]): Promise<void>;
|
|
21
|
+
export declare function diffTemporaryLockedOutpoints(before: RpcLockedUnspent[], after: RpcLockedUnspent[]): OutpointRecord[];
|
|
22
|
+
export declare function persistWalletMutationState(options: {
|
|
23
|
+
state: WalletStateV1;
|
|
24
|
+
provider: WalletSecretProvider;
|
|
25
|
+
nowUnixMs: number;
|
|
26
|
+
paths: WalletRuntimePaths;
|
|
27
|
+
}): Promise<WalletStateV1>;
|