Skip to content
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
12 changes: 6 additions & 6 deletions src/api/method/get_compressed_account_proof/v2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::api::error::PhotonApiError;
use crate::api::method::get_validity_proof::ContextInfo;
use crate::api::method::get_validity_proof::TreeContextInfo;
use crate::api::method::utils::HashRequest;
use crate::common::typedefs::context::Context;
use crate::common::typedefs::hash::Hash;
Expand Down Expand Up @@ -33,7 +33,7 @@ pub struct GetCompressedAccountProofResponseValueV2 {
pub hash: Hash,
pub root_seq: u64,
pub prove_by_index: bool,
pub context: ContextInfo,
pub tree_context: TreeContextInfo,
}

impl From<MerkleProofWithContext> for GetCompressedAccountProofResponseValueV2 {
Expand All @@ -46,9 +46,9 @@ impl From<MerkleProofWithContext> for GetCompressedAccountProofResponseValueV2 {
root_seq: proof.root_seq,
prove_by_index: false,
// Default values to be overridden as needed
context: ContextInfo {
tree_context: TreeContextInfo {
tree_type: 0,
merkle_tree: proof.merkle_tree,
tree: proof.merkle_tree,
queue: Default::default(),
cpi_context: None,
},
Expand Down Expand Up @@ -127,8 +127,8 @@ pub async fn get_compressed_account_proof_v2(

// Enrich with account data if available
if let Some(account) = account {
result.context.tree_type = account.tree_type as u16;
result.context.queue = SerializablePubkey::try_from(account.queue)?;
result.tree_context.tree_type = account.tree_type as u16;
result.tree_context.queue = SerializablePubkey::try_from(account.queue)?;
}

let response = GetCompressedAccountProofResponseV2 {
Expand Down
6 changes: 3 additions & 3 deletions src/api/method/get_multiple_compressed_account_proofs/v2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::api::error::PhotonApiError;
use crate::api::method::get_compressed_account_proof::GetCompressedAccountProofResponseValueV2;
use crate::api::method::get_multiple_compressed_account_proofs::HashList;
use crate::api::method::get_validity_proof::ContextInfo;
use crate::api::method::get_validity_proof::TreeContextInfo;
use crate::api::method::utils::PAGE_LIMIT;
use crate::common::typedefs::context::Context;
use crate::common::typedefs::hash::Hash;
Expand Down Expand Up @@ -145,9 +145,9 @@ pub async fn get_multiple_compressed_account_proofs_v2(
// Enrich with account data
for value in &mut result {
if let Some(account) = account_map.get(&value.hash.to_vec()) {
value.context = ContextInfo {
value.tree_context = TreeContextInfo {
tree_type: account.tree_type as u16,
merkle_tree: SerializablePubkey::try_from(account.tree.clone())?,
tree: SerializablePubkey::try_from(account.tree.clone())?,
queue: SerializablePubkey::try_from(account.queue.clone())?,
cpi_context: None,
};
Expand Down
10 changes: 5 additions & 5 deletions src/api/method/get_queue_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::ingester::persist::get_multiple_compressed_leaf_proofs_by_indices;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema, Default)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct GetQueueElementsRequest {
pub merkle_tree: Hash,
pub tree: Hash,
pub start_offset: Option<u64>,
pub num_elements: u16,
pub queue_type: u8,
Expand All @@ -37,7 +37,7 @@ pub struct GetQueueElementsResponseValue {
pub root: Hash,
pub leaf_index: u64,
pub leaf: Hash,
pub merkle_tree: Hash,
pub tree: Hash,
pub root_seq: u64,
pub tx_hash: Option<Hash>,
pub account_hash: Hash,
Expand Down Expand Up @@ -68,7 +68,7 @@ pub async fn get_queue_elements(
}

let mut query_condition =
Condition::all().add(accounts::Column::Tree.eq(request.merkle_tree.to_vec()));
Condition::all().add(accounts::Column::Tree.eq(request.tree.to_vec()));

match queue_type {
QueueType::BatchedInput => {
Expand Down Expand Up @@ -132,7 +132,7 @@ pub async fn get_queue_elements(
(
get_multiple_compressed_leaf_proofs_by_indices(
&tx,
SerializablePubkey::from(request.merkle_tree.0),
SerializablePubkey::from(request.tree.0),
indices,
)
.await?,
Expand All @@ -158,7 +158,7 @@ pub async fn get_queue_elements(
root: proof.root,
leaf_index: proof.leaf_index as u64,
leaf: proof.hash,
merkle_tree: Hash::from(proof.merkle_tree.0.to_bytes()),
tree: Hash::from(proof.merkle_tree.0.to_bytes()),
root_seq: proof.root_seq,
tx_hash,
account_hash,
Expand Down
36 changes: 18 additions & 18 deletions src/api/method/get_transaction_with_compression_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ pub struct AccountWithOptionalTokenDataV2 {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, ToSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
#[allow(non_snake_case)]
pub struct ClosedAccountWithOptionalTokenData {
pub account: ClosedAccount,
pub struct ClosedAccountWithOptionalTokenDataV2 {
pub account: ClosedAccountV2,
pub optionalTokenData: Option<TokenData>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, ToSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
#[allow(non_snake_case)]
pub struct CompressionInfoV2 {
pub closedAccounts: Vec<ClosedAccountWithOptionalTokenData>,
pub closedAccounts: Vec<ClosedAccountWithOptionalTokenDataV2>,
pub openedAccounts: Vec<AccountWithOptionalTokenDataV2>,
}

Expand Down Expand Up @@ -285,20 +285,20 @@ fn parse_optional_token_data_v2(
})
}

fn parse_optional_token_data_for_multiple_accounts_closed_account(
accounts: Vec<ClosedAccount>,
) -> Result<Vec<ClosedAccountWithOptionalTokenData>, PhotonApiError> {
fn parse_optional_token_data_for_multiple_closed_accounts_v2(
accounts: Vec<ClosedAccountV2>,
) -> Result<Vec<ClosedAccountWithOptionalTokenDataV2>, PhotonApiError> {
accounts
.into_iter()
.map(parse_optional_token_data_closed_account)
.map(parse_optional_token_data_closed_account_v2)
.collect()
}

fn parse_optional_token_data_closed_account(
account: ClosedAccount,
) -> Result<ClosedAccountWithOptionalTokenData, PhotonApiError> {
fn parse_optional_token_data_closed_account_v2(
account: ClosedAccountV2,
) -> Result<ClosedAccountWithOptionalTokenDataV2, PhotonApiError> {
let hash = account.account.hash.clone();
Ok(ClosedAccountWithOptionalTokenData {
Ok(ClosedAccountWithOptionalTokenDataV2 {
optionalTokenData: parse_token_data_v2(&account.account).map_err(|e| {
PhotonApiError::UnexpectedError(format!(
"Failed to parse token data for account {}: {}",
Expand All @@ -320,7 +320,7 @@ fn parse_optional_token_data_for_multiple_accounts_v2(

#[derive(Debug, Clone, PartialEq, Eq, Serialize, ToSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct ClosedAccount {
pub struct ClosedAccountV2 {
pub account: AccountV2,
pub nullifier: Hash,
pub tx_hash: Hash,
Expand Down Expand Up @@ -368,8 +368,8 @@ pub async fn get_transaction_helper_v2(
.collect::<Result<Vec<AccountWithContext>, PhotonApiError>>()?;
let closed_accounts = closed_accounts
.into_iter()
.map(|x| -> Result<ClosedAccount, PhotonApiError> {
Ok(ClosedAccount {
.map(|x| -> Result<ClosedAccountV2, PhotonApiError> {
Ok(ClosedAccountV2 {
account: AccountV2 {
hash: x.account.hash,
address: x.account.address,
Expand All @@ -385,14 +385,14 @@ pub async fn get_transaction_helper_v2(
tree: x.account.tree,
queue: x.context.queue,
cpi_context: None,
next_context: None,
next_tree_context: None,
},
},
nullifier: x.context.nullifier.unwrap_or_default(),
tx_hash: x.context.tx_hash.unwrap_or_default(),
})
})
.collect::<Result<Vec<ClosedAccount>, PhotonApiError>>()?;
.collect::<Result<Vec<ClosedAccountV2>, PhotonApiError>>()?;

let out_accounts = status_update
.out_accounts
Expand All @@ -412,15 +412,15 @@ pub async fn get_transaction_helper_v2(
tree: x.account.tree,
queue: x.context.queue,
cpi_context: None,
next_context: None,
next_tree_context: None,
},
})
.collect::<Vec<AccountV2>>();

Ok(GetTransactionResponseV2 {
transaction: txn,
compressionInfo: CompressionInfoV2 {
closedAccounts: parse_optional_token_data_for_multiple_accounts_closed_account(
closedAccounts: parse_optional_token_data_for_multiple_closed_accounts_v2(
closed_accounts,
)?,
openedAccounts: parse_optional_token_data_for_multiple_accounts_v2(out_accounts)?,
Expand Down
12 changes: 6 additions & 6 deletions src/api/method/get_validity_proof/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl From<GetValidityProofResponse> for GetValidityProofResponseV2 {
.collect(),
leafIndices: response.value.leafIndices,
leaves: response.value.leaves,
merkle_context: response
merkle_contexts: response
.value
.merkleTrees
.iter()
Expand All @@ -131,7 +131,7 @@ impl From<GetValidityProofResponse> for GetValidityProofResponseV2 {
tree: SerializablePubkey::from(tree_info.tree),
queue: SerializablePubkey::from(tree_info.queue),
cpi_context: None,
next_context: None,
next_tree_context: None,
}
})
.collect(),
Expand Down Expand Up @@ -275,15 +275,15 @@ pub struct MerkleContextV2 {
// nullifier_queue in legacy trees, output_queue in V2 trees.
pub queue: SerializablePubkey,
pub cpi_context: Option<SerializablePubkey>,
pub next_context: Option<ContextInfo>,
pub next_tree_context: Option<TreeContextInfo>,
}

#[derive(Serialize, Deserialize, ToSchema, Debug, Default, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
#[allow(non_snake_case)]
pub struct ContextInfo {
pub struct TreeContextInfo {
pub tree_type: u16,
pub merkle_tree: SerializablePubkey,
pub tree: SerializablePubkey,
pub queue: SerializablePubkey,
pub cpi_context: Option<SerializablePubkey>,
}
Expand All @@ -297,7 +297,7 @@ pub struct CompressedProofWithContextV2 {
pub rootIndices: Vec<RootIndex>,
pub leafIndices: Vec<u32>,
pub leaves: Vec<String>,
pub merkle_context: Vec<MerkleContextV2>,
pub merkle_contexts: Vec<MerkleContextV2>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
3 changes: 2 additions & 1 deletion src/api/method/get_validity_proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ mod v1;
mod v2;

pub use common::{
CompressedProof, CompressedProofWithContext, CompressedProofWithContextV2, ContextInfo,
CompressedProof, CompressedProofWithContext, CompressedProofWithContextV2,
GetValidityProofRequest, GetValidityProofRequestDocumentation, GetValidityProofRequestV2,
GetValidityProofResponse, GetValidityProofResponseV2, MerkleContextV2, RootIndex,
TreeContextInfo,
};
pub use v1::get_validity_proof;
pub use v2::get_validity_proof_v2;
4 changes: 2 additions & 2 deletions src/api/method/get_validity_proof/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub async fn get_validity_proof_v2(
.value
.leaves
.insert(index, Hash::new(account.hash.as_slice())?.to_string());
v2_response.value.merkle_context.insert(
v2_response.value.merkle_contexts.insert(
index,
MerkleContextV2 {
tree_type: account.tree_type as u16,
Expand All @@ -117,7 +117,7 @@ pub async fn get_validity_proof_v2(
queue: SerializablePubkey::try_from_slice(account.queue.as_slice())
.unwrap_or(SerializablePubkey::default()),
cpi_context: None,
next_context: None,
next_tree_context: None,
},
);
// proof by index has no root.
Expand Down
2 changes: 1 addition & 1 deletion src/common/typedefs/account/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl TryFrom<Model> for AccountV2 {
tree: account.tree.try_into()?,
queue: account.queue.clone().try_into()?,
cpi_context: None,
next_context: None,
next_tree_context: None,
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/ingester/persist/persisted_state_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ mod tests {
root: Hash::try_from(ZERO_BYTES[31].to_vec()).unwrap(),
leaf_index: test_leaf_index,
hash: Hash::try_from(ZERO_BYTES[0].to_vec()).unwrap(),
merkle_tree: merkle_tree,
merkle_tree,
root_seq: 0,
};

Expand Down
14 changes: 7 additions & 7 deletions src/openapi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ use crate::api::method::get_multiple_new_address_proofs::MerkleContextWithNewAdd
use crate::api::method::get_queue_elements::GetQueueElementsResponseValue;
use crate::api::method::get_transaction_with_compression_info::CompressionInfoV2;
use crate::api::method::get_transaction_with_compression_info::{
AccountWithOptionalTokenData, AccountWithOptionalTokenDataV2, ClosedAccount,
ClosedAccountWithOptionalTokenData,
AccountWithOptionalTokenData, AccountWithOptionalTokenDataV2, ClosedAccountV2,
ClosedAccountWithOptionalTokenDataV2,
};
use crate::api::method::get_validity_proof::{
CompressedProof, CompressedProofWithContext, CompressedProofWithContextV2, ContextInfo,
MerkleContextV2, RootIndex,
CompressedProof, CompressedProofWithContext, CompressedProofWithContextV2, MerkleContextV2,
RootIndex, TreeContextInfo,
};
use crate::api::method::utils::PaginatedSignatureInfoList;
use crate::api::method::utils::SignatureInfo;
Expand Down Expand Up @@ -113,8 +113,8 @@ const JSON_CONTENT_TYPE: &str = "application/json";
AccountData,
AccountState,
AccountWithOptionalTokenData,
ClosedAccountWithOptionalTokenData,
ClosedAccount,
ClosedAccountWithOptionalTokenDataV2,
ClosedAccountV2,
AccountWithOptionalTokenDataV2,
UnixTimestamp,
UnsignedInteger,
Expand All @@ -135,7 +135,7 @@ const JSON_CONTENT_TYPE: &str = "application/json";
OwnerBalancesResponse,
TokenBalanceListV2,
MerkleContextV2,
ContextInfo,
TreeContextInfo,
GetCompressedAccountProofResponseValueV1,
GetCompressedAccountProofResponseValueV2,
GetMultipleCompressedAccountProofsResponseValue
Expand Down
Loading