feat: specify program account when using bpf loader

This commit is contained in:
Justin Starry 2020-04-15 21:26:19 +08:00 committed by Michael Vines
parent 56781f893e
commit e6fb146809
4 changed files with 10 additions and 4 deletions

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

@ -651,6 +651,7 @@ declare module '@solana/web3.js' {
static load( static load(
connection: Connection, connection: Connection,
payer: Account, payer: Account,
program: Account,
elfBytes: Buffer | Uint8Array | Array<number>, elfBytes: Buffer | Uint8Array | Array<number>,
): Promise<PublicKey>; ): Promise<PublicKey>;
} }

View File

@ -662,6 +662,7 @@ declare module '@solana/web3.js' {
static load( static load(
connection: Connection, connection: Connection,
payer: Account, payer: Account,
program: Account,
elfBytes: Buffer | Uint8Array | Array<number>, elfBytes: Buffer | Uint8Array | Array<number>,
): Promise<PublicKey>; ): Promise<PublicKey>;
} }

View File

@ -30,15 +30,16 @@ export class BpfLoader {
* Load a BPF program * Load a BPF program
* *
* @param connection The connection to use * @param connection The connection to use
* @param owner User account to load the program into * @param payer Account that will pay program loading fees
* @param program Account to load the program into
* @param elfBytes The entire ELF containing the BPF program * @param elfBytes The entire ELF containing the BPF program
*/ */
static load( static load(
connection: Connection, connection: Connection,
payer: Account, payer: Account,
program: Account,
elf: Buffer | Uint8Array | Array<number>, elf: Buffer | Uint8Array | Array<number>,
): Promise<PublicKey> { ): Promise<PublicKey> {
const program = new Account();
return Loader.load(connection, payer, program, BpfLoader.programId, elf); return Loader.load(connection, payer, program, BpfLoader.programId, elf);
} }
} }

View File

@ -7,6 +7,7 @@ import {
BpfLoader, BpfLoader,
Transaction, Transaction,
sendAndConfirmTransaction, sendAndConfirmTransaction,
Account,
} from '../src'; } from '../src';
import {mockRpcEnabled} from './__mocks__/node-fetch'; import {mockRpcEnabled} from './__mocks__/node-fetch';
import {url} from './url'; import {url} from './url';
@ -37,7 +38,8 @@ test('load BPF C program', async () => {
); );
const from = await newAccountWithLamports(connection, fees + balanceNeeded); const from = await newAccountWithLamports(connection, fees + balanceNeeded);
const programId = await BpfLoader.load(connection, from, data); const program = new Account();
const programId = await BpfLoader.load(connection, from, program, data);
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, programId,
@ -65,7 +67,8 @@ test('load BPF Rust program', async () => {
); );
const from = await newAccountWithLamports(connection, fees + balanceNeeded); const from = await newAccountWithLamports(connection, fees + balanceNeeded);
const programId = await BpfLoader.load(connection, from, data); const program = new Account();
const programId = await BpfLoader.load(connection, from, program, data);
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, programId,