Conversation
WalkthroughIntroduces a DefaultEventsPipeline adapter and converts LocalDb-bound event fetch/decode APIs into RpcClient-based free functions; many modules and CLI/web bindings switched from LocalDb to RpcClient and new public pipeline/raindex_client free functions. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant SyncRunner
participant EventsPipeline
participant RpcClient
participant RPC as "Remote RPC"
rect rgba(120,200,255,0.08)
SyncRunner->>EventsPipeline: request latest_block / fetch events
EventsPipeline->>RpcClient: get_latest_block / collect_logs(...)
RpcClient->>RPC: HTTP/RPC request(s)
RPC-->>RpcClient: responses (LogEntryResponse / block number)
RpcClient-->>EventsPipeline: aggregated LogEntryResponse
EventsPipeline->>EventsPipeline: decode_events(...)
EventsPipeline-->>SyncRunner: DecodedEventData / latest block
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Areas needing extra attention:
Possibly related issues
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
| transaction_hash: format!( | ||
| "0x{}", | ||
| "aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899" | ||
| ), |
There was a problem hiding this comment.
lol why not
| transaction_hash: format!( | |
| "0x{}", | |
| "aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899" | |
| ), | |
| transaction_hash: "0xaabbccddeeff00112233445566778899aabbccddeeff00112233445566778899".to_string(), |
| transaction_index: "0x0".to_string(), | ||
| block_hash: format!( | ||
| "0x{}", | ||
| "bbccddeeff00112233445566778899aabbccddeeff00112233445566778899aa" |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/webapp/src/lib/services/startLocalDbSync.ts (1)
36-45: Reset sync metadata when no rows are returnedIf
getSyncStatus(queryFn)yields an emptyvalue, we leave whatever was previously indbSyncLastBlock/dbSyncLastSyncTime. After a table clear or a fresh DB, the UI will continue to show the last run’s block/time, which is misleading. Please reset those stores when the result set is empty so the UI reflects the absence of sync progress.- if (!statusResult.error && statusResult.value && statusResult.value.length > 0) { + if (!statusResult.error && statusResult.value && statusResult.value.length > 0) { const latestStatus = statusResult.value[statusResult.value.length - 1]; dbSyncLastBlock.set(latestStatus.last_synced_block?.toString?.() ?? null); const syncTime = latestStatus.updated_at ? new Date(latestStatus.updated_at) : new Date(); dbSyncLastSyncTime.set(syncTime); } else if (statusResult.error) { dbSyncStatus.set( statusResult.error.readableMsg ?? statusResult.error.msg ?? 'Failed to fetch sync status' ); + } else { + dbSyncLastBlock.set(null); + dbSyncLastSyncTime.set(null); }crates/common/src/local_db/sync.rs (1)
70-113: Avoid invalid block ranges when already caught upOnce
last_synced_blockequalslatest_block,start_blockbecomeslatest_block + 1, so the nextfetch_orderbook_eventscall passesfrom > to.collect_logsrightfully rejects that, and every subsequent interval will hitLocalDbError::FetchEventsFailed. Please short-circuit whenstart_block > latest_block(e.g., send a status update and skip the fetch + insert work) so steady-state syncs don’t fail.let start_block = if last_synced_block == 0 { orderbook_cfg.deployment_block } else { last_synced_block.saturating_add(1) }; status.send("Fetching latest onchain events...".to_string())?; + if start_block > latest_block { + status.send("Already synced to the latest block; nothing to do.".to_string())?; + status.send("Database sync complete.".to_string())?; + return Ok(()); + } let events = fetch_orderbook_events( &rpc_client, orderbook_cfg.address, start_block, latest_block, &FetchConfig::default(),
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (18)
crates/cli/src/commands/local_db/sync/cli.rs(1 hunks)crates/cli/src/commands/local_db/sync/data_source.rs(5 hunks)crates/cli/src/commands/local_db/sync/storage.rs(4 hunks)crates/common/src/local_db/fetch.rs(14 hunks)crates/common/src/local_db/mod.rs(4 hunks)crates/common/src/local_db/pipeline/adapters/events.rs(1 hunks)crates/common/src/local_db/pipeline/adapters/mod.rs(1 hunks)crates/common/src/local_db/pipeline/mod.rs(2 hunks)crates/common/src/local_db/sync.rs(12 hunks)crates/common/src/raindex_client/local_db/mod.rs(1 hunks)crates/common/src/raindex_client/local_db/query/clear_tables.rs(2 hunks)crates/common/src/raindex_client/local_db/query/fetch_last_synced_block.rs(2 hunks)crates/common/src/raindex_client/orders.rs(3 hunks)crates/common/src/raindex_client/trades.rs(3 hunks)crates/common/src/raindex_client/vaults.rs(4 hunks)crates/common/src/rpc_client.rs(1 hunks)packages/webapp/src/lib/services/startLocalDbSync.ts(9 hunks)packages/webapp/src/routes/db-playground/+page.svelte(3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
crates/*/{src,tests,benches,examples}/**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Rust code must pass clippy with all warnings denied (cargo clippy --workspace --all-targets --all-features -D warnings)
Files:
crates/common/src/local_db/pipeline/mod.rscrates/common/src/rpc_client.rscrates/common/src/local_db/pipeline/adapters/mod.rscrates/common/src/raindex_client/trades.rscrates/common/src/raindex_client/local_db/query/clear_tables.rscrates/common/src/raindex_client/orders.rscrates/cli/src/commands/local_db/sync/storage.rscrates/cli/src/commands/local_db/sync/cli.rscrates/common/src/raindex_client/vaults.rscrates/common/src/local_db/mod.rscrates/common/src/raindex_client/local_db/query/fetch_last_synced_block.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/raindex_client/local_db/mod.rscrates/common/src/local_db/sync.rscrates/common/src/local_db/pipeline/adapters/events.rscrates/common/src/local_db/fetch.rs
crates/**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
Rust code lives in the workspace under crates/* (e.g., cli, common, bindings, js_api, quote, subgraph, settings, math, integration_tests)
Files:
crates/common/src/local_db/pipeline/mod.rscrates/common/src/rpc_client.rscrates/common/src/local_db/pipeline/adapters/mod.rscrates/common/src/raindex_client/trades.rscrates/common/src/raindex_client/local_db/query/clear_tables.rscrates/common/src/raindex_client/orders.rscrates/cli/src/commands/local_db/sync/storage.rscrates/cli/src/commands/local_db/sync/cli.rscrates/common/src/raindex_client/vaults.rscrates/common/src/local_db/mod.rscrates/common/src/raindex_client/local_db/query/fetch_last_synced_block.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/raindex_client/local_db/mod.rscrates/common/src/local_db/sync.rscrates/common/src/local_db/pipeline/adapters/events.rscrates/common/src/local_db/fetch.rs
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/*.rs: Format Rust with nix develop -c cargo fmt --all
Lint Rust with nix develop -c rainix-rs-static (preconfigured flags)
Use snake_case for Rust crates/modules and PascalCase for types
Files:
crates/common/src/local_db/pipeline/mod.rscrates/common/src/rpc_client.rscrates/common/src/local_db/pipeline/adapters/mod.rscrates/common/src/raindex_client/trades.rscrates/common/src/raindex_client/local_db/query/clear_tables.rscrates/common/src/raindex_client/orders.rscrates/cli/src/commands/local_db/sync/storage.rscrates/cli/src/commands/local_db/sync/cli.rscrates/common/src/raindex_client/vaults.rscrates/common/src/local_db/mod.rscrates/common/src/raindex_client/local_db/query/fetch_last_synced_block.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/raindex_client/local_db/mod.rscrates/common/src/local_db/sync.rscrates/common/src/local_db/pipeline/adapters/events.rscrates/common/src/local_db/fetch.rs
packages/webapp/**/*.{svelte,ts}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Webapp must pass Svelte lint/format checks (npm run svelte-lint-format-check -w @rainlanguage/webapp)
Files:
packages/webapp/src/routes/db-playground/+page.sveltepackages/webapp/src/lib/services/startLocalDbSync.ts
packages/{webapp,ui-components}/**/*.{svelte,ts}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
If you modify frontend code, you must include a screenshot of the built webapp reflecting the change
Files:
packages/webapp/src/routes/db-playground/+page.sveltepackages/webapp/src/lib/services/startLocalDbSync.ts
packages/**
📄 CodeRabbit inference engine (AGENTS.md)
JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)
Files:
packages/webapp/src/routes/db-playground/+page.sveltepackages/webapp/src/lib/services/startLocalDbSync.ts
🧠 Learnings (53)
📓 Common learnings
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2123
File: crates/common/src/raindex_client/local_db/mod.rs:23-29
Timestamp: 2025-10-06T11:13:29.956Z
Learning: In `crates/common/src/raindex_client/local_db/mod.rs`, the `Default` implementation for `LocalDb` that creates an RPC client pointing to `http://localhost:4444` is acceptable because the RPC client must be explicitly configured before actual usage in production scenarios.
📚 Learning: 2025-10-18T10:38:41.273Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2237
File: crates/common/src/raindex_client/local_db/sync.rs:79-89
Timestamp: 2025-10-18T10:38:41.273Z
Learning: In `crates/common/src/raindex_client/local_db/sync.rs`, the sync_database method currently only supports indexing a single orderbook per chain ID, which is why `.first()` is used to select the orderbook configuration. Multi-orderbook support per chain ID is planned for future PRs.
Applied to files:
crates/common/src/local_db/pipeline/mod.rscrates/common/src/raindex_client/trades.rspackages/webapp/src/routes/db-playground/+page.sveltecrates/common/src/raindex_client/orders.rscrates/cli/src/commands/local_db/sync/storage.rscrates/cli/src/commands/local_db/sync/cli.rscrates/common/src/raindex_client/vaults.rscrates/common/src/local_db/mod.rscrates/common/src/raindex_client/local_db/query/fetch_last_synced_block.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/raindex_client/local_db/mod.rscrates/common/src/local_db/sync.rscrates/common/src/local_db/fetch.rspackages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-10-14T07:51:55.148Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2202
File: crates/common/src/raindex_client/local_db/sync.rs:33-34
Timestamp: 2025-10-14T07:51:55.148Z
Learning: In `crates/common/src/raindex_client/local_db/sync.rs`, the hard-coded `DEFAULT_SYNC_CHAIN_ID` constant (set to `SUPPORTED_LOCAL_DB_CHAINS[0]`) will be replaced with proper chain ID handling in downstream PRs as part of the multi-network/orderbook implementation.
Applied to files:
crates/common/src/local_db/pipeline/mod.rscrates/common/src/raindex_client/trades.rspackages/webapp/src/routes/db-playground/+page.sveltecrates/common/src/raindex_client/orders.rscrates/cli/src/commands/local_db/sync/storage.rscrates/cli/src/commands/local_db/sync/cli.rscrates/common/src/raindex_client/vaults.rscrates/common/src/local_db/mod.rscrates/common/src/raindex_client/local_db/query/fetch_last_synced_block.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/raindex_client/local_db/mod.rscrates/common/src/local_db/sync.rscrates/common/src/local_db/pipeline/adapters/events.rscrates/common/src/local_db/fetch.rspackages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-10-06T11:13:29.956Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2123
File: crates/common/src/raindex_client/local_db/mod.rs:23-29
Timestamp: 2025-10-06T11:13:29.956Z
Learning: In `crates/common/src/raindex_client/local_db/mod.rs`, the `Default` implementation for `LocalDb` that creates an RPC client pointing to `http://localhost:4444` is acceptable because the RPC client must be explicitly configured before actual usage in production scenarios.
Applied to files:
crates/common/src/local_db/pipeline/mod.rscrates/common/src/rpc_client.rscrates/common/src/raindex_client/trades.rscrates/common/src/raindex_client/orders.rscrates/cli/src/commands/local_db/sync/storage.rscrates/cli/src/commands/local_db/sync/cli.rscrates/common/src/raindex_client/vaults.rscrates/common/src/local_db/mod.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/raindex_client/local_db/mod.rscrates/common/src/local_db/sync.rscrates/common/src/local_db/pipeline/adapters/events.rscrates/common/src/local_db/fetch.rspackages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-10-06T14:41:41.909Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2159
File: crates/cli/src/commands/local_db/sync/runner/mod.rs:52-113
Timestamp: 2025-10-06T14:41:41.909Z
Learning: The local DB sync CLI command (crates/cli/src/commands/local_db/sync/) is designed for CI-only usage, and simple println! statements are preferred over structured logging for status messages.
Applied to files:
crates/common/src/local_db/pipeline/mod.rscrates/common/src/raindex_client/trades.rspackages/webapp/src/routes/db-playground/+page.sveltecrates/cli/src/commands/local_db/sync/storage.rscrates/cli/src/commands/local_db/sync/cli.rscrates/common/src/raindex_client/vaults.rscrates/common/src/local_db/mod.rscrates/common/src/raindex_client/local_db/query/fetch_last_synced_block.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/local_db/sync.rscrates/common/src/local_db/fetch.rspackages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-10-06T11:28:30.692Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2145
File: crates/common/src/raindex_client/local_db/query/fetch_orders/query.sql:6-7
Timestamp: 2025-10-06T11:28:30.692Z
Learning: In `crates/common/src/raindex_client/local_db/query/fetch_orders/query.sql`, the orderbook_address is currently hardcoded to '0x2f209e5b67A33B8fE96E28f24628dF6Da301c8eB' because the system only supports a single orderbook at the moment. Multiorderbook logic is not yet implemented and will be added in the future.
Applied to files:
crates/common/src/local_db/pipeline/mod.rspackages/webapp/src/routes/db-playground/+page.sveltecrates/common/src/raindex_client/orders.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/local_db/sync.rscrates/common/src/local_db/fetch.rs
📚 Learning: 2025-06-17T16:28:19.664Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1903
File: tauri-app/src/routes/orders/[network]-[orderHash]/page.test.ts:68-69
Timestamp: 2025-06-17T16:28:19.664Z
Learning: In the tauri-app test files, the team is comfortable using single URLs in rpcs arrays for test mocks rather than multiple URLs, even when testing multi-RPC functionality. They don't consider this a coverage gap that needs to be addressed.
Applied to files:
crates/common/src/rpc_client.rs
📚 Learning: 2025-10-06T14:13:18.531Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2155
File: crates/common/src/raindex_client/trades.rs:133-152
Timestamp: 2025-10-06T14:13:18.531Z
Learning: In the rain.orderbook codebase, the `page` parameter in `RaindexOrder::get_trades_list` method (in crates/common/src/raindex_client/trades.rs) is kept for backwards compatibility with subgraph logic, but the LocalDb fast-path intentionally returns all trades without implementing pagination.
Applied to files:
crates/common/src/raindex_client/trades.rspackages/webapp/src/routes/db-playground/+page.sveltecrates/common/src/raindex_client/orders.rscrates/common/src/raindex_client/vaults.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/local_db/fetch.rspackages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-10-06T11:44:07.888Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2145
File: crates/common/src/raindex_client/local_db/query/create_tables/query.sql:71-72
Timestamp: 2025-10-06T11:44:07.888Z
Learning: The local DB feature in the rain.orderbook codebase is not live yet (as of PR #2145), so schema migrations for existing databases are not required when modifying table structures in `crates/common/src/raindex_client/local_db/query/create_tables/query.sql`.
Applied to files:
crates/common/src/raindex_client/trades.rspackages/webapp/src/routes/db-playground/+page.sveltecrates/common/src/raindex_client/local_db/query/clear_tables.rscrates/common/src/raindex_client/orders.rscrates/cli/src/commands/local_db/sync/storage.rscrates/common/src/raindex_client/vaults.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/raindex_client/local_db/mod.rscrates/common/src/local_db/sync.rscrates/common/src/local_db/fetch.rspackages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-07-04T10:24:56.163Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1956
File: crates/common/src/raindex_client/trades.rs:215-223
Timestamp: 2025-07-04T10:24:56.163Z
Learning: In the rain.orderbook codebase, the get_trade_count method implementation that fetches all trades to count them is intentionally consistent with previous implementations and not considered a performance issue, as indicated by findolor for the trades counting functionality in crates/common/src/raindex_client/trades.rs.
Applied to files:
crates/common/src/raindex_client/trades.rs
📚 Learning: 2025-10-02T19:17:20.332Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2163
File: crates/common/src/raindex_client/orders.rs:738-741
Timestamp: 2025-10-02T19:17:20.332Z
Learning: In crates/common/src/raindex_client/orders.rs, fetch_dotrain_source() is intentionally called in try_from_sg_order for every order conversion because the dotrain source information is needed immediately. A future optimization with local DB logic is planned to eliminate the network round-trip concern.
Applied to files:
crates/common/src/raindex_client/trades.rscrates/common/src/raindex_client/orders.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/local_db/fetch.rs
📚 Learning: 2025-07-21T16:34:31.193Z
Learnt from: 0xgleb
Repo: rainlanguage/rain.orderbook PR: 1911
File: crates/subgraph/src/types/impls.rs:7-15
Timestamp: 2025-07-21T16:34:31.193Z
Learning: In the rainlanguage/rain.orderbook codebase, user 0xgleb considers breaking changes that remove unsafe default behaviors to be intentional and acceptable. Specifically, the get_decimals() method in crates/subgraph/src/types/impls.rs was intentionally changed to return MissingDecimals error instead of defaulting to 18 decimals, as defaulting to 18 is considered unsafe and should never have been done.
Applied to files:
crates/common/src/raindex_client/trades.rs
📚 Learning: 2025-07-16T10:40:05.717Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2000
File: crates/common/src/raindex_client/vaults.rs:183-183
Timestamp: 2025-07-16T10:40:05.717Z
Learning: In the rainlanguage/rain.orderbook codebase, user findolor considers breaking changes from Option<U256> to U256 for required fields like decimals in RaindexVaultToken to be acceptable and safe, even when they affect multiple usage sites across the codebase.
Applied to files:
crates/common/src/raindex_client/trades.rscrates/common/src/raindex_client/orders.rscrates/common/src/raindex_client/vaults.rscrates/cli/src/commands/local_db/sync/data_source.rs
📚 Learning: 2025-10-06T14:12:05.824Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2155
File: crates/common/src/raindex_client/local_db/query/fetch_order_trades/query.sql:86-108
Timestamp: 2025-10-06T14:12:05.824Z
Learning: CTEs (Common Table Expressions) are not supported in the local DB SQL implementation used in the rain.orderbook codebase.
Applied to files:
crates/common/src/raindex_client/trades.rs
📚 Learning: 2025-10-06T10:23:57.479Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2111
File: packages/webapp/src/routes/db-playground/+page.svelte:149-153
Timestamp: 2025-10-06T10:23:57.479Z
Learning: The db-playground page at packages/webapp/src/routes/db-playground/+page.svelte is used for testing purposes, and production-level concerns (such as invalid RPC tokens) are acceptable in this context.
Applied to files:
packages/webapp/src/routes/db-playground/+page.svelte
📚 Learning: 2025-10-29T13:29:29.578Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2278
File: packages/webapp/src/lib/services/startLocalDbSync.ts:23-29
Timestamp: 2025-10-29T13:29:29.578Z
Learning: In packages/webapp/src/lib/services/startLocalDbSync.ts, the hard-coded default orderbook address '0x2f209e5b67A33B8fE96E28f24628dF6Da301c8eB' is a temporary placeholder that will be removed when new sync logic is introduced in the Raindex client, as documented in the NOTE comment.
Applied to files:
packages/webapp/src/routes/db-playground/+page.sveltepackages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-03-31T10:16:53.544Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1469
File: packages/ui-components/src/__tests__/CodeMirrorDotrain.test.ts:75-98
Timestamp: 2025-03-31T10:16:53.544Z
Learning: In the rainlanguage/rain.orderbook project, direct manipulation of Svelte's internal state (component.$$.ctx) in tests is an acceptable approach for testing component behavior, as demonstrated in the CodeMirrorDotrain tests.
Applied to files:
packages/webapp/src/routes/db-playground/+page.svelte
📚 Learning: 2025-10-19T20:24:08.629Z
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 2246
File: packages/webapp/src/hooks.client.ts:2-2
Timestamp: 2025-10-19T20:24:08.629Z
Learning: In the rain.orderbook repository, the import `rainlanguage/orderbook/esm` in packages/webapp/src/hooks.client.ts is intentional and should not be changed to the root package path, as it's specific to the webapp build configuration.
Applied to files:
packages/webapp/src/routes/db-playground/+page.sveltepackages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-06-07T05:19:04.767Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1872
File: packages/webapp/src/lib/services/handleVaultWithdraw.ts:50-54
Timestamp: 2025-06-07T05:19:04.767Z
Learning: In the rainlanguage/rain.orderbook codebase, the team prefers pragmatic code approaches over strict TypeScript patterns when the current implementation is sufficient for their use case, such as using `if (result.error)` instead of `if ('error' in result)` for discriminated union type checking.
Applied to files:
packages/webapp/src/routes/db-playground/+page.sveltepackages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-08-02T02:34:32.237Z
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2036
File: crates/js_api/src/filters/raindex_filter_store.rs:446-533
Timestamp: 2025-08-02T02:34:32.237Z
Learning: In the rainlanguage/rain.orderbook project's RaindexFilterStore WASM tests (crates/js_api/src/filters/raindex_filter_store.rs), brusherru decided to focus on testing only methods without side effects (that don't use web_sys) due to difficulties with mocking localStorage and window APIs in the WASM test environment. This pragmatic approach tests pure logic separately from browser integration.
Applied to files:
packages/webapp/src/routes/db-playground/+page.sveltecrates/common/src/raindex_client/local_db/query/clear_tables.rscrates/common/src/raindex_client/local_db/mod.rspackages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-08-01T07:44:53.910Z
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2036
File: crates/js_api/src/filters/raindex_filter_store.rs:319-336
Timestamp: 2025-08-01T07:44:53.910Z
Learning: In the rainlanguage/rain.orderbook project's RaindexFilterStore (crates/js_api/src/filters/raindex_filter_store.rs), the team chose a simplified monolithic approach with hard-coded keys and default auto-save behavior over configurable stores. The update_vaults method intentionally auto-saves to both localStorage and URL after each update as the default behavior, following a design evolution from a previous configurable approach.
Applied to files:
packages/webapp/src/routes/db-playground/+page.sveltepackages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-07-31T19:34:11.716Z
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2044
File: crates/common/src/raindex_client/vaults_list.rs:363-423
Timestamp: 2025-07-31T19:34:11.716Z
Learning: In the rainlanguage/rain.orderbook project, for WASM-exposed functionality like VaultsList, the team prefers to keep comprehensive tests in the non-WASM environment due to the complexity of recreating objects like RaindexVaults in WASM. WASM tests focus on basic functionality and error cases since the WASM code reuses the already-tested non-WASM implementation.
Applied to files:
packages/webapp/src/routes/db-playground/+page.sveltecrates/common/src/raindex_client/local_db/mod.rspackages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-10-21T05:15:50.518Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2256
File: crates/common/src/raindex_client/local_db/query/fetch_tables.rs:7-7
Timestamp: 2025-10-21T05:15:50.518Z
Learning: In Rust 2021+ editions, passing a reference to a temporary into an async function within the same expression (e.g., `exec.query_json(&fetch_tables_stmt()).await`) is safe and idiomatic. The temporary lifetime is extended across the await point, so this pattern should not be flagged as an issue.
Applied to files:
crates/common/src/raindex_client/local_db/query/clear_tables.rs
📚 Learning: 2025-08-01T09:07:20.383Z
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2044
File: packages/orderbook/README.md:186-189
Timestamp: 2025-08-01T09:07:20.383Z
Learning: In the rainlanguage/rain.orderbook project, Rust methods on structs like RaindexVaultsList are exported as JavaScript getters in WASM bindings using #[wasm_bindgen(getter)]. This means while the Rust code uses method calls like items(), the JavaScript/WASM API exposes them as property access like .items. The README.md correctly documents the JavaScript API surface, not the Rust implementation details.
Applied to files:
crates/common/src/raindex_client/local_db/query/clear_tables.rscrates/common/src/raindex_client/local_db/query/fetch_last_synced_block.rscrates/common/src/raindex_client/local_db/mod.rs
📚 Learning: 2025-07-04T09:02:57.301Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1956
File: crates/common/src/fuzz/mod.rs:64-64
Timestamp: 2025-07-04T09:02:57.301Z
Learning: In rainlanguage/rain.orderbook, user findolor prefers to limit type consistency changes to only the parts directly related to the current work scope. For example, when updating chain_id fields from u64 to u32 in fuzz-related code, unrelated files like tauri-app wallet commands can remain as u64 if they serve different purposes and aren't part of the current changes.
Applied to files:
crates/common/src/raindex_client/orders.rs
📚 Learning: 2025-06-24T08:46:03.368Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1947
File: crates/common/src/raindex_client/orders.rs:98-125
Timestamp: 2025-06-24T08:46:03.368Z
Learning: In the vault merging logic in crates/common/src/raindex_client/orders.rs, optimization isn't necessary because the maximum list items are usually around 5 items. For such small datasets, the simple three-loop approach is preferred over HashMap-based optimization due to clarity and minimal performance impact.
Applied to files:
crates/common/src/raindex_client/orders.rs
📚 Learning: 2025-10-06T14:39:36.425Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2159
File: crates/cli/src/commands/local_db/sync/cli.rs:37-78
Timestamp: 2025-10-06T14:39:36.425Z
Learning: In the SyncLocalDb CLI command (crates/cli/src/commands/local_db/sync/cli.rs), block range validation (e.g., start_block <= end_block) is handled internally by the sync runner, not at the CLI entry point.
Applied to files:
crates/cli/src/commands/local_db/sync/storage.rscrates/cli/src/commands/local_db/sync/cli.rscrates/common/src/raindex_client/local_db/query/fetch_last_synced_block.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/local_db/sync.rscrates/common/src/local_db/fetch.rs
📚 Learning: 2025-06-17T16:32:04.554Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1903
File: crates/js_api/src/gui/order_operations.rs:124-134
Timestamp: 2025-06-17T16:32:04.554Z
Learning: In the rain.orderbook codebase, RPC lists are typically small (2 items maximum), so performance optimizations around cloning and converting small Vec<Url> collections are generally unnecessary.
Applied to files:
crates/cli/src/commands/local_db/sync/storage.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/local_db/fetch.rs
📚 Learning: 2025-08-26T14:52:37.000Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2099
File: crates/common/src/hyper_rpc.rs:3-7
Timestamp: 2025-08-26T14:52:37.000Z
Learning: In the rain.orderbook codebase, creating new reqwest::Client instances per request in HyperRpcClient is not considered an issue by the maintainers, despite potential performance benefits of client reuse.
Applied to files:
crates/cli/src/commands/local_db/sync/storage.rscrates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/raindex_client/local_db/mod.rscrates/common/src/local_db/fetch.rs
📚 Learning: 2025-10-13T12:57:05.900Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2198
File: crates/common/src/raindex_client/local_db/query/fetch_store_addresses/mod.rs:7-8
Timestamp: 2025-10-13T12:57:05.900Z
Learning: In the rain.orderbook repository, using unqualified serde helper names (e.g., `#[serde(with = "serde_address")]`) that rely on glob imports is acceptable and does not need to be changed to fully qualified paths.
Applied to files:
crates/cli/src/commands/local_db/sync/storage.rscrates/cli/src/commands/local_db/sync/data_source.rs
📚 Learning: 2025-04-07T09:51:52.614Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1483
File: crates/settings/src/remote_tokens.rs:32-57
Timestamp: 2025-04-07T09:51:52.614Z
Learning: The implementation for remote token fetching in `crates/settings/src/remote_tokens.rs` does not include explicit timeouts/retries, as the team considers the current implementation sufficient for now.
Applied to files:
crates/cli/src/commands/local_db/sync/storage.rs
📚 Learning: 2025-07-11T06:40:49.511Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1983
File: crates/js_api/src/gui/mod.rs:964-1199
Timestamp: 2025-07-11T06:40:49.511Z
Learning: In crates/js_api/src/gui/mod.rs tests, findolor prefers to keep large hardcoded YAML strings (like the validation test YAML) inline in the test file rather than extracting them to separate external files for maintainability purposes.
Applied to files:
crates/cli/src/commands/local_db/sync/storage.rs
📚 Learning: 2025-05-16T17:24:34.724Z
Learnt from: 0xgleb
Repo: rainlanguage/rain.orderbook PR: 1844
File: tauri-app/src-tauri/src/commands/wallet.rs:27-28
Timestamp: 2025-05-16T17:24:34.724Z
Learning: In Rust projects, dependencies listed in the [dependencies] section of Cargo.toml are available for both application code and tests. The tokio crate with the "full" feature set includes the "test" feature needed for `#[tokio::test]` to work properly.
Applied to files:
crates/cli/src/commands/local_db/sync/storage.rs
📚 Learning: 2025-07-11T06:41:11.924Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1983
File: crates/js_api/src/gui/deposits.rs:147-156
Timestamp: 2025-07-11T06:41:11.924Z
Learning: In the Rain OrderBook project, token info is already cached in the YAML file which serves as the source of truth, so the `get_token_info()` async method in the GUI SDK retrieves from pre-loaded/parsed data rather than making expensive network calls.
Applied to files:
crates/cli/src/commands/local_db/sync/data_source.rs
📚 Learning: 2025-05-20T10:20:08.206Z
Learnt from: 0xgleb
Repo: rainlanguage/rain.orderbook PR: 1859
File: crates/quote/src/quote_debug.rs:472-492
Timestamp: 2025-05-20T10:20:08.206Z
Learning: In the Rain Orderbook codebase, the `#[tokio::test(flavor = "multi_thread")]` annotation is specifically needed for tests that use `LocalEvm`, not just for consistency across all async tests.
Applied to files:
crates/cli/src/commands/local_db/sync/data_source.rscrates/common/src/local_db/sync.rscrates/common/src/local_db/pipeline/adapters/events.rs
📚 Learning: 2025-05-14T05:51:50.277Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1715
File: crates/js_api/src/common/mod.rs:55-59
Timestamp: 2025-05-14T05:51:50.277Z
Learning: In the Rain Orderbook project, the error handling for WASM exported functions uses WasmEncodedError which includes both the original error message and a human-readable version, making direct modification of the JsValue conversion unnecessary.
Applied to files:
crates/common/src/raindex_client/local_db/mod.rs
📚 Learning: 2025-05-19T13:40:56.080Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1858
File: crates/subgraph/src/orderbook_client/mod.rs:54-58
Timestamp: 2025-05-19T13:40:56.080Z
Learning: The `wasm_bindgen_utils` crate in the Rain Orderbook project handles conditional compilation for `JsValue` and `JsError` internally, allowing `impl From<Error> for JsValue` to work on non-WASM targets without explicit cfg guards.
Applied to files:
crates/common/src/raindex_client/local_db/mod.rs
📚 Learning: 2025-05-14T04:49:14.621Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1710
File: crates/quote/Cargo.toml:30-30
Timestamp: 2025-05-14T04:49:14.621Z
Learning: In the rain.orderbook repository, wasm-bindgen-utils is intentionally used as an unconditional dependency because non-wasm targets (like tests) sometimes need to use it.
Applied to files:
crates/common/src/raindex_client/local_db/mod.rs
📚 Learning: 2025-06-24T13:36:28.797Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1950
File: crates/common/src/raindex_client/orders.rs:301-301
Timestamp: 2025-06-24T13:36:28.797Z
Learning: In the RaindexClient codebase, when Arc::new(RwLock::new(self.clone())) is used (e.g., in get_orders and get_order_by_hash methods), this creates new Arc/RwLock wrappers around a cloned RaindexClient, but the underlying client data is functionally the same. This pattern is used to provide the correct Arc<RwLock<RaindexClient>> type expected by RaindexOrder::try_from_sg_order() method.
Applied to files:
crates/common/src/raindex_client/local_db/mod.rs
📚 Learning: 2025-06-20T07:51:08.790Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1941
File: crates/js_api/src/raindex/vaults.rs:175-181
Timestamp: 2025-06-20T07:51:08.790Z
Learning: In the RaindexClient vault methods, `&self` parameters are intentionally kept for API consistency to make all vault operations instance methods, even when the methods don't use client state. This is a design preference for maintaining a uniform interface.
Applied to files:
crates/common/src/raindex_client/local_db/mod.rs
📚 Learning: 2025-06-17T16:21:24.384Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1903
File: crates/settings/src/yaml/orderbook.rs:371-377
Timestamp: 2025-06-17T16:21:24.384Z
Learning: In crates/settings/src/yaml/orderbook.rs tests, the user findolor considers RPC ordering in Vec<Url> assertions to be intentional and not a test brittleness issue. The ordering of RPCs in tests should be preserved as specified.
Applied to files:
crates/common/src/local_db/pipeline/adapters/events.rscrates/common/src/local_db/fetch.rs
📚 Learning: 2025-06-18T18:24:32.049Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1938
File: crates/settings/src/yaml/orderbook.rs:180-199
Timestamp: 2025-06-18T18:24:32.049Z
Learning: In crates/settings/src/yaml/orderbook.rs, the user prefers to avoid refactoring duplicate search logic between get_orderbook_by_address and get_orderbook_by_network_key when there are only 2 functions, indicating they would consider it if more similar functions are added in the future.
Applied to files:
crates/common/src/local_db/fetch.rs
📚 Learning: 2025-06-30T14:17:16.626Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1926
File: packages/ui-components/src/lib/__mocks__/stores.ts:13-17
Timestamp: 2025-06-30T14:17:16.626Z
Learning: User findolor reports that vi.mock(import('rainlanguage/orderbook'), async (importOriginal) => { ... }) syntax works in their testing environment, despite official Vitest documentation indicating the first argument should be a string. This suggests there may be specific Vitest versions or configurations that support dynamic import() as the first argument to vi.mock().
Applied to files:
packages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-09-02T08:04:44.814Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2117
File: packages/ui-components/src/__tests__/VaultIdInformation.test.ts:9-13
Timestamp: 2025-09-02T08:04:44.814Z
Learning: In packages/ui-components/src/__tests__/VaultIdInformation.test.ts and similar test files in the rain.orderbook project, the passthrough vi.mock('rainlanguage/orderbook', async (importOriginal) => { return { ...(await importOriginal()) }; }); block is required for tests to run properly, even when not overriding any exports. This is needed due to the specific Vitest configuration or test environment setup in the project.
Applied to files:
packages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-06-17T14:55:22.914Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1936
File: packages/ui-components/vite.config.ts:21-23
Timestamp: 2025-06-17T14:55:22.914Z
Learning: In the rain.orderbook project, the Vite configuration uses `'import.meta.vitest': 'undefined'` (as a string) combined with conditional `if (import.meta.vitest)` checks for in-source testing. The mock files are excluded from test execution using `exclude: ['src/lib/__mocks__/**/*.ts']`. This configuration successfully allows dev builds to work without `vi` undefined errors, despite the theoretical expectation that the string "undefined" would be truthy and cause issues.
Applied to files:
packages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-08-14T18:29:32.933Z
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2083
File: packages/ui-components/src/__tests__/VaultsListTable.test.ts:16-19
Timestamp: 2025-08-14T18:29:32.933Z
Learning: In the rain.orderbook project's UI components tests, mocking hooks like useToasts is often required as infrastructure even when not directly asserting on their calls, because components internally depend on these hooks. Removing such mocks would break component rendering in tests and require more complex test setup with providers.
Applied to files:
packages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-06-08T18:43:51.842Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1891
File: packages/webapp/src/routes/deploy/[strategyName]/[deploymentKey]/page.test.ts:66-80
Timestamp: 2025-06-08T18:43:51.842Z
Learning: In the rain.orderbook webapp test files, when mocking objects like the transaction manager, it's acceptable to use simple empty objects with ts-expect-error comments rather than providing complete mock implementations with all properties and methods.
Applied to files:
packages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-04-04T11:25:21.518Z
Learnt from: hardingjam
Repo: rainlanguage/rain.orderbook PR: 1559
File: packages/ui-components/src/__tests__/OrderOrVaultHash.test.ts:94-94
Timestamp: 2025-04-04T11:25:21.518Z
Learning: In the rain.orderbook project, minimal test fixtures are preferred over complete mocks that implement the entire interface. Type casting (e.g., `as unknown as SgVault`) is an acceptable approach to maintain both minimal fixtures and TypeScript type compatibility.
Applied to files:
packages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-04-08T09:18:46.653Z
Learnt from: hardingjam
Repo: rainlanguage/rain.orderbook PR: 1597
File: packages/ui-components/src/__tests__/OrderDetail.test.ts:120-120
Timestamp: 2025-04-08T09:18:46.653Z
Learning: In test files for the Rain Orderbook project, it's acceptable to bypass TypeScript's strict typing using constructs like `as unknown as [Type]` to create simplified mock objects that don't need to implement the entire interface.
Applied to files:
packages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-10-06T08:05:02.438Z
Learnt from: CR
Repo: rainlanguage/rain.orderbook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-06T08:05:02.438Z
Learning: Applies to packages/orderbook/**/*.{test,spec}.{ts,tsx} : Orderbook tests must pass (npm run test -w rainlanguage/orderbook)
Applied to files:
packages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-07-04T09:14:35.748Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1956
File: packages/ui-components/src/__tests__/VaultDetail.test.ts:177-181
Timestamp: 2025-07-04T09:14:35.748Z
Learning: In the rain.orderbook project, maintainer findolor is fine with mutating mock data directly in test files using ts-expect-error comments, preferring this pragmatic approach over immutable patterns like spread operators for test data updates.
Applied to files:
packages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-04-07T08:18:36.473Z
Learnt from: hardingjam
Repo: rainlanguage/rain.orderbook PR: 1565
File: packages/webapp/src/routes/deploy/layout.test.ts:12-29
Timestamp: 2025-04-07T08:18:36.473Z
Learning: In test files for this project, hardingjam prefers to use custom mocks (such as for localStorage) rather than relying on environment-provided implementations, as this allows for spying on individual methods and having precise control over implementation details for more robust testing.
Applied to files:
packages/webapp/src/lib/services/startLocalDbSync.ts
📚 Learning: 2025-07-09T12:35:45.699Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1974
File: packages/ui-components/src/__tests__/DeploymentSteps.test.ts:123-126
Timestamp: 2025-07-09T12:35:45.699Z
Learning: In packages/ui-components/src/__tests__/DeploymentSteps.test.ts, findolor prefers to keep mock initializations (like setSelectToken) in individual test cases rather than consolidating them into shared beforeEach blocks, even when it results in duplication.
Applied to files:
packages/webapp/src/lib/services/startLocalDbSync.ts
🧬 Code graph analysis (13)
crates/common/src/rpc_client.rs (1)
crates/bindings/src/provider.rs (1)
mk_read_provider(24-42)
crates/common/src/raindex_client/trades.rs (2)
crates/common/src/local_db/mod.rs (1)
is_chain_supported_local_db(187-189)crates/common/src/raindex_client/local_db/query/fetch_order_trades.rs (1)
fetch_order_trades(6-15)
crates/common/src/raindex_client/local_db/query/clear_tables.rs (1)
crates/common/src/raindex_client/local_db/mod.rs (1)
from(10-15)
crates/common/src/raindex_client/orders.rs (1)
crates/common/src/local_db/mod.rs (1)
is_chain_supported_local_db(187-189)
crates/cli/src/commands/local_db/sync/storage.rs (2)
crates/common/src/rpc_client.rs (1)
new_with_hyper_rpc(103-111)crates/cli/src/commands/local_db/sync/runner/mod.rs (1)
metadata_rpcs(163-169)
crates/cli/src/commands/local_db/sync/cli.rs (2)
crates/cli/src/commands/local_db/sync/storage.rs (1)
build_local_db_from_network(81-105)crates/cli/src/commands/local_db/sync/runner/mod.rs (1)
new(45-57)
crates/common/src/raindex_client/vaults.rs (1)
crates/common/src/local_db/mod.rs (1)
is_chain_supported_local_db(187-189)
crates/common/src/local_db/mod.rs (4)
crates/common/src/local_db/pipeline/adapters/events.rs (1)
decode(72-77)crates/common/src/local_db/pipeline/mod.rs (1)
decode(205-208)crates/common/src/raindex_client/local_db/mod.rs (1)
from(10-15)crates/common/src/raindex_client/mod.rs (6)
from(241-245)from(323-325)from(329-331)from(335-337)from(456-458)from(462-467)
crates/cli/src/commands/local_db/sync/data_source.rs (4)
crates/common/src/local_db/fetch.rs (2)
fetch_orderbook_events(125-138)fetch_store_events(140-153)crates/common/src/local_db/insert.rs (3)
decoded_events_to_statements(95-154)raw_events_to_statements(156-237)raw_events(168-191)crates/common/src/local_db/token_fetch.rs (1)
fetch_erc20_metadata_concurrent(16-57)crates/common/src/rpc_client.rs (1)
rpc_urls(124-126)
crates/common/src/local_db/sync.rs (3)
crates/common/src/local_db/fetch.rs (3)
fetch_orderbook_events(125-138)fetch_store_events(140-153)new(42-71)crates/common/src/local_db/insert.rs (1)
decoded_events_to_statements(95-154)crates/common/src/rpc_client.rs (1)
new_with_urls(88-101)
crates/common/src/local_db/pipeline/adapters/events.rs (3)
crates/common/src/local_db/pipeline/mod.rs (4)
decode(205-208)latest_block(183-183)fetch_orderbook(186-192)fetch_stores(195-201)crates/common/src/local_db/fetch.rs (2)
fetch_orderbook_events(125-138)fetch_store_events(140-153)crates/common/src/rpc_client.rs (2)
new_with_urls(88-101)new_with_hyper_rpc(103-111)
crates/common/src/local_db/fetch.rs (2)
crates/common/src/retry.rs (1)
retry_with_backoff(31-55)crates/common/src/rpc_client.rs (2)
new_with_urls(88-101)mock(168-176)
packages/webapp/src/lib/services/startLocalDbSync.ts (1)
packages/webapp/src/lib/stores/dbSync.ts (2)
dbSyncStatus(3-3)dbSyncIsActive(6-6)
🔇 Additional comments (19)
crates/common/src/raindex_client/local_db/query/fetch_last_synced_block.rs (1)
14-27: LGTM! Clean refactoring to a standalone exported function.The implementation correctly wraps the existing helper with WASM bindings, follows idiomatic error handling patterns, and maintains proper naming conventions for both Rust and JavaScript APIs.
crates/common/src/rpc_client.rs (1)
167-176: LGTM! Well-structured test utility.The mock constructor is properly scoped with
cfg(all(test, not(target_family = "wasm")))andpub(crate)visibility, follows the same pattern as the existingupdate_rpc_urlstest helper, and has no impact on production code paths.crates/common/src/raindex_client/local_db/mod.rs (1)
1-16: LGTM! Clean refactoring toward RpcClient-based flows.The removal of the wasm-exported
get_local_db_clientconstructor and associated imports simplifies the module surface while properly retaining the error conversion implementation. This aligns well with the broader PR objective of migrating from LocalDb-centric to RpcClient-centric patterns.crates/common/src/local_db/pipeline/adapters/mod.rs (1)
1-1: LGTM! Proper module organization.Clean public exposure of the events submodule as part of the adapters surface area.
crates/common/src/raindex_client/trades.rs (1)
3-4: LGTM! Consistent migration to centralized chain support checks.The replacement of
LocalDb::check_support(chain_id)withis_chain_supported_local_db(chain_id)in bothget_trades_listandget_trade_countcentralizes chain support logic and eliminates direct LocalDb coupling. The free function approach is cleaner and aligns with the broader RpcClient-based refactoring across the PR.Also applies to: 135-135, 247-247
crates/common/src/raindex_client/orders.rs (1)
3-3: LGTM! Consistent chain support check migration.The replacement of
LocalDb::check_supportwithis_chain_supported_local_dbin bothget_orders(partition logic) andget_order_by_hash(conditional branch) maintains consistency with the same refactoring pattern applied intrades.rs. This centralizes chain support validation and removes direct LocalDb dependencies.Also applies to: 520-520, 699-699
crates/common/src/local_db/pipeline/mod.rs (1)
10-10: LGTM! Proper public API surface.The addition of
pub mod adapters;appropriately exposes the adapters module as the public entry point for pipeline-related functionality, including the new EventsPipeline implementations. Clean modular design that supports the RpcClient-based refactoring.crates/common/src/raindex_client/vaults.rs (1)
3-3: LGTM! Consistent migration to free function.The replacement of
LocalDb::check_support(chain_id)withis_chain_supported_local_db(chain_id)at all three call sites is consistent with the broader architectural shift away from LocalDb. The semantics remain identical—both check if the chain is in the supported list.Also applies to: 310-310, 1105-1105, 1336-1336
crates/common/src/raindex_client/local_db/query/clear_tables.rs (1)
13-21: LGTM! Clean refactor to free function.The conversion of
clear_tables_wasmfrom a LocalDb method to a standalone free function maintains the same behavior while removing the LocalDb dependency. The function properly creates a JsCallbackExecutor and delegates to the existingclear_tablesimplementation with appropriate error mapping.crates/cli/src/commands/local_db/sync/cli.rs (1)
65-68: LGTM! Type parameter updated consistently.The change from
local_dbtorpc_clientis a straightforward type parameter update that aligns with the broader migration from LocalDb to RpcClient. The call toSyncRunner::newcorrectly passes the newrpc_clientreference.packages/webapp/src/routes/db-playground/+page.svelte (1)
7-7: LGTM! Clean migration to public API.The change from using a
localDbClientinstance to directly calling free functions (getSyncStatus(queryFn)andclearTables(queryFn)) is a clean refactor. The error handling pattern (result.error/result.value) remains unchanged, and thequeryFncallback is consistently bound todb.value.query.Also applies to: 134-134, 358-358
crates/cli/src/commands/local_db/sync/storage.rs (2)
81-104: LGTM! Function signature updated to return RpcClient.The
build_local_db_from_networkfunction signature has been correctly updated to return(RpcClient, Vec<Url>)instead of(LocalDb, Vec<Url>). The construction usesRpcClient::new_with_hyper_rpcwhich properly initializes the client with the HyperRPC endpoint.
158-166: LGTM! Tests updated correctly.The test correctly verifies the new return type by calling
rpc_client.rpc_urls()and asserting on the HyperRPC URL structure. The test properly validates that metadata RPCs match the network configuration and that the event RPC URL is correctly constructed with the HyperRPC endpoint.crates/cli/src/commands/local_db/sync/data_source.rs (1)
79-155: LGTM! Well-structured trait implementation for RpcClient.The
SyncDataSourcetrait implementation forRpcClientproperly delegates to the new free functions:
latest_block()correctly maps errors throughanyhow!fetch_events()efficiently converts the orderbook address once before passing tofetch_orderbook_eventsfetch_store_set_events()provides good error context when parsing each store address- All decode/SQL generation methods correctly delegate to the new free functions with proper error mapping
The refactor maintains all original functionality while removing the LocalDb dependency.
crates/common/src/local_db/mod.rs (2)
111-115: LGTM! Improved error handling with transparent error variants.The refactoring of
DecodeErrorandInsertErrorfrom struct-like variants with message fields to transparent variants using#[from]is a cleaner design. This enables automatic error conversions and preserves the full error context from the underlying error types.
187-189: LGTM! New public helper for chain support checks.The new
is_chain_supported_local_dbfunction provides a clean public API for checking if a chain is supported by the local DB. This replaces the previous pattern of callingLocalDb::check_supportand aligns with the migration away from LocalDb as a central type.crates/common/src/local_db/pipeline/adapters/events.rs (3)
18-34: LGTM! Well-designed constructors for different use cases.The
DefaultEventsPipelineprovides two clear construction paths:
with_regular_rpcsfor browser/public RPCswith_hyperrpcfor the producer/HyperRPC pathBoth properly handle errors by converting
RpcClientErrorintoLocalDbErrorthrough the?operator andFromconversion.
36-78: LGTM! Clean trait implementation with proper delegation.The
EventsPipelinetrait implementation correctly delegates to the corresponding free functions:
latest_block()usesget_latest_block_number()withInto::intoerror mappingfetch_orderbook()andfetch_stores()delegate tofetch_orderbook_eventsandfetch_store_eventsdecode()wraps the result withLocalDbError::DecodeErrorfor proper error propagationThe use of
#[async_trait(?Send)]is appropriate for the WASM target.
91-148: LGTM! Comprehensive test coverage.The tests properly cover:
- Successful construction via both
with_regular_rpcsandwith_hyperrpc- Decode error propagation when invalid log data is provided
- Constructor error paths for empty RPC lists and unsupported chain IDs
The test assertions correctly match against specific error variants to ensure proper error handling.
| /// Returns the sync status rows from the local DB (via provided JS query callback) | ||
| #[wasm_export( | ||
| js_name = "getSyncStatus", | ||
| unchecked_return_type = "SyncStatusResponse[]" | ||
| )] | ||
| pub async fn get_sync_status( | ||
| #[wasm_export(param_description = "JavaScript function to execute database queries")] | ||
| db_callback: js_sys::Function, | ||
| ) -> Result<Vec<SyncStatusResponse>, LocalDbError> { | ||
| let exec = crate::raindex_client::local_db::executor::JsCallbackExecutor::new(&db_callback); | ||
| fetch_last_synced_block(&exec) | ||
| .await | ||
| .map_err(LocalDbError::from) | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Consider adding test coverage for the exported function.
While the existing test validates the helper function, there's no test for the new get_sync_status wrapper, particularly the error mapping from LocalDbQueryError to LocalDbError. A simple test could verify the error conversion path works as expected.
🤖 Prompt for AI Agents
In crates/common/src/raindex_client/local_db/query/fetch_last_synced_block.rs
around lines 14 to 27, add a unit test that exercises the exported async wrapper
get_sync_status to ensure the LocalDbQueryError -> LocalDbError mapping works;
write a test that constructs a JsCallbackExecutor (or supply a js_sys::Function
stub) that causes fetch_last_synced_block to fail with a LocalDbQueryError, call
get_sync_status().await and assert it returns
Err(LocalDbError::from(the_query_error)) (or matches the expected LocalDbError
variant/message), and include any necessary wasm-bindgen test harness setup and
async test attribute so the exported wrapper error path is covered.
|
@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:
Review Effort: Would have taken 5-10 minutes Examples:
Medium (M)Characteristics:
Review Effort: Would have taken 15-30 minutes Examples:
Large (L)Characteristics:
Review Effort: Would have taken 45+ minutes Examples:
Additional Factors to ConsiderWhen deciding between sizes, also consider:
Notes:
|
|
Tip For best results, initiate chat on the files or code changes. SIZE=L 🧠 Learnings used |
Motivation
See issues:
sync_database_with_servicesinto Testable Stages #2233Solution
Checks
By submitting this for review, I'm confirming I've done the following:
Summary by CodeRabbit
New Features
Refactor
Tests