use std::{mem, sync::Mutex};
use zksync_web3_decl::jsonrpsee::MethodResponse;
use super::metadata::MethodMetadata;
#[derive(Debug, Clone)]
pub(crate) struct RecordedCall {
pub metadata: MethodMetadata,
pub error_code: Option<i32>,
}
#[derive(Debug, Default)]
pub(crate) struct RecordedMethodCalls(Mutex<Vec<RecordedCall>>);
impl RecordedMethodCalls {
pub fn observe_response(&self, metadata: &MethodMetadata, response: &MethodResponse) {
self.0
.lock()
.expect("recorded calls are poisoned")
.push(RecordedCall {
metadata: metadata.clone(),
error_code: response.as_error_code(),
});
}
pub fn take(&self) -> Vec<RecordedCall> {
mem::take(&mut *self.0.lock().expect("recorded calls are poisoned"))
}
}