fix: use bpf-loader-deprecated explicitly (#11818)

This commit is contained in:
Jack May 2020-08-25 09:05:33 -07:00 committed by GitHub
parent 4593c3a172
commit 2395e57f45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 37 deletions

7
web3.js/module.d.ts vendored
View File

@ -938,18 +938,21 @@ declare module '@solana/web3.js' {
} }
// === src/bpf-loader.js === // === src/bpf-loader.js ===
export const BPF_LOADER_PROGRAM_ID: PublicKey;
export class BpfLoader { export class BpfLoader {
static programId(version?: number): PublicKey;
static getMinNumSignatures(dataLength: number): number; static getMinNumSignatures(dataLength: number): number;
static load( static load(
connection: Connection, connection: Connection,
payer: Account, payer: Account,
program: Account, program: Account,
elfBytes: Buffer | Uint8Array | Array<number>, elfBytes: Buffer | Uint8Array | Array<number>,
version?: number, loaderProgramId: PublicKey,
): Promise<PublicKey>; ): Promise<PublicKey>;
} }
// === src/bpf-loader-deprecated.js ===
export const BPF_LOADER_DEPRECATED_PROGRAM_ID: PublicKey;
// === src/util/send-and-confirm-transaction.js === // === src/util/send-and-confirm-transaction.js ===
export function sendAndConfirmTransaction( export function sendAndConfirmTransaction(
connection: Connection, connection: Connection,

View File

@ -708,7 +708,7 @@ declare module '@solana/web3.js' {
stakePubkey: PublicKey, stakePubkey: PublicKey,
authorityBase: PublicKey, authorityBase: PublicKey,
authoritySeed: string, authoritySeed: string,
authorityOwner: PublicKey; authorityOwner: PublicKey,
newAuthorizedPubkey: PublicKey, newAuthorizedPubkey: PublicKey,
stakeAuthorizationType: StakeAuthorizationType, stakeAuthorizationType: StakeAuthorizationType,
|}; |};
@ -953,18 +953,21 @@ declare module '@solana/web3.js' {
} }
// === src/bpf-loader.js === // === src/bpf-loader.js ===
declare export var BPF_LOADER_PROGRAM_ID;
declare export class BpfLoader { declare export class BpfLoader {
static programId(version: ?number): PublicKey;
static getMinNumSignatures(dataLength: number): number; static getMinNumSignatures(dataLength: number): number;
static load( static load(
connection: Connection, connection: Connection,
payer: Account, payer: Account,
program: Account, program: Account,
elfBytes: Buffer | Uint8Array | Array<number>, elfBytes: Buffer | Uint8Array | Array<number>,
version: ?number, loaderProgramId: PublicKey,
): Promise<PublicKey>; ): Promise<PublicKey>;
} }
// === src/bpf-loader-deprecated.js ===
declare export var BPF_LOADER_DEPRECATED_PROGRAM_ID;
// === src/util/send-and-confirm-transaction.js === // === src/util/send-and-confirm-transaction.js ===
declare export function sendAndConfirmTransaction( declare export function sendAndConfirmTransaction(
connection: Connection, connection: Connection,

View File

@ -0,0 +1,7 @@
// @flow
import {PublicKey} from './publickey';
export const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey(
'BPFLoader1111111111111111111111111111111111',
);

View File

@ -5,21 +5,14 @@ import {PublicKey} from './publickey';
import {Loader} from './loader'; import {Loader} from './loader';
import type {Connection} from './connection'; import type {Connection} from './connection';
export const BPF_LOADER_PROGRAM_ID = new PublicKey(
'BPFLoader2111111111111111111111111111111111',
);
/** /**
* Factory class for transactions to interact with a program loader * Factory class for transactions to interact with a program loader
*/ */
export class BpfLoader { export class BpfLoader {
/**
* Public key that identifies the BpfLoader
*/
static programId(version: number = 2): PublicKey {
if (version === 1) {
return new PublicKey('BPFLoader1111111111111111111111111111111111');
} else {
return new PublicKey('BPFLoader2111111111111111111111111111111111');
}
}
/** /**
* Minimum number of signatures required to load a program not including * Minimum number of signatures required to load a program not including
* retries * retries
@ -37,21 +30,15 @@ export class BpfLoader {
* @param payer Account that will pay program loading fees * @param payer Account that will pay program loading fees
* @param program Account to load the program into * @param program Account to load the program into
* @param elf The entire ELF containing the BPF program * @param elf The entire ELF containing the BPF program
* @param version The version of the BPF loader to use * @param loaderProgramId The program id of the BPF loader to use
*/ */
static load( static load(
connection: Connection, connection: Connection,
payer: Account, payer: Account,
program: Account, program: Account,
elf: Buffer | Uint8Array | Array<number>, elf: Buffer | Uint8Array | Array<number>,
version: number = 2, loaderProgramId: PublicKey,
): Promise<void> { ): Promise<void> {
return Loader.load( return Loader.load(connection, payer, program, loaderProgramId, elf);
connection,
payer,
program,
BpfLoader.programId(version),
elf,
);
} }
} }

View File

@ -1754,11 +1754,7 @@ export class Connection {
publicKey: PublicKey, publicKey: PublicKey,
commitment: ?Commitment, commitment: ?Commitment,
): Promise<RpcResponseAndContext<AccountInfo<Buffer> | null>> { ): Promise<RpcResponseAndContext<AccountInfo<Buffer> | null>> {
const args = this._buildArgs( const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64');
[publicKey.toBase58()],
commitment,
'base64',
);
const unsafeRes = await this._rpcRequest('getAccountInfo', args); const unsafeRes = await this._rpcRequest('getAccountInfo', args);
const res = GetAccountInfoAndContextRpcResult(unsafeRes); const res = GetAccountInfoAndContextRpcResult(unsafeRes);
if (res.error) { if (res.error) {
@ -1868,11 +1864,7 @@ export class Connection {
programId: PublicKey, programId: PublicKey,
commitment: ?Commitment, commitment: ?Commitment,
): Promise<Array<{pubkey: PublicKey, account: AccountInfo<Buffer>}>> { ): Promise<Array<{pubkey: PublicKey, account: AccountInfo<Buffer>}>> {
const args = this._buildArgs( const args = this._buildArgs([programId.toBase58()], commitment, 'base64');
[programId.toBase58()],
commitment,
'base64',
);
const unsafeRes = await this._rpcRequest('getProgramAccounts', args); const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
const res = GetProgramAccountsRpcResult(unsafeRes); const res = GetProgramAccountsRpcResult(unsafeRes);
if (res.error) { if (res.error) {

View File

@ -13,6 +13,7 @@ import {
import {mockRpcEnabled} from './__mocks__/node-fetch'; import {mockRpcEnabled} from './__mocks__/node-fetch';
import {url} from './url'; import {url} from './url';
import {newAccountWithLamports} from './new-account-with-lamports'; import {newAccountWithLamports} from './new-account-with-lamports';
import {BPF_LOADER_PROGRAM_ID} from '../src/bpf-loader';
if (!mockRpcEnabled) { if (!mockRpcEnabled) {
// The default of 5 seconds is too slow for live testing sometimes // The default of 5 seconds is too slow for live testing sometimes
@ -40,7 +41,7 @@ test('load BPF C program', async () => {
const from = await newAccountWithLamports(connection, fees + balanceNeeded); const from = await newAccountWithLamports(connection, fees + balanceNeeded);
const program = new Account(); const program = new Account();
await BpfLoader.load(connection, from, program, data); await BpfLoader.load(connection, from, program, data, BPF_LOADER_PROGRAM_ID);
const transaction = new Transaction().add({ const transaction = new Transaction().add({
keys: [{pubkey: from.publicKey, isSigner: true, isWritable: true}], keys: [{pubkey: from.publicKey, isSigner: true, isWritable: true}],
programId: program.publicKey, programId: program.publicKey,
@ -82,7 +83,13 @@ describe('load BPF Rust program', () => {
); );
program = new Account(); program = new Account();
await BpfLoader.load(connection, payerAccount, program, data); await BpfLoader.load(
connection,
payerAccount,
program,
data,
BPF_LOADER_PROGRAM_ID,
);
const transaction = new Transaction().add({ const transaction = new Transaction().add({
keys: [ keys: [
{pubkey: payerAccount.publicKey, isSigner: true, isWritable: true}, {pubkey: payerAccount.publicKey, isSigner: true, isWritable: true},