feat: async client + async tool variants (AsyncRustChainClient) — #1 Task 2 - #3
Conversation
jaxint
left a comment
There was a problem hiding this comment.
感谢您的贡献!代码审查完成。
钱包地址: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG
Automated review by RustChain bounty participant.
jaxint
left a comment
There was a problem hiding this comment.
PR Review Summary
Thank you for this contribution to the RustChain ecosystem!
Quick Review
- ✅ PR title is clear and descriptive
- ✅ Changes align with project goals
- ✅ Appreciate the effort in improving the codebase
Wallet for RTC Reward
AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG
Automated review by RustChain bounty hunter
|
Consolidated change-request for this stack is on #2 (#2 (comment)) — it covers the async-extra packaging, bounty-shape consistency, and reward parsing across #2/#3/#4. Addressing those there unblocks all three. Thanks! |
This file implements an asynchronous read-only HTTP client for RustChain's public API using httpx. It provides methods to access various endpoints like network stats, payouts, miners, and bounties, allowing concurrent requests.
Added asynchronous RustChain tools for balance and bounties.
Added AsyncRustChainClient and related async tools to the module.
Added section on async client for concurrent reads with examples.
Added tests for AsyncRustChainClient methods and tools.
…ps, safer parser Addresses the consolidated Codex+Grok review on Scottcjn#2 (blocks Scottcjn#2 -> Scottcjn#3 -> Scottcjn#4): 1. (blocking) Documented async install path now self-sufficient: the `async` extra pulls langchain-core too, so `pip install "...[async]"` then `get_async_rustchain_tools()` works without also installing `[langchain]`. README updated to match. 2. (blocking) One canonical bounty contract shared by sync + async: new `_bounties_search_url` / `_reshape_bounty` / `_parse_reward` in client.py; both `RustChainClient.bounties` and `AsyncRustChainClient.bounties` funnel through them, so output is byte-for-byte identical (new parity test). 3. (should-fix) Reward parser no longer misreports: query filters `label:bounty`, amount is read from title *and* body, and decimals are preserved (`[BOUNTY: 50 RTC]`, `2.5 RTC`) instead of falling back to "see issue". 4. (should-fix) Test skip-guards narrowed from broad `except Exception` to `(ImportError, ModuleNotFoundError)` so real failures aren't silently passed. 5. Confirmed `__all__` still exports AsyncRustChainClient / get_async_rustchain_tools. All 25 tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2b22a2c to
2d84806
Compare
|
Thanks for the detailed consolidated review @Scottcjn — that was very clear. I pushed a commit to this branch (#3) that addresses the stack-wide blockers; since they centre on the async packaging + bounty contract, fixing them here is the right home and #4 will rebase cleanly on top. Blocking
Should-fix All 25 tests pass locally. Re #5-vs-#6 demo: agreed, keep #5 (the |
Implements Task 2 — Async client (8 RTC) from #1.
Adds an async (httpx) twin of the read-only client plus matching async tools, so an agent can fan out several RustChain reads concurrently instead of blocking on each request.
What's added
AsyncRustChainClient(rustchain_langchain/async_client.py) — mirrorsRustChainClientmethod-for-method (network_stats,payouts,metrics,miners,health,balance,epoch,bounties), every call a coroutine backed byhttpx.AsyncClient. Returns the exact same shapes, so the existing framework-freesummarize_*helpers consume its output unchanged.get_async_rustchain_tools()— the same 7 LangChain tools (same names, descriptions andargs_schemaforrustchain_balance/rustchain_bounties), but each tool's_arunawaits the async client._runbridges to the coroutine for sync callers when no event loop is already running.Safety contract kept
httpxis imported lazily in the request path, so the sync client andsummarize_*helpers keep working without it installed. Added as an optionalasyncextra (and totest).Tests
pytest -q→ 23 passed (10 new). HTTP is fully mocked (httpx.AsyncClientmonkeypatched), coroutines driven withasyncio.run— no network, no pytest-asyncio needed. New tests cover URL/param building, thebalanceminer_id pass-through, thebountiesreshape, concurrentasyncio.gatherfan-out, async tool_arunsuccess + never-raise, the sync bridge, and sync/async tool-name parity.Live-smoke-tested against rustchain.org too: 3 concurrent reads in ~0.5s, all summaries correct.
/claim #1