@parity/dotns-cli 0.5.6 → 0.6.0
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/dist/cli.js +84 -45
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -240167,6 +240167,20 @@ var require_bn = __commonJS((exports, module) => {
|
|
|
240167
240167
|
});
|
|
240168
240168
|
|
|
240169
240169
|
// src/utils/contractInteractions.ts
|
|
240170
|
+
function isRevertFlag(flags) {
|
|
240171
|
+
return (flags & 1n) === 1n;
|
|
240172
|
+
}
|
|
240173
|
+
function buildRevertError(data, abi) {
|
|
240174
|
+
if (data === "0x") {
|
|
240175
|
+
return new Error(UNMAPPED_ORIGIN_REVERT_HINT);
|
|
240176
|
+
}
|
|
240177
|
+
let revertReason = data;
|
|
240178
|
+
try {
|
|
240179
|
+
const decoded = decodeErrorResult({ abi, data });
|
|
240180
|
+
revertReason = decoded.args ? `${decoded.errorName}(${decoded.args.map(String).join(", ")})` : decoded.errorName;
|
|
240181
|
+
} catch {}
|
|
240182
|
+
return new Error(`Contract reverted: ${revertReason}`);
|
|
240183
|
+
}
|
|
240170
240184
|
async function performContractCall(clientWrapper, originSubstrateAddress, contractAddress, abi, functionName, args) {
|
|
240171
240185
|
const encodedData = encodeFunctionData({
|
|
240172
240186
|
abi,
|
|
@@ -240176,13 +240190,8 @@ async function performContractCall(clientWrapper, originSubstrateAddress, contra
|
|
|
240176
240190
|
const call = await clientWrapper.performDryRunCall(originSubstrateAddress, contractAddress, 0n, encodedData);
|
|
240177
240191
|
const data = call?.result?.value?.data ?? "0x";
|
|
240178
240192
|
const flags = call?.result?.value?.flags ?? 1n;
|
|
240179
|
-
if ((flags
|
|
240180
|
-
|
|
240181
|
-
try {
|
|
240182
|
-
const decoded2 = decodeErrorResult({ abi, data });
|
|
240183
|
-
revertReason = decoded2.args ? `${decoded2.errorName}(${decoded2.args.map(String).join(", ")})` : decoded2.errorName;
|
|
240184
|
-
} catch {}
|
|
240185
|
-
throw new Error(`Contract reverted: ${revertReason}`);
|
|
240193
|
+
if (isRevertFlag(flags)) {
|
|
240194
|
+
throw buildRevertError(data, abi);
|
|
240186
240195
|
}
|
|
240187
240196
|
const decoded = decodeFunctionResult({
|
|
240188
240197
|
abi,
|
|
@@ -240225,10 +240234,12 @@ function computeDomainTokenId(label) {
|
|
|
240225
240234
|
const node = keccak256(concatHex([DOT_NODE, labelhash]));
|
|
240226
240235
|
return BigInt(node);
|
|
240227
240236
|
}
|
|
240237
|
+
var UNMAPPED_ORIGIN_REVERT_HINT;
|
|
240228
240238
|
var init_contractInteractions = __esm(() => {
|
|
240229
240239
|
init__esm();
|
|
240230
240240
|
init_constants();
|
|
240231
240241
|
init_formatting();
|
|
240242
|
+
UNMAPPED_ORIGIN_REVERT_HINT = "Contract reverted with empty data. The origin SS58 is likely not mapped on " + "Asset Hub Revive. Run `dotns account map` (or any signed transaction from " + "this account), then retry.";
|
|
240232
240243
|
});
|
|
240233
240244
|
|
|
240234
240245
|
// abis/Multicall3.json
|
|
@@ -264950,6 +264961,9 @@ async function createAccountFromSource(source, isKeyUri) {
|
|
|
264950
264961
|
const keyring = new Keyring({ type: "sr25519" });
|
|
264951
264962
|
return isKeyUri ? keyring.addFromUri(source) : keyring.addFromMnemonic(source);
|
|
264952
264963
|
}
|
|
264964
|
+
function createSubstrateSigner(keypair3) {
|
|
264965
|
+
return getPolkadotSigner(keypair3.publicKey, "Sr25519", async (input) => keypair3.sign(input));
|
|
264966
|
+
}
|
|
264953
264967
|
async function readDefaultAccountName2(keystoreDirectoryPath) {
|
|
264954
264968
|
try {
|
|
264955
264969
|
const defaultPointerPath = path8.join(keystoreDirectoryPath, ".default");
|
|
@@ -265071,7 +265085,7 @@ async function prepareAssetHubContext(options2) {
|
|
|
265071
265085
|
}));
|
|
265072
265086
|
const account = await step("Loading keypair", async () => createAccountFromSource(auth.source, auth.isKeyUri));
|
|
265073
265087
|
const substrateAddress = account.address;
|
|
265074
|
-
const signer =
|
|
265088
|
+
const signer = createSubstrateSigner(account);
|
|
265075
265089
|
const clientWrapper = new ReviveClientWrapper(client);
|
|
265076
265090
|
const evmAddress = await step("Resolving EVM address", async () => clientWrapper.getEvmAddress(substrateAddress));
|
|
265077
265091
|
console.log(source_default.bold(`
|
|
@@ -265117,7 +265131,7 @@ async function prepareBulletinContext(options2) {
|
|
|
265117
265131
|
}));
|
|
265118
265132
|
const account = await step("Loading keypair", async () => createAccountFromSource(auth.source, auth.isKeyUri));
|
|
265119
265133
|
const substrateAddress = account.address;
|
|
265120
|
-
const signer =
|
|
265134
|
+
const signer = createSubstrateSigner(account);
|
|
265121
265135
|
console.log(source_default.bold(`
|
|
265122
265136
|
\uD83D\uDCCB Configuration
|
|
265123
265137
|
`));
|
|
@@ -266429,11 +266443,18 @@ async function waitForMinimumCommitmentAge(clientWrapper, originSubstrateAddress
|
|
|
266429
266443
|
clearInterval(intervalId);
|
|
266430
266444
|
waitSpinner.text = "Verifying commitment age on-chain";
|
|
266431
266445
|
const pollDeadline = Date.now() + COMMITMENT_POLL_TIMEOUT_MS;
|
|
266446
|
+
const timestampQuery = clientWrapper.client.query?.Timestamp?.Now;
|
|
266432
266447
|
while (Date.now() < pollDeadline) {
|
|
266433
266448
|
const polledTimestamp = await performContractCall(clientWrapper, originSubstrateAddress, CONTRACTS.DOTNS_REGISTRAR_CONTROLLER, DOTNS_REGISTRAR_CONTROLLER_ABI, "commitments", [commitment]);
|
|
266434
266449
|
const polledCommitTime = typeof polledTimestamp === "bigint" ? Number(polledTimestamp) : polledTimestamp;
|
|
266435
|
-
|
|
266436
|
-
if (
|
|
266450
|
+
let chainNowSeconds;
|
|
266451
|
+
if (timestampQuery?.getValue) {
|
|
266452
|
+
const timestampMs = await timestampQuery.getValue();
|
|
266453
|
+
chainNowSeconds = Math.floor(Number(timestampMs) / 1000);
|
|
266454
|
+
} else {
|
|
266455
|
+
chainNowSeconds = Math.floor(Date.now() / 1000);
|
|
266456
|
+
}
|
|
266457
|
+
if (polledCommitTime > 0 && chainNowSeconds - polledCommitTime >= minimumAgeSeconds) {
|
|
266437
266458
|
waitSpinner.succeed("Commitment age requirement met (verified on-chain)");
|
|
266438
266459
|
return;
|
|
266439
266460
|
}
|
|
@@ -266950,12 +266971,23 @@ async function prepareReadOnlyContext(options2) {
|
|
|
266950
266971
|
};
|
|
266951
266972
|
});
|
|
266952
266973
|
const keypair3 = await step("Loading keypair", async () => createAccountFromSource(auth.source, auth.isKeyUri));
|
|
266974
|
+
await ensureAccountMappedWhenAuthenticated(clientWrapper, keypair3, auth.resolvedFrom);
|
|
266953
266975
|
const evmAddress = await step("Resolving EVM address", async () => clientWrapper.getEvmAddress(keypair3.address));
|
|
266954
266976
|
console.log(source_default.gray(`
|
|
266955
266977
|
RPC: `) + source_default.white(rpc));
|
|
266956
266978
|
console.log(source_default.gray(" Account: ") + source_default.white(keypair3.address));
|
|
266957
266979
|
return { clientWrapper, account: { address: keypair3.address }, rpc, evmAddress };
|
|
266958
266980
|
}
|
|
266981
|
+
async function ensureAccountMappedWhenAuthenticated(clientWrapper, keypair3, resolvedFrom) {
|
|
266982
|
+
if (resolvedFrom === "default")
|
|
266983
|
+
return;
|
|
266984
|
+
const signer = createSubstrateSigner(keypair3);
|
|
266985
|
+
try {
|
|
266986
|
+
await step("Ensuring account mapped", async () => clientWrapper.ensureAccountMapped(keypair3.address, signer));
|
|
266987
|
+
} catch (mapError) {
|
|
266988
|
+
console.log(source_default.yellow(` ⚠ Account mapping skipped: ${mapError instanceof Error ? mapError.message : String(mapError)}`));
|
|
266989
|
+
}
|
|
266990
|
+
}
|
|
266959
266991
|
async function resolveRecipientByKind(clientWrapper, substrateAddress, destination) {
|
|
266960
266992
|
const kind = classifyTransferDestination(destination);
|
|
266961
266993
|
switch (kind) {
|
|
@@ -267208,29 +267240,37 @@ init_constants();
|
|
|
267208
267240
|
init_contractInteractions();
|
|
267209
267241
|
async function viewDomainText(clientWrapper, originSubstrateAddress, label, key, spinner) {
|
|
267210
267242
|
const namehashNode = namehash(`${label}.dot`);
|
|
267243
|
+
const domain = `${label}.dot`;
|
|
267211
267244
|
spinner.start("Querying registry");
|
|
267212
267245
|
const recordExists = await performContractCall(clientWrapper, originSubstrateAddress, CONTRACTS.DOTNS_REGISTRY, DOTNS_REGISTRY_ABI, "recordExists", [namehashNode]);
|
|
267213
267246
|
const ownerAddress = await performContractCall(clientWrapper, originSubstrateAddress, CONTRACTS.DOTNS_REGISTRY, DOTNS_REGISTRY_ABI, "owner", [namehashNode]);
|
|
267214
267247
|
spinner.succeed("Registry read");
|
|
267215
267248
|
console.log(source_default.gray(" registry: ") + source_default.white(CONTRACTS.DOTNS_REGISTRY));
|
|
267216
|
-
console.log(source_default.gray(" domain: ") + source_default.cyan(
|
|
267249
|
+
console.log(source_default.gray(" domain: ") + source_default.cyan(domain));
|
|
267217
267250
|
console.log(source_default.gray(" node: ") + source_default.white(namehashNode));
|
|
267218
267251
|
console.log(source_default.gray(" exists: ") + source_default.white(String(recordExists)));
|
|
267219
267252
|
console.log(source_default.gray(" owner: ") + source_default.white(ownerAddress));
|
|
267220
267253
|
console.log();
|
|
267221
267254
|
if (!recordExists || ownerAddress === zeroAddress) {
|
|
267222
267255
|
console.log(source_default.yellow(" status: Domain not registered"));
|
|
267223
|
-
return;
|
|
267256
|
+
return { domain, key, exists: false, owner: null, value: null };
|
|
267224
267257
|
}
|
|
267225
267258
|
const value3 = await performContractCall(clientWrapper, originSubstrateAddress, CONTRACTS.DOTNS_CONTENT_RESOLVER, DOTNS_CONTENT_RESOLVER_ABI, "text", [namehashNode, key]);
|
|
267226
267259
|
console.log(source_default.gray(" resolver: ") + source_default.white(CONTRACTS.DOTNS_CONTENT_RESOLVER));
|
|
267227
267260
|
console.log(source_default.gray(" key: ") + source_default.white(key));
|
|
267228
267261
|
console.log(source_default.gray(" value: ") + source_default.cyan(value3 || "(not set)"));
|
|
267229
|
-
return
|
|
267262
|
+
return {
|
|
267263
|
+
domain,
|
|
267264
|
+
key,
|
|
267265
|
+
exists: true,
|
|
267266
|
+
owner: ownerAddress,
|
|
267267
|
+
value: value3 === "" ? null : value3
|
|
267268
|
+
};
|
|
267230
267269
|
}
|
|
267231
267270
|
async function setDomainText(clientWrapper, originSubstrateAddress, signer, label, key, value3, spinner) {
|
|
267232
267271
|
const namehashNode = namehash(`${label}.dot`);
|
|
267233
|
-
|
|
267272
|
+
const domain = `${label}.dot`;
|
|
267273
|
+
console.log(source_default.gray(" domain: ") + source_default.cyan(domain));
|
|
267234
267274
|
console.log(source_default.gray(" node: ") + source_default.white(namehashNode));
|
|
267235
267275
|
console.log();
|
|
267236
267276
|
const { exists: exists2, owner, caller } = await getResolverNodeInfo(clientWrapper, originSubstrateAddress, namehashNode);
|
|
@@ -267239,7 +267279,7 @@ async function setDomainText(clientWrapper, originSubstrateAddress, signer, labe
|
|
|
267239
267279
|
console.log(source_default.gray(" caller: ") + source_default.white(caller));
|
|
267240
267280
|
console.log();
|
|
267241
267281
|
if (!exists2) {
|
|
267242
|
-
throw new Error(`Domain ${
|
|
267282
|
+
throw new Error(`Domain ${domain} is not registered`);
|
|
267243
267283
|
}
|
|
267244
267284
|
await requireResolverAuthorization(clientWrapper, originSubstrateAddress, owner, caller);
|
|
267245
267285
|
console.log(source_default.gray(" status: ") + source_default.green("Ownership verified"));
|
|
@@ -267261,46 +267301,45 @@ async function setDomainText(clientWrapper, originSubstrateAddress, signer, labe
|
|
|
267261
267301
|
const updatedValue = await performContractCall(clientWrapper, originSubstrateAddress, CONTRACTS.DOTNS_CONTENT_RESOLVER, DOTNS_CONTENT_RESOLVER_ABI, "text", [namehashNode, key]);
|
|
267262
267302
|
console.log();
|
|
267263
267303
|
console.log(source_default.gray(" new: ") + source_default.cyan(updatedValue));
|
|
267304
|
+
return {
|
|
267305
|
+
ok: true,
|
|
267306
|
+
domain,
|
|
267307
|
+
key,
|
|
267308
|
+
value: value3,
|
|
267309
|
+
txHash: transactionHash
|
|
267310
|
+
};
|
|
267264
267311
|
}
|
|
267265
267312
|
|
|
267266
267313
|
// src/cli/commands/text.ts
|
|
267267
|
-
init_formatting();
|
|
267268
267314
|
init_ora();
|
|
267269
267315
|
function attachTextCommands(root) {
|
|
267270
267316
|
const textCommand = root.command("text").description("Manage domain text records");
|
|
267271
267317
|
addAuthOptions(textCommand);
|
|
267272
|
-
const viewTextCommand = textCommand.command("view <name> <key>").description("View a domain text record");
|
|
267318
|
+
const viewTextCommand = textCommand.command("view <name> <key>").description("View a domain text record").option("--json", "Output result as JSON (suppresses all other output)", false);
|
|
267273
267319
|
addAuthOptions(viewTextCommand).action(async (name10, key, options2, command) => {
|
|
267274
|
-
const
|
|
267275
|
-
const origWrite = process.stdout.write.bind(process.stdout);
|
|
267276
|
-
if (piped) {
|
|
267277
|
-
console.log = console.error;
|
|
267278
|
-
process.stdout.write = process.stderr.write.bind(process.stderr);
|
|
267279
|
-
}
|
|
267320
|
+
const jsonOutput = getJsonFlag(command);
|
|
267280
267321
|
try {
|
|
267281
267322
|
const mergedOptions = getMergedOptions(command, options2);
|
|
267282
|
-
const context = await prepareReadOnlyContext(mergedOptions);
|
|
267283
|
-
|
|
267323
|
+
const context = await maybeQuiet(jsonOutput, () => prepareReadOnlyContext(mergedOptions));
|
|
267324
|
+
if (!jsonOutput)
|
|
267325
|
+
console.log(source_default.bold(`
|
|
267284
267326
|
▶ Text View
|
|
267285
267327
|
`));
|
|
267286
|
-
const spinner = ora(
|
|
267287
|
-
const
|
|
267288
|
-
|
|
267328
|
+
const spinner = ora();
|
|
267329
|
+
const result = await maybeQuiet(jsonOutput, () => viewDomainText(context.clientWrapper, context.account.address, name10, key, spinner));
|
|
267330
|
+
if (!emitJsonResult(jsonOutput, result)) {
|
|
267331
|
+
console.log(source_default.green(`
|
|
267289
267332
|
✓ Complete
|
|
267290
267333
|
`));
|
|
267291
|
-
if (piped && value3 != null) {
|
|
267292
|
-
origWrite(value3);
|
|
267293
267334
|
}
|
|
267294
267335
|
process.exit(0);
|
|
267295
267336
|
} catch (error2) {
|
|
267296
|
-
|
|
267297
|
-
✗ Error: ${formatErrorMessage(error2)}
|
|
267298
|
-
`));
|
|
267299
|
-
process.exit(1);
|
|
267337
|
+
handleCommandError(jsonOutput, error2);
|
|
267300
267338
|
}
|
|
267301
267339
|
});
|
|
267302
|
-
const setTextCommand = textCommand.command("set <name> <key> [value]").description("Set a domain text record (reads from stdin if value omitted)");
|
|
267340
|
+
const setTextCommand = textCommand.command("set <name> <key> [value]").description("Set a domain text record (reads from stdin if value omitted)").option("--json", "Output result as JSON (suppresses all other output)", false);
|
|
267303
267341
|
addAuthOptions(setTextCommand).action(async (name10, key, value3, options2, command) => {
|
|
267342
|
+
const jsonOutput = getJsonFlag(command);
|
|
267304
267343
|
try {
|
|
267305
267344
|
const mergedOptions = getMergedOptions(command, options2);
|
|
267306
267345
|
if (!value3) {
|
|
@@ -267316,21 +267355,21 @@ function attachTextCommands(root) {
|
|
|
267316
267355
|
if (mergedOptions.mnemonic && mergedOptions.keyUri) {
|
|
267317
267356
|
throw new Error("Cannot specify both --mnemonic and --key-uri");
|
|
267318
267357
|
}
|
|
267319
|
-
const context = await prepareContext({ ...mergedOptions, useRevive: true });
|
|
267320
|
-
|
|
267358
|
+
const context = await maybeQuiet(jsonOutput, () => prepareContext({ ...mergedOptions, useRevive: true }));
|
|
267359
|
+
if (!jsonOutput)
|
|
267360
|
+
console.log(source_default.bold(`
|
|
267321
267361
|
▶ Text Set
|
|
267322
267362
|
`));
|
|
267323
267363
|
const spinner = ora();
|
|
267324
|
-
await setDomainText(context.clientWrapper, context.substrateAddress, context.signer, name10, key, value3, spinner);
|
|
267325
|
-
|
|
267364
|
+
const result = await maybeQuiet(jsonOutput, () => setDomainText(context.clientWrapper, context.substrateAddress, context.signer, name10, key, value3, spinner));
|
|
267365
|
+
if (!emitJsonResult(jsonOutput, result)) {
|
|
267366
|
+
console.log(source_default.green(`
|
|
267326
267367
|
✓ Complete
|
|
267327
267368
|
`));
|
|
267369
|
+
}
|
|
267328
267370
|
process.exit(0);
|
|
267329
267371
|
} catch (error2) {
|
|
267330
|
-
|
|
267331
|
-
✗ Error: ${formatErrorMessage(error2)}
|
|
267332
|
-
`));
|
|
267333
|
-
process.exit(1);
|
|
267372
|
+
handleCommandError(jsonOutput, error2);
|
|
267334
267373
|
}
|
|
267335
267374
|
});
|
|
267336
267375
|
}
|
|
@@ -267674,7 +267713,7 @@ function attachAccountCommands(root) {
|
|
|
267674
267713
|
});
|
|
267675
267714
|
}
|
|
267676
267715
|
// package.json
|
|
267677
|
-
var version5 = "0.
|
|
267716
|
+
var version5 = "0.6.0";
|
|
267678
267717
|
|
|
267679
267718
|
// src/cli/commands/store.ts
|
|
267680
267719
|
init_source();
|