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

Commit 886693d

Browse files
authored
token-client: Refactor Message creation to use the same instructions everywhere (#6494)
token-client: Refactor `Message` creation
1 parent b13a58b commit 886693d

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

token/client/src/token.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -561,32 +561,25 @@ where
561561
));
562562
}
563563

564-
let (message, blockhash) =
565-
if let (Some(nonce_account), Some(nonce_authority), Some(nonce_blockhash)) = (
566-
self.nonce_account,
567-
&self.nonce_authority,
568-
self.nonce_blockhash,
569-
) {
570-
let mut message = Message::new_with_nonce(
571-
token_instructions.to_vec(),
572-
fee_payer,
573-
&nonce_account,
574-
&nonce_authority.pubkey(),
575-
);
576-
message.recent_blockhash = nonce_blockhash;
577-
(message, nonce_blockhash)
578-
} else {
579-
let latest_blockhash = self
580-
.client
581-
.get_latest_blockhash()
582-
.await
583-
.map_err(TokenError::Client)?;
584-
(
585-
Message::new_with_blockhash(&instructions, fee_payer, &latest_blockhash),
586-
latest_blockhash,
587-
)
588-
};
564+
let blockhash = if let (Some(nonce_account), Some(nonce_authority), Some(nonce_blockhash)) = (
565+
self.nonce_account,
566+
&self.nonce_authority,
567+
self.nonce_blockhash,
568+
) {
569+
let nonce_instruction = system_instruction::advance_nonce_account(
570+
&nonce_account,
571+
&nonce_authority.pubkey(),
572+
);
573+
instructions.insert(0, nonce_instruction);
574+
nonce_blockhash
575+
} else {
576+
self.client
577+
.get_latest_blockhash()
578+
.await
579+
.map_err(TokenError::Client)?
580+
};
589581

582+
let message = Message::new_with_blockhash(&instructions, fee_payer, &blockhash);
590583
let mut transaction = Transaction::new_unsigned(message);
591584
let signing_pubkeys = signing_keypairs.pubkeys();
592585

0 commit comments

Comments
 (0)