fix: add TypeScript buffer type to stake-program.ts
This commit is contained in:
committed by
Steven Luscher
parent
6686b7c534
commit
477355df3b
@ -1,6 +1,11 @@
|
|||||||
import * as BufferLayout from '@solana/buffer-layout';
|
import * as BufferLayout from '@solana/buffer-layout';
|
||||||
|
|
||||||
import {encodeData, decodeData, InstructionType} from './instruction';
|
import {
|
||||||
|
encodeData,
|
||||||
|
decodeData,
|
||||||
|
InstructionType,
|
||||||
|
IInstructionInputData,
|
||||||
|
} from './instruction';
|
||||||
import * as Layout from './layout';
|
import * as Layout from './layout';
|
||||||
import {PublicKey} from './publickey';
|
import {PublicKey} from './publickey';
|
||||||
import {SystemProgram} from './system-program';
|
import {SystemProgram} from './system-program';
|
||||||
@ -40,6 +45,11 @@ export class Authorized {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AuthorizedRaw = Readonly<{
|
||||||
|
staker: Uint8Array;
|
||||||
|
withdrawer: Uint8Array;
|
||||||
|
}>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stake account lockup info
|
* Stake account lockup info
|
||||||
*/
|
*/
|
||||||
@ -66,6 +76,12 @@ export class Lockup {
|
|||||||
static default: Lockup = new Lockup(0, 0, PublicKey.default);
|
static default: Lockup = new Lockup(0, 0, PublicKey.default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LockupRaw = Readonly<{
|
||||||
|
custodian: Uint8Array;
|
||||||
|
epoch: number;
|
||||||
|
unixTimestamp: number;
|
||||||
|
}>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create stake account transaction params
|
* Create stake account transaction params
|
||||||
*/
|
*/
|
||||||
@ -429,25 +445,63 @@ export class StakeInstruction {
|
|||||||
* An enumeration of valid StakeInstructionType's
|
* An enumeration of valid StakeInstructionType's
|
||||||
*/
|
*/
|
||||||
export type StakeInstructionType =
|
export type StakeInstructionType =
|
||||||
| 'AuthorizeWithSeed'
|
// FIXME
|
||||||
|
// It would be preferable for this type to be `keyof StakeInstructionInputData`
|
||||||
|
// but Typedoc does not transpile `keyof` expressions.
|
||||||
|
// See https://github.com/TypeStrong/typedoc/issues/1894
|
||||||
| 'Authorize'
|
| 'Authorize'
|
||||||
|
| 'AuthorizeWithSeed'
|
||||||
| 'Deactivate'
|
| 'Deactivate'
|
||||||
| 'Delegate'
|
| 'Delegate'
|
||||||
| 'Initialize'
|
| 'Initialize'
|
||||||
|
| 'Merge'
|
||||||
| 'Split'
|
| 'Split'
|
||||||
| 'Withdraw'
|
| 'Withdraw';
|
||||||
| 'Merge';
|
|
||||||
|
type StakeInstructionInputData = {
|
||||||
|
Authorize: IInstructionInputData &
|
||||||
|
Readonly<{
|
||||||
|
newAuthorized: Uint8Array;
|
||||||
|
stakeAuthorizationType: number;
|
||||||
|
}>;
|
||||||
|
AuthorizeWithSeed: IInstructionInputData &
|
||||||
|
Readonly<{
|
||||||
|
authorityOwner: Uint8Array;
|
||||||
|
authoritySeed: string;
|
||||||
|
instruction: number;
|
||||||
|
newAuthorized: Uint8Array;
|
||||||
|
stakeAuthorizationType: number;
|
||||||
|
}>;
|
||||||
|
Deactivate: IInstructionInputData;
|
||||||
|
Delegate: IInstructionInputData;
|
||||||
|
Initialize: IInstructionInputData &
|
||||||
|
Readonly<{
|
||||||
|
authorized: AuthorizedRaw;
|
||||||
|
lockup: LockupRaw;
|
||||||
|
}>;
|
||||||
|
Merge: IInstructionInputData;
|
||||||
|
Split: IInstructionInputData &
|
||||||
|
Readonly<{
|
||||||
|
lamports: number;
|
||||||
|
}>;
|
||||||
|
Withdraw: IInstructionInputData &
|
||||||
|
Readonly<{
|
||||||
|
lamports: number;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An enumeration of valid stake InstructionType's
|
* An enumeration of valid stake InstructionType's
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export const STAKE_INSTRUCTION_LAYOUTS: {
|
export const STAKE_INSTRUCTION_LAYOUTS = Object.freeze<{
|
||||||
[type in StakeInstructionType]: InstructionType;
|
[Instruction in StakeInstructionType]: InstructionType<
|
||||||
} = Object.freeze({
|
StakeInstructionInputData[Instruction]
|
||||||
|
>;
|
||||||
|
}>({
|
||||||
Initialize: {
|
Initialize: {
|
||||||
index: 0,
|
index: 0,
|
||||||
layout: BufferLayout.struct([
|
layout: BufferLayout.struct<StakeInstructionInputData['Initialize']>([
|
||||||
BufferLayout.u32('instruction'),
|
BufferLayout.u32('instruction'),
|
||||||
Layout.authorized(),
|
Layout.authorized(),
|
||||||
Layout.lockup(),
|
Layout.lockup(),
|
||||||
@ -455,7 +509,7 @@ export const STAKE_INSTRUCTION_LAYOUTS: {
|
|||||||
},
|
},
|
||||||
Authorize: {
|
Authorize: {
|
||||||
index: 1,
|
index: 1,
|
||||||
layout: BufferLayout.struct([
|
layout: BufferLayout.struct<StakeInstructionInputData['Authorize']>([
|
||||||
BufferLayout.u32('instruction'),
|
BufferLayout.u32('instruction'),
|
||||||
Layout.publicKey('newAuthorized'),
|
Layout.publicKey('newAuthorized'),
|
||||||
BufferLayout.u32('stakeAuthorizationType'),
|
BufferLayout.u32('stakeAuthorizationType'),
|
||||||
@ -463,39 +517,47 @@ export const STAKE_INSTRUCTION_LAYOUTS: {
|
|||||||
},
|
},
|
||||||
Delegate: {
|
Delegate: {
|
||||||
index: 2,
|
index: 2,
|
||||||
layout: BufferLayout.struct([BufferLayout.u32('instruction')]),
|
layout: BufferLayout.struct<StakeInstructionInputData['Delegate']>([
|
||||||
|
BufferLayout.u32('instruction'),
|
||||||
|
]),
|
||||||
},
|
},
|
||||||
Split: {
|
Split: {
|
||||||
index: 3,
|
index: 3,
|
||||||
layout: BufferLayout.struct([
|
layout: BufferLayout.struct<StakeInstructionInputData['Split']>([
|
||||||
BufferLayout.u32('instruction'),
|
BufferLayout.u32('instruction'),
|
||||||
BufferLayout.ns64('lamports'),
|
BufferLayout.ns64('lamports'),
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
Withdraw: {
|
Withdraw: {
|
||||||
index: 4,
|
index: 4,
|
||||||
layout: BufferLayout.struct([
|
layout: BufferLayout.struct<StakeInstructionInputData['Withdraw']>([
|
||||||
BufferLayout.u32('instruction'),
|
BufferLayout.u32('instruction'),
|
||||||
BufferLayout.ns64('lamports'),
|
BufferLayout.ns64('lamports'),
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
Deactivate: {
|
Deactivate: {
|
||||||
index: 5,
|
index: 5,
|
||||||
layout: BufferLayout.struct([BufferLayout.u32('instruction')]),
|
layout: BufferLayout.struct<StakeInstructionInputData['Deactivate']>([
|
||||||
|
BufferLayout.u32('instruction'),
|
||||||
|
]),
|
||||||
},
|
},
|
||||||
Merge: {
|
Merge: {
|
||||||
index: 7,
|
index: 7,
|
||||||
layout: BufferLayout.struct([BufferLayout.u32('instruction')]),
|
layout: BufferLayout.struct<StakeInstructionInputData['Merge']>([
|
||||||
|
BufferLayout.u32('instruction'),
|
||||||
|
]),
|
||||||
},
|
},
|
||||||
AuthorizeWithSeed: {
|
AuthorizeWithSeed: {
|
||||||
index: 8,
|
index: 8,
|
||||||
layout: BufferLayout.struct([
|
layout: BufferLayout.struct<StakeInstructionInputData['AuthorizeWithSeed']>(
|
||||||
BufferLayout.u32('instruction'),
|
[
|
||||||
Layout.publicKey('newAuthorized'),
|
BufferLayout.u32('instruction'),
|
||||||
BufferLayout.u32('stakeAuthorizationType'),
|
Layout.publicKey('newAuthorized'),
|
||||||
Layout.rustString('authoritySeed'),
|
BufferLayout.u32('stakeAuthorizationType'),
|
||||||
Layout.publicKey('authorityOwner'),
|
Layout.rustString('authoritySeed'),
|
||||||
]),
|
Layout.publicKey('authorityOwner'),
|
||||||
|
],
|
||||||
|
),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user