Skip to content

Commit

Permalink
feat: create the ChainId type
Browse files Browse the repository at this point in the history
  • Loading branch information
BenFaruna committed Sep 12, 2024
1 parent b4198bd commit 000f6fb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
11 changes: 6 additions & 5 deletions src/channel/rpc_0_6.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkName, StarknetChainId } from '../constants';
import { NetworkName } from '../constants';
import { LibraryError } from '../provider/errors';
import {
AccountInvocationItem,
Expand All @@ -7,6 +7,7 @@ import {
BlockIdentifier,
BlockTag,
Call,
ChainId,
DeclareContractTransaction,
DeployAccountContractTransaction,
Invocation,
Expand Down Expand Up @@ -47,7 +48,7 @@ export class RpcChannel {

readonly blockIdentifier: BlockIdentifier;

private chainId?: StarknetChainId;
private chainId?: ChainId;

private specVersion?: string;

Expand Down Expand Up @@ -82,7 +83,7 @@ export class RpcChannel {
}
}

public setChainId(chainId: StarknetChainId) {
public setChainId(chainId: ChainId) {
this.chainId = chainId;
}

Expand Down Expand Up @@ -142,12 +143,12 @@ export class RpcChannel {
}

public async getChainId() {
this.chainId ??= (await this.fetchEndpoint('starknet_chainId')) as StarknetChainId;
this.chainId ??= (await this.fetchEndpoint('starknet_chainId')) as ChainId;
return this.chainId;
}

public async getSpecVersion() {
this.specVersion ??= (await this.fetchEndpoint('starknet_specVersion')) as StarknetChainId;
this.specVersion ??= (await this.fetchEndpoint('starknet_specVersion')) as ChainId;
return this.specVersion;
}

Expand Down
11 changes: 6 additions & 5 deletions src/channel/rpc_0_7.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkName, StarknetChainId } from '../constants';
import { NetworkName } from '../constants';
import { LibraryError } from '../provider/errors';
import {
AccountInvocationItem,
Expand All @@ -7,6 +7,7 @@ import {
BlockIdentifier,
BlockTag,
Call,
ChainId,
DeclareContractTransaction,
DeployAccountContractTransaction,
Invocation,
Expand Down Expand Up @@ -47,7 +48,7 @@ export class RpcChannel {

readonly blockIdentifier: BlockIdentifier;

private chainId?: StarknetChainId;
private chainId?: ChainId;

private specVersion?: string;

Expand Down Expand Up @@ -98,7 +99,7 @@ export class RpcChannel {
return this.transactionRetryIntervalFallback ?? 5000;
}

public setChainId(chainId: StarknetChainId) {
public setChainId(chainId: ChainId) {
this.chainId = chainId;
}

Expand Down Expand Up @@ -158,12 +159,12 @@ export class RpcChannel {
}

public async getChainId() {
this.chainId ??= (await this.fetchEndpoint('starknet_chainId')) as StarknetChainId;
this.chainId ??= (await this.fetchEndpoint('starknet_chainId')) as ChainId;
return this.chainId;
}

public async getSpecVersion() {
this.specVersion ??= (await this.fetchEndpoint('starknet_specVersion')) as StarknetChainId;
this.specVersion ??= (await this.fetchEndpoint('starknet_specVersion')) as ChainId;
return this.specVersion;
}

Expand Down
6 changes: 4 additions & 2 deletions src/types/provider/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkName, StarknetChainId } from '../../constants';
import { NetworkName } from '../../constants';
import { BlockIdentifier } from '../lib';

export interface ProviderOptions extends RpcProviderOptions {}
Expand All @@ -9,7 +9,7 @@ export type RpcProviderOptions = {
transactionRetryIntervalFallback?: number;
headers?: object;
blockIdentifier?: BlockIdentifier;
chainId?: StarknetChainId;
chainId?: ChainId;
specVersion?: string;
default?: boolean;
waitMode?: boolean;
Expand All @@ -20,3 +20,5 @@ export type RpcProviderOptions = {
};
batch?: false | number;
};

export type ChainId = `0x${string}`;

0 comments on commit 000f6fb

Please sign in to comment.