use hopper_runtime::error::ProgramError;
use hopper_runtime::{AccountView, Address};
use crate::check;
pub struct ProgramRef<'a> {
view: &'a AccountView,
}
impl<'a> ProgramRef<'a> {
#[inline]
pub fn from_account(account: &'a AccountView) -> Result<Self, ProgramError> {
check::check_executable(account)?;
Ok(Self { view: account })
}
#[inline]
pub fn from_account_checked(
account: &'a AccountView,
expected_key: &Address,
) -> Result<Self, ProgramError> {
check::check_executable(account)?;
check::check_address(account, expected_key)?;
Ok(Self { view: account })
}
#[inline(always)]
pub fn address(&self) -> &Address {
self.view.address()
}
#[inline(always)]
pub fn to_account_view(&self) -> &'a AccountView {
self.view
}
}