• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript knex.first函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: updateMarketOpenInterest

export async function updateMarketOpenInterest(db: Knex, marketId: Address) {
  const marketRow: {
    category: string,
    numTicks: BigNumber,
    openInterest: BigNumber,
    reportingState: ReportingState,
  } | undefined = await db.first([
    "markets.category as category",
    "markets.numTicks as numTicks",
    "markets.openInterest as openInterest",
    "market_state.reportingState as reportingState",
  ]).from("markets")
    .leftJoin("market_state", "markets.marketStateId", "market_state.marketStateId")
    .where({ "markets.marketId": marketId });
  if (marketRow == null) throw new Error(`No marketId for openInterest: ${marketId}`);

  const shareTokenRow: { supply: BigNumber } | undefined = await db.first("supply").from("token_supply").join("tokens", "token_supply.token", "tokens.contractAddress").where({
    marketId,
    symbol: "shares",
  });
  if (shareTokenRow == null) throw new Error(`No shareToken supply found for market: ${marketId}`);

  const newOpenInterestInETHString: string = convertFixedPointToDecimal(shareTokenRow.supply.multipliedBy(marketRow.numTicks), WEI_PER_ETHER);
  await db("markets").update({ openInterest: newOpenInterestInETHString }).where({ marketId });

  const newOpenInterestInETH = new BigNumber(newOpenInterestInETHString, 10);
  await updateCategoryAggregationsOnMarketOpenInterestChanged({
    db,
    categoryName: marketRow.category,
    reportingState: marketRow.reportingState,
    newOpenInterest: newOpenInterestInETH,
    oldOpenInterest: marketRow.openInterest,
  });
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:34,代码来源:update-volumetrics.ts


示例2: async

  return async(db: Knex) => {
    const amount: BigNumber = new BigNumber(log.amount, 10);
    const price: BigNumber = new BigNumber(log.price, 10);
    const orderType: string = log.orderType;
    const moneyEscrowed: BigNumber = new BigNumber(log.moneyEscrowed, 10);
    const sharesEscrowed: BigNumber = new BigNumber(log.sharesEscrowed, 10);
    const shareToken: Address = log.shareToken;
    const tokensRow: TokensRow|undefined = await db.first("marketId", "outcome").from("tokens").where({ contractAddress: shareToken });
    if (!tokensRow) throw new Error(`market and outcome not found for shareToken ${shareToken} (${log.transactionHash}`);
    const marketId = tokensRow.marketId;
    const outcome = tokensRow.outcome!;
    const marketsRow: MarketsRow<BigNumber> = await db.first("minPrice", "maxPrice", "numTicks", "numOutcomes").from("markets").where({ marketId });
    if (!marketsRow) throw new Error(`market not found: ${marketId}`);
    const minPrice = marketsRow.minPrice;
    const maxPrice = marketsRow.maxPrice;
    const numTicks = marketsRow.numTicks;
    const tickSize = numTicksToTickSize(numTicks, minPrice, maxPrice);
    const numOutcomes = marketsRow.numOutcomes;
    const fullPrecisionAmount = augur.utils.convertOnChainAmountToDisplayAmount(amount, tickSize);
    const fullPrecisionPrice = augur.utils.convertOnChainPriceToDisplayPrice(price, minPrice, tickSize);
    const orderTypeLabel = orderType === "0" ? "buy" : "sell";
    const displaySharesEscrowed = augur.utils.convertOnChainAmountToDisplayAmount(sharesEscrowed, tickSize).toString();
    const displayTokensEscrowed = fixedPointToDecimal(moneyEscrowed, BN_WEI_PER_ETHER).toString();
    const orderData: OrdersRow<string> = {
      marketId,
      blockNumber: log.blockNumber,
      transactionHash: log.transactionHash,
      logIndex: log.logIndex,
      outcome,
      shareToken,
      orderCreator: log.creator,
      orderState: OrderState.OPEN,
      tradeGroupId: log.tradeGroupId,
      orderType: orderTypeLabel,
      price: formatOrderPrice(orderTypeLabel, minPrice, maxPrice, fullPrecisionPrice),
      amount: formatOrderAmount(fullPrecisionAmount),
      originalAmount: formatOrderAmount(fullPrecisionAmount),
      fullPrecisionPrice: fullPrecisionPrice.toString(),
      fullPrecisionAmount: fullPrecisionAmount.toString(),
      originalFullPrecisionAmount: fullPrecisionAmount.toString(),
      originalTokensEscrowed: displayTokensEscrowed,
      originalSharesEscrowed: displaySharesEscrowed,
      tokensEscrowed: displayTokensEscrowed,
      sharesEscrowed: displaySharesEscrowed,
    };
    const orderId = { orderId: log.orderId };
    const ordersRows: Array<Partial<OrdersRow<BigNumber>>> = await db.select("marketId").from("orders").where(orderId);
    let upsertOrder: QueryBuilder;
    if (!ordersRows || !ordersRows.length) {
      upsertOrder = db.insert(Object.assign(orderData, orderId)).into("orders");
    } else {
      upsertOrder = db.from("orders").where(orderId).update(orderData);
    }
    await upsertOrder;
    await marketPendingOrphanCheck(db, orderData);

    augurEmitter.emit(SubscriptionEventNames.OrderCreated, Object.assign({}, log, orderData));
  };
开发者ID:AugurProject,项目名称:augur_node,代码行数:58,代码来源:order-created.ts


示例3: updateVolumetrics

export async function updateVolumetrics(db: Knex, augur: Augur, category: string, marketId: Address, outcome: number, blockNumber: number, orderId: Bytes32, orderCreator: Address, tickSize: BigNumber, minPrice: BigNumber, maxPrice: BigNumber, isIncrease: boolean) {
  const shareTokenRow: { supply: BigNumber } = await db.first("token_supply.supply").from("tokens").join("token_supply", "token_supply.token", "tokens.contractAddress").where({ outcome, marketId });
  if (shareTokenRow == null) throw new Error(`No shareToken found for market: ${marketId} outcome: ${outcome}`);
  const sharesOutstanding = augur.utils.convertOnChainAmountToDisplayAmount(new BigNumber(shareTokenRow.supply, 10), tickSize).toString();
  await db("markets").where({ marketId }).update({ sharesOutstanding });
  const tradesRow: TradesRow<BigNumber> | undefined = await db.first("numCreatorShares", "numCreatorTokens", "numFillerTokens", "numFillerShares", "amount").from("trades")
    .where({ marketId, outcome, orderId, blockNumber });
  if (!tradesRow) throw new Error(`trade not found, orderId: ${orderId}`);
  let amount = tradesRow.amount!;
  if (!isIncrease) amount = amount.negated();
  await incrementMarketVolume(db, marketId, amount, tradesRow, isIncrease);
  await incrementOutcomeVolume(db, marketId, outcome, amount, tradesRow, isIncrease);
  await setMarketLastTrade(db, marketId, blockNumber);
  await updateMarketOpenInterest(db, marketId);
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:15,代码来源:update-volumetrics.ts


示例4: async

  return async (db: Knex) => {
    const shareToken: Address = log.shareToken;
    const blockNumber: number = log.blockNumber;
    const tokensRow: TokensRowWithNumTicksAndCategory|undefined = await db.first("tokens.marketId", "tokens.outcome", "markets.numTicks", "markets.category", "markets.minPrice", "markets.maxPrice").from("tokens").join("markets", "tokens.marketId", "markets.marketId").where("tokens.contractAddress", shareToken);

    if (!tokensRow) throw new Error(`market and outcome not found for ShareToken: ${shareToken} (${log.transactionHash})`);
    const marketId = tokensRow.marketId;
    const outcome = tokensRow.outcome!;
    const numTicks = tokensRow.numTicks;
    const minPrice = tokensRow.minPrice;
    const maxPrice = tokensRow.maxPrice;
    const category = tokensRow.category;
    const orderId = log.orderId;
    const ordersRow: OrdersRow<BigNumber>|undefined = await db.first("orderCreator", "fullPrecisionPrice", "orderType").from("orders").where({ orderId });

    if (!ordersRow) throw new Error(`order not found, orderId: ${orderId} (${log.transactionHash}`);
    const orderCreator = ordersRow.orderCreator;
    const price = ordersRow.fullPrecisionPrice;
    const orderType = ordersRow.orderType;
    const tickSize = numTicksToTickSize(numTicks, minPrice, maxPrice);
    const numCreatorTokens = fixedPointToDecimal(new BigNumber(log.numCreatorTokens), BN_WEI_PER_ETHER);
    const numCreatorShares = augur.utils.convertOnChainAmountToDisplayAmount(new BigNumber(log.numCreatorShares, 10), new BigNumber(tickSize, 10));
    const numFillerTokens = fixedPointToDecimal(new BigNumber(log.numFillerTokens), BN_WEI_PER_ETHER);
    const numFillerShares = augur.utils.convertOnChainAmountToDisplayAmount(new BigNumber(log.numFillerShares, 10), new BigNumber(tickSize, 10));
    const marketCreatorFees = fixedPointToDecimal(new BigNumber(log.marketCreatorFees), BN_WEI_PER_ETHER);
    const reporterFees = fixedPointToDecimal(new BigNumber(log.reporterFees), BN_WEI_PER_ETHER);
    const amount = augur.utils.convertOnChainAmountToDisplayAmount(new BigNumber(log.amountFilled, 10), tickSize);

    await updateVolumetrics(db, augur, category, marketId, outcome, blockNumber, orderId, orderCreator, tickSize, minPrice, maxPrice, false);
    await db.from("trades").where({ marketId, outcome, orderId, blockNumber }).del();
    await updateOrder(db, augur, marketId, orderId, amount.negated(), price, numCreatorShares.negated(), numCreatorTokens.negated());
    augurEmitter.emit(SubscriptionEventNames.OrderFilled, Object.assign({}, log, {
      marketId,
      outcome,
      creator: orderCreator,
      orderType,
      numCreatorTokens,
      numCreatorShares,
      numFillerTokens,
      numFillerShares,
      price,
      amount,
      marketCreatorFees,
      reporterFees,
    }));
    await removeOutcomeValue(db, log.transactionHash);
    await updateProfitLossRemoveRow(db, log.transactionHash);
  };
开发者ID:AugurProject,项目名称:augur_node,代码行数:48,代码来源:index.ts


示例5: decreaseTokenSupply

export async function decreaseTokenSupply(db: Knex, augur: Augur, token: Address, amount: BigNumber) {
  const oldSupply: SupplyResult|null = await db.first("supply").from("token_supply").where({ token });
  if (amount.isZero()) return;
  if (oldSupply == null) throw new Error(`Could not find supply for token decrease (token: ${token})`);
  const supply = oldSupply.supply.minus(amount);
  return db.update({ supply: supply.toString() }).into("token_supply").where({ token });
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:7,代码来源:decrease-token-supply.ts


示例6: async

 return async (db: Knex) => {
   const marketId = log.market;
   const marketsRow: MarketsRow<BigNumber>|undefined = await db.first("minPrice", "maxPrice", "numTicks", "numOutcomes").from("markets").where({ marketId });
   if (!marketsRow) throw new Error(`market not found: ${marketId}`);
   const minPrice = marketsRow.minPrice;
   const maxPrice = marketsRow.maxPrice;
   const numTicks = marketsRow.numTicks;
   const numOutcomes = marketsRow.numOutcomes;
   const tickSize = numTicksToTickSize(numTicks, minPrice, maxPrice);
   const numCompleteSets = augur.utils.convertOnChainAmountToDisplayAmount(new BigNumber(log.numCompleteSets, 10), tickSize);
   const completeSetPurchasedData: CompleteSetsRow<string> = {
     marketId,
     account: log.account,
     blockNumber: log.blockNumber,
     universe: log.universe,
     eventName: log.eventName,
     transactionHash: log.transactionHash,
     logIndex: log.logIndex,
     numCompleteSets: numCompleteSets.toString(),
     numPurchasedOrSold: numCompleteSets.toString(),
   };
   const eventName = log.eventName as keyof typeof SubscriptionEventNames;
   await db.insert(completeSetPurchasedData).into("completeSets");
   augurEmitter.emit(SubscriptionEventNames[eventName], completeSetPurchasedData);
   await updateMarketOpenInterest(db, marketId);
 };
开发者ID:AugurProject,项目名称:augur_node,代码行数:26,代码来源:completesets.ts


示例7: updateOutcomeValuesFromFinalization

export async function updateOutcomeValuesFromFinalization(db: Knex, augur: Augur, marketId: Address, transactionHash: string, blockNumber: number, logIndex: number): Promise<void> {
  const payouts: PayoutAndMarket<BigNumber> = await db
    .first(["payouts.payout0", "payouts.payout1", "payouts.payout2", "payouts.payout3", "payouts.payout4", "payouts.payout5", "payouts.payout6", "payouts.payout7", "markets.minPrice", "markets.maxPrice", "markets.numTicks"])
    .from("payouts")
    .where("payouts.marketId", marketId)
    .join("markets", function() {
      this.on("payouts.marketId", "markets.marketId");
    });
  const timestamp = getCurrentTime();
  const maxPrice = payouts.maxPrice;
  const minPrice = payouts.minPrice;
  const numTicks = payouts.numTicks;
  const tickSize = numTicksToTickSize(numTicks, minPrice, maxPrice);
  const insertValues = [];
  for (let i: number = 0; i <= 7; i++) {
    const column = `payout${i}`;
    const payoutValue = payouts[column as keyof PayoutAndMarket<BigNumber>];
    if (payoutValue != null) {
      const value = payoutValue.times(tickSize).plus(minPrice);
      insertValues.push({
        marketId,
        transactionHash,
        blockNumber,
        logIndex,
        outcome: i,
        value: value.toString(),
        timestamp,
      });
    }
  }
  await db.insert(insertValues).into("outcome_value_timeseries");
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:32,代码来源:update-outcome-value.ts


示例8: getOrphanedOrderIds

async function getOrphanedOrderIds(db: Knex, augur: Augur, orderData: PendingOrphanedOrderData): Promise<Array<string>> {
  const queryData = {
    marketId: orderData.marketId,
    outcome: orderData.outcome,
    orderType: orderData.orderType,
    orderState: OrderState.OPEN,
    orphaned: 0,
  };

  const results: { numOrders: number } = await db.first(db.raw("count(*) as numOrders")).from("orders").where(queryData);

  if (results.numOrders < 1) return [];

  const requestData = {
    _type: orderData.orderType === "buy" ? 0 : 1,
    _market: orderData.marketId,
    _outcome: orderData.outcome,
  };
  // Use the function that will return the least amount of data assuming we're close to the right number of orders currently. Failure is expected when syncing and will correct later
  let getExistingOrders: ApiFunction;
  if (results.numOrders >= 500) {
    getExistingOrders = augur.api.OrdersFinder.getExistingOrders1000;
  } else if (results.numOrders >= 200) {
    getExistingOrders = augur.api.OrdersFinder.getExistingOrders500;
  } else if (results.numOrders >= 100) {
    getExistingOrders = augur.api.OrdersFinder.getExistingOrders200;
  } else if (results.numOrders >= 50) {
    getExistingOrders = augur.api.OrdersFinder.getExistingOrders100;
  } else {
    getExistingOrders = augur.api.OrdersFinder.getExistingOrders50;
  }

  return await getExistingOrders(requestData);
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:34,代码来源:check-orphaned-orders.ts


示例9: queryUniverse

async function queryUniverse(db: Knex, marketId: Address): Promise<Address> {
  const market = await db
    .first("universe")
    .from("markets")
    .where({ marketId });
  if (!market || market.universe == null) throw new Error("If universe isn't provided, you must provide a valid marketId");
  return market.universe;
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:8,代码来源:get-user-trading-positions.ts


示例10: async

 return async (db: Knex) => {
   const orderTypeLabel = log.orderType === "0" ? "buy" : "sell";
   await db.from("orders").where("orderId", log.orderId).update({ orderState: OrderState.OPEN });
   await db.from("orders_canceled").where("orderId", log.orderId).delete();
   const ordersRow: MarketIDAndOutcomeAndPrice = await db.first("marketId", "outcome", "price").from("orders").where("orderId", log.orderId);
   if (ordersRow) ordersRow.orderType = orderTypeLabel;
   augurEmitter.emit(SubscriptionEventNames.OrderCanceled, Object.assign({}, log, ordersRow));
 };
开发者ID:AugurProject,项目名称:augur_node,代码行数:8,代码来源:order-canceled.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript knex.from函数代码示例发布时间:2022-05-25
下一篇:
TypeScript knex.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap