2929use borsh:: { BorshDeserialize , BorshSerialize } ;
3030use tracing:: { debug, instrument} ;
3131
32- use crate :: { account:: Accounts , crypto:: Pubkey } ;
32+ use crate :: { account:: TransactionAccount , crypto:: Pubkey } ;
3333
3434use super :: { Error , Result } ;
3535
3636/// The System's program id (`BifrostSystemProgram111111111111111111111111`)
3737pub const SYSTEM_PROGRAM : Pubkey = Pubkey :: from_bytes ( & [
38- 159 , 65 , 158 , 196 , 5 , 83 , 96 , 13 , 242 , 56 , 2 , 138 , 167 , 225 , 20 , 157 , 169 , 199 , 82 , 249 , 248 ,
39- 91 , 220 , 170 , 46 , 53 , 235 , 98 , 98 , 0 , 0 , 0 ,
38+ 2 , 190 , 236 , 171 , 26 , 147 , 23 , 185 , 158 , 168 , 176 , 152 , 117 , 167 , 48 , 232 , 60 , 78 , 120 , 154 ,
39+ 96 , 248 , 193 , 153 , 0 , 203 , 246 , 209 , 37 , 0 , 0 , 0 ,
4040] ) ;
4141
4242#[ derive( Debug , BorshSerialize , BorshDeserialize ) ]
@@ -53,24 +53,28 @@ enum SystemInstruction {
5353/// # Errors
5454/// if the instruction fails to complete (missing accounts, arithmetic overflows, *etc.*).
5555#[ instrument( skip_all) ]
56- pub fn execute_instruction < ' a > ( accounts : & ' a Accounts < ' a > , payload : & [ u8 ] ) -> Result < ( ) > {
56+ pub fn execute_instruction < ' a > ( accounts : & ' a [ TransactionAccount ] , payload : & [ u8 ] ) -> Result < ( ) > {
5757 debug ! ( "received system insruction" ) ;
5858 match borsh:: from_slice ( payload) ? {
5959 SystemInstruction :: Transfer ( amount) => transfer ( accounts, amount) ,
6060 }
6161}
6262
6363#[ instrument( skip( accounts) ) ]
64- fn transfer < ' a > ( accounts : & ' a Accounts < ' a > , amount : u64 ) -> Result < ( ) > {
64+ fn transfer < ' a > ( accounts : & ' a [ TransactionAccount ] , amount : u64 ) -> Result < ( ) > {
6565 debug ! ( "transferring prisms" ) ;
66- let payer = accounts. next ( ) ?;
66+ if accounts. len ( ) != 2 {
67+ return Err ( Error :: Account ( crate :: account:: Error :: MissingAccounts ) ) ;
68+ }
69+ assert ! ( accounts. len( ) > 1 , "missing accounts" ) ;
70+ let payer = & accounts[ 0 ] ;
6771 if !payer. is_signer {
6872 return Err ( Error :: Custom ( format ! (
6973 "{} must be a signing account" ,
7074 payer. key
7175 ) ) ) ;
7276 }
73- let receiver = accounts. next ( ) ? ;
77+ let receiver = & accounts[ 1 ] ;
7478 debug ! ( "from {} to {}" , payer. key, receiver. key) ;
7579 payer. sub_prisms ( amount) ?;
7680 receiver. add_prisms ( amount) ?;
@@ -140,12 +144,11 @@ mod tests {
140144 TransactionAccount :: new( & meta1, & mut wallet1) ,
141145 TransactionAccount :: new( & meta2, & mut wallet2) ,
142146 ] ;
143- let accounts = Accounts :: new ( accounts_vec. as_slice ( ) ) ;
144147
145148 let payload = borsh:: to_vec ( & SystemInstruction :: Transfer ( 100 ) ) . unwrap ( ) ;
146149
147150 // When
148- execute_instruction ( & accounts , & payload) ?;
151+ execute_instruction ( & accounts_vec , & payload) ?;
149152
150153 // Then
151154 assert_eq ! ( wallet1. prisms, AMOUNT - 100 ) ;
@@ -163,13 +166,12 @@ mod tests {
163166 let mut wallet1 = Wallet { prisms : AMOUNT } ;
164167
165168 let accounts_vec = vec ! [ TransactionAccount :: new( & meta1, & mut wallet1) ] ;
166- let accounts = Accounts :: new ( accounts_vec. as_slice ( ) ) ;
167169
168170 #[ expect( clippy:: unwrap_used) ]
169171 let payload = borsh:: to_vec ( & SystemInstruction :: Transfer ( 100 ) ) . unwrap ( ) ;
170172
171173 // When
172- let res = execute_instruction ( & accounts , & payload) ;
174+ let res = execute_instruction ( & accounts_vec , & payload) ;
173175
174176 // Then
175177 assert_matches ! ( res, Err ( error) if matches!( error, Error :: Account ( _) ) ) ;
@@ -192,13 +194,12 @@ mod tests {
192194 TransactionAccount :: new( & meta1, & mut wallet1) ,
193195 TransactionAccount :: new( & meta2, & mut wallet2) ,
194196 ] ;
195- let accounts = Accounts :: new ( accounts_vec. as_slice ( ) ) ;
196197
197198 #[ expect( clippy:: unwrap_used) ]
198199 let payload = borsh:: to_vec ( & SystemInstruction :: Transfer ( 100 ) ) . unwrap ( ) ;
199200
200201 // When
201- let res = execute_instruction ( & accounts , & payload) ;
202+ let res = execute_instruction ( & accounts_vec , & payload) ;
202203
203204 // Then
204205 assert_matches ! ( res, Err ( error) if matches!( error, Error :: Custom { .. } ) ) ;
0 commit comments