Skip to content

Commit

Permalink
error log for rpc (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAWM authored Nov 18, 2023
1 parent ad4e8ec commit d0506da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 41 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ jobs:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Format check
run: cargo fmt -- --check
- name: Clippy
run: cargo clippy --all-features
- name: Download and Extract Cache
run: curl -L https://github.com/fuzzland/ityfuzz-test-cache/releases/latest/download/cache.tar.gz -o cache.tar.gz && tar -xzf cache.tar.gz
- name: Build
Expand Down
50 changes: 11 additions & 39 deletions src/evm/onchain/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Chain {
return url;
}
match self {
Chain::ETH => "https://eth.llamarpc.com",
Chain::ETH => "https://eth.merkle.io",
Chain::GOERLI => "https://rpc.ankr.com/eth_goerli",
Chain::SEPOLIA => "https://rpc.ankr.com/eth_sepolia",
Chain::BSC => "https://rpc.ankr.com/bsc",
Expand Down Expand Up @@ -529,55 +529,27 @@ impl OnChainConfig {
"{{\"jsonrpc\":\"2.0\", \"method\": \"{}\", \"params\": {}, \"id\": {}}}",
method, params, self.chain_id
);

match self.post(self.endpoint_url.clone(), data) {
Some(resp) => {
let json: Result<Value, _> = serde_json::from_str(&resp);

match json {
Ok(json) => {
return json.get("result").cloned();
}
Err(e) => {
error!("{:?}", e);
None
}
}
}

None => {
self.post(self.endpoint_url.clone(), data)
.and_then(|resp| serde_json::from_str(&resp).ok())
.and_then(|json: Value| json.get("result").cloned())
.or_else(|| {
error!("failed to fetch from {}", self.endpoint_url);
None
}
}
})
}

fn _request_with_id(&self, method: String, params: String, id: u8) -> Option<Value> {
let data = format!(
"{{\"jsonrpc\":\"2.0\", \"method\": \"{}\", \"params\": {}, \"id\": {}}}",
method, params, id
);

match self.post(self.endpoint_url.clone(), data) {
Some(resp) => {
let json: Result<Value, _> = serde_json::from_str(&resp);

match json {
Ok(json) => {
return json.get("result").cloned();
}
Err(e) => {
error!("{:?}", e);
None
}
}
}

None => {
self.post(self.endpoint_url.clone(), data)
.and_then(|resp| serde_json::from_str(&resp).ok())
.and_then(|json: Value| json.get("result").cloned())
.or_else(|| {
error!("failed to fetch from {}", self.endpoint_url);
None
}
}
})
}

pub fn get_balance(&mut self, address: EVMAddress) -> EVMU256 {
Expand Down

0 comments on commit d0506da

Please sign in to comment.