ts: Use Signer instead of Keypair (#296)

This commit is contained in:
Armani Ferrante 2021-05-20 02:26:32 -07:00 committed by GitHub
parent b652f5f940
commit 364f957c9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 16 deletions

View File

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

View File

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

View File

@ -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<Keypair>;
signers?: Array<Signer>;
/**
* Instructions to run *before* a given method. Often this is used, for

View File

@ -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<ProgramAccount<any>[]>;
subscribe: (address: PublicKey, commitment?: Commitment) => EventEmitter;
unsubscribe: (address: PublicKey) => void;
createInstruction: (keypair: Keypair) => Promise<TransactionInstruction>;
createInstruction: (signer: Signer) => Promise<TransactionInstruction>;
associated: (...args: PublicKey[]) => Promise<any>;
associatedAddress: (...args: PublicKey[]) => Promise<PublicKey>;
};
@ -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<TransactionInstruction> => {
// @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

View File

@ -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<Keypair | undefined>,
signers?: Array<Signer | undefined>,
opts?: ConfirmOptions
): Promise<TransactionSignature> {
if (signers === undefined) {
@ -91,7 +92,7 @@ export default class Provider {
opts = this.opts;
}
const signerKps = signers.filter((s) => s !== undefined) as Array<Keypair>;
const signerKps = signers.filter((s) => s !== undefined) as Array<Signer>;
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<Keypair>;
const signerKps = signers.filter((s) => s !== undefined) as Array<Signer>;
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<Keypair | undefined>,
signers?: Array<Signer | undefined>,
opts?: ConfirmOptions
): Promise<RpcResponseAndContext<SimulatedTransactionResponse>> {
if (signers === undefined) {
@ -190,7 +189,7 @@ export default class Provider {
opts = this.opts;
}
const signerKps = signers.filter((s) => s !== undefined) as Array<Keypair>;
const signerKps = signers.filter((s) => s !== undefined) as Array<Signer>;
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<Keypair | undefined>;
signers: Array<Signer | undefined>;
};
/**