diff --git a/crates/sui-graphql-client/src/lib.rs b/crates/sui-graphql-client/src/lib.rs index 7072f9ca0..314ea1c74 100644 --- a/crates/sui-graphql-client/src/lib.rs +++ b/crates/sui-graphql-client/src/lib.rs @@ -320,11 +320,11 @@ impl Client { /// /// If `coin_type` is not provided, it will default to `0x2::coin::Coin`, which will return all /// coins. For SUI coin, pass in the coin type: `0x2::coin::Coin<0x2::sui::SUI>`. - pub async fn coins( - &self, + pub async fn coins<'a>( + &'a self, owner: Address, - after: Option, - before: Option, + after: Option<&'a str>, + before: Option<&'a str>, first: Option, last: Option, coin_type: Option<&str>, @@ -360,17 +360,17 @@ impl Client { pub fn coins_stream<'a>( &'a self, owner: Address, - coin_type: Option, + coin_type: Option<&'a str>, ) -> Pin> + 'a>> { - let coin_type = coin_type.unwrap_or_else(|| "0x2::coin::Coin".to_string()); + let coin_type = coin_type.unwrap_or("0x2::coin::Coin"); + let mut after: Option = None; Box::pin(try_stream! { - let mut after = None; loop { let response = self.objects( - after, + after.as_deref(), None, Some(ObjectFilter { - type_: Some(&coin_type), + type_: Some(coin_type), owner: Some(owner), object_ids: None, object_keys: None, @@ -387,7 +387,7 @@ impl Client { } if let Some(end_cursor) = page.page_info.end_cursor { - after = Some(end_cursor); + after = Some (end_cursor); } else { break; } @@ -519,11 +519,11 @@ impl Client { // Events API // =========================================================================== - pub async fn events( - &self, + pub async fn events<'a>( + &'a self, filter: Option, - after: Option, - before: Option, + after: Option<&'a str>, + before: Option<&'a str>, first: Option, last: Option, ) -> Result>, Error> { @@ -558,16 +558,16 @@ impl Client { pub async fn events_stream<'a>( &'a self, - after: Option, - before: Option, + after: Option<&'a str>, + before: Option<&'a str>, filter: Option, first: Option, last: Option, ) -> Pin> + 'a>> { + let mut after = after.map(|s| s.to_string()); Box::pin(try_stream! { - let mut after = after; loop { - let response = self.events(filter.clone(), after, before.clone(), first, last).await?; + let response = self.events(filter.clone(), after.as_deref(), before, first, last).await?; if let Some(page) = response { for event in page.data { yield event; @@ -644,10 +644,10 @@ impl Client { /// /// let owned_objects = client.objects(None, None, Some(filter), None, None).await; /// ``` - pub async fn objects( - &self, - after: Option, - before: Option, + pub async fn objects<'a>( + &'a self, + after: Option<&'a str>, + before: Option<&'a str>, filter: Option>, first: Option, last: Option, @@ -693,16 +693,17 @@ impl Client { /// Stream objects. pub async fn objects_stream<'a>( &'a self, - after: Option, - before: Option, + after: Option<&'a str>, + before: Option<&'a str>, filter: Option>, first: Option, last: Option, ) -> Pin> + 'a>> { + let after = after.map(|s| s.to_string()); Box::pin(try_stream! { let mut after = after; loop { - let response = self.objects(after, before.clone(), filter.clone(), first, last).await?; + let response = self.objects(after.as_deref(), before, filter.clone(), first, last).await?; if let Some(page) = response { for object in page.data { yield object; @@ -769,10 +770,10 @@ impl Client { } /// Get a page of transactions based on the provided filters. - pub async fn transactions( - &self, - after: Option, - before: Option, + pub async fn transactions<'a>( + &'a self, + after: Option<&'a str>, + before: Option<&'a str>, first: Option, last: Option, filter: Option, @@ -854,16 +855,16 @@ impl Client { /// Stream of transactions based on the provided filters. pub async fn transactions_stream<'a>( &'a self, - after: Option, - before: Option, + after: Option<&'a str>, + before: Option<&'a str>, first: Option, last: Option, filter: Option, ) -> Pin> + 'a>> { + let mut after = after.map(|s| s.to_string()); Box::pin(try_stream! { - let mut after = after; loop { - let response = self.transactions(after, before.clone(), first, last, filter.clone()).await?; + let response = self.transactions(after.as_deref(), before, first, last, filter.clone()).await?; if let Some(page) = response { for tx in page.data { yield tx; diff --git a/crates/sui-graphql-client/src/query_types/events.rs b/crates/sui-graphql-client/src/query_types/events.rs index 3006b9b9a..15f13d7b1 100644 --- a/crates/sui-graphql-client/src/query_types/events.rs +++ b/crates/sui-graphql-client/src/query_types/events.rs @@ -28,10 +28,10 @@ pub struct EventsQuery { // =========================================================================== #[derive(cynic::QueryVariables, Debug)] -pub struct EventsQueryArgs { +pub struct EventsQueryArgs<'a> { pub filter: Option, - pub after: Option, - pub before: Option, + pub after: Option<&'a str>, + pub before: Option<&'a str>, pub first: Option, pub last: Option, } diff --git a/crates/sui-graphql-client/src/query_types/object.rs b/crates/sui-graphql-client/src/query_types/object.rs index c7952738c..cef8250c2 100644 --- a/crates/sui-graphql-client/src/query_types/object.rs +++ b/crates/sui-graphql-client/src/query_types/object.rs @@ -37,8 +37,8 @@ pub struct ObjectQueryArgs { #[derive(cynic::QueryVariables, Debug)] pub struct ObjectsQueryArgs<'a> { - pub after: Option, - pub before: Option, + pub after: Option<&'a str>, + pub before: Option<&'a str>, pub filter: Option>, pub first: Option, pub last: Option, diff --git a/crates/sui-graphql-client/src/query_types/transaction.rs b/crates/sui-graphql-client/src/query_types/transaction.rs index 66d4cbdae..841d89808 100644 --- a/crates/sui-graphql-client/src/query_types/transaction.rs +++ b/crates/sui-graphql-client/src/query_types/transaction.rs @@ -43,11 +43,11 @@ pub struct TransactionBlockArgs { } #[derive(cynic::QueryVariables, Debug)] -pub struct TransactionBlocksQueryArgs { +pub struct TransactionBlocksQueryArgs<'a> { pub first: Option, - pub after: Option, + pub after: Option<&'a str>, pub last: Option, - pub before: Option, + pub before: Option<&'a str>, pub filter: Option, }