From b7291e654732bd5f57b2d477b20a5467dfc9854b Mon Sep 17 00:00:00 2001 From: Antun Badurina Date: Wed, 13 Jul 2022 22:00:50 +0200 Subject: [PATCH] fix: rename gateway to sequencer --- __tests__/fixtures.ts | 2 +- ...ider.test.ts => sequencerProvider.test.ts} | 8 ++-- src/provider/default.ts | 6 +-- src/provider/index.ts | 2 +- src/provider/{gateway.ts => sequencer.ts} | 40 +++++++++---------- src/types/api/index.ts | 2 +- src/types/api/{gateway.ts => sequencer.ts} | 2 +- .../{gateway.ts => sequencer.ts} | 26 +++++++----- 8 files changed, 47 insertions(+), 41 deletions(-) rename __tests__/{gatewayProvider.test.ts => sequencerProvider.test.ts} (97%) rename src/provider/{gateway.ts => sequencer.ts} (89%) rename src/types/api/{gateway.ts => sequencer.ts} (99%) rename src/utils/responseParser/{gateway.ts => sequencer.ts} (78%) diff --git a/__tests__/fixtures.ts b/__tests__/fixtures.ts index 8bc3d76cb..19c35db64 100644 --- a/__tests__/fixtures.ts +++ b/__tests__/fixtures.ts @@ -21,7 +21,7 @@ const BASE_URL = process.env.TEST_PROVIDER_BASE_URL || DEFAULT_TEST_PROVIDER_BAS export const IS_DEVNET = !BASE_URL.includes('starknet.io'); export const getTestProvider = () => { - const provider = new Provider({ gateway: { baseUrl: BASE_URL } }); + const provider = new Provider({ sequencer: { baseUrl: BASE_URL } }); if (IS_DEVNET) { // accelerate the tests when running locally diff --git a/__tests__/gatewayProvider.test.ts b/__tests__/sequencerProvider.test.ts similarity index 97% rename from __tests__/gatewayProvider.test.ts rename to __tests__/sequencerProvider.test.ts index b38a1f68a..0e89e0350 100644 --- a/__tests__/gatewayProvider.test.ts +++ b/__tests__/sequencerProvider.test.ts @@ -1,12 +1,12 @@ -import { DeclareContractResponse, DeployContractResponse, GatewayProvider } from '../src'; +import { DeclareContractResponse, DeployContractResponse, SequencerProvider } from '../src'; import { compileCalldata } from '../src/utils/stark'; import { compiledErc20 } from './fixtures'; -describe('GatewayProvider', () => { - let provider: GatewayProvider; +describe('SequencerProvider', () => { + let provider: SequencerProvider; beforeAll(async () => { - provider = new GatewayProvider(); + provider = new SequencerProvider(); }); describe('Provider methods', () => { diff --git a/src/provider/default.ts b/src/provider/default.ts index f3b3f0241..4c19aa397 100644 --- a/src/provider/default.ts +++ b/src/provider/default.ts @@ -15,13 +15,13 @@ import { InvokeFunctionResponse, } from '../types'; import { BigNumberish } from '../utils/number'; -import { GatewayProvider, GatewayProviderOptions } from './gateway'; import { ProviderInterface } from './interface'; import { RPCProvider, RpcProviderOptions } from './rpc'; +import { SequencerProvider, SequencerProviderOptions } from './sequencer'; import { BlockIdentifier } from './utils'; export interface ProviderOptions { - gateway?: GatewayProviderOptions; + sequencer?: SequencerProviderOptions; rpc?: RpcProviderOptions; } @@ -34,7 +34,7 @@ export class Provider implements ProviderInterface { } else if (providerOrOptions && providerOrOptions.rpc) { this.provider = new RPCProvider(providerOrOptions.rpc); } else { - this.provider = new GatewayProvider(providerOrOptions?.gateway); + this.provider = new SequencerProvider(providerOrOptions?.sequencer); } } diff --git a/src/provider/index.ts b/src/provider/index.ts index 62eed4c28..d06fccdb9 100644 --- a/src/provider/index.ts +++ b/src/provider/index.ts @@ -2,7 +2,7 @@ import { Provider } from './default'; export * from './default'; export * from './errors'; -export * from './gateway'; +export * from './sequencer'; export * from './interface'; export * from './rpc'; diff --git a/src/provider/gateway.ts b/src/provider/sequencer.ts similarity index 89% rename from src/provider/gateway.ts rename to src/provider/sequencer.ts index 9f8ce7786..cdd0146ee 100644 --- a/src/provider/gateway.ts +++ b/src/provider/sequencer.ts @@ -10,7 +10,6 @@ import { DeployContractPayload, DeployContractResponse, EstimateFeeResponse, - Gateway, GetBlockResponse, GetContractAddressesResponse, GetTransactionReceiptResponse, @@ -20,12 +19,13 @@ import { Invocation, InvocationsDetails, InvokeFunctionResponse, + Sequencer, } from '../types'; import { getSelectorFromName } from '../utils/hash'; import { parse, parseAlwaysAsBig, stringify } from '../utils/json'; import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number'; import { parseContract, wait } from '../utils/provider'; -import { GatewayAPIResponseParser } from '../utils/responseParser/gateway'; +import { SequencerAPIResponseParser } from '../utils/responseParser/sequencer'; import { randomAddress } from '../utils/stark'; import { GatewayError, HttpError } from './errors'; import { ProviderInterface } from './interface'; @@ -42,7 +42,7 @@ function isEmptyQueryObject(obj?: Record): obj is undefined { ); } -export type GatewayProviderOptions = +export type SequencerProviderOptions = | { network: NetworkName } | { baseUrl: string; @@ -51,7 +51,7 @@ export type GatewayProviderOptions = chainId?: StarknetChainId; }; -export class GatewayProvider implements ProviderInterface { +export class SequencerProvider implements ProviderInterface { public baseUrl: string; public feederGatewayUrl: string; @@ -60,12 +60,12 @@ export class GatewayProvider implements ProviderInterface { public chainId: StarknetChainId; - private responseParser = new GatewayAPIResponseParser(); + private responseParser = new SequencerAPIResponseParser(); - constructor(optionsOrProvider: GatewayProviderOptions = { network: 'goerli-alpha' }) { + constructor(optionsOrProvider: SequencerProviderOptions = { network: 'goerli-alpha' }) { if ('network' in optionsOrProvider) { - this.baseUrl = GatewayProvider.getNetworkFromName(optionsOrProvider.network); - this.chainId = GatewayProvider.getChainIdFromBaseUrl(this.baseUrl); + this.baseUrl = SequencerProvider.getNetworkFromName(optionsOrProvider.network); + this.chainId = SequencerProvider.getChainIdFromBaseUrl(this.baseUrl); this.feederGatewayUrl = urljoin(this.baseUrl, 'feeder_gateway'); this.gatewayUrl = urljoin(this.baseUrl, 'gateway'); } else { @@ -75,7 +75,7 @@ export class GatewayProvider implements ProviderInterface { this.gatewayUrl = optionsOrProvider.gatewayUrl ?? urljoin(this.baseUrl, 'gateway'); this.chainId = optionsOrProvider.chainId ?? - GatewayProvider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl); + SequencerProvider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl); } } @@ -102,13 +102,13 @@ export class GatewayProvider implements ProviderInterface { return StarknetChainId.TESTNET; } - private getFetchUrl(endpoint: keyof Gateway.Endpoints) { + private getFetchUrl(endpoint: keyof Sequencer.Endpoints) { const gatewayUrlEndpoints = ['add_transaction']; return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl; } - private getFetchMethod(endpoint: keyof Gateway.Endpoints) { + private getFetchMethod(endpoint: keyof Sequencer.Endpoints) { const postMethodEndpoints = ['add_transaction', 'call_contract', 'estimate_fee']; return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET'; @@ -140,17 +140,17 @@ export class GatewayProvider implements ProviderInterface { } // typesafe fetch - protected async fetchEndpoint( + protected async fetchEndpoint( endpoint: T, // typescript type magiuc to create a nice fitting function interface - ...[query, request]: Gateway.Endpoints[T]['QUERY'] extends never - ? Gateway.Endpoints[T]['REQUEST'] extends never + ...[query, request]: Sequencer.Endpoints[T]['QUERY'] extends never + ? Sequencer.Endpoints[T]['REQUEST'] extends never ? [] // when no query and no request is needed, we can omit the query and request parameters - : [undefined, Gateway.Endpoints[T]['REQUEST']] - : Gateway.Endpoints[T]['REQUEST'] extends never - ? [Gateway.Endpoints[T]['QUERY']] // when no request is needed, we can omit the request parameter - : [Gateway.Endpoints[T]['QUERY'], Gateway.Endpoints[T]['REQUEST']] // when both query and request are needed, we cant omit anything - ): Promise { + : [undefined, Sequencer.Endpoints[T]['REQUEST']] + : Sequencer.Endpoints[T]['REQUEST'] extends never + ? [Sequencer.Endpoints[T]['QUERY']] // when no request is needed, we can omit the request parameter + : [Sequencer.Endpoints[T]['QUERY'], Sequencer.Endpoints[T]['REQUEST']] // when both query and request are needed, we cant omit anything + ): Promise { const baseUrl = this.getFetchUrl(endpoint); const method = this.getFetchMethod(endpoint); const queryString = this.getQueryString(query); @@ -186,7 +186,7 @@ export class GatewayProvider implements ProviderInterface { return v; }); } - return parse(textResponse) as Gateway.Endpoints[T]['RESPONSE']; + return parse(textResponse) as Sequencer.Endpoints[T]['RESPONSE']; } catch (err) { // rethrow custom errors if (err instanceof GatewayError || err instanceof HttpError) { diff --git a/src/types/api/index.ts b/src/types/api/index.ts index 636484949..17c034e1e 100644 --- a/src/types/api/index.ts +++ b/src/types/api/index.ts @@ -13,5 +13,5 @@ export type Overrides = { signature?: Signature; }; -export * from './gateway'; +export * from './sequencer'; export * from './rpc'; diff --git a/src/types/api/gateway.ts b/src/types/api/sequencer.ts similarity index 99% rename from src/types/api/gateway.ts rename to src/types/api/sequencer.ts index c79fa99cc..dc55bd204 100644 --- a/src/types/api/gateway.ts +++ b/src/types/api/sequencer.ts @@ -78,7 +78,7 @@ export type RawArgs = { [inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish }; }; -export namespace Gateway { +export namespace Sequencer { export type DeclareTransaction = { type: 'DECLARE'; contract_class: ContractClass; diff --git a/src/utils/responseParser/gateway.ts b/src/utils/responseParser/sequencer.ts similarity index 78% rename from src/utils/responseParser/gateway.ts rename to src/utils/responseParser/sequencer.ts index 43c525185..10c0639fd 100644 --- a/src/utils/responseParser/gateway.ts +++ b/src/utils/responseParser/sequencer.ts @@ -3,17 +3,17 @@ import { DeclareContractResponse, DeployContractResponse, EstimateFeeResponse, - Gateway, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, InvokeFunctionResponse, + Sequencer, } from '../../types'; import { toBN } from '../number'; import { ResponseParser } from '.'; -export class GatewayAPIResponseParser extends ResponseParser { - public parseGetBlockResponse(res: Gateway.GetBlockResponse): GetBlockResponse { +export class SequencerAPIResponseParser extends ResponseParser { + public parseGetBlockResponse(res: Sequencer.GetBlockResponse): GetBlockResponse { return { accepted_time: res.timestamp, block_hash: res.block_hash, @@ -30,7 +30,9 @@ export class GatewayAPIResponseParser extends ResponseParser { }; } - public parseGetTransactionResponse(res: Gateway.GetTransactionResponse): GetTransactionResponse { + public parseGetTransactionResponse( + res: Sequencer.GetTransactionResponse + ): GetTransactionResponse { return { calldata: 'calldata' in res.transaction ? (res.transaction.calldata as Array) : [], contract_address: @@ -55,7 +57,7 @@ export class GatewayAPIResponseParser extends ResponseParser { } public parseGetTransactionReceiptResponse( - res: Gateway.TransactionReceiptResponse + res: Sequencer.TransactionReceiptResponse ): GetTransactionReceiptResponse { return { transaction_hash: res.transaction_hash, @@ -68,25 +70,29 @@ export class GatewayAPIResponseParser extends ResponseParser { }; } - public parseFeeEstimateResponse(res: Gateway.EstimateFeeResponse): EstimateFeeResponse { + public parseFeeEstimateResponse(res: Sequencer.EstimateFeeResponse): EstimateFeeResponse { return { overall_fee: toBN(res.amount), }; } - public parseCallContractResponse(res: Gateway.CallContractResponse): CallContractResponse { + public parseCallContractResponse(res: Sequencer.CallContractResponse): CallContractResponse { return { result: res.result, }; } - public parseInvokeFunctionResponse(res: Gateway.AddTransactionResponse): InvokeFunctionResponse { + public parseInvokeFunctionResponse( + res: Sequencer.AddTransactionResponse + ): InvokeFunctionResponse { return { transaction_hash: res.transaction_hash, }; } - public parseDeployContractResponse(res: Gateway.AddTransactionResponse): DeployContractResponse { + public parseDeployContractResponse( + res: Sequencer.AddTransactionResponse + ): DeployContractResponse { return { transaction_hash: res.transaction_hash, contract_address: res.address as string, @@ -94,7 +100,7 @@ export class GatewayAPIResponseParser extends ResponseParser { } public parseDeclareContractResponse( - res: Gateway.AddTransactionResponse + res: Sequencer.AddTransactionResponse ): DeclareContractResponse { return { transaction_hash: res.transaction_hash,