Skip to content

Commit 0ea7b33

Browse files
committed
refactor
1 parent a067df8 commit 0ea7b33

4 files changed

Lines changed: 23 additions & 8 deletions

File tree

crates/cli/src/commands/local_db/sync/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pub(crate) mod config;
33
pub(crate) mod data_source;
44
pub(crate) mod runner;
55
pub(crate) mod storage;
6-
pub(crate) mod store;
76
pub(crate) mod token;
87

98
pub use cli::SyncLocalDb;

crates/cli/src/commands/local_db/sync/runner/apply.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ mod tests {
111111
use crate::commands::local_db::sqlite::sqlite_execute;
112112
use crate::commands::local_db::sync::storage::DEFAULT_SCHEMA_SQL;
113113

114+
const RAW_SQL_STUB: &str = "INSERT INTO raw_events (block_number, block_timestamp, transaction_hash, log_index, address, topics, data, raw_json) VALUES (0, NULL, '0x0', 0, '0x0', '[]', '0x', '{}');\n";
115+
114116
struct MockDataSource {
115117
sql_result: String,
116118
rpc_urls: Vec<Url>,
@@ -258,7 +260,7 @@ mod tests {
258260
captured_prefixes: Mutex::new(vec![]),
259261
captured_events: Mutex::new(vec![]),
260262
captured_decimals: Mutex::new(vec![]),
261-
raw_sql: "RAW_PREFIX;\n".to_string(),
263+
raw_sql: RAW_SQL_STUB.to_string(),
262264
captured_raw: Mutex::new(vec![]),
263265
};
264266

@@ -279,7 +281,7 @@ mod tests {
279281
assert!(result.contains("INSERT INTO sync"));
280282
let prefixes = data_source.captured_prefixes.lock().unwrap();
281283
assert_eq!(prefixes.len(), 1);
282-
assert!(prefixes[0].starts_with("RAW_PREFIX;"));
284+
assert!(prefixes[0].starts_with("INSERT INTO raw_events"));
283285
let raw = data_source.captured_raw.lock().unwrap();
284286
assert_eq!(raw.len(), 1);
285287
assert!(raw[0].is_empty());
@@ -323,7 +325,7 @@ mod tests {
323325
captured_prefixes: Mutex::new(Vec::new()),
324326
captured_events: Mutex::new(Vec::new()),
325327
captured_decimals: Mutex::new(Vec::new()),
326-
raw_sql: "RAW;\n".into(),
328+
raw_sql: RAW_SQL_STUB.into(),
327329
captured_raw: Mutex::new(Vec::new()),
328330
};
329331

@@ -357,7 +359,7 @@ mod tests {
357359

358360
let prefixes = data_source.captured_prefixes.lock().unwrap();
359361
assert_eq!(prefixes.len(), 1);
360-
assert!(prefixes[0].starts_with("RAW;\n"));
362+
assert!(prefixes[0].starts_with("INSERT INTO raw_events"));
361363

362364
let captured_events = data_source.captured_events.lock().unwrap();
363365
assert_eq!(captured_events.len(), 1);

crates/cli/src/commands/local_db/sync/runner/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ mod tests {
198198
use crate::commands::local_db::sqlite::sqlite_execute;
199199
use crate::commands::local_db::sync::storage::DEFAULT_SCHEMA_SQL;
200200

201+
const RAW_SQL_STUB: &str = "INSERT INTO raw_events (block_number, block_timestamp, transaction_hash, log_index, address, topics, data, raw_json) VALUES (0, NULL, '0x0', 0, '0x0', '[]', '0x', '{}');\n";
202+
201203
struct TestFetcher {
202204
metadata: Vec<(Address, TokenInfo)>,
203205
calls: Mutex<Vec<Vec<Address>>>,
@@ -403,7 +405,7 @@ mod tests {
403405
sql_calls: Mutex::new(vec![]),
404406
prefixes: Mutex::new(vec![]),
405407
decimals: Mutex::new(vec![]),
406-
raw_sql: "RAW_EVENTS;\n".into(),
408+
raw_sql: RAW_SQL_STUB.into(),
407409
raw_calls: Mutex::new(vec![]),
408410
};
409411

@@ -512,7 +514,7 @@ mod tests {
512514
sql_calls: Mutex::new(vec![]),
513515
prefixes: Mutex::new(vec![]),
514516
decimals: Mutex::new(vec![]),
515-
raw_sql: "RAW;\n".into(),
517+
raw_sql: RAW_SQL_STUB.into(),
516518
raw_calls: Mutex::new(vec![]),
517519
};
518520
let fetcher = TestFetcher {

crates/common/src/raindex_client/local_db/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use alloy::primitives::ruint::ParseError;
1212
use alloy::primitives::{hex::FromHexError, Address};
1313
use decode::{decode_events as decode_events_impl, DecodedEvent, DecodedEventData};
1414
pub use fetch::FetchConfig;
15-
use insert::decoded_events_to_sql as decoded_events_to_sql_impl;
15+
use insert::{
16+
decoded_events_to_sql as decoded_events_to_sql_impl,
17+
raw_events_to_sql as raw_events_to_sql_impl,
18+
};
1619
use query::LocalDbQueryError;
1720
use std::collections::HashMap;
1821
use url::Url;
@@ -234,6 +237,15 @@ impl LocalDb {
234237
},
235238
)
236239
}
240+
241+
pub fn raw_events_to_sql(
242+
&self,
243+
raw_events: &[LogEntryResponse],
244+
) -> Result<String, LocalDbError> {
245+
raw_events_to_sql_impl(raw_events).map_err(|err| LocalDbError::InsertError {
246+
message: err.to_string(),
247+
})
248+
}
237249
}
238250

239251
#[wasm_export]

0 commit comments

Comments
 (0)