From 403ceebff97adc7e74489282f529daf3ab9c5872 Mon Sep 17 00:00:00 2001 From: fragosti Date: Fri, 8 Nov 2019 16:09:53 -0800 Subject: [PATCH] Remove chainId from json-schemas and connect --- packages/connect/docs/reference.mdx | 13 ------ packages/connect/src/http_client.ts | 41 +++++-------------- packages/connect/src/index.ts | 1 - packages/connect/test/http_client_test.ts | 14 +++---- ...ders_channel_subscribe_payload_schema.json | 29 +++++++++---- .../schemas/request_opts_schema.json | 7 ---- packages/sra-spec/src/md/introduction.md | 34 --------------- packages/sra-spec/src/parameters.ts | 12 +----- 8 files changed, 38 insertions(+), 113 deletions(-) delete mode 100644 packages/json-schemas/schemas/request_opts_schema.json diff --git a/packages/connect/docs/reference.mdx b/packages/connect/docs/reference.mdx index a166e163dc..3d59b4317a 100644 --- a/packages/connect/docs/reference.mdx +++ b/packages/connect/docs/reference.mdx @@ -379,19 +379,6 @@ ___ -# Interface: RequestOpts - - -## Properties - -### `Optional` chainId - -• **chainId**? : *undefined | number* - -*Defined in [types/src/index.ts:487](https://github.com/0xProject/0x-monorepo/blob/c93b02d55/packages/types/src/index.ts#L487)* - -
- # Interface: SignedOrder diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 9281606fce..7946280ed5 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -12,7 +12,6 @@ import { OrdersRequestOpts, OrdersResponse, PagedRequestOpts, - RequestOpts, SignedOrder, } from '@0x/types'; import { fetchAsync } from '@0x/utils'; @@ -53,16 +52,15 @@ export class HttpClient { } /** * Retrieve assetData pair info from the API - * @param requestOpts Options specifying assetData information to retrieve, page information, and chain id. + * @param requestOpts Options specifying assetData information to retrieve, page information. * @return The resulting AssetPairsResponse that match the request */ public async getAssetPairsAsync( - requestOpts?: RequestOpts & AssetPairsRequestOpts & PagedRequestOpts, + requestOpts?: AssetPairsRequestOpts & PagedRequestOpts, ): Promise { if (requestOpts !== undefined) { assert.doesConformToSchema('requestOpts', requestOpts, schemas.assetPairsRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema); - assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema); } const httpRequestOpts = { params: requestOpts, @@ -73,16 +71,15 @@ export class HttpClient { } /** * Retrieve orders from the API - * @param requestOpts Options specifying orders to retrieve and page information, page information, and chain id. + * @param requestOpts Options specifying orders to retrieve and page information, page information. * @return The resulting OrdersResponse that match the request */ public async getOrdersAsync( - requestOpts?: RequestOpts & OrdersRequestOpts & PagedRequestOpts, + requestOpts?: OrdersRequestOpts & PagedRequestOpts, ): Promise { if (requestOpts !== undefined) { assert.doesConformToSchema('requestOpts', requestOpts, schemas.ordersRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema); - assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema); } const httpRequestOpts = { params: requestOpts, @@ -96,32 +93,25 @@ export class HttpClient { * @param orderHash An orderHash generated from the desired order * @return The APIOrder that matches the supplied orderHash */ - public async getOrderAsync(orderHash: string, requestOpts?: RequestOpts): Promise { - if (requestOpts !== undefined) { - assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema); - } + public async getOrderAsync(orderHash: string): Promise { assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); - const httpRequestOpts = { - params: requestOpts, - }; - const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get, httpRequestOpts); + const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get); const order = relayerResponseJsonParsers.parseAPIOrderJson(responseJson); return order; } /** * Retrieve an orderbook from the API * @param request An OrderbookRequest instance describing the specific orderbook to retrieve - * @param requestOpts Options specifying page information, and chain id. + * @param requestOpts Options specifying page information. * @return The resulting OrderbookResponse that matches the request */ public async getOrderbookAsync( request: OrderbookRequest, - requestOpts?: RequestOpts & PagedRequestOpts, + requestOpts?: PagedRequestOpts, ): Promise { assert.doesConformToSchema('request', request, schemas.orderBookRequestSchema); if (requestOpts !== undefined) { assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema); - assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema); } const httpRequestOpts = { params: _.defaults({}, request, requestOpts), @@ -133,19 +123,13 @@ export class HttpClient { /** * Retrieve fee information from the API * @param request A OrderConfigRequest instance describing the specific fees to retrieve - * @param requestOpts Options specifying chain id. * @return The resulting OrderConfigResponse that matches the request */ public async getOrderConfigAsync( request: OrderConfigRequest, - requestOpts?: RequestOpts, ): Promise { - if (requestOpts !== undefined) { - assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema); - } assert.doesConformToSchema('request', request, schemas.orderConfigRequestSchema); const httpRequestOpts = { - params: requestOpts, payload: request, }; const responseJson = await this._requestAsync('/order_config', HttpRequestType.Post, httpRequestOpts); @@ -154,13 +138,12 @@ export class HttpClient { } /** * Retrieve the list of fee recipient addresses used by the relayer. - * @param requestOpts Options specifying page information, and chain id. + * @param requestOpts Options specifying page information. * @return The resulting FeeRecipientsResponse */ - public async getFeeRecipientsAsync(requestOpts?: RequestOpts & PagedRequestOpts): Promise { + public async getFeeRecipientsAsync(requestOpts?: PagedRequestOpts): Promise { if (requestOpts !== undefined) { assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema); - assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema); } const httpRequestOpts = { params: requestOpts, @@ -172,12 +155,10 @@ export class HttpClient { /** * Submit a signed order to the API * @param signedOrder A SignedOrder instance to submit - * @param requestOpts Options specifying chain id. */ - public async submitOrderAsync(signedOrder: SignedOrder, requestOpts?: RequestOpts): Promise { + public async submitOrderAsync(signedOrder: SignedOrder): Promise { assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema); const httpRequestOpts = { - params: requestOpts, payload: signedOrder, }; await this._requestAsync('/order', HttpRequestType.Post, httpRequestOpts); diff --git a/packages/connect/src/index.ts b/packages/connect/src/index.ts index 517678bd52..0849c9a633 100644 --- a/packages/connect/src/index.ts +++ b/packages/connect/src/index.ts @@ -15,6 +15,5 @@ export { OrdersResponse, PagedRequestOpts, PaginatedCollection, - RequestOpts, SignedOrder, } from '@0x/types'; diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 5fb6364eb8..81fbc24b46 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -53,9 +53,8 @@ describe('HttpClient', () => { assetDataA: assetData, page: 3, perPage: 50, - chainId: 42, }; - const urlWithQuery = `${url}?assetDataA=${assetData}&chainId=42&page=3&perPage=50`; + const urlWithQuery = `${url}?assetDataA=${assetData}&page=3&perPage=50`; fetchMock.get(urlWithQuery, assetDataPairsResponseJSON); const assetDataPairs = await relayerClient.getAssetPairsAsync(assetPairsRequestOpts); expect(assetDataPairs).to.be.deep.equal(assetDataPairsResponse); @@ -78,9 +77,8 @@ describe('HttpClient', () => { assetDataAddress, page: 3, perPage: 50, - chainId: 42, }; - const urlWithQuery = `${url}?assetDataAddress=${assetDataAddress}&chainId=42&page=3&perPage=50`; + const urlWithQuery = `${url}?assetDataAddress=${assetDataAddress}&page=3&perPage=50`; fetchMock.get(urlWithQuery, ordersResponseJSON); const orders = await relayerClient.getOrdersAsync(ordersRequest); expect(orders).to.be.deep.equal(ordersResponse); @@ -112,7 +110,7 @@ describe('HttpClient', () => { it('gets orderbook with default page options when none are provided', async () => { const urlWithQuery = `${url}?baseAssetData=${request.baseAssetData}"eAssetData=${ request.quoteAssetData - }`; + }`; fetchMock.get(urlWithQuery, orderbookJSON); const orderbook = await relayerClient.getOrderbookAsync(request); expect(orderbook).to.be.deep.equal(orderbookResponse); @@ -120,12 +118,11 @@ describe('HttpClient', () => { it('gets orderbook with specified page options', async () => { const urlWithQuery = `${url}?baseAssetData=${ request.baseAssetData - }&chainId=42&page=3&perPage=50"eAssetData=${request.quoteAssetData}`; + }&page=3&perPage=50"eAssetData=${request.quoteAssetData}`; fetchMock.get(urlWithQuery, orderbookJSON); const pagedRequestOptions = { page: 3, perPage: 50, - chainId: 42, }; const orderbook = await relayerClient.getOrderbookAsync(request, pagedRequestOptions); expect(orderbook).to.be.deep.equal(orderbookResponse); @@ -175,12 +172,11 @@ describe('HttpClient', () => { expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse); }); it('gets fee recipient with specified page options', async () => { - const urlWithQuery = `${url}?chainId=42&page=3&perPage=50`; + const urlWithQuery = `${url}?page=3&perPage=50`; fetchMock.get(urlWithQuery, feeRecipientsResponseJSON); const pagedRequestOptions = { page: 3, perPage: 50, - chainId: 42, }; const feeRecipients = await relayerClient.getFeeRecipientsAsync(pagedRequestOptions); expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse); diff --git a/packages/json-schemas/schemas/relayer_api_orders_channel_subscribe_payload_schema.json b/packages/json-schemas/schemas/relayer_api_orders_channel_subscribe_payload_schema.json index 120ec5ab25..a002c21fb9 100644 --- a/packages/json-schemas/schemas/relayer_api_orders_channel_subscribe_payload_schema.json +++ b/packages/json-schemas/schemas/relayer_api_orders_channel_subscribe_payload_schema.json @@ -2,13 +2,26 @@ "id": "/relayerApiOrdersChannelSubscribePayloadSchema", "type": "object", "properties": { - "makerAssetProxyId": { "$ref": "/hexSchema" }, - "takerAssetProxyId": { "$ref": "/hexSchema" }, - "chainId": { "type": "number" }, - "makerAssetAddress": { "$ref": "/addressSchema" }, - "takerAssetAddress": { "$ref": "/addressSchema" }, - "makerAssetData": { "$ref": "/hexSchema" }, - "takerAssetData": { "$ref": "/hexSchema" }, - "traderAssetData": { "$ref": "/hexSchema" } + "makerAssetProxyId": { + "$ref": "/hexSchema" + }, + "takerAssetProxyId": { + "$ref": "/hexSchema" + }, + "makerAssetAddress": { + "$ref": "/addressSchema" + }, + "takerAssetAddress": { + "$ref": "/addressSchema" + }, + "makerAssetData": { + "$ref": "/hexSchema" + }, + "takerAssetData": { + "$ref": "/hexSchema" + }, + "traderAssetData": { + "$ref": "/hexSchema" + } } } diff --git a/packages/json-schemas/schemas/request_opts_schema.json b/packages/json-schemas/schemas/request_opts_schema.json deleted file mode 100644 index 54dba1d66b..0000000000 --- a/packages/json-schemas/schemas/request_opts_schema.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "id": "/RequestOptsSchema", - "type": "object", - "properties": { - "chainId": { "type": "number" } - } -} diff --git a/packages/sra-spec/src/md/introduction.md b/packages/sra-spec/src/md/introduction.md index c735c44361..a9e9ecf12c 100644 --- a/packages/sra-spec/src/md/introduction.md +++ b/packages/sra-spec/src/md/introduction.md @@ -34,40 +34,6 @@ All endpoints that are paginated should return a `total`, `page`, `perPage` and These requests include the [`/v3/asset_pairs`](#operation/getAssetPairs), [`/v3/orders`](#operation/getOrders), [`/v3/fee_recipients`](#operation/getFeeRecipients) and [`/v3/orderbook`](#operation/getOrderbook) endpoints. -# Chain Id - -All requests should be able to specify a **?chainId** query param for all supported chains. For example: - -```bash -$ curl https://api.example-relayer.com/v3/asset_pairs?chainId=1 -``` - -If the query param is not provided, it should default to **1** (mainnet). - -Chains and their Ids: - -| Chain Id | Chain Name | -| -------- | ---------- | -| 1 | Mainnet | -| 42 | Kovan | -| 3 | Ropsten | -| 4 | Rinkeby | - -If a certain chain is not supported, the response should **400** as specified in the [error response](#section/Errors) section. For example: - -```json -{ - "code": 100, - "reason": "Validation failed", - "validationErrors": [ - { - "field": "chainId", - "code": 1006, - "reason": "Chain id 42 is not supported" - } - ] -} -``` # Link Header diff --git a/packages/sra-spec/src/parameters.ts b/packages/sra-spec/src/parameters.ts index 496e9d05cb..4a4e229bc6 100644 --- a/packages/sra-spec/src/parameters.ts +++ b/packages/sra-spec/src/parameters.ts @@ -22,18 +22,8 @@ export const paginationParameters: ParameterObject[] = [ }, ]; -export const chainIdParameter: ParameterObject = { - name: 'chainId', - in: 'query', - description: 'The id of the Ethereum chain', - example: 42, - schema: { - type: 'number', - default: 1, - }, -}; export const generateParameters = (parameters: ParameterObject[], isPaginated: boolean = false): ParameterObject[] => { const optionalParameters = isPaginated ? paginationParameters : []; - return [...parameters, chainIdParameter, ...optionalParameters]; + return [...parameters, ...optionalParameters]; };