Skip to content

Commit

Permalink
Merge pull request #1295 from rainlanguage/02/13/25-branched-add-orde…
Browse files Browse the repository at this point in the history
…r-rush-function

02/13/25 Add_order.rs query for new deployments, and await new deployment as part of tx flow
  • Loading branch information
hardyjosh authored Feb 15, 2025
2 parents f09f6c9 + 8b727ba commit 1334ecc
Show file tree
Hide file tree
Showing 14 changed files with 596 additions and 36 deletions.
16 changes: 16 additions & 0 deletions crates/js_api/src/subgraph/add_order.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use cynic::Id;
use rain_orderbook_bindings::wasm_traits::prelude::*;
use rain_orderbook_subgraph_client::{OrderbookSubgraphClient, OrderbookSubgraphClientError};
use reqwest::Url;

/// Internal function to fetch Add Orders for a given transaction
/// Returns an array of AddOrder structs
#[wasm_bindgen(js_name = "getTransactionAddOrders")]
pub async fn get_transaction_add_orders(
url: &str,
tx_hash: &str,
) -> Result<JsValue, OrderbookSubgraphClientError> {
let client = OrderbookSubgraphClient::new(Url::parse(url)?);
let add_orders = client.transaction_add_orders(Id::new(tx_hash)).await?;
Ok(to_value(&add_orders)?)
}
1 change: 1 addition & 0 deletions crates/js_api/src/subgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rain_orderbook_subgraph_client::OrderbookSubgraphClientError;
use thiserror::Error;
use wasm_bindgen::{JsError, JsValue};

pub mod add_order;
pub mod order;
pub mod transaction;
pub mod vault;
Expand Down
21 changes: 21 additions & 0 deletions crates/subgraph/src/orderbook_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::cynic_client::{CynicClient, CynicClientError};
use crate::pagination::{PaginationArgs, PaginationClient, PaginationClientError};
use crate::performance::vol::{get_vaults_vol, VaultVolume};
use crate::performance::OrderPerformance;
use crate::types::add_order::{TransactionAddOrdersQuery, TransactionAddOrdersVariables};
use crate::types::common::*;
use crate::types::order::{
BatchOrderDetailQuery, BatchOrderDetailQueryVariables, OrderDetailQuery, OrderIdList,
Expand Down Expand Up @@ -395,4 +396,24 @@ impl OrderbookSubgraphClient {
.ok_or(OrderbookSubgraphClientError::Empty)?;
Ok(transaction)
}

/// Fetch all add orders for a given transaction
pub async fn transaction_add_orders(
&self,
id: Id,
) -> Result<Vec<AddOrderWithOrder>, OrderbookSubgraphClientError> {
let data = self
.query::<TransactionAddOrdersQuery, TransactionAddOrdersVariables>(
TransactionAddOrdersVariables {
id: Bytes(id.inner().to_string()),
},
)
.await?;

if data.add_orders.is_empty() {
return Err(OrderbookSubgraphClientError::Empty);
}

Ok(data.add_orders)
}
}
16 changes: 16 additions & 0 deletions crates/subgraph/src/types/add_order.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use super::common::{AddOrderWithOrder, Bytes};
use crate::schema;
use typeshare::typeshare;

#[derive(cynic::QueryVariables, Debug)]
pub struct TransactionAddOrdersVariables {
pub id: Bytes,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Query", variables = "TransactionAddOrdersVariables")]
#[typeshare]
pub struct TransactionAddOrdersQuery {
#[arguments(where: { transaction_: { id: $id } })]
pub add_orders: Vec<AddOrderWithOrder>,
}
9 changes: 9 additions & 0 deletions crates/subgraph/src/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,15 @@ pub struct AddOrder {
pub transaction: Transaction,
}

#[derive(cynic::QueryFragment, Debug, Serialize, Clone)]
#[cfg_attr(target_family = "wasm", derive(Tsify))]
#[cynic(graphql_type = "AddOrder")]
pub struct AddOrderWithOrder {
pub transaction: Transaction,
#[cfg_attr(target_family = "wasm", tsify(type = "OrderSubgraph"))]
pub order: Order,
}

#[derive(cynic::Scalar, Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(target_family = "wasm", derive(Tsify), serde(rename = "SgBigInt"))]
#[typeshare]
Expand Down
1 change: 1 addition & 0 deletions crates/subgraph/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod add_order;
pub mod common;
mod impls;
pub mod order;
Expand Down
Loading

0 comments on commit 1334ecc

Please sign in to comment.