All files / src/Utxo/DbSyncUtxoProvider UtxoBuilder.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21        41x 41x   41x 31x 31x   31x 31x     10x 10x 10x      
import { Cardano } from '@cardano-sdk/core';
import { Logger } from 'ts-log';
import { Pool, QueryResult } from 'pg';
import { UtxoModel } from './types';
import { findUtxosByAddresses } from './queries';
import { utxosToCore } from './mappers';
 
export class UtxoBuilder {
  #db: Pool;
  #logger: Logger;
  constructor(db: Pool, logger: Logger) {
    this.#db = db;
    this.#logger = logger;
  }
  public async utxoByAddresses(addresses: Cardano.PaymentAddress[]): Promise<Cardano.Utxo[]> {
    this.#logger.debug('About to find utxos of addresses ', addresses);
    const result: QueryResult<UtxoModel> = await this.#db.query(findUtxosByAddresses, [addresses]);
    return result.rows.length > 0 ? utxosToCore(result.rows) : [];
  }
}