aimo_core/state/
events.rs

1use serde::{Deserialize, Serialize};
2use sha2::{Digest, Sha256};
3use solana_sdk::pubkey::Pubkey;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct KeyRevocation {
7    pub key: String,
8}
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct RequestSettled {
12    pub sender: Pubkey,
13    pub request_id: Pubkey,
14    pub service_id: Pubkey,
15    pub max_est_cost: u64,
16    pub timestamp: i64,
17    pub finish_reason: u8,
18    pub prompt_tokens: u64,
19    pub completion_tokens: u64,
20    pub amount: u64,
21    pub token_mint: Pubkey,
22    pub model_name: Option<String>, // Added model name for better statistics tracking
23}
24
25impl RequestSettled {
26    pub fn into_bytes(self) -> Vec<u8> {
27        let model_name_bytes = self.model_name.unwrap_or_default().into_bytes();
28        vec![
29            self.sender.to_bytes().to_vec(),
30            self.request_id.to_bytes().to_vec(),
31            self.service_id.to_bytes().to_vec(),
32            self.max_est_cost.to_be_bytes().to_vec(),
33            self.timestamp.to_be_bytes().to_vec(),
34            self.finish_reason.to_be_bytes().to_vec(),
35            self.prompt_tokens.to_be_bytes().to_vec(),
36            self.completion_tokens.to_be_bytes().to_vec(),
37            self.amount.to_be_bytes().to_vec(),
38            self.token_mint.to_bytes().to_vec(),
39            model_name_bytes,
40        ]
41        .concat()
42    }
43
44    pub fn into_hash(self) -> [u8; 32] {
45        let mut hasher = Sha256::new();
46        hasher.update(self.into_bytes());
47        hasher.finalize().into()
48    }
49}