Skip to content

Commit

Permalink
Add the slot value to getValidityProof (helius-labs#147)
Browse files Browse the repository at this point in the history
* Fix concurrency

* Reformat getValidityProof

* Reformat the get validity proof field
  • Loading branch information
pmantica11 authored Jul 23, 2024
1 parent 07e1191 commit df8786e
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 234 deletions.
6 changes: 3 additions & 3 deletions src/api/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use super::method::get_transaction_with_compression_info::{
get_transaction_with_compression_info, GetTransactionRequest, GetTransactionResponse,
};
use super::method::get_validity_proof::{
get_validity_proof, CompressedProofWithContext, GetValidityProofRequest,
get_validity_proof, GetValidityProofRequest, GetValidityProofResponse,
};
use super::method::utils::GetLatestSignaturesRequest;
use super::method::utils::{AccountBalanceResponse, GetPaginatedSignaturesResponse, HashRequest};
Expand Down Expand Up @@ -276,7 +276,7 @@ impl PhotonApi {
pub async fn get_validity_proof(
&self,
request: GetValidityProofRequest,
) -> Result<CompressedProofWithContext, PhotonApiError> {
) -> Result<GetValidityProofResponse, PhotonApiError> {
get_validity_proof(self.db_conn.as_ref(), &self.prover_url, request).await
}

Expand Down Expand Up @@ -319,7 +319,7 @@ impl PhotonApi {
OpenApiSpec {
name: "getValidityProof".to_string(),
request: Some(GetValidityProofRequest::schema().1),
response: CompressedProofWithContext::schema().1,
response: GetValidityProofResponse::schema().1,
},
OpenApiSpec {
name: "getCompressedTokenAccountsByOwner".to_string(),
Expand Down
23 changes: 19 additions & 4 deletions src/api/method/get_validity_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ use serde::{Deserialize, Serialize};
use std::str::FromStr;
use utoipa::ToSchema;

use super::get_multiple_new_address_proofs::{
get_multiple_new_address_proofs_helper, MerkleContextWithNewAddressProof,
use super::{
get_multiple_new_address_proofs::{
get_multiple_new_address_proofs_helper, MerkleContextWithNewAddressProof,
},
utils::Context,
};

lazy_static! {
Expand Down Expand Up @@ -249,16 +252,24 @@ pub struct GetValidityProofRequest {
pub newAddresses: Vec<SerializablePubkey>,
}

#[derive(Serialize, Deserialize, ToSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct GetValidityProofResponse {
pub value: CompressedProofWithContext,
pub context: Context,
}

pub async fn get_validity_proof(
conn: &DatabaseConnection,
prover_url: &str,
request: GetValidityProofRequest,
) -> Result<CompressedProofWithContext, PhotonApiError> {
) -> Result<GetValidityProofResponse, PhotonApiError> {
if request.hashes.is_empty() && request.newAddresses.is_empty() {
return Err(PhotonApiError::UnexpectedError(
"No hashes or new addresses provided for proof generation".to_string(),
));
}
let context = Context::extract(conn).await?;
let client = Client::new();
let tx = conn.begin().await?;
if tx.get_database_backend() == DatabaseBackend::Postgres {
Expand Down Expand Up @@ -328,7 +339,7 @@ pub async fn get_validity_proof(
#[allow(non_snake_case)]
let compressedProof = negate_and_compress_proof(proof);

Ok(CompressedProofWithContext {
let compressed_proof_with_context = CompressedProofWithContext {
compressedProof,
roots: account_proofs
.iter()
Expand Down Expand Up @@ -368,5 +379,9 @@ pub async fn get_validity_proof(
.map(|x| x.merkleTree.clone().to_string()),
)
.collect(),
};
Ok(GetValidityProofResponse {
value: compressed_proof_with_context,
context,
})
}
6 changes: 3 additions & 3 deletions tests/integration_tests/e2e_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async fn test_e2e_mint_and_transfer_legacy_transactions(
.await
.unwrap();
// The Gnark prover has some randomness.
validity_proof.compressedProof = CompressedProof::default();
validity_proof.value.compressedProof = CompressedProof::default();

assert_json_snapshot!(
format!("{}-{}-validity-proof", name.clone(), person),
Expand Down Expand Up @@ -326,7 +326,7 @@ async fn test_e2e_mint_and_transfer_new_transactions(
.await
.unwrap();
// The Gnark prover has some randomness.
validity_proof.compressedProof = CompressedProof::default();
validity_proof.value.compressedProof = CompressedProof::default();

assert_json_snapshot!(
format!("{}-{}-validity-proof", name.clone(), person),
Expand Down Expand Up @@ -538,7 +538,7 @@ async fn test_lamport_transfers(
hash_list.0.len()
));
// The Gnark prover has some randomness.
validity_proof.compressedProof = CompressedProof::default();
validity_proof.value.compressedProof = CompressedProof::default();

assert_json_snapshot!(
format!("{}-{}-validity-proof", name.clone(), owner_name),
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/mock_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ async fn test_get_multiple_new_address_proofs_interop(
.await
.unwrap();
// The Gnark prover has some randomness.
validity_proof.compressedProof = CompressedProof::default();
validity_proof.value.compressedProof = CompressedProof::default();

insta::assert_json_snapshot!(format!("{}-validity-proof", name), validity_proof);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@ source: tests/integration_tests/e2e_tests.rs
expression: validity_proof
---
{
"compressedProof": {
"a": [],
"b": [],
"c": []
"value": {
"compressedProof": {
"a": [],
"b": [],
"c": []
},
"roots": [
"jQKhAHpGbSTJLimk3bGSX7KLi7CsX6nkosS9YeCFfVs",
"jQKhAHpGbSTJLimk3bGSX7KLi7CsX6nkosS9YeCFfVs"
],
"rootIndices": [
7,
7
],
"leafIndices": [
3,
6
],
"leaves": [
"JsiSYnfKzmaxKvU8vhqsM6PiuPEFVVVwAsNcPUtDo64",
"2hXgiYUBfsVEreTuq8PKumwE1dUkkeACw4HVf9ZZoi1H"
],
"merkleTrees": [
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W",
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W"
]
},
"roots": [
"jQKhAHpGbSTJLimk3bGSX7KLi7CsX6nkosS9YeCFfVs",
"jQKhAHpGbSTJLimk3bGSX7KLi7CsX6nkosS9YeCFfVs"
],
"rootIndices": [
7,
7
],
"leafIndices": [
3,
6
],
"leaves": [
"JsiSYnfKzmaxKvU8vhqsM6PiuPEFVVVwAsNcPUtDo64",
"2hXgiYUBfsVEreTuq8PKumwE1dUkkeACw4HVf9ZZoi1H"
],
"merkleTrees": [
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W",
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W"
]
"context": {
"slot": 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@ source: tests/integration_tests/e2e_tests.rs
expression: validity_proof
---
{
"compressedProof": {
"a": [],
"b": [],
"c": []
"value": {
"compressedProof": {
"a": [],
"b": [],
"c": []
},
"roots": [
"jQKhAHpGbSTJLimk3bGSX7KLi7CsX6nkosS9YeCFfVs",
"jQKhAHpGbSTJLimk3bGSX7KLi7CsX6nkosS9YeCFfVs"
],
"rootIndices": [
7,
7
],
"leafIndices": [
5,
4
],
"leaves": [
"2uSjtTXvYYb544CrvmDsTJ98M8qdw8SFmZ5muEHnZET9",
"3a6Rs5JJ66YWEHuYm4KQuhbHAFnUszWiL8kgzV4MHFZW"
],
"merkleTrees": [
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W",
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W"
]
},
"roots": [
"jQKhAHpGbSTJLimk3bGSX7KLi7CsX6nkosS9YeCFfVs",
"jQKhAHpGbSTJLimk3bGSX7KLi7CsX6nkosS9YeCFfVs"
],
"rootIndices": [
7,
7
],
"leafIndices": [
5,
4
],
"leaves": [
"2uSjtTXvYYb544CrvmDsTJ98M8qdw8SFmZ5muEHnZET9",
"3a6Rs5JJ66YWEHuYm4KQuhbHAFnUszWiL8kgzV4MHFZW"
],
"merkleTrees": [
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W",
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W"
]
"context": {
"slot": 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@ source: tests/integration_tests/e2e_tests.rs
expression: validity_proof
---
{
"compressedProof": {
"a": [],
"b": [],
"c": []
"value": {
"compressedProof": {
"a": [],
"b": [],
"c": []
},
"roots": [
"ZMg67iuQAyRUALR4TmAMyWGVEXV2e8yCpRSqdnR8Y1n",
"ZMg67iuQAyRUALR4TmAMyWGVEXV2e8yCpRSqdnR8Y1n"
],
"rootIndices": [
7,
7
],
"leafIndices": [
6,
3
],
"leaves": [
"2WfNf8qZoMNGR4mAPX8toADTdRpcKYTX1KUUAEHMi7dJ",
"36ewgEJTqSu4enYGWUcxm4CYezR3kgfHBeV29WiEgKaY"
],
"merkleTrees": [
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W",
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W"
]
},
"roots": [
"ZMg67iuQAyRUALR4TmAMyWGVEXV2e8yCpRSqdnR8Y1n",
"ZMg67iuQAyRUALR4TmAMyWGVEXV2e8yCpRSqdnR8Y1n"
],
"rootIndices": [
7,
7
],
"leafIndices": [
6,
3
],
"leaves": [
"2WfNf8qZoMNGR4mAPX8toADTdRpcKYTX1KUUAEHMi7dJ",
"36ewgEJTqSu4enYGWUcxm4CYezR3kgfHBeV29WiEgKaY"
],
"merkleTrees": [
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W",
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W"
]
"context": {
"slot": 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@ source: tests/integration_tests/e2e_tests.rs
expression: validity_proof
---
{
"compressedProof": {
"a": [],
"b": [],
"c": []
"value": {
"compressedProof": {
"a": [],
"b": [],
"c": []
},
"roots": [
"ZMg67iuQAyRUALR4TmAMyWGVEXV2e8yCpRSqdnR8Y1n",
"ZMg67iuQAyRUALR4TmAMyWGVEXV2e8yCpRSqdnR8Y1n"
],
"rootIndices": [
7,
7
],
"leafIndices": [
4,
5
],
"leaves": [
"21a33JmBirKxeMq88LfBKfZy5VM5Gb8Jf2H6RV4zN7Xy",
"3gX31m9xhLEs2r4DR1f1gePqJyUEA3Qk38WLiYbGkonm"
],
"merkleTrees": [
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W",
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W"
]
},
"roots": [
"ZMg67iuQAyRUALR4TmAMyWGVEXV2e8yCpRSqdnR8Y1n",
"ZMg67iuQAyRUALR4TmAMyWGVEXV2e8yCpRSqdnR8Y1n"
],
"rootIndices": [
7,
7
],
"leafIndices": [
4,
5
],
"leaves": [
"21a33JmBirKxeMq88LfBKfZy5VM5Gb8Jf2H6RV4zN7Xy",
"3gX31m9xhLEs2r4DR1f1gePqJyUEA3Qk38WLiYbGkonm"
],
"merkleTrees": [
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W",
"5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W"
]
"context": {
"slot": 0
}
}
Loading

0 comments on commit df8786e

Please sign in to comment.