fix: update buffer-layout to fix downstream bundler issues (#18529)

* fix: update buffer-layout to fix downstream bundler issues

* chore: run check on generated type declaration
This commit is contained in:
Justin Starry
2021-07-08 20:01:11 -05:00
committed by GitHub
parent 6188283ba6
commit 4fb1c9da26
23 changed files with 141 additions and 1196 deletions

View File

@@ -1,5 +1,6 @@
import * as nacl from 'tweetnacl';
import type {SignKeyPair as KeyPair} from 'tweetnacl';
import type {Buffer} from 'buffer';
import {toBuffer} from './util/to-buffer';
import {PublicKey} from './publickey';

View File

@@ -1,3 +1,5 @@
import type {Buffer} from 'buffer';
import {PublicKey} from './publickey';
import {Loader} from './loader';
import type {Connection} from './connection';

View File

@@ -1 +0,0 @@
declare module 'buffer-layout';

View File

@@ -1,5 +1,4 @@
// @ts-ignore
import * as BufferLayout from 'buffer-layout';
import * as BufferLayout from '@solana/buffer-layout';
/**
* https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11

View File

@@ -1,5 +1,5 @@
import {Buffer} from 'buffer';
import * as BufferLayout from 'buffer-layout';
import * as BufferLayout from '@solana/buffer-layout';
import * as Layout from './layout';
@@ -10,7 +10,7 @@ export type InstructionType = {
/** The Instruction index (from solana upstream program) */
index: number;
/** The BufferLayout to use to build data */
layout: typeof BufferLayout;
layout: BufferLayout.Layout;
};
/**

View File

@@ -1,17 +1,19 @@
import {Buffer} from 'buffer';
import * as BufferLayout from 'buffer-layout';
import * as BufferLayout from '@solana/buffer-layout';
/**
* Layout for a public key
*/
export const publicKey = (property: string = 'publicKey'): Object => {
export const publicKey = (
property: string = 'publicKey',
): BufferLayout.Layout => {
return BufferLayout.blob(32, property);
};
/**
* Layout for a 64bit unsigned value
*/
export const uint64 = (property: string = 'uint64'): Object => {
export const uint64 = (property: string = 'uint64'): BufferLayout.Layout => {
return BufferLayout.blob(8, property);
};
@@ -32,7 +34,7 @@ export const rustString = (property: string = 'string') => {
rsl.decode = (buffer: any, offset: any) => {
const data = _decode(buffer, offset);
return data.chars.toString('utf8');
return data['chars'].toString('utf8');
};
rsl.encode = (str: any, buffer: any, offset: any) => {
@@ -42,7 +44,7 @@ export const rustString = (property: string = 'string') => {
return _encode(data, buffer, offset);
};
rsl.alloc = (str: any) => {
(rsl as any).alloc = (str: any) => {
return (
BufferLayout.u32().span +
BufferLayout.u32().span +

View File

@@ -1,5 +1,5 @@
import {Buffer} from 'buffer';
import * as BufferLayout from 'buffer-layout';
import * as BufferLayout from '@solana/buffer-layout';
import {PublicKey} from './publickey';
import {Transaction, PACKET_DATA_SIZE} from './transaction';

View File

@@ -1,6 +1,6 @@
import bs58 from 'bs58';
import {Buffer} from 'buffer';
import * as BufferLayout from 'buffer-layout';
import * as BufferLayout from '@solana/buffer-layout';
import {PublicKey} from './publickey';
import type {Blockhash} from './blockhash';

View File

@@ -1,4 +1,5 @@
import * as BufferLayout from 'buffer-layout';
import * as BufferLayout from '@solana/buffer-layout';
import {Buffer} from 'buffer';
import type {Blockhash} from './blockhash';
import * as Layout from './layout';

View File

@@ -1,8 +1,8 @@
import BN from 'bn.js';
import bs58 from 'bs58';
import {Buffer} from 'buffer';
import nacl from 'tweetnacl';
import {sha256} from 'crypto-hash';
import {Buffer} from 'buffer';
import {Struct, SOLANA_SCHEMA} from './util/borsh-schema';
import {toBuffer} from './util/to-buffer';

View File

@@ -1,5 +1,5 @@
import {Buffer} from 'buffer';
import * as BufferLayout from 'buffer-layout';
import * as BufferLayout from '@solana/buffer-layout';
import secp256k1 from 'secp256k1';
import assert from 'assert';
import {keccak_256} from 'js-sha3';

View File

@@ -1,4 +1,4 @@
import * as BufferLayout from 'buffer-layout';
import * as BufferLayout from '@solana/buffer-layout';
import {encodeData, decodeData, InstructionType} from './instruction';
import * as Layout from './layout';

View File

@@ -1,4 +1,4 @@
import * as BufferLayout from 'buffer-layout';
import * as BufferLayout from '@solana/buffer-layout';
import {encodeData, decodeData, InstructionType} from './instruction';
import * as Layout from './layout';

View File

@@ -1,3 +1,5 @@
import type {Buffer} from 'buffer';
import {Connection} from '../connection';
import type {TransactionSignature} from '../transaction';
import type {ConfirmOptions} from '../connection';

View File

@@ -1,7 +1,7 @@
import {Buffer} from 'buffer';
export const toBuffer = (arr: Buffer | Uint8Array | Array<number>): Buffer => {
if (arr instanceof Buffer) {
if (Buffer.isBuffer(arr)) {
return arr;
} else if (arr instanceof Uint8Array) {
return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);

View File

@@ -94,8 +94,8 @@ export class ValidatorInfo {
if (configKeys[0].publicKey.equals(VALIDATOR_INFO_KEY)) {
if (configKeys[1].isSigner) {
const rawInfo = Layout.rustString().decode(Buffer.from(byteArray));
const info = JSON.parse(rawInfo);
const rawInfo: any = Layout.rustString().decode(Buffer.from(byteArray));
const info = JSON.parse(rawInfo as string);
assertType(info, InfoString);
return new ValidatorInfo(configKeys[1].publicKey, info);
}

View File

@@ -1,4 +1,5 @@
import * as BufferLayout from 'buffer-layout';
import * as BufferLayout from '@solana/buffer-layout';
import type {Buffer} from 'buffer';
import * as Layout from './layout';
import {PublicKey} from './publickey';