Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit bf5c68b

Browse files
committed
Fix delegate transfer
1 parent 40a2e23 commit bf5c68b

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

program/src/processor/shared/transfer.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,27 @@ pub fn process_transfer(
126126
(self_transfer, remaining_amount, delegated_amount)
127127
};
128128

129-
// SAFETY: there is a single mutable borrow to `source_account_info` account data. The account
130-
// is also guaranteed to be initialized.
131-
let source_account =
132-
unsafe { load_mut_unchecked::<Account>(source_account_info.borrow_mut_data_unchecked())? };
133-
134-
// Updated the delegated amount if necessary.
135-
if let Some(delegated_amount) = delegated_amount {
136-
source_account.set_delegated_amount(delegated_amount);
137-
138-
if delegated_amount == 0 {
139-
source_account.clear_delegate();
140-
}
141-
}
142-
143129
if self_transfer || amount == 0 {
144130
// Validates the token accounts owner since we are not writing
145131
// to these account.
146132
check_account_owner(source_account_info)?;
147133
check_account_owner(destination_account_info)?;
148134
} else {
135+
// SAFETY: there is a single mutable borrow to `source_account_info` account data. The account
136+
// is also guaranteed to be initialized.
137+
let source_account = unsafe {
138+
load_mut_unchecked::<Account>(source_account_info.borrow_mut_data_unchecked())?
139+
};
140+
141+
// Updated the delegated amount if necessary.
142+
if let Some(delegated_amount) = delegated_amount {
143+
source_account.set_delegated_amount(delegated_amount);
144+
145+
if delegated_amount == 0 {
146+
source_account.clear_delegate();
147+
}
148+
}
149+
149150
// Moves the tokens.
150151

151152
source_account.set_amount(remaining_amount);

0 commit comments

Comments
 (0)