-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1260 from rainlanguage/02/10/25-Add-getTransactio…
…n-wasm-fn Add getTransaction wasm function, to poll for new txs
- Loading branch information
Showing
27 changed files
with
398 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_transaction( | ||
url: &str, | ||
tx_hash: &str, | ||
) -> Result<JsValue, OrderbookSubgraphClientError> { | ||
let client = OrderbookSubgraphClient::new(Url::parse(url)?); | ||
let transaction = client.transaction_detail(Id::new(tx_hash)).await?; | ||
Ok(to_value(&transaction)?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.