Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #102 from 0xProject/feat/sra/order-validation
Browse files Browse the repository at this point in the history
/sra/orders POST schema validation
  • Loading branch information
dave4506 authored Feb 18, 2020
2 parents f7f2abf + 11708a6 commit 1902655
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/handlers/sra_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as HttpStatus from 'http-status-codes';
import { FEE_RECIPIENT_ADDRESS, WHITELISTED_TOKENS } from '../config';
import { SRA_DOCS_URL } from '../constants';
import { NotFoundError, ValidationError, ValidationErrorCodes } from '../errors';
import { schemas as apiSchemas } from '../schemas/schemas';
import { OrderBookService } from '../services/orderbook_service';
import { orderUtils } from '../utils/order_utils';
import { paginationUtils } from '../utils/pagination_utils';
Expand Down Expand Up @@ -67,7 +68,7 @@ export class SRAHandlers {
res.status(HttpStatus.OK).send(orderbookResponse);
}
public async postOrderAsync(req: express.Request, res: express.Response): Promise<void> {
schemaUtils.validateSchema(req.body, schemas.signedOrderSchema);
schemaUtils.validateSchema(req.body, apiSchemas.sraPostOrderRequestSchema);
const signedOrder = unmarshallOrder(req.body);
if (WHITELISTED_TOKENS !== '*') {
const allowedTokens: string[] = WHITELISTED_TOKENS;
Expand Down
2 changes: 2 additions & 0 deletions src/schemas/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as sraPostOrderRequestSchema from './sra_post_order_request_schema.json';
import * as swapQuoteRequestSchema from './swap_quote_request_schema.json';

export const schemas = {
swapQuoteRequestSchema,
sraPostOrderRequestSchema,
};
75 changes: 75 additions & 0 deletions src/schemas/sra_post_order_request_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"id": "/PostQuoteRequestSchema",
"properties": {
"signature": {
"type": "string"
},
"senderAddress": {
"$ref": "/addressSchema"
},
"makerAddress": {
"$ref": "/addressSchema"
},
"takerAddress": {
"$ref": "/addressSchema"
},
"makerFee": {
"type": "string"
},
"takerFee": {
"type": "string"
},
"makerAssetAmount": {
"type": "string"
},
"takerAssetAmount": {
"type": "string"
},
"makerAssetData": {
"type": "string"
},
"takerAssetData": {
"type": "string"
},
"salt": {
"type": "string"
},
"exchangeAddress": {
"$ref": "/addressSchema"
},
"feeRecipientAddress": {
"$ref": "/addressSchema"
},
"expirationTimeSeconds": {
"type": "string"
},
"makerFeeAssetData": {
"type": "string"
},
"takerFeeAssetData": {
"type": "string"
},
"chainId": {
"$ref": "/wholeNumberSchema"
}
},
"required": [
"signature",
"senderAddress",
"makerAddress",
"takerAddress",
"makerFee",
"takerFee",
"makerAssetAmount",
"makerAssetData",
"takerAssetData",
"salt",
"exchangeAddress",
"feeRecipientAddress",
"expirationTimeSeconds",
"makerFeeAssetData",
"takerFeeAssetData",
"chainId"
],
"type": "object"
}

0 comments on commit 1902655

Please sign in to comment.