fuel_core/schema/
relayed_tx.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::{
    fuel_core_graphql_api::query_costs,
    schema::{
        scalars::{
            RelayedTransactionId,
            U32,
        },
        ReadViewProvider,
    },
};
use async_graphql::{
    Context,
    Object,
    Union,
};
use fuel_core_types::{
    entities::relayer::transaction::RelayedTransactionStatus as FuelRelayedTransactionStatus,
    fuel_types::BlockHeight,
};

#[derive(Default)]
pub struct RelayedTransactionQuery {}

#[Object]
impl RelayedTransactionQuery {
    #[graphql(complexity = "query_costs().storage_read + child_complexity")]
    async fn relayed_transaction_status(
        &self,
        ctx: &Context<'_>,
        #[graphql(desc = "The id of the relayed tx")] id: RelayedTransactionId,
    ) -> async_graphql::Result<Option<RelayedTransactionStatus>> {
        let query = ctx.read_view()?;
        let status = query.relayed_tx_status(id.0)?.map(|status| status.into());
        Ok(status)
    }
}

#[derive(Union, Debug)]
pub enum RelayedTransactionStatus {
    Failed(RelayedTransactionFailed),
}

#[derive(Debug)]
pub struct RelayedTransactionFailed {
    pub block_height: BlockHeight,
    pub failure: String,
}

#[Object]
impl RelayedTransactionFailed {
    async fn block_height(&self) -> U32 {
        let as_u32: u32 = self.block_height.into();
        as_u32.into()
    }

    async fn failure(&self) -> String {
        self.failure.clone()
    }
}

impl From<FuelRelayedTransactionStatus> for RelayedTransactionStatus {
    fn from(status: FuelRelayedTransactionStatus) -> Self {
        match status {
            FuelRelayedTransactionStatus::Failed {
                block_height,
                failure,
            } => RelayedTransactionStatus::Failed(RelayedTransactionFailed {
                block_height,
                failure,
            }),
        }
    }
}