forked from entros-protocol/executor-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransaction.rs
More file actions
68 lines (56 loc) · 2.01 KB
/
transaction.rs
File metadata and controls
68 lines (56 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use std::sync::Arc;
use crate::error::AppError;
use crate::solana::client::SolanaClient;
use crate::solana::instructions;
use crate::solana::pda;
pub struct VerificationOutcome {
pub signature: String,
pub is_valid: bool,
}
pub struct RelayerTransaction {
client: Arc<SolanaClient>,
}
impl RelayerTransaction {
pub fn new(client: Arc<SolanaClient>) -> Self {
Self { client }
}
/// Submit a verification: create_challenge + verify_proof in one transaction.
/// After the verify_proof revert fix, a confirmed transaction guarantees the
/// proof was valid (invalid proofs revert the entire transaction).
pub async fn submit_verification(
&self,
proof_bytes: &[u8],
public_inputs: &[[u8; 32]],
) -> Result<VerificationOutcome, AppError> {
let nonce: [u8; 32] = rand::random();
let relayer = self.client.relayer_pubkey();
let (challenge_pda, _) = pda::find_challenge_pda(&relayer, &nonce);
let (verification_pda, _) = pda::find_verification_result_pda(&relayer, &nonce);
tracing::info!(
nonce = %bs58::encode(&nonce).into_string(),
"Generated verification nonce"
);
let ix1 = instructions::build_create_challenge(&relayer, &challenge_pda, &nonce);
let ix2 = instructions::build_verify_proof(
&relayer,
&challenge_pda,
&verification_pda,
proof_bytes,
public_inputs,
&nonce,
);
let signature = self.client.send_verification_tx(vec![ix1, ix2]).await?;
tracing::info!(
signature = %signature,
"Verification transaction confirmed — proof valid"
);
// Transaction confirmed = proof was valid (invalid proofs revert on-chain)
Ok(VerificationOutcome {
signature: signature.to_string(),
is_valid: true,
})
}
pub async fn get_balance(&self) -> Result<u64, AppError> {
self.client.get_balance().await
}
}