Skip to content

Commit

Permalink
Upgrade jsonrpsee to latest (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xh3rman authored Dec 21, 2023
1 parent 2800fa6 commit 75e0be0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
17 changes: 8 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ hmac = { version = "0.12.1" }
sha2 = { version = "0.10.8" }
strum = { version = "0.25.0", features = ["derive"] }
strum_macros = "0.25"
jsonrpsee = { version = "0.20.3", features = ["http-client"] }
jsonrpsee = { version = "0.21.0", features = ["http-client"] }
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
itoa = { version = "1.0.10" }
curve25519-dalek = { version = "4.1.1" }
4 changes: 2 additions & 2 deletions blockchain/src/solana/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl ChainProvider for SolanaClient {
"rewards": false
}),
];
let block: Result<BlockTransactions, jsonrpsee::core::Error> =
let block: Result<BlockTransactions, jsonrpsee::core::ClientError> =
self.client.request("getBlock", params).await;
match block {
Ok(block) => {
Expand All @@ -276,7 +276,7 @@ impl ChainProvider for SolanaClient {
Ok(transactions)
}
Err(err) => match err {
jsonrpsee::core::Error::Call(err) => {
jsonrpsee::core::ClientError::Call(err) => {
let errors = [
MISSING_SLOT_ERROR,
NOT_AVAILABLE_SLOT_ERROR,
Expand Down
24 changes: 17 additions & 7 deletions name_resolver/src/ens_provider/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::namehash::namehash;
use jsonrpsee::core::{client::ClientT, Error};
use jsonrpsee::core::client::ClientT;
use jsonrpsee::core::ClientError;
use jsonrpsee::http_client::HttpClient;
use primitives::keccak::keccak256;
use serde_json::json;
Expand All @@ -10,34 +11,43 @@ pub struct Contract {
}

impl Contract {
pub async fn resolver(&self, name: &str) -> Result<String, Error> {
pub async fn resolver(&self, name: &str) -> Result<String, ClientError> {
let hash = namehash(name);
let data = encode_resolver(hash);
let response = self.eth_call(&self.registry, data).await?;
let result = response.unwrap_or_default().to_string().replace('\"', "");
if result.is_empty() {
return Err(Error::Custom(String::from("no resolver set")));
return Err(ClientError::Custom("no resolver set".into()));
}
let addr = self.extract_address(&result);
Ok(addr)
}

pub async fn addr(&self, _resolver: &str, _name: &str, _coin_id: u32) -> Result<String, Error> {
pub async fn addr(
&self,
_resolver: &str,
_name: &str,
_coin_id: u32,
) -> Result<String, ClientError> {
todo!()
}

pub async fn legacy_addr(&self, resolver: &str, name: &str) -> Result<String, Error> {
pub async fn legacy_addr(&self, resolver: &str, name: &str) -> Result<String, ClientError> {
let hash = namehash(name);
let data = encode_legacy_addr(hash);
let response = self.eth_call(resolver, data).await?;
let result = response.unwrap_or_default().to_string().replace('\"', "");
if result.is_empty() {
return Err(Error::Custom(String::from("no address")));
return Err(ClientError::Custom("no address".into()));
}
Ok(self.extract_address(&result))
}

async fn eth_call(&self, to: &str, data: Vec<u8>) -> Result<Option<serde_json::Value>, Error> {
async fn eth_call(
&self,
to: &str,
data: Vec<u8>,
) -> Result<Option<serde_json::Value>, ClientError> {
let parmas = json!({
"to": to,
"data": format!("0x{}", hex::encode(data))
Expand Down
8 changes: 4 additions & 4 deletions name_resolver/src/ens_provider/provider.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::contract::Contract;
use jsonrpsee::core::Error;
use jsonrpsee::core::ClientError;
use jsonrpsee::http_client::HttpClientBuilder;
use primitives::Chain;

Expand All @@ -20,10 +20,10 @@ impl Provider {
}
}

pub async fn resolve_name(&self, name: &str, _chain: Chain) -> Result<String, Error> {
pub async fn resolve_name(&self, name: &str, _chain: Chain) -> Result<String, ClientError> {
let resolver = self.contract.resolver(name).await?;
if resolver.is_empty() {
return Err(Error::Custom(String::from("no resolver set")));
return Err(ClientError::Custom(String::from("no resolver set")));
}
// TODO: support other chain lookup
// TODO: support recursive parent lookup
Expand All @@ -32,7 +32,7 @@ impl Provider {
Ok(addr)
}

pub async fn get_address(&self, _resolver: &str, _chain: Chain) -> Result<String, Error> {
pub async fn get_address(&self, _resolver: &str, _chain: Chain) -> Result<String, ClientError> {
todo!()
}
}
Expand Down

0 comments on commit 75e0be0

Please sign in to comment.