當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript assert.assert類代碼示例

本文整理匯總了TypeScript中@0xproject/assert.assert的典型用法代碼示例。如果您正苦於以下問題:TypeScript assert類的具體用法?TypeScript assert怎麽用?TypeScript assert使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了assert類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getOrdersAsync

 /**
  * Retrieve orders from the API
  * @param   requestOpts     Options specifying orders to retrieve and page information, defaults to { page: 1, perPage: 100 }
  * @return  The resulting SignedOrders that match the request
  */
 public async getOrdersAsync(requestOpts?: OrdersRequestOpts & PagedRequestOpts): Promise<SignedOrder[]> {
     if (!_.isUndefined(requestOpts)) {
         assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.ordersRequestOptsSchema);
         assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema);
     }
     const httpRequestOpts = {
         params: _.defaults({}, requestOpts, DEFAULT_PAGED_REQUEST_OPTS),
     };
     const responseJson = await this._requestAsync(`/orders`, HttpRequestType.Get, httpRequestOpts);
     const orders = relayerResponseJsonParsers.parseOrdersJson(responseJson);
     return orders;
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:17,代碼來源:http_client.ts

示例2: getTokenPairsAsync

 /**
  * Retrieve token pair info from the API
  * @param   requestOpts     Options specifying token information to retrieve and page information, defaults to { page: 1, perPage: 100 }
  * @return  The resulting TokenPairsItems that match the request
  */
 public async getTokenPairsAsync(requestOpts?: TokenPairsRequestOpts & PagedRequestOpts): Promise<TokenPairsItem[]> {
     if (!_.isUndefined(requestOpts)) {
         assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.tokenPairsRequestOptsSchema);
         assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema);
     }
     const httpRequestOpts = {
         params: _.defaults({}, requestOpts, DEFAULT_PAGED_REQUEST_OPTS),
     };
     const responseJson = await this._requestAsync('/token_pairs', HttpRequestType.Get, httpRequestOpts);
     const tokenPairs = relayerResponseJsonParsers.parseTokenPairsJson(responseJson);
     return tokenPairs;
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:17,代碼來源:http_client.ts

示例3: getOrderbookAsync

 /**
  * Retrieve an orderbook from the API
  * @param   request         An OrderbookRequest instance describing the specific orderbook to retrieve
  * @param   requestOpts     Options specifying page information, defaults to { page: 1, perPage: 100 }
  * @return  The resulting OrderbookResponse that matches the request
  */
 public async getOrderbookAsync(
     request: OrderbookRequest,
     requestOpts?: PagedRequestOpts,
 ): Promise<OrderbookResponse> {
     assert.doesConformToSchema('request', request, clientSchemas.orderBookRequestSchema);
     if (!_.isUndefined(requestOpts)) {
         assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema);
     }
     const httpRequestOpts = {
         params: _.defaults({}, request, requestOpts, DEFAULT_PAGED_REQUEST_OPTS),
     };
     const responseJson = await this._requestAsync('/orderbook', HttpRequestType.Get, httpRequestOpts);
     const orderbook = relayerResponseJsonParsers.parseOrderbookResponseJson(responseJson);
     return orderbook;
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:21,代碼來源:http_client.ts

示例4: submitOrderAsync

 /**
  * Submit a signed order to the API
  * @param   signedOrder     A SignedOrder instance to submit
  */
 public async submitOrderAsync(signedOrder: SignedOrder): Promise<void> {
     assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
     const requestOpts = {
         payload: signedOrder,
     };
     await this._requestAsync('/order', HttpRequestType.Post, requestOpts);
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:11,代碼來源:http_client.ts

示例5: getFeesAsync

 /**
  * Retrieve fee information from the API
  * @param   request     A FeesRequest instance describing the specific fees to retrieve
  * @return  The resulting FeesResponse that matches the request
  */
 public async getFeesAsync(request: FeesRequest): Promise<FeesResponse> {
     assert.doesConformToSchema('request', request, clientSchemas.feesRequestSchema);
     const httpRequestOpts = {
         payload: request,
     };
     const responseJson = await this._requestAsync('/fees', HttpRequestType.Post, httpRequestOpts);
     const fees = relayerResponseJsonParsers.parseFeesResponseJson(responseJson);
     return fees;
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:14,代碼來源:http_client.ts

示例6: catch

        demandOption: false,
    })
    .option('export-environment', {
        alias: ['ee'],
        describe: 'The relative path to write the postman environment file used by the collection run',
        type: 'string',
        normalize: true,
        demandOption: false,
    })
    .example(
        "$0 --endpoint-url 'http://api.example.com' --out 'path/to/report.json' --network-id 42 --environment 'path/to/custom/environment.json' --export-collection 'path/to/collection.json' --export-environment 'path/to/environment.json'",
        'Full usage example',
    ).argv;
