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


TypeScript web3_wrapper.Web3Wrapper类代码示例

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


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

示例1: providerTypeUpdatedFireAndForgetAsync

    public async providerTypeUpdatedFireAndForgetAsync(providerType: ProviderType) {
        utils.assert(!_.isUndefined(this.zeroEx), 'ZeroEx must be instantiated.');
        // Should actually be Web3.Provider|ProviderEngine union type but it causes issues
        // later on in the logic.
        let provider;
        switch (providerType) {
            case ProviderType.LEDGER: {
                const isU2FSupported = await utils.isU2FSupportedAsync();
                if (!isU2FSupported) {
                    throw new Error('Cannot update providerType to LEDGER without U2F support');
                }

                // Cache injected provider so that we can switch the user back to it easily
                this.cachedProvider = this.web3Wrapper.getProviderObj();

                this.dispatcher.updateUserAddress(''); // Clear old userAddress

                provider = new ProviderEngine();
                this.ledgerSubProvider = ledgerWalletSubproviderFactory(this.getBlockchainNetworkId.bind(this));
                provider.addProvider(this.ledgerSubProvider);
                provider.addProvider(new FilterSubprovider());
                const networkId = configs.isMainnetEnabled ?
                    constants.MAINNET_NETWORK_ID :
                    constants.TESTNET_NETWORK_ID;
                provider.addProvider(new RedundantRPCSubprovider(
                    constants.PUBLIC_NODE_URLS_BY_NETWORK_ID[networkId],
                ));
                provider.start();
                this.web3Wrapper.destroy();
                const shouldPollUserAddress = false;
                this.web3Wrapper = new Web3Wrapper(this.dispatcher, provider, this.networkId, shouldPollUserAddress);
                await this.zeroEx.setProviderAsync(provider);
                await this.postInstantiationOrUpdatingProviderZeroExAsync();
                break;
            }

            case ProviderType.INJECTED: {
                if (_.isUndefined(this.cachedProvider)) {
                    return; // Going from injected to injected, so we noop
                }
                provider = this.cachedProvider;
                const shouldPollUserAddress = true;
                this.web3Wrapper = new Web3Wrapper(this.dispatcher, provider, this.networkId, shouldPollUserAddress);
                await this.zeroEx.setProviderAsync(provider);
                await this.postInstantiationOrUpdatingProviderZeroExAsync();
                delete this.ledgerSubProvider;
                delete this.cachedProvider;
                break;
            }

            default:
                throw utils.spawnSwitchErr('providerType', providerType);
        }

        await this.fetchTokenInformationAsync();
    }
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:56,代码来源:blockchain.ts

示例2: updateWeb3WrapperPrevUserAddress

 // HACK: When a user is using a Ledger, we simply dispatch the selected userAddress, which
 // by-passes the web3Wrapper logic for updating the prevUserAddress. We therefore need to
 // manually update it. This should only be called by the LedgerConfigDialog.
 public updateWeb3WrapperPrevUserAddress(newUserAddress: string) {
     this.web3Wrapper.updatePrevUserAddress(newUserAddress);
 }
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:6,代码来源:blockchain.ts

示例3: fetchTokenInformationAsync

    private async fetchTokenInformationAsync() {
        utils.assert(!_.isUndefined(this.networkId),
                     'Cannot call fetchTokenInformationAsync if disconnected from Ethereum node');

        this.dispatcher.updateBlockchainIsLoaded(false);
        this.dispatcher.clearTokenByAddress();
        const tokenArrays = await Promise.all([
                this.getTokenRegistryTokensAsync(),
                this.getCustomTokensAsync(),
        ]);
        const tokens = _.flatten(tokenArrays);
        // HACK: We need to fetch the userAddress here because otherwise we cannot fetch the token
        // balances and allowances and we need to do this in order not to trigger the blockchain
        // loading dialog to show up twice. First to load the contracts, and second to load the
        // balances and allowances.
        this.userAddress = await this.web3Wrapper.getFirstAccountIfExistsAsync();
        if (!_.isEmpty(this.userAddress)) {
            this.dispatcher.updateUserAddress(this.userAddress);
        }
        await this.updateTokenBalancesAndAllowancesAsync(tokens);
        const mostPopularTradingPairTokens: Token[] = [
            _.find(tokens, {symbol: configs.mostPopularTradingPairSymbols[0]}),
            _.find(tokens, {symbol: configs.mostPopularTradingPairSymbols[1]}),
        ];
        this.dispatcher.updateChosenAssetTokenAddress(Side.deposit, mostPopularTradingPairTokens[0].address);
        this.dispatcher.updateChosenAssetTokenAddress(Side.receive, mostPopularTradingPairTokens[1].address);
        this.dispatcher.updateBlockchainIsLoaded(true);
    }
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:28,代码来源:blockchain.ts

