Skip to content

Commit

Permalink
fix: all tests done for typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed Mar 21, 2024
1 parent 8f93076 commit 5fe68fa
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 97 deletions.
1 change: 0 additions & 1 deletion fedimint-clientd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ fn fedimint_v2_rest() -> Router<AppState> {
post(fedimint::ln::await_invoice::handle_rest),
)
.route("/pay", post(fedimint::ln::pay::handle_rest))
.route("/await-pay", post(fedimint::ln::await_pay::handle_rest))
.route(
"/list-gateways",
post(fedimint::ln::list_gateways::handle_rest),
Expand Down
65 changes: 0 additions & 65 deletions fedimint-clientd/src/router/handlers/fedimint/ln/await_pay.rs

This file was deleted.

1 change: 0 additions & 1 deletion fedimint-clientd/src/router/handlers/fedimint/ln/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use tracing::{debug, info};
use self::pay::{LnPayRequest, LnPayResponse};

pub mod await_invoice;
pub mod await_pay;
pub mod invoice;
pub mod list_gateways;
pub mod pay;
Expand Down
24 changes: 7 additions & 17 deletions fedimint-clientd/src/router/handlers/fedimint/ln/pay.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Context};
use anyhow::anyhow;
use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
Expand All @@ -20,7 +20,6 @@ use crate::state::AppState;
pub struct LnPayRequest {
pub payment_info: String,
pub amount_msat: Option<Amount>,
pub finish_in_background: bool,
pub lnurl_comment: Option<String>,
pub federation_id: FederationId,
}
Expand Down Expand Up @@ -68,22 +67,13 @@ async fn _pay(client: ClientHandleArc, req: LnPayRequest) -> Result<LnPayRespons
.await?;
let operation_id = payment_type.operation_id();
info!("Gateway fee: {fee}, payment operation id: {operation_id}");
if req.finish_in_background {
wait_for_ln_payment(&client, payment_type, contract_id.to_string(), true).await?;
info!("Payment will finish in background, use await-ln-pay to get the result");
Ok(LnPayResponse {
operation_id,
payment_type,
contract_id: contract_id.to_string(),
fee,

wait_for_ln_payment(&client, payment_type, contract_id.to_string(), false)
.await?
.ok_or_else(|| {
error!("Payment failed");
AppError::new(StatusCode::INTERNAL_SERVER_ERROR, anyhow!("Payment failed"))
})
} else {
Ok(
wait_for_ln_payment(&client, payment_type, contract_id.to_string(), false)
.await?
.context("expected a response")?,
)
}
}

pub async fn handle_ws(state: AppState, v: Value) -> Result<Value, AppError> {
Expand Down
6 changes: 3 additions & 3 deletions fedimint-clientd/src/router/handlers/fedimint/mint/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::error::AppError;
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CombineRequest {
pub notes: Vec<OOBNotes>,
pub notes_vec: Vec<OOBNotes>,
}

#[derive(Debug, Serialize)]
Expand All @@ -22,7 +22,7 @@ pub struct CombineResponse {

async fn _combine(req: CombineRequest) -> Result<CombineResponse, AppError> {
let federation_id_prefix = match req
.notes
.notes_vec
.iter()
.map(|notes| notes.federation_id_prefix())
.all_equal_value()
Expand All @@ -43,7 +43,7 @@ async fn _combine(req: CombineRequest) -> Result<CombineResponse, AppError> {
};

let combined_notes = req
.notes
.notes_vec
.iter()
.flat_map(|notes| notes.notes().iter_items().map(|(amt, note)| (amt, *note)))
.collect();
Expand Down
4 changes: 0 additions & 4 deletions fedimint-clientd/src/router/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pub enum JsonRpcMethod {
LnInvoice,
LnAwaitInvoice,
LnPay,
LnAwaitPay,
LnListGateways,
WalletDepositAddress,
WalletAwaitDeposit,
Expand Down Expand Up @@ -189,9 +188,6 @@ async fn match_method(req: JsonRpcRequest, state: AppState) -> Result<Value, App
JsonRpcMethod::LnPay => {
handlers::fedimint::ln::pay::handle_ws(state.clone(), req.params).await
}
JsonRpcMethod::LnAwaitPay => {
handlers::fedimint::ln::await_pay::handle_ws(state.clone(), req.params).await
}
JsonRpcMethod::LnListGateways => {
handlers::fedimint::ln::list_gateways::handle_ws(state.clone(), req.params).await
}
Expand Down
12 changes: 9 additions & 3 deletions wrappers/fedimint-ts/FedimintClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,15 @@ class FedimintClient {
amountMsat: number,
allowOverpay: boolean,
timeout: number,
includeInvite: boolean,
federationId?: string
): FedimintResponse<SpendResponse> => {
const request: SpendRequest = { amountMsat, allowOverpay, timeout };
const request: SpendRequest = {
amountMsat,
allowOverpay,
timeout,
includeInvite,
};

return await this.postWithId<SpendResponse>(
"/mint/spend",
Expand Down Expand Up @@ -425,10 +431,10 @@ class FedimintClient {
*/
withdraw: async (
address: string,
amountMsat: number | "all",
amountSat: number | "all",
federationId?: string
): FedimintResponse<WithdrawResponse> => {
const request: WithdrawRequest = { address, amountMsat };
const request: WithdrawRequest = { address, amountSat };

return await this.postWithId<WithdrawResponse>(
"/wallet/withdraw",
Expand Down
6 changes: 4 additions & 2 deletions wrappers/fedimint-ts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async function main() {
// MINT METHODS
// `/v2/mint/spend`
logMethod("/v2/mint/spend");
let mintData = await fedimintClient.mint.spend(3000, true, 1000);
let mintData = await fedimintClient.mint.spend(3000, true, 1000, false);
logInputAndOutput(
{ amountMsat: 3000, allowOverpay: true, timeout: 1000 },
data
Expand Down Expand Up @@ -116,11 +116,13 @@ async function main() {
// `/v2/onchain/withdraw`
logMethod("/v2/onchain/withdraw");
data = await fedimintClient.onchain.withdraw(data.address, 1000);
logInputAndOutput({ address: data.address, amountMsat: 1000 }, data);
logInputAndOutput({ address: data.address, amountSat: 1000 }, data);
// // `/v2/onchain/await-deposit`
// logMethod("/v2/onchain/await-deposit");
// data = await fedimintClient.onchain.awaitDeposit(data.operationId);
// logInputAndOutput({ operationId: data.operationId }, data);

console.log("Done: All methods tested successfully!");
}

main().catch(console.error);
3 changes: 2 additions & 1 deletion wrappers/fedimint-ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ interface AwaitDepositResponse {

interface WithdrawRequest {
address: string;
amountMsat: number | "all";
amountSat: number | "all";
}

interface WithdrawResponse {
Expand Down Expand Up @@ -158,6 +158,7 @@ interface SpendRequest {
amountMsat: number;
allowOverpay: boolean;
timeout: number;
includeInvite: boolean;
}

interface SpendResponse {
Expand Down

0 comments on commit 5fe68fa

Please sign in to comment.