Skip to content

Commit

Permalink
withdraw method accept optional epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed Jul 9, 2024
1 parent c66c31f commit 721ac2f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions webserver/src/dto/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ pub struct UnbondsDto {
pub struct WithdrawsDto {
#[validate(range(min = 1, max = 10000))]
pub page: Option<u64>,
#[validate(range(min = 1, max = 10000))]
pub epoch: Option<u64>,
}
4 changes: 2 additions & 2 deletions webserver/src/handler/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ pub async fn get_merged_unbonds(
pub async fn get_withdraws(
_headers: HeaderMap,
query: Query<WithdrawsDto>,
Path((address, epoch)): Path<(String, u64)>,
Path(address): Path<String>,
State(state): State<CommonState>,
) -> Result<Json<PaginatedResponse<Vec<Withdraw>>>, ApiError> {
let page = query.page.unwrap_or(1);

let (withdraws, total_pages, total_withdraws) = state
.pos_service
.get_withdraws_by_address(address, epoch, page)
.get_withdraws_by_address(address, query.epoch, page)
.await?;

let response =
Expand Down
18 changes: 12 additions & 6 deletions webserver/src/service/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,22 @@ impl PosService {
pub async fn get_withdraws_by_address(
&self,
address: String,
current_epoch: u64,
epoch: Option<u64>,
page: u64,
) -> Result<(Vec<Withdraw>, u64, u64), PoSError> {
let epoch = if let Some(epoch) = epoch {
epoch as i32
} else {
self.chain_repo
.get_chain_state()
.await
.map_err(PoSError::Database)?
.epoch
};

let (db_withdraws, total_pages, total_items) = self
.pos_repo
.find_withdraws_by_address(
address,
current_epoch as i32,
page as i64,
)
.find_withdraws_by_address(address, epoch, page as i64)
.await
.map_err(PoSError::Database)?;

Expand Down

0 comments on commit 721ac2f

Please sign in to comment.