feat: add stake program methods; refactor instruction type handling
This commit is contained in:
committed by
Michael Vines
parent
fc77e55920
commit
532b28e96e
@ -2,9 +2,11 @@
|
||||
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
|
||||
import {Transaction, TransactionInstruction} from './transaction';
|
||||
import {PublicKey} from './publickey';
|
||||
import {encodeData} from './instruction';
|
||||
import type {InstructionType} from './instruction';
|
||||
import * as Layout from './layout';
|
||||
import {PublicKey} from './publickey';
|
||||
import {Transaction, TransactionInstruction} from './transaction';
|
||||
import type {TransactionInstructionCtorFields} from './transaction';
|
||||
|
||||
/**
|
||||
@ -14,12 +16,9 @@ export class SystemInstruction extends TransactionInstruction {
|
||||
/**
|
||||
* Type of SystemInstruction
|
||||
*/
|
||||
type: SystemInstructionType;
|
||||
type: InstructionType;
|
||||
|
||||
constructor(
|
||||
opts?: TransactionInstructionCtorFields,
|
||||
type?: SystemInstructionType,
|
||||
) {
|
||||
constructor(opts?: TransactionInstructionCtorFields, type?: InstructionType) {
|
||||
if (
|
||||
opts &&
|
||||
opts.programId &&
|
||||
@ -107,16 +106,6 @@ export class SystemInstruction extends TransactionInstruction {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} SystemInstructionType
|
||||
* @property (index} The System Instruction index (from solana-sdk)
|
||||
* @property (BufferLayout} The BufferLayout to use to build data
|
||||
*/
|
||||
type SystemInstructionType = {|
|
||||
index: number,
|
||||
layout: typeof BufferLayout,
|
||||
|};
|
||||
|
||||
/**
|
||||
* An enumeration of valid SystemInstructionTypes
|
||||
*/
|
||||
@ -157,18 +146,6 @@ const SystemInstructionLayout = Object.freeze({
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Populate a buffer of instruction data using the SystemInstructionType
|
||||
*/
|
||||
function encodeData(type: SystemInstructionType, fields: Object): Buffer {
|
||||
const allocLength =
|
||||
type.layout.span >= 0 ? type.layout.span : Layout.getAlloc(type, fields);
|
||||
const data = Buffer.alloc(allocLength);
|
||||
const layoutFields = Object.assign({instruction: type.index}, fields);
|
||||
type.layout.encode(layoutFields, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory class for transactions to interact with the System program
|
||||
*/
|
||||
|
Reference in New Issue
Block a user