Skip to content

Commit befd571

Browse files
committed
Added enum for graphql transaction status
1 parent 7a5c1e2 commit befd571

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

node/native/src/graphql/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ use openmina_core::consensus::ConsensusConstants;
1919
use openmina_core::constants::constraint_constants;
2020
use openmina_node_common::rpc::RpcSender;
2121
use std::str::FromStr;
22+
use transaction::GraphQLTransactionStatus;
2223
use warp::{Filter, Rejection, Reply};
2324

2425
pub mod account;
2526
pub mod block;
2627
pub mod constants;
28+
pub mod transaction;
2729
pub mod zkapp;
2830

2931
#[derive(Debug, thiserror::Error)]
@@ -236,7 +238,7 @@ impl Query {
236238
payment: Option<String>,
237239
zkapp_transaction: Option<String>,
238240
context: &Context,
239-
) -> juniper::FieldResult<String> {
241+
) -> juniper::FieldResult<GraphQLTransactionStatus> {
240242
if payment.is_some() && zkapp_transaction.is_some() {
241243
return Err(Error::Custom(
242244
"Cannot provide both payment and zkapp transaction".to_string(),
@@ -263,7 +265,8 @@ impl Query {
263265
.oneshot_request(RpcRequest::TransactionStatusGet(tx))
264266
.await
265267
.ok_or(Error::StateMachineEmptyResponse)?;
266-
Ok(res.to_string())
268+
269+
Ok(GraphQLTransactionStatus::from(res))
267270
}
268271

269272
/// Retrieve a block with the given state hash or height, if contained in the transition frontier
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use juniper::GraphQLEnum;
2+
use node::rpc::TransactionStatus;
3+
4+
#[derive(Clone, Copy, Debug, GraphQLEnum)]
5+
#[allow(non_camel_case_types)]
6+
pub enum GraphQLTransactionStatus {
7+
INCLUDED,
8+
PENDING,
9+
UNKNOWN,
10+
}
11+
12+
impl From<TransactionStatus> for GraphQLTransactionStatus {
13+
fn from(value: TransactionStatus) -> Self {
14+
match value {
15+
TransactionStatus::Included => Self::INCLUDED,
16+
TransactionStatus::Pending => Self::PENDING,
17+
TransactionStatus::Unknown => Self::UNKNOWN,
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)