fix: add type def for NonceAccount.fromAccountData

This commit is contained in:
Justin Starry 2020-05-13 22:44:41 +08:00 committed by Michael Vines
parent 02a278b3b2
commit a112d9cedf
3 changed files with 11 additions and 2 deletions

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

@ -285,6 +285,9 @@ declare module '@solana/web3.js' {
authorizedPubkey: PublicKey;
nonce: Blockhash;
feeCalculator: FeeCalculator;
static fromAccountData(
buffer: Buffer | Uint8Array | Array<number>,
): NonceAccount;
}
export const NONCE_ACCOUNT_LENGTH: number;

View File

@ -298,6 +298,9 @@ declare module '@solana/web3.js' {
authorizedPubkey: PublicKey;
nonce: Blockhash;
feeCalculator: FeeCalculator;
static fromAccountData(
buffer: Buffer | Uint8Array | Array<number>,
): NonceAccount;
}
declare export var NONCE_ACCOUNT_LENGTH: number;

View File

@ -6,6 +6,7 @@ import * as Layout from './layout';
import {PublicKey} from './publickey';
import type {FeeCalculator} from './fee-calculator';
import {FeeCalculatorLayout} from './fee-calculator';
import {toBuffer} from './util/to-buffer';
/**
* See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
@ -36,8 +37,10 @@ export class NonceAccount {
* @param buffer account data
* @return NonceAccount
*/
static fromAccountData(buffer: Buffer): NonceAccount {
const nonceAccount = NonceAccountLayout.decode(buffer, 0);
static fromAccountData(
buffer: Buffer | Uint8Array | Array<number>,
): NonceAccount {
const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
nonceAccount.authorizedPubkey = new PublicKey(
nonceAccount.authorizedPubkey,
);