@@ -381,6 +381,18 @@ impl Processor {
381
381
}
382
382
383
383
let self_transfer = source_account_info. key == destination_account_info. key ;
384
+ if let Ok ( cpi_guard) = source_account. get_extension :: < CpiGuard > ( ) {
385
+ // Blocks all cases where the authority has signed if CPI Guard is
386
+ // enabled, including:
387
+ // * the account is delegated to the owner
388
+ // * the account owner is the permanent delegate
389
+ if * authority_info. key == source_account. base . owner
390
+ && cpi_guard. lock_cpi . into ( )
391
+ && in_cpi ( )
392
+ {
393
+ return Err ( TokenError :: CpiGuardTransferBlocked . into ( ) ) ;
394
+ }
395
+ }
384
396
match ( source_account. base . delegate , maybe_permanent_delegate) {
385
397
( _, Some ( ref delegate) ) if authority_info. key == delegate => Self :: validate_owner (
386
398
program_id,
@@ -403,15 +415,6 @@ impl Processor {
403
415
authority_info_data_len,
404
416
account_info_iter. as_slice ( ) ,
405
417
) ?;
406
- if let Ok ( cpi_guard) = source_account. get_extension :: < CpiGuard > ( ) {
407
- // If delegated to self, don't allow a transfer with CPI Guard
408
- if delegate == source_account. base . owner
409
- && cpi_guard. lock_cpi . into ( )
410
- && in_cpi ( )
411
- {
412
- return Err ( TokenError :: CpiGuardTransferBlocked . into ( ) ) ;
413
- }
414
- }
415
418
let delegated_amount = u64:: from ( source_account. base . delegated_amount ) ;
416
419
if delegated_amount < amount {
417
420
return Err ( TokenError :: InsufficientFunds . into ( ) ) ;
@@ -434,12 +437,6 @@ impl Processor {
434
437
authority_info_data_len,
435
438
account_info_iter. as_slice ( ) ,
436
439
) ?;
437
-
438
- if let Ok ( cpi_guard) = source_account. get_extension :: < CpiGuard > ( ) {
439
- if cpi_guard. lock_cpi . into ( ) && in_cpi ( ) {
440
- return Err ( TokenError :: CpiGuardTransferBlocked . into ( ) ) ;
441
- }
442
- }
443
440
}
444
441
}
445
442
@@ -1033,6 +1030,19 @@ impl Processor {
1033
1030
}
1034
1031
let maybe_permanent_delegate = get_permanent_delegate ( & mint) ;
1035
1032
1033
+ if let Ok ( cpi_guard) = source_account. get_extension :: < CpiGuard > ( ) {
1034
+ // Blocks all cases where the authority has signed if CPI Guard is
1035
+ // enabled, including:
1036
+ // * the account is delegated to the owner
1037
+ // * the account owner is the permanent delegate
1038
+ if * authority_info. key == source_account. base . owner
1039
+ && cpi_guard. lock_cpi . into ( )
1040
+ && in_cpi ( )
1041
+ {
1042
+ return Err ( TokenError :: CpiGuardBurnBlocked . into ( ) ) ;
1043
+ }
1044
+ }
1045
+
1036
1046
if !source_account
1037
1047
. base
1038
1048
. is_owned_by_system_program_or_incinerator ( )
@@ -1080,12 +1090,6 @@ impl Processor {
1080
1090
authority_info_data_len,
1081
1091
account_info_iter. as_slice ( ) ,
1082
1092
) ?;
1083
-
1084
- if let Ok ( cpi_guard) = source_account. get_extension :: < CpiGuard > ( ) {
1085
- if cpi_guard. lock_cpi . into ( ) && in_cpi ( ) {
1086
- return Err ( TokenError :: CpiGuardBurnBlocked . into ( ) ) ;
1087
- }
1088
- }
1089
1093
}
1090
1094
}
1091
1095
}
0 commit comments