Skip to content

Commit

Permalink
rusk: add next_phoenix to graphQL
Browse files Browse the repository at this point in the history
- Add ord param to full_moonlight_history
  • Loading branch information
Neotamandua committed Dec 4, 2024
1 parent ce15620 commit 3b7f794
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
17 changes: 16 additions & 1 deletion rusk/src/lib/http/chain/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ impl Query {
&self,
ctx: &Context<'_>,
address: String,
ord: Option<String>,
) -> OptResult<DeserializedMoonlightGroups> {
full_moonlight_history(ctx, address).await
full_moonlight_history(ctx, address, ord).await
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -251,4 +252,18 @@ impl Query {
last_finalized_block,
})
}

/// Get the next block height that contains a Phoenix event after the given
/// block height.
#[cfg(feature = "archive")]
async fn next_phoenix(
&self,
ctx: &Context<'_>,
height: i64,
) -> OptResult<u64> {
let (_, archive) = ctx.data::<DBContext>()?;
let next_height = archive.next_phoenix(height).await?;

Ok(next_height)
}
}
11 changes: 9 additions & 2 deletions rusk/src/lib/http/chain/graphql/archive/moonlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use execution_core::transfer::{
CONVERT_TOPIC, MINT_TOPIC, MOONLIGHT_TOPIC, TRANSFER_CONTRACT,
WITHDRAW_TOPIC,
};
use node::archive::MoonlightGroup;
use node::archive::{MoonlightGroup, Order};
use node_data::events::contract::ContractEvent;

use async_graphql::{Context, FieldError};
Expand All @@ -25,6 +25,7 @@ use crate::http::chain::graphql::{DBContext, OptResult};
pub async fn full_moonlight_history(
ctx: &Context<'_>,
address: String,
ordering: Option<String>,
) -> OptResult<DeserializedMoonlightGroups> {
let (_, archive) = ctx.data::<DBContext>()?;
let v = bs58::decode(address).into_vec()?;
Expand All @@ -36,7 +37,13 @@ pub async fn full_moonlight_history(
let pk = AccountPublicKey::from_bytes(&pk_bytes)
.map_err(|_| anyhow::anyhow!("Failed to serialize given public key"))?;

let moonlight_groups = archive.full_moonlight_history(pk)?;
let ord = match ordering.unwrap_or_default().as_str() {
"asc" => Some(Order::Ascending),
"desc" => Some(Order::Descending),
_ => None,
};

let moonlight_groups = archive.full_moonlight_history(pk, ord)?;

let mut deser_moonlight_groups = Vec::new();

Expand Down

0 comments on commit 3b7f794

Please sign in to comment.