• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 12304263166

12 Dec 2024 08:28PM UTC coverage: 46.87%. First build
12304263166

Pull #10167

github

web-flow
Merge 8892fe0b8 into 807071c54
Pull Request #10167: Farcaster weighted voting

1192 of 2847 branches covered (41.87%)

Branch coverage included in aggregate %.

4 of 59 new or added lines in 5 files covered. (6.78%)

2447 of 4917 relevant lines covered (49.77%)

30.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

5.88
/libs/model/src/contest/FarcasterUpvoteAction.command.ts
1
import { logger, type Command } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { NeynarAPIClient } from '@neynar/nodejs-sdk';
4
import { config } from '../config';
5
import { models } from '../database';
6
import { mustExist } from '../middleware/guards';
7
import { buildFarcasterContentUrl, emitEvent } from '../utils';
8

9
const log = logger(import.meta);
26✔
10

11
// This webhook processes the cast action event
12
export function FarcasterUpvoteAction(): Command<
13
  typeof schemas.FarcasterUpvoteAction
14
> {
15
  return {
×
16
    ...schemas.FarcasterUpvoteAction,
17
    auth: [],
18
    body: async ({ payload }) => {
19
      const client = new NeynarAPIClient(config.CONTESTS.NEYNAR_API_KEY!);
×
20
      // get user verified address
NEW
21
      const { users } = await client.fetchBulkUsers([
×
22
        payload.untrustedData.fid,
23
      ]);
NEW
24
      const verified_address = users[0].verified_addresses.eth_addresses.at(0);
×
NEW
25
      if (!verified_address) {
×
NEW
26
        log.warn(
×
27
          'Farcaster verified address not found for upvote action- upvote will be ignored.',
28
        );
NEW
29
        return;
×
30
      }
31

32
      const castsResponse = await client.fetchBulkCasts([
×
33
        payload.untrustedData.castId.hash,
34
      ]);
35
      const { parent_hash, hash } = castsResponse.result.casts.at(0)!;
×
36
      const content_url = buildFarcasterContentUrl(parent_hash!, hash);
×
37

38
      // find content from farcaster hash
39
      const addAction = await models.ContestAction.findOne({
×
40
        where: {
41
          action: 'added',
42
          content_url,
43
        },
44
      });
45
      mustExist(`Contest Action (${content_url})`, addAction);
×
46

47
      await emitEvent(
×
48
        models.Outbox,
49
        [
50
          {
51
            event_name: schemas.EventNames.FarcasterVoteCreated,
52
            event_payload: {
53
              ...payload,
54
              contest_address: addAction.contest_address,
55
              verified_address,
56
            },
57
          },
58
        ],
59
        null,
60
      );
61

62
      return {
×
63
        message: 'Vote Added',
64
      };
65
    },
66
  };
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc