From 2c7c774c19c4387be78f0e7baef90dc2e60ce6be Mon Sep 17 00:00:00 2001 From: Swenschaeferjohann Date: Fri, 28 Feb 2025 01:54:55 +0000 Subject: [PATCH 1/2] pass as u16 --- src/api/method/get_validity_proof/common.rs | 28 ++++++++++----------- src/api/method/get_validity_proof/v2.rs | 2 +- src/api/method/utils.rs | 2 +- src/common/typedefs/account.rs | 6 ++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/api/method/get_validity_proof/common.rs b/src/api/method/get_validity_proof/common.rs index 17d6aa49..d4e03509 100644 --- a/src/api/method/get_validity_proof/common.rs +++ b/src/api/method/get_validity_proof/common.rs @@ -124,7 +124,7 @@ impl From for GetValidityProofResponseV2 { .merkleTrees .iter() .map(|x| MerkleContextV2 { - tree_type: SerializableTreeType::Unknown, + tree_type: 0, // TODO: check tree: SerializablePubkey::try_from(x.as_str()).unwrap(), // TODO: handle error queue: SerializablePubkey::default(), cpi_context: None, @@ -273,24 +273,24 @@ pub enum SerializableTreeType { } // from u64 -impl From for SerializableTreeType { - fn from(value: u16) -> Self { - match value { - 0 => SerializableTreeType::Unknown, - 1 => SerializableTreeType::State, - 2 => SerializableTreeType::Address, - 3 => SerializableTreeType::BatchedState, - 4 => SerializableTreeType::BatchedAddress, - _ => panic!("Invalid TreeType"), - } - } -} +// impl From for SerializableTreeType { +// fn from(value: u16) -> Self { +// match value { +// 0 => SerializableTreeType::Unknown, +// 1 => SerializableTreeType::State, +// 2 => SerializableTreeType::Address, +// 3 => SerializableTreeType::BatchedState, +// 4 => SerializableTreeType::BatchedAddress, +// _ => panic!("Invalid TreeType"), +// } +// } +// } #[derive(Serialize, Deserialize, ToSchema, Debug, Clone, Eq, PartialEq)] #[serde(rename_all = "camelCase")] #[allow(non_snake_case)] pub struct MerkleContextV2 { - pub tree_type: SerializableTreeType, + pub tree_type: u16, pub tree: SerializablePubkey, // nullifier_queue in legacy trees, output_queue in V2 trees. pub queue: SerializablePubkey, diff --git a/src/api/method/get_validity_proof/v2.rs b/src/api/method/get_validity_proof/v2.rs index 872d05f8..ea22f1db 100644 --- a/src/api/method/get_validity_proof/v2.rs +++ b/src/api/method/get_validity_proof/v2.rs @@ -114,7 +114,7 @@ pub async fn get_validity_proof_v2( v2_response.value.merkle_context.insert( index, MerkleContextV2 { - tree_type: SerializableTreeType::from(account.tree_type as u16), + tree_type: account.tree_type as u16, tree: SerializablePubkey::try_from_slice(account.tree.as_slice()) .unwrap_or(SerializablePubkey::default()), queue: SerializablePubkey::try_from_slice(account.queue.as_slice()) diff --git a/src/api/method/utils.rs b/src/api/method/utils.rs index 99da827a..559e7bc9 100644 --- a/src/api/method/utils.rs +++ b/src/api/method/utils.rs @@ -178,7 +178,7 @@ impl TryFrom for AccountWithContext { .map(|index| UnsignedInteger(index as u64)), nullifier: account.nullifier.map(Hash::try_from).transpose()?, tx_hash: account.tx_hash.map(Hash::try_from).transpose()?, - tree_type: SerializableTreeType::from(account.tree_type as u16), + tree_type: account.tree_type as u16, }, }) } diff --git a/src/common/typedefs/account.rs b/src/common/typedefs/account.rs index 0d528253..ab00262c 100644 --- a/src/common/typedefs/account.rs +++ b/src/common/typedefs/account.rs @@ -127,7 +127,7 @@ impl TryFrom for AccountV2 { seq: account.seq.map(|seq| UnsignedInteger(seq as u64)), prove_by_index: account.in_output_queue, merkle_context: MerkleContextV2 { - tree_type: SerializableTreeType::from(account.tree_type as u16), + tree_type: account.tree_type as u16, tree: account.tree.try_into()?, queue: account.queue.clone().try_into()?, cpi_context: None, @@ -162,7 +162,7 @@ pub struct AccountContext { // Legacy: None // Batched: None if inserted into output queue or inserted in tree from output queue, else Some(nullifier) pub tx_hash: Option, - pub tree_type: SerializableTreeType, + pub tree_type: u16, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, ToSchema)] @@ -221,7 +221,7 @@ impl AccountWithContext { nullifier_queue_index: nullifier_queue_index.map(UnsignedInteger), nullifier, tx_hash: None, - tree_type: SerializableTreeType::from(tree_type as u16), + tree_type: tree_type as u16, }, } } From 27c1c7d05f28314a2542217d006e24033147b863 Mon Sep 17 00:00:00 2001 From: Swenschaeferjohann Date: Fri, 28 Feb 2025 02:06:32 +0000 Subject: [PATCH 2/2] rm --- src/api/method/get_validity_proof/common.rs | 17 ++--------------- src/api/method/get_validity_proof/mod.rs | 1 - src/api/method/get_validity_proof/v2.rs | 1 - src/api/method/utils.rs | 1 - src/common/typedefs/account.rs | 2 +- src/openapi/mod.rs | 3 +-- 6 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/api/method/get_validity_proof/common.rs b/src/api/method/get_validity_proof/common.rs index d4e03509..a38b8b1a 100644 --- a/src/api/method/get_validity_proof/common.rs +++ b/src/api/method/get_validity_proof/common.rs @@ -262,7 +262,8 @@ impl From> for RootIndex { } } -#[repr(u64)] +// TODO: Keep in here for API doc generation? +#[repr(u16)] #[derive(Serialize, Deserialize, ToSchema, Debug, PartialEq, Clone, Copy, Eq)] pub enum SerializableTreeType { State = 1, @@ -272,20 +273,6 @@ pub enum SerializableTreeType { Unknown = 0, // TODO: remove this } -// from u64 -// impl From for SerializableTreeType { -// fn from(value: u16) -> Self { -// match value { -// 0 => SerializableTreeType::Unknown, -// 1 => SerializableTreeType::State, -// 2 => SerializableTreeType::Address, -// 3 => SerializableTreeType::BatchedState, -// 4 => SerializableTreeType::BatchedAddress, -// _ => panic!("Invalid TreeType"), -// } -// } -// } - #[derive(Serialize, Deserialize, ToSchema, Debug, Clone, Eq, PartialEq)] #[serde(rename_all = "camelCase")] #[allow(non_snake_case)] diff --git a/src/api/method/get_validity_proof/mod.rs b/src/api/method/get_validity_proof/mod.rs index f31416a7..e6131274 100644 --- a/src/api/method/get_validity_proof/mod.rs +++ b/src/api/method/get_validity_proof/mod.rs @@ -6,7 +6,6 @@ pub use common::{ CompressedProof, CompressedProofWithContext, CompressedProofWithContextV2, ContextInfo, GetValidityProofRequest, GetValidityProofRequestDocumentation, GetValidityProofRequestV2, GetValidityProofResponse, GetValidityProofResponseV2, MerkleContextV2, RootIndex, - SerializableTreeType, }; pub use v1::get_validity_proof; pub use v2::get_validity_proof_v2; diff --git a/src/api/method/get_validity_proof/v2.rs b/src/api/method/get_validity_proof/v2.rs index ea22f1db..5513d82b 100644 --- a/src/api/method/get_validity_proof/v2.rs +++ b/src/api/method/get_validity_proof/v2.rs @@ -7,7 +7,6 @@ use itertools::Itertools; use sea_orm::{DatabaseBackend, DatabaseConnection, Statement, TransactionTrait}; use super::common::{GetValidityProofRequestV2, GetValidityProofResponseV2, MerkleContextV2}; -use crate::api::method::get_validity_proof::SerializableTreeType; use crate::common::typedefs::hash::Hash; use crate::dao::generated::accounts; use sea_orm::{ColumnTrait, ConnectionTrait, EntityTrait, QueryFilter}; diff --git a/src/api/method/utils.rs b/src/api/method/utils.rs index 559e7bc9..700b4d3e 100644 --- a/src/api/method/utils.rs +++ b/src/api/method/utils.rs @@ -26,7 +26,6 @@ use crate::common::typedefs::hash::Hash; use crate::common::typedefs::serializable_pubkey::SerializablePubkey; use super::super::error::PhotonApiError; -use crate::api::method::get_validity_proof::SerializableTreeType; use crate::dao::generated::accounts::Model; use sea_orm_migration::sea_query::Expr; diff --git a/src/common/typedefs/account.rs b/src/common/typedefs/account.rs index ab00262c..113ebdf4 100644 --- a/src/common/typedefs/account.rs +++ b/src/common/typedefs/account.rs @@ -3,7 +3,7 @@ use super::{ unsigned_integer::UnsignedInteger, }; use crate::api::error::PhotonApiError; -use crate::api::method::get_validity_proof::{MerkleContextV2, SerializableTreeType}; +use crate::api::method::get_validity_proof::MerkleContextV2; use crate::api::method::utils::parse_decimal; use crate::dao::generated::accounts; use crate::dao::generated::accounts::Model; diff --git a/src/openapi/mod.rs b/src/openapi/mod.rs index 93079a45..1058e408 100644 --- a/src/openapi/mod.rs +++ b/src/openapi/mod.rs @@ -25,7 +25,7 @@ use crate::api::method::get_transaction_with_compression_info::{ }; use crate::api::method::get_validity_proof::{ CompressedProof, CompressedProofWithContext, CompressedProofWithContextV2, ContextInfo, - MerkleContextV2, RootIndex, SerializableTreeType, + MerkleContextV2, RootIndex, }; use crate::api::method::utils::Context; use crate::api::method::utils::Limit; @@ -134,7 +134,6 @@ const JSON_CONTENT_TYPE: &str = "application/json"; TokenBalanceListV2, MerkleContextV2, ContextInfo, - SerializableTreeType )))] struct ApiDoc;