Skip to content

Commit

Permalink
allow ability to pass in feePayer to Provider methods [WIP] (#2186)
Browse files Browse the repository at this point in the history
* allow ability to pass in feePayer to Provider methods

* align comments

* prettier

* check if feePayer set, handle if not

* remove unnecessary spaces in comments

* update changelog

* strict equality check

* use null check

* use logical or

* use logical or

Co-authored-by: Henry-E <henry.elder@adaptcentre.ie>
  • Loading branch information
surfertas and Henry-E committed Dec 5, 2022
1 parent bbeffd5 commit 50724df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- ts: Add ability to set args after setting accounts and retrieving pubkyes ([#2160](https://github.com/coral-xyz/anchor/pull/2160))
- ts: Add `.prepare()` to builder pattern ([#2160](https://github.com/coral-xyz/anchor/pull/2160))
- spl: Add `freeze_delegated_account` and `thaw_delegated_account` wrappers ([#2164](https://github.com/coral-xyz/anchor/pull/2164))
- ts: Add `feePayer` check to `AnchorProvider` methods, so that anchor writes the provider's wallet as fee payer if fee payer isn't already set ([#2186](https://github.com/coral-xyz/anchor/pull/2186))
- ts: Add nested PDA inference ([#2194](https://github.com/coral-xyz/anchor/pull/2194))
- ts: Add ability to resolve missing accounts with a custom resolver ([#2194](https://github.com/coral-xyz/anchor/pull/2194))
- ts: Update the Solana web3 library used by anchor ts to version 1.64.0 ([#2220](https://github.com/coral-xyz/anchor/issues/2220))
Expand Down
12 changes: 9 additions & 3 deletions ts/packages/anchor/src/provider.ts
Expand Up @@ -132,7 +132,8 @@ export class AnchorProvider implements Provider {
opts = this.opts;
}

tx.feePayer = this.wallet.publicKey;
tx.feePayer = tx.feePayer || this.wallet.publicKey;

tx.recentBlockhash = (
await this.connection.getLatestBlockhash(opts.preflightCommitment)
).blockhash;
Expand Down Expand Up @@ -172,6 +173,9 @@ export class AnchorProvider implements Provider {

/**
* Similar to `send`, but for an array of transactions and signers.
*
* @param txWithSigners Array of transactions and signers.
* @param opts Transaction confirmation options.
*/
async sendAll(
txWithSigners: { tx: Transaction; signers?: Signer[] }[],
Expand All @@ -188,7 +192,8 @@ export class AnchorProvider implements Provider {
let tx = r.tx;
let signers = r.signers ?? [];

tx.feePayer = this.wallet.publicKey;
tx.feePayer = tx.feePayer || this.wallet.publicKey;

tx.recentBlockhash = blockhash.blockhash;

signers.forEach((kp) => {
Expand Down Expand Up @@ -226,7 +231,8 @@ export class AnchorProvider implements Provider {
commitment?: Commitment,
includeAccounts?: boolean | PublicKey[]
): Promise<SuccessfulTxSimulationResponse> {
tx.feePayer = this.wallet.publicKey;
tx.feePayer = tx.feePayer || this.wallet.publicKey;

tx.recentBlockhash = (
await this.connection.getLatestBlockhash(
commitment ?? this.connection.commitment
Expand Down

1 comment on commit 50724df

@vercel
Copy link

@vercel vercel bot commented on 50724df Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

anchor-docs – ./

anchor-docs-git-master-200ms.vercel.app
anchor-docs-200ms.vercel.app
www.anchor-lang.com
anchor-lang.com

Please sign in to comment.