Skip to content

Commit

Permalink
ts: improve types for Provider and AccountClient
Browse files Browse the repository at this point in the history
  • Loading branch information
kAsky53 committed Oct 13, 2023
1 parent 23eeb1e commit 5fe49da
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- ts: Remove `base64-js` dependency ([#2635](https://github.com/coral-xyz/anchor/pull/2635)).
- syn: `IdlTypeDefinitionTy` enum has a new variant `Alias` ([#2637](https://github.com/coral-xyz/anchor/pull/2637)).
- cli, client, lang, spl: Solana `1.14` is no longer supported, minimum required Solana version is `1.16.0` ([#2645](https://github.com/coral-xyz/anchor/pull/2645)).
- ts: Change Provider.publicKey type into `PublicKey | null` instead of `PublicKey | undefined`, `AccountClient.createInstruction(signer: Signer, size?: number)` into `AccountClient.createInstruction(signerPubkey: PublicKey, size?: number)` ([#2665](https://github.com/coral-xyz/anchor/issues/2665)).

## [0.28.0] - 2023-06-09

Expand Down
2 changes: 1 addition & 1 deletion ts/packages/anchor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coral-xyz/anchor",
"version": "0.28.1-beta.2",
"version": "0.28.1-beta.3",
"description": "Anchor client",
"module": "./dist/esm/index.js",
"main": "./dist/cjs/index.js",
Expand Down
14 changes: 6 additions & 8 deletions ts/packages/anchor/src/program/namespace/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,25 +349,23 @@ export class AccountClient<
* Returns an instruction for creating this account.
*/
async createInstruction(
signer: Signer,
signerPubkey: PublicKey,
sizeOverride?: number
): Promise<TransactionInstruction> {
const size = this.size;
const size = sizeOverride ?? this.size;

if (this._provider.publicKey === undefined) {
if (!this._provider.publicKey) {
throw new Error(
"This function requires the Provider interface implementor to have a 'publicKey' field."
);
}

return SystemProgram.createAccount({
fromPubkey: this._provider.publicKey,
newAccountPubkey: signer.publicKey,
space: sizeOverride ?? size,
newAccountPubkey: signerPubkey,
space: size,
lamports:
await this._provider.connection.getMinimumBalanceForRentExemption(
sizeOverride ?? size
),
await this._provider.connection.getMinimumBalanceForRentExemption(size),
programId: this._programId,
});
}
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/anchor/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {

export default interface Provider {
readonly connection: Connection;
readonly publicKey?: PublicKey;
readonly publicKey: PublicKey | null;

send?(
tx: Transaction | VersionedTransaction,
Expand Down

0 comments on commit 5fe49da

Please sign in to comment.