@net-protocol/cli 0.1.17 → 0.1.18
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/index.mjs +32 -13
- package/dist/cli/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/cli/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { createRequire } from 'module';
|
|
|
6
6
|
import chalk4 from 'chalk';
|
|
7
7
|
import * as fs4 from 'fs';
|
|
8
8
|
import { readFileSync } from 'fs';
|
|
9
|
-
import { StorageClient, detectFileTypeFromBase64, base64ToDataUri, shouldSuggestXmlStorage, getStorageKeyBytes, encodeStorageKeyForUrl, chunkDataForStorage, CHUNKED_STORAGE_CONTRACT, STORAGE_CONTRACT as STORAGE_CONTRACT$1 } from '@net-protocol/storage';
|
|
9
|
+
import { OPTIMAL_CHUNK_SIZE, StorageClient, detectFileTypeFromBase64, base64ToDataUri, shouldSuggestXmlStorage, getStorageKeyBytes, encodeStorageKeyForUrl, chunkDataForStorage, CHUNKED_STORAGE_CONTRACT, STORAGE_CONTRACT as STORAGE_CONTRACT$1 } from '@net-protocol/storage';
|
|
10
10
|
import { stringToHex, createWalletClient, http, hexToString, parseEther, encodeFunctionData, publicActions, defineChain } from 'viem';
|
|
11
11
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
12
12
|
import { getNetContract, getChainName, getPublicClient, getChainRpcUrls, NetClient, toBytes32, NULL_ADDRESS } from '@net-protocol/core';
|
|
@@ -264,7 +264,7 @@ function prepareNormalStorageTransaction(storageClient, args, originalStorageKey
|
|
|
264
264
|
};
|
|
265
265
|
}
|
|
266
266
|
function prepareXmlStorageTransactions(params) {
|
|
267
|
-
const { storageClient, storageKey, text, content, operatorAddress } = params;
|
|
267
|
+
const { storageClient, storageKey, text, content, operatorAddress, chunkSize } = params;
|
|
268
268
|
const storageKeyBytes = getStorageKeyBytes(storageKey);
|
|
269
269
|
const result = storageClient.prepareXmlStorage({
|
|
270
270
|
data: content,
|
|
@@ -272,8 +272,9 @@ function prepareXmlStorageTransactions(params) {
|
|
|
272
272
|
storageKey,
|
|
273
273
|
// Pass as string, not bytes32
|
|
274
274
|
filename: text,
|
|
275
|
-
useChunkedStorageBackend: true
|
|
275
|
+
useChunkedStorageBackend: true,
|
|
276
276
|
// Use ChunkedStorage backend (default)
|
|
277
|
+
chunkSize
|
|
277
278
|
});
|
|
278
279
|
const transactions = result.transactionConfigs.map(
|
|
279
280
|
(tx, index) => {
|
|
@@ -550,7 +551,8 @@ async function uploadFile(options) {
|
|
|
550
551
|
storageKey: options.storageKey,
|
|
551
552
|
text: options.text,
|
|
552
553
|
content: fileContent,
|
|
553
|
-
operatorAddress
|
|
554
|
+
operatorAddress,
|
|
555
|
+
chunkSize: options.chunkSize
|
|
554
556
|
});
|
|
555
557
|
} else {
|
|
556
558
|
const storageKeyBytes = getStorageKeyBytes(
|
|
@@ -791,7 +793,8 @@ async function uploadFileWithRelay(options) {
|
|
|
791
793
|
operatorAddress: backendWalletAddress,
|
|
792
794
|
storageKey: options.storageKey,
|
|
793
795
|
filename: options.text,
|
|
794
|
-
useChunkedStorageBackend: true
|
|
796
|
+
useChunkedStorageBackend: true,
|
|
797
|
+
chunkSize: options.chunkSize
|
|
795
798
|
});
|
|
796
799
|
const chunkTxs = chunkPrepareResult.transactionConfigs.slice(1);
|
|
797
800
|
const topLevelHash = chunkPrepareResult.topLevelHash;
|
|
@@ -999,7 +1002,8 @@ async function previewFile(options) {
|
|
|
999
1002
|
storageKey: options.storageKey,
|
|
1000
1003
|
text: options.text,
|
|
1001
1004
|
content: fileContent,
|
|
1002
|
-
operatorAddress
|
|
1005
|
+
operatorAddress,
|
|
1006
|
+
chunkSize: options.chunkSize
|
|
1003
1007
|
});
|
|
1004
1008
|
} else {
|
|
1005
1009
|
const storageKeyBytes = getStorageKeyBytes(
|
|
@@ -1260,7 +1264,8 @@ async function encodeStorageUpload(options) {
|
|
|
1260
1264
|
data: fileContent,
|
|
1261
1265
|
operatorAddress,
|
|
1262
1266
|
storageKey: options.storageKey,
|
|
1263
|
-
filename: options.text
|
|
1267
|
+
filename: options.text,
|
|
1268
|
+
chunkSize: options.chunkSize
|
|
1264
1269
|
});
|
|
1265
1270
|
const encodedTransactions = transactionConfigs.map(
|
|
1266
1271
|
(config) => encodeTransaction(config, readOnlyOptions.chainId)
|
|
@@ -1290,8 +1295,6 @@ async function encodeStorageUpload(options) {
|
|
|
1290
1295
|
};
|
|
1291
1296
|
}
|
|
1292
1297
|
}
|
|
1293
|
-
|
|
1294
|
-
// src/commands/storage/index.ts
|
|
1295
1298
|
function registerStorageCommand(program2) {
|
|
1296
1299
|
const storageCommand = program2.command("storage").description("Storage operations");
|
|
1297
1300
|
const uploadCommand = new Command("upload").description("Upload files to Net Storage").requiredOption("--file <path>", "Path to file to upload").requiredOption("--key <key>", "Storage key (filename/identifier)").requiredOption("--text <text>", "Text description/filename").option(
|
|
@@ -1307,6 +1310,10 @@ function registerStorageCommand(program2) {
|
|
|
1307
1310
|
).option(
|
|
1308
1311
|
"--encode-only",
|
|
1309
1312
|
"Output transaction data as JSON instead of executing"
|
|
1313
|
+
).option(
|
|
1314
|
+
"--chunk-size <bytes>",
|
|
1315
|
+
`Max chunk size in bytes for splitting large files (default: ${OPTIMAL_CHUNK_SIZE})`,
|
|
1316
|
+
(value) => parseInt(value, 10)
|
|
1310
1317
|
).action(async (options) => {
|
|
1311
1318
|
if (options.encodeOnly) {
|
|
1312
1319
|
try {
|
|
@@ -1316,7 +1323,8 @@ function registerStorageCommand(program2) {
|
|
|
1316
1323
|
text: options.text,
|
|
1317
1324
|
privateKey: options.privateKey,
|
|
1318
1325
|
chainId: options.chainId,
|
|
1319
|
-
rpcUrl: options.rpcUrl
|
|
1326
|
+
rpcUrl: options.rpcUrl,
|
|
1327
|
+
chunkSize: options.chunkSize
|
|
1320
1328
|
});
|
|
1321
1329
|
console.log(JSON.stringify(result, null, 2));
|
|
1322
1330
|
process.exit(0);
|
|
@@ -1345,7 +1353,8 @@ function registerStorageCommand(program2) {
|
|
|
1345
1353
|
text: options.text,
|
|
1346
1354
|
privateKey: commonOptions.privateKey,
|
|
1347
1355
|
chainId: commonOptions.chainId,
|
|
1348
|
-
rpcUrl: commonOptions.rpcUrl
|
|
1356
|
+
rpcUrl: commonOptions.rpcUrl,
|
|
1357
|
+
chunkSize: options.chunkSize
|
|
1349
1358
|
};
|
|
1350
1359
|
try {
|
|
1351
1360
|
console.log(chalk4.blue(`\u{1F4C1} Reading file: ${options.file}`));
|
|
@@ -1410,6 +1419,10 @@ function registerStorageCommand(program2) {
|
|
|
1410
1419
|
).option(
|
|
1411
1420
|
"--rpc-url <url>",
|
|
1412
1421
|
"Custom RPC URL (can also be set via NET_RPC_URL env var)"
|
|
1422
|
+
).option(
|
|
1423
|
+
"--chunk-size <bytes>",
|
|
1424
|
+
`Max chunk size in bytes for splitting large files (default: ${OPTIMAL_CHUNK_SIZE})`,
|
|
1425
|
+
(value) => parseInt(value, 10)
|
|
1413
1426
|
).action(async (options) => {
|
|
1414
1427
|
const commonOptions = parseCommonOptions({
|
|
1415
1428
|
privateKey: options.privateKey,
|
|
@@ -1422,7 +1435,8 @@ function registerStorageCommand(program2) {
|
|
|
1422
1435
|
text: options.text,
|
|
1423
1436
|
privateKey: commonOptions.privateKey,
|
|
1424
1437
|
chainId: commonOptions.chainId,
|
|
1425
|
-
rpcUrl: commonOptions.rpcUrl
|
|
1438
|
+
rpcUrl: commonOptions.rpcUrl,
|
|
1439
|
+
chunkSize: options.chunkSize
|
|
1426
1440
|
};
|
|
1427
1441
|
try {
|
|
1428
1442
|
console.log(chalk4.blue(`\u{1F4C1} Reading file: ${options.file}`));
|
|
@@ -1504,6 +1518,10 @@ function registerStorageCommand(program2) {
|
|
|
1504
1518
|
).option(
|
|
1505
1519
|
"--rpc-url <url>",
|
|
1506
1520
|
"Custom RPC URL (can also be set via NET_RPC_URL env var)"
|
|
1521
|
+
).option(
|
|
1522
|
+
"--chunk-size <bytes>",
|
|
1523
|
+
`Max chunk size in bytes for splitting large files (default: ${OPTIMAL_CHUNK_SIZE})`,
|
|
1524
|
+
(value) => parseInt(value, 10)
|
|
1507
1525
|
).action(async (options) => {
|
|
1508
1526
|
const commonOptions = parseCommonOptions({
|
|
1509
1527
|
privateKey: options.privateKey,
|
|
@@ -1527,7 +1545,8 @@ function registerStorageCommand(program2) {
|
|
|
1527
1545
|
chainId: commonOptions.chainId,
|
|
1528
1546
|
rpcUrl: commonOptions.rpcUrl,
|
|
1529
1547
|
apiUrl: options.apiUrl,
|
|
1530
|
-
secretKey
|
|
1548
|
+
secretKey,
|
|
1549
|
+
chunkSize: options.chunkSize
|
|
1531
1550
|
};
|
|
1532
1551
|
try {
|
|
1533
1552
|
console.log(chalk4.blue(`\u{1F4C1} Reading file: ${options.file}`));
|