Skip to content

Add decode-events CLI command for processing JSON event files#2103

Closed
findolor wants to merge 2 commits intolocal-db-clifrom
local-db-cli-decode-events
Closed

Add decode-events CLI command for processing JSON event files#2103
findolor wants to merge 2 commits intolocal-db-clifrom
local-db-cli-decode-events

Conversation

@findolor
Copy link
Copy Markdown
Collaborator

@findolor findolor commented Aug 28, 2025

Caution

Chained PR - Do not merge before #2102

Motivation

The CLI needed a way to decode events that have been previously fetched and stored in JSON format. This
functionality allows users to take raw event data and decode it into a more usable format, completing the
workflow of fetching and then processing events locally.

Solution

  • Reads events from a JSON input file
  • Processes the events using the existing decode_events function from rain_orderbook_common::raindex_client
  • Outputs the decoded results to a JSON file (with configurable output filename)
  • Includes comprehensive error handling for file operations and JSON parsing
  • Added appropriate gitignore entries for decoded event output files

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • New Features

    • Introduced a “local-db” CLI with:
      • fetch-events: fetch blockchain events for a contract and save as pretty JSON (auto-resolves latest block if omitted; sensible default output filename).
      • decode-events: decode raw event JSON into human-readable JSON (supports custom or default output file).
    • Clear status messages and robust error handling.
  • Chores

    • Ignore generated event JSON files in the CLI package.
    • Added trailing newline to .env.example.
    • Test configuration updated to run single-threaded for stability.

@findolor findolor self-assigned this Aug 28, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 28, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a new local-db CLI with fetch-events and decode-events commands. Implements a HyperRpcClient and a SqliteWeb client (fetch/decode/insert modules) with schema SQL. Wires modules into crates, updates Cargo deps, ignores generated files, and tweaks testing/threading and .env newline.

Changes

Cohort / File(s) Summary of changes
Build/Test Config
/.cargo/config.toml
Adds env RUST_TEST_THREADS="1" for wasm32-unknown-unknown target.
Env Sample
/.env.example
Adds trailing newline.
CLI housekeeping
/crates/cli/.gitignore
Ignores local_db event JSON outputs.
CLI dependencies
/crates/cli/Cargo.toml
Adds async-trait and serde_json to dependencies; moves serde_json from dev-dependencies.
CLI commands: local-db (fetch/decode)
/crates/cli/src/commands/local_db/decode_events.rs, /crates/cli/src/commands/local_db/fetch_events.rs
Introduces DecodeEvents command to decode events JSON; introduces FetchEvents command with EventClient trait and SqliteWeb implementation for fetching events. Includes tests.
CLI module wiring
/crates/cli/src/commands/local_db/mod.rs, /crates/cli/src/commands/mod.rs, /crates/cli/src/lib.rs
Exposes local_db module; adds LocalDb subcommand to top-level Orderbook CLI and dispatch logic; re-exports DecodeEvents and FetchEvents.
Common: hyper RPC client
/crates/common/src/hyper_rpc.rs, /crates/common/src/lib.rs
Adds HyperRpcClient with JSON-RPC methods and HyperRpcError; exposes module publicly. Includes tests (non-wasm).
Common: raindex_client surface
/crates/common/src/raindex_client/mod.rs
Adds public sqlite_web submodule.
SqliteWeb client: decode/fetch/insert and types
/crates/common/src/raindex_client/sqlite_web/mod.rs, /crates/common/src/raindex_client/sqlite_web/decode.rs, /crates/common/src/raindex_client/sqlite_web/fetch.rs, /crates/common/src/raindex_client/sqlite_web/insert.rs
Introduces SqliteWeb wrapper over HyperRpcClient with SqliteWebError; adds FetchConfig and event fetching with retries/concurrency; adds event decoding; adds decoded-events to SQL conversion. Includes tests.
SQLite schema
/crates/common/src/raindex_client/sqlite_web/sql/tables.sql
Adds schema for deposits, withdrawals, order events/IOs, take orders, clear/after_clear/meta events, indexes, and FKs.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant CLI as CLI LocalDb
  participant FE as FetchEvents
  participant SW as SqliteWeb
  participant HRPC as HyperRpcClient
  participant RPC as JSON-RPC Endpoint

  User->>CLI: orderbook local-db fetch-events ...
  CLI->>FE: execute()
  FE->>SW: fetch_events(start,end?,address)
  alt end_block not provided
    SW->>HRPC: get_latest_block_number()
    HRPC->>RPC: eth_blockNumber
    RPC-->>HRPC: hex blockNumber
    HRPC-->>SW: latest block (u64)
  end
  loop chunks
    SW->>HRPC: get_logs(range,address,topics)
    HRPC->>RPC: eth_getLogs
    RPC-->>HRPC: logs JSON
    HRPC-->>SW: logs text
  end
  SW-->>FE: aggregated events JSON
  FE-->>CLI: write events_{{end}}.json
  CLI-->>User: Done
  note over SW,HRPC: Retries and concurrency per FetchConfig
Loading
sequenceDiagram
  autonumber
  actor User
  participant CLI as CLI LocalDb
  participant DE as DecodeEvents
  participant DEC as sqlite_web::decode

  User->>CLI: orderbook local-db decode-events --input-file ...
  CLI->>DE: execute()
  DE->>DEC: decode_events(Value::Array)
  DEC-->>DE: decoded JSON (structured)
  DE-->>CLI: write decoded_events.json
  CLI-->>User: Done
  note over DEC: Maps topics to event types and decodes ABI data
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

rust

Suggested reviewers

  • 0xgleb
  • hardyjosh

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0b895e7 and 1051761.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (17)
  • .cargo/config.toml (1 hunks)
  • .env.example (1 hunks)
  • crates/cli/.gitignore (1 hunks)
  • crates/cli/Cargo.toml (2 hunks)
  • crates/cli/src/commands/local_db/decode_events.rs (1 hunks)
  • crates/cli/src/commands/local_db/fetch_events.rs (1 hunks)
  • crates/cli/src/commands/local_db/mod.rs (1 hunks)
  • crates/cli/src/commands/mod.rs (1 hunks)
  • crates/cli/src/lib.rs (3 hunks)
  • crates/common/src/hyper_rpc.rs (1 hunks)
  • crates/common/src/lib.rs (1 hunks)
  • crates/common/src/raindex_client/mod.rs (1 hunks)
  • crates/common/src/raindex_client/sqlite_web/decode.rs (1 hunks)
  • crates/common/src/raindex_client/sqlite_web/fetch.rs (1 hunks)
  • crates/common/src/raindex_client/sqlite_web/insert.rs (1 hunks)
  • crates/common/src/raindex_client/sqlite_web/mod.rs (1 hunks)
  • crates/common/src/raindex_client/sqlite_web/sql/tables.sql (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch local-db-cli-decode-events

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@findolor findolor changed the base branch from main to local-db-cli August 28, 2025 12:06
@findolor findolor closed this Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant