Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serialization issue #319

Merged
merged 12 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ target/

.vscode/

.env
.env

**/.idea
2 changes: 1 addition & 1 deletion backend-rust/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ services:
- ./data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: ${PGPASSWORD}
POSTGRES_DB: ccd-scan
POSTGRES_DB: ccdscan
lassemand marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 27 additions & 4 deletions backend-rust/src/graphql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use sqlx::{postgres::types::PgInterval, PgPool};
use std::{error::Error, mem, str::FromStr, sync::Arc};
use tokio::{net::TcpListener, sync::broadcast};
use tokio_util::sync::CancellationToken;
use tracing::error;
use transaction_metrics::TransactionMetricsQuery;

const VERSION: &str = clap::crate_version!();
Expand Down Expand Up @@ -4159,7 +4160,6 @@ pub fn events_from_summary(
} => {
vec![Event::DataRegistered(DataRegistered {
data_as_hex: hex::encode(data.as_ref()),
decoded: DecodedText::from_bytes(data.as_ref()),
})]
}
AccountTransactionEffects::BakerConfigured {
Expand Down Expand Up @@ -4675,7 +4675,6 @@ impl TryFrom<concordium_rust_sdk::types::RejectReason> for TransactionRejectReas
impl From<concordium_rust_sdk::types::Memo> for TransferMemo {
fn from(value: concordium_rust_sdk::types::Memo) -> Self {
TransferMemo {
decoded: DecodedText::from_bytes(value.as_ref()),
raw_hex: hex::encode(value.as_ref()),
}
}
Expand Down Expand Up @@ -4917,11 +4916,23 @@ pub struct CredentialsUpdated {
}

#[derive(SimpleObject, serde::Serialize, serde::Deserialize)]
#[graphql(complex)]
pub struct DataRegistered {
decoded: DecodedText,
data_as_hex: String,
}

#[ComplexObject]
impl DataRegistered {
async fn decoded(&self) -> ApiResult<DecodedText> {
let decoded_data = hex::decode(&self.data_as_hex).map_err(|e| {
error!("Invalid hex encoding {:?} in a controlled environment", e);
lassemand marked this conversation as resolved.
Show resolved Hide resolved
ApiError::InternalError("Failed to decode hex data".to_string())
})?;

Ok(DecodedText::from_bytes(decoded_data.as_slice()))
}
}

#[derive(SimpleObject, serde::Serialize, serde::Deserialize)]
pub struct DecodedText {
text: String,
Expand Down Expand Up @@ -5004,11 +5015,23 @@ impl TryFrom<concordium_rust_sdk::types::NewEncryptedAmountEvent> for NewEncrypt
}

#[derive(SimpleObject, serde::Serialize, serde::Deserialize)]
#[graphql(complex)]
pub struct TransferMemo {
decoded: DecodedText,
raw_hex: String,
}

#[ComplexObject]
impl TransferMemo {
async fn decoded(&self) -> ApiResult<DecodedText> {
let decoded_data = hex::decode(&self.raw_hex).map_err(|e| {
error!("Invalid hex encoding {:?} in a controlled environment", e);
ApiError::InternalError("Failed to decode hex data".to_string())
})?;

Ok(DecodedText::from_bytes(decoded_data.as_slice()))
}
}

#[derive(SimpleObject, serde::Serialize, serde::Deserialize)]
pub struct TransferredWithSchedule {
from_account_address: AccountAddress,
Expand Down
Loading