Skip to content

Commit 9817c89

Browse files
sergeytimoshinananas-block
authored andcommitted
feat: add v2 endpoints and update response schemas for compressed accounts and transactions
1 parent 651f24a commit 9817c89

File tree

7 files changed

+851
-99
lines changed

7 files changed

+851
-99
lines changed

src/api/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl PhotonApi {
482482
OpenApiSpec {
483483
name: "getValidityProofV2".to_string(),
484484
request: Some(GetValidityProofRequestDocumentation::schema().1),
485-
response: GetValidityProofResponse::schema().1,
485+
response: GetValidityProofResponseV2::schema().1,
486486
},
487487
OpenApiSpec {
488488
name: "getCompressionSignaturesForAccount".to_string(),

src/api/method/get_validity_proof/common.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl From<GetValidityProofResponse> for GetValidityProofResponseV2 {
8888
value: CompressedProofWithContextV2 {
8989
compressedProof: response.value.compressedProof,
9090
roots: response.value.roots,
91-
rootIndices: response.value.rootIndices.into_iter().map(Some).collect(),
91+
rootIndices: response.value.rootIndices.into_iter().map(|x| RootIndex { root_index: x, in_tree: true}).collect(),
9292
leafIndices: response.value.leafIndices,
9393
leaves: response.value.leaves,
9494
merkleTrees: response.value.merkleTrees,
@@ -191,13 +191,45 @@ pub struct CompressedProofWithContext {
191191
pub merkleTrees: Vec<String>,
192192
}
193193

194+
#[derive(Serialize, Deserialize, ToSchema, Debug, Default)]
195+
#[serde(rename_all = "camelCase")]
196+
#[allow(non_snake_case)]
197+
pub struct RootIndex {
198+
pub root_index: u64,
199+
pub in_tree: bool,
200+
}
201+
202+
impl From<RootIndex> for Option<u64> {
203+
fn from(val: RootIndex) -> Option<u64> {
204+
match val.in_tree {
205+
true => Some(val.root_index),
206+
false => None,
207+
}
208+
}
209+
}
210+
211+
impl From<Option<u64>> for RootIndex {
212+
fn from(val: Option<u64>) -> RootIndex {
213+
match val {
214+
Some(root_index) => RootIndex {
215+
root_index,
216+
in_tree: true,
217+
},
218+
None => RootIndex {
219+
root_index: 0,
220+
in_tree: false,
221+
},
222+
}
223+
}
224+
}
225+
194226
#[derive(Serialize, Deserialize, ToSchema, Debug, Default)]
195227
#[serde(rename_all = "camelCase")]
196228
#[allow(non_snake_case)]
197229
pub struct CompressedProofWithContextV2 {
198230
pub compressedProof: CompressedProof,
199231
pub roots: Vec<String>,
200-
pub rootIndices: Vec<Option<u64>>,
232+
pub rootIndices: Vec<RootIndex>,
201233
pub leafIndices: Vec<u32>,
202234
pub leaves: Vec<String>,
203235
pub merkleTrees: Vec<String>,

src/api/method/get_validity_proof/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod v1;
33
mod v2;
44

55
pub use common::{
6-
CompressedProof, CompressedProofWithContext, GetValidityProofRequest,
6+
CompressedProof, CompressedProofWithContext, CompressedProofWithContextV2, RootIndex, GetValidityProofRequest,
77
GetValidityProofRequestDocumentation, GetValidityProofResponse, GetValidityProofResponseV2,
88
};
99
pub use v1::get_validity_proof;

src/api/method/get_validity_proof/v2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub async fn get_validity_proof_v2(
9292
.to_string(),
9393
);
9494
// proof by index has no root.
95-
v2_response.value.rootIndices.insert(index, None);
95+
v2_response.value.rootIndices.insert(index, None.into());
9696
v2_response.value.roots.insert(index, "".to_string());
9797
}
9898
Ok(v2_response)

src/ingester/persist/leaf_node_proof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::dao::generated::state_trees;
55
use crate::ingester::persist::get_tree_height;
66
use crate::ingester::persist::leaf_node::{leaf_index_to_node_index, LeafNode};
77
use crate::ingester::persist::persisted_state_tree::{
8-
get_proof_nodes, get_proof_path, validate_proof, MerkleProofWithContext, ZERO_BYTES,
8+
get_proof_nodes, get_proof_path, MerkleProofWithContext, ZERO_BYTES,
99
};
1010
use sea_orm::QueryFilter;
1111
use sea_orm::{ColumnTrait, DatabaseTransaction, EntityTrait};

src/openapi/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ use crate::api::method::get_multiple_new_address_proofs::AddressWithTree;
1919
use crate::api::method::get_multiple_new_address_proofs::MerkleContextWithNewAddressProof;
2020
use crate::api::method::get_queue_elements::MerkleProofWithContextV2;
2121
use crate::api::method::get_transaction_with_compression_info::AccountWithOptionalTokenData;
22-
use crate::api::method::get_validity_proof::CompressedProof;
23-
use crate::api::method::get_validity_proof::CompressedProofWithContext;
22+
use crate::api::method::get_validity_proof::{CompressedProof, CompressedProofWithContext, CompressedProofWithContextV2, RootIndex};
2423
use crate::api::method::utils::Context;
2524
use crate::api::method::utils::Limit;
2625
use crate::api::method::utils::PaginatedSignatureInfoList;
@@ -105,6 +104,8 @@ const JSON_CONTENT_TYPE: &str = "application/json";
105104
UnsignedInteger,
106105
CompressedProof,
107106
CompressedProofWithContext,
107+
CompressedProofWithContextV2,
108+
RootIndex,
108109
MerkleContextWithNewAddressProof,
109110
SignatureInfoListWithError,
110111
SignatureInfoWithError,

0 commit comments

Comments
 (0)