Skip to content

Commit

Permalink
Merge pull request #319 from Concordium/lma/fix/serialization
Browse files Browse the repository at this point in the history
Fix serialization issue
  • Loading branch information
lassemand authored Dec 4, 2024
2 parents 0c3df2b + 31921d5 commit 46871c6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
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
31 changes: 27 additions & 4 deletions backend-rust/src/graphql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use std::{error::Error, mem, str::FromStr, sync::Arc};
use tokio::{net::TcpListener, sync::broadcast};
use tokio_stream::wrappers::errors::BroadcastStreamRecvError;
use tokio_util::sync::CancellationToken;
use tracing::error;
use transaction_metrics::TransactionMetricsQuery;

const VERSION: &str = clap::crate_version!();
Expand Down Expand Up @@ -4258,7 +4259,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 @@ -4774,7 +4774,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 @@ -5025,11 +5024,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);
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 @@ -5112,11 +5123,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

0 comments on commit 46871c6

Please sign in to comment.