feat: add API for decoding stake instructions

This commit is contained in:
Justin Starry
2020-03-02 23:58:10 +08:00
committed by Michael Vines
parent 01e65d2070
commit aba7e14f3a
6 changed files with 660 additions and 426 deletions

134
web3.js/module.d.ts vendored
View File

@ -369,52 +369,74 @@ declare module '@solana/web3.js' {
constructor(unixTimestamp: number, epoch: number, custodian: PublicKey);
}
export type CreateStakeAccountParams = {
fromPubkey: PublicKey;
stakePubkey: PublicKey;
authorized: Authorized;
lockup: Lockup;
lamports: number;
};
export type CreateStakeAccountWithSeedParams = {
fromPubkey: PublicKey;
stakePubkey: PublicKey;
basePubkey: PublicKey;
seed: string;
authorized: Authorized;
lockup: Lockup;
lamports: number;
};
export type InitializeStakeParams = {
stakePubkey: PublicKey;
authorized: Authorized;
lockup: Lockup;
};
export type DelegateStakeParams = {
stakePubkey: PublicKey;
authorizedPubkey: PublicKey;
votePubkey: PublicKey;
};
export type AuthorizeStakeParams = {
stakePubkey: PublicKey;
authorizedPubkey: PublicKey;
newAuthorizedPubkey: PublicKey;
stakeAuthorizationType: StakeAuthorizationType;
};
export type SplitStakeParams = {
stakePubkey: PublicKey;
authorizedPubkey: PublicKey;
splitStakePubkey: PublicKey;
lamports: number;
};
export type WithdrawStakeParams = {
stakePubkey: PublicKey;
authorizedPubkey: PublicKey;
toPubkey: PublicKey;
lamports: number;
};
export type DeactivateStakeParams = {
stakePubkey: PublicKey;
authorizedPubkey: PublicKey;
};
export class StakeProgram {
static programId: PublicKey;
static space: number;
static createAccount(
from: PublicKey,
stakeAccount: PublicKey,
authorized: Authorized,
lockup: Lockup,
lamports: number,
): Transaction;
static createAccount(params: CreateStakeAccountParams): Transaction;
static createAccountWithSeed(
from: PublicKey,
stakeAccount: PublicKey,
seed: string,
authorized: Authorized,
lockup: Lockup,
lamports: number,
): Transaction;
static delegate(
stakeAccount: PublicKey,
authorizedPubkey: PublicKey,
votePubkey: PublicKey,
): Transaction;
static authorize(
stakeAccount: PublicKey,
authorizedPubkey: PublicKey,
newAuthorized: PublicKey,
stakeAuthorizationType: StakeAuthorizationType,
): Transaction;
static split(
stakeAccount: PublicKey,
authorizedPubkey: PublicKey,
lamports: number,
splitStakePubkey: PublicKey,
): Transaction;
static withdraw(
stakeAccount: PublicKey,
withdrawerPubkey: PublicKey,
to: PublicKey,
lamports: number,
): Transaction;
static deactivate(
stakeAccount: PublicKey,
authorizedPubkey: PublicKey,
params: CreateStakeAccountWithSeedParams,
): Transaction;
static delegate(params: DelegateStakeParams): Transaction;
static authorize(params: AuthorizeStakeParams): Transaction;
static split(params: SplitStakeParams): Transaction;
static withdraw(params: WithdrawStakeParams): Transaction;
static deactivate(params: DeactivateStakeParams): Transaction;
}
export type StakeInstructionType =
@ -429,16 +451,26 @@ declare module '@solana/web3.js' {
[type in StakeInstructionType]: InstructionType;
};
export class StakeInstruction extends TransactionInstruction {
type: StakeInstructionType;
stakePublicKey: PublicKey | null;
authorizedPublicKey: PublicKey | null;
constructor(
opts: TransactionInstructionCtorFields,
type: StakeInstructionType,
);
static from(instruction: TransactionInstruction): StakeInstruction;
export class StakeInstruction {
static decodeInstructionType(
instruction: TransactionInstruction,
): StakeInstructionType;
static decodeInitialize(
instruction: TransactionInstruction,
): InitializeStakeParams;
static decodeDelegate(
instruction: TransactionInstruction,
): DelegateStakeParams;
static decodeAuthorize(
instruction: TransactionInstruction,
): AuthorizeStakeParams;
static decodeSplit(instruction: TransactionInstruction): SplitStakeParams;
static decodeWithdraw(
instruction: TransactionInstruction,
): WithdrawStakeParams;
static decodeDeactivate(
instruction: TransactionInstruction,
): DeactivateStakeParams;
}
// === src/system-program.js ===