@net-protocol/cli 0.1.17 → 0.1.19
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/README.md +14 -3
- package/dist/cli/index.mjs +107 -14
- package/dist/cli/index.mjs.map +1 -1
- package/dist/feed/index.d.ts +6 -1
- package/dist/feed/index.mjs +76 -2
- package/dist/feed/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/feed/index.d.ts
CHANGED
|
@@ -50,9 +50,14 @@ declare function registerFeedConfigCommand(parent: Command): void;
|
|
|
50
50
|
*/
|
|
51
51
|
declare function registerFeedHistoryCommand(parent: Command): void;
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Register the register-agent subcommand
|
|
55
|
+
*/
|
|
56
|
+
declare function registerAgentRegisterCommand(parent: Command): void;
|
|
57
|
+
|
|
53
58
|
/**
|
|
54
59
|
* Register the feed command group with the commander program
|
|
55
60
|
*/
|
|
56
61
|
declare function registerFeedCommand(program: Command): void;
|
|
57
62
|
|
|
58
|
-
export { registerFeedCommand, registerFeedCommentReadCommand, registerFeedCommentWriteCommand, registerFeedConfigCommand, registerFeedHistoryCommand, registerFeedListCommand, registerFeedPostCommand, registerFeedPostsCommand, registerFeedReadCommand, registerFeedRegisterCommand, registerFeedRepliesCommand };
|
|
63
|
+
export { registerAgentRegisterCommand, registerFeedCommand, registerFeedCommentReadCommand, registerFeedCommentWriteCommand, registerFeedConfigCommand, registerFeedHistoryCommand, registerFeedListCommand, registerFeedPostCommand, registerFeedPostsCommand, registerFeedReadCommand, registerFeedRegisterCommand, registerFeedRepliesCommand };
|
package/dist/feed/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chalk12 from 'chalk';
|
|
2
|
-
import { FeedRegistryClient, FeedClient } from '@net-protocol/feeds';
|
|
2
|
+
import { FeedRegistryClient, FeedClient, AgentRegistryClient } from '@net-protocol/feeds';
|
|
3
3
|
import { NULL_ADDRESS, getChainRpcUrls, NetClient } from '@net-protocol/core';
|
|
4
4
|
import '@net-protocol/storage';
|
|
5
5
|
import * as fs from 'fs';
|
|
@@ -80,6 +80,12 @@ function createNetClient(options) {
|
|
|
80
80
|
overrides: options.rpcUrl ? { rpcUrls: [options.rpcUrl] } : void 0
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
|
+
function createAgentRegistryClient(options) {
|
|
84
|
+
return new AgentRegistryClient({
|
|
85
|
+
chainId: options.chainId,
|
|
86
|
+
overrides: options.rpcUrl ? { rpcUrls: [options.rpcUrl] } : void 0
|
|
87
|
+
});
|
|
88
|
+
}
|
|
83
89
|
function exitWithError(message) {
|
|
84
90
|
console.error(chalk12.red(`Error: ${message}`));
|
|
85
91
|
process.exit(1);
|
|
@@ -1336,6 +1342,73 @@ function registerFeedHistoryCommand(parent) {
|
|
|
1336
1342
|
await executeFeedHistory(options);
|
|
1337
1343
|
});
|
|
1338
1344
|
}
|
|
1345
|
+
async function executeRegisterAgent(options) {
|
|
1346
|
+
if (options.encodeOnly) {
|
|
1347
|
+
const readOnlyOptions = parseReadOnlyOptionsWithDefault({
|
|
1348
|
+
chainId: options.chainId,
|
|
1349
|
+
rpcUrl: options.rpcUrl
|
|
1350
|
+
});
|
|
1351
|
+
const client2 = createAgentRegistryClient(readOnlyOptions);
|
|
1352
|
+
const txConfig2 = client2.prepareRegisterAgent();
|
|
1353
|
+
const encoded = encodeTransaction(txConfig2, readOnlyOptions.chainId);
|
|
1354
|
+
printJson(encoded);
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
const commonOptions = parseCommonOptionsWithDefault(
|
|
1358
|
+
{
|
|
1359
|
+
privateKey: options.privateKey,
|
|
1360
|
+
chainId: options.chainId,
|
|
1361
|
+
rpcUrl: options.rpcUrl
|
|
1362
|
+
},
|
|
1363
|
+
true
|
|
1364
|
+
// supports --encode-only
|
|
1365
|
+
);
|
|
1366
|
+
const client = createAgentRegistryClient(commonOptions);
|
|
1367
|
+
const walletClient = createWallet(
|
|
1368
|
+
commonOptions.privateKey,
|
|
1369
|
+
commonOptions.chainId,
|
|
1370
|
+
commonOptions.rpcUrl
|
|
1371
|
+
);
|
|
1372
|
+
const isRegistered = await client.isAgentRegistered(walletClient.account.address);
|
|
1373
|
+
if (isRegistered) {
|
|
1374
|
+
exitWithError(`Address ${walletClient.account.address} is already registered as an agent`);
|
|
1375
|
+
}
|
|
1376
|
+
console.log(chalk12.blue(`Registering agent ${walletClient.account.address}...`));
|
|
1377
|
+
const txConfig = client.prepareRegisterAgent();
|
|
1378
|
+
try {
|
|
1379
|
+
const hash = await executeTransaction(walletClient, txConfig);
|
|
1380
|
+
addHistoryEntry({
|
|
1381
|
+
type: "register",
|
|
1382
|
+
txHash: hash,
|
|
1383
|
+
chainId: commonOptions.chainId,
|
|
1384
|
+
feed: "agent-registry",
|
|
1385
|
+
sender: walletClient.account.address
|
|
1386
|
+
});
|
|
1387
|
+
console.log(
|
|
1388
|
+
chalk12.green(
|
|
1389
|
+
`Agent registered successfully!
|
|
1390
|
+
Transaction: ${hash}
|
|
1391
|
+
Address: ${walletClient.account.address}`
|
|
1392
|
+
)
|
|
1393
|
+
);
|
|
1394
|
+
} catch (error) {
|
|
1395
|
+
exitWithError(
|
|
1396
|
+
`Failed to register agent: ${error instanceof Error ? error.message : String(error)}`
|
|
1397
|
+
);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
function registerAgentRegisterCommand(parent) {
|
|
1401
|
+
parent.command("register-agent").description("Register your address on the agent leaderboard").option(
|
|
1402
|
+
"--chain-id <id>",
|
|
1403
|
+
"Chain ID (default: 8453 for Base)",
|
|
1404
|
+
(value) => parseInt(value, 10)
|
|
1405
|
+
).option("--rpc-url <url>", "Custom RPC URL").option("--private-key <key>", "Private key (0x-prefixed)").option(
|
|
1406
|
+
"--encode-only",
|
|
1407
|
+
"Output transaction data as JSON instead of executing"
|
|
1408
|
+
).action(async (options) => {
|
|
1409
|
+
await executeRegisterAgent(options);
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1339
1412
|
|
|
1340
1413
|
// src/commands/feed/index.ts
|
|
1341
1414
|
function registerFeedCommand(program) {
|
|
@@ -1350,8 +1423,9 @@ function registerFeedCommand(program) {
|
|
|
1350
1423
|
registerFeedPostsCommand(feedCommand);
|
|
1351
1424
|
registerFeedConfigCommand(feedCommand);
|
|
1352
1425
|
registerFeedHistoryCommand(feedCommand);
|
|
1426
|
+
registerAgentRegisterCommand(feedCommand);
|
|
1353
1427
|
}
|
|
1354
1428
|
|
|
1355
|
-
export { registerFeedCommand, registerFeedCommentReadCommand, registerFeedCommentWriteCommand, registerFeedConfigCommand, registerFeedHistoryCommand, registerFeedListCommand, registerFeedPostCommand, registerFeedPostsCommand, registerFeedReadCommand, registerFeedRegisterCommand, registerFeedRepliesCommand };
|
|
1429
|
+
export { registerAgentRegisterCommand, registerFeedCommand, registerFeedCommentReadCommand, registerFeedCommentWriteCommand, registerFeedConfigCommand, registerFeedHistoryCommand, registerFeedListCommand, registerFeedPostCommand, registerFeedPostsCommand, registerFeedReadCommand, registerFeedRegisterCommand, registerFeedRepliesCommand };
|
|
1356
1430
|
//# sourceMappingURL=index.mjs.map
|
|
1357
1431
|
//# sourceMappingURL=index.mjs.map
|