From 364f957c9a3ada69c4bcd2331e967e797899ea31 Mon Sep 17 00:00:00 2001 From: Armani Ferrante Date: Thu, 20 May 2021 02:26:32 -0700 Subject: [PATCH] ts: Use Signer instead of Keypair (#296) --- CHANGELOG.md | 2 +- ts/package.json | 2 +- ts/src/program/context.ts | 4 ++-- ts/src/program/namespace/account.ts | 8 ++++---- ts/src/provider.ts | 15 +++++++-------- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fdffd0b9..f743cd2a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ incremented for features. ## Breaking Changes -* ts: Replace deprecated `web3.Account` with `web3.Keypair` ([#274](https://github.com/project-serum/anchor/pull/274)). +* ts: Replace deprecated `web3.Account` with `web3.Signer` in public APIs ([#296](https://github.com/project-serum/anchor/pull/296)). ## [0.5.0] - 2021-05-07 diff --git a/ts/package.json b/ts/package.json index cfbe0c685..54b1306ca 100644 --- a/ts/package.json +++ b/ts/package.json @@ -1,6 +1,6 @@ { "name": "@project-serum/anchor", - "version": "0.6.0-beta.1", + "version": "0.6.0-beta.2", "description": "Anchor client", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", diff --git a/ts/src/program/context.ts b/ts/src/program/context.ts index 59b73fcaa..e11dc95c7 100644 --- a/ts/src/program/context.ts +++ b/ts/src/program/context.ts @@ -1,6 +1,6 @@ import { AccountMeta, - Keypair, + Signer, PublicKey, ConfirmOptions, TransactionInstruction, @@ -25,7 +25,7 @@ export type Context = { /** * Accounts that must sign a given transaction. */ - signers?: Array; + signers?: Array; /** * Instructions to run *before* a given method. Often this is used, for diff --git a/ts/src/program/namespace/account.ts b/ts/src/program/namespace/account.ts index 574f61526..cf032fcda 100644 --- a/ts/src/program/namespace/account.ts +++ b/ts/src/program/namespace/account.ts @@ -2,7 +2,7 @@ import camelCase from "camelcase"; import EventEmitter from "eventemitter3"; import * as bs58 from "bs58"; import { - Keypair, + Signer, PublicKey, SystemProgram, TransactionInstruction, @@ -38,7 +38,7 @@ type AccountProps = { all: (filter?: Buffer) => Promise[]>; subscribe: (address: PublicKey, commitment?: Commitment) => EventEmitter; unsubscribe: (address: PublicKey) => void; - createInstruction: (keypair: Keypair) => Promise; + createInstruction: (signer: Signer) => Promise; associated: (...args: PublicKey[]) => Promise; associatedAddress: (...args: PublicKey[]) => Promise; }; @@ -93,7 +93,7 @@ export default class AccountFactory { // Returns an instruction for creating this account. // @ts-ignore accountsNamespace["createInstruction"] = async ( - keypair: Keypair, + signer: Signer, sizeOverride?: number ): Promise => { // @ts-ignore @@ -101,7 +101,7 @@ export default class AccountFactory { return SystemProgram.createAccount({ fromPubkey: provider.wallet.publicKey, - newAccountPubkey: keypair.publicKey, + newAccountPubkey: signer.publicKey, space: sizeOverride ?? size, lamports: await provider.connection.getMinimumBalanceForRentExemption( sizeOverride ?? size diff --git a/ts/src/provider.ts b/ts/src/provider.ts index 253c93af9..11f8a68da 100644 --- a/ts/src/provider.ts +++ b/ts/src/provider.ts @@ -1,6 +1,7 @@ import { Connection, Keypair, + Signer, PublicKey, Transaction, TransactionSignature, @@ -81,7 +82,7 @@ export default class Provider { */ async send( tx: Transaction, - signers?: Array, + signers?: Array, opts?: ConfirmOptions ): Promise { if (signers === undefined) { @@ -91,7 +92,7 @@ export default class Provider { opts = this.opts; } - const signerKps = signers.filter((s) => s !== undefined) as Array; + const signerKps = signers.filter((s) => s !== undefined) as Array; const signerPubkeys = [this.wallet.publicKey].concat( signerKps.map((s) => s.publicKey) ); @@ -139,9 +140,7 @@ export default class Provider { signers = []; } - const signerKps = signers.filter( - (s) => s !== undefined - ) as Array; + const signerKps = signers.filter((s) => s !== undefined) as Array; const signerPubkeys = [this.wallet.publicKey].concat( signerKps.map((s) => s.publicKey) ); @@ -180,7 +179,7 @@ export default class Provider { */ async simulate( tx: Transaction, - signers?: Array, + signers?: Array, opts?: ConfirmOptions ): Promise> { if (signers === undefined) { @@ -190,7 +189,7 @@ export default class Provider { opts = this.opts; } - const signerKps = signers.filter((s) => s !== undefined) as Array; + const signerKps = signers.filter((s) => s !== undefined) as Array; const signerPubkeys = [this.wallet.publicKey].concat( signerKps.map((s) => s.publicKey) ); @@ -216,7 +215,7 @@ export default class Provider { export type SendTxRequest = { tx: Transaction; - signers: Array; + signers: Array; }; /**