TypeScript @0xproject-utils.logUtils类(方法)实例源码

下面列出了TypeScript @0xproject-utils.logUtils 类(方法)源码代码实例,从而了解它的用法。

作者:ewingr    项目:0x-monorep   
return async () => {
     logUtils.log(`Processing ${tokenSymbol} ${recipientAddress}`);
     const amountToDispense = new BigNumber(DISPENSE_AMOUNT_TOKEN);
     const token = await zeroEx.tokenRegistry.getTokenBySymbolIfExistsAsync(tokenSymbol);
     if (_.isUndefined(token)) {
         throw new Error(`Unsupported asset type: ${tokenSymbol}`);
     }
     const baseUnitAmount = ZeroEx.toBaseUnitAmount(amountToDispense, token.decimals);
     const userBalanceBaseUnits = await zeroEx.token.getBalanceAsync(token.address, recipientAddress);
     const maxAmountBaseUnits = ZeroEx.toBaseUnitAmount(
         new BigNumber(DISPENSE_MAX_AMOUNT_TOKEN),
         token.decimals,
     );
     if (userBalanceBaseUnits.greaterThanOrEqualTo(maxAmountBaseUnits)) {
         logUtils.log(
             `User exceeded token balance maximum (${maxAmountBaseUnits}) ${recipientAddress} ${userBalanceBaseUnits} `,
         );
         return;
     }
     const txHash = await zeroEx.token.transferAsync(
         token.address,
         configs.DISPENSER_ADDRESS,
         recipientAddress,
         baseUnitAmount,
     );
     logUtils.log(`Sent ${amountToDispense} ZRX to ${recipientAddress} tx: ${txHash}`);
 };

作者:ewingr    项目:0x-monorep   
private async _instantiateContractIfExistsAsync(artifact: any, address?: string): Promise<ContractInstance> {
        const c = await contract(artifact);
        const providerObj = this._web3Wrapper.getProvider();
        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) {
                logUtils.log(`Contract does not exist: ${artifact.contract_name} at ${contractAddress}`);
                throw new Error(BlockchainCallErrs.ContractDoesNotExist);
            }
        }

        try {
            const contractInstance = _.isUndefined(address) ? await c.deployed() : await c.at(address);
            return contractInstance;
        } catch (err) {
            const errMsg = `${err}`;
            logUtils.log(`Notice: Error encountered: ${err} ${err.stack}`);
            if (_.includes(errMsg, 'not been deployed to detected network')) {
                throw new Error(BlockchainCallErrs.ContractDoesNotExist);
            } else {
                await errorReporter.reportAsync(err);
                throw new Error(BlockchainCallErrs.UnhandledError);
            }
        }
    }

作者:ewingr    项目:0x-monorep   
/**
  * Loads a contract's corresponding artifacts and deploys it with the supplied constructor arguments.
  * @param contractName Name of the contract to deploy. Must match name of an artifact in supplied artifacts directory.
  * @param args Array of contract constructor arguments.
  * @return Deployed contract instance.
  */
 public async deployAsync(contractName: string, args: any[] = []): Promise<Web3.ContractInstance> {
     const contractArtifactIfExists: ContractArtifact = this._loadContractArtifactIfExists(contractName);
     const contractNetworkDataIfExists: ContractNetworkData = this._getContractNetworkDataFromArtifactIfExists(
         contractArtifactIfExists,
     );
     const data = contractNetworkDataIfExists.bytecode;
     const from = await this._getFromAddressAsync();
     const gas = await this._getAllowableGasEstimateAsync(data);
     const txData = {
         gasPrice: this._defaults.gasPrice,
         from,
         data,
         gas,
     };
     const abi = contractNetworkDataIfExists.abi;
     const constructorAbi = _.find(abi, { type: AbiType.Constructor }) as ConstructorAbi;
     const constructorArgs = _.isUndefined(constructorAbi) ? [] : constructorAbi.inputs;
     if (constructorArgs.length !== args.length) {
         const constructorSignature = `constructor(${_.map(constructorArgs, arg => `${arg.type} ${arg.name}`).join(
             ', ',
         )})`;
         throw new Error(
             `${contractName} expects ${constructorArgs.length} constructor params: ${constructorSignature}. Got ${
                 args.length
             }`,
         );
     }
     const web3ContractInstance = await this._deployFromAbiAsync(abi, args, txData);
     logUtils.log(`${contractName}.sol successfully deployed at ${web3ContractInstance.address}`);
     const contractInstance = new Contract(web3ContractInstance, this._defaults);
     return contractInstance;
 }

作者:ewingr    项目:0x-monorep   
rollbar.handleError(err, req, (rollbarErr: Error) => {
     if (rollbarErr) {
         logUtils.log(`Error reporting to rollbar, ignoring: ${rollbarErr}`);
         reject(rollbarErr);
     } else {
         resolve();
     }
 });

作者:ewingr    项目:0x-monorep   
const noThrowFnAsync = async (arg: T) => {
     try {
         const result = await asyncFn(arg);
         return result;
     } catch (err) {
         logUtils.log(`${err}`);
     }
 };

作者:ewingr    项目:0x-monorep   
function registerPartials(partialsGlob: string) {
    const partialTemplateFileNames = globSync(partialsGlob);
    logUtils.log(`Found ${chalk.green(`${partialTemplateFileNames.length}`)} ${chalk.bold('partial')} templates`);
    for (const partialTemplateFileName of partialTemplateFileNames) {
        const namedContent = utils.getNamedContent(partialTemplateFileName);
        Handlebars.registerPartial(namedContent.name, namedContent.content);
    }
    return partialsGlob;
}

作者:ewingr    项目:0x-monorep   
function writeOutputFile(name: string, renderedTsCode: string): void {
    let fileName = toSnakeCase(name);
    if (fileName === 'z_r_x_token') {
        fileName = 'zrx_token';
    }
    const filePath = `${args.output}/${fileName}.ts`;
    fs.writeFileSync(filePath, renderedTsCode);
    logUtils.log(`Created: ${chalk.bold(filePath)}`);
}

作者:ewingr    项目:0x-monorep   
(contract as any).new(...args, txData, (err: Error, res: any): any => {
     if (err) {
         reject(err);
     } else if (_.isUndefined(res.address) && !_.isUndefined(res.transactionHash)) {
         logUtils.log(`transactionHash: ${res.transactionHash}`);
     } else {
         resolve(res);
     }
 });

作者:ewingr    项目:0x-monorep   
rollbar.error(err, (rollbarErr: Error) => {
     if (rollbarErr) {
         logUtils.log(`Error reporting to rollbar, ignoring: ${rollbarErr}`);
         // We never want to reject and cause the app to throw because of rollbar
         resolve();
     } else {
         resolve();
     }
 });


问题


面经


文章

微信
公众号

扫码关注公众号