Skip to content

refactor(parser): drop alloy-ethers-typecast for alloy Provider#511

Merged
thedavidmeister merged 1 commit into
mainfrom
2026-05-22-parser-drop-typecast
May 22, 2026
Merged

refactor(parser): drop alloy-ethers-typecast for alloy Provider#511
thedavidmeister merged 1 commit into
mainfrom
2026-05-22-parser-drop-typecast

Conversation

@thedavidmeister
Copy link
Copy Markdown
Contributor

@thedavidmeister thedavidmeister commented May 22, 2026

Summary

  • `rainlang_parser` no longer depends on the rainlanguage/alloy-ethers-typecast fork (git dep).
  • Public API: `Parser2::parse{,_pragma}{,_text}` now take a generic `P: Provider` instead of `ReadableClient`.
  • Error variants collapse to `Transport(TransportError)` + `AbiDecode(sol_types::Error)`.
  • Tests use `ProviderBuilder::new().connect_mocked_client(asserter)`.
  • Workspace-level `alloy-ethers-typecast` entry removed (only consumer).

Why

The git dep on the rainlanguage typecast fork prevented publishing `rainlang_parser` to crates.io. Drops the dep entirely by inlining the only thing the parser was using it for (an `eth_call` + ABI-decode round-trip).

Tracks #510 (rainlang Rust crate publishing).

Breaking change

Downstream callers — currently raindex — pass an alloy provider instead of `ReadableClient`. Migration is replacing `ReadableClient::new_from_http_urls(rpcs)` with `ProviderBuilder::new().connect_http(url)` (or any other alloy provider).

Test plan

  • CI green.
  • After merge: tag the rainlang Rust crates and publish them.
  • Migrate raindex's parser usage to alloy Provider.

Summary by CodeRabbit

  • Refactor
    • Refactored the on-chain parser to use the alloy library for blockchain interactions, replacing the previous client dependency.
    • Updated parser API methods to accept a generic provider interface, offering greater flexibility for different provider implementations.
    • Improved error handling with native alloy error types for better library compatibility.

Review Change Stack

The rainlang_parser crate carried a git dep on the rainlanguage/alloy-ethers-typecast
fork purely for ReadableClient + ReadContractParametersBuilder. Those wrap a
trivial eth_call + abi_decode_returns pattern that maps onto alloy::providers::Provider
directly.

Replaces ReadableClient parameters on Parser2::parse, parse_pragma, parse_text,
parse_pragma_text with a generic P: Provider bound. Error variants collapse to
Transport + AbiDecode (re-exported alloy types).

Removes the workspace-level alloy-ethers-typecast entry. Tests now build a
mocked provider via ProviderBuilder::new().connect_mocked_client(asserter).

Breaking change for downstream consumers (raindex). Required for publishing
rainlang_parser to crates.io.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@thedavidmeister thedavidmeister self-assigned this May 22, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

This PR replaces the alloy-ethers-typecast dependency with native alloy library integration for the Rainlang v2 parser. Workspace and crate manifests are updated, error types are refactored to use alloy primitives, the Parser2 trait is generalized to accept any Provider implementation via eth_call helper, and all tests are migrated to use ProviderBuilder mocks.

Changes

Alloy Provider Trait Migration

Layer / File(s) Summary
Dependency manifest updates
Cargo.toml, crates/parser/Cargo.toml
Workspace removes alloy-ethers-typecast and parser crate replaces unfeatured alloy with one specifying providers, network, rpc-types-eth features; explicit rainlang_dispair and rainlang_bindings dependencies are added.
Error type refactoring
crates/parser/src/error.rs
ParserError enum replaces alloy-ethers-typecast variants (ReadableClientError, ReadContractParametersBuilderError) with alloy primitives: Transport(TransportError) and AbiDecode(sol_types::Error).
Parser2 trait and eth_call helper
crates/parser/src/v2.rs (lines 3–107)
Parser2 trait methods refactored to accept generic &P: Provider instead of ReadableClient. An eth_call helper performs TransactionRequest calls and handles ABI encoding/decoding via generated SolCall types. Non-wasm and wasm trait variants updated separately.
ParserV2 implementation and tests
crates/parser/src/v2.rs (lines 147–305)
ParserV2 implements Parser2 for both non-wasm and wasm via eth_call routing. Unit tests updated to use ProviderBuilder::new().connect_mocked_client() and pass &provider references; test_parse, test_parse_text, and test_parse_pragma_text all migrated to provider-based mocks.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🐰 Hopping from old clients to new,
The Parser2 trait shines bright and true,
With Provider's grace and eth_call's might,
Rainlang v2 takes Provider's flight! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: removing the alloy-ethers-typecast dependency and migrating to the alloy Provider.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-05-22-parser-drop-typecast

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
crates/parser/src/v2.rs (1)

147-207: 💤 Low value

