Skip to content

Commit b7291e6

Browse files
committed
fix: rename gateway to sequencer
1 parent b2fc530 commit b7291e6

File tree

8 files changed

+47
-41
lines changed

8 files changed

+47
-41
lines changed

__tests__/fixtures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const BASE_URL = process.env.TEST_PROVIDER_BASE_URL || DEFAULT_TEST_PROVIDER_BAS
2121
export const IS_DEVNET = !BASE_URL.includes('starknet.io');
2222

2323
export const getTestProvider = () => {
24-
const provider = new Provider({ gateway: { baseUrl: BASE_URL } });
24+
const provider = new Provider({ sequencer: { baseUrl: BASE_URL } });
2525

2626
if (IS_DEVNET) {
2727
// accelerate the tests when running locally

__tests__/gatewayProvider.test.ts renamed to __tests__/sequencerProvider.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { DeclareContractResponse, DeployContractResponse, GatewayProvider } from '../src';
1+
import { DeclareContractResponse, DeployContractResponse, SequencerProvider } from '../src';
22
import { compileCalldata } from '../src/utils/stark';
33
import { compiledErc20 } from './fixtures';
44

5-
describe('GatewayProvider', () => {
6-
let provider: GatewayProvider;
5+
describe('SequencerProvider', () => {
6+
let provider: SequencerProvider;
77

88
beforeAll(async () => {
9-
provider = new GatewayProvider();
9+
provider = new SequencerProvider();
1010
});
1111

1212
describe('Provider methods', () => {

src/provider/default.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import {
1515
InvokeFunctionResponse,
1616
} from '../types';
1717
import { BigNumberish } from '../utils/number';
18-
import { GatewayProvider, GatewayProviderOptions } from './gateway';
1918
import { ProviderInterface } from './interface';
2019
import { RPCProvider, RpcProviderOptions } from './rpc';
20+
import { SequencerProvider, SequencerProviderOptions } from './sequencer';
2121
import { BlockIdentifier } from './utils';
2222

2323
export interface ProviderOptions {
24-
gateway?: GatewayProviderOptions;
24+
sequencer?: SequencerProviderOptions;
2525
rpc?: RpcProviderOptions;
2626
}
2727

@@ -34,7 +34,7 @@ export class Provider implements ProviderInterface {
3434
} else if (providerOrOptions && providerOrOptions.rpc) {
3535
this.provider = new RPCProvider(providerOrOptions.rpc);
3636
} else {
37-
this.provider = new GatewayProvider(providerOrOptions?.gateway);
37+
this.provider = new SequencerProvider(providerOrOptions?.sequencer);
3838
}
3939
}
4040

src/provider/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Provider } from './default';
22

33
export * from './default';
44
export * from './errors';
5-
export * from './gateway';
5+
export * from './sequencer';
66
export * from './interface';
77
export * from './rpc';
88

src/provider/gateway.ts renamed to src/provider/sequencer.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
DeployContractPayload,
1111
DeployContractResponse,
1212
EstimateFeeResponse,
13-
Gateway,
1413
GetBlockResponse,
1514
GetContractAddressesResponse,
1615
GetTransactionReceiptResponse,
@@ -20,12 +19,13 @@ import {
2019
Invocation,
2120
InvocationsDetails,
2221
InvokeFunctionResponse,
22+
Sequencer,
2323
} from '../types';
2424
import { getSelectorFromName } from '../utils/hash';
2525
import { parse, parseAlwaysAsBig, stringify } from '../utils/json';
2626
import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number';
2727
import { parseContract, wait } from '../utils/provider';
28-
import { GatewayAPIResponseParser } from '../utils/responseParser/gateway';
28+
import { SequencerAPIResponseParser } from '../utils/responseParser/sequencer';
2929
import { randomAddress } from '../utils/stark';
3030
import { GatewayError, HttpError } from './errors';
3131
import { ProviderInterface } from './interface';
@@ -42,7 +42,7 @@ function isEmptyQueryObject(obj?: Record<any, any>): obj is undefined {
4242
);
4343
}
4444

45-
export type GatewayProviderOptions =
45+
export type SequencerProviderOptions =
4646
| { network: NetworkName }
4747
| {
4848
baseUrl: string;
@@ -51,7 +51,7 @@ export type GatewayProviderOptions =
5151
chainId?: StarknetChainId;
5252
};
5353

54-
export class GatewayProvider implements ProviderInterface {
54+
export class SequencerProvider implements ProviderInterface {
5555
public baseUrl: string;
5656

5757
public feederGatewayUrl: string;
@@ -60,12 +60,12 @@ export class GatewayProvider implements ProviderInterface {
6060

6161
public chainId: StarknetChainId;
6262

63-
private responseParser = new GatewayAPIResponseParser();
63+
private responseParser = new SequencerAPIResponseParser();
6464

65-
constructor(optionsOrProvider: GatewayProviderOptions = { network: 'goerli-alpha' }) {
65+
constructor(optionsOrProvider: SequencerProviderOptions = { network: 'goerli-alpha' }) {
6666
if ('network' in optionsOrProvider) {
67-
this.baseUrl = GatewayProvider.getNetworkFromName(optionsOrProvider.network);
68-
this.chainId = GatewayProvider.getChainIdFromBaseUrl(this.baseUrl);
67+
this.baseUrl = SequencerProvider.getNetworkFromName(optionsOrProvider.network);
68+
this.chainId = SequencerProvider.getChainIdFromBaseUrl(this.baseUrl);
6969
this.feederGatewayUrl = urljoin(this.baseUrl, 'feeder_gateway');
7070
this.gatewayUrl = urljoin(this.baseUrl, 'gateway');
7171
} else {
@@ -75,7 +75,7 @@ export class GatewayProvider implements ProviderInterface {
7575
this.gatewayUrl = optionsOrProvider.gatewayUrl ?? urljoin(this.baseUrl, 'gateway');
7676
this.chainId =
7777
optionsOrProvider.chainId ??
78-
GatewayProvider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl);
78+
SequencerProvider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl);
7979
}
8080
}
8181

@@ -102,13 +102,13 @@ export class GatewayProvider implements ProviderInterface {
102102
return StarknetChainId.TESTNET;
103103
}
104104

105-
private getFetchUrl(endpoint: keyof Gateway.Endpoints) {
105+
private getFetchUrl(endpoint: keyof Sequencer.Endpoints) {
106106
const gatewayUrlEndpoints = ['add_transaction'];
107107

108108
return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
109109
}
110110

111-
private getFetchMethod(endpoint: keyof Gateway.Endpoints) {
111+
private getFetchMethod(endpoint: keyof Sequencer.Endpoints) {
112112
const postMethodEndpoints = ['add_transaction', 'call_contract', 'estimate_fee'];
113113

114114
return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET';
@@ -140,17 +140,17 @@ export class GatewayProvider implements ProviderInterface {
140140
}
141141

142142
// typesafe fetch
143-
protected async fetchEndpoint<T extends keyof Gateway.Endpoints>(
143+
protected async fetchEndpoint<T extends keyof Sequencer.Endpoints>(
144144
endpoint: T,
145145
// typescript type magiuc to create a nice fitting function interface
146-
...[query, request]: Gateway.Endpoints[T]['QUERY'] extends never
147-
? Gateway.Endpoints[T]['REQUEST'] extends never
146+
...[query, request]: Sequencer.Endpoints[T]['QUERY'] extends never
147+
? Sequencer.Endpoints[T]['REQUEST'] extends never
148148
? [] // when no query and no request is needed, we can omit the query and request parameters
149-
: [undefined, Gateway.Endpoints[T]['REQUEST']]
150-
: Gateway.Endpoints[T]['REQUEST'] extends never
151-
? [Gateway.Endpoints[T]['QUERY']] // when no request is needed, we can omit the request parameter
152-
: [Gateway.Endpoints[T]['QUERY'], Gateway.Endpoints[T]['REQUEST']] // when both query and request are needed, we cant omit anything
153-
): Promise<Gateway.Endpoints[T]['RESPONSE']> {
149+
: [undefined, Sequencer.Endpoints[T]['REQUEST']]
150+
: Sequencer.Endpoints[T]['REQUEST'] extends never
151+
? [Sequencer.Endpoints[T]['QUERY']] // when no request is needed, we can omit the request parameter
152+
: [Sequencer.Endpoints[T]['QUERY'], Sequencer.Endpoints[T]['REQUEST']] // when both query and request are needed, we cant omit anything
153+
): Promise<Sequencer.Endpoints[T]['RESPONSE']> {
154154
const baseUrl = this.getFetchUrl(endpoint);
155155
const method = this.getFetchMethod(endpoint);
156156
const queryString = this.getQueryString(query);
@@ -186,7 +186,7 @@ export class GatewayProvider implements ProviderInterface {
186186
return v;
187187
});
188188
}
189-
return parse(textResponse) as Gateway.Endpoints[T]['RESPONSE'];
189+
return parse(textResponse) as Sequencer.Endpoints[T]['RESPONSE'];
190190
} catch (err) {
191191
// rethrow custom errors
192192
if (err instanceof GatewayError || err instanceof HttpError) {

src/types/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ export type Overrides = {
1313
signature?: Signature;
1414
};
1515

16-
export * from './gateway';
16+
export * from './sequencer';
1717
export * from './rpc';

src/types/api/gateway.ts renamed to src/types/api/sequencer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export type RawArgs = {
7878
[inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish };
7979
};
8080

81-
export namespace Gateway {
81+
export namespace Sequencer {
8282
export type DeclareTransaction = {
8383
type: 'DECLARE';
8484
contract_class: ContractClass;

src/utils/responseParser/gateway.ts renamed to src/utils/responseParser/sequencer.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import {
33
DeclareContractResponse,
44
DeployContractResponse,
55
EstimateFeeResponse,
6-
Gateway,
76
GetBlockResponse,
87
GetTransactionReceiptResponse,
98
GetTransactionResponse,
109
InvokeFunctionResponse,
10+
Sequencer,
1111
} from '../../types';
1212
import { toBN } from '../number';
1313
import { ResponseParser } from '.';
1414

15-
export class GatewayAPIResponseParser extends ResponseParser {
16-
public parseGetBlockResponse(res: Gateway.GetBlockResponse): GetBlockResponse {
15+
export class SequencerAPIResponseParser extends ResponseParser {
16+
public parseGetBlockResponse(res: Sequencer.GetBlockResponse): GetBlockResponse {
1717
return {
1818
accepted_time: res.timestamp,
1919
block_hash: res.block_hash,
@@ -30,7 +30,9 @@ export class GatewayAPIResponseParser extends ResponseParser {
3030
};
3131
}
3232

33-
public parseGetTransactionResponse(res: Gateway.GetTransactionResponse): GetTransactionResponse {
33+
public parseGetTransactionResponse(
34+
res: Sequencer.GetTransactionResponse
35+
): GetTransactionResponse {
3436
return {
3537
calldata: 'calldata' in res.transaction ? (res.transaction.calldata as Array<string>) : [],
3638
contract_address:
@@ -55,7 +57,7 @@ export class GatewayAPIResponseParser extends ResponseParser {
5557
}
5658

5759
public parseGetTransactionReceiptResponse(
58-
res: Gateway.TransactionReceiptResponse
60+
res: Sequencer.TransactionReceiptResponse
5961
): GetTransactionReceiptResponse {
6062
return {
6163
transaction_hash: res.transaction_hash,
@@ -68,33 +70,37 @@ export class GatewayAPIResponseParser extends ResponseParser {
6870
};
6971
}
7072

71-
public parseFeeEstimateResponse(res: Gateway.EstimateFeeResponse): EstimateFeeResponse {
73+
public parseFeeEstimateResponse(res: Sequencer.EstimateFeeResponse): EstimateFeeResponse {
7274
return {
7375
overall_fee: toBN(res.amount),
7476
};
7577
}
7678

77-
public parseCallContractResponse(res: Gateway.CallContractResponse): CallContractResponse {
79+
public parseCallContractResponse(res: Sequencer.CallContractResponse): CallContractResponse {
7880
return {
7981
result: res.result,
8082
};
8183
}
8284

83-
public parseInvokeFunctionResponse(res: Gateway.AddTransactionResponse): InvokeFunctionResponse {
85+
public parseInvokeFunctionResponse(
86+
res: Sequencer.AddTransactionResponse
87+
): InvokeFunctionResponse {
8488
return {
8589
transaction_hash: res.transaction_hash,
8690
};
8791
}
8892

89-
public parseDeployContractResponse(res: Gateway.AddTransactionResponse): DeployContractResponse {
93+
public parseDeployContractResponse(
94+
res: Sequencer.AddTransactionResponse
95+
): DeployContractResponse {
9096
return {
9197
transaction_hash: res.transaction_hash,
9298
contract_address: res.address as string,
9399
};
94100
}
95101

96102
public parseDeclareContractResponse(
97-
res: Gateway.AddTransactionResponse
103+
res: Sequencer.AddTransactionResponse
98104
): DeclareContractResponse {
99105
return {
100106
transaction_hash: res.transaction_hash,

0 commit comments

Comments
 (0)