Skip to content

Commit

Permalink
Merge pull request #69 from starknet-id/fix/resolving
Browse files Browse the repository at this point in the history
Fix/resolving
  • Loading branch information
Th0rgal authored Mar 22, 2024
2 parents 0e3feaf + 033fb55 commit edb7ac2
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 33 deletions.
141 changes: 113 additions & 28 deletions src/endpoints/domain_to_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,119 @@ pub async fn handler(
.starknetid_db
.collection::<mongodb::bson::Document>("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
Expand Down
9 changes: 4 additions & 5 deletions src/endpoints/renewal/get_renewal_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +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 (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();

Expand Down

0 comments on commit edb7ac2

Please sign in to comment.