Skip to content

Commit

Permalink
token-client: Refactor Message creation to use the same `instructio…
Browse files Browse the repository at this point in the history
…ns` everywhere (#6494)

token-client: Refactor `Message` creation
  • Loading branch information
joncinque authored Mar 26, 2024
1 parent b13a58b commit 886693d
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions token/client/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,32 +561,25 @@ where
));
}

let (message, blockhash) =
if let (Some(nonce_account), Some(nonce_authority), Some(nonce_blockhash)) = (
self.nonce_account,
&self.nonce_authority,
self.nonce_blockhash,
) {
let mut message = Message::new_with_nonce(
token_instructions.to_vec(),
fee_payer,
&nonce_account,
&nonce_authority.pubkey(),
);
message.recent_blockhash = nonce_blockhash;
(message, nonce_blockhash)
} else {
let latest_blockhash = self
.client
.get_latest_blockhash()
.await
.map_err(TokenError::Client)?;
(
Message::new_with_blockhash(&instructions, fee_payer, &latest_blockhash),
latest_blockhash,
)
};
let blockhash = if let (Some(nonce_account), Some(nonce_authority), Some(nonce_blockhash)) = (
self.nonce_account,
&self.nonce_authority,
self.nonce_blockhash,
) {
let nonce_instruction = system_instruction::advance_nonce_account(
&nonce_account,
&nonce_authority.pubkey(),
);
instructions.insert(0, nonce_instruction);
nonce_blockhash
} else {
self.client
.get_latest_blockhash()
.await
.map_err(TokenError::Client)?
};

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

Expand Down

0 comments on commit 886693d

Please sign in to comment.