Skip to content

[BUG] Storyline indexer missing genesis plot + StorylineCreated ABI incomplete #52

@realproject7

Description

@realproject7

Bug Description

Two related issues found during code review of PRs #45-#50:

1. StorylineCreated event ABI missing fields (lib/contracts/abi.ts)

The StorylineCreated event is missing openingCID and openingHash fields. Per proposal §4.1, createStoryline() emits these so the indexer can fetch and verify the genesis plot content.

Current:

export const storylineCreatedEvent = {
  inputs: [
    { name: "storylineId", type: "uint256", indexed: true },
    { name: "writer", type: "address", indexed: true },
    { name: "tokenAddress", type: "address", indexed: false },
    { name: "title", type: "string", indexed: false },
    { name: "hasDeadline", type: "bool", indexed: false },
  ],
} as const;

Expected — add these two fields:

{ name: "openingCID", type: "string", indexed: false },
{ name: "openingHash", type: "bytes32", indexed: false },

2. Storyline indexer does not store genesis plot (src/app/api/index/storyline/route.ts)

The storyline indexer creates a storylines row with plot_count: 1 but never inserts a row into the plots table for the opening chapter (plot_index = 0). This means readers cannot see the genesis plot.

Fix: After creating the storyline record, the indexer must:

  1. Read openingCID and openingHash from the decoded event (requires ABI fix above)
  2. Fetch content from IPFS via https://<bucket>.s3.filebase.com/plotlink/<openingCID>
  3. Fall back to request body content field if IPFS fetch fails
  4. Verify keccak256(toHex(content)) === openingHash
  5. Insert into plots table with plot_index: 0, storyline_id, writer_address, content, content_cid: openingCID, content_hash: openingHash

Reference the existing plot indexer (src/app/api/index/plot/route.ts) for the IPFS fetch + hash verify + Supabase upsert pattern.

3. createStoryline function ABI may also need openingCID and openingHash params

Check lib/contracts/abi.ts — if the createStoryline function ABI is also missing these input params, add them to match proposal §4.1.

Acceptance Criteria

  • storylineCreatedEvent in lib/contracts/abi.ts includes openingCID (string) and openingHash (bytes32)
  • createStoryline function ABI in lib/contracts/abi.ts includes openingCID and openingHash params if missing
  • Storyline indexer inserts a plots row for the genesis plot (plot_index = 0)
  • Genesis plot content is fetched from IPFS, verified against hash, stored in content column
  • Falls back to request body if IPFS fetch fails (same pattern as plot indexer)
  • npm run lint and npm run typecheck pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions