Skip to content

Commit

Permalink
fix: functionRequestInit signer check gets ignored if not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
gallynaut committed Oct 17, 2023
1 parent 1b777a6 commit da69aa6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion javascript/solana.js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@switchboard-xyz/solana.js",
"version": "2.7.1",
"version": "2.8.1",
"author": "",
"license": "MIT",
"description": "A Typescript client to interact with Switchboard on Solana.",
Expand Down
36 changes: 31 additions & 5 deletions javascript/solana.js/src/accounts/functionRequestAccount.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Idl, Program } from "@coral-xyz/anchor";
import { Account } from "../accounts/account.js";
import * as errors from "../errors.js";
import * as types from "../generated/attestation-program/index.js";
Expand All @@ -16,6 +17,7 @@ import {
TOKEN_PROGRAM_ID,
} from "@solana/spl-token";
import type {
AccountMeta,
Commitment,
PublicKey,
TransactionInstruction,
Expand All @@ -42,6 +44,12 @@ export interface FunctionRequestAccountInitParams {
keypair?: Keypair;

authority?: PublicKey;

/**
* An optional keypair to be used to sign the transaction if the function requires
* authorization on request initialization.
*/
functionAuthority?: Keypair;
}

/**
Expand Down Expand Up @@ -121,9 +129,6 @@ export class FunctionRequestAccount extends Account<types.FunctionRequestAccount
params: FunctionRequestAccountInitParams,
options?: TransactionObjectOptions
): Promise<[FunctionRequestAccount, TransactionObject]> {
// TODO: Calculate the max size of data we can support up front then split into multiple txns

// TODO: Add way to make this a PDA
const requestKeypair = params.keypair ?? Keypair.generate();
await program.verifyNewKeypair(requestKeypair);

Expand All @@ -147,7 +152,9 @@ export class FunctionRequestAccount extends Account<types.FunctionRequestAccount
{
request: requestKeypair.publicKey,
function: params.functionAccount.publicKey,
functionAuthority: functionState.authority,
functionAuthority: params.functionAuthority
? params.functionAuthority.publicKey
: program.attestationProgramId,
attestationQueue: functionState.attestationQueue,
escrow,
mint: program.mint.address,
Expand All @@ -159,9 +166,28 @@ export class FunctionRequestAccount extends Account<types.FunctionRequestAccount
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
}
);

instruction.keys = instruction.keys.map(
(accountMeta): AccountMeta =>
accountMeta.pubkey.equals(program.programId)
? {
pubkey: accountMeta.pubkey,
isSigner: false,
isWritable: accountMeta.isWritable,
}
: accountMeta
);

return [
new FunctionRequestAccount(program, requestKeypair.publicKey),
new TransactionObject(payer, [instruction], [requestKeypair], options),
new TransactionObject(
payer,
[instruction],
params.functionAuthority
? [requestKeypair, params.functionAuthority]
: [requestKeypair],
options
),
];
}

Expand Down

0 comments on commit da69aa6

Please sign in to comment.