Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused Results in rust client #3563

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- spl: Upgrade SPL deps to latest ([#3346](https://github.com/coral-xyz/anchor/pull/3346)).
- cli: Upgrade `typescript` version of templates to v5 ([#3480](https://github.com/coral-xyz/anchor/pull/3480)).
- ts: Remove `snake-case` dependency ([#3507](https://github.com/coral-xyz/anchor/pull/3507)).
- client: Remove unused `Result` return types to simplify certain functions ([#3563](https://github.com/coral-xyz/anchor/pull/3563)).

## [0.30.1] - 2024-06-20

Expand Down
28 changes: 11 additions & 17 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ impl<C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'_, C,
self
}

pub fn instructions(&self) -> Result<Vec<Instruction>, ClientError> {
pub fn instructions(&self) -> Vec<Instruction> {
let mut instructions = self.instructions.clone();
if let Some(ix_data) = &self.instruction_data {
instructions.push(Instruction {
Expand All @@ -606,44 +606,38 @@ impl<C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'_, C,
});
}

Ok(instructions)
instructions
}

fn signed_transaction_with_blockhash(
&self,
latest_hash: Hash,
) -> Result<Transaction, ClientError> {
let instructions = self.instructions()?;
fn signed_transaction_with_blockhash(&self, latest_hash: Hash) -> Transaction {
let instructions = self.instructions();
let signers: Vec<&dyn Signer> = self.signers.iter().map(|s| s.as_signer()).collect();
let mut all_signers = signers;
all_signers.push(&*self.payer);

let tx = Transaction::new_signed_with_payer(
Transaction::new_signed_with_payer(
&instructions,
Some(&self.payer.pubkey()),
&all_signers,
latest_hash,
);

Ok(tx)
)
}

pub fn transaction(&self) -> Result<Transaction, ClientError> {
pub fn transaction(&self) -> Transaction {
let instructions = &self.instructions;
let tx = Transaction::new_with_payer(instructions, Some(&self.payer.pubkey()));
Ok(tx)
Transaction::new_with_payer(instructions, Some(&self.payer.pubkey()))
}

async fn signed_transaction_internal(&self) -> Result<Transaction, ClientError> {
let latest_hash = self.internal_rpc_client.get_latest_blockhash().await?;

let tx = self.signed_transaction_with_blockhash(latest_hash)?;
let tx = self.signed_transaction_with_blockhash(latest_hash);
Ok(tx)
}

async fn send_internal(&self) -> Result<Signature, ClientError> {
let latest_hash = self.internal_rpc_client.get_latest_blockhash().await?;
let tx = self.signed_transaction_with_blockhash(latest_hash)?;
let tx = self.signed_transaction_with_blockhash(latest_hash);

self.internal_rpc_client
.send_and_confirm_transaction(&tx)
Expand All @@ -656,7 +650,7 @@ impl<C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'_, C,
config: RpcSendTransactionConfig,
) -> Result<Signature, ClientError> {
let latest_hash = self.internal_rpc_client.get_latest_blockhash().await?;
let tx = self.signed_transaction_with_blockhash(latest_hash)?;
let tx = self.signed_transaction_with_blockhash(latest_hash);

self.internal_rpc_client
.send_and_confirm_transaction_with_spinner_and_config(
Expand Down