use crate::{Context, Handler}; use actix_web::{post, web, HttpResponse, Responder}; use serde::Deserialize; use serde_json::json; use verax::{AccountId, AnyAmount, Status, Tag}; #[derive(Deserialize)] pub struct Deposit { pub account: AccountId, #[serde(flatten)] pub amount: AnyAmount, pub memo: String, pub tags: Vec, pub status: Status, } #[async_trait::async_trait] impl Handler for Deposit { type Ok = verax::Transaction; type Err = verax::Error; async fn handle(self, ctx: &Context) -> Result { ctx.ledger .deposit( &self.account, self.amount.try_into()?, self.status, self.tags, self.memo, ) .await } } #[post("/deposit")] pub async fn handler(item: web::Json, ledger: web::Data) -> impl Responder { // Insert the item into a database or another data source. // For this example, we'll just echo the received item. match item.into_inner().handle(&ledger).await { Ok(tx) => { // Insert the item into a database or another data source. // For this example, we'll just echo the received item. HttpResponse::Created().json(tx) } Err(err) => HttpResponse::BadRequest().json(json!({ "text": err.to_string(), "err": err})), } }