當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。