Skip to content

Commit 8b77683

Browse files
committed
requested changes
1 parent bf2020e commit 8b77683

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

sentry/src/routes/channel.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use primitives::{
3131
},
3232
spender::{Spendable, Spender},
3333
validator::NewState,
34-
Address, ChainOf, Channel, Deposit, UnifiedNum,
34+
Address, ChainOf, Channel, ChannelId, Deposit, UnifiedNum,
3535
};
3636
use serde::{Deserialize, Serialize};
3737
use slog::{error, Logger};
@@ -269,16 +269,13 @@ pub async fn get_spender_limits<C: Locked + 'static>(
269269
}
270270

271271
pub async fn get_spender_limits_axum<C: Locked + 'static>(
272-
Path(params): Path<HashMap<String, String>>,
272+
Path(params): Path<(ChannelId, Address)>,
273273
Extension(app): Extension<Arc<Application<C>>>,
274274
Extension(channel_context): Extension<ChainOf<Channel>>,
275275
) -> Result<Json<SpenderResponse>, ResponseError> {
276276
let channel = &channel_context.context;
277277

278-
let spender = params
279-
.get("addr")
280-
.ok_or_else(|| ResponseError::BadRequest("Invalid spender address".to_string()))?;
281-
let spender = Address::from_str(spender)?;
278+
let spender = params.1;
282279

283280
let latest_spendable = fetch_spendable(app.pool.clone(), &spender, &channel.id()).await?;
284281

@@ -313,14 +310,12 @@ pub async fn get_spender_limits_axum<C: Locked + 'static>(
313310
.get(&spender)
314311
.map(|spent| spent.to_owned());
315312

316-
// returned output
317-
let res = SpenderResponse {
313+
Ok(Json(SpenderResponse {
318314
spender: Spender {
319315
total_deposited: latest_spendable.deposit.total,
320316
total_spent,
321317
},
322-
};
323-
Ok(Json(res))
318+
}))
324319
}
325320

326321
/// GET `/v5/channel/0xXXX.../spender/all` request.
@@ -422,12 +417,10 @@ pub async fn get_all_spender_limits_axum<C: Locked + 'static>(
422417
all_spender_limits.insert(spender, spender_info);
423418
}
424419

425-
let res = AllSpendersResponse {
420+
Ok(Json(AllSpendersResponse {
426421
spenders: all_spender_limits,
427422
pagination,
428-
};
429-
430-
Ok(Json(res))
423+
}))
431424
}
432425

433426
/// POST `/v5/channel/0xXXX.../spender/0xXXX...` request
@@ -495,12 +488,9 @@ pub async fn add_spender_leaf<C: Locked + 'static>(
495488
pub async fn add_spender_leaf_axum<C: Locked + 'static>(
496489
Extension(app): Extension<Arc<Application<C>>>,
497490
Extension(channel): Extension<ChainOf<Channel>>,
498-
Path(params): Path<HashMap<String, String>>,
491+
Path(params): Path<(ChannelId, Address)>,
499492
) -> Result<Json<SpenderResponse>, ResponseError> {
500-
let spender = params
501-
.get("addr")
502-
.ok_or_else(|| ResponseError::BadRequest("Invalid spender address".to_string()))?;
503-
let spender = Address::from_str(spender)?;
493+
let spender = params.1;
504494

505495
update_accounting(
506496
app.pool.clone(),
@@ -541,13 +531,12 @@ pub async fn add_spender_leaf_axum<C: Locked + 'static>(
541531
.get(&spender)
542532
.map(|spent| spent.to_owned());
543533

544-
let res = SpenderResponse {
534+
Ok(Json(SpenderResponse {
545535
spender: Spender {
546536
total_deposited: latest_spendable.deposit.total,
547537
total_spent,
548538
},
549-
};
550-
Ok(Json(res))
539+
}))
551540
}
552541

553542
async fn get_corresponding_new_state(

0 commit comments

Comments
 (0)