本文整理汇总了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);
}
});