Remove chainId from json-schemas and connect

This commit is contained in:
fragosti 2019-11-08 16:09:53 -08:00
parent 3b9d84fa58
commit 403ceebff9
8 changed files with 38 additions and 113 deletions

View File

@ -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)*
<hr />
# Interface: SignedOrder

View File

@ -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<AssetPairsResponse> {
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<OrdersResponse> {
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<APIOrder> {
if (requestOpts !== undefined) {
assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema);
}
public async getOrderAsync(orderHash: string): Promise<APIOrder> {
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<OrderbookResponse> {
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<OrderConfigResponse> {
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<FeeRecipientsResponse> {
public async getFeeRecipientsAsync(requestOpts?: PagedRequestOpts): Promise<FeeRecipientsResponse> {
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<void> {
public async submitOrderAsync(signedOrder: SignedOrder): Promise<void> {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
const httpRequestOpts = {
params: requestOpts,
payload: signedOrder,
};
await this._requestAsync('/order', HttpRequestType.Post, httpRequestOpts);

View File

@ -15,6 +15,5 @@ export {
OrdersResponse,
PagedRequestOpts,
PaginatedCollection,
RequestOpts,
SignedOrder,
} from '@0x/types';

View File

@ -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);
@ -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&quoteAssetData=${request.quoteAssetData}`;
}&page=3&perPage=50&quoteAssetData=${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);

View File

@ -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"
}
}
}

View File

@ -1,7 +0,0 @@
{
"id": "/RequestOptsSchema",
"type": "object",
"properties": {
"chainId": { "type": "number" }
}
}

View File

@ -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

View File

@ -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];
};