mod error;
pub use crate::handler::error::{ApplyError, ContextError};
use crate::protocol::transaction::TransactionPair;
pub trait TransactionContext {
fn get_state_entry(&self, address: &str) -> Result<Option<Vec<u8>>, ContextError> {
Ok(self
.get_state_entries(&[address.to_string()])?
.into_iter()
.map(|(_, val)| val)
.next())
}
fn get_state_entries(
&self,
addresses: &[String],
) -> Result<Vec<(String, Vec<u8>)>, ContextError>;
fn set_state_entry(&self, address: String, data: Vec<u8>) -> Result<(), ContextError> {
self.set_state_entries(vec![(address, data)])
}
fn set_state_entries(&self, entries: Vec<(String, Vec<u8>)>) -> Result<(), ContextError>;
fn delete_state_entry(&self, address: &str) -> Result<Option<String>, ContextError> {
Ok(self
.delete_state_entries(&[address.to_string()])?
.into_iter()
.next())
}
fn delete_state_entries(&self, addresses: &[String]) -> Result<Vec<String>, ContextError>;
fn add_receipt_data(&self, data: Vec<u8>) -> Result<(), ContextError>;
fn add_event(
&self,
event_type: String,
attributes: Vec<(String, String)>,
data: Vec<u8>,
) -> Result<(), ContextError>;
}
pub trait TransactionHandler: Send {
fn family_name(&self) -> &str;
fn family_versions(&self) -> &[String];
fn apply(
&self,
transaction: &TransactionPair,
context: &mut dyn TransactionContext,
) -> Result<(), ApplyError>;
}