diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-09-21 21:58:04 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-09-21 21:58:04 +0800 |
commit | c64dcec772d8f5bfa7a32c5e60bfe808229d4d5e (patch) | |
tree | c1fe70d472f4e8df391d2a1f686beb835b03a2b0 /packages/asset-buyer/src/order_providers/basic_order_provider.ts | |
parent | 8dea48ebeff775f7437c45f5a6d39dfc7dbf704e (diff) | |
download | dexon-sol-tools-c64dcec772d8f5bfa7a32c5e60bfe808229d4d5e.tar dexon-sol-tools-c64dcec772d8f5bfa7a32c5e60bfe808229d4d5e.tar.gz dexon-sol-tools-c64dcec772d8f5bfa7a32c5e60bfe808229d4d5e.tar.bz2 dexon-sol-tools-c64dcec772d8f5bfa7a32c5e60bfe808229d4d5e.tar.lz dexon-sol-tools-c64dcec772d8f5bfa7a32c5e60bfe808229d4d5e.tar.xz dexon-sol-tools-c64dcec772d8f5bfa7a32c5e60bfe808229d4d5e.tar.zst dexon-sol-tools-c64dcec772d8f5bfa7a32c5e60bfe808229d4d5e.zip |
More renaming
Diffstat (limited to 'packages/asset-buyer/src/order_providers/basic_order_provider.ts')
-rw-r--r-- | packages/asset-buyer/src/order_providers/basic_order_provider.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/packages/asset-buyer/src/order_providers/basic_order_provider.ts b/packages/asset-buyer/src/order_providers/basic_order_provider.ts new file mode 100644 index 000000000..9bb2d90ac --- /dev/null +++ b/packages/asset-buyer/src/order_providers/basic_order_provider.ts @@ -0,0 +1,32 @@ +import { schemas } from '@0xproject/json-schemas'; +import { SignedOrder } from '@0xproject/types'; +import * as _ from 'lodash'; + +import { OrderProvider, OrderProviderRequest, OrderProviderResponse } from '../types'; +import { assert } from '../utils/assert'; + +export class BasicOrderProvider implements OrderProvider { + public readonly orders: SignedOrder[]; + /** + * Instantiates a new BasicOrderProvider instance + * @param orders An array of objects that conform to SignedOrder to fetch from. + * @return An instance of BasicOrderProvider + */ + constructor(orders: SignedOrder[]) { + assert.doesConformToSchema('orders', orders, schemas.signedOrdersSchema); + this.orders = orders; + } + /** + * Given an object that conforms to OrderFetcherRequest, return the corresponding OrderProviderResponse that satisfies the request. + * @param orderProviderRequest An instance of OrderFetcherRequest. See type for more information. + * @return An instance of OrderProviderResponse. See type for more information. + */ + public async getOrdersAsync(orderProviderRequest: OrderProviderRequest): Promise<OrderProviderResponse> { + assert.isValidOrderProviderRequest('orderProviderRequest', orderProviderRequest); + const { makerAssetData, takerAssetData } = orderProviderRequest; + const orders = _.filter(this.orders, order => { + return order.makerAssetData === makerAssetData && order.takerAssetData === takerAssetData; + }); + return { orders }; + } +} |