Skip to content

Commit

Permalink
Add /wallet/fail_transfer API endpoint.
Browse files Browse the repository at this point in the history
This will fix #60 .

Signed-off-by: Masaki Muranaka <[email protected]>
  • Loading branch information
monaka committed Mar 28, 2023
1 parent 20a5171 commit a5011eb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod blind;
pub mod data;
pub mod dir;
pub mod drain_to;
pub mod fail_transfers;
pub mod go_online;
pub mod invoice;
pub mod issue;
Expand Down
54 changes: 54 additions & 0 deletions src/wallet/fail_transfers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use crate::ShiroWallet;
use actix_web::{put, web, HttpResponse, Responder};
use serde::Deserialize;
use serde::Serialize;
use std::sync::Mutex;

#[derive(Deserialize, Serialize)]
pub struct FailTransfersParams {
blinded_utxo: Option<String>,
txid: Option<String>,
no_asset_only: bool,
}

#[derive(Deserialize, Serialize)]
pub struct FailTransersResult {
transfer_changed: bool,
}

#[put("/wallet/fail_transifers")]
pub async fn put(
params: web::Json<FailTransfersParams>,
data: web::Data<Mutex<ShiroWallet>>,
) -> impl Responder {
if data.lock().unwrap().wallet.is_some() {
match actix_web::rt::task::spawn_blocking(move || {
let mut shiro_wallet = data.lock().unwrap();
let online = shiro_wallet.get_online().unwrap();
shiro_wallet.wallet.as_mut().unwrap().fail_transfers(
online,
params.blinded_utxo.clone(),
params.txid.clone(),
params.no_asset_only,
)
})
.await
.unwrap()
{
Ok(transfer_changed) => {
HttpResponse::Ok().json(FailTransersResult { transfer_changed })
}
Err(e) => HttpResponse::BadRequest().body(e.to_string()),
}
} else {
HttpResponse::BadRequest().body("wallet should be created first")
}
}

#[cfg(test)]
mod tests {
#[actix_web::test]
async fn test_put() {
//TODO: implement
}
}

0 comments on commit a5011eb

Please sign in to comment.