diff --git a/src/app.module.ts b/src/app.module.ts index 243b27e..6eeb969 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -4,6 +4,7 @@ import { AppService } from '@/app.service'; import { TypeOrmModule } from '@nestjs/typeorm'; import { ConfigModule, ConfigService } from '@nestjs/config'; import configuration from '@/configuration'; +import { TransactionsModule } from '@/transactions/transactions.module'; @Module({ imports: [ @@ -26,6 +27,7 @@ import configuration from '@/configuration'; autoLoadEntities: true, }), }), + TransactionsModule, ], controllers: [AppController], providers: [AppService], diff --git a/src/transactions/transaction.entity.ts b/src/transactions/transaction.entity.ts new file mode 100644 index 0000000..f61f217 --- /dev/null +++ b/src/transactions/transaction.entity.ts @@ -0,0 +1,28 @@ +import { Column, Entity, PrimaryColumn } from 'typeorm'; + +export type TransactionOutput = { + pubKey: string; + vout: number; + value: number; +}; + +@Entity() +export class Transaction { + @PrimaryColumn('text') + id: string; // txid + + @Column({ type: 'integer', nullable: false }) + blockHeight: number; + + @Column({ type: 'text', nullable: false }) + blockHash: string; + + @Column({ type: 'text', nullable: false }) + scanTweak: string; + + @Column({ type: 'jsonb', nullable: false }) + outputs: TransactionOutput[]; + + @Column({ type: 'boolean', nullable: false }) + isSpent: boolean; +} diff --git a/src/transactions/transactions.module.ts b/src/transactions/transactions.module.ts new file mode 100644 index 0000000..f6e16aa --- /dev/null +++ b/src/transactions/transactions.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { TransactionsService } from '@/transactions/transactions.service'; +import { Transaction } from '@/transactions/transaction.entity'; + +@Module({ + imports: [TypeOrmModule.forFeature([Transaction])], + controllers: [], + providers: [TransactionsService], + exports: [TransactionsService], +}) +export class TransactionsModule {} diff --git a/src/transactions/transactions.service.ts b/src/transactions/transactions.service.ts new file mode 100644 index 0000000..d5f81bb --- /dev/null +++ b/src/transactions/transactions.service.ts @@ -0,0 +1,22 @@ +import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { Transaction } from '@/transactions/transaction.entity'; +import { Repository } from 'typeorm'; + +@Injectable() +export class TransactionsService { + constructor( + @InjectRepository(Transaction) + private readonly transactionRepository: Repository, + ) {} + + async getTransactionByBlockHeight( + blockHeight: number, + ): Promise { + return this.transactionRepository.find({ where: { blockHeight } }); + } + + async getTransactionByBlockHash(blockHash: string): Promise { + return this.transactionRepository.find({ where: { blockHash } }); + } +}