allow ability to pass in feePayer to Provider methods [WIP] (#2186)

* 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>
This commit is contained in:
surfertas 2022-12-05 21:45:27 +09:00 committed by GitHub
parent bbeffd58f7
commit 50724df110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -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))

View File

@ -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;
@ -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[] }[],
@ -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) => {
@ -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