From db92b148982174718a5bb8b1a7fb03803b2a15d0 Mon Sep 17 00:00:00 2001 From: Ashok Menon Date: Mon, 13 Nov 2023 15:48:54 +0000 Subject: [PATCH] [GraphQL] Fix default coin type (#14804) ## Description If no coin type is provided, we should default to `0x2::sui::SUI`. Previously we added no filter on the coin type, which meant that we were returning arbitrary objects from the coin connection field. ## Test Plan GraphiQL: --- .../src/context_data/db_data_provider.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/sui-graphql-rpc/src/context_data/db_data_provider.rs b/crates/sui-graphql-rpc/src/context_data/db_data_provider.rs index 8c85c563f4a4d..7ca4388e6561e 100644 --- a/crates/sui-graphql-rpc/src/context_data/db_data_provider.rs +++ b/crates/sui-graphql-rpc/src/context_data/db_data_provider.rs @@ -93,6 +93,7 @@ use sui_types::{ digests::TransactionDigest, dynamic_field::{DynamicFieldType, Field}, event::EventID, + gas_coin::GAS, governance::StakedSui, Identifier, }; @@ -393,7 +394,7 @@ impl QueryBuilder { descending_order: bool, limit: i64, address: Vec, - coin_type: Option, + coin_type: String, ) -> objects::BoxedQuery<'a, Pg> { let mut query = objects::dsl::objects.into_boxed(); if let Some(cursor) = cursor { @@ -412,11 +413,9 @@ impl QueryBuilder { query = query .filter(objects::dsl::owner_id.eq(address)) - .filter(objects::dsl::owner_type.eq(OwnerType::Address as i16)); // Leverage index on objects table + .filter(objects::dsl::owner_type.eq(OwnerType::Address as i16)) // Leverage index on objects table + .filter(objects::dsl::coin_type.eq(coin_type)); - if let Some(coin_type) = coin_type { - query = query.filter(objects::dsl::coin_type.eq(coin_type)); - } query } @@ -695,7 +694,7 @@ impl PgManager { async fn multi_get_coins( &self, address: Vec, - coin_type: Option, + coin_type: String, first: Option, after: Option, last: Option, @@ -1375,6 +1374,9 @@ impl PgManager { before: Option, ) -> Result>, Error> { let address = address.into_vec(); + let coin_type = coin_type.unwrap_or_else(|| { + GAS::type_().to_canonical_string(/* with_prefix */ true) + }); let coins = self .multi_get_coins(address, coin_type, first, after, last, before)