Skip to content

Commit

Permalink
Take contract hash from server config.
Browse files Browse the repository at this point in the history
  • Loading branch information
koxu1996 committed Jun 12, 2024
1 parent 736a540 commit 3b52fb1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
6 changes: 2 additions & 4 deletions kairos-server/src/l1_sync/event_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ pub struct EventManager {
}

impl EventManager {
pub async fn new(
contract_hash: &str,
server_state: Arc<ServerStateInner>,
) -> Result<Self, L1SyncError> {
pub async fn new(server_state: Arc<ServerStateInner>) -> Result<Self, L1SyncError> {
tracing::info!("Initializing event manager");

let rpc_url = server_state.server_config.casper_rpc.as_str();
let contract_hash = server_state.server_config.casper_contract_hash.as_str();
let client = CasperClient::new(rpc_url);
let metadata = CesMetadataRef::fetch_metadata(&client, contract_hash).await?;
tracing::debug!("Metadata fetched successfully");
Expand Down
7 changes: 2 additions & 5 deletions kairos-server/src/l1_sync/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ pub struct L1SyncService {
}

impl L1SyncService {
pub async fn new(
contract_hash: String,
server_state: Arc<ServerStateInner>,
) -> Result<Self, L1SyncError> {
let event_manager = EventManager::new(&contract_hash, server_state.clone()).await?;
pub async fn new(server_state: Arc<ServerStateInner>) -> Result<Self, L1SyncError> {
let event_manager = EventManager::new(server_state.clone()).await?;

let (tx, rx) = mpsc::channel(32);
let _handle = tokio::spawn(async move {
Expand Down
8 changes: 3 additions & 5 deletions kairos-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ pub async fn run_l1_sync(config: ServerConfig, server_state: Arc<ServerStateInne
}

// Initialize L1 synchronizer.
let l1_sync_service = L1SyncService::new(config.casper_contract_hash, server_state)
.await
.unwrap_or_else(|e| {
panic!("Event manager failed to initialize: {}", e);
});
let l1_sync_service = L1SyncService::new(server_state).await.unwrap_or_else(|e| {
panic!("Event manager failed to initialize: {}", e);
});

// Run periodic synchronization.
// TODO: Add additional SSE trigger.
Expand Down

0 comments on commit 3b52fb1

Please sign in to comment.