iota_faucet/
responses.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use serde::{Deserialize, Serialize};
6use uuid::Uuid;
7
8use crate::*;
9
10#[derive(Serialize, Deserialize, Debug, Clone)]
11#[serde(rename_all = "camelCase")]
12pub struct FaucetResponse {
13    pub transferred_gas_objects: Vec<CoinInfo>,
14    pub error: Option<String>,
15}
16
17impl From<FaucetError> for FaucetResponse {
18    fn from(e: FaucetError) -> Self {
19        Self {
20            error: Some(e.to_string()),
21            transferred_gas_objects: vec![],
22        }
23    }
24}
25
26impl From<FaucetReceipt> for FaucetResponse {
27    fn from(v: FaucetReceipt) -> Self {
28        Self {
29            transferred_gas_objects: v.sent,
30            error: None,
31        }
32    }
33}
34
35#[derive(Serialize, Deserialize, Debug, Clone)]
36#[serde(rename_all = "camelCase")]
37pub struct BatchFaucetResponse {
38    // This string is the Uuid for the req
39    pub task: Option<String>,
40    pub error: Option<String>,
41}
42
43impl From<FaucetError> for BatchFaucetResponse {
44    fn from(e: FaucetError) -> Self {
45        Self {
46            error: Some(e.to_string()),
47            task: None,
48        }
49    }
50}
51
52impl From<BatchFaucetReceipt> for BatchFaucetResponse {
53    fn from(v: BatchFaucetReceipt) -> Self {
54        Self {
55            task: Some(v.task),
56            error: None,
57        }
58    }
59}
60
61impl From<Uuid> for BatchFaucetResponse {
62    fn from(v: Uuid) -> Self {
63        Self {
64            task: Some(v.to_string()),
65            error: None,
66        }
67    }
68}
69
70#[derive(Serialize, Deserialize, Debug, Clone)]
71#[serde(rename_all = "camelCase")]
72pub struct BatchStatusFaucetResponse {
73    // This string is the Uuid for the req
74    pub status: Option<BatchSendStatus>,
75    pub error: Option<String>,
76}
77
78impl From<FaucetError> for BatchStatusFaucetResponse {
79    fn from(e: FaucetError) -> Self {
80        Self {
81            error: Some(e.to_string()),
82            status: None,
83        }
84    }
85}
86
87impl From<BatchSendStatus> for BatchStatusFaucetResponse {
88    fn from(v: BatchSendStatus) -> Self {
89        Self {
90            status: Some(v),
91            error: None,
92        }
93    }
94}