hopper_core/accounts/
program.rs1use hopper_runtime::error::ProgramError;
7use hopper_runtime::{AccountView, Address};
8
9use crate::check;
10
11pub struct ProgramRef<'a> {
16 view: &'a AccountView,
17}
18
19impl<'a> ProgramRef<'a> {
20 #[inline]
22 pub fn from_account(account: &'a AccountView) -> Result<Self, ProgramError> {
23 check::check_executable(account)?;
24 Ok(Self { view: account })
25 }
26
27 #[inline]
29 pub fn from_account_checked(
30 account: &'a AccountView,
31 expected_key: &Address,
32 ) -> Result<Self, ProgramError> {
33 check::check_executable(account)?;
34 check::check_address(account, expected_key)?;
35 Ok(Self { view: account })
36 }
37
38 #[inline(always)]
40 pub fn address(&self) -> &Address {
41 self.view.address()
42 }
43
44 #[inline(always)]
46 pub fn to_account_view(&self) -> &'a AccountView {
47 self.view
48 }
49}