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


TypeScript Web3Wrapper.getBlockTimestampAsync方法代码示例

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


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

示例1:

 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


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