use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use solana_sdk::pubkey::Pubkey;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RequestReceipt {
pub sender: Pubkey,
pub request_id: Pubkey,
pub service_id: Pubkey,
pub max_est_cost: u64,
pub timestamp: i64,
pub finish_reason: u8,
pub prompt_tokens: u64,
pub completion_tokens: u64,
pub amount: u64,
pub token_mint: Pubkey,
pub model_name: Option<String>, }
impl RequestReceipt {
pub fn into_bytes(self) -> Vec<u8> {
let model_name_bytes = self.model_name.unwrap_or_default().into_bytes();
vec![
self.sender.to_bytes().to_vec(),
self.request_id.to_bytes().to_vec(),
self.service_id.to_bytes().to_vec(),
self.max_est_cost.to_be_bytes().to_vec(),
self.timestamp.to_be_bytes().to_vec(),
self.finish_reason.to_be_bytes().to_vec(),
self.prompt_tokens.to_be_bytes().to_vec(),
self.completion_tokens.to_be_bytes().to_vec(),
self.amount.to_be_bytes().to_vec(),
self.token_mint.to_bytes().to_vec(),
model_name_bytes,
]
.concat()
}
pub fn into_hash(self) -> [u8; 32] {
let mut hasher = Sha256::new();
hasher.update(self.into_bytes());
hasher.finalize().into()
}
}