From b2d30d6655b4575b1969937139c4cefe1b8c4808 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Mon, 9 Mar 2020 10:48:50 +0800 Subject: [PATCH] fix: update TS SystemInstruction API and add missing flow method --- web3.js/module.d.ts | 49 ++------- web3.js/module.flow.js | 243 +++++++++++++++++++++-------------------- 2 files changed, 131 insertions(+), 161 deletions(-) diff --git a/web3.js/module.d.ts b/web3.js/module.d.ts index a043601ed0..8b524f1307 100644 --- a/web3.js/module.d.ts +++ b/web3.js/module.d.ts @@ -544,49 +544,16 @@ declare module '@solana/web3.js' { export class SystemProgram { static programId: PublicKey; - static createAccount( - from: PublicKey, - newAccount: PublicKey, - lamports: number, - space: number, - programId: PublicKey, - ): Transaction; - static transfer( - from: PublicKey, - to: PublicKey, - amount: number, - ): Transaction; - static assign(from: PublicKey, programId: PublicKey): Transaction; + static createAccount(params: CreateAccountParams): Transaction; + static transfer(params: TransferParams): Transaction; + static assign(params: AssignParams): Transaction; static createAccountWithSeed( - from: PublicKey, - newAccount: PublicKey, - base: PublicKey, - seed: string, - lamports: number, - space: number, - programId: PublicKey, - ): Transaction; - static createNonceAccount( - from: PublicKey, - nonceAccount: PublicKey, - authorizedPubkey: PublicKey, - lamports: number, - ): Transaction; - static nonceAdvance( - nonceAccount: PublicKey, - authorizedPubkey: PublicKey, - ): TransactionInstruction; - static nonceWithdraw( - nonceAccount: PublicKey, - authorizedPubkey: PublicKey, - to: PublicKey, - lamports: number, - ): Transaction; - static nonceAuthorize( - nonceAccount: PublicKey, - authorizedPubkey: PublicKey, - newAuthorized: PublicKey, + params: CreateAccountWithSeedParams, ): Transaction; + static createNonceAccount(params: CreateNonceAccountParams): Transaction; + static nonceAdvance(params: AdvanceNonceParams): TransactionInstruction; + static nonceWithdraw(params: WithdrawNonceParams): Transaction; + static nonceAuthorize(params: AuthorizeNonceParams): Transaction; } export type SystemInstructionType = diff --git a/web3.js/module.flow.js b/web3.js/module.flow.js index c2b7a8de52..06cec220c0 100644 --- a/web3.js/module.flow.js +++ b/web3.js/module.flow.js @@ -251,6 +251,126 @@ declare module '@solana/web3.js' { feeCalculator: FeeCalculator; } + // === src/validator-info.js === + declare export var VALIDATOR_INFO_KEY; + declare export type Info = {| + name: string, + website?: string, + details?: string, + keybaseUsername?: string, + |}; + + declare export class ValidatorInfo { + key: PublicKey; + info: Info; + + constructor(key: PublicKey, info: Info): ValidatorInfo; + static fromConfigData( + buffer: Buffer | Uint8Array | Array, + ): ValidatorInfo | null; + } + + // === src/sysvar.js === + declare export var SYSVAR_CLOCK_PUBKEY; + declare export var SYSVAR_RENT_PUBKEY; + declare export var SYSVAR_REWARDS_PUBKEY; + declare export var SYSVAR_STAKE_HISTORY_PUBKEY; + + // === src/vote-account.js === + declare export var VOTE_PROGRAM_ID; + declare export type Lockout = {| + slot: number, + confirmationCount: number, + |}; + + declare export type EpochCredits = {| + epoch: number, + credits: number, + prevCredits: number, + |}; + + declare export class VoteAccount { + votes: Array; + nodePubkey: PublicKey; + authorizedVoterPubkey: PublicKey; + commission: number; + rootSlot: number | null; + epoch: number; + credits: number; + lastEpochCredits: number; + epochCredits: Array; + static fromAccountData( + buffer: Buffer | Uint8Array | Array, + ): VoteAccount; + } + + // === src/instruction.js === + declare export type InstructionType = {| + index: number, + layout: typeof BufferLayout, + |}; + + declare export function encodeData( + type: InstructionType, + fields: Object, + ): Buffer; + + // === src/transaction.js === + declare export type TransactionSignature = string; + + declare type TransactionInstructionCtorFields = {| + keys: ?Array<{pubkey: PublicKey, isSigner: boolean, isWritable: boolean}>, + programId?: PublicKey, + data?: Buffer, + |}; + + declare export class TransactionInstruction { + keys: Array<{pubkey: PublicKey, isSigner: boolean, isWritable: boolean}>; + programId: PublicKey; + data: Buffer; + + constructor( + opts?: TransactionInstructionCtorFields, + ): TransactionInstruction; + } + + declare type SignaturePubkeyPair = {| + signature: Buffer | null, + publicKey: PublicKey, + |}; + + declare type NonceInformation = {| + nonce: Blockhash, + nonceInstruction: TransactionInstruction, + |}; + + declare type TransactionCtorFields = {| + recentBlockhash?: Blockhash, + nonceInfo?: NonceInformation, + signatures?: Array, + |}; + + declare export class Transaction { + signatures: Array; + signature: ?Buffer; + instructions: Array; + recentBlockhash: ?Blockhash; + nonceInfo: ?NonceInformation; + + constructor(opts?: TransactionCtorFields): Transaction; + static from(buffer: Buffer | Uint8Array | Array): Transaction; + add( + ...items: Array< + Transaction | TransactionInstruction | TransactionInstructionCtorFields, + > + ): Transaction; + sign(...signers: Array): void; + signPartial(...partialSigners: Array): void; + addSigner(signer: Account): void; + verifySignatures(): boolean; + serialize(): Buffer; + } + // === src/stake-program.js === declare export type StakeAuthorizationType = {| index: number, @@ -467,6 +587,9 @@ declare module '@solana/web3.js' { }; declare export class SystemInstruction { + static decodeInstructionType( + instruction: TransactionInstruction, + ): SystemInstructionType; static decodeCreateAccount( instruction: TransactionInstruction, ): CreateAccountParams; @@ -489,126 +612,6 @@ declare module '@solana/web3.js' { ): AuthorizeNonceParams; } - // === src/validator-info.js === - declare export var VALIDATOR_INFO_KEY; - declare export type Info = {| - name: string, - website?: string, - details?: string, - keybaseUsername?: string, - |}; - - declare export class ValidatorInfo { - key: PublicKey; - info: Info; - - constructor(key: PublicKey, info: Info): ValidatorInfo; - static fromConfigData( - buffer: Buffer | Uint8Array | Array, - ): ValidatorInfo | null; - } - - // === src/sysvar.js === - declare export var SYSVAR_CLOCK_PUBKEY; - declare export var SYSVAR_RENT_PUBKEY; - declare export var SYSVAR_REWARDS_PUBKEY; - declare export var SYSVAR_STAKE_HISTORY_PUBKEY; - - // === src/vote-account.js === - declare export var VOTE_PROGRAM_ID; - declare export type Lockout = {| - slot: number, - confirmationCount: number, - |}; - - declare export type EpochCredits = {| - epoch: number, - credits: number, - prevCredits: number, - |}; - - declare export class VoteAccount { - votes: Array; - nodePubkey: PublicKey; - authorizedVoterPubkey: PublicKey; - commission: number; - rootSlot: number | null; - epoch: number; - credits: number; - lastEpochCredits: number; - epochCredits: Array; - static fromAccountData( - buffer: Buffer | Uint8Array | Array, - ): VoteAccount; - } - - // === src/instruction.js === - declare export type InstructionType = {| - index: number, - layout: typeof BufferLayout, - |}; - - declare export function encodeData( - type: InstructionType, - fields: Object, - ): Buffer; - - // === src/transaction.js === - declare export type TransactionSignature = string; - - declare type TransactionInstructionCtorFields = {| - keys: ?Array<{pubkey: PublicKey, isSigner: boolean, isWritable: boolean}>, - programId?: PublicKey, - data?: Buffer, - |}; - - declare export class TransactionInstruction { - keys: Array<{pubkey: PublicKey, isSigner: boolean, isWritable: boolean}>; - programId: PublicKey; - data: Buffer; - - constructor( - opts?: TransactionInstructionCtorFields, - ): TransactionInstruction; - } - - declare type SignaturePubkeyPair = {| - signature: Buffer | null, - publicKey: PublicKey, - |}; - - declare type NonceInformation = {| - nonce: Blockhash, - nonceInstruction: TransactionInstruction, - |}; - - declare type TransactionCtorFields = {| - recentBlockhash?: Blockhash, - nonceInfo?: NonceInformation, - signatures?: Array, - |}; - - declare export class Transaction { - signatures: Array; - signature: ?Buffer; - instructions: Array; - recentBlockhash: ?Blockhash; - nonceInfo: ?NonceInformation; - - constructor(opts?: TransactionCtorFields): Transaction; - static from(buffer: Buffer | Uint8Array | Array): Transaction; - add( - ...items: Array< - Transaction | TransactionInstruction | TransactionInstructionCtorFields, - > - ): Transaction; - sign(...signers: Array): void; - signPartial(...partialSigners: Array): void; - addSigner(signer: Account): void; - verifySignatures(): boolean; - serialize(): Buffer; - } - // === src/loader.js === declare export class Loader { static getMinNumSignatures(dataLength: number): number;