Skip to content

Commit

Permalink
eth watch
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Jan 6, 2021
1 parent 1d81d8d commit f069afe
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 86 deletions.
62 changes: 0 additions & 62 deletions core/bin/zksync_core/src/eth_watch/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use zksync_types::{ethereum::CompleteWithdrawalsTx, Address, Nonce, PriorityOp,

struct ContractTopics {
new_priority_request: Hash,
complete_withdrawals_event: Hash,
}

impl ContractTopics {
Expand All @@ -25,11 +24,6 @@ impl ContractTopics {
.event("NewPriorityRequest")
.expect("main contract abi error")
.signature(),

complete_withdrawals_event: zksync_contract
.event("PendingWithdrawalsComplete")
.expect("main contract abi error")
.signature(),
}
}
}
Expand All @@ -41,15 +35,8 @@ pub trait EthClient {
from: BlockNumber,
to: BlockNumber,
) -> anyhow::Result<Vec<PriorityOp>>;
async fn get_complete_withdrawals_event(
&self,
from: BlockNumber,
to: BlockNumber,
) -> anyhow::Result<Vec<CompleteWithdrawalsTx>>;
async fn block_number(&self) -> anyhow::Result<u64>;
async fn get_auth_fact(&self, address: Address, nonce: Nonce) -> anyhow::Result<Vec<u8>>;
async fn get_first_pending_withdrawal_index(&self) -> anyhow::Result<u32>;
async fn get_number_of_pending_withdrawals(&self) -> anyhow::Result<u32>;
}

pub struct EthHttpClient {
Expand Down Expand Up @@ -116,24 +103,6 @@ impl EthClient for EthHttpClient {
result
}

async fn get_complete_withdrawals_event(
&self,
from: BlockNumber,
to: BlockNumber,
) -> anyhow::Result<Vec<CompleteWithdrawalsTx>> {
let start = Instant::now();

let result = self
.get_events(from, to, vec![self.topics.complete_withdrawals_event])
.await;

metrics::histogram!(
"eth_watcher.get_complete_withdrawals_event",
start.elapsed()
);
result
}

async fn block_number(&self) -> anyhow::Result<u64> {
Ok(self.web3.eth().block_number().await?.as_u64())
}
Expand All @@ -150,35 +119,4 @@ impl EthClient for EthHttpClient {
.await
.map_err(|e| format_err!("Failed to query contract authFacts: {}", e))
}

async fn get_first_pending_withdrawal_index(&self) -> anyhow::Result<u32> {
self.zksync_contract
.query(
"firstPendingWithdrawalIndex",
(),
None,
Options::default(),
None,
)
.await
.map_err(|e| {
format_err!(
"Failed to query contract firstPendingWithdrawalIndex: {}",
e
)
})
}

async fn get_number_of_pending_withdrawals(&self) -> anyhow::Result<u32> {
self.zksync_contract
.query(
"numberOfPendingWithdrawals",
(),
None,
Options::default(),
None,
)
.await
.map_err(|e| format_err!("Failed to query contract numberOfPendingWithdrawals: {}", e))
}
}
24 changes: 0 additions & 24 deletions core/bin/zksync_core/src/eth_watch/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,6 @@ impl EthClient for FakeEthClient {
Ok(operations)
}

async fn get_complete_withdrawals_event(
&self,
from: BlockNumber,
to: BlockNumber,
) -> Result<Vec<CompleteWithdrawalsTx>, anyhow::Error> {
let from = self.block_to_number(&from).await;
let to = self.block_to_number(&to).await;
let mut withdrawals = vec![];
for number in from..=to {
if let Some(ops) = self.inner.read().await.withdrawals.get(&number) {
withdrawals.extend_from_slice(ops);
}
}
Ok(withdrawals)
}

async fn block_number(&self) -> Result<u64, anyhow::Error> {
Ok(self.inner.read().await.last_block_number)
}
Expand All @@ -131,14 +115,6 @@ impl EthClient for FakeEthClient {
) -> Result<Vec<u8>, anyhow::Error> {
unreachable!()
}

async fn get_first_pending_withdrawal_index(&self) -> Result<u32, anyhow::Error> {
unreachable!()
}

async fn get_number_of_pending_withdrawals(&self) -> Result<u32, anyhow::Error> {
unreachable!()
}
}

fn create_watcher<T: EthClient>(client: T) -> EthWatch<T, FakeStorage> {
Expand Down

0 comments on commit f069afe

Please sign in to comment.