All files / src/Asset/DbSyncAssetProvider AssetBuilder.ts

100% Statements 12/12
100% Branches 0/0
100% Functions 3/3
100% Lines 12/12

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 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36        36x   36x 18x 18x     18x 18x       8x 8x         8x       12x 12x         12x      
import { Cardano } from '@cardano-sdk/core';
import { LastMintTxModel, MultiAssetModel } from './types';
import { Logger } from 'ts-log';
import { Pool } from 'pg';
import Queries from './queries';
 
export class AssetBuilder {
  #db: Pool;
  #logger: Logger;
 
  constructor(db: Pool, logger: Logger) {
    this.#db = db;
    this.#logger = logger;
  }
 
  public async queryLastMintTx(policyId: Cardano.PolicyId, name: Cardano.AssetName) {
    this.#logger.debug('About to query last nft mint tx for asset', { name, policyId });
    const result = await this.#db.query<LastMintTxModel>({
      name: 'nft_last_mint_tx',
      text: Queries.findLastNftMintTx,
      values: [Buffer.from(policyId, 'hex'), Buffer.from(name, 'hex')]
    });
    return result.rows[0];
  }
 
  public async queryMultiAsset(policyId: Cardano.PolicyId, name: Cardano.AssetName) {
    this.#logger.debug('About to query multi asset', { name, policyId });
    const result = await this.#db.query<MultiAssetModel>({
      name: 'find_multi_asset',
      text: Queries.findMultiAsset,
      values: [Buffer.from(policyId, 'hex'), Buffer.from(name, 'hex')]
    });
    return result.rows[0];
  }
}