// perform extra validation on command line arguments
try {
    assert.isWebUri('args', args.endpointUrl);
} catch (err) {
    logUtils.log(`${chalk.red(`Invalid url format:`)} ${args.endpointUrl}`);
    process.exit(1);
}
if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) {
    logUtils.log(`${chalk.red(`Unsupported network id:`)} ${args.networkId}`);
    logUtils.log(`${chalk.bold(`Supported network ids:`)} ${SUPPORTED_NETWORK_IDS}`);
    process.exit(1);
}
const mainAsync = async () => {
    const newmanReporterOptions = !_.isUndefined(args.output)
        ? {
              reporters: 'json',
              reporter: {
                  json: {
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:31,代碼來源:index.ts

示例7: parse

import { assert } from '@0xproject/assert';
import { schemas } from '@0xproject/json-schemas';
import * as _ from 'lodash';

import { OrderbookChannelMessage, OrderbookChannelMessageTypes } from '../types';

import { relayerResponseJsonParsers } from './relayer_response_json_parsers';

export const orderbookChannelMessageParser = {
    parse(utf8Data: string): OrderbookChannelMessage {
        const messageObj = JSON.parse(utf8Data);
        const type: string = _.get(messageObj, 'type');
        assert.assert(!_.isUndefined(type), `Message is missing a type parameter: ${utf8Data}`);
        assert.isString('type', type);
        switch (type) {
            case OrderbookChannelMessageTypes.Snapshot: {
                assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrderbookChannelSnapshotSchema);
                const orderbookJson = messageObj.payload;
                const orderbook = relayerResponseJsonParsers.parseOrderbookResponseJson(orderbookJson);
                return _.assign(messageObj, { payload: orderbook });
            }
            case OrderbookChannelMessageTypes.Update: {
                assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrderbookChannelUpdateSchema);
                const orderJson = messageObj.payload;
                const order = relayerResponseJsonParsers.parseOrderJson(orderJson);
                return _.assign(messageObj, { payload: order });
            }
            default: {
                return {
                    type: OrderbookChannelMessageTypes.Unknown,
                    requestId: 0,
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:31,代碼來源:orderbook_channel_message_parser.ts

示例8: isValidSignature

import { ECSignature } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';

import { signatureUtils } from '../utils/signature_utils';

export const assert = {
    ...sharedAssert,
    isValidSignature(orderHash: string, ecSignature: ECSignature, signerAddress: string) {
        const isValidSignature = signatureUtils.isValidSignature(orderHash, ecSignature, signerAddress);
        this.assert(isValidSignature, `Expected order with hash '${orderHash}' to have a valid signature`);
    },
    async isSenderAddressAsync(
        variableName: string,
        senderAddressHex: string,
        web3Wrapper: Web3Wrapper,
    ): Promise<void> {
        sharedAssert.isETHAddressHex(variableName, senderAddressHex);
        const isSenderAddressAvailable = await web3Wrapper.isSenderAddressAvailableAsync(senderAddressHex);
        sharedAssert.assert(
            isSenderAddressAvailable,
            `Specified ${variableName} ${senderAddressHex} isn't available through the supplied web3 provider`,
        );
    },
    async isUserAddressAvailableAsync(web3Wrapper: Web3Wrapper): Promise<void> {
        const availableAddresses = await web3Wrapper.getAvailableAddressesAsync();
        this.assert(!_.isEmpty(availableAddresses), 'No addresses were available on the provided web3 provider');
    },
};
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:30,代碼來源:assert.ts

示例9: constructor

 /**
  * Instantiates a new HttpClient instance
  * @param   url    The relayer API base HTTP url you would like to interact with
  * @return  An instance of HttpClient
  */
 constructor(url: string) {
     assert.isWebUri('url', url);
     this._apiEndpointUrl = url.replace(TRAILING_SLASHES_REGEX, ''); // remove trailing slashes
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:9,代碼來源:http_client.ts

示例10: getOrderAsync

 /**
  * Retrieve a specific order from the API
  * @param   orderHash     An orderHash generated from the desired order
  * @return  The SignedOrder that matches the supplied orderHash
  */
 public async getOrderAsync(orderHash: string): Promise<SignedOrder> {
     assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
     const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get);
     const order = relayerResponseJsonParsers.parseOrderJson(responseJson);
     return order;
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:11,代碼來源:http_client.ts


注:本文中的@0xproject/assert.assert類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。