示例4:

 exchangeLogFillEventEmitter.watch(async (err: Error, event: ContractEvent) => {
     if (err) {
         // Note: it's not entirely clear from the documentation which
         // errors will be thrown by `watch`. For now, let's log the error
         // to rollbar and stop watching when one occurs
         errorReporter.reportAsync(err); // fire and forget
         this.stopWatchingExchangeLogFillEventsAsync(); // fire and forget
         return;
     } else {
         const args = event.args as LogFillContractEventArgs;
         const isBlockPending = _.isNull(event.blockNumber);
         if (!isBlockPending) {
             // Hack: I've observed the behavior where a client won't register certain fill events
             // and lowering the cache blockNumber fixes the issue. As a quick fix for now, simply
             // set the cached blockNumber 50 below the one returned. This way, upon refreshing, a user
             // would still attempt to re-fetch events from the previous 50 blocks, but won't need to
             // re-fetch all events in all blocks.
             // TODO: Debug if this is a race condition, and apply a more precise fix
             const blockNumberToSet = event.blockNumber - 50 < 0 ? 0 : event.blockNumber - 50;
             tradeHistoryStorage.setFillsLatestBlock(this.userAddress, this.networkId, blockNumberToSet);
         }
         const isUserMakerOrTaker = args.maker === this.userAddress ||
                                    args.taker === this.userAddress;
         if (!isUserMakerOrTaker) {
             return; // We aren't interested in the fill event
         }
         const blockTimestamp = await this.web3Wrapper.getBlockTimestampAsync(event.blockHash);
         const fill = {
             filledTakerTokenAmount: args.filledTakerTokenAmount,
             filledMakerTokenAmount: args.filledMakerTokenAmount,
             logIndex: event.logIndex,
             maker: args.maker,
             orderHash: args.orderHash,
             taker: args.taker,
             makerToken: args.makerToken,
             takerToken: args.takerToken,
             paidMakerFee: args.paidMakerFee,
             paidTakerFee: args.paidTakerFee,
             transactionHash: event.transactionHash,
             blockTimestamp,
         };
         tradeHistoryStorage.addFillToUser(this.userAddress, this.networkId, fill);
     }
 });
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:44,代码来源:blockchain.ts

示例5: instantiateContractIfExistsAsync

    private async instantiateContractIfExistsAsync(artifact: any, address?: string): Promise<ContractInstance> {
        const c = await contract(artifact);
        const providerObj = this.web3Wrapper.getProviderObj();
        c.setProvider(providerObj);

        const artifactNetworkConfigs = artifact.networks[this.networkId];
        let contractAddress;
        if (!_.isUndefined(address)) {
            contractAddress = address;
        } else if (!_.isUndefined(artifactNetworkConfigs)) {
            contractAddress = artifactNetworkConfigs.address;
        }

        if (!_.isUndefined(contractAddress)) {
            const doesContractExist = await this.doesContractExistAtAddressAsync(contractAddress);
            if (!doesContractExist) {
                utils.consoleLog(`Contract does not exist: ${artifact.contract_name} at ${contractAddress}`);
                throw new Error(BlockchainCallErrs.CONTRACT_DOES_NOT_EXIST);
            }
        }

        try {
            let contractInstance;
            if (_.isUndefined(address)) {
                contractInstance = await c.deployed();
            } else {
                contractInstance = await c.at(address);
            }
            return contractInstance;
        } catch (err) {
            const errMsg = `${err}`;
            utils.consoleLog(`Notice: Error encountered: ${err} ${err.stack}`);
            if (_.includes(errMsg, 'not been deployed to detected network')) {
                throw new Error(BlockchainCallErrs.CONTRACT_DOES_NOT_EXIST);
            } else {
                await errorReporter.reportAsync(err);
                throw new Error(BlockchainCallErrs.UNHANDLED_ERROR);
            }
        }
    }
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:40,代码来源:blockchain.ts

示例6: destroy

 public destroy() {
     clearInterval(this.zrxPollIntervalId);
     this.web3Wrapper.destroy();
     this.stopWatchingExchangeLogFillEventsAsync(); // fire and forget
 }
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:5,代码来源:blockchain.ts

示例7: doesContractExistAtAddressAsync

 public async doesContractExistAtAddressAsync(address: string) {
     return await this.web3Wrapper.doesContractExistAtAddressAsync(address);
 }
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:3,代码来源:blockchain.ts

示例8: getBalanceInEthAsync

 public async getBalanceInEthAsync(owner: string): Promise<BigNumber.BigNumber> {
     const balance = await this.web3Wrapper.getBalanceInEthAsync(owner);
     return balance;
 }
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:4,代码来源:blockchain.ts

示例9: isValidAddress

 public isValidAddress(address: string): boolean {
     const lowercaseAddress = address.toLowerCase();
     return this.web3Wrapper.isAddress(lowercaseAddress);
 }
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:4,代码来源:blockchain.ts


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