Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getTransaction wasm function, to poll for new txs #1260

Merged
merged 30 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3e288c4
Add getTransaction
hardingjam Feb 10, 2025
8bd686d
getting the tc and polling
hardingjam Feb 11, 2025
03b8e83
add deploymemt
hardingjam Feb 11, 2025
f0645e8
add wait for tx
hardingjam Feb 11, 2025
9c73aec
add tests
hardingjam Feb 11, 2025
914a903
Merge branch 'main' into 02/10/25-Add-getTransaction-wasm-fn
hardingjam Feb 11, 2025
72ea287
test not passing
hardingjam Feb 12, 2025
30af707
format test
hardingjam Feb 12, 2025
391df8e
invalidate queries on tx success
hardingjam Feb 13, 2025
affd03d
WIP live update
hardingjam Feb 13, 2025
8690ff3
wip, trying to get chart updating automatically without re-rendering
hardingjam Feb 13, 2025
9b49a8e
Merge branch 'main' into 02/10/25-Add-getTransaction-wasm-fn
hardingjam Feb 13, 2025
a654c20
invalidate queries and show toast
hardingjam Feb 13, 2025
8fec5eb
remove logs
hardingjam Feb 13, 2025
9d1a141
update reactively on transaction success
hardingjam Feb 13, 2025
fff8ee3
add refetch on success
hardingjam Feb 13, 2025
6c62abc
update chart test
hardingjam Feb 13, 2025
314e0ac
mock getNetworkKey
hardingjam Feb 13, 2025
3ed5517
test returning network
hardingjam Feb 13, 2025
7278c03
Merge branch 'main' into 02/10/25-Add-getTransaction-wasm-fn
hardingjam Feb 14, 2025
981d68e
add
hardingjam Feb 14, 2025
35753c6
tx test not working
hardingjam Feb 14, 2025
16906ad
logging status
hardingjam Feb 14, 2025
16d4354
rm unused logs
hardingjam Feb 14, 2025
a140ab0
timer fix
hardyjosh Feb 14, 2025
44057c9
rm logs
hardingjam Feb 14, 2025
56b72e7
lint
hardingjam Feb 14, 2025
e105801
Merge branch 'main' into 02/10/25-Add-getTransaction-wasm-fn
hardingjam Feb 14, 2025
5f34657
rm only
hardingjam Feb 14, 2025
8b7dec3
Merge branch 'main' into 02/10/25-Add-getTransaction-wasm-fn
hardingjam Feb 14, 2025
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
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 @@ -8,6 +8,7 @@ use thiserror::Error;
use wasm_bindgen::{JsError, JsValue};

pub mod order;
pub mod transaction;
pub mod vault;

#[derive(Error, Debug)]
Expand Down
16 changes: 16 additions & 0 deletions crates/js_api/src/subgraph/transaction.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 a single transaction
/// Returns the Transaction struct
#[wasm_bindgen(js_name = "getTransaction")]
pub async fn get_sg_transaction(
url: &str,
id: &str,
) -> Result<JsValue, OrderbookSubgraphClientError> {
let client = OrderbookSubgraphClient::new(Url::parse(url)?);
let transaction = client.transaction_detail(Id::new(id)).await?;
Ok(to_value(&transaction)?)
}
14 changes: 14 additions & 0 deletions crates/subgraph/src/orderbook_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::types::order::{
OrdersListQuery,
};
use crate::types::order_trade::{OrderTradeDetailQuery, OrderTradesListQuery};
use crate::types::transaction::TransactionDetailQuery;
use crate::types::vault::{VaultDetailQuery, VaultsListQuery};
use crate::vault_balance_changes_query::VaultBalanceChangesListPageQueryClient;
use cynic::Id;
Expand Down Expand Up @@ -379,4 +380,17 @@ impl OrderbookSubgraphClient {
}
Ok(all_pages_merged)
}

pub async fn transaction_detail(
&self,
id: Id,
) -> Result<Transaction, OrderbookSubgraphClientError> {
let data = self
.query::<TransactionDetailQuery, IdQueryVariables>(IdQueryVariables { id: &id })
.await?;
let transaction = data
.transaction
.ok_or(OrderbookSubgraphClientError::Empty)?;
Ok(transaction)
}
}
1 change: 1 addition & 0 deletions crates/subgraph/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod impls;
pub mod order;
pub mod order_detail_traits;
pub mod order_trade;
pub mod transaction;
pub mod vault;

pub use cynic::Id;
12 changes: 12 additions & 0 deletions crates/subgraph/src/types/transaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use super::common::*;
use crate::schema;
use typeshare::typeshare;

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Query", variables = "IdQueryVariables")]
#[typeshare]
pub struct TransactionDetailQuery {
#[arguments(id: $id)]
#[typeshare(typescript(type = "TransactionSubgraph"))]
pub transaction: Option<Transaction>,
}
31 changes: 31 additions & 0 deletions packages/orderbook/test/js_api/transaction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import assert from 'assert';
import { getLocal } from 'mockttp';
import { describe, it, beforeEach, afterEach } from 'vitest';
import { Transaction } from '../../dist/types/js_api.js';
import { getTransaction } from '../../dist/cjs/js_api.js';

const transaction1 = {
id: 'tx1',
from: '0x1',
blockNumber: '1',
timestamp: '1'
} as unknown as Transaction;

describe('Rain Orderbook JS API Package Bindgen Tests - Order', async function () {
const mockServer = getLocal();
beforeEach(() => mockServer.start(8090));
afterEach(() => mockServer.stop());

it('should fetch a single transaction', async () => {
await mockServer
.forPost('/sg1')
.thenReply(200, JSON.stringify({ data: { transaction: transaction1 } }));

try {
const result: Transaction = await getTransaction(mockServer.url + '/sg1', transaction1.id);
assert.equal(result.id, transaction1.id);
} catch (e) {
assert.fail('expected to resolve, but failed' + (e instanceof Error ? e.message : String(e)));
}
});
});
Loading