@shelby-protocol/cli 0.0.5 → 0.0.6

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/bin/entry.js +127 -51
  2. package/package.json +1 -1
package/bin/entry.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { Command } from "commander";
5
5
 
6
6
  // package.json
7
- var version = "0.0.5";
7
+ var version = "0.0.6";
8
8
 
9
9
  // src/commands/init.tsx
10
10
  import { render } from "ink";
@@ -2174,6 +2174,76 @@ import { Box as Box5, Text as Text5, render as render4 } from "ink";
2174
2174
  import SelectInput2 from "ink-select-input";
2175
2175
  import ora2 from "ora";
2176
2176
  import { z as z9 } from "zod";
2177
+
2178
+ // src/utils/errors.ts
2179
+ var ERROR_CODES = {
2180
+ UNKNOWN_ERROR: "UNKNOWN_ERROR",
2181
+ EBLOB_WRITE_INSUFFICIENT_FUNDS: "EBLOB_WRITE_INSUFFICIENT_FUNDS",
2182
+ EBLOB_WRITE_CHUNKSET_ALREADY_EXISTS: "EBLOB_WRITE_CHUNKSET_ALREADY_EXISTS",
2183
+ ECONNREFUSED: "ECONNREFUSED",
2184
+ ENOTFOUND: "ENOTFOUND"
2185
+ };
2186
+ var DEFAULT_ERROR_RESPONSE = {
2187
+ displayMessage: "An unknown error occurred",
2188
+ code: ERROR_CODES.UNKNOWN_ERROR
2189
+ };
2190
+ var formatHostInfo = (error) => {
2191
+ if (error instanceof Error) {
2192
+ if ("hostname" in error) {
2193
+ return `(${error.hostname})`;
2194
+ }
2195
+ if ("address" in error && "port" in error) {
2196
+ return `(${error.address}:${error.port})`;
2197
+ }
2198
+ }
2199
+ return void 0;
2200
+ };
2201
+ var handleError = (error) => {
2202
+ if (error instanceof Error) {
2203
+ if (error.message.includes(ERROR_CODES.EBLOB_WRITE_INSUFFICIENT_FUNDS)) {
2204
+ return {
2205
+ displayMessage: "Insufficient Shelby tokens. Please fund your account with Shelby tokens to continue.",
2206
+ code: ERROR_CODES.EBLOB_WRITE_INSUFFICIENT_FUNDS
2207
+ };
2208
+ }
2209
+ if (error.message.includes(ERROR_CODES.EBLOB_WRITE_CHUNKSET_ALREADY_EXISTS)) {
2210
+ return {
2211
+ displayMessage: "The blob already exists on L1.",
2212
+ code: ERROR_CODES.EBLOB_WRITE_CHUNKSET_ALREADY_EXISTS
2213
+ };
2214
+ }
2215
+ if ("code" in error) {
2216
+ if (error.code === ERROR_CODES.ECONNREFUSED) {
2217
+ return {
2218
+ displayMessage: `Could not connect to the Shelby RPC endpoint. Please check that the endpoint you are using is correct ${formatHostInfo(error) ?? ""}.`,
2219
+ code: ERROR_CODES.ECONNREFUSED
2220
+ };
2221
+ }
2222
+ if (error.code === ERROR_CODES.ENOTFOUND) {
2223
+ return {
2224
+ displayMessage: `Could not connect to the Shelby RPC endpoint. Please check that the endpoint you are using is correct ${formatHostInfo(error) ?? ""}.`,
2225
+ code: ERROR_CODES.ENOTFOUND
2226
+ };
2227
+ }
2228
+ }
2229
+ if (error.cause instanceof AggregateError) {
2230
+ const firstKnownError = error.cause.errors.find((error2) => {
2231
+ const handledError = handleError(error2);
2232
+ return handledError.code !== ERROR_CODES.UNKNOWN_ERROR;
2233
+ });
2234
+ if (firstKnownError) return handleError(firstKnownError);
2235
+ }
2236
+ if (error.cause instanceof Error) {
2237
+ return handleError(error.cause);
2238
+ }
2239
+ }
2240
+ return {
2241
+ displayMessage: `An unknown error occurred ${error instanceof Error ? `: ${error.message}` : ""}`,
2242
+ code: ERROR_CODES.UNKNOWN_ERROR
2243
+ };
2244
+ };
2245
+
2246
+ // src/commands/upload.tsx
2177
2247
  import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
2178
2248
  var normBlobName2 = (i, f, b) => normBlobName(path4, i, f, b);
2179
2249
  var flexibleDateSchema = z9.string().transform((val) => {
@@ -2374,60 +2444,66 @@ function uploadCommand(program) {
2374
2444
  let hasUploadedBlob = false;
2375
2445
  for (const entry of filelist) {
2376
2446
  spinner.text = `Reading ${entry.filename}.. (Overall: ${formatProgressPercent()}%, ${formatProgressRate()} MiB/s)`;
2377
- const blobData = await fs3.readFile(entry.filename);
2378
- if (blobData.length !== entry.sizeBytes) {
2379
- throw new Error(
2380
- `Size of file ${entry.filename} changed after initial scan. Original size was ${entry.sizeBytes} but it is now ${blobData.length}`
2381
- );
2382
- }
2383
- spinner.text = `Committing ${entry.filename} to L1.. (Overall: ${formatProgressPercent()}%, ${formatProgressRate()} MiB/s)`;
2384
- const existingBlobMetadata = await shelbyBlobClient.getBlobMetadata({
2385
- account: activeAccount.accountAddress,
2386
- name: entry.blobname
2387
- });
2388
- const blobCommitments = await generateCommitments(
2389
- Readable4.from(blobData)
2390
- );
2391
- if (!existingBlobMetadata) {
2392
- const { transaction: pendingWriteBlobCommitmentsTransaction } = await shelbyBlobClient.writeBlobCommitments({
2393
- account: activeAccount,
2394
- blobName: entry.blobname,
2395
- lifetime: validatedOptions.expiration.getTime() * 1e3,
2396
- blobCommitments
2397
- });
2398
- await aptos.waitForTransaction({
2399
- transactionHash: pendingWriteBlobCommitmentsTransaction.hash
2447
+ try {
2448
+ const blobData = await fs3.readFile(entry.filename);
2449
+ if (blobData.length !== entry.sizeBytes) {
2450
+ throw new Error(
2451
+ `Size of file ${entry.filename} changed after initial scan. Original size was ${entry.sizeBytes} but it is now ${blobData.length}`
2452
+ );
2453
+ }
2454
+ spinner.text = `Committing ${entry.filename} to L1.. (Overall: ${formatProgressPercent()}%, ${formatProgressRate()} MiB/s)`;
2455
+ const existingBlobMetadata = await shelbyBlobClient.getBlobMetadata({
2456
+ account: activeAccount.accountAddress,
2457
+ name: entry.blobname
2400
2458
  });
2401
- } else {
2402
- spinner.text = `Blob ${entry.blobname} already exists on L1, skipping commitments and uploading to Shelby RPC...`;
2403
- }
2404
- if (validatedOptions.outputCommitments) {
2405
- outputCommitments[entry.filename] = blobCommitments;
2406
- }
2407
- const existingBlobChunks = await shelbyBlobClient.getBlobChunks({
2408
- account: activeAccount.accountAddress,
2409
- name: entry.blobname
2410
- });
2411
- if (existingBlobChunks.length === 0) {
2412
- console.error(
2413
- `Blob ${entry.blobname} does not exist on L1, an error occurred when uploading commitments...`
2459
+ const blobCommitments = await generateCommitments(
2460
+ Readable4.from(blobData)
2414
2461
  );
2462
+ if (!existingBlobMetadata) {
2463
+ const { transaction: pendingWriteBlobCommitmentsTransaction } = await shelbyBlobClient.writeBlobCommitments({
2464
+ account: activeAccount,
2465
+ blobName: entry.blobname,
2466
+ lifetime: validatedOptions.expiration.getTime() * 1e3,
2467
+ blobCommitments
2468
+ });
2469
+ await aptos.waitForTransaction({
2470
+ transactionHash: pendingWriteBlobCommitmentsTransaction.hash
2471
+ });
2472
+ } else {
2473
+ spinner.text = `Blob ${entry.blobname} already exists on L1, skipping commitments and uploading to Shelby RPC...`;
2474
+ }
2475
+ if (validatedOptions.outputCommitments) {
2476
+ outputCommitments[entry.filename] = blobCommitments;
2477
+ }
2478
+ const existingBlobChunks = await shelbyBlobClient.getBlobChunks({
2479
+ account: activeAccount.accountAddress,
2480
+ name: entry.blobname
2481
+ });
2482
+ if (existingBlobChunks.length === 0) {
2483
+ console.error(
2484
+ `Blob ${entry.blobname} does not exist on L1, an error occurred when uploading commitments...`
2485
+ );
2486
+ process.exit(1);
2487
+ }
2488
+ if (!existingBlobChunks.every(
2489
+ (chunk) => chunk.location.variant === "stored"
2490
+ )) {
2491
+ spinner.text = `Uploading ${entry.filename} to Shelby RPC.. (Overall: ${formatProgressPercent()}%, ${formatProgressRate()} MiB/s)`;
2492
+ await shelbyNodeClient.putBlob(
2493
+ activeAccount.accountAddress,
2494
+ entry.blobname,
2495
+ blobData
2496
+ );
2497
+ hasUploadedBlob = true;
2498
+ } else {
2499
+ spinner.text = "All blob chunks have been stored on L1, skipping upload to Shelby RPC...";
2500
+ }
2501
+ amountUploaded += blobData.length;
2502
+ } catch (error) {
2503
+ const { displayMessage } = handleError(error);
2504
+ spinner.fail(displayMessage);
2415
2505
  process.exit(1);
2416
2506
  }
2417
- if (!existingBlobChunks.every(
2418
- (chunk) => chunk.location.variant === "stored"
2419
- )) {
2420
- spinner.text = `Uploading ${entry.filename} to Shelby RPC.. (Overall: ${formatProgressPercent()}%, ${formatProgressRate()} MiB/s)`;
2421
- await shelbyNodeClient.putBlob(
2422
- activeAccount.accountAddress,
2423
- entry.blobname,
2424
- blobData
2425
- );
2426
- hasUploadedBlob = true;
2427
- } else {
2428
- spinner.text = "All blob chunks have been stored on L1, skipping upload to Shelby RPC...";
2429
- }
2430
- amountUploaded += blobData.length;
2431
2507
  }
2432
2508
  if (validatedOptions.outputCommitments) {
2433
2509
  await fs3.writeFile(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shelby-protocol/cli",
3
3
  "type": "module",
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
5
5
  "private": false,
6
6
  "bin": {
7
7
  "shelby": "bin/entry.js"