xand_api_client/
proto_help.rs1use crate::{models::Paginated, TransactionHistoryPage};
2use std::convert::{TryFrom, TryInto};
3use xand_api_proto::error::XandApiProtoErrs;
4use xand_api_proto::proto_models::{PendingCreateRequest, PendingRedeemRequest};
5use xand_api_proto::{PendingCreateRequests, PendingRedeemRequests, TransactionHistory};
6
7impl TryFrom<PendingCreateRequests> for Paginated<Vec<PendingCreateRequest>> {
8 type Error = XandApiProtoErrs;
9
10 fn try_from(pc: PendingCreateRequests) -> Result<Self, Self::Error> {
11 Ok(Paginated {
12 data: pc
13 .pending_create_requests
14 .into_iter()
15 .map(PendingCreateRequest::try_from)
16 .collect::<Result<_, _>>()?,
17 total: pc.total,
18 })
19 }
20}
21
22impl TryFrom<PendingRedeemRequests> for Paginated<Vec<PendingRedeemRequest>> {
23 type Error = XandApiProtoErrs;
24
25 fn try_from(pr: PendingRedeemRequests) -> Result<Self, Self::Error> {
26 Ok(Paginated {
27 data: pr
28 .pending_redeem_requests
29 .into_iter()
30 .map(PendingRedeemRequest::try_from)
31 .collect::<Result<_, _>>()?,
32 total: pr.total,
33 })
34 }
35}
36
37impl TryFrom<TransactionHistory> for TransactionHistoryPage {
38 type Error = XandApiProtoErrs;
39
40 fn try_from(h: TransactionHistory) -> Result<Self, Self::Error> {
41 Ok(Paginated {
42 data: h
43 .transactions
44 .into_iter()
45 .map(TryInto::try_into)
46 .collect::<Result<Vec<_>, _>>()?,
47 total: h.total,
48 })
49 }
50}