@parity/dotns-cli 0.6.7 → 0.6.8

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.
Files changed (2) hide show
  1. package/dist/cli.js +169 -7
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -272360,8 +272360,13 @@ function resolveAuthSourceFromEnv(account) {
272360
272360
  }
272361
272361
  return;
272362
272362
  }
272363
+ function isExplicitKeystorePath(keystorePath) {
272364
+ if (keystorePath == null || keystorePath.trim().length === 0)
272365
+ return false;
272366
+ return resolveKeystorePath(keystorePath) !== resolveKeystorePath(undefined);
272367
+ }
272363
272368
  function hasKeystoreSelectionHint(opts) {
272364
- return Boolean(opts.account != null && String(opts.account).trim().length > 0 || opts.keystorePath != null && String(opts.keystorePath).trim().length > 0 || opts.password != null && String(opts.password).trim().length > 0);
272369
+ return Boolean(opts.account != null && String(opts.account).trim().length > 0 || isExplicitKeystorePath(opts.keystorePath) || opts.password != null && String(opts.password).trim().length > 0);
272365
272370
  }
272366
272371
  async function resolveAuthSourceFromKeystore(opts, accountName, requireKeystore) {
272367
272372
  const keystoreDirectoryPath = resolveKeystorePath(opts.keystorePath);
@@ -276074,19 +276079,18 @@ init_ora();
276074
276079
 
276075
276080
  // src/commands/escrow.ts
276076
276081
  init_source();
276082
+ init__esm();
276077
276083
  init_constants();
276078
276084
  init_contractInteractions();
276079
276085
  init_formatting();
276080
276086
  var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
276081
- async function viewEscrowPosition(clientWrapper, originSubstrateAddress, label, spinner) {
276087
+ async function readPositionForName(clientWrapper, originSubstrateAddress, name10) {
276088
+ const label = name10.replace(/\.dot$/, "");
276082
276089
  const tokenId = computeDomainTokenId(label);
276083
- spinner.start(`Reading escrow position for ${source_default.cyan(label + ".dot")}`);
276084
276090
  const raw = await performContractCall(clientWrapper, originSubstrateAddress, CONTRACTS.DOTNS_NAME_ESCROW, DOTNS_NAME_ESCROW_ABI, "getReleasePosition", [tokenId]);
276085
276091
  if (raw.recipient === ZERO_ADDRESS && raw.amount === 0n && !raw.released) {
276086
- spinner.succeed(`No escrow position for ${source_default.cyan(label + ".dot")}`);
276087
276092
  return null;
276088
276093
  }
276089
- spinner.succeed(`Position for ${source_default.cyan(label + ".dot")}`);
276090
276094
  return {
276091
276095
  domain: label,
276092
276096
  tokenId,
@@ -276098,6 +276102,79 @@ async function viewEscrowPosition(clientWrapper, originSubstrateAddress, label,
276098
276102
  claimed: raw.claimed
276099
276103
  };
276100
276104
  }
276105
+ async function viewEscrowPosition(clientWrapper, originSubstrateAddress, label, spinner) {
276106
+ spinner.start(`Reading escrow position for ${source_default.cyan(label + ".dot")}`);
276107
+ const position = await readPositionForName(clientWrapper, originSubstrateAddress, label);
276108
+ spinner.succeed(position === null ? `No escrow position for ${source_default.cyan(label + ".dot")}` : `Position for ${source_default.cyan(label + ".dot")}`);
276109
+ return position;
276110
+ }
276111
+ async function listAccountPositions(clientWrapper, originSubstrateAddress, recipient, names, spinner) {
276112
+ spinner.start(`Reading escrow positions for ${source_default.white(recipient)}`);
276113
+ const me = getAddress(recipient);
276114
+ const positions = [];
276115
+ for (const name10 of names) {
276116
+ const position = await readPositionForName(clientWrapper, originSubstrateAddress, name10).catch(() => null);
276117
+ if (position !== null && getAddress(position.recipient) === me) {
276118
+ positions.push(position);
276119
+ }
276120
+ }
276121
+ spinner.succeed(`Found ${positions.length} position(s)`);
276122
+ return positions;
276123
+ }
276124
+ function totalEscrowAmount(positions) {
276125
+ return positions.reduce((sum, position) => sum + position.amount, 0n);
276126
+ }
276127
+ function cooldownRemainingSeconds(position, nowSeconds) {
276128
+ const remaining = position.withdrawAvailableAt - nowSeconds;
276129
+ return remaining > 0n ? remaining : 0n;
276130
+ }
276131
+ function formatCooldown(seconds) {
276132
+ if (seconds <= 0n)
276133
+ return "0s";
276134
+ const total = Number(seconds);
276135
+ const minutes = Math.floor(total / 60);
276136
+ const rest = total % 60;
276137
+ return minutes > 0 ? `${minutes}m ${rest}s` : `${rest}s`;
276138
+ }
276139
+ function formatPositionStatus(position, nowSeconds) {
276140
+ if (position.claimed)
276141
+ return "claimed";
276142
+ if (!position.released)
276143
+ return "held";
276144
+ const remaining = cooldownRemainingSeconds(position, nowSeconds);
276145
+ return remaining > 0n ? `cooldown ${formatCooldown(remaining)}` : "claimable";
276146
+ }
276147
+ function colorPositionStatus(status) {
276148
+ if (status === "claimable")
276149
+ return source_default.green(status);
276150
+ if (status.startsWith("cooldown"))
276151
+ return source_default.yellow(status);
276152
+ if (status === "held")
276153
+ return source_default.cyan(status);
276154
+ return source_default.gray(status);
276155
+ }
276156
+ function formatPositionsTable(positions, nowSeconds) {
276157
+ if (positions.length === 0)
276158
+ return [];
276159
+ const rows = positions.map((position) => ({
276160
+ name: `${position.domain}.dot`,
276161
+ deposit: `${formatWeiAsEther(position.amount)} PAS`,
276162
+ status: formatPositionStatus(position, nowSeconds)
276163
+ }));
276164
+ const nameWidth = Math.max("NAME".length, ...rows.map((row) => row.name.length));
276165
+ const depositWidth = Math.max("DEPOSIT".length, ...rows.map((row) => row.deposit.length));
276166
+ const header = `${source_default.bold("NAME".padEnd(nameWidth))} ${source_default.bold("DEPOSIT".padEnd(depositWidth))} ${source_default.bold("STATUS")}`;
276167
+ return [
276168
+ header,
276169
+ ...rows.map((row) => `${source_default.cyan(row.name.padEnd(nameWidth))} ${source_default.green(row.deposit.padEnd(depositWidth))} ${colorPositionStatus(row.status)}`)
276170
+ ];
276171
+ }
276172
+ async function getPendingWithdrawal(clientWrapper, originSubstrateAddress, recipient, spinner) {
276173
+ spinner.start(`Reading pull-payment balance for ${source_default.white(recipient)}`);
276174
+ const balance = await performContractCall(clientWrapper, originSubstrateAddress, CONTRACTS.DOTNS_NAME_ESCROW, DOTNS_NAME_ESCROW_ABI, "pendingWithdrawal", [recipient]);
276175
+ spinner.succeed(`Pull-payment balance: ${source_default.green(formatWeiAsEther(balance))} PAS`);
276176
+ return balance;
276177
+ }
276101
276178
  async function releaseDomain(clientWrapper, originSubstrateAddress, signer, label, spinner) {
276102
276179
  const tokenId = computeDomainTokenId(label);
276103
276180
  spinner.start(`Approving escrow for ${source_default.cyan(label + ".dot")}`);
@@ -276160,6 +276237,7 @@ function formatRefundEntryLine(entry4) {
276160
276237
  }
276161
276238
 
276162
276239
  // src/cli/commands/escrow.ts
276240
+ init_storeManagement();
276163
276241
  init_formatting();
276164
276242
  var DEFAULT_REFUND_PAGE_SIZE = 50;
276165
276243
  var MAX_REFUND_PAGE_SIZE = 200;
@@ -276192,6 +276270,8 @@ function attachEscrowCommands(root) {
276192
276270
  console.log(source_default.gray(" amount: ") + source_default.green(formatWeiAsEther(position.amount) + " PAS"));
276193
276271
  console.log(source_default.gray(" released: ") + source_default.white(String(position.released)));
276194
276272
  console.log(source_default.gray(" claimed: ") + source_default.white(String(position.claimed)));
276273
+ const nowSeconds = BigInt(Math.floor(Date.now() / 1000));
276274
+ console.log(source_default.gray(" status: ") + source_default.white(formatPositionStatus(position, nowSeconds)));
276195
276275
  if (position.withdrawAvailableAt > 0n) {
276196
276276
  const t2 = new Date(Number(position.withdrawAvailableAt) * 1000).toISOString();
276197
276277
  console.log(source_default.gray(" withdraw: ") + source_default.white(t2));
@@ -276199,6 +276279,78 @@ function attachEscrowCommands(root) {
276199
276279
  }
276200
276280
  console.log(source_default.green(`
276201
276281
  ✓ Complete
276282
+ `));
276283
+ }
276284
+ process.exit(0);
276285
+ } catch (error2) {
276286
+ handleCommandError(jsonOutput, error2);
276287
+ }
276288
+ });
276289
+ const balanceCommand = escrowCommand.command("balance").description("Show the caller's claimable pull-payment balance").option("--recipient <address>", "Recipient EVM address (defaults to caller)").option("--json", "Output result as JSON (suppresses all other output)", false);
276290
+ addAuthOptions(balanceCommand).action(async (options2, command) => {
276291
+ const jsonOutput = getJsonFlag(command);
276292
+ try {
276293
+ const mergedOptions = getMergedOptions(command, options2);
276294
+ const context = await maybeQuiet(jsonOutput, () => prepareReadOnlyContext(mergedOptions));
276295
+ const recipient = options2.recipient ?? context.evmAddress;
276296
+ if (!jsonOutput)
276297
+ console.log(source_default.bold(`
276298
+ ▶ Escrow balance
276299
+ `));
276300
+ const spinner = ora();
276301
+ const balance = await maybeQuiet(jsonOutput, () => getPendingWithdrawal(context.clientWrapper, context.account.address, recipient, spinner));
276302
+ if (!emitJsonResult(jsonOutput, { recipient, balance: balance.toString() })) {
276303
+ console.log(source_default.gray(" claimable: ") + source_default.green(formatWeiAsEther(balance) + " PAS"));
276304
+ console.log(source_default.green(`
276305
+ ✓ Complete
276306
+ `));
276307
+ }
276308
+ process.exit(0);
276309
+ } catch (error2) {
276310
+ handleCommandError(jsonOutput, error2);
276311
+ }
276312
+ });
276313
+ const positionsCommand = escrowCommand.command("positions").description("List all escrow positions for the caller and the total locked").option("--recipient <address>", "Recipient EVM address (defaults to caller)").option("--json", "Output result as JSON (suppresses all other output)", false);
276314
+ addAuthOptions(positionsCommand).action(async (options2, command) => {
276315
+ const jsonOutput = getJsonFlag(command);
276316
+ try {
276317
+ const mergedOptions = getMergedOptions(command, options2);
276318
+ const context = await maybeQuiet(jsonOutput, () => prepareReadOnlyContext(mergedOptions));
276319
+ const recipient = options2.recipient ?? context.evmAddress;
276320
+ if (!jsonOutput)
276321
+ console.log(source_default.bold(`
276322
+ ▶ Escrow positions
276323
+ `));
276324
+ const spinner = ora();
276325
+ const names = await maybeQuiet(jsonOutput, () => listStoreNames(context.clientWrapper, context.account.address, recipient));
276326
+ const positions = await maybeQuiet(jsonOutput, () => listAccountPositions(context.clientWrapper, context.account.address, recipient, names, spinner));
276327
+ const total = totalEscrowAmount(positions);
276328
+ const nowSeconds = BigInt(Math.floor(Date.now() / 1000));
276329
+ const handled = emitJsonResult(jsonOutput, {
276330
+ recipient,
276331
+ total: total.toString(),
276332
+ positions: positions.map((position) => ({
276333
+ domain: position.domain,
276334
+ tokenId: position.tokenId.toString(),
276335
+ amount: position.amount.toString(),
276336
+ released: position.released,
276337
+ claimed: position.claimed,
276338
+ withdrawAvailableAt: position.withdrawAvailableAt.toString(),
276339
+ status: formatPositionStatus(position, nowSeconds),
276340
+ cooldownSeconds: cooldownRemainingSeconds(position, nowSeconds).toString()
276341
+ }))
276342
+ });
276343
+ if (!handled) {
276344
+ if (positions.length === 0) {
276345
+ console.log(source_default.gray(" no escrow positions"));
276346
+ } else {
276347
+ for (const line of formatPositionsTable(positions, nowSeconds))
276348
+ console.log(" " + line);
276349
+ }
276350
+ console.log(source_default.gray(`
276351
+ total in escrow: `) + source_default.green(formatWeiAsEther(total) + " PAS"));
276352
+ console.log(source_default.green(`
276353
+ ✓ Complete
276202
276354
  `));
276203
276355
  }
276204
276356
  process.exit(0);
@@ -276264,8 +276416,18 @@ function attachEscrowCommands(root) {
276264
276416
  ▶ Escrow claim-withdrawal
276265
276417
  `));
276266
276418
  const spinner = ora();
276419
+ const balance = await maybeQuiet(jsonOutput, () => getPendingWithdrawal(context.clientWrapper, context.substrateAddress, context.evmAddress, spinner));
276420
+ if (balance === 0n) {
276421
+ if (!emitJsonResult(jsonOutput, { ok: true, txHash: null, balance: "0" })) {
276422
+ console.log(source_default.gray(" nothing to claim; pull-payment balance is 0"));
276423
+ console.log(source_default.green(`
276424
+ ✓ Complete
276425
+ `));
276426
+ }
276427
+ process.exit(0);
276428
+ }
276267
276429
  const txHash = await maybeQuiet(jsonOutput, () => claimWithdrawal(context.clientWrapper, context.substrateAddress, context.signer, spinner));
276268
- if (!emitJsonResult(jsonOutput, { ok: true, txHash })) {
276430
+ if (!emitJsonResult(jsonOutput, { ok: true, txHash, balance: balance.toString() })) {
276269
276431
  console.log(source_default.gray(" tx: ") + source_default.blue(txHash));
276270
276432
  console.log(source_default.green(`
276271
276433
  ✓ Complete
@@ -276290,7 +276452,7 @@ function attachEscrowCommands(root) {
276290
276452
  if (!Number.isInteger(limit) || limit < 1 || limit > MAX_REFUND_PAGE_SIZE) {
276291
276453
  throw new Error(`limit must be between 1 and ${MAX_REFUND_PAGE_SIZE}`);
276292
276454
  }
276293
- const recipient = options2.recipient ?? context.account.address;
276455
+ const recipient = options2.recipient ?? context.evmAddress;
276294
276456
  if (!jsonOutput)
276295
276457
  console.log(source_default.bold(`
276296
276458
  ▶ Refund ledger
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@parity/dotns-cli",
3
3
  "module": "index.ts",
4
- "version": "0.6.7",
4
+ "version": "0.6.8",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "packageManager": "bun@1.2.6",