Sfoglia il codice sorgente

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>
surfertas 2 anni fa
parent
commit
50724df110
2 ha cambiato i file con 10 aggiunte e 3 eliminazioni
  1. 1 0
      CHANGELOG.md
  2. 9 3
      ts/packages/anchor/src/provider.ts

+ 1 - 0
CHANGELOG.md

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

+ 9 - 3
ts/packages/anchor/src/provider.ts

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