Skip to content

Commit

Permalink
fix(RpcChannel): allow client to provide specVersion
Browse files Browse the repository at this point in the history
this saves an extra call on RPC for optionally-known information (like the `chainId` case).
also fixed speck -> spec typo
  • Loading branch information
avimak committed Feb 29, 2024
1 parent d56be0c commit ae8cf8e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/channel/rpc_0_6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ export class RpcChannel {

private chainId?: StarknetChainId;

private speckVersion?: string;
private specVersion?: string;

readonly waitMode: Boolean; // behave like web2 rpc and return when tx is processed

constructor(optionsOrProvider?: RpcProviderOptions) {
const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } =
const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode } =
optionsOrProvider || {};
if (Object.values(NetworkName).includes(nodeUrl as NetworkName)) {
this.nodeUrl = getDefaultNodeUrl(nodeUrl as NetworkName, optionsOrProvider?.default);
Expand All @@ -66,6 +66,7 @@ export class RpcChannel {
this.headers = { ...defaultOptions.headers, ...headers };
this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
this.chainId = chainId;
this.specVersion = specVersion;
this.waitMode = waitMode || false;
this.requestId = 0;
}
Expand Down Expand Up @@ -121,8 +122,8 @@ export class RpcChannel {
}

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

public getNonceForAddress(
Expand Down
1 change: 1 addition & 0 deletions src/types/provider/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type RpcProviderOptions = {
headers?: object;
blockIdentifier?: BlockIdentifier;
chainId?: StarknetChainId;
specVersion?: string;
default?: boolean;
waitMode?: boolean;
};

0 comments on commit ae8cf8e

Please sign in to comment.