From 45d90a8c0a23f236cb03a978997d848f0d42ca00 Mon Sep 17 00:00:00 2001 From: Lymarenko Lev Date: Wed, 27 Dec 2023 21:49:11 +0700 Subject: [PATCH] Allow pagination be null and update BSL --- blockscout-ens/Cargo.lock | 29 ++++++++++--------- blockscout-ens/bens-proto/proto/bens.proto | 2 +- blockscout-ens/bens-server/Cargo.toml | 4 +-- .../bens-server/src/conversion/domain.rs | 10 +++++++ .../src/services/domain_extractor.rs | 16 +++------- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/blockscout-ens/Cargo.lock b/blockscout-ens/Cargo.lock index cccdf94a3..cdec17bc4 100644 --- a/blockscout-ens/Cargo.lock +++ b/blockscout-ens/Cargo.lock @@ -758,12 +758,13 @@ dependencies = [ [[package]] name = "blockscout-service-launcher" version = "0.10.0" -source = "git+https://github.com/blockscout/blockscout-rs?rev=22ba428#22ba428341212b9169e20a434702e38c229b2731" +source = "git+https://github.com/blockscout/blockscout-rs?rev=bad8909#bad890945329ee9a6b4e23be0c3ca67b77af81d9" dependencies = [ "actix-cors", "actix-web", "actix-web-prom", "anyhow", + "blockscout-tracing-actix-web", "cfg-if", "config", "futures", @@ -779,13 +780,25 @@ dependencies = [ "tokio", "tonic", "tracing", - "tracing-actix-web", "tracing-opentelemetry", "tracing-subscriber", "url", "uuid 1.5.0", ] +[[package]] +name = "blockscout-tracing-actix-web" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e9c18637c495cd78f0ba302727ca0be4f068a3a03633371c5bd1d8c0e9f1e6c" +dependencies = [ + "actix-web", + "mutually_exclusive_features", + "pin-project", + "tracing", + "uuid 1.5.0", +] + [[package]] name = "borsh" version = "0.10.3" @@ -5924,18 +5937,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "tracing-actix-web" -version = "0.7.9" -source = "git+https://github.com/blockscout/tracing-actix-web?branch=rimrakhimov/update-traces-for-services#66479b061021745b523eb48d0f5ae377233606e9" -dependencies = [ - "actix-web", - "mutually_exclusive_features", - "pin-project", - "tracing", - "uuid 1.5.0", -] - [[package]] name = "tracing-attributes" version = "0.1.26" diff --git a/blockscout-ens/bens-proto/proto/bens.proto b/blockscout-ens/bens-proto/proto/bens.proto index 8ea84e7f4..29e8ee6ae 100644 --- a/blockscout-ens/bens-proto/proto/bens.proto +++ b/blockscout-ens/bens-proto/proto/bens.proto @@ -81,7 +81,7 @@ enum Order { } message Pagination { - optional string page_token = 1; + string page_token = 1; uint32 page_size = 2; } diff --git a/blockscout-ens/bens-server/Cargo.toml b/blockscout-ens/bens-server/Cargo.toml index f7d2cd2c6..f87acf80d 100644 --- a/blockscout-ens/bens-server/Cargo.toml +++ b/blockscout-ens/bens-server/Cargo.toml @@ -12,7 +12,7 @@ bens-logic = { path = "../bens-logic" } actix-web = "4.2" anyhow = "1.0" blockscout-display-bytes = "1.0" -blockscout-service-launcher = { git = "https://github.com/blockscout/blockscout-rs", rev = "22ba428", features = ["database-0_12"] } +blockscout-service-launcher = { git = "https://github.com/blockscout/blockscout-rs", rev = "bad8909", features = ["database-0_12"] } config = "0.13" ethers = "2.0.0" serde = "1.0" @@ -38,6 +38,6 @@ features = [ [dev-dependencies] bens-logic = { path = "../bens-logic", features = ["test-utils"] } -blockscout-service-launcher = { git = "https://github.com/blockscout/blockscout-rs", rev = "22ba428", features = [ "database-0_12", "test-server" ] } +blockscout-service-launcher = { git = "https://github.com/blockscout/blockscout-rs", rev = "bad8909", features = [ "database-0_12", "test-server" ] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } pretty_assertions = "1.4.0" diff --git a/blockscout-ens/bens-server/src/conversion/domain.rs b/blockscout-ens/bens-server/src/conversion/domain.rs index 711de8faa..9c9101cd3 100644 --- a/blockscout-ens/bens-server/src/conversion/domain.rs +++ b/blockscout-ens/bens-server/src/conversion/domain.rs @@ -133,6 +133,16 @@ pub fn domain_from_logic(d: Domain) -> Result { }) } +pub fn pagination_from_logic( + page_token: Option, + page_size: u32, +) -> Option { + page_token.map(|page_token| proto::Pagination { + page_size, + page_token, + }) +} + fn address_from_str_inner(addr: &str) -> Result { Address::from_str(addr) .map_err(|e| ConversionError::UserRequest(format!("invalid address '{addr}': {e}"))) diff --git a/blockscout-ens/bens-server/src/services/domain_extractor.rs b/blockscout-ens/bens-server/src/services/domain_extractor.rs index addaf9a7b..67f08ea1a 100644 --- a/blockscout-ens/bens-server/src/services/domain_extractor.rs +++ b/blockscout-ens/bens-server/src/services/domain_extractor.rs @@ -1,4 +1,4 @@ -use crate::conversion::{self, batch_resolve_from_inner, ConversionError}; +use crate::conversion::{self, batch_resolve_from_inner, pagination_from_logic, ConversionError}; use async_trait::async_trait; use bens_logic::{ entity, @@ -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; @@ -76,14 +76,10 @@ impl DomainsExtractor for DomainsExtractorService { .lookup_domain_name(input) .await .map_err(map_subgraph_error)?; - let page_token = result.next_page_token; let domains = from_resolved_domains_result(result.items)?; let response = LookupDomainNameResponse { items: domains, - next_page_params: Some(Pagination { - page_token, - page_size, - }), + next_page_params: pagination_from_logic(result.next_page_token, page_size), }; Ok(tonic::Response::new(response)) } @@ -100,14 +96,10 @@ impl DomainsExtractor for DomainsExtractorService { .lookup_address(input) .await .map_err(map_subgraph_error)?; - let page_token = result.next_page_token; let items = from_resolved_domains_result(result.items)?; let response = LookupAddressResponse { items, - next_page_params: Some(Pagination { - page_token, - page_size, - }), + next_page_params: pagination_from_logic(result.next_page_token, page_size), }; Ok(tonic::Response::new(response)) }