-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Anmol Sharma <anmolsharma0234@gmail.com>
- Loading branch information
1 parent
10dfaec
commit 8011753
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Transaction>, | ||
) {} | ||
|
||
async getTransactionByBlockHeight( | ||
blockHeight: number, | ||
): Promise<Transaction[]> { | ||
return this.transactionRepository.find({ where: { blockHeight } }); | ||
} | ||
|
||
async getTransactionByBlockHash(blockHash: string): Promise<Transaction[]> { | ||
return this.transactionRepository.find({ where: { blockHash } }); | ||
} | ||
} |