Consider reducing duplication between wasm and non-wasm impls.

The two Parser2 implementations are nearly identical, differing only in the + Sync bound. A declarative macro could generate both variants from a single definition.

This is optional and can be deferred—the current approach is straightforward and the migration goal is already achieved.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/parser/src/v2.rs` around lines 147 - 207, The two impl blocks for
Parser2 on ParserV2 duplicate parse and parse_pragma, differing only by the
Provider + Sync bound and cfg; extract the shared implementation into a small
declarative macro that emits an impl Parser2 for ParserV2 with a configurable
provider bound and cfg attribute. Create a macro (e.g. impl_parser2!) that takes
the cfg attribute and the provider bound token(s), expands to the impl
containing the existing bodies that call eth_call with parse2Call and
parsePragma1Call and return parse2Return/parsePragma1Return, then invoke that
macro twice: once under #[cfg(not(target_family = "wasm"))] with P: Provider +
Sync and once under #[cfg(target_family = "wasm")] with P: Provider. This
removes duplication while keeping function bodies (parse, parse_pragma) and
symbols (Parser2, ParserV2, eth_call, parse2Call, parsePragma1Call,
parse2Return, parsePragma1Return) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/parser/src/v2.rs`:
- Around line 147-207: The two impl blocks for Parser2 on ParserV2 duplicate
parse and parse_pragma, differing only by the Provider + Sync bound and cfg;
extract the shared implementation into a small declarative macro that emits an
impl Parser2 for ParserV2 with a configurable provider bound and cfg attribute.
Create a macro (e.g. impl_parser2!) that takes the cfg attribute and the
provider bound token(s), expands to the impl containing the existing bodies that
call eth_call with parse2Call and parsePragma1Call and return
parse2Return/parsePragma1Return, then invoke that macro twice: once under
#[cfg(not(target_family = "wasm"))] with P: Provider + Sync and once under
#[cfg(target_family = "wasm")] with P: Provider. This removes duplication while
keeping function bodies (parse, parse_pragma) and symbols (Parser2, ParserV2,
eth_call, parse2Call, parsePragma1Call, parse2Return, parsePragma1Return)
unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 78dc1965-9520-44fe-84aa-cef84be10616

📥 Commits

Reviewing files that changed from the base of the PR and between 40a8f71 and 43e886b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • Cargo.toml
  • crates/parser/Cargo.toml
  • crates/parser/src/error.rs
  • crates/parser/src/v2.rs
💤 Files with no reviewable changes (1)
  • Cargo.toml

@thedavidmeister thedavidmeister merged commit bbd39ea into main May 22, 2026
8 checks passed
@thedavidmeister thedavidmeister deleted the 2026-05-22-parser-drop-typecast branch May 22, 2026 12:14
@github-actions
Copy link
Copy Markdown
Contributor

@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment:

S/M/L PR Classification Guidelines:

This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed.

Small (S)

Characteristics:

  • Simple bug fixes, typos, or minor refactoring
  • Single-purpose changes affecting 1-2 files
  • Documentation updates
  • Configuration tweaks
  • Changes that require minimal context to review

Review Effort: Would have taken 5-10 minutes

Examples:

  • Fix typo in variable name
  • Update README with new instructions
  • Adjust configuration values
  • Simple one-line bug fixes
  • Import statement cleanup

Medium (M)

Characteristics:

  • Feature additions or enhancements
  • Refactoring that touches multiple files but maintains existing behavior
  • Breaking changes with backward compatibility
  • Changes requiring some domain knowledge to review

Review Effort: Would have taken 15-30 minutes

Examples:

  • Add new feature or component
  • Refactor common utility functions
  • Update dependencies with minor breaking changes
  • Add new component with tests
  • Performance optimizations
  • More complex bug fixes

Large (L)

Characteristics:

  • Major feature implementations
  • Breaking changes or API redesigns
  • Complex refactoring across multiple modules
  • New architectural patterns or significant design changes
  • Changes requiring deep context and multiple review rounds

Review Effort: Would have taken 45+ minutes

Examples:

  • Complete new feature with frontend/backend changes
  • Protocol upgrades or breaking changes
  • Major architectural refactoring
  • Framework or technology upgrades

Additional Factors to Consider

When deciding between sizes, also consider:

  • Test coverage impact: More comprehensive test changes lean toward larger classification
  • Risk level: Changes to critical systems bump up a size category
  • Team familiarity: Novel patterns or technologies increase complexity

Notes:

  • the assessment must be for the totality of the PR, that means comparing the base branch to the last commit of the PR
  • the assessment output must be exactly one of: S, M or L (single-line comment) in format of: SIZE={S/M/L}
  • do not include any additional text, only the size classification
  • your assessment comment must not include tips or additional sections
  • do NOT tag me or anyone else on your comment

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Tip

For best results, initiate chat on the files or code changes.

SIZE=M

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