@shelby-protocol/cli 0.0.5 → 0.0.7
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/bin/entry.js +131 -63
- 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.
|
|
7
|
+
var version = "0.0.7";
|
|
8
8
|
|
|
9
9
|
// src/commands/init.tsx
|
|
10
10
|
import { render } from "ink";
|
|
@@ -1168,15 +1168,7 @@ var require2 = createRequire(import.meta.url);
|
|
|
1168
1168
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
1169
1169
|
var RS;
|
|
1170
1170
|
try {
|
|
1171
|
-
|
|
1172
|
-
RS = require2(join(__dirname, "binding.node"));
|
|
1173
|
-
} catch {
|
|
1174
|
-
try {
|
|
1175
|
-
RS = require2(join(dirname(process.execPath), "binding.node"));
|
|
1176
|
-
} catch {
|
|
1177
|
-
RS = require2(join(process.cwd(), "bin", "binding.node"));
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1171
|
+
RS = require2(join(__dirname, "binding.node"));
|
|
1180
1172
|
} catch {
|
|
1181
1173
|
RS = require2("@ronomon/reed-solomon");
|
|
1182
1174
|
}
|
|
@@ -1271,12 +1263,11 @@ async function generateCommitments(fullData, onChunk, options) {
|
|
|
1271
1263
|
};
|
|
1272
1264
|
}
|
|
1273
1265
|
|
|
1274
|
-
// ../../packages/sdk/dist/chunk-
|
|
1266
|
+
// ../../packages/sdk/dist/chunk-AASWNUSM.mjs
|
|
1275
1267
|
import { Readable as Readable3 } from "stream";
|
|
1276
1268
|
import {
|
|
1277
1269
|
AccountAddress as AccountAddress3,
|
|
1278
1270
|
Aptos as Aptos2,
|
|
1279
|
-
AptosApiError,
|
|
1280
1271
|
Hex,
|
|
1281
1272
|
MoveVector
|
|
1282
1273
|
} from "@aptos-labs/ts-sdk";
|
|
@@ -1317,7 +1308,8 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
|
|
|
1317
1308
|
expirationMicros: metadata.expiration_micros
|
|
1318
1309
|
};
|
|
1319
1310
|
} catch (error) {
|
|
1320
|
-
if (error instanceof
|
|
1311
|
+
if (error instanceof Error && // Depending on the network, the error message may show up differently.
|
|
1312
|
+
(error.message?.includes("sub_status: Some(404)") || error.message?.includes("EBLOB_NOT_FOUND"))) {
|
|
1321
1313
|
return void 0;
|
|
1322
1314
|
}
|
|
1323
1315
|
throw error;
|
|
@@ -2174,6 +2166,76 @@ import { Box as Box5, Text as Text5, render as render4 } from "ink";
|
|
|
2174
2166
|
import SelectInput2 from "ink-select-input";
|
|
2175
2167
|
import ora2 from "ora";
|
|
2176
2168
|
import { z as z9 } from "zod";
|
|
2169
|
+
|
|
2170
|
+
// src/utils/errors.ts
|
|
2171
|
+
var ERROR_CODES = {
|
|
2172
|
+
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
2173
|
+
EBLOB_WRITE_INSUFFICIENT_FUNDS: "EBLOB_WRITE_INSUFFICIENT_FUNDS",
|
|
2174
|
+
EBLOB_WRITE_CHUNKSET_ALREADY_EXISTS: "EBLOB_WRITE_CHUNKSET_ALREADY_EXISTS",
|
|
2175
|
+
ECONNREFUSED: "ECONNREFUSED",
|
|
2176
|
+
ENOTFOUND: "ENOTFOUND"
|
|
2177
|
+
};
|
|
2178
|
+
var DEFAULT_ERROR_RESPONSE = {
|
|
2179
|
+
displayMessage: "An unknown error occurred",
|
|
2180
|
+
code: ERROR_CODES.UNKNOWN_ERROR
|
|
2181
|
+
};
|
|
2182
|
+
var formatHostInfo = (error) => {
|
|
2183
|
+
if (error instanceof Error) {
|
|
2184
|
+
if ("hostname" in error) {
|
|
2185
|
+
return `(${error.hostname})`;
|
|
2186
|
+
}
|
|
2187
|
+
if ("address" in error && "port" in error) {
|
|
2188
|
+
return `(${error.address}:${error.port})`;
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
return void 0;
|
|
2192
|
+
};
|
|
2193
|
+
var handleError = (error) => {
|
|
2194
|
+
if (error instanceof Error) {
|
|
2195
|
+
if (error.message.includes(ERROR_CODES.EBLOB_WRITE_INSUFFICIENT_FUNDS)) {
|
|
2196
|
+
return {
|
|
2197
|
+
displayMessage: "Insufficient Shelby tokens. Please fund your account with Shelby tokens to continue.",
|
|
2198
|
+
code: ERROR_CODES.EBLOB_WRITE_INSUFFICIENT_FUNDS
|
|
2199
|
+
};
|
|
2200
|
+
}
|
|
2201
|
+
if (error.message.includes(ERROR_CODES.EBLOB_WRITE_CHUNKSET_ALREADY_EXISTS)) {
|
|
2202
|
+
return {
|
|
2203
|
+
displayMessage: "The blob already exists on L1.",
|
|
2204
|
+
code: ERROR_CODES.EBLOB_WRITE_CHUNKSET_ALREADY_EXISTS
|
|
2205
|
+
};
|
|
2206
|
+
}
|
|
2207
|
+
if ("code" in error) {
|
|
2208
|
+
if (error.code === ERROR_CODES.ECONNREFUSED) {
|
|
2209
|
+
return {
|
|
2210
|
+
displayMessage: `Could not connect to the Shelby RPC endpoint. Please check that the endpoint you are using is correct ${formatHostInfo(error) ?? ""}.`,
|
|
2211
|
+
code: ERROR_CODES.ECONNREFUSED
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
if (error.code === ERROR_CODES.ENOTFOUND) {
|
|
2215
|
+
return {
|
|
2216
|
+
displayMessage: `Could not connect to the Shelby RPC endpoint. Please check that the endpoint you are using is correct ${formatHostInfo(error) ?? ""}.`,
|
|
2217
|
+
code: ERROR_CODES.ENOTFOUND
|
|
2218
|
+
};
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
if (error.cause instanceof AggregateError) {
|
|
2222
|
+
const firstKnownError = error.cause.errors.find((error2) => {
|
|
2223
|
+
const handledError = handleError(error2);
|
|
2224
|
+
return handledError.code !== ERROR_CODES.UNKNOWN_ERROR;
|
|
2225
|
+
});
|
|
2226
|
+
if (firstKnownError) return handleError(firstKnownError);
|
|
2227
|
+
}
|
|
2228
|
+
if (error.cause instanceof Error) {
|
|
2229
|
+
return handleError(error.cause);
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
return {
|
|
2233
|
+
displayMessage: `An unknown error occurred ${error instanceof Error ? `: ${error.message}` : ""}`,
|
|
2234
|
+
code: ERROR_CODES.UNKNOWN_ERROR
|
|
2235
|
+
};
|
|
2236
|
+
};
|
|
2237
|
+
|
|
2238
|
+
// src/commands/upload.tsx
|
|
2177
2239
|
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
2178
2240
|
var normBlobName2 = (i, f, b) => normBlobName(path4, i, f, b);
|
|
2179
2241
|
var flexibleDateSchema = z9.string().transform((val) => {
|
|
@@ -2374,60 +2436,66 @@ function uploadCommand(program) {
|
|
|
2374
2436
|
let hasUploadedBlob = false;
|
|
2375
2437
|
for (const entry of filelist) {
|
|
2376
2438
|
spinner.text = `Reading ${entry.filename}.. (Overall: ${formatProgressPercent()}%, ${formatProgressRate()} MiB/s)`;
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
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
|
|
2439
|
+
try {
|
|
2440
|
+
const blobData = await fs3.readFile(entry.filename);
|
|
2441
|
+
if (blobData.length !== entry.sizeBytes) {
|
|
2442
|
+
throw new Error(
|
|
2443
|
+
`Size of file ${entry.filename} changed after initial scan. Original size was ${entry.sizeBytes} but it is now ${blobData.length}`
|
|
2444
|
+
);
|
|
2445
|
+
}
|
|
2446
|
+
spinner.text = `Committing ${entry.filename} to L1.. (Overall: ${formatProgressPercent()}%, ${formatProgressRate()} MiB/s)`;
|
|
2447
|
+
const existingBlobMetadata = await shelbyBlobClient.getBlobMetadata({
|
|
2448
|
+
account: activeAccount.accountAddress,
|
|
2449
|
+
name: entry.blobname
|
|
2400
2450
|
});
|
|
2401
|
-
|
|
2402
|
-
|
|
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...`
|
|
2451
|
+
const blobCommitments = await generateCommitments(
|
|
2452
|
+
Readable4.from(blobData)
|
|
2414
2453
|
);
|
|
2454
|
+
if (!existingBlobMetadata) {
|
|
2455
|
+
const { transaction: pendingWriteBlobCommitmentsTransaction } = await shelbyBlobClient.writeBlobCommitments({
|
|
2456
|
+
account: activeAccount,
|
|
2457
|
+
blobName: entry.blobname,
|
|
2458
|
+
lifetime: validatedOptions.expiration.getTime() * 1e3,
|
|
2459
|
+
blobCommitments
|
|
2460
|
+
});
|
|
2461
|
+
await aptos.waitForTransaction({
|
|
2462
|
+
transactionHash: pendingWriteBlobCommitmentsTransaction.hash
|
|
2463
|
+
});
|
|
2464
|
+
} else {
|
|
2465
|
+
spinner.text = `Blob ${entry.blobname} already exists on L1, skipping commitments and uploading to Shelby RPC...`;
|
|
2466
|
+
}
|
|
2467
|
+
if (validatedOptions.outputCommitments) {
|
|
2468
|
+
outputCommitments[entry.filename] = blobCommitments;
|
|
2469
|
+
}
|
|
2470
|
+
const existingBlobChunks = await shelbyBlobClient.getBlobChunks({
|
|
2471
|
+
account: activeAccount.accountAddress,
|
|
2472
|
+
name: entry.blobname
|
|
2473
|
+
});
|
|
2474
|
+
if (existingBlobChunks.length === 0) {
|
|
2475
|
+
console.error(
|
|
2476
|
+
`Blob ${entry.blobname} does not exist on L1, an error occurred when uploading commitments...`
|
|
2477
|
+
);
|
|
2478
|
+
process.exit(1);
|
|
2479
|
+
}
|
|
2480
|
+
if (!existingBlobChunks.every(
|
|
2481
|
+
(chunk) => chunk.location.variant === "stored"
|
|
2482
|
+
)) {
|
|
2483
|
+
spinner.text = `Uploading ${entry.filename} to Shelby RPC.. (Overall: ${formatProgressPercent()}%, ${formatProgressRate()} MiB/s)`;
|
|
2484
|
+
await shelbyNodeClient.putBlob(
|
|
2485
|
+
activeAccount.accountAddress,
|
|
2486
|
+
entry.blobname,
|
|
2487
|
+
blobData
|
|
2488
|
+
);
|
|
2489
|
+
hasUploadedBlob = true;
|
|
2490
|
+
} else {
|
|
2491
|
+
spinner.text = "All blob chunks have been stored on L1, skipping upload to Shelby RPC...";
|
|
2492
|
+
}
|
|
2493
|
+
amountUploaded += blobData.length;
|
|
2494
|
+
} catch (error) {
|
|
2495
|
+
const { displayMessage } = handleError(error);
|
|
2496
|
+
spinner.fail(displayMessage);
|
|
2415
2497
|
process.exit(1);
|
|
2416
2498
|
}
|
|
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
2499
|
}
|
|
2432
2500
|
if (validatedOptions.outputCommitments) {
|
|
2433
2501
|
await fs3.writeFile(
|