Skip to content

Commit

Permalink
Add /market_jobs{id} API
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay111meher committed Dec 17, 2024
1 parent 4538f74 commit d7c3e41
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions matching_engine/src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub fn ui_scope() -> actix_web::Scope {
"/market/{id}",
web::get().to(ui_routes::single_market::single_market),
)
.route(
"/market_jobs/{id}",
web::get().to(ui_routes::single_market::jobs),
)
.route(
"/withdrawals/{id}",
web::get().to(ui_routes::single_generator::withdrawal_request),
Expand Down
55 changes: 55 additions & 0 deletions matching_engine/src/routes/ui_routes/single_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,61 @@ impl CachedMarketResponse {
}
}

pub async fn jobs(
_local_ask_store: Data<Arc<RwLock<LocalAskStore>>>,
path: web::Path<(String,)>,
) -> actix_web::Result<HttpResponse> {
let market_id: U256 = match U256::from_dec_str(&path.0) {
Ok(data) => data,
_ => {
return Ok(HttpResponse::BadRequest().json(WelcomeResponse {
status: "Invalid Market Id".into(),
}))
}
};

try_read_or_lock!(_local_ask_store, local_ask_store);

let jobs = Jobs {
proofs_generated: local_ask_store.get_proof_count(&market_id),
proofs_pending: {
let result = local_ask_store
.get_by_ask_state_except_complete(AskState::Create)
.filter_by_market_id(market_id)
.result();

if result.is_some() {
result.unwrap().len()
} else {
0
}
},
proofs_in_progress: {
let result = local_ask_store
.get_by_ask_state_except_complete(AskState::Assigned)
.filter_by_market_id(market_id)
.result();

if result.is_some() {
result.unwrap().len()
} else {
0
}
},
requests_made: { local_ask_store.get_request_count_by_market_id(&market_id) },
inputs_challenged: { local_ask_store.get_failed_request_count_by_market_id(&market_id) },
};

#[derive(Serialize, Deserialize, Debug, Clone)]
struct JobRespone {
jobs: Jobs,
}

let response = JobRespone { jobs };

return Ok(HttpResponse::Ok().json(response));
}

pub async fn single_market(
_local_market_store: Data<Arc<RwLock<MarketMetadataStore>>>,
_local_ask_store: Data<Arc<RwLock<LocalAskStore>>>,
Expand Down

0 comments on commit d7c3e41

Please sign in to comment.