@prisma/client#Deposit TypeScript Examples

The following examples show how to use @prisma/client#Deposit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: deposits.service.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
async findOrThrow(id: number): Promise<Deposit> {
    const deposit = await this.find(id);

    if (!deposit) {
      throw new NotFoundException();
    }

    return deposit;
  }
Example #2
Source File: deposits.service.ts    From ironfish-api with Mozilla Public License 2.0 5 votes vote down vote up
async find(id: number): Promise<Deposit | null> {
    return this.prisma.deposit.findUnique({
      where: {
        id,
      },
    });
  }
Example #3
Source File: deposits.upsert.service.ts    From ironfish-api with Mozilla Public License 2.0 4 votes vote down vote up
async upsert(operation: UpsertDepositsOperationDto): Promise<Deposit[]> {
    const networkVersion = this.config.get<number>('NETWORK_VERSION');
    const deposits = new Array<Deposit>();

    for (const transaction of operation.transactions) {
      const shouldUpsertDeposit =
        operation.type === BlockOperation.CONNECTED ||
        operation.type === BlockOperation.DISCONNECTED;
      if (!shouldUpsertDeposit) {
        continue;
      }

      await this.prisma.$transaction(async (prisma) => {
        const amounts = new Map<string, number>();

        for (const deposit of transaction.notes) {
          const amount = amounts.get(deposit.memo) ?? 0;
          amounts.set(deposit.memo, amount + deposit.amount);
        }

        for (const [graffiti, amount] of amounts) {
          const depositParams = {
            transaction_hash: standardizeHash(transaction.hash),
            block_hash: standardizeHash(operation.block.hash),
            block_sequence: operation.block.sequence,
            network_version: networkVersion,
            graffiti,
            main: operation.type === BlockOperation.CONNECTED,
            amount,
          };

          const deposit = await prisma.deposit.upsert({
            create: depositParams,
            update: depositParams,
            where: {
              uq_deposits_on_transaction_hash_and_graffiti: {
                transaction_hash: depositParams.transaction_hash,
                graffiti: depositParams.graffiti,
              },
            },
          });
          deposits.push(deposit);

          if (!deposit.main) {
            const event = await prisma.event.findUnique({
              where: {
                deposit_id: deposit.id,
              },
            });
            if (event) {
              await this.eventsService.deleteWithClient(event, prisma);
            }
          }

          if (deposit.main && deposit.amount >= SEND_TRANSACTION_LIMIT_ORE) {
            const user = await this.usersService.findByGraffiti(
              deposit.graffiti,
              prisma,
            );

            if (user) {
              await this.eventsService.createWithClient(
                {
                  occurredAt: operation.block.timestamp,
                  type: EventType.SEND_TRANSACTION,
                  userId: user.id,
                  deposit,
                },
                prisma,
              );
            }
          }
        }

        const headHash =
          operation.type === BlockOperation.CONNECTED
            ? operation.block.hash
            : operation.block.previousBlockHash;
        await this.depositHeadsService.upsert(headHash, prisma);
      });
    }

    return deposits;
  }