@net-protocol/cli 0.1.40 → 0.1.42

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.
@@ -60,9 +60,14 @@ declare function registerAgentRegisterCommand(parent: Command): void;
60
60
  */
61
61
  declare function registerListAgentsCommand(parent: Command, commandName?: string): void;
62
62
 
63
+ /**
64
+ * Register the feed verify-claim subcommand
65
+ */
66
+ declare function registerFeedVerifyClaimCommand(parent: Command): void;
67
+
63
68
  /**
64
69
  * Register the feed command group with the commander program
65
70
  */
66
71
  declare function registerFeedCommand(program: Command): void;
67
72
 
68
- export { registerAgentRegisterCommand, registerFeedCommand, registerFeedCommentReadCommand, registerFeedCommentWriteCommand, registerFeedConfigCommand, registerFeedHistoryCommand, registerFeedListCommand, registerFeedPostCommand, registerFeedPostsCommand, registerFeedReadCommand, registerFeedRegisterCommand, registerFeedRepliesCommand, registerListAgentsCommand };
73
+ export { registerAgentRegisterCommand, registerFeedCommand, registerFeedCommentReadCommand, registerFeedCommentWriteCommand, registerFeedConfigCommand, registerFeedHistoryCommand, registerFeedListCommand, registerFeedPostCommand, registerFeedPostsCommand, registerFeedReadCommand, registerFeedRegisterCommand, registerFeedRepliesCommand, registerFeedVerifyClaimCommand, registerListAgentsCommand };
@@ -1,12 +1,12 @@
1
1
  import chalk12 from 'chalk';
2
- import { FeedRegistryClient, FeedClient, AgentRegistryClient } from '@net-protocol/feeds';
2
+ import { isCommentTopic, parseCommentData, FeedRegistryClient, FeedClient, AgentRegistryClient, COMMENT_TOPIC_SUFFIX, FEED_TOPIC_PREFIX } from '@net-protocol/feeds';
3
3
  import '@net-protocol/chats';
4
- import { NULL_ADDRESS, getBaseDataSuffix, getChainRpcUrls, NetClient } from '@net-protocol/core';
4
+ import { NULL_ADDRESS, getPublicClient, getNetContract, getBaseDataSuffix, getChainRpcUrls, NetClient } from '@net-protocol/core';
5
5
  import '@net-protocol/storage';
6
6
  import * as fs from 'fs';
7
7
  import * as path from 'path';
8
8
  import * as os from 'os';
9
- import { encodeFunctionData, concat, createWalletClient, http } from 'viem';
9
+ import { decodeEventLog, encodeFunctionData, concat, createWalletClient, http } from 'viem';
10
10
  import { privateKeyToAccount } from 'viem/accounts';
11
11
  import * as readline from 'readline';
12
12
 
@@ -656,6 +656,9 @@ function registerFeedPostCommand(parent) {
656
656
  }
657
657
 
658
658
  // src/shared/postId.ts
659
+ function createPostId(post) {
660
+ return `${post.sender}:${post.timestamp}`;
661
+ }
659
662
  function parsePostId(postId) {
660
663
  const parts = postId.split(":");
661
664
  if (parts.length !== 2) {
@@ -1480,6 +1483,143 @@ function registerListAgentsCommand(parent, commandName = "list-agents") {
1480
1483
  await executeListAgents(options);
1481
1484
  });
1482
1485
  }
