openmina_core/transaction/
transaction_with_hash.rs

1use serde::{Deserialize, Serialize};
2
3use super::{Transaction, TransactionHash};
4
5#[derive(Serialize, Deserialize, Debug, Clone)]
6pub struct TransactionWithHash<T: AsRef<Transaction> = Transaction> {
7    hash: TransactionHash,
8    body: T,
9}
10
11impl<T: AsRef<Transaction>> TransactionWithHash<T> {
12    pub fn try_new(body: T) -> std::io::Result<Self> {
13        Ok(Self {
14            hash: body.as_ref().hash()?,
15            body,
16        })
17    }
18
19    pub fn hash(&self) -> &TransactionHash {
20        &self.hash
21    }
22
23    pub fn body(&self) -> &Transaction {
24        self.body.as_ref()
25    }
26
27    pub fn into_body(self) -> T {
28        self.body
29    }
30}