Skip to content

Commit

Permalink
feat: set testnet2 chain id, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Dec 2, 2022
1 parent 1af5a3f commit 16cdfd4
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/provider/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ import { Block, BlockIdentifier } from './utils';

type NetworkName = 'mainnet-alpha' | 'goerli-alpha' | 'goerli-alpha-2';

function isEmptyQueryObject(obj?: Record<any, any>): obj is undefined {
return (
obj === undefined ||
Object.keys(obj).length === 0 ||
(Object.keys(obj).length === 1 &&
Object.entries(obj).every(([k, v]) => k === 'blockIdentifier' && v === null))
);
}

export type SequencerProviderOptions =
| { network: NetworkName }
| {
Expand All @@ -64,6 +55,19 @@ export type SequencerProviderOptions =
headers?: object;
};

function isEmptyQueryObject(obj?: Record<any, any>): obj is undefined {
return (
obj === undefined ||
Object.keys(obj).length === 0 ||
(Object.keys(obj).length === 1 &&
Object.entries(obj).every(([k, v]) => k === 'blockIdentifier' && v === null))
);
}

const defaultOptions: SequencerProviderOptions = {
network: 'goerli-alpha-2',
};

export class SequencerProvider implements ProviderInterface {
public baseUrl: string;

Expand All @@ -77,7 +81,7 @@ export class SequencerProvider implements ProviderInterface {

private responseParser = new SequencerAPIResponseParser();

constructor(optionsOrProvider: SequencerProviderOptions = { network: 'goerli-alpha-2' }) {
constructor(optionsOrProvider: SequencerProviderOptions = defaultOptions) {
if ('network' in optionsOrProvider) {
this.baseUrl = SequencerProvider.getNetworkFromName(optionsOrProvider.network);
this.chainId = SequencerProvider.getChainIdFromBaseUrl(this.baseUrl);
Expand Down Expand Up @@ -119,6 +123,9 @@ export class SequencerProvider implements ProviderInterface {
if (url.host.includes('mainnet.starknet.io')) {
return StarknetChainId.MAINNET;
}
if (url.host.includes('alpha4-2.starknet.io')) {
return StarknetChainId.TESTNET2;
}
} catch {
// eslint-disable-next-line no-console
console.error(`Could not parse baseUrl: ${baseUrl}`);
Expand Down

0 comments on commit 16cdfd4

Please sign in to comment.