From c4208726865b0a29bcfcdf12c9f64b2e508ceb6c Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Fri, 22 Dec 2023 15:52:49 +0100 Subject: [PATCH 01/12] fix: wip temp commit, extracting types to provider and rest --- __tests__/config/jestGlobalSetup.ts | 10 ++++---- __tests__/rpcProvider.test.ts | 9 ++++--- src/account/default.ts | 6 +++-- src/channel/rpc_0_6.ts | 22 +++++++++++----- src/constants.ts | 22 +++++++++++----- src/provider/rpc.ts | 4 +-- src/types/account.ts | 5 ---- src/types/api/index.ts | 5 ++++ src/types/api/rpcspec_0_6/nonspec.ts | 3 +++ src/types/index.ts | 2 ++ src/types/lib/index.ts | 38 +++++++++++++++++----------- src/types/provider/configuration.ts | 2 ++ src/types/provider/response.ts | 2 +- src/utils/provider.ts | 28 +++++++++++--------- 14 files changed, 98 insertions(+), 60 deletions(-) diff --git a/__tests__/config/jestGlobalSetup.ts b/__tests__/config/jestGlobalSetup.ts index 0b052f5fa..6df6049f0 100644 --- a/__tests__/config/jestGlobalSetup.ts +++ b/__tests__/config/jestGlobalSetup.ts @@ -6,6 +6,7 @@ */ import { BaseUrl } from '../../src/constants'; +import { getDefaultNodeUrl } from '../../src/utils/provider'; type DevnetStrategy = { isDevnet: boolean; @@ -155,11 +156,10 @@ const verifySetup = (final?: boolean) => { if (final) throw new Error('TEST_ACCOUNT_PRIVATE_KEY env is not provided'); else warnings.push('TEST_ACCOUNT_PRIVATE_KEY env is not provided!'); } - // TODO: revise after Sequencer removal - // if (!process.env.TEST_RPC_URL) { - // process.env.TEST_RPC_URL = getDefaultNodeUrl(); - // console.warn('TEST_RPC_URL env is not provided'); - // } + + if (!process.env.TEST_RPC_URL) { + process.env.TEST_RPC_URL = getDefaultNodeUrl(); + } if (warnings.length > 0) { console.log('\x1b[33m', warnings.join('\n'), '\x1b[0m'); diff --git a/__tests__/rpcProvider.test.ts b/__tests__/rpcProvider.test.ts index 3da84184c..8f607e49e 100644 --- a/__tests__/rpcProvider.test.ts +++ b/__tests__/rpcProvider.test.ts @@ -5,8 +5,9 @@ import { Block, CallData, Contract, + ETransactionExecutionStatus, + ETransactionStatus, RPC, - TransactionExecutionStatus, stark, waitForTransactionOptions, } from '../src'; @@ -112,8 +113,8 @@ describeIfRpc('RPCProvider', () => { const generateOptions = (o: waitForTransactionOptions) => ({ retryInterval: 10, ...o }); const generateTransactionStatus = ( - finality_status: RPC.SPEC.TXN_STATUS, - execution_status?: RPC.SPEC.TXN_EXECUTION_STATUS + finality_status: `${ETransactionStatus}`, + execution_status?: `${ETransactionExecutionStatus}` ): RPC.TransactionStatus => ({ finality_status, execution_status, @@ -153,7 +154,7 @@ describeIfRpc('RPCProvider', () => { test('reverted - as error state', async () => { transactionStatusSpy.mockResolvedValueOnce(response.reverted); - const options = generateOptions({ errorStates: [TransactionExecutionStatus.REVERTED] }); + const options = generateOptions({ errorStates: [ETransactionExecutionStatus.REVERTED] }); await expect(rpcProvider.waitForTransaction(0, options)).rejects.toThrow( `${RPC.ETransactionExecutionStatus.REVERTED}: ${RPC.ETransactionStatus.ACCEPTED_ON_L2}` ); diff --git a/src/account/default.ts b/src/account/default.ts index 743671d28..eba2080c7 100644 --- a/src/account/default.ts +++ b/src/account/default.ts @@ -1,4 +1,4 @@ -import { UDC, ZERO } from '../constants'; +import { DEFAULT_TRANSACTION_VERSION, UDC, ZERO } from '../constants'; import { Provider, ProviderInterface } from '../provider'; import { Signer, SignerInterface } from '../signer'; import { @@ -73,7 +73,9 @@ export class Account extends Provider implements AccountInterface { address: string, pkOrSigner: Uint8Array | string | SignerInterface, cairoVersion?: CairoVersion, - transactionVersion: ETransactionVersion.V2 | ETransactionVersion.V3 = ETransactionVersion.V2 // TODO: Discuss this, set to v2 for backward compatibility + transactionVersion: + | ETransactionVersion.V2 + | ETransactionVersion.V3 = DEFAULT_TRANSACTION_VERSION ) { super(providerOrOptions); this.address = address.toLowerCase(); diff --git a/src/channel/rpc_0_6.ts b/src/channel/rpc_0_6.ts index c533c9ef8..8f3da4c17 100644 --- a/src/channel/rpc_0_6.ts +++ b/src/channel/rpc_0_6.ts @@ -5,10 +5,10 @@ import { AccountInvocations, BigNumberish, BlockIdentifier, - BlockTag, Call, DeclareContractTransaction, DeployAccountContractTransaction, + EBlockTag, Invocation, InvocationsDetailsWithNonce, RPC, @@ -18,7 +18,7 @@ import { getSimulateTransactionOptions, waitForTransactionOptions, } from '../types'; -import { ETransactionVersion } from '../types/api'; +import { ERPCVersion, ETransactionVersion } from '../types/api'; import { CallData } from '../utils/calldata'; import { isSierra } from '../utils/contract'; import fetch from '../utils/fetchPonyfill'; @@ -31,7 +31,7 @@ import { getVersionsByType } from '../utils/transaction'; const defaultOptions = { headers: { 'Content-Type': 'application/json' }, - blockIdentifier: BlockTag.pending, + blockIdentifier: EBlockTag.PENDING, retries: 200, }; @@ -54,11 +54,19 @@ export class RpcChannel { const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } = optionsOrProvider || {}; if (Object.values(NetworkName).includes(nodeUrl as NetworkName)) { - this.nodeUrl = getDefaultNodeUrl(nodeUrl as NetworkName, optionsOrProvider?.default); + this.nodeUrl = getDefaultNodeUrl( + nodeUrl as NetworkName, + optionsOrProvider?.rpcVersion, + optionsOrProvider?.default + ); } else if (nodeUrl) { this.nodeUrl = nodeUrl; } else { - this.nodeUrl = getDefaultNodeUrl(undefined, optionsOrProvider?.default); + this.nodeUrl = getDefaultNodeUrl( + undefined, + optionsOrProvider?.rpcVersion, + optionsOrProvider?.default + ); } this.retries = retries || defaultOptions.retries; this.headers = { ...defaultOptions.headers, ...headers }; @@ -118,7 +126,7 @@ export class RpcChannel { } public async getSpecVersion() { - this.speckVersion ??= (await this.fetchEndpoint('starknet_specVersion')) as StarknetChainId; + this.speckVersion ??= await this.fetchEndpoint('starknet_specVersion'); return this.speckVersion; } @@ -371,7 +379,7 @@ export class RpcChannel { ) { const block_id = new Block(blockIdentifier).identifier; let flags = {}; - if (isVersion('0.6', await this.getSpecVersion())) { + if (isVersion(ERPCVersion.V0_6, await this.getSpecVersion())) { flags = { simulation_flags: skipValidate ? [RPC.ESimulationFlag.SKIP_VALIDATE] : [], }; diff --git a/src/constants.ts b/src/constants.ts index df86dc97c..a287f82ab 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -53,19 +53,27 @@ export const UDC = { ENTRYPOINT: 'deployContract', }; -export const RPC_DEFAULT_VERSION = 'v0_6'; +export const DEFAULT_TRANSACTION_VERSION = ETransactionVersion.V2; // TODO: Discuss this, set to v2 for backward compatibility +export const DEFAULT_NETWORK_NAME = NetworkName.SN_GOERLI; // TODO: when goerli deprecated switch default to sepolia +export const RPC_DEFAULT_VERSION_TAG = 'v0_6'; export const RPC_NODES = { SN_GOERLI: [ - `https://starknet-testnet.public.blastapi.io/rpc/${RPC_DEFAULT_VERSION}`, - `https://free-rpc.nethermind.io/goerli-juno/${RPC_DEFAULT_VERSION}`, + `https://starknet-testnet.public.blastapi.io/rpc/${RPC_DEFAULT_VERSION_TAG}`, + `https://free-rpc.nethermind.io/goerli-juno/${RPC_DEFAULT_VERSION_TAG}`, ], SN_MAIN: [ - `https://starknet-mainnet.public.blastapi.io/rpc/${RPC_DEFAULT_VERSION}`, - `https://free-rpc.nethermind.io/mainnet-juno/${RPC_DEFAULT_VERSION}`, + `https://starknet-mainnet.public.blastapi.io/rpc/${RPC_DEFAULT_VERSION_TAG}`, + `https://free-rpc.nethermind.io/mainnet-juno/${RPC_DEFAULT_VERSION_TAG}`, ], SN_SEPOLIA: [ - `https://starknet-sepolia.public.blastapi.io/rpc/${RPC_DEFAULT_VERSION}`, - `https://free-rpc.nethermind.io/sepolia-juno/${RPC_DEFAULT_VERSION}`, + `https://starknet-sepolia.public.blastapi.io/rpc/${RPC_DEFAULT_VERSION_TAG}`, + `https://free-rpc.nethermind.io/sepolia-juno/${RPC_DEFAULT_VERSION_TAG}`, ], + getNode(network: NetworkName, index: number, rpcVersion?: string) { + const defRpcUrl = this[network][index]; + return rpcVersion + ? `${defRpcUrl.substring(0, defRpcUrl.lastIndexOf('/') + 1)}v${rpcVersion.replace('.', '_')}` + : defRpcUrl; + }, }; diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index f71ee8f48..a8b08f7f6 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -4,11 +4,11 @@ import { BigNumberish, Block, BlockIdentifier, - BlockTag, Call, ContractVersion, DeclareContractTransaction, DeployAccountContractTransaction, + EBlockTag, GetBlockResponse, Invocation, InvocationsDetailsWithNonce, @@ -119,7 +119,7 @@ export class RpcProvider implements ProviderInterface { * Utility method, same result can be achieved using getBlockWithTxHashes(BlockTag.pending); */ public async getPendingTransactions() { - const { transactions } = await this.getBlockWithTxHashes(BlockTag.pending).then( + const { transactions } = await this.getBlockWithTxHashes(EBlockTag.PENDING).then( this.responseParser.parseGetBlockResponse ); return Promise.all(transactions.map((it: any) => this.getTransactionByHash(it))); diff --git a/src/types/account.ts b/src/types/account.ts index a54a56247..c83573e23 100644 --- a/src/types/account.ts +++ b/src/types/account.ts @@ -75,11 +75,6 @@ export type SimulateTransactionDetails = { skipExecute?: boolean; } & Partial; -export enum SIMULATION_FLAG { - SKIP_VALIDATE = 'SKIP_VALIDATE', - SKIP_EXECUTE = 'SKIP_EXECUTE', -} - export type EstimateFeeAction = | { type: TransactionType.INVOKE; diff --git a/src/types/api/index.ts b/src/types/api/index.ts index 9fd21dd55..c0ccee567 100644 --- a/src/types/api/index.ts +++ b/src/types/api/index.ts @@ -1,2 +1,7 @@ export * as JRPC from './jsonrpc'; export * from './rpcspec_0_6'; + +export enum ERPCVersion { + V0_5 = '0.5', + V0_6 = '0.6', +} diff --git a/src/types/api/rpcspec_0_6/nonspec.ts b/src/types/api/rpcspec_0_6/nonspec.ts index f3453b43b..ec25ba158 100644 --- a/src/types/api/rpcspec_0_6/nonspec.ts +++ b/src/types/api/rpcspec_0_6/nonspec.ts @@ -120,6 +120,7 @@ export enum ESimulationFlag { SKIP_FEE_CHARGE = 'SKIP_FEE_CHARGE', } +// TXN_STATUS export enum ETransactionStatus { RECEIVED = 'RECEIVED', REJECTED = 'REJECTED', @@ -131,6 +132,8 @@ export enum ETransactionFinalityStatus { ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2', ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1', } + +// TXN_EXECUTION_STATUS export enum ETransactionExecutionStatus { SUCCEEDED = 'SUCCEEDED', REVERTED = 'REVERTED', diff --git a/src/types/index.ts b/src/types/index.ts index a096ffccc..cda84b6cc 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,5 +6,7 @@ export * from './provider'; export * from './signer'; export * from './typedData'; export * from './cairoEnum'; +export * from './api/forward'; export * as RPC from './api'; +// export * from './api'; diff --git a/src/types/lib/index.ts b/src/types/lib/index.ts index 2b85b9a9a..b6affa0a8 100644 --- a/src/types/lib/index.ts +++ b/src/types/lib/index.ts @@ -1,6 +1,12 @@ import { StarknetChainId } from '../../constants'; import { weierstrass } from '../../utils/ec'; -import { EDataAvailabilityMode, ResourceBounds } from '../api'; +import { + EBlockTag, + EDataAvailabilityMode, + ETransactionExecutionStatus, + ETransactionFinalityStatus, + ResourceBounds, +} from '../api'; import { CairoEnum } from '../cairoEnum'; import { CompiledContract, CompiledSierraCasm, ContractClass } from './contract'; @@ -149,52 +155,54 @@ export enum TransactionType { INVOKE = 'INVOKE_FUNCTION', } +// TODO: All this should be removed + /** * new statuses are defined by props: finality_status and execution_status * to be #deprecated */ -export enum TransactionStatus { +/* export enum TransactionStatus { NOT_RECEIVED = 'NOT_RECEIVED', RECEIVED = 'RECEIVED', ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2', ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1', REJECTED = 'REJECTED', REVERTED = 'REVERTED', -} +} */ -export enum TransactionFinalityStatus { +/* export enum TransactionFinalityStatus { NOT_RECEIVED = 'NOT_RECEIVED', RECEIVED = 'RECEIVED', ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2', ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1', -} +} */ -export enum TransactionExecutionStatus { +/* export enum TransactionExecutionStatus { REJECTED = 'REJECTED', REVERTED = 'REVERTED', SUCCEEDED = 'SUCCEEDED', -} +} */ -export enum BlockStatus { +/* export enum BlockStatus { PENDING = 'PENDING', ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1', ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2', REJECTED = 'REJECTED', -} +} */ -export enum BlockTag { +/* export enum BlockTag { pending = 'pending', latest = 'latest', -} +} */ -export type BlockNumber = BlockTag | null | number; +export type BlockNumber = number; /** * hex string and BN are detected as block hashes * decimal string and number are detected as block numbers * null appends nothing to the request url */ -export type BlockIdentifier = BlockNumber | BigNumberish; +export type BlockIdentifier = BlockNumber | BigNumberish | EBlockTag | null; /** * items used by AccountInvocations @@ -234,8 +242,8 @@ export type ParsedStruct = { export type waitForTransactionOptions = { retryInterval?: number; - successStates?: Array; - errorStates?: Array; + successStates?: Array; + errorStates?: Array; }; export type getSimulateTransactionOptions = { diff --git a/src/types/provider/configuration.ts b/src/types/provider/configuration.ts index b4d614f6d..5374564bc 100644 --- a/src/types/provider/configuration.ts +++ b/src/types/provider/configuration.ts @@ -1,4 +1,5 @@ import { NetworkName, StarknetChainId } from '../../constants'; +import { ERPCVersion } from '../api'; import { BlockIdentifier } from '../lib'; export interface ProviderOptions extends RpcProviderOptions {} @@ -11,4 +12,5 @@ export type RpcProviderOptions = { chainId?: StarknetChainId; default?: boolean; waitMode?: boolean; + rpcVersion?: ERPCVersion; }; diff --git a/src/types/provider/response.ts b/src/types/provider/response.ts index 2ff3eded7..ff110364e 100644 --- a/src/types/provider/response.ts +++ b/src/types/provider/response.ts @@ -70,7 +70,7 @@ export type Storage = RPC.Felt; export type Nonce = string; -export type SimulationFlags = RPC.SimulationFlags; +// export type SimulationFlags = RPC.SimulationFlags; export type SimulatedTransaction = RPC.SimulateTransaction & { suggestedMaxFee: bigint; diff --git a/src/utils/provider.ts b/src/utils/provider.ts index 7e5f52ec3..c997ea15b 100644 --- a/src/utils/provider.ts +++ b/src/utils/provider.ts @@ -1,11 +1,12 @@ -import { NetworkName, RPC_NODES } from '../constants'; +/* eslint-disable no-console */ +import { DEFAULT_NETWORK_NAME, NetworkName, RPC_NODES } from '../constants'; import { BigNumberish, BlockIdentifier, - BlockTag, CompiledContract, CompiledSierra, ContractClass, + EBlockTag, GetBlockResponse, GetTransactionReceiptResponse, InvocationsDetailsWithNonce, @@ -17,7 +18,7 @@ import { StateUpdateResponse, V3TransactionDetails, } from '../types'; -import { ETransactionVersion } from '../types/api'; +import { ERPCVersion, ETransactionVersion } from '../types/api'; import { isSierra } from './contract'; import { formatSpaces } from './hash'; import { parse, stringify } from './json'; @@ -72,13 +73,16 @@ export function parseContract(contract: CompiledContract | string): ContractClas * @param mute mute public node warning * @returns default node url */ -export const getDefaultNodeUrl = (networkName?: NetworkName, mute: boolean = false): string => { +export const getDefaultNodeUrl = ( + networkName?: NetworkName, + rpcVersion?: ERPCVersion, + mute: boolean = false +): string => { if (!mute) - // eslint-disable-next-line no-console console.warn('Using default public node url, please provide nodeUrl in provider options!'); - const nodes = RPC_NODES[networkName ?? NetworkName.SN_GOERLI]; // TODO: when goerli deprecated switch default to sepolia - const randIdx = Math.floor(Math.random() * nodes.length); - return nodes[randIdx]; + const network = networkName ?? DEFAULT_NETWORK_NAME; + const randIdx = Math.floor(Math.random() * RPC_NODES[network].length); + return RPC_NODES.getNode(network, randIdx, rpcVersion); }; /** @@ -101,7 +105,7 @@ export function txIdentifier(txHash?: BigNumberish, txId?: BigNumberish): string return `transactionHash=${hashString}`; } -export const validBlockTags = Object.values(BlockTag); +export const validBlockTags = Object.values(EBlockTag); export class Block { hash: BlockIdentifier = null; @@ -119,12 +123,12 @@ export class Block { this.number = __identifier; } else if ( typeof __identifier === 'string' && - validBlockTags.includes(__identifier as BlockTag) + validBlockTags.includes(__identifier as EBlockTag) ) { this.tag = __identifier; } else { // default - this.tag = BlockTag.pending; + this.tag = EBlockTag.PENDING; } } @@ -178,7 +182,7 @@ export function isV3Tx(details: InvocationsDetailsWithNonce): details is V3Trans return version === ETransactionVersion.V3 || version === ETransactionVersion.F3; } -export function isVersion(version: '0.5' | '0.6', response: string) { +export function isVersion(version: string, response: string) { const [majorS, minorS] = version.split('.'); const [majorR, minorR] = response.split('.'); From 24941b32d526610c652aa1df81c513e5611459fb Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Fri, 22 Dec 2023 15:53:20 +0100 Subject: [PATCH 02/12] chore: leftover --- src/types/api/forward.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/types/api/forward.ts diff --git a/src/types/api/forward.ts b/src/types/api/forward.ts new file mode 100644 index 000000000..ea8eed4f1 --- /dev/null +++ b/src/types/api/forward.ts @@ -0,0 +1,30 @@ +/* eslint-disable prefer-destructuring */ +/* + * Forward important RPC types into the top namespace + */ + +import { + EBlockTag as _EBlockTag, + EDAMode as _EDAMode, + EDataAvailabilityMode as _EDataAvailabilityMode, + ESimulationFlag as _ESimulationFlag, + ETransactionExecutionStatus as _ETransactionExecutionStatus, + ETransactionFinalityStatus as _ETransactionFinalityStatus, + ETransactionStatus as _ETransactionStatus, + ETransactionType as _ETransactionType, + ETransactionVersion as _ETransactionVersion, + ETransactionVersion2 as _ETransactionVersion2, + ETransactionVersion3 as _ETransactionVersion3, +} from '.'; + +export { _ETransactionStatus as ETransactionStatus }; +export { _ESimulationFlag as ESimulationFlag }; +export { _ETransactionType as ETransactionType }; +export { _ETransactionFinalityStatus as ETransactionFinalityStatus }; +export { _ETransactionExecutionStatus as ETransactionExecutionStatus }; +export { _EBlockTag as EBlockTag }; +export { _EDataAvailabilityMode as EDataAvailabilityMode }; +export { _EDAMode as EDAMode }; +export { _ETransactionVersion as ETransactionVersion }; +export { _ETransactionVersion2 as ETransactionVersion2 }; +export { _ETransactionVersion3 as ETransactionVersion3 }; From 7a54fa29ddff348c04cb2160f35643b39429bc30 Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Thu, 11 Jan 2024 12:54:07 +0100 Subject: [PATCH 03/12] chore: ignore scripts --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3a5a151fb..b7d03563f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ dist node_modules npm-debug.log package -yarn.lock \ No newline at end of file +yarn.lock +__tests__/scripts \ No newline at end of file From 2347018cfd4d8e1ac67dfae8fa47f374bbb54daa Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Fri, 12 Jan 2024 16:24:02 +0100 Subject: [PATCH 04/12] chore: vip --- src/provider/rpc.ts | 3 ++- src/types/provider/response.ts | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index a8b08f7f6..b38352c62 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -3,6 +3,7 @@ import { AccountInvocations, BigNumberish, Block, + BlockHashAndNumber, BlockIdentifier, Call, ContractVersion, @@ -74,7 +75,7 @@ export class RpcProvider implements ProviderInterface { /** * Get the most recent accepted block hash and number */ - public async getBlockLatestAccepted() { + public async getBlockLatestAccepted(): Promise { return this.channel.getBlockLatestAccepted(); } diff --git a/src/types/provider/response.ts b/src/types/provider/response.ts index ff110364e..fcf226b99 100644 --- a/src/types/provider/response.ts +++ b/src/types/provider/response.ts @@ -1,6 +1,7 @@ /** - * Common interface response - * Intersection (sequencer response ∩ (∪ rpc responses)) + * Provider interface responses + * DEV NOTE: For stability ensure this types do not change with minor versions + * aka. when rpc spec change update parser so this types can stay the same */ import * as RPC from '../api'; @@ -92,3 +93,12 @@ export type PendingStateUpdate = RPC.SPEC.PENDING_STATE_UPDATE; export type ContractClassResponse = | LegacyContractClass | Omit; + +/* RE-Export from RPC */ + +export type BlockHashAndNumber = { + block_hash: string; + block_number: number; +}; + +export type BlockWithTxHashes = RPC.BlockWithTxHashes; From 5c282827878d4f2d3dd0c11c48fc337c8fd17dd6 Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Mon, 12 Feb 2024 11:30:40 +0100 Subject: [PATCH 05/12] feat: custom rpcprovider without channel, speckVersion setup, tests fix --- .gitignore | 2 +- __tests__/config/jestGlobalSetup.ts | 2 +- src/channel/rpc_0_6.ts | 7 ++++--- src/provider/interface.ts | 2 +- src/provider/rpc.ts | 6 +++++- src/types/index.ts | 1 + 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index b7d03563f..33b6c5da3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ node_modules npm-debug.log package yarn.lock -__tests__/scripts \ No newline at end of file +__tests__/scripts diff --git a/__tests__/config/jestGlobalSetup.ts b/__tests__/config/jestGlobalSetup.ts index 6df6049f0..c5f37fdb2 100644 --- a/__tests__/config/jestGlobalSetup.ts +++ b/__tests__/config/jestGlobalSetup.ts @@ -157,7 +157,7 @@ const verifySetup = (final?: boolean) => { else warnings.push('TEST_ACCOUNT_PRIVATE_KEY env is not provided!'); } - if (!process.env.TEST_RPC_URL) { + if (!process.env.TEST_RPC_URL && final) { process.env.TEST_RPC_URL = getDefaultNodeUrl(); } diff --git a/src/channel/rpc_0_6.ts b/src/channel/rpc_0_6.ts index d9cf636f7..641e2dde9 100644 --- a/src/channel/rpc_0_6.ts +++ b/src/channel/rpc_0_6.ts @@ -12,7 +12,7 @@ import { Invocation, InvocationsDetailsWithNonce, RPC, - RpcProviderOptions, + RpcChannelOptions, TransactionType, getEstimateFeeBulkOptions, getSimulateTransactionOptions, @@ -52,8 +52,8 @@ export class RpcChannel { readonly waitMode: Boolean; // behave like web2 rpc and return when tx is processed - constructor(optionsOrProvider?: RpcProviderOptions) { - const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } = + constructor(optionsOrProvider?: RpcChannelOptions) { + const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode, speckVersion } = optionsOrProvider || {}; if (Object.values(NetworkName).includes(nodeUrl as NetworkName)) { this.nodeUrl = getDefaultNodeUrl( @@ -76,6 +76,7 @@ export class RpcChannel { this.chainId = chainId; this.waitMode = waitMode || false; this.requestId = 0; + this.speckVersion = speckVersion; } public fetch(method: string, params?: object, id: string | number = 0) { diff --git a/src/provider/interface.ts b/src/provider/interface.ts index e046fe7c3..8bbadab86 100644 --- a/src/provider/interface.ts +++ b/src/provider/interface.ts @@ -34,7 +34,7 @@ import type { } from '../types'; export abstract class ProviderInterface { - public abstract channel: RpcChannel; + public abstract channel: RpcChannel | undefined; /** * Gets the Starknet chain Id diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index b38352c62..9b362061d 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -36,7 +36,11 @@ export class RpcProvider implements ProviderInterface { public channel: RpcChannel; constructor(optionsOrProvider?: RpcProviderOptions | ProviderInterface | RpcProvider) { - if (optionsOrProvider && 'channel' in optionsOrProvider) { + if ( + optionsOrProvider && + 'channel' in optionsOrProvider && + optionsOrProvider.channel !== undefined + ) { this.channel = optionsOrProvider.channel; } else { this.channel = new RpcChannel({ ...optionsOrProvider, waitMode: false }); diff --git a/src/types/index.ts b/src/types/index.ts index cda84b6cc..3d454217e 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -3,6 +3,7 @@ export * from './calldata'; export * from './contract'; export * from './lib'; export * from './provider'; +export * from './channel'; export * from './signer'; export * from './typedData'; export * from './cairoEnum'; From 68cb801d699ce7632211c5e1781d381013ac39c5 Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Mon, 12 Feb 2024 11:34:24 +0100 Subject: [PATCH 06/12] chore: channel constructor props --- src/types/channel/index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/types/channel/index.ts diff --git a/src/types/channel/index.ts b/src/types/channel/index.ts new file mode 100644 index 000000000..7b5f88419 --- /dev/null +++ b/src/types/channel/index.ts @@ -0,0 +1,15 @@ +import { NetworkName, StarknetChainId } from '../../constants'; +import { ERPCVersion } from '../api'; +import { BlockIdentifier } from '../lib'; + +export type RpcChannelOptions = { + nodeUrl?: string | NetworkName; + retries?: number; + headers?: object; + blockIdentifier?: BlockIdentifier; + chainId?: StarknetChainId; + default?: boolean; + waitMode?: boolean; + rpcVersion?: ERPCVersion; + speckVersion?: string; +}; From 399197709bcde40a909a02a2f09325812fe4862b Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Tue, 13 Feb 2024 11:35:34 +0100 Subject: [PATCH 07/12] feat: use existing rpc provider instance for Account --- src/provider/rpc.ts | 9 ++++++++- src/types/provider/configuration.ts | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index 9b362061d..ec18cd9ae 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -36,7 +36,14 @@ export class RpcProvider implements ProviderInterface { public channel: RpcChannel; constructor(optionsOrProvider?: RpcProviderOptions | ProviderInterface | RpcProvider) { - if ( + if (optionsOrProvider && 'onInstance' in optionsOrProvider && optionsOrProvider.onInstance) { + // stop ts complains + // @ts-expect-error + this.channel = null; + // use provided instance + Object.setPrototypeOf(this, Object.getPrototypeOf(optionsOrProvider)); + Object.assign(this, optionsOrProvider); + } else if ( optionsOrProvider && 'channel' in optionsOrProvider && optionsOrProvider.channel !== undefined diff --git a/src/types/provider/configuration.ts b/src/types/provider/configuration.ts index 5374564bc..57f30ff85 100644 --- a/src/types/provider/configuration.ts +++ b/src/types/provider/configuration.ts @@ -13,4 +13,5 @@ export type RpcProviderOptions = { default?: boolean; waitMode?: boolean; rpcVersion?: ERPCVersion; + speckVersion?: string; }; From 480620191bd23eb427a4f29e080b7e65406e80ea Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Tue, 13 Feb 2024 14:30:13 +0100 Subject: [PATCH 08/12] feat: new AccountInstance for creating Account from provider instance --- src/account/default.ts | 5 +++-- src/index.ts | 1 + src/provider/rpc.ts | 7 +++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/account/default.ts b/src/account/default.ts index a12d66df7..b8a5db556 100644 --- a/src/account/default.ts +++ b/src/account/default.ts @@ -75,9 +75,10 @@ export class Account extends Provider implements AccountInterface { cairoVersion?: CairoVersion, transactionVersion: | ETransactionVersion.V2 - | ETransactionVersion.V3 = DEFAULT_TRANSACTION_VERSION + | ETransactionVersion.V3 = DEFAULT_TRANSACTION_VERSION, + instance?: boolean ) { - super(providerOrOptions); + super(providerOrOptions, instance); this.address = address.toLowerCase(); this.signer = typeof pkOrSigner === 'string' || pkOrSigner instanceof Uint8Array diff --git a/src/index.ts b/src/index.ts index ec85e525d..858e7248c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ export * from './contract'; export * from './provider'; export * from './signer'; export * from './channel'; +export * from './account/instance'; // TODO: decide on final export style export * from './types'; diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index ec18cd9ae..5313d3dca 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -35,8 +35,11 @@ export class RpcProvider implements ProviderInterface { public channel: RpcChannel; - constructor(optionsOrProvider?: RpcProviderOptions | ProviderInterface | RpcProvider) { - if (optionsOrProvider && 'onInstance' in optionsOrProvider && optionsOrProvider.onInstance) { + constructor( + optionsOrProvider?: RpcProviderOptions | ProviderInterface | RpcProvider, + instance?: boolean + ) { + if (optionsOrProvider && instance) { // stop ts complains // @ts-expect-error this.channel = null; From aa56f1f090b0162dcc9bf288f2b67b921e6130cf Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Tue, 13 Feb 2024 14:31:22 +0100 Subject: [PATCH 09/12] chore: forgoten files --- __tests__/accountInstance.test.ts | 28 ++++++++++++++++++++++++++++ src/account/instance.ts | 19 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 __tests__/accountInstance.test.ts create mode 100644 src/account/instance.ts diff --git a/__tests__/accountInstance.test.ts b/__tests__/accountInstance.test.ts new file mode 100644 index 000000000..fe1aa29c0 --- /dev/null +++ b/__tests__/accountInstance.test.ts @@ -0,0 +1,28 @@ +import { Account, AccountInstance, BigNumberish, LibraryError, RpcProvider } from '../src'; + +describe('Account instantiated from provider instance', () => { + const rpc = new RpcProvider(); + + const customNonce = async function (contractAddress: BigNumberish) { + return `my custom implementation of get nonce for address ${contractAddress}`; + }; + rpc.getNonceForAddress = customNonce; + + test('Account to throw on extended custom methods for using re-instantiation on provider', () => { + const acc = new Account(rpc, '0x0', '0x1'); + + return expect(acc.getNonceForAddress('0x0')).rejects.toThrow(LibraryError); + }); + + test('AccountInstance to pass on extending', async () => { + const acc = new AccountInstance(rpc, '0x0', '0x1'); + const result = await acc.getNonceForAddress('0x0'); + expect(result).toBe('my custom implementation of get nonce for address 0x0'); + }); + + test('Account to pass on extended custom methods for using instance on provider', async () => { + const acc = new Account(rpc, '0x0', '0x1', undefined, undefined, true); + const result = await acc.getNonceForAddress('0x0'); + expect(result).toBe('my custom implementation of get nonce for address 0x0'); + }); +}); diff --git a/src/account/instance.ts b/src/account/instance.ts new file mode 100644 index 000000000..6dd1ebe67 --- /dev/null +++ b/src/account/instance.ts @@ -0,0 +1,19 @@ +import { DEFAULT_TRANSACTION_VERSION } from '../constants'; +import { ProviderInterface } from '../provider/interface'; +import { SignerInterface } from '../signer/interface'; +import { CairoVersion, ETransactionVersion, ProviderOptions } from '../types'; +import { Account } from '.'; + +export class AccountInstance extends Account { + constructor( + providerOrOptions: ProviderOptions | ProviderInterface, + address: string, + pkOrSigner: Uint8Array | string | SignerInterface, + cairoVersion?: CairoVersion, + transactionVersion: + | ETransactionVersion.V2 + | ETransactionVersion.V3 = DEFAULT_TRANSACTION_VERSION + ) { + super(providerOrOptions, address, pkOrSigner, cairoVersion, transactionVersion, true); + } +} From 83011bed44857d9161e055d1d6d411d8e7532b92 Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Fri, 1 Mar 2024 16:38:45 -0700 Subject: [PATCH 10/12] Update __tests__/accountInstance.test.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Petar Penović --- __tests__/accountInstance.test.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/__tests__/accountInstance.test.ts b/__tests__/accountInstance.test.ts index fe1aa29c0..2e23b5945 100644 --- a/__tests__/accountInstance.test.ts +++ b/__tests__/accountInstance.test.ts @@ -2,11 +2,8 @@ import { Account, AccountInstance, BigNumberish, LibraryError, RpcProvider } fro describe('Account instantiated from provider instance', () => { const rpc = new RpcProvider(); - - const customNonce = async function (contractAddress: BigNumberish) { - return `my custom implementation of get nonce for address ${contractAddress}`; - }; - rpc.getNonceForAddress = customNonce; + const getNonceMock = jest.fn().mockResolvedValue('mock'); + rpc.getNonceForAddress = getNonceMock; test('Account to throw on extended custom methods for using re-instantiation on provider', () => { const acc = new Account(rpc, '0x0', '0x1'); @@ -16,13 +13,13 @@ describe('Account instantiated from provider instance', () => { test('AccountInstance to pass on extending', async () => { const acc = new AccountInstance(rpc, '0x0', '0x1'); - const result = await acc.getNonceForAddress('0x0'); - expect(result).toBe('my custom implementation of get nonce for address 0x0'); + expect(await acc.getNonceForAddress('0x1')).toBe('mock'); + expect(getNonceMock).toHaveBeenLastCalledWith('0x1'); }); test('Account to pass on extended custom methods for using instance on provider', async () => { const acc = new Account(rpc, '0x0', '0x1', undefined, undefined, true); - const result = await acc.getNonceForAddress('0x0'); - expect(result).toBe('my custom implementation of get nonce for address 0x0'); + expect(await acc.getNonceForAddress('0x2')).toBe('mock'); + expect(getNonceMock).toHaveBeenLastCalledWith('0x2'); }); }); From 2e6e087384d37be8cda950a2237c4074e966659f Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Fri, 1 Mar 2024 16:58:14 -0700 Subject: [PATCH 11/12] chore: cleanup --- __tests__/accountInstance.test.ts | 2 +- src/channel/rpc_0_6.ts | 10 ++++---- src/provider/interface.ts | 2 +- src/provider/rpc.ts | 3 +-- src/types/channel/index.ts | 2 +- src/types/index.ts | 1 - src/types/lib/index.ts | 40 ----------------------------- src/types/provider/configuration.ts | 2 +- src/types/provider/response.ts | 2 -- 9 files changed, 10 insertions(+), 54 deletions(-) diff --git a/__tests__/accountInstance.test.ts b/__tests__/accountInstance.test.ts index 2e23b5945..86d43ea9d 100644 --- a/__tests__/accountInstance.test.ts +++ b/__tests__/accountInstance.test.ts @@ -1,4 +1,4 @@ -import { Account, AccountInstance, BigNumberish, LibraryError, RpcProvider } from '../src'; +import { Account, AccountInstance, LibraryError, RpcProvider } from '../src'; describe('Account instantiated from provider instance', () => { const rpc = new RpcProvider(); diff --git a/src/channel/rpc_0_6.ts b/src/channel/rpc_0_6.ts index 641e2dde9..14443684b 100644 --- a/src/channel/rpc_0_6.ts +++ b/src/channel/rpc_0_6.ts @@ -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?: RpcChannelOptions) { - const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode, speckVersion } = + const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode, specVersion } = optionsOrProvider || {}; if (Object.values(NetworkName).includes(nodeUrl as NetworkName)) { this.nodeUrl = getDefaultNodeUrl( @@ -76,7 +76,7 @@ export class RpcChannel { this.chainId = chainId; this.waitMode = waitMode || false; this.requestId = 0; - this.speckVersion = speckVersion; + this.specVersion = specVersion; } public fetch(method: string, params?: object, id: string | number = 0) { @@ -130,8 +130,8 @@ export class RpcChannel { } public async getSpecVersion() { - this.speckVersion ??= await this.fetchEndpoint('starknet_specVersion'); - return this.speckVersion; + this.specVersion ??= await this.fetchEndpoint('starknet_specVersion'); + return this.specVersion; } public getNonceForAddress( diff --git a/src/provider/interface.ts b/src/provider/interface.ts index 8bbadab86..e046fe7c3 100644 --- a/src/provider/interface.ts +++ b/src/provider/interface.ts @@ -34,7 +34,7 @@ import type { } from '../types'; export abstract class ProviderInterface { - public abstract channel: RpcChannel | undefined; + public abstract channel: RpcChannel; /** * Gets the Starknet chain Id diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index 5313d3dca..543374485 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -41,8 +41,7 @@ export class RpcProvider implements ProviderInterface { ) { if (optionsOrProvider && instance) { // stop ts complains - // @ts-expect-error - this.channel = null; + this.channel = null as any; // use provided instance Object.setPrototypeOf(this, Object.getPrototypeOf(optionsOrProvider)); Object.assign(this, optionsOrProvider); diff --git a/src/types/channel/index.ts b/src/types/channel/index.ts index 7b5f88419..07b2b3a25 100644 --- a/src/types/channel/index.ts +++ b/src/types/channel/index.ts @@ -11,5 +11,5 @@ export type RpcChannelOptions = { default?: boolean; waitMode?: boolean; rpcVersion?: ERPCVersion; - speckVersion?: string; + specVersion?: string; }; diff --git a/src/types/index.ts b/src/types/index.ts index 3d454217e..50e9d0fda 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -10,4 +10,3 @@ export * from './cairoEnum'; export * from './api/forward'; export * as RPC from './api'; -// export * from './api'; diff --git a/src/types/lib/index.ts b/src/types/lib/index.ts index 1c8d30809..eb6a45931 100644 --- a/src/types/lib/index.ts +++ b/src/types/lib/index.ts @@ -161,46 +161,6 @@ export enum TransactionType { INVOKE = 'INVOKE_FUNCTION', } -// TODO: All this should be removed - -/** - * new statuses are defined by props: finality_status and execution_status - * to be #deprecated - */ -/* export enum TransactionStatus { - NOT_RECEIVED = 'NOT_RECEIVED', - RECEIVED = 'RECEIVED', - ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2', - ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1', - REJECTED = 'REJECTED', - REVERTED = 'REVERTED', -} */ - -/* export enum TransactionFinalityStatus { - NOT_RECEIVED = 'NOT_RECEIVED', - RECEIVED = 'RECEIVED', - ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2', - ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1', -} */ - -/* export enum TransactionExecutionStatus { - REJECTED = 'REJECTED', - REVERTED = 'REVERTED', - SUCCEEDED = 'SUCCEEDED', -} */ - -/* export enum BlockStatus { - PENDING = 'PENDING', - ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1', - ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2', - REJECTED = 'REJECTED', -} */ - -/* export enum BlockTag { - pending = 'pending', - latest = 'latest', -} */ - export type BlockNumber = number; /** diff --git a/src/types/provider/configuration.ts b/src/types/provider/configuration.ts index 57f30ff85..66bbea2a9 100644 --- a/src/types/provider/configuration.ts +++ b/src/types/provider/configuration.ts @@ -13,5 +13,5 @@ export type RpcProviderOptions = { default?: boolean; waitMode?: boolean; rpcVersion?: ERPCVersion; - speckVersion?: string; + specVersion?: string; }; diff --git a/src/types/provider/response.ts b/src/types/provider/response.ts index fcf226b99..bc90c9819 100644 --- a/src/types/provider/response.ts +++ b/src/types/provider/response.ts @@ -71,8 +71,6 @@ export type Storage = RPC.Felt; export type Nonce = string; -// export type SimulationFlags = RPC.SimulationFlags; - export type SimulatedTransaction = RPC.SimulateTransaction & { suggestedMaxFee: bigint; resourceBounds: RPC.ResourceBounds; From f0565364c3f0b14ac90622caaec4a1f16720c5a4 Mon Sep 17 00:00:00 2001 From: Toni Tabak Date: Mon, 25 Mar 2024 10:39:21 +0100 Subject: [PATCH 12/12] chore: post merge --- src/channel/rpc_0_6.ts | 1 - src/channel/rpc_0_7.ts | 29 +++++++++++++++++++---------- src/provider/rpc.ts | 11 ++++++----- src/types/provider/response.ts | 2 +- src/utils/responseParser/rpc.ts | 8 ++++---- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/channel/rpc_0_6.ts b/src/channel/rpc_0_6.ts index f59f805e0..df25c819a 100644 --- a/src/channel/rpc_0_6.ts +++ b/src/channel/rpc_0_6.ts @@ -73,7 +73,6 @@ 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; this.specVersion = specVersion; diff --git a/src/channel/rpc_0_7.ts b/src/channel/rpc_0_7.ts index 7e74e0fa5..b9712a819 100644 --- a/src/channel/rpc_0_7.ts +++ b/src/channel/rpc_0_7.ts @@ -5,13 +5,13 @@ import { AccountInvocations, BigNumberish, BlockIdentifier, - BlockTag, Call, DeclareContractTransaction, DeployAccountContractTransaction, + EBlockTag, Invocation, InvocationsDetailsWithNonce, - RpcProviderOptions, + RpcChannelOptions, TransactionType, getEstimateFeeBulkOptions, getSimulateTransactionOptions, @@ -30,7 +30,7 @@ import { getVersionsByType } from '../utils/transaction'; const defaultOptions = { headers: { 'Content-Type': 'application/json' }, - blockIdentifier: BlockTag.pending, + blockIdentifier: EBlockTag.PENDING, retries: 200, }; @@ -47,19 +47,27 @@ 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 } = + constructor(optionsOrProvider?: RpcChannelOptions) { + 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); + this.nodeUrl = getDefaultNodeUrl( + nodeUrl as NetworkName, + optionsOrProvider?.rpcVersion, + optionsOrProvider?.default + ); } else if (nodeUrl) { this.nodeUrl = nodeUrl; } else { - this.nodeUrl = getDefaultNodeUrl(undefined, optionsOrProvider?.default); + this.nodeUrl = getDefaultNodeUrl( + undefined, + optionsOrProvider?.rpcVersion, + optionsOrProvider?.default + ); } this.retries = retries || defaultOptions.retries; this.headers = { ...defaultOptions.headers, ...headers }; @@ -67,6 +75,7 @@ export class RpcChannel { this.chainId = chainId; this.waitMode = waitMode || false; this.requestId = 0; + this.specVersion = specVersion; } public setChainId(chainId: StarknetChainId) { @@ -124,8 +133,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( diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index 324a70ee5..e294d7792 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -1,6 +1,4 @@ -import { ProviderInterface } from './interface'; -import { LibraryError } from './errors'; -import { RpcChannel, RPC06, RPC07 } from '../channel'; +import { RPC06, RPC07, RpcChannel } from '../channel'; import { AccountInvocations, BigNumberish, @@ -30,9 +28,11 @@ import { import { getAbiContractVersion } from '../utils/calldata/cairo'; import { isSierra } from '../utils/contract'; import { RPCResponseParser } from '../utils/responseParser/rpc'; +import { LibraryError } from './errors'; +import { ProviderInterface } from './interface'; export class RpcProvider implements ProviderInterface { - private responseParser: RPCResponseParser; + private responseParser = new RPCResponseParser(); public channel: RPC07.RpcChannel | RPC06.RpcChannel; @@ -55,7 +55,8 @@ export class RpcProvider implements ProviderInterface { this.responseParser = (optionsOrProvider as any).responseParser; } else { this.channel = new RpcChannel({ ...optionsOrProvider, waitMode: false }); - this.responseParser = new RPCResponseParser(optionsOrProvider?.feeMarginPercentage); + // TODO: check this hotfix (optionsOrProvider as any)? why required ? + this.responseParser = new RPCResponseParser((optionsOrProvider as any)?.feeMarginPercentage); } } diff --git a/src/types/provider/response.ts b/src/types/provider/response.ts index 350d93020..33f70117c 100644 --- a/src/types/provider/response.ts +++ b/src/types/provider/response.ts @@ -32,7 +32,7 @@ import { TransactionWithHash, } from './spec'; -export { ContractClassPayload, FeeEstimate, TransactionReceipt } from './spec'; +export { BlockWithTxHashes, ContractClassPayload, FeeEstimate, TransactionReceipt } from './spec'; export type GetBlockResponse = PendingBlock | Block; diff --git a/src/utils/responseParser/rpc.ts b/src/utils/responseParser/rpc.ts index 9ae3ce45d..c50830156 100644 --- a/src/utils/responseParser/rpc.ts +++ b/src/utils/responseParser/rpc.ts @@ -6,20 +6,20 @@ import { BlockWithTxHashes, ContractClassPayload, ContractClassResponse, - TransactionReceipt, EstimateFeeResponse, EstimateFeeResponseBulk, + FeeEstimate, GetBlockResponse, GetTransactionReceiptResponse, - FeeEstimate, + RpcProviderOptions, SimulateTransactionResponse, SimulatedTransaction, - RpcProviderOptions, + TransactionReceipt, } from '../../types/provider'; import { toBigInt } from '../num'; +import { isString } from '../shortString'; import { estimateFeeToBounds, estimatedFeeToMaxFee } from '../stark'; import { ResponseParser } from '.'; -import { isString } from '../shortString'; export class RPCResponseParser implements