11use {
22 super :: { account_state:: AccountState , COption , Initializable , Transmutable } ,
3- pinocchio:: pubkey:: Pubkey ,
3+ pinocchio:: { program_error :: ProgramError , pubkey:: Pubkey } ,
44} ;
55
66/// Incinerator address.
@@ -27,7 +27,7 @@ pub struct Account {
2727 delegate : COption < Pubkey > ,
2828
2929 /// The account's state.
30- pub state : AccountState ,
30+ state : u8 ,
3131
3232 /// Indicates whether this account represents a native token or not.
3333 is_native : [ u8 ; 4 ] ,
@@ -46,6 +46,16 @@ pub struct Account {
4646}
4747
4848impl Account {
49+ #[ inline( always) ]
50+ pub fn set_account_state ( & mut self , state : AccountState ) {
51+ self . state = state as u8 ;
52+ }
53+
54+ #[ inline( always) ]
55+ pub fn account_state ( & self ) -> Result < AccountState , ProgramError > {
56+ AccountState :: try_from ( self . state )
57+ }
58+
4959 #[ inline( always) ]
5060 pub fn set_amount ( & mut self , amount : u64 ) {
5161 self . amount = amount. to_le_bytes ( ) ;
@@ -131,8 +141,8 @@ impl Account {
131141 }
132142
133143 #[ inline( always) ]
134- pub fn is_frozen ( & self ) -> bool {
135- self . state == AccountState :: Frozen
144+ pub fn is_frozen ( & self ) -> Result < bool , ProgramError > {
145+ AccountState :: try_from ( self . state ) . map ( |state| state == AccountState :: Frozen )
136146 }
137147
138148 #[ inline( always) ]
@@ -147,7 +157,7 @@ impl Transmutable for Account {
147157
148158impl Initializable for Account {
149159 #[ inline( always) ]
150- fn is_initialized ( & self ) -> bool {
151- self . state != AccountState :: Uninitialized
160+ fn is_initialized ( & self ) -> Result < bool , ProgramError > {
161+ AccountState :: try_from ( self . state ) . map ( |state| state != AccountState :: Uninitialized )
152162 }
153163}
0 commit comments