@@ -69,8 +69,6 @@ pub struct ScheduleCommitCpiArgs {
6969 pub players : Vec < Pubkey > ,
7070 /// If true, the accounts will be modified after the commit
7171 pub modify_accounts : bool ,
72- /// If true, the accounts will be undelegated after the commit
73- pub undelegate : bool ,
7472 /// If true, also commit the payer account
7573 pub commit_payer : bool ,
7674}
@@ -99,7 +97,7 @@ pub enum ScheduleCommitInstruction {
9997 /// - **1** `[]` MagicContext (used to record scheduled commit)
10098 /// - **2** `[]` MagicBlock Program (used to schedule commit)
10199 /// - **3..n** `[]` PDA accounts to be committed
102- ScheduleCommitCpi ( ScheduleCommitCpiArgs ) ,
100+ ScheduleCommitCpi ( ScheduleCommitCpiArgs , ScheduleCommitType ) ,
103101
104102 /// Same instruction input like [ScheduleCommitInstruction::ScheduleCommitCpi].
105103 /// Behavior differs that it will modify the accounts after it
@@ -165,11 +163,54 @@ pub enum ScheduleCommitInstruction {
165163
166164#[ derive( BorshSerialize , BorshDeserialize , Debug , Clone , Copy ) ]
167165pub enum ScheduleCommitType {
166+ Commit ,
168167 CommitAndUndelegate ,
169168 CommitFinalize ,
170169 CommitFinalizeAndUndelegate ,
171170}
172171
172+ impl ScheduleCommitType {
173+ fn invoke_commit < ' a , ' info > (
174+ self ,
175+ payer : & ' a AccountInfo < ' info > ,
176+ accounts : Vec < & ' a AccountInfo < ' info > > ,
177+ magic_context : & ' a AccountInfo < ' info > ,
178+ magic_program : & ' a AccountInfo < ' info > ,
179+ ) -> ProgramResult {
180+ match self {
181+ ScheduleCommitType :: Commit => {
182+ commit_accounts ( payer, accounts, magic_context, magic_program) ?;
183+ }
184+ ScheduleCommitType :: CommitAndUndelegate => {
185+ commit_and_undelegate_accounts (
186+ payer,
187+ accounts,
188+ magic_context,
189+ magic_program,
190+ ) ?;
191+ }
192+ ScheduleCommitType :: CommitFinalize => {
193+ commit_finalize_accounts (
194+ payer,
195+ accounts,
196+ magic_context,
197+ magic_program,
198+ ) ?;
199+ }
200+ ScheduleCommitType :: CommitFinalizeAndUndelegate => {
201+ commit_finalize_and_undelegate_accounts (
202+ payer,
203+ accounts,
204+ magic_context,
205+ magic_program,
206+ ) ?;
207+ }
208+ } ;
209+
210+ Ok ( ( ) )
211+ }
212+ }
213+
173214pub fn process_instruction < ' a > (
174215 program_id : & ' a Pubkey ,
175216 accounts : & ' a [ AccountInfo < ' a > ] ,
@@ -197,14 +238,14 @@ pub fn process_instruction<'a>(
197238 match ix {
198239 Init => process_init ( program_id, accounts) ,
199240 DelegateCpi ( args) => process_delegate_cpi ( accounts, args) ,
200- ScheduleCommitCpi ( args) => process_schedulecommit_cpi (
241+ ScheduleCommitCpi ( args, commit_type ) => process_schedulecommit_cpi (
201242 accounts,
202243 & args. players ,
203244 ProcessSchedulecommitCpiArgs {
204245 modify_accounts : args. modify_accounts ,
205- undelegate : args. undelegate ,
206246 commit_payer : args. commit_payer ,
207247 } ,
248+ commit_type,
208249 ) ,
209250 ScheduleCommitAndUndelegateCpiModAfter ( players) => {
210251 process_schedulecommit_and_undelegation_cpi_with_mod_after (
@@ -469,32 +510,12 @@ pub fn process_schedulecommit_for_orderbook(
469510
470511 assert_is_signer ( payer, "payer" ) ?;
471512
472- match commit_type {
473- ScheduleCommitType :: CommitAndUndelegate => {
474- commit_and_undelegate_accounts (
475- payer,
476- vec ! [ order_book_account] ,
477- magic_context,
478- magic_program,
479- ) ?;
480- }
481- ScheduleCommitType :: CommitFinalize => {
482- commit_finalize_accounts (
483- payer,
484- vec ! [ order_book_account] ,
485- magic_context,
486- magic_program,
487- ) ?;
488- }
489- ScheduleCommitType :: CommitFinalizeAndUndelegate => {
490- commit_finalize_and_undelegate_accounts (
491- payer,
492- vec ! [ order_book_account] ,
493- magic_context,
494- magic_program,
495- ) ?;
496- }
497- } ;
513+ commit_type. invoke_commit (
514+ payer,
515+ vec ! [ order_book_account] ,
516+ magic_context,
517+ magic_program,
518+ ) ?;
498519
499520 Ok ( ( ) )
500521}
@@ -541,7 +562,6 @@ pub fn process_delegate_cpi(
541562
542563pub struct ProcessSchedulecommitCpiArgs {
543564 pub modify_accounts : bool ,
544- pub undelegate : bool ,
545565 pub commit_payer : bool ,
546566}
547567
@@ -552,6 +572,7 @@ pub fn process_schedulecommit_cpi(
552572 accounts : & [ AccountInfo ] ,
553573 player_pubkeys : & [ Pubkey ] ,
554574 args : ProcessSchedulecommitCpiArgs ,
575+ commit_type : ScheduleCommitType ,
555576) -> Result < ( ) , ProgramError > {
556577 msg ! ( "Processing schedulecommit_cpi instruction" ) ;
557578
@@ -604,16 +625,12 @@ pub fn process_schedulecommit_cpi(
604625 committees. iter( ) . map( |x| x. key) . collect:: <Vec <_>>( )
605626 ) ;
606627
607- if args. undelegate {
608- commit_and_undelegate_accounts (
609- payer,
610- committees,
611- magic_context,
612- magic_program,
613- ) ?;
614- } else {
615- commit_accounts ( payer, committees, magic_context, magic_program) ?;
616- }
628+ commit_type. invoke_commit (
629+ payer,
630+ committees,
631+ magic_context,
632+ magic_program,
633+ ) ?;
617634
618635 Ok ( ( ) )
619636}
0 commit comments