Skip to content

Commit

Permalink
Bump
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Nov 22, 2023
1 parent 1d37585 commit 1d5eafd
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,41 @@ impl Database {
map
})
}

pub async fn get_addresses(
&self,
node: &[u8],
addresses: &[&str],
) -> HashMap<String, Option<String>> {
// require that every record matches /a-zA-Z\./
// if records.iter().any(|x| !x.chars().all(|c| c.is_alphanumeric() || c == '.')) {
// panic!("Invalid record name");
// }

// converts ['avatar', 'header'] to "records->'avatar', records->'header'"
let addresses_raw = addresses.iter().fold(String::new(), |acc, x| {
if acc.is_empty() {
format!("addresses->'{}'", x)
} else {
format!("{}, addresses->'{}'", acc, x)
}
});

let x = self
.client
.query_one(
&format!("SELECT {} FROM ens_data WHERE node = $1", addresses_raw),
&[&node],
)
.await
.unwrap();

addresses
.iter()
.enumerate()
.fold(HashMap::new(), |mut map, (i, record)| {
map.insert(record.to_string(), x.get::<_, Option<String>>(i));
map
})
}
}
23 changes: 23 additions & 0 deletions src/gateway/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ impl UnresolvedQuery<'_> {

vec![Token::String(value)]
}
ResolverFunctionCall::AddrMultichain(_bf, chain) => {
let hash = namehash(&self.name).to_fixed_bytes().to_vec();

info!("Resolving addr record: {:?}", hash);

let x = state.db.get_addresses(&hash, &[&chain.to_string()]).await;

let value = x.get(&chain.to_string()).to_owned().unwrap().clone().unwrap();

vec![Token::String(value)]
}
ResolverFunctionCall::Addr(_bf) => {
let chain = 60;
let hash = namehash(&self.name).to_fixed_bytes().to_vec();

info!("Resolving addr record: {:?}", hash);

let x = state.db.get_addresses(&hash, &[&chain.to_string()]).await;

let value = x.get(&chain.to_string()).to_owned().unwrap().clone().unwrap();

vec![Token::String(value)]
}
_ => Vec::new(),
};

Expand Down

0 comments on commit 1d5eafd

Please sign in to comment.