1486
+ function extractFeedName(topic) {
1487
+ const baseTopic = isCommentTopic(topic) ? topic.split(COMMENT_TOPIC_SUFFIX)[0] : topic;
1488
+ return baseTopic.startsWith(FEED_TOPIC_PREFIX) ? baseTopic.slice(FEED_TOPIC_PREFIX.length) : baseTopic;
1489
+ }
1490
+ async function executeFeedVerifyClaim(txHash, options) {
1491
+ if (!txHash.startsWith("0x") || txHash.length !== 66) {
1492
+ exitWithError(
1493
+ "Invalid transaction hash format (must be 0x-prefixed, 66 characters)"
1494
+ );
1495
+ }
1496
+ const readOnlyOptions = parseReadOnlyOptionsWithDefault({
1497
+ chainId: options.chainId,
1498
+ rpcUrl: options.rpcUrl
1499
+ });
1500
+ const publicClient = getPublicClient({
1501
+ chainId: readOnlyOptions.chainId,
1502
+ rpcUrl: readOnlyOptions.rpcUrl
1503
+ });
1504
+ const netContract = getNetContract(readOnlyOptions.chainId);
1505
+ const netClient = createNetClient(readOnlyOptions);
1506
+ const existingHistory = getHistory();
1507
+ if (existingHistory.some((entry) => entry.txHash === txHash)) {
1508
+ console.log(
1509
+ chalk12.yellow("Transaction already recorded in history. Skipping.")
1510
+ );
1511
+ return;
1512
+ }
1513
+ const receipt = await publicClient.getTransactionReceipt({ hash: txHash }).catch(
1514
+ () => exitWithError(
1515
+ "Could not fetch transaction receipt. Make sure the transaction hash is correct and the transaction has been confirmed."
1516
+ )
1517
+ );
1518
+ const contractAddress = netContract.address.toLowerCase();
1519
+ const messageSentEvents = [];
1520
+ for (const log of receipt.logs) {
1521
+ if (log.address.toLowerCase() !== contractAddress) {
1522
+ continue;
1523
+ }
1524
+ try {
1525
+ const decoded = decodeEventLog({
1526
+ abi: netContract.abi,
1527
+ data: log.data,
1528
+ topics: log.topics
1529
+ });
1530
+ if (decoded.eventName === "MessageSent") {
1531
+ const args = decoded.args;
1532
+ messageSentEvents.push({
1533
+ sender: args.sender,
1534
+ messageIndex: args.messageIndex
1535
+ });
1536
+ }
1537
+ } catch {
1538
+ }
1539
+ }
1540
+ if (messageSentEvents.length === 0) {
1541
+ exitWithError(
1542
+ "Transaction does not contain any Net protocol messages."
1543
+ );
1544
+ }
1545
+ console.log(
1546
+ chalk12.blue(
1547
+ `Found ${messageSentEvents.length} message(s) in transaction. Fetching details...`
1548
+ )
1549
+ );
1550
+ const messages = await Promise.all(
1551
+ messageSentEvents.map(
1552
+ (event) => netClient.getMessageAtIndex({
1553
+ messageIndex: Number(event.messageIndex)
1554
+ })
1555
+ )
1556
+ );
1557
+ let recorded = 0;
1558
+ for (let i = 0; i < messages.length; i++) {
1559
+ const message = messages[i];
1560
+ if (!message) {
1561
+ console.log(
1562
+ chalk12.yellow(
1563
+ ` Could not fetch message at index ${messageSentEvents[i].messageIndex}. Skipping.`
1564
+ )
1565
+ );
1566
+ continue;
1567
+ }
1568
+ const feedName = extractFeedName(message.topic);
1569
+ const isComment = isCommentTopic(message.topic);
1570
+ let type;
1571
+ let postId;
1572
+ let label;
1573
+ if (isComment) {
1574
+ type = "comment";
1575
+ const commentData = parseCommentData(message.data);
1576
+ postId = commentData ? `${commentData.parentSender}:${commentData.parentTimestamp}` : void 0;
1577
+ label = `Verified comment:
1578
+ Feed: ${feedName}
1579
+ Sender: ${message.sender}
1580
+ Text: ${message.text}
1581
+ Parent post: ${postId ?? "unknown"}
1582
+ Tx: ${txHash}`;
1583
+ } else {
1584
+ type = "post";
1585
+ postId = createPostId(message);
1586
+ label = `Verified post:
1587
+ Feed: ${feedName}
1588
+ Sender: ${message.sender}
1589
+ Text: ${message.text}
1590
+ Post ID: ${postId}
1591
+ Tx: ${txHash}`;
1592
+ }
1593
+ addHistoryEntry({
1594
+ type,
1595
+ txHash,
1596
+ chainId: readOnlyOptions.chainId,
1597
+ feed: feedName,
1598
+ sender: message.sender,
1599
+ text: message.text,
1600
+ postId
1601
+ });
1602
+ console.log(chalk12.green(` ${label}`));
1603
+ recorded++;
1604
+ }
1605
+ if (recorded > 0) {
1606
+ console.log(
1607
+ chalk12.green(`
1608
+ Successfully recorded ${recorded} history entry(ies).`)
1609
+ );
1610
+ }
1611
+ }
1612
+ function registerFeedVerifyClaimCommand(parent) {
1613
+ parent.command("verify-claim <tx-hash>").description(
1614
+ "Verify a transaction and add it to history. Recovers post/comment details from on-chain data."
1615
+ ).option(
1616
+ "--chain-id <id>",
1617
+ "Chain ID (default: 8453 for Base)",
1618
+ (value) => parseInt(value, 10)
1619
+ ).option("--rpc-url <url>", "Custom RPC URL").action(async (txHash, options) => {
1620
+ await executeFeedVerifyClaim(txHash, options);
1621
+ });
1622
+ }
1483
1623
 
1484
1624
  // src/commands/feed/index.ts
1485
1625
  function registerFeedCommand(program) {
@@ -1496,8 +1636,9 @@ function registerFeedCommand(program) {
1496
1636
  registerFeedHistoryCommand(feedCommand);
1497
1637
  registerAgentRegisterCommand(feedCommand);
1498
1638
  registerListAgentsCommand(feedCommand);
1639
+ registerFeedVerifyClaimCommand(feedCommand);
1499
1640
  }
1500
1641
 
1501
- export { registerAgentRegisterCommand, registerFeedCommand, registerFeedCommentReadCommand, registerFeedCommentWriteCommand, registerFeedConfigCommand, registerFeedHistoryCommand, registerFeedListCommand, registerFeedPostCommand, registerFeedPostsCommand, registerFeedReadCommand, registerFeedRegisterCommand, registerFeedRepliesCommand, registerListAgentsCommand };
1642
+ export { registerAgentRegisterCommand, registerFeedCommand, registerFeedCommentReadCommand, registerFeedCommentWriteCommand, registerFeedConfigCommand, registerFeedHistoryCommand, registerFeedListCommand, registerFeedPostCommand, registerFeedPostsCommand, registerFeedReadCommand, registerFeedRegisterCommand, registerFeedRepliesCommand, registerFeedVerifyClaimCommand, registerListAgentsCommand };
1502
1643
  //# sourceMappingURL=index.mjs.map
1503
1644
  //# sourceMappingURL=index.mjs.map