fix: Pass full BPF ELF (#60)

This commit is contained in:
jackcmay
2018-11-06 15:14:59 -08:00
committed by Michael Vines
parent ee25e0278c
commit 71328e9420
4 changed files with 3190 additions and 3195 deletions

6368
web3.js/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -66,7 +66,6 @@
"bn.js": "^4.11.8", "bn.js": "^4.11.8",
"bs58": "^4.0.1", "bs58": "^4.0.1",
"buffer-layout": "^1.2.0", "buffer-layout": "^1.2.0",
"elfy": "^0.1.0",
"jayson": "^2.0.6", "jayson": "^2.0.6",
"mz": "^2.7.0", "mz": "^2.7.0",
"node-fetch": "^2.2.0", "node-fetch": "^2.2.0",
@ -85,6 +84,7 @@
"babel-preset-stage-0": "6.24.1", "babel-preset-stage-0": "6.24.1",
"codecov": "^3.0.4", "codecov": "^3.0.4",
"cross-env": "5.2.0", "cross-env": "5.2.0",
"elfy": "^0.1.0",
"enzyme": "3.6.0", "enzyme": "3.6.0",
"esdoc": "^1.1.0", "esdoc": "^1.1.0",
"esdoc-ecmascript-proposal-plugin": "^1.0.0", "esdoc-ecmascript-proposal-plugin": "^1.0.0",

View File

@ -1,7 +1,5 @@
// @flow // @flow
import elfy from 'elfy';
import {Account} from './account'; import {Account} from './account';
import {PublicKey} from './publickey'; import {PublicKey} from './publickey';
import {Loader} from './loader'; import {Loader} from './loader';
@ -27,31 +25,26 @@ export class BpfLoader {
* *
* @param connection The connection to use * @param connection The connection to use
* @param owner User account to load the program into * @param owner User account to load the program into
* @param elfBytes the entire ELF containing the BPF program in its .text.entrypoint section * @param elfBytes The entire ELF containing the BPF program
*/ */
static async load( static async load(
connection: Connection, connection: Connection,
owner: Account, owner: Account,
elfBytes: Array<number>, elf: Array<number>,
): Promise<PublicKey> { ): Promise<PublicKey> {
const programAccount = new Account(); const programAccount = new Account();
const elf = elfy.parse(elfBytes);
const section = elf.body.sections.find(
section => section.name === '.text.entrypoint',
);
const transaction = SystemProgram.createAccount( const transaction = SystemProgram.createAccount(
owner.publicKey, owner.publicKey,
programAccount.publicKey, programAccount.publicKey,
1, 1,
section.data.length, elf.length,
BpfLoader.programId, BpfLoader.programId,
); );
await sendAndConfirmTransaction(connection, owner, transaction); await sendAndConfirmTransaction(connection, owner, transaction);
const loader = new Loader(connection, BpfLoader.programId); const loader = new Loader(connection, BpfLoader.programId);
await loader.load(programAccount, section.data); await loader.load(programAccount, elf);
await loader.finalize(programAccount); await loader.finalize(programAccount);
return programAccount.publicKey; return programAccount.publicKey;

Binary file not shown.