solana_program/message/
address_loader.rsuse {
super::v0::{LoadedAddresses, MessageAddressTableLookup},
thiserror::Error,
};
#[derive(Debug, Error, PartialEq, Eq, Clone)]
pub enum AddressLoaderError {
#[error("Address loading from lookup tables is disabled")]
Disabled,
#[error("Failed to load slot hashes sysvar")]
SlotHashesSysvarNotFound,
#[error("Attempted to lookup addresses from a table that does not exist")]
LookupTableAccountNotFound,
#[error("Attempted to lookup addresses from an account owned by the wrong program")]
InvalidAccountOwner,
#[error("Attempted to lookup addresses from an invalid account")]
InvalidAccountData,
#[error("Address lookup contains an invalid index")]
InvalidLookupIndex,
}
pub trait AddressLoader: Clone {
fn load_addresses(
self,
lookups: &[MessageAddressTableLookup],
) -> Result<LoadedAddresses, AddressLoaderError>;
}
#[derive(Clone)]
pub enum SimpleAddressLoader {
Disabled,
Enabled(LoadedAddresses),
}
impl AddressLoader for SimpleAddressLoader {
fn load_addresses(
self,
_lookups: &[MessageAddressTableLookup],
) -> Result<LoadedAddresses, AddressLoaderError> {
match self {
Self::Disabled => Err(AddressLoaderError::Disabled),
Self::Enabled(loaded_addresses) => Ok(loaded_addresses),
}
}
}