Skip to content

Commit ac86a9b

Browse files
committed
Adapt context to main
1 parent f47500d commit ac86a9b

File tree

4 files changed

+66
-65
lines changed

4 files changed

+66
-65
lines changed

Cargo.lock

Lines changed: 21 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ members = ["contracts", "contracts/wallet", "server"]
77
# client-sdk = { default-features = false, package = "hyle-client-sdk", version = "0.13.0-rc.4" }
88
# hyle = { version = "0.13.0-rc.4" }
99

10-
sdk = { git = "https://github.com/Hyle-org/hyle.git", package = "hyle-contract-sdk", branch = "secp256k1blob" }
11-
client-sdk = { git = "https://github.com/Hyle-org/hyle.git", default-features = false, package = "hyle-client-sdk", branch = "secp256k1blob" }
12-
hyle-hyllar = { git = "https://github.com/Hyle-org/hyle", package = "hyle-hyllar", branch = "secp256k1blob" }
13-
hyle-modules = { git = "https://github.com/Hyle-org/hyle.git", package = "hyle-modules", branch = "secp256k1blob" }
10+
sdk = { git = "https://github.com/Hyle-org/hyle.git", package = "hyle-contract-sdk", branch = "main" }
11+
client-sdk = { git = "https://github.com/Hyle-org/hyle.git", default-features = false, package = "hyle-client-sdk", branch = "main" }
12+
hyle-hyllar = { git = "https://github.com/Hyle-org/hyle", package = "hyle-hyllar", branch = "main" }
13+
hyle-modules = { git = "https://github.com/Hyle-org/hyle.git", package = "hyle-modules", branch = "main" }
14+
1415

1516
contracts = { path = "contracts", default-features = false, package = "contracts" }
1617
wallet = { path = "contracts/wallet", package = "wallet" }

server/src/app.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ use axum::{
1010
};
1111
use client_sdk::rest_client::NodeApiHttpClient;
1212
use hyle_modules::{
13-
bus::BusClientSender,
13+
bus::{BusClientSender, SharedMessageBus},
1414
module_bus_client, module_handle_messages,
1515
modules::{
16-
contract_state_indexer::CSIBusEvent, websocket::WsTopicMessage, CommonRunContext, Module,
16+
contract_state_indexer::CSIBusEvent, websocket::WsTopicMessage, BuildApiContextInner,
17+
Module,
1718
},
1819
};
1920

@@ -29,9 +30,9 @@ pub struct AppModule {
2930
}
3031

3132
pub struct AppModuleCtx {
32-
pub common: Arc<CommonRunContext>,
3333
pub node_client: Arc<NodeApiHttpClient>,
3434
pub wallet_cn: ContractName,
35+
pub api: Arc<BuildApiContextInner>,
3536
}
3637

