Skip to main content

csv_adapter_aptos/
types.rs

1//! Aptos-specific type definitions
2
3use serde::{Deserialize, Serialize};
4
5/// Aptos seal reference (resource with key + delete)
6#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub struct AptosSealRef {
8    /// Account address (32 bytes)
9    pub account_address: [u8; 32],
10    /// Resource type tag
11    pub resource_type: String,
12    /// Nonce for replay resistance
13    pub nonce: u64,
14}
15
16impl AptosSealRef {
17    pub fn new(account_address: [u8; 32], resource_type: String, nonce: u64) -> Self {
18        Self {
19            account_address,
20            resource_type,
21            nonce,
22        }
23    }
24
25    pub fn to_vec(&self) -> Vec<u8> {
26        let mut out = Vec::with_capacity(32 + 8 + self.resource_type.len());
27        out.extend_from_slice(&self.account_address);
28        out.extend_from_slice(&(self.resource_type.len() as u64).to_le_bytes());
29        out.extend_from_slice(self.resource_type.as_bytes());
30        out.extend_from_slice(&self.nonce.to_le_bytes());
31        out
32    }
33}
34
35/// Aptos anchor reference (EventHandle containing commitment)
36#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
37pub struct AptosAnchorRef {
38    /// Transaction version
39    pub version: u64,
40    /// Event handle address
41    pub event_handle: [u8; 32],
42    /// Event sequence number
43    pub sequence_number: u64,
44}
45
46impl AptosAnchorRef {
47    pub fn new(version: u64, event_handle: [u8; 32], sequence_number: u64) -> Self {
48        Self {
49            version,
50            event_handle,
51            sequence_number,
52        }
53    }
54}
55
56/// Aptos inclusion proof
57#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
58pub struct AptosInclusionProof {
59    /// Transaction proof bytes
60    pub transaction_proof: Vec<u8>,
61    /// Event proof bytes
62    pub event_proof: Vec<u8>,
63    /// Version number
64    pub version: u64,
65}
66
67impl AptosInclusionProof {
68    pub fn new(transaction_proof: Vec<u8>, event_proof: Vec<u8>, version: u64) -> Self {
69        Self {
70            transaction_proof,
71            event_proof,
72            version,
73        }
74    }
75}
76
77/// Aptos finality proof (checkpoint)
78#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
79pub struct AptosFinalityProof {
80    /// Version number
81    pub version: u64,
82    /// Whether certified by 2f+1
83    pub is_certified: bool,
84}
85
86impl AptosFinalityProof {
87    pub fn new(version: u64, is_certified: bool) -> Self {
88        Self {
89            version,
90            is_certified,
91        }
92    }
93}
94
95#[cfg(test)]
96mod tests {
97    use super::*;
98
99    #[test]
100    fn test_seal_ref_creation() {
101        let seal = AptosSealRef::new([1u8; 32], "CSV::Seal".to_string(), 42);
102        assert_eq!(seal.nonce, 42);
103    }
104}