29
29
use borsh:: { BorshDeserialize , BorshSerialize } ;
30
30
use tracing:: { debug, instrument} ;
31
31
32
- use crate :: { account:: Accounts , crypto:: Pubkey } ;
32
+ use crate :: { account:: TransactionAccount , crypto:: Pubkey } ;
33
33
34
34
use super :: { Error , Result } ;
35
35
36
36
/// The System's program id (`BifrostSystemProgram111111111111111111111111`)
37
37
pub 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 ,
40
40
] ) ;
41
41
42
42
#[ derive( Debug , BorshSerialize , BorshDeserialize ) ]
@@ -53,24 +53,28 @@ enum SystemInstruction {
53
53
/// # Errors
54
54
/// if the instruction fails to complete (missing accounts, arithmetic overflows, *etc.*).
55
55
#[ 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 < ( ) > {
57
57
debug ! ( "received system insruction" ) ;
58
58
match borsh:: from_slice ( payload) ? {
59
59
SystemInstruction :: Transfer ( amount) => transfer ( accounts, amount) ,
60
60
}
61
61
}
62
62
63
63
#[ instrument( skip( accounts) ) ]
64
- fn transfer < ' a > ( accounts : & ' a Accounts < ' a > , amount : u64 ) -> Result < ( ) > {
64
+ fn transfer < ' a > ( accounts : & ' a [ TransactionAccount ] , amount : u64 ) -> Result < ( ) > {
65
65
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 ] ;
67
71
if !payer. is_signer {
68
72
return Err ( Error :: Custom ( format ! (
69
73
"{} must be a signing account" ,
70
74
payer. key
71
75
) ) ) ;
72
76
}
73
- let receiver = accounts. next ( ) ? ;
77
+ let receiver = & accounts[ 1 ] ;
74
78
debug ! ( "from {} to {}" , payer. key, receiver. key) ;
75
79
payer. sub_prisms ( amount) ?;
76
80
receiver. add_prisms ( amount) ?;
@@ -140,12 +144,11 @@ mod tests {
140
144
TransactionAccount :: new( & meta1, & mut wallet1) ,
141
145
TransactionAccount :: new( & meta2, & mut wallet2) ,
142
146
] ;
143
- let accounts = Accounts :: new ( accounts_vec. as_slice ( ) ) ;
144
147
145
148
let payload = borsh:: to_vec ( & SystemInstruction :: Transfer ( 100 ) ) . unwrap ( ) ;
146
149
147
150
// When
148
- execute_instruction ( & accounts , & payload) ?;
151
+ execute_instruction ( & accounts_vec , & payload) ?;
149
152
150
153
// Then
151
154
assert_eq ! ( wallet1. prisms, AMOUNT - 100 ) ;
@@ -163,13 +166,12 @@ mod tests {
163
166
let mut wallet1 = Wallet { prisms : AMOUNT } ;
164
167
165
168
let accounts_vec = vec ! [ TransactionAccount :: new( & meta1, & mut wallet1) ] ;
166
- let accounts = Accounts :: new ( accounts_vec. as_slice ( ) ) ;
167
169
168
170
#[ expect( clippy:: unwrap_used) ]
169
171
let payload = borsh:: to_vec ( & SystemInstruction :: Transfer ( 100 ) ) . unwrap ( ) ;
170
172
171
173
// When
172
- let res = execute_instruction ( & accounts , & payload) ;
174
+ let res = execute_instruction ( & accounts_vec , & payload) ;
173
175
174
176
// Then
175
177
assert_matches ! ( res, Err ( error) if matches!( error, Error :: Account ( _) ) ) ;
@@ -192,13 +194,12 @@ mod tests {
192
194
TransactionAccount :: new( & meta1, & mut wallet1) ,
193
195
TransactionAccount :: new( & meta2, & mut wallet2) ,
194
196
] ;
195
- let accounts = Accounts :: new ( accounts_vec. as_slice ( ) ) ;
196
197
197
198
#[ expect( clippy:: unwrap_used) ]
198
199
let payload = borsh:: to_vec ( & SystemInstruction :: Transfer ( 100 ) ) . unwrap ( ) ;
199
200
200
201
// When
201
- let res = execute_instruction ( & accounts , & payload) ;
202
+ let res = execute_instruction ( & accounts_vec , & payload) ;
202
203
203
204
// Then
204
205
assert_matches ! ( res, Err ( error) if matches!( error, Error :: Custom { .. } ) ) ;
0 commit comments