Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 41 additions & 44 deletions crates/common/src/raindex_client/add_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ enum PollError {
impl RaindexClient {
/// Fetches orders that were added in a specific transaction
///
/// Retrieves all orders created within a single blockchain transaction, useful
/// for tracking order deployment.
/// Retrieves all orders created within a single blockchain transaction across
/// all configured orderbooks for the given chain, useful for tracking order deployment.
///
/// ## Examples
///
/// ```javascript
/// const result = await client.getAddOrdersForTransaction(1, "0x1234567890abcdef1234567890abcdef12345678");
/// const result = await client.getAddOrdersForTransaction(1, "0xabc...");
/// if (result.error) {
/// console.error("Cannot fetch added orders:", result.error.readableMsg);
/// return;
Expand All @@ -44,12 +44,6 @@ impl RaindexClient {
&self,
#[wasm_export(js_name = "chainId", param_description = "Chain ID for the network")]
chain_id: u32,
#[wasm_export(
js_name = "orderbookAddress",
param_description = "Orderbook contract address",
unchecked_param_type = "Hex"
)]
orderbook_address: String,
#[wasm_export(
js_name = "txHash",
param_description = "Transaction hash",
Expand All @@ -67,11 +61,9 @@ impl RaindexClient {
)]
interval_ms: Option<u32>,
) -> Result<Vec<RaindexOrder>, RaindexError> {
let orderbook_address = Address::from_str(&orderbook_address)?;
let tx_hash = B256::from_str(&tx_hash)?;
self.get_add_orders_for_transaction(
chain_id,
orderbook_address,
tx_hash,
max_attempts.map(|v| v as usize),
interval_ms.map(|v| v as u64),
Expand All @@ -80,16 +72,19 @@ impl RaindexClient {
}
}
impl RaindexClient {
async fn get_add_orders_for_transaction(
pub async fn get_add_orders_for_transaction(
&self,
chain_id: u32,
orderbook_address: Address,
tx_hash: B256,
max_attempts: Option<usize>,
interval_ms: Option<u64>,
) -> Result<Vec<RaindexOrder>, RaindexError> {
let raindex_client = ClientRef::new(self.clone());

let orderbooks = self.orderbook_yaml.get_orderbooks_by_chain_id(chain_id)?;
let orderbook_addresses: Vec<Address> =
orderbooks.iter().map(|ob| ob.address).collect();
Comment on lines +84 to +86
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot Mar 10, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Local DB is still effectively single-orderbook, so this loop can duplicate or miss results.

When query_source(chain_id) selects LocalDb, iterating every configured orderbook here is not safe yet. The local DB stack still indexes only one orderbook per chain, and fetch_orders still uses a single hardcoded orderbook filter underneath. On a chain with multiple configured orderbooks, this branch can therefore either repeat the same indexed order for each iteration or time out for orders that belong to a non-indexed orderbook, with no subgraph fallback on this path.

Based on learnings, sync_database currently only supports indexing a single orderbook per chain ID, and fetch_orders/query.sql still hardcodes a single orderbook_address because multiorderbook local DB support is planned for a future PR.

Also applies to: 93-116

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/common/src/raindex_client/add_orders.rs` around lines 84 - 86, The
current loop over orderbooks (orderbook_yaml.get_orderbooks_by_chain_id ->
orderbook_addresses) is unsafe when query_source(chain_id) returns LocalDb
because the local DB indexes only one orderbook per chain; modify the logic so
that when query_source(chain_id) == LocalDb you do not iterate all configured
orderbooks but instead pick the single indexed orderbook address used by
sync_database (or explicitly the first/configured indexed address) and call
fetch_orders only once for that address; for non-indexed orderbooks ensure you
fall back to the Subgraph path instead of repeating fetch_orders. Apply this
change where orderbook_addresses is built and in the related branch handling
(see functions/refs: orderbook_yaml.get_orderbooks_by_chain_id, query_source,
sync_database, and fetch_orders/query.sql) so lines 93-116 no longer loop over
all orderbooks for LocalDb.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No duplicates — the SQL filters by orderbook_address via IN ({list}), so each iteration queries a distinct orderbook. The subgraph path requires separate calls per endpoint, so the loop is necessary there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check the SQL query for fetch_orders to see if it filters by orderbook_address using IN clause
fd "query.sql" --full-path | xargs grep -l "orderbook_address" 2>/dev/null | head -20

Length of output: 1101


🏁 Script executed:

#!/bin/bash
# Check the fetch_orders query.sql for IN clause on orderbook_address
cat crates/common/src/local_db/query/fetch_orders/query.sql

# Also check the get_added_by_tx_hash implementation in local_db/orders.rs
fd "orders.rs" --full-path | xargs grep -l "get_added_by_tx_hash" 2>/dev/null

Length of output: 7444


🏁 Script executed:

#!/bin/bash
# Check the get_added_by_tx_hash implementation in local_db/orders.rs
cat crates/common/src/raindex_client/local_db/orders.rs | grep -A 40 "get_added_by_tx_hash"

# Also check how MAIN_ORDERBOOKS_CLAUSE is built - look for the builder
rg "MAIN_ORDERBOOKS_CLAUSE\|ORDERBOOKS_CLAUSE\|orderbook_addresses\|build_fetch_orders" --type=rust -n -C 3

Length of output: 2823


@findolor, you're right — I was mistaken. Looking at the code, each iteration calls get_added_by_tx_hash with a distinct orderbook_address, and the SQL applies it via the /*MAIN_ORDERBOOKS_CLAUSE*/ template placeholder. Since each call is scoped to a different orderbook, results are disjoint and there is no duplication. The loop is correct for both the LocalDb and Subgraph paths.

Also, the learning I had about fetch_orders/query.sql hardcoding a single orderbook address is now stale. I'll remove it.


⛔ Learnings removed
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.

🧠 Learnings used
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.

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.

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.

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.

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.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2460
File: crates/subgraph/src/orderbook_client/order.rs:143-168
Timestamp: 2026-02-25T12:20:58.472Z
Learning: In the rainlanguage/rain.orderbook codebase at crates/subgraph/src/orderbook_client/order.rs, user findolor prefers not to implement overflow protection for the u16 `page` counter in `orders_count`, considering it unnecessary since reaching 65,535 pages (requiring ~13M orders at page_size=200) is far beyond any realistic dataset and not worth the added complexity.

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.

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.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2488
File: crates/common/src/raindex_client/orders.rs:844-865
Timestamp: 2026-03-05T09:51:23.105Z
Learning: In `crates/common/src/raindex_client/orders.rs`, `get_orders` applies `page_number` independently to `LocalDbOrders::list` and `SubgraphOrders::list` and concatenates the results. This is intentional and correct because `classify_chains` partitions chain IDs into mutually exclusive sets (local DB chains vs subgraph chains), so the two source branches never query overlapping data. Global pagination across both backends is not implemented because it would require a complex cursor/merge strategy that is not warranted. Do not flag per-source pagination as a bug when results are from disjoint chain sets.

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.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2376
File: crates/common/src/raindex_client/orders.rs:2-2
Timestamp: 2026-01-07T14:21:36.804Z
Learning: Enforce the exclusive local DB data source pattern for all raindex_client files. When is_chain_supported_local_db() is true and local_db is available, code should return local DB results without falling back to the subgraph, even if results are empty. Ensure methods like get_trades_list() and get_vaults_volume() follow this behavior. Identify and fix any outliers (e.g., get_balance_changes() returning results when local_changes is empty) to align with the exclusive local DB pattern. This guideline applies across all files in crates/common/src/raindex_client (and similar paths) that implement data-source selection.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2497
File: crates/subgraph/src/multi_orderbook_client.rs:128-160
Timestamp: 2026-03-10T06:24:18.339Z
Learning: In `crates/subgraph/src/multi_orderbook_client.rs`, the `filter_map(Result::ok)` pattern for silently dropping failing subgraphs and returning partial results is the intentional, established convention across all multi-subgraph methods (`orders_list`, `vaults_list`, `trades_by_transaction`). Do not flag this as a bug for individual methods — if the error propagation behavior needs to change, it should be done consistently across all methods in a dedicated PR.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2499
File: crates/common/src/local_db/query/fetch_owner_trades/query.sql:273-281
Timestamp: 2026-03-10T11:19:18.334Z
Learning: In `crates/common/src/local_db/query/` SQL files (rain.orderbook), passthrough `SELECT *` projections in intermediate CTEs (e.g., `clear_trades`, `unioned_trades`) are the accepted codebase-wide pattern. Do not flag these as issues; changing only one query would be inconsistent with the rest of the codebase.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2497
File: crates/common/src/raindex_client/local_db/query/fetch_trades_by_tx.rs:27-49
Timestamp: 2026-03-09T11:54:48.469Z
Learning: In `crates/common/src/raindex_client/local_db/query/fetch_trades_by_tx.rs`, the WASM unit test `wrapper_uses_builder_sql_exactly` intentionally returns an empty `[]` from the callback to focus exclusively on validating that the wrapper forwards the SQL built by `build_fetch_trades_by_tx_stmt`. The deserialization path (including new fields like `chain_id` on `LocalDbOrderTrade`) is intentionally covered by separate WASM and integration tests, not this unit test. This is by design and should not be flagged as a coverage gap.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2488
File: crates/common/src/raindex_client/local_db/state.rs:71-74
Timestamp: 2026-03-03T13:05:32.771Z
Learning: In `crates/common/src/raindex_client/local_db/state.rs`, the `compute_chain_ids()` method intentionally allows sync keys in the YAML that don't match any network entry; these stray keys are harmless and simply go unused. The validation is performed in the reverse direction by `build_runner_targets()`, which ensures every orderbook network must have a sync config. There's no need to warn about unmatched sync keys.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1858
File: crates/subgraph/src/orderbook_client/order.rs:94-108
Timestamp: 2025-05-19T11:40:45.864Z
Learning: Order hashes are unique in the subgraph data model, so a query by hash (`order_detail_by_hash`) will never return multiple orders with the same hash.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1938
File: crates/js_api/src/raindex/mod.rs:92-99
Timestamp: 2025-06-18T18:18:44.330Z
Learning: In crates/js_api/src/raindex/mod.rs, the get_subgraph_url_for_chain method and get_multi_subgraph_args method intentionally duplicate lookup logic because they serve different purposes: get_subgraph_url_for_chain returns only the URL string, while get_multi_subgraph_args returns MultiSubgraphArgs structures containing both URL and network information (name/label). This duplication is acceptable and by design.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2370
File: crates/common/src/raindex_client/vaults.rs:896-973
Timestamp: 2026-01-07T15:38:32.716Z
Learning: In the rainlanguage/rain.orderbook repo, prefer keeping self-contained match arms over extracting a helper function to avoid duplicating many fields when handling related subgraph types (e.g., SgDeposit, SgWithdrawal, SgClearBounty). The cost of passing 10+ fields to a helper may reduce readability and maintainability; duplicating the match arms is acceptable if it keeps the code clearer in this module. Apply this guidance broadly to Rust files in crates/common/src/raindex_client unless refactoring clearly improves structure without excessive boilerplate.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1858
File: crates/subgraph/src/orderbook_client/vault.rs:81-92
Timestamp: 2025-05-19T12:09:10.694Z
Learning: The `vault_balance_changes_list` function in OrderbookSubgraphClient uses a different pagination approach compared to other list methods. It uses hard-coded GraphQL query parameters (first=200, skip=0) while still accepting pagination arguments, and the pagination is handled by special logic inside the `query_paginated` method that properly processes these values.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1913
File: Cargo.toml:55-55
Timestamp: 2025-06-06T16:38:04.182Z
Learning: In rain.orderbook repository, during PR chains involving dependency updates, wasm-bindgen-utils may temporarily point to git commits that don't contain the full required functionality, with the understanding that subsequent PRs in the chain will update it to the correct commit.

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.

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.

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.

Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:26:31.566Z
Learning: For PR `#1884` and future PRs in rainlanguage/rain.orderbook repository, provide PR size reports in a separate comment with ONLY the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number", without any additional text or explanation. Reports should exclude irrelevant files such as lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, 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: 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: 2117
File: crates/js_api/src/gui/select_tokens.rs:421-424
Timestamp: 2025-09-02T08:04:34.729Z
Learning: User findolor in the rainlanguage/rain.orderbook codebase prefers not to change test code when tests are already passing, even if there appear to be type mismatches or potential issues. Working tests should be left alone unless there are actual errors.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2399
File: crates/rest_api/src/routes/take_orders.rs:74-95
Timestamp: 2026-01-16T12:07:15.521Z
Learning: In Rust projects using utoipa, when you use #[schema(...)] attributes (for example #[schema(example = json!(...))]), the json! macro is handled internally by utoipa's proc-macro at compile time. You do not need to import serde_json::json! in the module for these attributes. Do not add a serde_json::json! import solely for these schema attributes; ensure serde_json is present only if used elsewhere."


let attempts = max_attempts
.unwrap_or(DEFAULT_ADD_ORDER_POLL_ATTEMPTS)
.max(1);
Expand All @@ -100,14 +95,18 @@ impl RaindexClient {
let local_source = LocalDbOrders::new(&local_db, raindex_client.clone());
let local_result = retry_with_constant_interval(
|| async {
let orders = local_source
.get_added_by_tx_hash(chain_id, orderbook_address, tx_hash)
.await
.map_err(PollError::Inner)?;
if orders.is_empty() {
let mut all_orders = Vec::new();
for &orderbook_address in &orderbook_addresses {
let orders = local_source
.get_added_by_tx_hash(chain_id, orderbook_address, tx_hash)
.await
.map_err(PollError::Inner)?;
all_orders.extend(orders);
}
if all_orders.is_empty() {
Err(PollError::Empty)
} else {
Ok(orders)
Ok(all_orders)
}
},
attempts,
Expand All @@ -132,20 +131,24 @@ impl RaindexClient {
let subgraph_source = SubgraphOrders::new(self);
let subgraph_result = retry_with_constant_interval(
|| async {
let orders = match subgraph_source
.get_added_by_tx_hash(chain_id, orderbook_address, tx_hash)
.await
{
Ok(orders) => orders,
Err(RaindexError::OrderbookSubgraphClientError(
rain_orderbook_subgraph_client::OrderbookSubgraphClientError::Empty,
)) => return Err(PollError::Empty),
Err(e) => return Err(PollError::Inner(e)),
};
if orders.is_empty() {
let mut all_orders = Vec::new();
for &orderbook_address in &orderbook_addresses {
let orders = match subgraph_source
.get_added_by_tx_hash(chain_id, orderbook_address, tx_hash)
.await
{
Ok(orders) => orders,
Err(RaindexError::OrderbookSubgraphClientError(
rain_orderbook_subgraph_client::OrderbookSubgraphClientError::Empty,
)) => continue,
Err(e) => return Err(PollError::Inner(e)),
};
all_orders.extend(orders);
}
if all_orders.is_empty() {
Err(PollError::Empty)
} else {
Ok(orders)
Ok(all_orders)
}
},
attempts,
Expand Down Expand Up @@ -178,9 +181,7 @@ mod tests {
#[cfg(not(target_family = "wasm"))]
mod non_wasm {
use super::*;
use crate::raindex_client::tests::{
get_test_yaml, new_with_local_db, CHAIN_ID_1_ORDERBOOK_ADDRESS,
};
use crate::raindex_client::tests::{get_test_yaml, new_with_local_db};
use crate::{
local_db::query::{
fetch_orders::LocalDbOrder, FromDbJson, LocalDbQueryError, LocalDbQueryExecutor,
Expand Down Expand Up @@ -364,7 +365,6 @@ mod tests {
let res = raindex_client
.get_add_orders_for_transaction(
1,
Address::from_str(CHAIN_ID_1_ORDERBOOK_ADDRESS).unwrap(),
b256!("0x0000000000000000000000000000000000000000000000000000000000000123"),
None,
None,
Expand Down Expand Up @@ -549,7 +549,6 @@ mod tests {
let res = raindex_client
.get_add_orders_for_transaction(
1,
Address::from_str(CHAIN_ID_1_ORDERBOOK_ADDRESS).unwrap(),
b256!("0x0000000000000000000000000000000000000000000000000000000000000123"),
Some(DEFAULT_ADD_ORDER_POLL_ATTEMPTS),
Some(10),
Expand Down Expand Up @@ -583,7 +582,6 @@ mod tests {
let err = raindex_client
.get_add_orders_for_transaction(
1,
Address::from_str(CHAIN_ID_1_ORDERBOOK_ADDRESS).unwrap(),
b256!("0x0000000000000000000000000000000000000000000000000000000000000123"),
Some(DEFAULT_ADD_ORDER_POLL_ATTEMPTS),
Some(10),
Expand All @@ -603,8 +601,6 @@ mod tests {
async fn test_get_transaction_add_orders_prefers_local_db() {
let tx_hash =
b256!("0x00000000000000000000000000000000000000000000000000000000deadbeef");
let orderbook_address =
Address::from_str("0x0987654321098765432109876543210987654321").unwrap();
let owner = Address::from_str("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").unwrap();

let local_order = LocalDbOrder {
Expand All @@ -615,7 +611,10 @@ mod tests {
owner,
block_timestamp: 1_000,
block_number: 50,
orderbook_address,
orderbook_address: Address::from_str(
"0x0987654321098765432109876543210987654321",
)
.unwrap(),
order_bytes: Bytes::from_str("0x01").unwrap(),
transaction_hash: tx_hash,
inputs: None,
Expand Down Expand Up @@ -651,7 +650,7 @@ mod tests {
.await;

let res = client
.get_add_orders_for_transaction(137, orderbook_address, tx_hash, Some(3), Some(1))
.get_add_orders_for_transaction(137, tx_hash, Some(3), Some(1))
.await
.unwrap();

Expand All @@ -671,8 +670,6 @@ mod tests {
async fn test_get_transaction_add_orders_exhausts_local_without_fallback() {
let tx_hash =
b256!("0x00000000000000000000000000000000000000000000000000000000cafebabe");
let orderbook_address =
Address::from_str("0x0987654321098765432109876543210987654321").unwrap();

let local_exec = CountingJsonExec {
json: "[]".to_string(),
Expand Down Expand Up @@ -701,7 +698,7 @@ mod tests {
.await;

let err = client
.get_add_orders_for_transaction(137, orderbook_address, tx_hash, Some(2), Some(1))
.get_add_orders_for_transaction(137, tx_hash, Some(2), Some(1))
.await
.unwrap_err();

Expand Down
9 changes: 4 additions & 5 deletions crates/common/src/raindex_client/local_db/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ mod tests {
let orderbook_address = address!("0x2f209e5b67A33B8fE96E28f24628dF6Da301c8eB");

let local_order = LocalDbOrder {
chain_id: 137,
chain_id: 42161,
order_hash,
owner,
block_timestamp: 123456,
Expand All @@ -621,13 +621,12 @@ mod tests {
let client = new_test_client_with_db_callback(
vec![get_local_db_test_yaml()],
callback,
vec![42161, 137],
vec![42161],
);

let orders = client
.get_add_orders_for_transaction_wasm_binding(
137,
orderbook_address.to_string(),
42161,
transaction_hash.to_string(),
Some(1),
Some(1),
Expand All @@ -637,7 +636,7 @@ mod tests {

assert_eq!(orders.len(), 1);
let order = &orders[0];
assert_eq!(order.chain_id(), 137);
assert_eq!(order.chain_id(), 42161);
assert_eq!(order.order_hash(), order_hash.to_string());
assert_eq!(order.order_bytes(), order_bytes.to_string());
let tx = order.transaction().expect("transaction should be set");
Expand Down
5 changes: 1 addition & 4 deletions packages/orderbook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,14 @@ async function waitForOrderFromTx(
client: RaindexClient,
{
chainId,
orderbookAddress,
txHash
}: {
chainId: number;
orderbookAddress: string;
txHash: string;
}
) {
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
const result = await client.getAddOrdersForTransaction(chainId, orderbookAddress, txHash);
const result = await client.getAddOrdersForTransaction(chainId, txHash);
if (result.error) throw new Error(result.error.readableMsg);

if (result.value.length) {
Expand All @@ -291,7 +289,6 @@ async function waitForOrderFromTx(
const txReceipt = await executeOrder(...);
const raindexOrder = await waitForOrderFromTx(client, {
chainId: 8453,
orderbookAddress: '0x52CEB8eBEf648744fFDDE89F7Bc9C3aC35944775',
txHash: txReceipt.transactionHash
});
```
Expand Down
6 changes: 1 addition & 5 deletions packages/orderbook/test/js_api/raindexClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1599,11 +1599,7 @@ describe('Rain Orderbook JS API Package Bindgen Tests - Raindex Client', async f

const raindexClient = extractWasmEncodedData(await RaindexClient.new([YAML]));
const result = extractWasmEncodedData(
await raindexClient.getAddOrdersForTransaction(
1,
CHAIN_ID_1_ORDERBOOK_ADDRESS,
mockOrder.transaction.id
)
await raindexClient.getAddOrdersForTransaction(1, mockOrder.transaction.id)
);
assert.equal(result[0].id, mockAddOrder.order.id);
assert.equal(result[0].chainId, BigInt(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ export class TransactionManager {
// SDK-based indexing - the SDK's getAddOrdersForTransaction handles
// local-DB-first polling followed by subgraph fallback internally
const awaitIndexingFn = createSdkIndexingFn({
call: () => raindexClient.getAddOrdersForTransaction(chainId, orderbook, txHash),
call: () => raindexClient.getAddOrdersForTransaction(chainId, txHash),
isSuccess: (orders) => Array.isArray(orders) && orders.length > 0,
buildLinks: (orders) => {
if (!Array.isArray(orders) || orders.length === 0) return [];
Expand Down
Loading