fix: Remove fs dep, bpf_loader now takes ELF as bytes
This commit is contained in:
parent
224d929d4d
commit
f871b0410a
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,5 @@
|
|||
// @flow
|
||||
|
||||
import fs from 'mz/fs';
|
||||
import elfy from 'elfy';
|
||||
|
||||
import {Account, PublicKey, Loader, SystemProgram} from '.';
|
||||
|
@ -12,31 +11,29 @@ import type {Connection} from '.';
|
|||
*/
|
||||
export class BpfLoader {
|
||||
/**
|
||||
* Public key that identifies the NativeLoader
|
||||
* Public key that identifies the BpfLoader
|
||||
*/
|
||||
static get programId(): PublicKey {
|
||||
return new PublicKey('0x0606060606060606060606060606060606060606060606060606060606060606');
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a BPF program
|
||||
* Load a BPF program
|
||||
*
|
||||
* @param connection The connection to use
|
||||
* @param owner User account to load the program with
|
||||
* @param programName Name of the BPF program
|
||||
* @param owner User account to load the program into
|
||||
* @param elfBytes the entire ELF containing the BPF program in its .text.entrypoint section
|
||||
*/
|
||||
static async load(
|
||||
connection: Connection,
|
||||
owner: Account,
|
||||
programName: string,
|
||||
elfBytes: Array<number>,
|
||||
): Promise<PublicKey> {
|
||||
const programAccount = new Account();
|
||||
|
||||
const data = await fs.readFile(programName);
|
||||
const elf = elfy.parse(data);
|
||||
const elf = elfy.parse(elfBytes);
|
||||
const section = elf.body.sections.find(section => section.name === '.text.entrypoint');
|
||||
|
||||
// Allocate memory for the program account
|
||||
const transaction = SystemProgram.createAccount(
|
||||
owner.publicKey,
|
||||
programAccount.publicKey,
|
||||
|
|
|
@ -51,7 +51,7 @@ export class Loader {
|
|||
const transactions = [];
|
||||
while (array.length > 0) {
|
||||
const bytes = array.slice(0, chunkSize);
|
||||
let userdata = Buffer.alloc(chunkSize + 16);
|
||||
const userdata = Buffer.alloc(chunkSize + 16);
|
||||
userdataLayout.encode(
|
||||
{
|
||||
instruction: 0, // Load instruction
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
// @flow
|
||||
|
||||
import fs from 'mz/fs';
|
||||
|
||||
import {
|
||||
Connection,
|
||||
BpfLoader,
|
||||
|
@ -23,7 +25,8 @@ test('load BPF program', async () => {
|
|||
|
||||
const connection = new Connection(url);
|
||||
const from = await newAccountWithTokens(connection);
|
||||
const programId = await BpfLoader.load(connection, from, 'test/bin/noop_c.o');
|
||||
const data = await fs.readFile('test/bin/noop_c.o');
|
||||
const programId = await BpfLoader.load(connection, from, data);
|
||||
const transaction = new Transaction().add({
|
||||
keys: [from.publicKey],
|
||||
programId,
|
||||
|
|
Loading…
Reference in New Issue