data_anchor_client/client/
proof_client.rs

1use anchor_lang::solana_program::clock::Slot;
2use data_anchor_api::{CustomerElf, ProofRpcClient, RequestStatus};
3use data_anchor_utils::{compression::DataAnchorCompressionAsync, encoding::DataAnchorEncoding};
4use solana_signer::Signer;
5
6use super::BloberIdentifier;
7use crate::{DataAnchorClient, DataAnchorClientResult};
8
9#[derive(thiserror::Error, Debug)]
10pub enum ProofError {
11    /// Failed to read checkpoint proof for blober {0} and slot {1} with {2} via indexer client: {3}
12    #[error(
13        "Failed to read checkpoint proof for blober {0} and slot {1} with {2} via indexer client: {3}"
14    )]
15    ZKProof(String, u64, CustomerElf, String),
16    /// Failed to get proof request status: {0}
17    #[error("Failed to get proof request status for request ID {0}: {1}")]
18    ProofRequestStatus(String, String),
19}
20
21impl<Encoding, Compression> DataAnchorClient<Encoding, Compression>
22where
23    Encoding: DataAnchorEncoding + Default,
24    Compression: DataAnchorCompressionAsync,
25{
26    /// Requests ZK proof generation on the proof RPC for a given blober, slot and proof type.
27    pub async fn checkpoint_custom_proof(
28        &self,
29        slot: Slot,
30        identifier: BloberIdentifier,
31        customer_elf: CustomerElf,
32    ) -> DataAnchorClientResult<String> {
33        let blober = identifier.to_blober_address(self.program_id, self.payer.pubkey());
34
35        self.proof()
36            .checkpoint_proof(blober.into(), slot, customer_elf)
37            .await
38            .map_err(|e| {
39                ProofError::ZKProof(blober.to_string(), slot, customer_elf, e.to_string()).into()
40            })
41    }
42
43    /// Returns the status of a proof request by its request ID.
44    pub async fn get_proof_request_status(
45        &self,
46        request_id: String,
47    ) -> DataAnchorClientResult<RequestStatus> {
48        self.proof()
49            .get_proof_request_status(request_id.clone())
50            .await
51            .map_err(|e| ProofError::ProofRequestStatus(request_id, e.to_string()).into())
52    }
53}