From 1a6551edfd1d33ee4fbe74352615ead9dfea5c24 Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Thu, 21 Mar 2024 17:06:30 -0300 Subject: [PATCH 1/3] fix: empty domain target when no legacy address --- src/endpoints/domain_to_addr.rs | 141 +++++++++++++++++++++++++------- 1 file changed, 113 insertions(+), 28 deletions(-) diff --git a/src/endpoints/domain_to_addr.rs b/src/endpoints/domain_to_addr.rs index 63c67cc..06da9b1 100644 --- a/src/endpoints/domain_to_addr.rs +++ b/src/endpoints/domain_to_addr.rs @@ -68,34 +68,119 @@ pub async fn handler( .starknetid_db .collection::("domains"); - let pipeline = vec![ - doc! { "$match": { "_cursor.to": null, "domain": query.domain.clone() } }, - doc! { "$lookup": { - "from": "id_user_data", - "let": { "userId": "$id" }, - "pipeline": [ - doc! { "$match": { - "_cursor.to": { "$exists": false }, - "field": "0x000000000000000000000000000000000000000000000000737461726b6e6574", - "$expr": { "$eq": ["$id", "$$userId"] } - } } - ], - "as": "ownerData" - }}, - doc! { "$unwind": { "path": "$ownerData", "preserveNullAndEmptyArrays": true } }, - doc! { "$project": { - "addr": { - "$cond": { - "if": { "$and": [ - { "$ne": [{ "$type": "$legacy_address" }, "0x0000000000000000000000000000000000000000000000000000000000000000"] }, - { "$ne": ["$legacy_address", "0x0000000000000000000000000000000000000000000000000000000000000000"] } - ] }, - "then": "$legacy_address", - "else": "$ownerData.data" - } - }, - "domain_expiry" : "$expiry" - }}, + let pipeline = [ + doc! { + "$match": doc! { + "_cursor.to": null, + "domain": query.domain.clone() + } + }, + doc! { + "$lookup": doc! { + "from": "id_user_data", + "let": doc! { + "userId": "$id" + }, + "pipeline": [ + doc! { + "$match": doc! { + "_cursor.to": doc! { + "$exists": false + }, + "field": "0x000000000000000000000000000000000000000000000000737461726b6e6574", + "$expr": doc! { + "$eq": [ + "$id", + "$$userId" + ] + } + } + } + ], + "as": "userData" + } + }, + doc! { + "$unwind": doc! { + "path": "$userData", + "preserveNullAndEmptyArrays": true + } + }, + doc! { + "$lookup": doc! { + "from": "id_owners", + "let": doc! { + "userId": "$id" + }, + "pipeline": [ + doc! { + "$match": doc! { + "$or": [ + doc! { + "_cursor.to": doc! { + "$exists": false + } + }, + doc! { + "_cursor.to": null + } + ], + "$expr": doc! { + "$eq": [ + "$id", + "$$userId" + ] + } + } + } + ], + "as": "ownerData" + } + }, + doc! { + "$unwind": doc! { + "path": "$ownerData", + "preserveNullAndEmptyArrays": true + } + }, + doc! { + "$project": doc! { + "addr": doc! { + "$cond": doc! { + "if": doc! { + "$and": [ + doc! { + "$ifNull": [ + "$legacy_address", + false + ] + }, + doc! { + "$ne": [ + "$legacy_address", + "0x0000000000000000000000000000000000000000000000000000000000000000" + ] + } + ] + }, + "then": "$legacy_address", + "else": doc! { + "$cond": doc! { + "if": doc! { + "$ifNull": [ + "$userData.data", + false + ] + }, + "then": "$userData.data", + "else": "$ownerData.owner" + } + } + } + }, + "domain_expiry": "$expiry" + } + }, ]; // Execute the aggregation pipeline From 8c1401185bff43cd0c708298362a2366490a2b6d Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Thu, 21 Mar 2024 17:07:39 -0300 Subject: [PATCH 2/3] fix: warning for get renewal data --- src/endpoints/renewal/get_renewal_data.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/endpoints/renewal/get_renewal_data.rs b/src/endpoints/renewal/get_renewal_data.rs index 7bcdef1..321d9d4 100644 --- a/src/endpoints/renewal/get_renewal_data.rs +++ b/src/endpoints/renewal/get_renewal_data.rs @@ -36,7 +36,7 @@ pub async fn handler( ) -> impl IntoResponse { let result_auto_renew_flows = find_renewal_data(&state, "auto_renew_flows", &query).await; - let mut document_to_return = None; + let document_to_return; if let Ok(Some(doc)) = result_auto_renew_flows { if doc.get_bool("enabled").unwrap_or(true) { @@ -52,11 +52,11 @@ pub async fn handler( } } else { let result_altcoins = find_renewal_data(&state, "auto_renew_flows_altcoins", &query) - .await - .ok() - .flatten(); - // we return this document - document_to_return = result_altcoins; + .await + .ok() + .flatten(); + // we return this document + document_to_return = result_altcoins; } let mut headers = HeaderMap::new(); From 033fb5548fe5e5cd4046efc47815f0c832d7b327 Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Fri, 22 Mar 2024 10:24:38 -0300 Subject: [PATCH 3/3] fix: conflict --- src/endpoints/renewal/get_renewal_data.rs | 32 +++-------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/endpoints/renewal/get_renewal_data.rs b/src/endpoints/renewal/get_renewal_data.rs index 27bb41a..1bd6f16 100644 --- a/src/endpoints/renewal/get_renewal_data.rs +++ b/src/endpoints/renewal/get_renewal_data.rs @@ -36,35 +36,11 @@ pub async fn handler( ) -> impl IntoResponse { // Fetch data from both collections and combine the results let auto_renew_flows_future = find_renewal_data(&state, "auto_renew_flows", &query); - let auto_renew_flows_altcoins_future = find_renewal_data(&state, "auto_renew_flows_altcoins", &query); + let auto_renew_flows_altcoins_future = + find_renewal_data(&state, "auto_renew_flows_altcoins", &query); - let document_to_return; - - if let Ok(Some(doc)) = result_auto_renew_flows { - if doc.get_bool("enabled").unwrap_or(true) { - // If enabled is true, return this document - document_to_return = Some(doc); - } else { - // If enabled is false, check auto_renew_flows_altcoins but keep this document as a fallback. - let result_altcoins = find_renewal_data(&state, "auto_renew_flows_altcoins", &query) - .await - .ok() - .flatten(); - document_to_return = result_altcoins.or(Some(doc)); // Use the altcoins result or fallback to the original document. - } - } else { - let result_altcoins = find_renewal_data(&state, "auto_renew_flows_altcoins", &query) - .await - .ok() - .flatten(); - // we return this document - document_to_return = result_altcoins; - } - - let (auto_renew_flows, auto_renew_flows_altcoins) = futures::join!( - auto_renew_flows_future, - auto_renew_flows_altcoins_future - ); + let (auto_renew_flows, auto_renew_flows_altcoins) = + futures::join!(auto_renew_flows_future, auto_renew_flows_altcoins_future); let mut combined_results = Vec::new();