fix: Remove fs dep, bpf_loader now takes ELF as bytes

This commit is contained in:
Jack May 2018-10-25 10:41:18 -07:00 committed by Michael Vines
parent 224d929d4d
commit f871b0410a
4 changed files with 3175 additions and 3175 deletions

6328
web3.js/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -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,

View File

@ -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

View File

@ -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,