Skip to content

Commit

Permalink
feat: get_proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
Tguntenaar committed Nov 6, 2024
1 parent eee3ff2 commit ef397f7
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/entrypoints/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,10 @@ struct ProposalQuery {
}

// add query params to get_proposals entrypoint
#[utoipa::path(get, path = "/proposals")]
#[utoipa::path(
get,
path = "/proposals?<order>&<limit>&<offset>&<filtered_account_id>&<block_timestamp>"
)]
#[get("/?<order>&<limit>&<offset>&<filtered_account_id>&<block_timestamp>")]
// Json<Proposal>
async fn get_proposals(
Expand Down Expand Up @@ -454,11 +457,11 @@ async fn get_proposals(
}

async fn process_transactions(
transactions: &Vec<Transaction>,
transactions: &[Transaction],
db: &State<DB>,
) -> Result<String, Status> {
for transaction in transactions.iter() {
if let Some(action) = transaction.actions.get(0) {
if let Some(action) = transaction.actions.first() {
let result = match action.method.as_str() {
"set_block_height_callback" => {
handle_set_block_height_callback(transaction.to_owned(), db).await
Expand All @@ -476,9 +479,7 @@ async fn process_transactions(
continue;
} // or do something else if you want
};
if let Err(e) = result {
return Err(e);
}
result?;
}
}

Expand Down Expand Up @@ -577,8 +578,15 @@ async fn handle_edit_proposal(

#[utoipa::path(get, path = "/proposals/{proposal_id}")]
#[get("/<proposal_id>")]
async fn get_proposal(proposal_id: i32, db: &State<DB>) -> Result<String, rocket::http::Status> {
Ok(format!("Hello, {:?}!", proposal_id))
async fn get_proposal(proposal_id: i32) -> Result<Json<VersionedProposal>, rocket::http::Status> {
let rpc_service = RpcService::default();
match rpc_service.get_proposal(proposal_id).await {
Ok(proposal) => Ok(Json(proposal)),
Err(e) => {
eprintln!("Failed to get proposal from RPC: {:?}", e);
Err(Status::InternalServerError)
}
}
}

pub fn stage() -> rocket::fairing::AdHoc {
Expand Down

0 comments on commit ef397f7

Please sign in to comment.