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


TypeScript knex.first函数代码示例

本文整理汇总了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;未经允许,请勿转载。