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

Commit 594b725

Browse files
committed
add support for transfer-hook account resolution in transfer_with_fee
1 parent 2ec0b9b commit 594b725

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

token/client/src/token.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,21 +1166,44 @@ where
11661166
let multisig_signers = self.get_multisig_signers(authority, &signing_pubkeys);
11671167
let decimals = self.decimals.ok_or(TokenError::MissingDecimals)?;
11681168

1169-
self.process_ixs(
1170-
&[transfer_fee::instruction::transfer_checked_with_fee(
1169+
let fetch_account_data_fn = |address| {
1170+
self.client
1171+
.get_account(address)
1172+
.map_ok(|opt| opt.map(|acc| acc.data))
1173+
};
1174+
1175+
let instruction = if let Some(transfer_hook_accounts) = &self.transfer_hook_accounts {
1176+
let mut instruction = transfer_fee::instruction::transfer_checked_with_fee(
11711177
&self.program_id,
11721178
source,
1173-
&self.pubkey,
1179+
self.get_address(),
11741180
destination,
11751181
authority,
11761182
&multisig_signers,
11771183
amount,
11781184
decimals,
11791185
fee,
1180-
)?],
1181-
signing_keypairs,
1182-
)
1183-
.await
1186+
)?;
1187+
instruction.accounts.extend(transfer_hook_accounts.clone());
1188+
instruction
1189+
} else {
1190+
offchain::create_transfer_checked_with_fee_instruction_with_extra_metas(
1191+
&self.program_id,
1192+
source,
1193+
self.get_address(),
1194+
destination,
1195+
authority,
1196+
&multisig_signers,
1197+
amount,
1198+
decimals,
1199+
fee,
1200+
fetch_account_data_fn,
1201+
)
1202+
.await
1203+
.map_err(|_| TokenError::AccountNotFound)?
1204+
};
1205+
1206+
self.process_ixs(&[instruction], signing_keypairs).await
11841207
}
11851208

11861209
/// Burn tokens from account

0 commit comments

Comments
 (0)