2021-07-08 18:01:11 -07:00
|
|
|
import type {Buffer} from 'buffer';
|
|
|
|
|
2018-10-26 13:19:47 -07:00
|
|
|
import {PublicKey} from './publickey';
|
|
|
|
import {Loader} from './loader';
|
|
|
|
import type {Connection} from './connection';
|
2021-05-07 01:59:51 -07:00
|
|
|
import type {Signer} from './keypair';
|
2018-10-23 20:56:54 -07:00
|
|
|
|
2020-08-25 09:05:33 -07:00
|
|
|
export const BPF_LOADER_PROGRAM_ID = new PublicKey(
|
|
|
|
'BPFLoader2111111111111111111111111111111111',
|
|
|
|
);
|
|
|
|
|
2018-10-23 20:56:54 -07:00
|
|
|
/**
|
|
|
|
* Factory class for transactions to interact with a program loader
|
|
|
|
*/
|
|
|
|
export class BpfLoader {
|
2019-10-22 15:16:12 -07:00
|
|
|
/**
|
|
|
|
* Minimum number of signatures required to load a program not including
|
|
|
|
* retries
|
|
|
|
*
|
|
|
|
* Can be used to calculate transaction fees
|
|
|
|
*/
|
|
|
|
static getMinNumSignatures(dataLength: number): number {
|
|
|
|
return Loader.getMinNumSignatures(dataLength);
|
|
|
|
}
|
|
|
|
|
2018-10-23 20:56:54 -07:00
|
|
|
/**
|
2022-10-28 11:30:31 -07:00
|
|
|
* Load a SBF program
|
2018-10-23 20:56:54 -07:00
|
|
|
*
|
|
|
|
* @param connection The connection to use
|
2020-04-15 06:26:19 -07:00
|
|
|
* @param payer Account that will pay program loading fees
|
|
|
|
* @param program Account to load the program into
|
2022-10-28 11:30:31 -07:00
|
|
|
* @param elf The entire ELF containing the SBF program
|
2020-08-25 09:05:33 -07:00
|
|
|
* @param loaderProgramId The program id of the BPF loader to use
|
2020-09-23 07:54:27 -07:00
|
|
|
* @return true if program was loaded successfully, false if program was already loaded
|
2018-10-23 20:56:54 -07:00
|
|
|
*/
|
2019-05-08 09:33:04 -07:00
|
|
|
static load(
|
2018-10-23 20:56:54 -07:00
|
|
|
connection: Connection,
|
2021-05-07 01:59:51 -07:00
|
|
|
payer: Signer,
|
|
|
|
program: Signer,
|
2020-02-12 16:25:22 -08:00
|
|
|
elf: Buffer | Uint8Array | Array<number>,
|
2020-08-25 09:05:33 -07:00
|
|
|
loaderProgramId: PublicKey,
|
2020-09-23 07:54:27 -07:00
|
|
|
): Promise<boolean> {
|
2020-08-25 09:05:33 -07:00
|
|
|
return Loader.load(connection, payer, program, loaderProgramId, elf);
|
2018-10-23 20:56:54 -07:00
|
|
|
}
|
|
|
|
}
|