3738
/// Messages received from WebSocket clients that will be processed by the system
@@ -57,7 +58,7 @@ pub struct AppModuleBusClient {
5758
impl Module for AppModule {
5859
type Context = Arc<AppModuleCtx>;
5960

60-
async fn build(ctx: Self::Context) -> Result<Self> {
61+
async fn build(bus: SharedMessageBus, ctx: Self::Context) -> Result<Self> {
6162
let state = RouterCtx {
6263
wallet_cn: ctx.wallet_cn.clone(),
6364
};
@@ -74,12 +75,12 @@ impl Module for AppModule {
7475
.with_state(state)
7576
.layer(cors); // Apply the CORS middleware
7677

77-
if let Ok(mut guard) = ctx.common.router.lock() {
78+
if let Ok(mut guard) = ctx.api.router.lock() {
7879
if let Some(router) = guard.take() {
7980
guard.replace(router.merge(api));
8081
}
8182
}
82-
let bus = AppModuleBusClient::new_from_bus(ctx.common.bus.new_handle()).await;
83+
let bus = AppModuleBusClient::new_from_bus(bus.new_handle()).await;
8384

8485
Ok(AppModule { bus })
8586
}

server/src/main.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@ use hyle_modules::{
1111
bus::{metrics::BusMetrics, SharedMessageBus},
1212
modules::{
1313
contract_state_indexer::{ContractStateIndexer, ContractStateIndexerCtx},
14-
da_listener::{DAListener, DAListenerCtx},
14+
da_listener::{DAListener, DAListenerConf},
1515
prover::{AutoProver, AutoProverCtx},
1616
rest::{RestApi, RestApiRunContext},
17-
websocket::{WebSocketModule, WebSocketModuleCtx},
18-
CommonRunContext, ModulesHandler,
17+
websocket::WebSocketModule,
18+
BuildApiContextInner, ModulesHandler,
1919
},
2020
utils::{conf, logger::setup_tracing},
2121
};
2222

2323
use prometheus::Registry;
2424
use sdk::{api::NodeInfo, info, ContractName, ZkContract};
25-
use std::{
26-
env,
27-
sync::{Arc, Mutex},
28-
};
25+
use std::{env, sync::Arc};
2926
use tracing::error;
3027
use wallet::{client::indexer::WalletEvent, Wallet};
3128

@@ -92,17 +89,15 @@ async fn main() -> Result<()> {
9289

9390
let mut handler = ModulesHandler::new(&bus).await;
9491

95-
let ctx = Arc::new(CommonRunContext {
96-
bus: bus.new_handle(),
97-
config: config.clone(),
98-
router: Mutex::new(Some(Router::new())),
99-
openapi: Default::default(),
92+
let build_api_ctx = Arc::new(BuildApiContextInner {
93+
router: std::sync::Mutex::new(Some(Router::new())),
94+
openapi: std::sync::Mutex::new(Default::default()),
10095
});
10196

10297
let app_ctx = Arc::new(AppModuleCtx {
103-
common: ctx.clone(),
10498
node_client,
10599
wallet_cn: contract_name.clone(),
100+
api: build_api_ctx.clone(),
106101
});
107102
let start_height = app_ctx.node_client.get_block_height().await?;
108103

@@ -111,22 +106,23 @@ async fn main() -> Result<()> {
111106
handler
112107
.build_module::<ContractStateIndexer<Wallet, WalletEvent>>(ContractStateIndexerCtx {
113108
contract_name: contract_name.clone(),
114-
common: ctx.clone(),
109+
data_directory: config.data_directory.clone(),
110+
api: build_api_ctx.clone(),
115111
})
116112
.await?;
117113
handler
118114
.build_module::<ContractStateIndexer<HyllarHistory, Vec<HistoryEvent>>>(
119115
ContractStateIndexerCtx {
120116
contract_name: "hyllar".into(),
121-
common: ctx.clone(),
117+
data_directory: config.data_directory.clone(),
118+
api: build_api_ctx.clone(),
122119
},
123120
)
124121
.await?;
125122

126123
handler
127124
.build_module::<AutoProver<Wallet>>(Arc::new(AutoProverCtx {
128125
start_height,
129-
bus: ctx.bus.new_handle(),
130126
data_directory: config.data_directory.clone(),
131127
prover: Arc::new(Risc0Prover::new(contracts::WALLET_ELF)),
132128
contract_name: contract_name.clone(),
@@ -136,7 +132,6 @@ async fn main() -> Result<()> {
136132
handler
137133
.build_module::<AutoProver<hyle_hyllar::Hyllar>>(Arc::new(AutoProverCtx {
138134
start_height,
139-
bus: ctx.bus.new_handle(),
140135
data_directory: config.data_directory.clone(),
141136
prover: Arc::new(Risc0Prover::new(
142137
hyle_hyllar::client::tx_executor_handler::metadata::HYLLAR_ELF,
@@ -147,40 +142,45 @@ async fn main() -> Result<()> {
147142
.await?;
148143

149144
handler
150-
.build_module::<WebSocketModule<AppWsInMessage, AppOutWsEvent>>(WebSocketModuleCtx {
151-
bus: ctx.bus.new_handle(),
152-
config: config.websocket.clone().into(),
153-
})
145+
.build_module::<WebSocketModule<AppWsInMessage, AppOutWsEvent>>(
146+
config.websocket.clone().into(),
147+
)
154148
.await?;
155149

156150
// This module connects to the da_address and receives all the blocks²
157151
handler
158-
.build_module::<DAListener>(DAListenerCtx {
159-
common: ctx.clone(),
152+
.build_module::<DAListener>(DAListenerConf {
153+
data_directory: config.data_directory.clone(),
154+
da_read_from: config.da_read_from.clone(),
160155
start_block: None,
161156
})
162157
.await?;
163158

164159
// Should come last so the other modules have nested their own routes.
165160
#[allow(clippy::expect_used, reason = "Fail on misconfiguration")]
166-
let router = ctx
161+
let router = build_api_ctx
167162
.router
168163
.lock()
169-
.expect("Context router should be available")
164+
.expect("Context router should be available.")
170165
.take()
171-
.expect("Context router should be available");
166+
.expect("Context router should be available.");
167+
#[allow(clippy::expect_used, reason = "Fail on misconfiguration")]
168+
let openapi = build_api_ctx
169+
.openapi
170+
.lock()
171+
.expect("OpenAPI should be available")
172+
.clone();
172173

173174
handler
174175
.build_module::<RestApi>(RestApiRunContext {
175-
port: ctx.config.rest_server_port,
176-
max_body_size: ctx.config.rest_server_max_body_size,
177-
bus: ctx.bus.new_handle(),
176+
port: config.rest_server_port,
177+
max_body_size: config.rest_server_max_body_size,
178178
registry: Registry::new(),
179-
router: router.clone(),
180-
openapi: Default::default(),
179+
router,
180+
openapi,
181181
info: NodeInfo {
182-
id: ctx.config.id.clone(),
183-
da_address: ctx.config.da_read_from.clone(),
182+
id: config.id.clone(),
183+
da_address: config.da_read_from.clone(),
184184
pubkey: None,
185185
},
186186
})

0 commit comments

Comments
 (0)