Have rest_api::Start take AppState as an argument
@@ -61,14 +61,8 @@ impl RestApiShutdownHandle {
}
}
-fn create_app(
- sawtooth_connection: Addr<SawtoothMessageSender>,
- database_connection: Addr<DbExecutor>,
-) -> App<AppState> {
- App::with_state(AppState {
- sawtooth_connection,
- database_connection,
- })
+fn create_app(app_state: AppState) -> App<AppState> {
+ App::with_state(app_state)
.resource("/batches", |r| {
r.method(Method::POST).with_async(submit_batches)
})
@@ -111,8 +105,7 @@ fn create_app(
pub fn run(
bind_url: &str,
- zmq_sender: Box<dyn MessageSender + Send>,
- connection_pool: ConnectionPool,
+ app_state: AppState,
) -> Result<
(
RestApiShutdownHandle,
@@ -126,16 +119,8 @@ pub fn run(
.name("GridRestApi".into())
.spawn(move || {
let sys = actix::System::new("Grid-Rest-API");
- let zmq_connection_addr =
- SawtoothMessageSender::create(move |_ctx: &mut Context<SawtoothMessageSender>| {
- SawtoothMessageSender::new(zmq_sender)
- });
- let db_executor_addr =
- SyncArbiter::start(2, move || DbExecutor::new(connection_pool.clone()));
info!("Starting Rest API at {}", &bind_url);
- let addr = server::new(move || {
- create_app(zmq_connection_addr.clone(), db_executor_addr.clone())
- })
+ let addr = server::new(move || create_app(app_state.clone()))
.bind(bind_url)?
.disable_signals()
.system_exit()
