当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript utils.promisify函数代码示例

本文整理汇总了TypeScript中@0xproject/utils.promisify函数的典型用法代码示例。如果您正苦于以下问题:TypeScript promisify函数的具体用法?TypeScript promisify怎么用?TypeScript promisify使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了promisify函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

    it('clears the cache on a Nonce Too Low Error', async () => {
        provider = new Web3ProviderEngine();
        const nonceTrackerSubprovider = new NonceTrackerSubprovider();
        provider.addProvider(nonceTrackerSubprovider);
        provider.addProvider(createFixtureSubprovider());
        provider.addProvider(
            new FixtureSubprovider({
                eth_sendRawTransaction: (data: any, next: any, end: any) => {
                    end(new Error('Transaction nonce is too low'));
                },
            }),
        );
        provider.start();

        const noncePayload = {
            ...getTransactionCountPayload,
            params: ['0x1f36f546477cda21bf2296c50976f2740247906f', 'pending'],
        };
        const transaction = new EthereumTx(txParams);
        const txPayload = {
            ...sendTransactionPayload,
            params: [transaction.serialize()],
        };

        const response = await promisify<any>(provider.sendAsync, provider)(noncePayload);
        expect(response.result).to.be.eq('0x00');
        const secondResponse = await promisify<any>(provider.sendAsync, provider)(noncePayload);
        expect(secondResponse.result).to.be.eq('0x00');
        try {
            await promisify(provider.sendAsync, provider)(txPayload);
        } catch (err) {
            const thirdResponse = await promisify<any>(provider.sendAsync, provider)(noncePayload);
            expect(thirdResponse.result).to.be.eq('0x99');
        }
    });
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:35,代码来源:nonce_tracker_subprovider_test.ts

示例2: promisify

 _.forEach(functionsAbi, (functionAbi: MethodAbi) => {
     if (functionAbi.constant) {
         const cbStyleCallFunction = this._contract[functionAbi.name].call;
         this[functionAbi.name] = promisify(cbStyleCallFunction, this._contract);
         this[functionAbi.name].call = promisify(cbStyleCallFunction, this._contract);
     } else {
         const cbStyleFunction = this._contract[functionAbi.name];
         const cbStyleCallFunction = this._contract[functionAbi.name].call;
         const cbStyleEstimateGasFunction = this._contract[functionAbi.name].estimateGas;
         this[functionAbi.name] = this._promisifyWithDefaultParams(cbStyleFunction);
         this[functionAbi.name].estimateGasAsync = promisify(cbStyleEstimateGasFunction);
         this[functionAbi.name].sendTransactionAsync = this._promisifyWithDefaultParams(cbStyleFunction);
         this[functionAbi.name].call = promisify(cbStyleCallFunction, this._contract);
     }
 });
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:15,代码来源:contract.ts

示例3: async

 return async () => {
     logUtils.log(`Processing ETH ${recipientAddress}`);
     const userBalance = await promisify<BigNumber>(web3.eth.getBalance)(recipientAddress);
     const maxAmountInWei = new BigNumber(web3.toWei(DISPENSE_MAX_AMOUNT_ETHER, 'ether'));
     if (userBalance.greaterThanOrEqualTo(maxAmountInWei)) {
         logUtils.log(
             `User exceeded ETH balance maximum (${maxAmountInWei}) ${recipientAddress} ${userBalance} `,
         );
         return;
     }
     const sendTransactionAsync = promisify(web3.eth.sendTransaction);
     const txHash = await sendTransactionAsync({
         from: configs.DISPENSER_ADDRESS,
         to: recipientAddress,
         value: web3.toWei(DISPENSE_AMOUNT_ETHER, 'ether'),
     });
     logUtils.log(`Sent ${DISPENSE_AMOUNT_ETHER} ETH to ${recipientAddress} tx: ${txHash}`);
 };
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:18,代码来源:dispense_asset_tasks.ts

示例4: _onPageLoadInitFireAndForgetAsync

    private async _onPageLoadInitFireAndForgetAsync() {
        await utils.onPageLoadAsync(); // wait for page to load

        // Hack: We need to know the networkId the injectedWeb3 is connected to (if it is defined) in
        // order to properly instantiate the web3Wrapper. Since we must use the async call, we cannot
        // retrieve it from within the web3Wrapper constructor. This is and should remain the only
        // call to a web3 instance outside of web3Wrapper in the entire dapp.
        // In addition, if the user has an injectedWeb3 instance that is disconnected from a backing
        // Ethereum node, this call will throw. We need to handle this case gracefully
        const injectedWeb3 = (window as any).web3;
        let networkIdIfExists: number;
        if (!_.isUndefined(injectedWeb3)) {
            try {
                networkIdIfExists = _.parseInt(await promisify<string>(injectedWeb3.version.getNetwork)());
            } catch (err) {
                // Ignore error and proceed with networkId undefined
            }
        }

        const provider = await Blockchain._getProviderAsync(injectedWeb3, networkIdIfExists);
        this.networkId = !_.isUndefined(networkIdIfExists)
            ? networkIdIfExists
            : configs.IS_MAINNET_ENABLED ? constants.NETWORK_ID_MAINNET : constants.NETWORK_ID_KOVAN;
        this._dispatcher.updateNetworkId(this.networkId);
        const zeroExConfigs = {
            networkId: this.networkId,
        };
        this._zeroEx = new ZeroEx(provider, zeroExConfigs);
        this._updateProviderName(injectedWeb3);
        const shouldPollUserAddress = true;
        this._web3Wrapper = new Web3Wrapper(provider);
        this._blockchainWatcher = new BlockchainWatcher(
            this._dispatcher,
            this._web3Wrapper,
            this.networkId,
            shouldPollUserAddress,
        );

        const userAddresses = await this._web3Wrapper.getAvailableAddressesAsync();
        this._userAddressIfExists = userAddresses[0];
        this._dispatcher.updateUserAddress(this._userAddressIfExists);
        await this.fetchTokenInformationAsync();
        this._blockchainWatcher.startEmittingNetworkConnectionAndUserBalanceState();
        await this._rehydrateStoreWithContractEvents();
    }
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:45,代码来源:blockchain.ts

示例5: _firstSuccessAsync

 private static async _firstSuccessAsync(
     rpcs: RpcSubprovider[],
     payload: JSONRPCRequestPayload,
     next: Callback,
 ): Promise<any> {
     let lastErr: Error | undefined;
     for (const rpc of rpcs) {
         try {
             const data = await promisify(rpc.handleRequest.bind(rpc))(payload, next);
             return data;
         } catch (err) {
             lastErr = err;
             continue;
         }
     }
     if (!_.isUndefined(lastErr)) {
         throw lastErr;
     }
 }
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:19,代码来源:redundant_rpc.ts

示例6:

import { promisify } from '@0xproject/utils';
import * as fs from 'fs';

export const fsWrapper = {
    readdirAsync: promisify<string[]>(fs.readdir),
    readFileAsync: promisify<string>(fs.readFile),
    writeFileAsync: promisify<undefined>(fs.writeFile),
    mkdirAsync: promisify<undefined>(fs.mkdir),
    doesPathExistSync: fs.existsSync,
    rmdirSync: fs.rmdirSync,
    removeFileAsync: promisify<undefined>(fs.unlink),
};
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:12,代码来源:fs_wrapper.ts

示例7:

import { promisify } from '@0xproject/utils';
import { NewmanRunSummary, run as newmanRun } from 'newman';

export const utils = {
    newmanRunAsync: promisify<NewmanRunSummary>(newmanRun),
};
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:6,代码来源:utils.ts


注:本文中的@0xproject/utils.promisify函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。