fix: remove buggy node polyfill plugin (#18531)
* fix: remove buggy node polyfill plugin * fix websocket test * remove assert dependency
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import assert from 'assert';
|
||||
import bs58 from 'bs58';
|
||||
import {Buffer} from 'buffer';
|
||||
import {parse as urlParse} from 'url';
|
||||
import fetch, {Response} from 'node-fetch';
|
||||
import {
|
||||
type as pick,
|
||||
@@ -34,6 +32,7 @@ import {Signer} from './keypair';
|
||||
import {MS_PER_SLOT} from './timing';
|
||||
import {Transaction} from './transaction';
|
||||
import {Message} from './message';
|
||||
import assert from './util/assert';
|
||||
import {sleep} from './util/sleep';
|
||||
import {promiseTimeout} from './util/promise-timeout';
|
||||
import {toBuffer} from './util/to-buffer';
|
||||
@@ -2025,7 +2024,7 @@ export class Connection {
|
||||
endpoint: string,
|
||||
commitmentOrConfig?: Commitment | ConnectionConfig,
|
||||
) {
|
||||
let url = urlParse(endpoint);
|
||||
let url = new URL(endpoint);
|
||||
const useHttps = url.protocol === 'https:';
|
||||
|
||||
let wsEndpoint;
|
||||
@@ -2046,7 +2045,7 @@ export class Connection {
|
||||
this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
|
||||
|
||||
this._rpcClient = createRpcClient(
|
||||
url.href,
|
||||
url.toString(),
|
||||
useHttps,
|
||||
httpHeaders,
|
||||
fetchMiddleware,
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import {Buffer} from 'buffer';
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
import secp256k1 from 'secp256k1';
|
||||
import assert from 'assert';
|
||||
import {keccak_256} from 'js-sha3';
|
||||
|
||||
import {PublicKey} from './publickey';
|
||||
import {TransactionInstruction} from './transaction';
|
||||
import assert from './util/assert';
|
||||
import {toBuffer} from './util/to-buffer';
|
||||
|
||||
const {publicKeyCreate, ecdsaSign} = secp256k1;
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import invariant from 'assert';
|
||||
import nacl from 'tweetnacl';
|
||||
import bs58 from 'bs58';
|
||||
import {Buffer} from 'buffer';
|
||||
@@ -7,6 +6,7 @@ import {Message} from './message';
|
||||
import {PublicKey} from './publickey';
|
||||
import * as shortvec from './util/shortvec-encoding';
|
||||
import {toBuffer} from './util/to-buffer';
|
||||
import invariant from './util/assert';
|
||||
import type {Signer} from './keypair';
|
||||
import type {Blockhash} from './blockhash';
|
||||
import type {CompiledInstruction} from './message';
|
||||
|
8
web3.js/src/util/assert.ts
Normal file
8
web3.js/src/util/assert.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export default function (
|
||||
condition: unknown,
|
||||
message?: string,
|
||||
): asserts condition {
|
||||
if (!condition) {
|
||||
throw new Error(message || 'Assertion failed');
|
||||
}
|
||||
}
|
@@ -1,7 +1,5 @@
|
||||
import {format as urlFormat, parse as urlParse} from 'url';
|
||||
|
||||
export function makeWebsocketUrl(endpoint: string) {
|
||||
let url = urlParse(endpoint);
|
||||
let url = new URL(endpoint);
|
||||
const useHttps = url.protocol === 'https:';
|
||||
|
||||
url.protocol = useHttps ? 'wss:' : 'ws:';
|
||||
@@ -13,8 +11,8 @@ export function makeWebsocketUrl(endpoint: string) {
|
||||
// When the endpoint omits the port, we're connecting to the protocol
|
||||
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
|
||||
// proxy which manages WebSocket upgrade and backend port redirection.
|
||||
if (url.port !== null) {
|
||||
if (url.port !== '') {
|
||||
url.port = String(Number(url.port) + 1);
|
||||
}
|
||||
return urlFormat(url);
|
||||
return url.toString();
|
||||
}
|
||||
|
Reference in New Issue
Block a user