Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add compatibility for publicKeys #5895

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions token/js/src/instructions/internal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AccountMeta, Signer } from '@solana/web3.js';
import { PublicKey } from '@solana/web3.js';
import { PublicKey, Keypair } from '@solana/web3.js';

/** @internal */
export function addSigners(
Expand All @@ -9,12 +9,28 @@ export function addSigners(
): AccountMeta[] {
if (multiSigners.length) {
keys.push({ pubkey: ownerOrAuthority, isSigner: false, isWritable: false });

for (const signer of multiSigners) {
keys.push({
pubkey: signer instanceof PublicKey ? signer : signer.publicKey,
isSigner: true,
isWritable: false,
});
if (signer instanceof PublicKey || signer instanceof Keypair) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All Keypair are Signer but not all Signer are Keypair.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gitmazter if we're going to proceed with changes, instanceof should also be revised here.

keys.push({
pubkey: 'publicKey' in signer ? signer.publicKey : signer,
isSigner: true,
isWritable: false,
});
}
else if (signer.toString()) {
try {
const compatiblePubkey = new PublicKey(signer.toString())
keys.push({
pubkey: compatiblePubkey,
isSigner: true,
isWritable: false,
});
}
catch (e) {
// not a pubkey
}
}
Comment on lines +21 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a try-catch here with no catch?

}
} else {
keys.push({ pubkey: ownerOrAuthority, isSigner: true, isWritable: false });
Expand Down
Loading