hopper_core/accounts/
signer.rs1use hopper_runtime::error::ProgramError;
8use hopper_runtime::{AccountView, Address};
9
10use super::traits::ValidateAccount;
11use crate::check;
12
13#[derive(Clone, Copy)]
18pub struct SignerAccount<'a> {
19 view: &'a AccountView,
20}
21
22impl<'a> SignerAccount<'a> {
23 #[inline]
25 pub fn from_account(account: &'a AccountView) -> Result<Self, ProgramError> {
26 check::check_signer(account)?;
27 Ok(Self { view: account })
28 }
29
30 #[inline(always)]
32 pub fn address(&self) -> &Address {
33 self.view.address()
34 }
35
36 #[inline(always)]
38 pub fn to_account_view(&self) -> &'a AccountView {
39 self.view
40 }
41
42 #[inline(always)]
44 pub fn is_writable(&self) -> bool {
45 self.view.is_writable()
46 }
47
48 #[inline(always)]
50 pub fn lamports(&self) -> u64 {
51 self.view.lamports()
52 }
53}
54
55impl<'a> ValidateAccount for SignerAccount<'a> {
56 #[inline]
57 fn validate(&self) -> Result<(), ProgramError> {
58 check::check_signer(self.view)
59 }
60}