diff --git a/blockscout-ens/bens-logic/src/subgraphs_reader/domain_name.rs b/blockscout-ens/bens-logic/src/subgraphs_reader/domain_name.rs new file mode 100644 index 000000000..990b72fd3 --- /dev/null +++ b/blockscout-ens/bens-logic/src/subgraphs_reader/domain_name.rs @@ -0,0 +1,16 @@ +use super::sql; +use sqlx::PgPool; +use std::sync::Arc; + +pub async fn fix_domain_name(pool: Arc, schema: &str, domain_name: &str, domain_id: &str) { + match sql::update_domain_name(pool.as_ref(), schema, domain_id, domain_name).await { + Ok(r) => { + tracing::info!( + rows_affected = r.rows_affected(), + name = domain_name, + "successfuly updated domain name" + ); + } + Err(err) => tracing::error!(name = domain_name, "cannot update domain name: {err}"), + } +} diff --git a/blockscout-ens/bens-logic/src/subgraphs_reader/mod.rs b/blockscout-ens/bens-logic/src/subgraphs_reader/mod.rs index 91397ae3b..94f4c4537 100644 --- a/blockscout-ens/bens-logic/src/subgraphs_reader/mod.rs +++ b/blockscout-ens/bens-logic/src/subgraphs_reader/mod.rs @@ -1,4 +1,5 @@ pub mod blockscout; +mod domain_name; mod reader; mod schema_selector; mod sql; diff --git a/blockscout-ens/bens-logic/src/subgraphs_reader/reader.rs b/blockscout-ens/bens-logic/src/subgraphs_reader/reader.rs index 1ea1abf13..c03a99bbd 100644 --- a/blockscout-ens/bens-logic/src/subgraphs_reader/reader.rs +++ b/blockscout-ens/bens-logic/src/subgraphs_reader/reader.rs @@ -1,5 +1,6 @@ use super::{ blockscout::{self, BlockscoutClient}, + domain_name::fix_domain_name, schema_selector::subgraph_deployments, sql::{self}, BatchResolveAddressNamesInput, GetDomainHistoryInput, GetDomainInput, LookupAddressInput, @@ -175,17 +176,16 @@ impl SubgraphReader { let id = domain_id(&input.name, subgraph.settings.empty_label_hash.clone()); let domain = sql::get_domain(self.pool.as_ref(), &id, &subgraph.schema_name, &input) .await? - .map(|mut domain| { - domain.other_addresses = sqlx::types::Json( - domain - .other_addresses - .0 - .into_iter() - .map(|(coin_type, address)| (coin_name(&coin_type), address)) - .collect(), - ); - domain + .map(|domain| { + patch_detailed_domain( + self.pool.clone(), + &subgraph.schema_name, + domain, + &input.name, + &id, + ) }); + Ok(domain) } @@ -217,13 +217,21 @@ impl SubgraphReader { .ok_or_else(|| SubgraphReadError::NetworkNotFound(input.network_id))?; let subgraph = &network.default_subgraph; let id = domain_id(&input.name, subgraph.settings.empty_label_hash.clone()); - sql::find_domains( - self.pool.as_ref(), - &network.default_subgraph.schema_name, - &id, - &input, - ) - .await + let domains = sql::find_domains(self.pool.as_ref(), &subgraph.schema_name, &id, &input) + .await? + .into_iter() + .map(|domain| { + patch_domain( + self.pool.clone(), + &subgraph.schema_name, + domain, + &input.name, + &id, + ) + }) + .collect(); + + Ok(domains) } pub async fn lookup_address( @@ -311,14 +319,76 @@ async fn events_from_transactions( Ok(events) } +macro_rules! build_fix_domain_name_function { + ($fn_name:tt, $struct_name:ident) => { + fn $fn_name( + pool: Arc, + schema: &str, + mut domain: $struct_name, + input_name: &str, + input_id: &str, + ) -> $struct_name { + if domain.name.as_deref() != Some(input_name) && input_id == domain.id { + tracing::warn!( + domain_id = domain.id, + input_name = input_name, + domain_name = domain.name, + "domain has invalid name, creating task to fix to" + ); + domain.name = Some(input_name.to_string()); + let input_name = input_name.to_string(); + let input_id = input_id.to_string(); + let schema = schema.to_string(); + tokio::spawn(async move { + fix_domain_name(pool, &schema, &input_name, &input_id).await; + }); + } + domain + } + }; +} + +build_fix_domain_name_function!(fix_domain_main, Domain); +fn patch_domain( + pool: Arc, + schema: &str, + domain: Domain, + input_name: &str, + input_id: &str, +) -> Domain { + fix_domain_main(pool, schema, domain, input_name, input_id) +} + +build_fix_domain_name_function!(fix_detailed_domain_name, DetailedDomain); +fn patch_detailed_domain( + pool: Arc, + schema: &str, + domain: DetailedDomain, + input_name: &str, + input_id: &str, +) -> DetailedDomain { + let mut domain = fix_detailed_domain_name(pool, schema, domain, input_name, input_id); + domain.other_addresses = sqlx::types::Json( + domain + .other_addresses + .0 + .into_iter() + .map(|(coin_type, address)| (coin_name(&coin_type), address)) + .collect(), + ); + domain +} + #[cfg(test)] mod tests { - use crate::test_utils::mocked_networks_with_blockscout; - use super::*; + use crate::{subgraphs_reader::sql, test_utils::mocked_networks_with_blockscout}; use ethers::types::Address; use pretty_assertions::assert_eq; + const DEFAULT_CHAIN_ID: i64 = 1; + const DEFAULT_SCHEMA: &str = "sgd1"; + #[sqlx::test(migrations = "tests/migrations")] async fn get_domain_works(pool: PgPool) { let pool = Arc::new(pool); @@ -331,7 +401,7 @@ mod tests { let name = "vitalik.eth".to_string(); let result = reader .get_domain(GetDomainInput { - network_id: 1, + network_id: DEFAULT_CHAIN_ID, name, only_active: false, }) @@ -354,7 +424,7 @@ mod tests { let name = "expired.eth".to_string(); let result = reader .get_domain(GetDomainInput { - network_id: 1, + network_id: DEFAULT_CHAIN_ID, name: name.clone(), only_active: false, }) @@ -372,7 +442,7 @@ mod tests { // get expired domain with only_active filter let result = reader .get_domain(GetDomainInput { - network_id: 1, + network_id: DEFAULT_CHAIN_ID, name, only_active: true, }) @@ -395,7 +465,7 @@ mod tests { let result = reader .lookup_domain(LookupDomainInput { - network_id: 1, + network_id: DEFAULT_CHAIN_ID, name: "vitalik.eth".to_string(), only_active: false, sort: Default::default(), @@ -419,7 +489,7 @@ mod tests { let result = reader .lookup_address(LookupAddressInput { - network_id: 1, + network_id: DEFAULT_CHAIN_ID, address: addr("0xd8da6bf26964af9d7eed9e03e53415d37aa96045"), resolved_to: true, owned_by: false, @@ -436,7 +506,7 @@ mod tests { let result = reader .lookup_address(LookupAddressInput { - network_id: 1, + network_id: DEFAULT_CHAIN_ID, address: addr("0xd8da6bf26964af9d7eed9e03e53415d37aa96045"), resolved_to: false, owned_by: true, @@ -454,7 +524,7 @@ mod tests { // search for expired address let result = reader .lookup_address(LookupAddressInput { - network_id: 1, + network_id: DEFAULT_CHAIN_ID, address: addr("0x9f7f7ddbfb8e14d1756580ba8037530da0880b99"), resolved_to: true, owned_by: true, @@ -472,7 +542,7 @@ mod tests { // search for expired address with only_active let result = reader .lookup_address(LookupAddressInput { - network_id: 1, + network_id: DEFAULT_CHAIN_ID, address: addr("0x9f7f7ddbfb8e14d1756580ba8037530da0880b99"), resolved_to: true, owned_by: true, @@ -499,7 +569,7 @@ mod tests { let name = "vitalik.eth".to_string(); let history = reader .get_domain_history(GetDomainHistoryInput { - network_id: 1, + network_id: DEFAULT_CHAIN_ID, name, sort: Default::default(), order: Default::default(), @@ -595,6 +665,8 @@ mod tests { "0x9c996076a85b46061d9a70ff81f013853a86b619", // not in database "0x0000000000000000000000000000000000000000", + // unresolved domain (labelname is not resolved) + "0x0101010101010101010101010101010101010101", ] .into_iter() .map(addr) @@ -607,7 +679,7 @@ mod tests { .unwrap(); let domains = reader .batch_resolve_address_names(BatchResolveAddressNamesInput { - network_id: 1, + network_id: DEFAULT_CHAIN_ID, addresses, }) .await @@ -615,6 +687,64 @@ mod tests { assert_eq!(domains, expected_domains); } + #[sqlx::test(migrations = "tests/migrations")] + async fn fix_domain_name_works(pool: PgPool) { + let unresolved = "you-dont-know-this-label.eth"; + let pool = Arc::new(pool); + let networks = mocked_networks_with_blockscout().await; + let reader = SubgraphReader::initialize(pool.clone(), networks) + .await + .expect("failed to init reader"); + + // Make sure that database contains unresolved domain + let domain = sql::get_domain( + pool.as_ref(), + &domain_id(unresolved, None), + DEFAULT_SCHEMA, + &GetDomainInput { + network_id: DEFAULT_CHAIN_ID, + name: unresolved.to_string(), + only_active: false, + }, + ) + .await + .expect("failed to get domain") + .expect("unresolved domain not found using sql"); + assert_eq!( + domain.name.as_deref(), + Some("[0b0e081f36b3970ff8e337f0ff7bdfad321a702fa00916b6ccfc47877144f7ad].eth") + ); + + // After reader requests domain should be resolved + let domain = reader + .get_domain(GetDomainInput { + network_id: DEFAULT_CHAIN_ID, + name: unresolved.to_string(), + only_active: false, + }) + .await + .expect("failed to get domain") + .expect("unresolved domain not found using reader"); + assert_eq!(domain.name.as_deref(), Some(unresolved)); + + // Make sure that unresolved name in database became resolved + tokio::time::sleep(std::time::Duration::from_millis(500)).await; + let domain = sql::get_domain( + pool.as_ref(), + &domain_id(unresolved, None), + DEFAULT_SCHEMA, + &GetDomainInput { + network_id: DEFAULT_CHAIN_ID, + name: unresolved.to_string(), + only_active: false, + }, + ) + .await + .expect("failed to get domain") + .expect("unresolved domain not found using sql"); + assert_eq!(domain.name.as_deref(), Some(unresolved)); + } + fn addr(a: &str) -> Address { let a = a.trim_start_matches("0x"); Address::from_slice( diff --git a/blockscout-ens/bens-logic/src/subgraphs_reader/sql/address_names.rs b/blockscout-ens/bens-logic/src/subgraphs_reader/sql/address_names.rs index 0adf30e09..ef4d12d8c 100644 --- a/blockscout-ens/bens-logic/src/subgraphs_reader/sql/address_names.rs +++ b/blockscout-ens/bens-logic/src/subgraphs_reader/sql/address_names.rs @@ -2,7 +2,10 @@ use crate::subgraphs_reader::SubgraphReadError; use sqlx::{postgres::PgPool, Executor}; use tracing::instrument; -use super::{DOMAIN_DEFAULT_WHERE_CLAUSE, DOMAIN_NOT_EXPIRED_WHERE_CLAUSE}; +use super::{ + DOMAIN_BLOCK_RANGE_WHERE_CLAUSE, DOMAIN_NONEMPTY_LABEL_WHERE_CLAUSE, + DOMAIN_NOT_EXPIRED_WHERE_CLAUSE, +}; #[instrument( name = "create_address_names_view", @@ -27,7 +30,8 @@ pub async fn create_address_names_view( where resolved_address IS NOT NULL AND name NOT LIKE '%[%' - AND {DOMAIN_DEFAULT_WHERE_CLAUSE} + AND {DOMAIN_BLOCK_RANGE_WHERE_CLAUSE} + AND {DOMAIN_NONEMPTY_LABEL_WHERE_CLAUSE} AND {DOMAIN_NOT_EXPIRED_WHERE_CLAUSE} ORDER BY resolved_address, created_at "#, diff --git a/blockscout-ens/bens-logic/src/subgraphs_reader/sql/domain.rs b/blockscout-ens/bens-logic/src/subgraphs_reader/sql/domain.rs index 7925381d9..5b82fa8f7 100644 --- a/blockscout-ens/bens-logic/src/subgraphs_reader/sql/domain.rs +++ b/blockscout-ens/bens-logic/src/subgraphs_reader/sql/domain.rs @@ -3,7 +3,7 @@ use crate::{ hash_name::hex, subgraphs_reader::{GetDomainInput, LookupAddressInput, LookupDomainInput, SubgraphReadError}, }; -use sqlx::postgres::PgPool; +use sqlx::postgres::{PgPool, PgQueryResult}; use tracing::instrument; const DETAILED_DOMAIN_DEFAULT_SELECT_CLAUSE: &str = r#" @@ -40,10 +40,9 @@ COALESCE(to_timestamp(expiry_date) < now(), false) AS is_expired // `block_range @>` is special sql syntax for fast filtering int4range // to access current version of domain. // Source: https://github.com/graphprotocol/graph-node/blob/19fd41bb48511f889dc94f5d82e16cd492f29da1/store/postgres/src/block_range.rs#L26 -pub const DOMAIN_DEFAULT_WHERE_CLAUSE: &str = r#" -label_name IS NOT NULL -AND block_range @> 2147483647 -"#; +pub const DOMAIN_BLOCK_RANGE_WHERE_CLAUSE: &str = "block_range @> 2147483647"; + +pub const DOMAIN_NONEMPTY_LABEL_WHERE_CLAUSE: &str = "label_name IS NOT NULL"; pub const DOMAIN_NOT_EXPIRED_WHERE_CLAUSE: &str = r#" ( @@ -86,7 +85,7 @@ pub async fn get_domain( ) multi_coin_addresses ON {schema}.domain.id = multi_coin_addresses.domain_id WHERE id = $1 - AND {DOMAIN_DEFAULT_WHERE_CLAUSE} + AND {DOMAIN_BLOCK_RANGE_WHERE_CLAUSE} {only_active_clause} ;"#, )) @@ -120,7 +119,7 @@ pub async fn find_domains( FROM {schema}.domain WHERE id = $1 - AND {DOMAIN_DEFAULT_WHERE_CLAUSE} + AND {DOMAIN_BLOCK_RANGE_WHERE_CLAUSE} {only_active_clause} ORDER BY {sort} {order} "#, @@ -168,7 +167,8 @@ pub async fn find_resolved_addresses( {resolved_to_clause} {owned_by_clause} ) - AND {DOMAIN_DEFAULT_WHERE_CLAUSE} + AND {DOMAIN_BLOCK_RANGE_WHERE_CLAUSE} + AND {DOMAIN_NONEMPTY_LABEL_WHERE_CLAUSE} {only_active_clause} ORDER BY {sort} {order} LIMIT 100 @@ -200,7 +200,8 @@ pub async fn batch_search_addresses( WHERE resolved_address = ANY($1) AND name NOT LIKE '%[%' - AND {DOMAIN_DEFAULT_WHERE_CLAUSE} + AND {DOMAIN_BLOCK_RANGE_WHERE_CLAUSE} + AND {DOMAIN_NONEMPTY_LABEL_WHERE_CLAUSE} AND {DOMAIN_NOT_EXPIRED_WHERE_CLAUSE} ORDER BY resolved_address, created_at "#, @@ -238,3 +239,25 @@ pub async fn batch_search_addresses_cached( Ok(domains) } + +#[instrument( + name = "update_domain_name", + skip(pool), + err(level = "error"), + level = "info" +)] +pub async fn update_domain_name( + pool: &PgPool, + schema: &str, + id: &str, + name: &str, +) -> Result { + let result = sqlx::query(&format!( + "UPDATE {schema}.domain SET name = $1 WHERE id = $2;" + )) + .bind(name) + .bind(id) + .execute(pool) + .await?; + Ok(result) +} diff --git a/blockscout-ens/bens-logic/tests/migrations/20231019103631_push_mock_data.sql b/blockscout-ens/bens-logic/tests/migrations/20231019103631_push_mock_data.sql index fb0c8f3ce..dee2b7fc8 100644 --- a/blockscout-ens/bens-logic/tests/migrations/20231019103631_push_mock_data.sql +++ b/blockscout-ens/bens-logic/tests/migrations/20231019103631_push_mock_data.sql @@ -56,7 +56,9 @@ VALUES (23,'[13695732,)','0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835','vitalik.eth','vitalik','\xAF2CAA1C2CA1D027F1AC823B529D0A67CD144264B2789FA2EA4D63A67C7103CC','0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae',0,'0xd8da6bf26964af9d7eed9e03e53415d37aa96045','0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41-0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835',NULL,true,1497775154,'0xd8da6bf26964af9d7eed9e03e53415d37aa96045','0x220866b1a2219f40e72f5c628b65d54268ca3a9d',NULL,1975009824), (24,'[13942919,)','0x68b620f61c87062cf680144f898582a631c90e39dd1badb35c241be0a7284fff','sashaxyz.eth','sashaxyz','\x5F5E95F7A849C60A514EB073C6FAFE97E835C0EE7B6DC15FC9D7DAA9E86F1A25','0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae',0,'0xd8da6bf26964af9d7eed9e03e53415d37aa96045','0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41-0x68b620f61c87062cf680144f898582a631c90e39dd1badb35c241be0a7284fff',NULL,true,1640341437,'0x66a6f7744ce4dea450910b81a7168588f992eafb','0x66a6f7744ce4dea450910b81a7168588f992eafb',NULL,1711231341), (25,'[12439863,)','0x86f0774249ae1b7dcb5873ac0ada288d09ec4b3bf8bbf672b67726793797142e','expired.eth','expired','\x64CA1AE50619F7F4AB23F4C22C6B85B70CFC49C072D731BE4F91487F95764C93','0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae',0,'0x9f7f7ddbfb8e14d1756580ba8037530da0880b99','0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41-0x86f0774249ae1b7dcb5873ac0ada288d09ec4b3bf8bbf672b67726793797142e',NULL,true,1496998132,'0x9f7f7ddbfb8e14d1756580ba8037530da0880b99','0x9f7f7ddbfb8e14d1756580ba8037530da0880b99',NULL,1688547600), -(26,'[13601083,)','0x5d438d292de31e08576d5bcd8a93aa41b401b9d9aeaba57da1a32c003e5fd5f5','wa🇬🇲i.eth','wa🇬🇲i','\x66F484A3530B784F2347DE3459625585DA2B38B429596364B98186B1C5E30180','0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae',0,'0x9c996076a85b46061d9a70ff81f013853a86b619','0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41-0x5d438d292de31e08576d5bcd8a93aa41b401b9d9aeaba57da1a32c003e5fd5f5',NULL,true,1636717006,'0x9c996076a85b46061d9a70ff81f013853a86b619','0x9c996076a85b46061d9a70ff81f013853a86b619',NULL,1802277766) +(26,'[13601083,)','0x5d438d292de31e08576d5bcd8a93aa41b401b9d9aeaba57da1a32c003e5fd5f5','wa🇬🇲i.eth','wa🇬🇲i','\x66F484A3530B784F2347DE3459625585DA2B38B429596364B98186B1C5E30180','0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae',0,'0x9c996076a85b46061d9a70ff81f013853a86b619','0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41-0x5d438d292de31e08576d5bcd8a93aa41b401b9d9aeaba57da1a32c003e5fd5f5',NULL,true,1636717006,'0x9c996076a85b46061d9a70ff81f013853a86b619','0x9c996076a85b46061d9a70ff81f013853a86b619',NULL,1802277766), +-- this is unresolved domain `you-dont-know-this-label.eth` +(27,'[13601083,)','0xbbe8c4a4631586c84c5b07cdfcbe27f5131ae9dc0176f8ecd324f9b6c5db777b','[0b0e081f36b3970ff8e337f0ff7bdfad321a702fa00916b6ccfc47877144f7ad].eth',NULL,'\x0b0e081f36b3970ff8e337f0ff7bdfad321a702fa00916b6ccfc47877144f7ad','0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae',0,'0x0101010101010101010101010101010101010101','0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41-0xbbe8c4a4631586c84c5b07cdfcbe27f5131ae9dc0176f8ecd324f9b6c5db777b',NULL,true,1636717006,'0x9c996076a85b46061d9a70ff81f013853a86b619','0x9c996076a85b46061d9a70ff81f013853a86b619',NULL,1802277766) ; -- vitalik.eth events diff --git a/blockscout-ens/bens-proto/build.rs b/blockscout-ens/bens-proto/build.rs index 95e722bb6..2b080998d 100644 --- a/blockscout-ens/bens-proto/build.rs +++ b/blockscout-ens/bens-proto/build.rs @@ -18,6 +18,10 @@ fn compile( .bytes(["."]) .btree_map(["."]) .type_attribute(".", "#[actix_prost_macros::serde]") + .field_attribute( + ".blockscout.bens.v1.GetDomainRequest.only_active", + "#[serde(default)]" + ) .field_attribute( ".blockscout.bens.v1.ListDomainEventsRequest.sort", "#[serde(default)]" diff --git a/blockscout-ens/bens-proto/proto/bens.proto b/blockscout-ens/bens-proto/proto/bens.proto index 6a4abd4a6..875e9dd20 100644 --- a/blockscout-ens/bens-proto/proto/bens.proto +++ b/blockscout-ens/bens-proto/proto/bens.proto @@ -69,9 +69,6 @@ message Address { string hash = 1; } -message Pagination { - uint32 total_records = 1; -} enum Order { ASC = 0; @@ -85,6 +82,8 @@ message GetDomainRequest { string name = 1; // The chain (network) where domain search should be done int64 chain_id = 2; + // Filtering field to remove expired domains + bool only_active = 3; } message ListDomainEventsRequest { @@ -100,7 +99,7 @@ message ListDomainEventsRequest { message ListDomainEventsResponse { repeated DomainEvent items = 1; - Pagination pagination = 2; + uint32 total_records = 2; } message LookupDomainNameRequest { @@ -120,7 +119,7 @@ message LookupDomainNameResponse { // List of domains that resolved to or owned by requested address // Sorted by relevance, so first address could be displayed as main resolved address repeated Domain items = 1; - Pagination pagination = 2; + uint32 total_records = 2; } message LookupAddressRequest { @@ -144,7 +143,7 @@ message LookupAddressResponse { // List of domains that resolved to or owned by requested address // Sorted by relevance, so first address could be displayed as main resolved address repeated Domain items = 1; - Pagination pagination = 2; + uint32 total_records = 2; } message BatchResolveAddressNamesRequest { diff --git a/blockscout-ens/bens-proto/swagger/bens.swagger.yaml b/blockscout-ens/bens-proto/swagger/bens.swagger.yaml index d2791880c..675a62aa5 100644 --- a/blockscout-ens/bens-proto/swagger/bens.swagger.yaml +++ b/blockscout-ens/bens-proto/swagger/bens.swagger.yaml @@ -114,6 +114,11 @@ paths: in: path required: true type: string + - name: onlyActive + description: Filtering field to remove expired domains + in: query + required: false + type: boolean tags: - DomainsExtractor /api/v1/{chainId}/domains/{name}/events: @@ -343,8 +348,9 @@ definitions: items: type: object $ref: '#/definitions/v1DomainEvent' - pagination: - $ref: '#/definitions/v1Pagination' + totalRecords: + type: integer + format: int64 v1LookupAddressResponse: type: object properties: @@ -356,8 +362,9 @@ definitions: title: |- List of domains that resolved to or owned by requested address Sorted by relevance, so first address could be displayed as main resolved address - pagination: - $ref: '#/definitions/v1Pagination' + totalRecords: + type: integer + format: int64 v1LookupDomainNameResponse: type: object properties: @@ -369,17 +376,12 @@ definitions: title: |- List of domains that resolved to or owned by requested address Sorted by relevance, so first address could be displayed as main resolved address - pagination: - $ref: '#/definitions/v1Pagination' + totalRecords: + type: integer + format: int64 v1Order: type: string enum: - ASC - DESC default: ASC - v1Pagination: - type: object - properties: - totalRecords: - type: integer - format: int64 diff --git a/blockscout-ens/bens-server/src/conversion/domain.rs b/blockscout-ens/bens-server/src/conversion/domain.rs index 3e5a0da42..a4b431af3 100644 --- a/blockscout-ens/bens-server/src/conversion/domain.rs +++ b/blockscout-ens/bens-server/src/conversion/domain.rs @@ -19,7 +19,7 @@ pub fn get_domain_input_from_inner( Ok(GetDomainInput { network_id: inner.chain_id, name: inner.name, - only_active: true, + only_active: inner.only_active, }) } diff --git a/blockscout-ens/bens-server/src/services/domain_extractor.rs b/blockscout-ens/bens-server/src/services/domain_extractor.rs index 94dcad5f4..b556395e7 100644 --- a/blockscout-ens/bens-server/src/services/domain_extractor.rs +++ b/blockscout-ens/bens-server/src/services/domain_extractor.rs @@ -8,7 +8,7 @@ use bens_proto::blockscout::bens::v1::{ domains_extractor_server::DomainsExtractor, BatchResolveAddressNamesRequest, BatchResolveAddressNamesResponse, DetailedDomain, Domain, DomainEvent, GetDomainRequest, ListDomainEventsRequest, ListDomainEventsResponse, LookupAddressRequest, LookupAddressResponse, - LookupDomainNameRequest, LookupDomainNameResponse, Pagination, + LookupDomainNameRequest, LookupDomainNameResponse, }; use std::sync::Arc; @@ -60,9 +60,7 @@ impl DomainsExtractor for DomainsExtractorService { .collect::>() .map_err(map_convertion_error)?; let response = ListDomainEventsResponse { - pagination: Some(Pagination { - total_records: events.len() as u32, - }), + total_records: events.len() as u32, items: events, }; Ok(tonic::Response::new(response)) @@ -78,9 +76,7 @@ impl DomainsExtractor for DomainsExtractorService { let result = self.subgraph_reader.lookup_domain(input).await; let domains = from_resolved_domains_result(result)?; let response = LookupDomainNameResponse { - pagination: Some(Pagination { - total_records: domains.len() as u32, - }), + total_records: domains.len() as u32, items: domains, }; Ok(tonic::Response::new(response)) @@ -95,9 +91,7 @@ impl DomainsExtractor for DomainsExtractorService { let result = self.subgraph_reader.lookup_address(input).await; let items = from_resolved_domains_result(result)?; let response = LookupAddressResponse { - pagination: Some(Pagination { - total_records: items.len() as u32, - }), + total_records: items.len() as u32, items, }; Ok(tonic::Response::new(response)) diff --git a/blockscout-ens/bens-server/tests/domains.rs b/blockscout-ens/bens-server/tests/domains.rs index c0f81fcf4..acb6aaa92 100644 --- a/blockscout-ens/bens-server/tests/domains.rs +++ b/blockscout-ens/bens-server/tests/domains.rs @@ -317,9 +317,7 @@ async fn expect_list_results(base: &Url, route: &str, route_desc: &str, items: V request, json!({ "items": items, - "pagination": { - "totalRecords": items.len() - } + "totalRecords": items.len() }) ); @@ -330,9 +328,7 @@ async fn expect_list_results(base: &Url, route: &str, route_desc: &str, items: V request, json!({ "items": reversed_items, - "pagination": { - "totalRecords": reversed_items.len() - } + "totalRecords": reversed_items.len() }) ); } @@ -343,9 +339,7 @@ async fn expect_lookup_results(base: &Url, route: &str, mut payload: Value, item request, json!({ "items": items, - "pagination": { - "totalRecords": items.len() - } + "totalRecords": items.len() }) ); payload @@ -359,9 +353,7 @@ async fn expect_lookup_results(base: &Url, route: &str, mut payload: Value, item request, json!({ "items": reversed_items, - "pagination": { - "totalRecords": reversed_items.len() - } + "totalRecords": reversed_items.len() }) ); }