From 9824c2c265faa0d14ae90bcb2b6ff7f609b969ac Mon Sep 17 00:00:00 2001 From: cfaur09 Date: Thu, 31 Oct 2024 11:16:07 +0200 Subject: [PATCH] remove postgres support --- src/common/indexer/indexer.module.ts | 19 +- .../indexer/postgres/entities/account.db.ts | 26 - .../postgres/entities/account.esdt.db.ts | 34 - .../entities/account.esdt.history.db.ts | 28 - .../postgres/entities/account.history.db.ts | 28 - .../indexer/postgres/entities/block.db.ts | 98 --- .../indexer/postgres/entities/delegator.db.ts | 19 - .../postgres/entities/epoch.info.db.ts | 13 - .../postgres/entities/epoch.start.info.db.ts | 31 - .../indexer/postgres/entities/event.db.ts | 20 - src/common/indexer/postgres/entities/index.ts | 59 -- .../indexer/postgres/entities/log.db.ts | 16 - .../indexer/postgres/entities/miniblock.db.ts | 38 - .../postgres/entities/owner.data.db.ts | 10 - .../indexer/postgres/entities/receipt.db.ts | 22 - .../postgres/entities/round.info.db.ts | 23 - .../postgres/entities/sc.deploy.info.db.ts | 13 - .../indexer/postgres/entities/sc.result.db.ts | 103 --- .../entities/sc.result.operation.db.ts | 103 --- .../indexer/postgres/entities/tag.db.ts | 11 - .../postgres/entities/token.info.db.ts | 59 -- .../postgres/entities/token.metadata.db.ts | 44 -- .../postgres/entities/transaction.db.ts | 106 --- .../entities/transaction.operation.db.ts | 106 --- .../indexer/postgres/entities/upgrade.db.ts | 13 - .../entities/validator.public.keys.db.ts | 10 - .../entities/validator.rating.info.db.ts | 10 - .../postgres/postgres.indexer.helper.ts | 444 ----------- .../postgres/postgres.indexer.module.ts | 51 -- .../postgres/postgres.indexer.service.ts | 703 ------------------ 30 files changed, 3 insertions(+), 2257 deletions(-) delete mode 100644 src/common/indexer/postgres/entities/account.db.ts delete mode 100644 src/common/indexer/postgres/entities/account.esdt.db.ts delete mode 100644 src/common/indexer/postgres/entities/account.esdt.history.db.ts delete mode 100644 src/common/indexer/postgres/entities/account.history.db.ts delete mode 100644 src/common/indexer/postgres/entities/block.db.ts delete mode 100644 src/common/indexer/postgres/entities/delegator.db.ts delete mode 100644 src/common/indexer/postgres/entities/epoch.info.db.ts delete mode 100644 src/common/indexer/postgres/entities/epoch.start.info.db.ts delete mode 100644 src/common/indexer/postgres/entities/event.db.ts delete mode 100644 src/common/indexer/postgres/entities/index.ts delete mode 100644 src/common/indexer/postgres/entities/log.db.ts delete mode 100644 src/common/indexer/postgres/entities/miniblock.db.ts delete mode 100644 src/common/indexer/postgres/entities/owner.data.db.ts delete mode 100644 src/common/indexer/postgres/entities/receipt.db.ts delete mode 100644 src/common/indexer/postgres/entities/round.info.db.ts delete mode 100644 src/common/indexer/postgres/entities/sc.deploy.info.db.ts delete mode 100644 src/common/indexer/postgres/entities/sc.result.db.ts delete mode 100644 src/common/indexer/postgres/entities/sc.result.operation.db.ts delete mode 100644 src/common/indexer/postgres/entities/tag.db.ts delete mode 100644 src/common/indexer/postgres/entities/token.info.db.ts delete mode 100644 src/common/indexer/postgres/entities/token.metadata.db.ts delete mode 100644 src/common/indexer/postgres/entities/transaction.db.ts delete mode 100644 src/common/indexer/postgres/entities/transaction.operation.db.ts delete mode 100644 src/common/indexer/postgres/entities/upgrade.db.ts delete mode 100644 src/common/indexer/postgres/entities/validator.public.keys.db.ts delete mode 100644 src/common/indexer/postgres/entities/validator.rating.info.db.ts delete mode 100644 src/common/indexer/postgres/postgres.indexer.helper.ts delete mode 100644 src/common/indexer/postgres/postgres.indexer.module.ts delete mode 100644 src/common/indexer/postgres/postgres.indexer.service.ts diff --git a/src/common/indexer/indexer.module.ts b/src/common/indexer/indexer.module.ts index 6f795eb4c..ebf731b11 100644 --- a/src/common/indexer/indexer.module.ts +++ b/src/common/indexer/indexer.module.ts @@ -1,34 +1,21 @@ -import { DynamicModule, Global, Module, Type } from "@nestjs/common"; -import configuration from "config/configuration"; +import { DynamicModule, Global, Module } from "@nestjs/common"; import { ElasticIndexerModule } from "./elastic/elastic.indexer.module"; import { ElasticIndexerService } from "./elastic/elastic.indexer.service"; -import { IndexerInterface } from "./indexer.interface"; import { IndexerService } from "./indexer.service"; -import { PostgresIndexerModule } from "./postgres/postgres.indexer.module"; -import { PostgresIndexerService } from "./postgres/postgres.indexer.service"; @Global() @Module({}) export class IndexerModule { static register(): DynamicModule { - let indexerModule: Type = ElasticIndexerModule; - let indexerInterface: Type = ElasticIndexerService; - - const isPostgres = configuration().indexer?.type === 'postgres'; - if (isPostgres) { - indexerModule = PostgresIndexerModule; - indexerInterface = PostgresIndexerService; - } - return { module: IndexerModule, imports: [ - indexerModule, + ElasticIndexerModule, ], providers: [ { provide: 'IndexerInterface', - useClass: indexerInterface, + useClass: ElasticIndexerService, }, IndexerService, ], diff --git a/src/common/indexer/postgres/entities/account.db.ts b/src/common/indexer/postgres/entities/account.db.ts deleted file mode 100644 index 85a508c0d..000000000 --- a/src/common/indexer/postgres/entities/account.db.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Column, Entity, PrimaryColumn } from "typeorm"; -import { Account } from "../../entities"; - -@Entity('accounts') -export class AccountDb implements Account { - @PrimaryColumn() - address: string = ''; - - @Column({ nullable: true }) - nonce: number = 0; - - @Column({ nullable: true }) - timestamp: number = 0; - - @Column({ nullable: true }) - balance: string = '0'; - - @Column({ nullable: true, name: 'balance_num' }) - balanceNum: number = 0; - - @Column({ nullable: true, name: 'total_balance_with_stake' }) - totalBalanceWithStake: string = '0'; - - @Column({ nullable: true, name: 'total_balance_with_stake_num' }) - totalBalanceWithStakeNum: number = 0; -} diff --git a/src/common/indexer/postgres/entities/account.esdt.db.ts b/src/common/indexer/postgres/entities/account.esdt.db.ts deleted file mode 100644 index b49793daf..000000000 --- a/src/common/indexer/postgres/entities/account.esdt.db.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Column, Entity, PrimaryColumn } from "typeorm"; - -@Entity('accounts_esdt') -export class AccountsEsdtDb { - @PrimaryColumn() - address: string = ''; - - @Column({ nullable: true }) - nonce: number = 0; - - @Column({ nullable: true }) - balance: string = '0'; - - @Column({ nullable: true, name: 'balance_num' }) - balanceNum: number = 0; - - @PrimaryColumn({ name: 'token_name' }) - tokenName: string = ''; - - @Column({ nullable: true, name: 'token_identifier' }) - tokenIdentifier: string = ''; - - @PrimaryColumn({ name: 'token_nonce' }) - tokenNonce: number = 0; - - @Column({ nullable: true }) - properties: string = ''; - - @Column({ nullable: true, name: 'total_balance_with_stake' }) - totalBalanceWithStake: string = '0'; - - @Column({ nullable: true, name: 'total_balance_with_stake_num' }) - totalBalanceWithStakeNum: number = 0; -} diff --git a/src/common/indexer/postgres/entities/account.esdt.history.db.ts b/src/common/indexer/postgres/entities/account.esdt.history.db.ts deleted file mode 100644 index 91c346fa2..000000000 --- a/src/common/indexer/postgres/entities/account.esdt.history.db.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Column, Entity, PrimaryColumn } from "typeorm"; - -@Entity('accounts_esdt_history') -export class AccountsEsdtHistoryDb { - @PrimaryColumn() - address: string = ''; - - @PrimaryColumn() - timestamp: number = 0; - - @Column({ nullable: true }) - balance: string = '0'; - - @PrimaryColumn() - token: string = ''; - - @Column({ nullable: true }) - identifier: string = ''; - - @PrimaryColumn({ name: 'token_nonce' }) - tokenNonce: number = 0; - - @Column({ nullable: true, name: 'is_sender' }) - isSender: boolean = false; - - @Column({ nullable: true, name: 'is_smart_contract' }) - isSmartContract: boolean = false; -} diff --git a/src/common/indexer/postgres/entities/account.history.db.ts b/src/common/indexer/postgres/entities/account.history.db.ts deleted file mode 100644 index 852bb18c9..000000000 --- a/src/common/indexer/postgres/entities/account.history.db.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Column, Entity, PrimaryColumn } from "typeorm"; - -@Entity('accounts_history') -export class AccountHistoryDb { - @PrimaryColumn() - address: string = ''; - - @PrimaryColumn() - timestamp: number = 0; - - @Column({ nullable: true }) - balance: string = '0'; - - @Column({ nullable: true }) - token: string = ''; - - @Column({ nullable: true }) - identifier: string = ''; - - @Column({ nullable: true, name: 'token_nonce' }) - tokenNonce: number = 0; - - @Column({ nullable: true, name: 'is_sender' }) - isSender: boolean = false; - - @Column({ nullable: true, name: 'is_smart_contract' }) - isSmartContract: boolean = false; -} diff --git a/src/common/indexer/postgres/entities/block.db.ts b/src/common/indexer/postgres/entities/block.db.ts deleted file mode 100644 index bfdc92ad3..000000000 --- a/src/common/indexer/postgres/entities/block.db.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { TypeormUtils } from "src/utils/typeorm.utils"; -import { Column, Entity, PrimaryColumn } from "typeorm"; - -@Entity('blocks') -export class BlockDb { - @PrimaryColumn() - hash: string = ''; - - @Column({ nullable: true }) - nonce: number = 0; - - @Column({ nullable: true }) - round: number = 0; - - @Column({ nullable: true }) - epoch: number = 0; - - @Column('text', { nullable: true, name: 'mini_blocks_hashes', transformer: TypeormUtils.textToStringArrayTransformer }) - miniBlocksHashes: string[] = []; - - @Column('text', { nullable: true, name: 'notarized_blocks_hashes', transformer: TypeormUtils.textToStringArrayTransformer }) - notarizedBlocksHashes?: string; - - @Column({ nullable: true }) - proposer: number = 0; - - @Column('text', { nullable: true, transformer: TypeormUtils.textToNumberArrayTransformer }) - validators: number[] = []; - - @Column({ nullable: true, name: 'pub_key_bitmap' }) - publicKeyBitmap: number = 0; - - @Column({ nullable: true }) - size: number = 0; - - @Column({ nullable: true, name: 'size_txs' }) - sizeTxs: number = 0; - - @Column({ nullable: true }) - timestamp: number = 0; - - @Column({ nullable: true, name: 'state_root_hash' }) - stateRootHash: string = ''; - - @Column({ nullable: true, name: 'prev_hash' }) - prevHash: string = ''; - - @Column({ nullable: true, name: 'shard_id' }) - shardId: number = 0; - - @Column({ nullable: true, name: 'tx_count' }) - txCount: number = 0; - - @Column({ nullable: true, name: 'notarized_txs_count' }) - notarizedTxsCount: number = 0; - - @Column({ nullable: true, name: 'accumulated_fees' }) - accumulatedFees: string = ''; - - @Column({ nullable: true, name: 'developer_fees' }) - developerFees: string = ''; - - @Column({ nullable: true, name: 'epoch_start_block' }) - epochStartBlock: boolean = false; - - @Column({ nullable: true, name: 'search_order' }) - searchOrder: number = 0; - - @Column({ nullable: true, name: 'gas_provided' }) - gasProvided: number = 0; - - @Column({ nullable: true, name: 'gas_refunded' }) - gasRefunded: number = 0; - - @Column({ nullable: true, name: 'gas_penalized' }) - gasPenalized: number = 0; - - @Column({ nullable: true, name: 'max_gas_limit' }) - maxGasLimit: number = 0; - - @Column({ nullable: true, name: 'scheduled_root_hash' }) - scheduledRootHash: string = ''; - - @Column({ nullable: true, name: 'scheduled_accumulated_fees' }) - scheduledAccumulatedFees: string = ''; - - @Column({ nullable: true, name: 'scheduled_developer_fees' }) - scheduledDeveloperFees: string = ''; - - @Column({ nullable: true, name: 'scheduled_gas_provided' }) - scheduledGasProvided: number = 0; - - @Column({ nullable: true, name: 'scheduled_gas_penalized' }) - scheduledGasPenalized: number = 0; - - @Column({ nullable: true, name: 'scheduled_gas_refunded' }) - scheduledGasRefunded: number = 0; -} diff --git a/src/common/indexer/postgres/entities/delegator.db.ts b/src/common/indexer/postgres/entities/delegator.db.ts deleted file mode 100644 index 59bab4137..000000000 --- a/src/common/indexer/postgres/entities/delegator.db.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Column, Entity, PrimaryColumn } from "typeorm"; - -@Entity('delegators') -export class DelegatorDb { - @PrimaryColumn() - address: string = ''; - - @Column({ nullable: true }) - contract: string = ''; - - @Column({ nullable: true, name: 'active_stake' }) - activeStake: string = ''; - - @Column({ nullable: true, name: 'active_stake_num' }) - activeStakeNum: number = 0; - - @Column({ nullable: true, name: 'should_delete' }) - shouldDelete: boolean = false; -} diff --git a/src/common/indexer/postgres/entities/epoch.info.db.ts b/src/common/indexer/postgres/entities/epoch.info.db.ts deleted file mode 100644 index 011378b99..000000000 --- a/src/common/indexer/postgres/entities/epoch.info.db.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Column, Entity, PrimaryColumn } from "typeorm"; - -@Entity('epoch_info') -export class EpochInfoDb { - @PrimaryColumn() - epoch: number = 0; - - @Column({ nullable: true, name: 'accumulated_fees' }) - accumulatedFees: string = '0'; - - @Column({ nullable: true, name: 'developer_fees' }) - developerFees: string = '0'; -} diff --git a/src/common/indexer/postgres/entities/epoch.start.info.db.ts b/src/common/indexer/postgres/entities/epoch.start.info.db.ts deleted file mode 100644 index 521d0c41f..000000000 --- a/src/common/indexer/postgres/entities/epoch.start.info.db.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Column, Entity, PrimaryColumn } from "typeorm"; - -@Entity('epoch_start_infos') -export class EpochStartInfosDb { - @PrimaryColumn() - hash: string = ''; - - @Column({ nullable: true, name: 'total_supply' }) - totalSupply: string = '0'; - - @Column({ nullable: true, name: 'total_to_distribute' }) - totalToDistribute: string = '0'; - - @Column({ nullable: true, name: 'total_newly_minted' }) - totalNewlyMinted: string = '0'; - - @Column({ nullable: true, name: 'rewards_per_block' }) - rewardsPerBlock: string = '0'; - - @Column({ nullable: true, name: 'rewards_for_protocol_sustainability' }) - rewardsForProtocolSustainability: string = '0'; - - @Column({ nullable: true, name: 'node_price' }) - nodePrice: string = '0'; - - @Column({ nullable: true, name: 'prev_epoch_start_round' }) - prev_epoch_start_round: number = 0; - - @Column({ nullable: true, name: 'prev_epoch_start_hash' }) - prev_epoch_start_hash: string = ''; -} diff --git a/src/common/indexer/postgres/entities/event.db.ts b/src/common/indexer/postgres/entities/event.db.ts deleted file mode 100644 index e0ee8221e..000000000 --- a/src/common/indexer/postgres/entities/event.db.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { TypeormUtils } from "src/utils/typeorm.utils"; -import { Column, Entity, PrimaryColumn } from "typeorm"; - -@Entity('events') -export class EventDb { - @PrimaryColumn() - address: string = ''; - - @Column({ nullable: true }) - identifier: string = ''; - - @Column('text', { nullable: true, transformer: TypeormUtils.textToStringArrayTransformer }) - topics: string[] = []; - - @Column({ nullable: true }) - data: string = ''; - - @Column({ nullable: true }) - order: number = 0; -} diff --git a/src/common/indexer/postgres/entities/index.ts b/src/common/indexer/postgres/entities/index.ts deleted file mode 100644 index 1b7cfe170..000000000 --- a/src/common/indexer/postgres/entities/index.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { AccountDb } from './account.db'; -import { AccountHistoryDb } from './account.history.db'; -import { AccountsEsdtDb } from './account.esdt.db'; -import { AccountsEsdtHistoryDb } from './account.esdt.history.db'; -import { BlockDb } from './block.db'; -import { DelegatorDb } from './delegator.db'; -import { EpochInfoDb } from './epoch.info.db'; -import { EpochStartInfosDb } from './epoch.start.info.db'; -import { EventDb } from './event.db'; -import { LogDb } from './log.db'; -import { MiniBlockDb } from './miniblock.db'; -import { OwnerDataDb } from './owner.data.db'; -import { ReceiptDb } from './receipt.db'; -import { RoundInfoDb } from './round.info.db'; -import { ScDeployInfoDb } from './sc.deploy.info.db'; -import { ScResultDb } from './sc.result.db'; -import { ScResultOperationDb } from './sc.result.operation.db'; -import { TagDb } from './tag.db'; -import { TokenInfoDb } from './token.info.db'; -import { TokenMetaDataDb } from './token.metadata.db'; -import { TransactionDb } from './transaction.db'; -import { TransactionOperationDb } from './transaction.operation.db'; -import { UpgradeDb } from './upgrade.db'; -import { ValidatorPublicKeysDb } from './validator.public.keys.db'; -import { ValidatorRatingInfoDb } from './validator.rating.info.db'; - -export { AccountDb } from './account.db'; -export { AccountHistoryDb } from './account.history.db'; -export { AccountsEsdtDb } from './account.esdt.db'; -export { AccountsEsdtHistoryDb } from './account.esdt.history.db'; -export { BlockDb } from './block.db'; -export { DelegatorDb } from './delegator.db'; -export { EpochInfoDb } from './epoch.info.db'; -export { EpochStartInfosDb } from './epoch.start.info.db'; -export { EventDb } from './event.db'; -export { LogDb } from './log.db'; -export { MiniBlockDb } from './miniblock.db'; -export { OwnerDataDb } from './owner.data.db'; -export { ReceiptDb } from './receipt.db'; -export { RoundInfoDb } from './round.info.db'; -export { ScDeployInfoDb } from './sc.deploy.info.db'; -export { ScResultDb } from './sc.result.db'; -export { ScResultOperationDb } from './sc.result.operation.db'; -export { TagDb } from './tag.db'; -export { TokenInfoDb } from './token.info.db'; -export { TokenMetaDataDb } from './token.metadata.db'; -export { TransactionDb } from './transaction.db'; -export { TransactionOperationDb } from './transaction.operation.db'; -export { UpgradeDb } from './upgrade.db'; -export { ValidatorPublicKeysDb } from './validator.public.keys.db'; -export { ValidatorRatingInfoDb } from './validator.rating.info.db'; - -export const entities = [ - AccountDb, AccountHistoryDb, AccountsEsdtDb, AccountsEsdtHistoryDb, BlockDb, - DelegatorDb, EpochInfoDb, EpochStartInfosDb, EventDb, LogDb, MiniBlockDb, - OwnerDataDb, ReceiptDb, RoundInfoDb, ScDeployInfoDb, ScResultDb, ScResultOperationDb, - TagDb, TokenInfoDb, TokenMetaDataDb, TransactionDb, TransactionOperationDb, UpgradeDb, - ValidatorPublicKeysDb, ValidatorRatingInfoDb, -]; diff --git a/src/common/indexer/postgres/entities/log.db.ts b/src/common/indexer/postgres/entities/log.db.ts deleted file mode 100644 index 4bfb290c7..000000000 --- a/src/common/indexer/postgres/entities/log.db.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Column, Entity, PrimaryColumn } from "typeorm"; - -@Entity('logs') -export class LogDb { - @PrimaryColumn() - id: string = ''; - - @Column({ nullable: true, name: 'original_tx_hash' }) - originalTxHash: string = ''; - - @Column({ nullable: true }) - address: string = ''; - - @Column({ nullable: true }) - timestamp: number = 0; -} diff --git a/src/common/indexer/postgres/entities/miniblock.db.ts b/src/common/indexer/postgres/entities/miniblock.db.ts deleted file mode 100644 index 1338e50cb..000000000 --- a/src/common/indexer/postgres/entities/miniblock.db.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Column, Entity, PrimaryColumn } from "typeorm"; -import { MiniBlock } from "../../entities"; - -@Entity('miniblocks') -export class MiniBlockDb implements MiniBlock { - @PrimaryColumn() - miniBlockHash: string = ''; - - @Column({ nullable: true, name: 'sender_shard_id' }) - senderShard: number = 0; - - @Column({ nullable: true, name: 'receiver_shard_id' }) - receiverShard: number = 0; - - @Column({ nullable: true, name: 'sender_block_hash' }) - senderBlockHash: string = ''; - - @Column({ nullable: true, name: 'receiver_block_hash' }) - receiverBlockHash: string = ''; - - @Column({ nullable: true }) - type: string = ''; - - @Column({ nullable: true, name: 'processing_type_on_destination' }) - procTypeD: string = ''; - - @Column({ nullable: true, name: 'processing_type_on_source' }) - procTypeS: string = ''; - - @Column({ nullable: true }) - timestamp: number = 0; - - @Column({ nullable: true, name: 'sender_block_nonce' }) - senderBlockNonce: string = ''; - - @Column({ nullable: true, name: 'receiver_block_nonce' }) - receiverBlockNonce: string = ''; -} diff --git a/src/common/indexer/postgres/entities/owner.data.db.ts b/src/common/indexer/postgres/entities/owner.data.db.ts deleted file mode 100644 index 61e82fe78..000000000 --- a/src/common/indexer/postgres/entities/owner.data.db.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Column, Entity, PrimaryColumn } from "typeorm"; - -@Entity('owner_data') -export class OwnerDataDb { - @PrimaryColumn() - address: string = ''; - - @Column({ nullable: true }) - timestamp: number = 0; -} diff --git a/src/common/indexer/postgres/entities/receipt.db.ts b/src/common/indexer/postgres/entities/receipt.db.ts deleted file mode 100644 index 2ed77efc9..000000000 --- a/src/common/indexer/postgres/entities/receipt.db.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('receipts') -export class ReceiptDb { - @PrimaryColumn() - hash: string = ''; - - @Column({ nullable: true }) - value: string = '0'; - - @Column({ nullable: true }) - sender: string = ''; - - @Column({ nullable: true }) - data: string = ''; - - @Column({ nullable: true, name: 'tx_hash' }) - txHash: string = ''; - - @Column({ nullable: true }) - timestamp: number = 0; -} diff --git a/src/common/indexer/postgres/entities/round.info.db.ts b/src/common/indexer/postgres/entities/round.info.db.ts deleted file mode 100644 index 8230d01c5..000000000 --- a/src/common/indexer/postgres/entities/round.info.db.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { TypeormUtils } from 'src/utils/typeorm.utils'; -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('round_infos') -export class RoundInfoDb { - @PrimaryColumn() - index: number = 0; - - @Column('text', { nullable: true, name: 'signers_indexes', transformer: TypeormUtils.textToNumberArrayTransformer }) - signersIndexes: number[] = []; - - @Column({ nullable: true, name: 'block_was_proposed' }) - blockWasProposed: boolean = false; - - @PrimaryColumn({ name: 'shard_id' }) - shardId: number = 0; - - @Column({ nullable: true }) - epoch: number = 0; - - @Column({ nullable: true }) - timestamp: number = 0; -} diff --git a/src/common/indexer/postgres/entities/sc.deploy.info.db.ts b/src/common/indexer/postgres/entities/sc.deploy.info.db.ts deleted file mode 100644 index d20297754..000000000 --- a/src/common/indexer/postgres/entities/sc.deploy.info.db.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('sc_deploy_infos') -export class ScDeployInfoDb { - @PrimaryColumn({ name: 'tx_hash' }) - txHash: string = ''; - - @Column({ nullable: true }) - creator: string = ''; - - @Column({ nullable: true }) - timestamp: number = 0; -} diff --git a/src/common/indexer/postgres/entities/sc.result.db.ts b/src/common/indexer/postgres/entities/sc.result.db.ts deleted file mode 100644 index fcf22b6e0..000000000 --- a/src/common/indexer/postgres/entities/sc.result.db.ts +++ /dev/null @@ -1,103 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('sc_results') -export class ScResultDb { - @PrimaryColumn() - hash: string = ''; - - @Column({ nullable: true, name: 'mb_hash' }) - mbHash: string = ''; - - @Column({ nullable: true }) - nonce: number = 0; - - @Column({ nullable: true, name: 'gas_limit' }) - gasLimit: number = 0; - - @Column({ nullable: true, name: 'gas_price' }) - gasPrice: number = 0; - - @Column({ nullable: true }) - value: string = ''; - - @Column({ nullable: true }) - sender: string = ''; - - @Column({ nullable: true }) - receiver: string = ''; - - @Column({ nullable: true, name: 'sender_shard' }) - senderShard: number = 0; - - @Column({ nullable: true, name: 'receiver_shard' }) - receiverShard: number = 0; - - @Column({ nullable: true, name: 'relayer_addr' }) - relayerAddr: string = ''; - - @Column({ nullable: true, name: 'relayed_value' }) - relayedValue: string = ''; - - @Column({ nullable: true }) - code: string = ''; - - @Column({ nullable: true }) - data: string = ''; - - @Column({ nullable: true, name: 'prev_tx_hash' }) - prevTxHash: string = ''; - - @Column({ nullable: true, name: 'original_tx_hash' }) - originalTxHash: string = ''; - - @Column({ nullable: true, name: 'call_type' }) - callType: string = ''; - - @Column({ nullable: true, name: 'code_metadata' }) - codeMetadata: string = ''; - - @Column({ nullable: true, name: 'return_message' }) - returnMessage: string = ''; - - @Column({ nullable: true }) - timestamp: number = 0; - - @Column({ nullable: true, name: 'has_operations' }) - hasOperations: boolean = false; - - @Column({ nullable: true }) - type: string = ''; - - @Column({ nullable: true }) - status: string = ''; - - @Column({ nullable: true }) - tokens: string = ''; - - @Column({ nullable: true, name: 'esdt_values' }) - esdtValues: string = ''; - - @Column({ nullable: true }) - receivers: string = ''; - - @Column({ nullable: true, name: 'receivers_shard_ids' }) - receiversShardIds: string = ''; - - @Column({ nullable: true }) - operation: string = ''; - - @Column({ nullable: true }) - function: string = ''; - - @Column({ nullable: true, name: 'is_relayed' }) - isRelayed: boolean = false; - - @Column({ nullable: true, name: 'can_be_ignored' }) - canBeIgnored: boolean = false; - - @Column({ nullable: true, name: 'original_sender' }) - originalSender: string = ''; - - @Column({ nullable: true, name: 'sender_address_bytes' }) - senderAddressBytes: string = ''; -} diff --git a/src/common/indexer/postgres/entities/sc.result.operation.db.ts b/src/common/indexer/postgres/entities/sc.result.operation.db.ts deleted file mode 100644 index 915f990e9..000000000 --- a/src/common/indexer/postgres/entities/sc.result.operation.db.ts +++ /dev/null @@ -1,103 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('scrs_operations') -export class ScResultOperationDb { - @PrimaryColumn() - hash: string = ''; - - @Column({ nullable: true, name: 'mb_hash' }) - mbHash: string = ''; - - @Column({ nullable: true }) - nonce: number = 0; - - @Column({ nullable: true, name: 'gas_limit' }) - gasLimit: number = 0; - - @Column({ nullable: true, name: 'gas_price' }) - gasPrice: number = 0; - - @Column({ nullable: true }) - value: string = ''; - - @Column({ nullable: true }) - sender: string = ''; - - @Column({ nullable: true }) - receiver: string = ''; - - @Column({ nullable: true, name: 'sender_shard' }) - senderShard: number = 0; - - @Column({ nullable: true, name: 'receiver_shard' }) - receiverShard: number = 0; - - @Column({ nullable: true, name: 'relayer_addr' }) - relayerAddr: string = ''; - - @Column({ nullable: true, name: 'relayed_value' }) - relayedValue: string = ''; - - @Column({ nullable: true }) - code: string = ''; - - @Column({ nullable: true }) - data: string = ''; - - @Column({ nullable: true, name: 'prev_tx_hash' }) - prevTxHash: string = ''; - - @Column({ nullable: true, name: 'original_tx_hash' }) - originalTxHash: string = ''; - - @Column({ nullable: true, name: 'call_type' }) - callType: string = ''; - - @Column({ nullable: true, name: 'code_metadata' }) - codeMetadata: string = ''; - - @Column({ nullable: true, name: 'return_message' }) - returnMessage: string = ''; - - @Column({ nullable: true }) - timestamp: number = 0; - - @Column({ nullable: true, name: 'has_operations' }) - hasOperations: boolean = false; - - @Column({ nullable: true }) - type: string = ''; - - @Column({ nullable: true }) - status: string = ''; - - @Column({ nullable: true }) - tokens: string = ''; - - @Column({ nullable: true, name: 'esdt_values' }) - esdtValues: string = ''; - - @Column({ nullable: true }) - receivers: string = ''; - - @Column({ nullable: true, name: 'receivers_shard_ids' }) - receiversShardIds: string = ''; - - @Column({ nullable: true }) - operation: string = ''; - - @Column({ nullable: true }) - function: string = ''; - - @Column({ nullable: true, name: 'is_relayed' }) - isRelayed: boolean = false; - - @Column({ nullable: true, name: 'can_be_ignored' }) - canBeIgnored: boolean = false; - - @Column({ nullable: true, name: 'original_sender' }) - originalSender: string = ''; - - @Column({ nullable: true, name: 'sender_address_bytes' }) - senderAddressBytes: string = ''; -} diff --git a/src/common/indexer/postgres/entities/tag.db.ts b/src/common/indexer/postgres/entities/tag.db.ts deleted file mode 100644 index 42139fd65..000000000 --- a/src/common/indexer/postgres/entities/tag.db.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; -import { Tag } from '../../entities'; - -@Entity('tags') -export class TagDb implements Tag { - @PrimaryColumn() - tag: string = ''; - - @Column({ nullable: true }) - count: number = 0; -} diff --git a/src/common/indexer/postgres/entities/token.info.db.ts b/src/common/indexer/postgres/entities/token.info.db.ts deleted file mode 100644 index 7d902d764..000000000 --- a/src/common/indexer/postgres/entities/token.info.db.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { TypeormUtils } from 'src/utils/typeorm.utils'; -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('token_infos') -export class TokenInfoDb { - @Column({ nullable: true }) - name: string = ''; - - @Column({ nullable: true }) - ticker: string = ''; - - @Column({ nullable: true }) - identifier: string = ''; - - @PrimaryColumn() - token: string = ''; - - @Column({ nullable: true }) - issuer: string = ''; - - @Column({ nullable: true, name: 'current_owner' }) - currentOwner: string = ''; - - @Column({ nullable: true }) - type: string = ''; - - @Column({ nullable: true }) - nonce: number = 0; - - @Column({ nullable: true }) - timestamp: number = 0; - - @Column({ nullable: true }) - creator: string = ''; - - @Column({ nullable: true }) - royalties: number = 0; - - @Column({ nullable: true }) - hash: string = ''; - - @Column('text', { nullable: true, transformer: TypeormUtils.textToStringArrayTransformer }) - uris: string[] = []; - - @Column('text', { nullable: true, transformer: TypeormUtils.textToStringArrayTransformer }) - tags: string[] = []; - - @Column({ nullable: true }) - attributes: string = ''; - - @Column({ nullable: true, name: 'meta_data' }) - meta_data: string = ''; - - @Column({ nullable: true, name: 'non_empty_uris' }) - nonEmptyUris: boolean = false; - - @Column({ nullable: true, name: 'white_listed_storage' }) - whiteListedStorage: boolean = false; -} diff --git a/src/common/indexer/postgres/entities/token.metadata.db.ts b/src/common/indexer/postgres/entities/token.metadata.db.ts deleted file mode 100644 index b45f45492..000000000 --- a/src/common/indexer/postgres/entities/token.metadata.db.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { TypeormUtils } from 'src/utils/typeorm.utils'; -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('token_meta_data') -export class TokenMetaDataDb { - @PrimaryColumn() - name: string = ''; - - @Column({ nullable: true }) - creator: string = ''; - - @Column({ nullable: true }) - royalties: number = 0; - - @Column({ nullable: true }) - hash: string = ''; - - @Column('text', { nullable: true, transformer: TypeormUtils.textToStringArrayTransformer }) - uris?: string[] = []; - - @Column('text', { nullable: true, array: true }) - tags?: string[] = []; - - @Column({ nullable: true }) - attributes: string = ''; - - @Column({ nullable: true, name: 'meta_data' }) - metaData: string = ''; - - @Column({ nullable: true, name: 'non_empty_uris' }) - nonEmptyUris: boolean = false; - - @Column({ nullable: true, name: 'white_listed_storage' }) - whiteListedStorage: boolean = false; - - @Column({ nullable: true }) - address: string = ''; - - @Column({ nullable: true, name: 'token_name' }) - tokenName: string = ''; - - @Column({ nullable: true, name: 'token_nonce' }) - tokenNonce: number = 0; -} diff --git a/src/common/indexer/postgres/entities/transaction.db.ts b/src/common/indexer/postgres/entities/transaction.db.ts deleted file mode 100644 index 6b93be8ad..000000000 --- a/src/common/indexer/postgres/entities/transaction.db.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('transactions') -export class TransactionDb { - @PrimaryColumn() - hash: string = ''; - - @Column({ nullable: true, name: 'mb_hash' }) - mbHash: string = ''; - - @Column({ nullable: true }) - nonce: number = 0; - - @Column({ nullable: true }) - round: number = 0; - - @Column({ nullable: true }) - value: string = ''; - - @Column({ nullable: true }) - receiver: string = ''; - - @Column({ nullable: true }) - sender: string = ''; - - @Column({ nullable: true, name: 'receiver_shard' }) - receiverShard: number = 0; - - @Column({ nullable: true, name: 'sender_shard' }) - senderShard: number = 0; - - @Column({ nullable: true, name: 'gas_price' }) - gasPrice: number = 0; - - @Column({ nullable: true, name: 'gas_limit' }) - gasLimit: number = 0; - - @Column({ nullable: true, name: 'gas_used' }) - gasUsed: number = 0; - - @Column({ nullable: true }) - fee: string = ''; - - @Column({ nullable: true }) - data: string = ''; - - @Column({ nullable: true }) - signature: string = ''; - - @Column({ nullable: true }) - timestamp: number = 0; - - @Column({ nullable: true }) - status: string = ''; - - @Column({ nullable: true, name: 'search_order' }) - searchOrder: number = 0; - - @Column({ nullable: true, name: 'sender_user_name' }) - senderUserName: string = ''; - - @Column({ nullable: true, name: 'receiver_user_name' }) - receiverUserName: string = ''; - - @Column({ nullable: true, name: 'has_scr' }) - hasScr: boolean = false; - - @Column({ nullable: true, name: 'is_sc_call' }) - isScCall: boolean = false; - - @Column({ nullable: true, name: 'has_operations' }) - hasOperations: boolean = false; - - @Column({ nullable: true }) - tokens: string = ''; - - @Column({ nullable: true, name: 'esdt_values' }) - esdtValues: string = ''; - - @Column({ nullable: true }) - receivers: string = ''; - - @Column({ nullable: true, name: 'receivers_shard_ids' }) - receiversShardIds: string = ''; - - @Column({ nullable: true }) - type: string = ''; - - @Column({ nullable: true }) - operation: string = ''; - - @Column({ nullable: true }) - function: string = ''; - - @Column({ nullable: true, name: 'is_relayed' }) - isRelayed: boolean = false; - - @Column({ nullable: true }) - version: number = 0; - - @Column({ nullable: true, name: 'receiver_address_bytes' }) - receiverAddressBytes: string = ''; - - @Column({ nullable: true, name: 'block_hash' }) - blockHash: string = ''; -} diff --git a/src/common/indexer/postgres/entities/transaction.operation.db.ts b/src/common/indexer/postgres/entities/transaction.operation.db.ts deleted file mode 100644 index c8600502f..000000000 --- a/src/common/indexer/postgres/entities/transaction.operation.db.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('txs_operations') -export class TransactionOperationDb { - @PrimaryColumn() - hash: string = ''; - - @Column({ nullable: true, name: 'mb_hash' }) - mbHash: string = ''; - - @Column({ nullable: true }) - nonce: number = 0; - - @Column({ nullable: true }) - round: number = 0; - - @Column({ nullable: true }) - value: string = ''; - - @Column({ nullable: true }) - receiver: string = ''; - - @Column({ nullable: true }) - sender: string = ''; - - @Column({ nullable: true, name: 'receiver_shard' }) - receiverShard: number = 0; - - @Column({ nullable: true, name: 'sender_shard' }) - senderShard: number = 0; - - @Column({ nullable: true, name: 'gas_price' }) - gasPrice: number = 0; - - @Column({ nullable: true, name: 'gas_limit' }) - gasLimit: number = 0; - - @Column({ nullable: true, name: 'gas_used' }) - gasUsed: number = 0; - - @Column({ nullable: true }) - fee: string = ''; - - @Column({ nullable: true }) - data: string = ''; - - @Column({ nullable: true }) - signature: string = ''; - - @Column({ nullable: true }) - timestamp: number = 0; - - @Column({ nullable: true }) - status: string = ''; - - @Column({ nullable: true, name: 'search_order' }) - searchOrder: number = 0; - - @Column({ nullable: true, name: 'sender_user_name' }) - senderUserName: string = ''; - - @Column({ nullable: true, name: 'receiver_user_name' }) - receiverUserName: string = ''; - - @Column({ nullable: true, name: 'has_scr' }) - hasScr: boolean = false; - - @Column({ nullable: true, name: 'is_sc_call' }) - isScCall: boolean = false; - - @Column({ nullable: true, name: 'has_operations' }) - hasOperations: boolean = false; - - @Column({ nullable: true }) - tokens: string = ''; - - @Column({ nullable: true, name: 'esdt_values' }) - esdtValues: string = ''; - - @Column({ nullable: true }) - receivers: string = ''; - - @Column({ nullable: true, name: 'receivers_shard_ids' }) - receiversShardIds: string = ''; - - @Column({ nullable: true }) - type: string = ''; - - @Column({ nullable: true }) - operation: string = ''; - - @Column({ nullable: true }) - function: string = ''; - - @Column({ nullable: true, name: 'is_relayed' }) - isRelayed: boolean = false; - - @Column({ nullable: true }) - version: number = 0; - - @Column({ nullable: true, name: 'receiver_address_bytes' }) - receiverAddressBytes: string = ''; - - @Column({ nullable: true, name: 'block_hash' }) - blockHash: string = ''; -} diff --git a/src/common/indexer/postgres/entities/upgrade.db.ts b/src/common/indexer/postgres/entities/upgrade.db.ts deleted file mode 100644 index 737154ee2..000000000 --- a/src/common/indexer/postgres/entities/upgrade.db.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('upgrades') -export class UpgradeDb { - @PrimaryColumn({ name: 'tx_hash' }) - txHash: string = ''; - - @Column({ nullable: true }) - upgrader: string = ''; - - @PrimaryColumn() - timestamp: number = 0; -} diff --git a/src/common/indexer/postgres/entities/validator.public.keys.db.ts b/src/common/indexer/postgres/entities/validator.public.keys.db.ts deleted file mode 100644 index 6de15ccc8..000000000 --- a/src/common/indexer/postgres/entities/validator.public.keys.db.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('validator_public_keys') -export class ValidatorPublicKeysDb { - @PrimaryColumn() - id: string = ''; - - @Column('text', { nullable: true, name: 'pub_keys', array: true }) - pubKeys: string[] = []; -} diff --git a/src/common/indexer/postgres/entities/validator.rating.info.db.ts b/src/common/indexer/postgres/entities/validator.rating.info.db.ts deleted file mode 100644 index c913d292b..000000000 --- a/src/common/indexer/postgres/entities/validator.rating.info.db.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; - -@Entity('validator_rating_infos') -export class ValidatorRatingInfoDb { - @PrimaryColumn() - id: string = ''; - - @Column({ nullable: true }) - rating: number = 0; -} diff --git a/src/common/indexer/postgres/postgres.indexer.helper.ts b/src/common/indexer/postgres/postgres.indexer.helper.ts deleted file mode 100644 index f9313c62d..000000000 --- a/src/common/indexer/postgres/postgres.indexer.helper.ts +++ /dev/null @@ -1,444 +0,0 @@ -import { AddressUtils } from "@multiversx/sdk-nestjs-common"; -import { QueryConditionOptions } from "@multiversx/sdk-nestjs-elastic"; -import { Injectable } from "@nestjs/common"; -import { InjectRepository } from "@nestjs/typeorm"; -import { QueryPagination } from "src/common/entities/query.pagination"; -import { BlockFilter } from "src/endpoints/blocks/entities/block.filter"; -import { BlsService } from "src/endpoints/bls/bls.service"; -import { CollectionFilter } from "src/endpoints/collections/entities/collection.filter"; -import { NftFilter } from "src/endpoints/nfts/entities/nft.filter"; -import { NftType } from "src/endpoints/nfts/entities/nft.type"; -import { RoundFilter } from "src/endpoints/rounds/entities/round.filter"; -import { TokenWithRolesFilter } from "src/endpoints/tokens/entities/token.with.roles.filter"; -import { TransactionFilter } from "src/endpoints/transactions/entities/transaction.filter"; -import { TransactionType } from "src/endpoints/transactions/entities/transaction.type"; -import { Repository, SelectQueryBuilder } from "typeorm"; -import { TokenType } from "../entities"; -import { AccountHistoryDb, AccountsEsdtDb, BlockDb, RoundInfoDb, ScResultDb, ScResultOperationDb, TokenInfoDb, TransactionDb, TransactionOperationDb } from "./entities"; - -@Injectable() -export class PostgresIndexerHelper { - constructor( - private readonly blsService: BlsService, - @InjectRepository(AccountHistoryDb) - private readonly accountHistoryRepository: Repository, - @InjectRepository(RoundInfoDb) - private readonly roundsRepository: Repository, - @InjectRepository(ScResultDb) - private readonly scResultsRepository: Repository, - @InjectRepository(TokenInfoDb) - private readonly tokensRepository: Repository, - @InjectRepository(TransactionDb) - private readonly transactionsRepository: Repository, - @InjectRepository(TransactionOperationDb) - private readonly operationsRepository: Repository, - @InjectRepository(BlockDb) - private readonly blocksRepository: Repository, - ) { } - - public async buildElasticBlocksFilter(filter: BlockFilter): Promise> { - let query = this.blocksRepository.createQueryBuilder(); - - if (filter.nonce !== undefined) { - query = query.andWhere('nonce = :nonce', { shard: filter.nonce }); - } - - if (filter.shard !== undefined) { - query = query.andWhere('shard_id = :shard', { shard: filter.shard }); - } - - if (filter.epoch !== undefined) { - query = query.andWhere('epoch = :epoch', { epoch: filter.epoch }); - } - - if (filter.proposer && filter.shard !== undefined && filter.epoch !== undefined) { - const index = await this.blsService.getBlsIndex(filter.proposer, filter.shard, filter.epoch); - query = query.andWhere('proposer = :index', { index }); - } - - if (filter.validator && filter.shard !== undefined && filter.epoch !== undefined) { - const index = await this.blsService.getBlsIndex(filter.validator, filter.shard, filter.epoch); - query = query.andWhere(`:index = ANY(REPLACE(REPLACE(validators, ']', '}'), '[', '{')::int[])`, { index }); - } - - return query; - } - - buildCollectionRolesFilter(filter: CollectionFilter, address?: string): SelectQueryBuilder { - let query = this.tokensRepository.createQueryBuilder() - .where(`(identifier IS NULL OR identifier = '')`) - .andWhere('type IN (:...types)', { types: [NftType.MetaESDT, NftType.NonFungibleESDT, NftType.SemiFungibleESDT] }); - - if (address) { - // TODO the "roles" column does not exist in "token_infos" table - query = query.andWhere('current_owner = :address', { address }); - // elasticQuery = elasticQuery.withMustCondition(QueryType.Should( - // [ - // QueryType.Match('currentOwner', address), - // QueryType.Nested('roles', { 'roles.ESDTRoleNFTCreate': address }), - // QueryType.Nested('roles', { 'roles.ESDTRoleNFTBurn': address }), - // QueryType.Nested('roles', { 'roles.ESDTRoleNFTAddQuantity': address }), - // QueryType.Nested('roles', { 'roles.ESDTRoleNFTUpdateAttributes': address }), - // QueryType.Nested('roles', { 'roles.ESDTRoleNFTAddURI': address }), - // QueryType.Nested('roles', { 'roles.ESDTTransferRole': address }), - // ] - // )); - } - - if (filter.before || filter.after) { - query = query.andWhere('timestamp BETWEEN :before AND :after', { before: filter.before ?? 0, after: filter.after ?? Date.now() }); - } - - // if (filter.canCreate !== undefined) { - // elasticQuery = this.getRoleCondition(elasticQuery, 'ESDTRoleNFTCreate', address, filter.canCreate); - // } - - // if (filter.canBurn !== undefined) { - // elasticQuery = this.getRoleCondition(elasticQuery, 'ESDTRoleNFTBurn', address, filter.canBurn); - // } - - // if (filter.canAddQuantity !== undefined) { - // elasticQuery = this.getRoleCondition(elasticQuery, 'ESDTRoleNFTAddQuantity', address, filter.canAddQuantity); - // } - - // if (filter.canUpdateAttributes !== undefined) { - // elasticQuery = this.getRoleCondition(elasticQuery, 'ESDTRoleNFTUpdateAttributes', address, filter.canUpdateAttributes); - // } - - // if (filter.canAddUri !== undefined) { - // elasticQuery = this.getRoleCondition(elasticQuery, 'ESDTRoleNFTAddURI', address, filter.canAddUri); - // } - - // if (filter.canTransferRole !== undefined) { - // elasticQuery = this.getRoleCondition(elasticQuery, 'ESDTTransferRole', address, filter.canTransferRole); - // } - - if (filter.collection !== undefined) { - query = query.andWhere('token = :token', { token: filter.collection }); - } - - if (filter.identifiers !== undefined) { - query = query.andWhere('identifier IN (:...identifiers)', { identifiers: filter.identifiers }); - } - - if (filter.search !== undefined) { - query = query.andWhere('(token like :search OR name like :search)', { search: `%${filter.search}%` }); - } - - if (filter.type !== undefined) { - query = query.andWhere('type IN (:...types)', { types: filter.type }); - } - - return query; - } - - // private getRoleCondition(query: ElasticQuery, name: string, address: string | undefined, value: string | boolean) { - // // TODO the "roles" column does not exist in "token_infos" table - // const condition = value === false ? QueryConditionOptions.mustNot : QueryConditionOptions.must; - // const targetAddress = typeof value === 'string' ? value : address; - - // return query.withCondition(condition, QueryType.Nested('roles', { [`roles.${name}`]: targetAddress })); - // } - - buildElasticNftFilter(repository: Repository, filter: NftFilter, identifier?: string, address?: string): SelectQueryBuilder { - let query = repository.createQueryBuilder() - .where(`identifier IS NOT NULL AND identifier != ''`); - - if (address) { - query = query.andWhere('address = :address', { address }); - } - - if (filter.search !== undefined) { - query = query.andWhere('(token like :search OR name like :search)', { search: `%${filter.search}%` }); - } - - if (filter.type !== undefined) { - query = query.andWhere('type IN (:...types)', { types: filter.type }); - } - - if (identifier !== undefined) { - query = query.andWhere('identifier = :identifier', { identifier }); - } - - if (filter.collection !== undefined && filter.collection !== '') { - query = query.andWhere('token = :token', { token: filter.collection }); - } - - if (filter.collections !== undefined && filter.collections.length !== 0) { - query = query.andWhere('token IN (:...collections)', { collections: filter.collections }); - } - - // TODO could not find a relationship between the "token_infos" and "token_meta_data" tables - // if (filter.name !== undefined && filter.name !== '') { - // query = query.withMustCondition(QueryType.Nested('data', { "data.name": filter.name })); - // } - - // if (filter.hasUris !== undefined) { - // query = query.withMustCondition(QueryType.Nested('data', { "data.nonEmptyURIs": filter.hasUris })); - // } - - // if (filter.tags) { - // query = query.withMustCondition(QueryType.Should(filter.tags.map(tag => QueryType.Nested("data", { "data.tags": tag })))); - // } - - // if (filter.creator !== undefined) { - // query = query.withMustCondition(QueryType.Nested("data", { "data.creator": filter.creator })); - // } - - if (filter.identifiers !== undefined) { - query = query.andWhere('identifier IN (:...identifiers)', { identifiers: filter.identifiers }); - } - - // if (filter.isWhitelistedStorage !== undefined && this.apiConfigService.getIsIndexerV3FlagActive()) { - // query = query.withMustCondition(QueryType.Nested("data", { "data.whiteListedStorage": filter.isWhitelistedStorage })); - // } - - // if (filter.isNsfw !== undefined) { - // const nsfwThreshold = this.apiConfigService.getNftExtendedAttributesNsfwThreshold(); - - // if (filter.isNsfw === true) { - // elasticQuery = elasticQuery.withRangeFilter('nft_nsfw_mark', new RangeGreaterThanOrEqual(nsfwThreshold)); - // } else { - // elasticQuery = elasticQuery.withRangeFilter('nft_nsfw_mark', new RangeLowerThan(nsfwThreshold)); - // } - - if (filter.before || filter.after) { - query = query.andWhere('timestamp BETWEEN :before AND :after', { before: filter.before ?? 0, after: filter.after ?? Date.now() }); - } - - return query; - } - - buildTransferFilterQuery(filter: TransactionFilter): SelectQueryBuilder { - let query = this.operationsRepository.createQueryBuilder(); - - if (filter.address) { - const smartContractResultCondition = AddressUtils.isSmartContractAddress(filter.address) - ? '(receiver = :receiver OR receivers like :receivers)' - : '(sender = :sender OR receiver = :receiver OR receivers like :receivers)'; // receivers: `%${filter.receiver}%`, - - query = query.andWhere( - `(((type = 'unsigned' AND ${smartContractResultCondition}) OR can_be_ignored IS NOT NULL) OR - (type = 'normal' AND (sender = :sender OR receiver = :receiver OR receivers like :receivers)))`, { - sender: filter.address, - receiver: filter.address, - receivers: `%${filter.address}%`, - }); - } - - if (filter.type) { - query = query.andWhere('type = :type', { type: filter.type === TransactionType.Transaction ? 'normal' : 'unsigned' }); - } - - if (filter.sender) { - query = query.andWhere('sender = :sender', { sender: filter.sender }); - } - - if (filter.receivers) { - query = query.andWhere('(receiver IN (:...receivers) OR receivers SIMILAR TO :similar)', { - receivers: filter.receivers, - similar: `%(${filter.receivers.join('|')})%`, - }); - } - - if (filter.token) { - query = query.andWhere('tokens like :token', { token: `%${filter.token}%` }); - } - - if (filter.functions !== undefined && filter.functions.length > 0) { - for (const func of filter.functions) { - query = query.andWhere('function = :function', { function: func }); - } - } - - if (filter.senderShard !== undefined) { - query = query.andWhere('sender_shard = :shard', { shard: filter.senderShard }); - } - - if (filter.receiverShard !== undefined) { - query = query.andWhere('receiver_shard = :shard', { shard: filter.receiverShard }); - } - - if (filter.miniBlockHash) { - query = query.andWhere('mb_hash = :hash', { hash: filter.miniBlockHash }); - } - - if (filter.hashes) { - query = query.andWhere('hash IN (:...hashes)', { hashes: filter.hashes }); - } - - if (filter.status) { - query = query.andWhere('status = :status', { status: filter.status }); - } - - if (filter.before || filter.after) { - query = query.andWhere('timestamp BETWEEN :before AND :after', { before: filter.before ?? 0, after: filter.after ?? Date.now() }); - } - - return query; - } - - buildTokensWithRolesForAddressQuery(_address: string, filter: TokenWithRolesFilter, pagination?: QueryPagination): SelectQueryBuilder { - let query = this.tokensRepository.createQueryBuilder() - .where(`identifier IS NOT NULL AND identifier != ''`) - .andWhere('type = :type', { type: TokenType.FungibleESDT }); - - // TODO the "roles" column does not exist in "token_infos" table - // .withMustCondition(QueryType.Should( - // [ - // QueryType.Match('currentOwner', address), - // QueryType.Nested('roles', { 'roles.ESDTRoleLocalMint': address }), - // QueryType.Nested('roles', { 'roles.ESDTRoleLocalBurn': address }), - // ] - // )) - - if (filter.identifier) { - query = query.andWhere('token = :token', { token: filter.identifier }); - } - if (filter.owner) { - query = query.andWhere('current_owner = :owner', { owner: filter.owner }); - } - if (filter.search) { - query = query.andWhere('(token like :search OR name like :search)', { search: `%${filter.search}%` }); - } - - if (filter.canMint !== undefined) { - // TODO the "roles" column does not exist in "token_infos" table - // const condition = filter.canMint === true ? QueryConditionOptions.must : QueryConditionOptions.mustNot; - // elasticQuery = elasticQuery.withCondition(condition, QueryType.Nested('roles', { 'roles.ESDTRoleLocalMint': address })); - } - - if (filter.canBurn !== undefined) { - // TODO the "roles" column does not exist in "token_infos" table - // const condition = filter.canBurn === true ? QueryConditionOptions.must : QueryConditionOptions.mustNot; - // elasticQuery = elasticQuery.withCondition(condition, QueryType.Nested('roles', { 'roles.ESDTRoleLocalBurn': address })); - } - - if (pagination) { - query = query.skip(pagination.from).take(pagination.size); - } - - return query; - } - - - async buildElasticRoundsFilter(filter: RoundFilter): Promise> { - let query = this.roundsRepository.createQueryBuilder(); - - if (filter.shard !== undefined) { - query = query.andWhere('shard_id = :shard', { shard: filter.shard }); - } - - if (filter.epoch !== undefined) { - query = query.andWhere('epoch = :epoch', { epoch: filter.epoch }); - } - - if (filter.validator !== undefined && filter.shard !== undefined && filter.epoch !== undefined) { - const index = await this.blsService.getBlsIndex(filter.validator, filter.shard, filter.epoch); - query = query.andWhere(`:index = ANY(REPLACE(REPLACE(signers_indexes, ']', '}'), '[', '{')::int[])`, { index }); - } - - return query; - } - - buildSmartContractResultFilterQuery(address?: string): SelectQueryBuilder { - let query = this.scResultsRepository.createQueryBuilder(); - - if (address) { - query = query.where('sender = :address OR receiver = :address', { address }); - } - - return query; - } - - buildTransactionFilterQuery(filter: TransactionFilter, address?: string): SelectQueryBuilder { - let query = this.transactionsRepository.createQueryBuilder(); - - if (filter.token !== undefined) { - query = query.andWhere('tokens like :token', { token: `%${filter.token}%` }); - } - if (filter.functions !== undefined && filter.functions.length > 0) { - for (const func of filter.functions) { - query = query.andWhere('function = :function', { function: func }); - } - } - if (filter.senderShard !== undefined) { - query = query.andWhere('sender_shard = :shard', { shard: filter.senderShard }); - } - if (filter.receiverShard !== undefined) { - query = query.andWhere('receiver_shard = :shard', { shard: filter.receiverShard }); - } - if (filter.miniBlockHash !== undefined) { - query = query.andWhere('mb_hash = :hash', { hash: filter.miniBlockHash }); - } - if (filter.status !== undefined) { - query = query.andWhere('status = :status', { status: filter.status }); - } - if (filter.hashes) { - query = query.andWhere('hash IN (:...hashes)', { hashes: filter.hashes }); - } - - if (filter.tokens !== undefined && filter.tokens.length !== 0) { - let condition = ''; - for (const index in filter.tokens) { - condition = `${condition} ${condition.length > 0 ? 'OR' : ''} (token like :token${index})`; - } - const params: any = {}; - for (const [token, index] of filter.tokens.entries()) { - params[`token${index}`] = token; - } - - query = query.andWhere(condition, params); - } - - if (filter.before || filter.after) { - query = query.andWhere('timestamp BETWEEN :before AND :after', { before: filter.before ?? 0, after: filter.after ?? Date.now() }); - } - - if (filter.condition === QueryConditionOptions.should) { - if (filter.sender) { - query = query.orWhere('sender = :sender', { sender: filter.sender }); - } - - if (filter.receivers) { - query = query.andWhere('(receiver IN (:...receivers) OR receivers SIMILAR TO :similar)', { - receivers: filter.receivers, - similar: `%(${filter.receivers.join('|')})%`, - }); - } - } else { - query = query.andWhere('sender = :sender', { sender: filter.sender }); - - if (filter.receivers) { - query = query.andWhere('(receiver IN (:...receivers) OR receivers SIMILAR TO :similar)', { - receivers: filter.receivers, - similar: `%(${filter.receivers.join('|')})%`, - }); - } - } - - if (address) { - query = query.andWhere('(sender = :sender OR receiver = :receiver OR receivers like :receivers)', { - sender: address, - receiver: address, - receivers: `%${address}%`, - }); - } - - return query; - } - - buildAccountHistoryFilterQuery(address?: string, token?: string): SelectQueryBuilder { - let query = this.accountHistoryRepository.createQueryBuilder(); - - if (address) { - query = query.andWhere('address = :address', { address }); - } - - if (token) { - query = query.andWhere('token = :token', { token }); - } - - return query; - } -} diff --git a/src/common/indexer/postgres/postgres.indexer.module.ts b/src/common/indexer/postgres/postgres.indexer.module.ts deleted file mode 100644 index cbad64af4..000000000 --- a/src/common/indexer/postgres/postgres.indexer.module.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { Module } from "@nestjs/common"; -import { TypeOrmModule, TypeOrmModuleOptions } from "@nestjs/typeorm"; -import { ApiConfigModule } from "src/common/api-config/api.config.module"; -import { ApiConfigService } from "src/common/api-config/api.config.service"; -import { PostgresIndexerService } from "./postgres.indexer.service"; -import { entities } from "./entities"; -import { PostgresIndexerHelper } from "./postgres.indexer.helper"; - -@Module({ - imports: [ - TypeOrmModule.forRootAsync({ - imports: [ApiConfigModule], - useFactory: (apiConfigService: ApiConfigService) => { - let replication = undefined; - const slaves = apiConfigService.getIndexerSlaveConnections(); - if (slaves.length > 0) { - replication = { - master: { - ...apiConfigService.getIndexerConnection(), - }, - slaves: apiConfigService.getIndexerSlaveConnections(), - }; - } - - const options: TypeOrmModuleOptions = { - type: 'postgres', - entities, - ...apiConfigService.getIndexerConnection(), - keepConnectionAlive: true, - synchronize: false, - retryAttempts: 300, - ssl: true, - extra: { - connectionLimit: 4, - ssl: { - rejectUnauthorized: false, - }, - }, - replication, - }; - - return options; - }, - inject: [ApiConfigService], - }), - TypeOrmModule.forFeature(entities), - ], - providers: [PostgresIndexerService, PostgresIndexerHelper], - exports: [PostgresIndexerService, TypeOrmModule.forFeature(entities), PostgresIndexerHelper], -}) -export class PostgresIndexerModule { } diff --git a/src/common/indexer/postgres/postgres.indexer.service.ts b/src/common/indexer/postgres/postgres.indexer.service.ts deleted file mode 100644 index 4999f9c80..000000000 --- a/src/common/indexer/postgres/postgres.indexer.service.ts +++ /dev/null @@ -1,703 +0,0 @@ -import { BinaryUtils } from "@multiversx/sdk-nestjs-common"; -import { Injectable } from "@nestjs/common"; -import { InjectRepository } from "@nestjs/typeorm"; -import { QueryPagination } from "src/common/entities/query.pagination"; -import { SortOrder } from "src/common/entities/sort.order"; -import { AccountHistoryFilter } from "src/endpoints/accounts/entities/account.history.filter"; -import { BlockFilter } from "src/endpoints/blocks/entities/block.filter"; -import { CollectionFilter } from "src/endpoints/collections/entities/collection.filter"; -import { MiniBlockFilter } from "src/endpoints/miniblocks/entities/mini.block.filter"; -import { NftFilter } from "src/endpoints/nfts/entities/nft.filter"; -import { RoundFilter } from "src/endpoints/rounds/entities/round.filter"; -import { SmartContractResultFilter } from "src/endpoints/sc-results/entities/smart.contract.result.filter"; -import { TokenFilter } from "src/endpoints/tokens/entities/token.filter"; -import { TokenWithRolesFilter } from "src/endpoints/tokens/entities/token.with.roles.filter"; -import { TransactionFilter } from "src/endpoints/transactions/entities/transaction.filter"; -import { Repository } from "typeorm"; -import { Collection, ScResult, Account, MiniBlock, Tag, TokenType, Block, ScDeploy } from "../entities"; -import { IndexerInterface } from "../indexer.interface"; -import { AccountDb, AccountsEsdtDb, BlockDb, LogDb, MiniBlockDb, ReceiptDb, RoundInfoDb, ScDeployInfoDb, ScResultDb, TagDb, TokenInfoDb, TransactionDb, ValidatorPublicKeysDb } from "./entities"; -import { PostgresIndexerHelper } from "./postgres.indexer.helper"; -import { AccountAssets } from "src/common/assets/entities/account.assets"; -import { ProviderDelegators } from "../entities/provider.delegators"; -import { ApplicationFilter } from "src/endpoints/applications/entities/application.filter"; -import { EventsFilter } from "src/endpoints/events/entities/events.filter"; -import { Events } from "../entities/events"; - -@Injectable() -export class PostgresIndexerService implements IndexerInterface { - constructor( - @InjectRepository(AccountDb) - private readonly accountsRepository: Repository, - @InjectRepository(AccountsEsdtDb) - private readonly accountsEsdtRepository: Repository, - @InjectRepository(ScResultDb) - private readonly scResultsRepository: Repository, - @InjectRepository(RoundInfoDb) - private readonly roundsRepository: Repository, - @InjectRepository(TokenInfoDb) - private readonly tokensRepository: Repository, - @InjectRepository(BlockDb) - private readonly blocksRepository: Repository, - @InjectRepository(TransactionDb) - private readonly transactionsRepository: Repository, - @InjectRepository(ScDeployInfoDb) - private readonly scDeploysRepository: Repository, - @InjectRepository(MiniBlockDb) - private readonly miniBlocksRepository: Repository, - @InjectRepository(TagDb) - private readonly tagsRepository: Repository, - @InjectRepository(ReceiptDb) - private readonly receiptsRepository: Repository, - @InjectRepository(LogDb) - private readonly logsRepository: Repository, - @InjectRepository(ValidatorPublicKeysDb) - private readonly validatorPublicKeysRepository: Repository, - private readonly indexerHelper: PostgresIndexerHelper, - ) { } - getEvents(_pagination: QueryPagination, _filter: EventsFilter): Promise { - throw new Error("Method not implemented."); - } - getEvent(_txHash: string): Promise { - throw new Error("Method not implemented."); - } - getEventsCount(_filter: EventsFilter): Promise { - throw new Error("Method not implemented."); - } - - getAccountDeploys(_pagination: QueryPagination, _address: string): Promise { - throw new Error("Method not implemented."); - } - getApplicationCount(): Promise { - throw new Error("Method not implemented."); - } - getApplications(_filter: ApplicationFilter): Promise { - throw new Error("Method not implemented."); - } - getProviderDelegatorsCount(_address: string): Promise { - throw new Error("Method not implemented."); - } - - getProviderDelegators(_address: string, _pagination: QueryPagination): Promise { - throw new Error("Method not implemented."); - } - getVersion(): Promise { - throw new Error("Method not implemented."); - } - - ensureAccountsWritable(): Promise { - throw new Error("Method not implemented."); - } - - ensureTokensWritable(): Promise { - throw new Error("Method not implemented."); - } - - setAccountAssetsFields(_address: string, _assets: AccountAssets): Promise { - throw new Error("Method not implemented."); - } - - getAccountHistoryCount(_address: string, _filter?: AccountHistoryFilter | undefined): Promise { - throw new Error("Method not implemented."); - } - - getAccountTokenHistoryCount(_address: string, _tokenIdentifier: string, _filter?: AccountHistoryFilter | undefined): Promise { - throw new Error("Method not implemented."); - } - - getAccountEsdtHistory(_address: string, _pagination: QueryPagination, _filter: AccountHistoryFilter): Promise { - throw new Error("Method not implemented."); - } - - getAccountEsdtHistoryCount(_address: string, _filter: AccountHistoryFilter): Promise { - throw new Error("Method not implemented."); - } - - getNftCollectionsByIds(_identifiers: string[]): Promise { - throw new Error("Method not implemented."); - } - - getSmartContractResults(_transactionHashes: string[]): Promise { - throw new Error("Method not implemented."); - } - - getAccountsForAddresses(_addresses: string[]): Promise { - throw new Error("Method not implemented."); - } - - getAccountsCount(): Promise { - throw new Error("Method not implemented."); - } - - async getScResultsCount(_filter: SmartContractResultFilter): Promise { - return await this.scResultsRepository.count(); - } - - async getAccountDeploysCount(address: string): Promise { - const query = this.scDeploysRepository - .createQueryBuilder() - .where('creator = :address', { address }); - - return await query.getCount(); - } - - async getBlocksCount(filter: BlockFilter): Promise { - const query = await this.indexerHelper.buildElasticBlocksFilter(filter); - return await query.getCount(); - } - - async getBlocks(filter: BlockFilter, { from, size }: QueryPagination): Promise { - let query = await this.indexerHelper.buildElasticBlocksFilter(filter); - query = query - .skip(from).take(size) - .orderBy('timestamp', 'DESC') - .addOrderBy('shard_id', 'ASC'); - - const result = await query.getMany(); - return result; - } - - async getNftCollectionCount(filter: CollectionFilter): Promise { - const query = this.indexerHelper.buildCollectionRolesFilter(filter); - return await query.getCount(); - } - - async getNftCountForAddress(address: string, filter: NftFilter): Promise { - const query = this.indexerHelper.buildElasticNftFilter(this.accountsEsdtRepository, filter, undefined, address); - return await query.getCount(); - } - - async getCollectionCountForAddress(address: string, filter: CollectionFilter): Promise { - const query = this.indexerHelper.buildCollectionRolesFilter(filter, address); - return await query.getCount(); - } - - async getNftCount(filter: NftFilter): Promise { - const query = this.indexerHelper.buildElasticNftFilter(this.tokensRepository, filter); - return await query.getCount(); - } - - async getNftOwnersCount(identifier: string): Promise { - const query = this.accountsEsdtRepository - .createQueryBuilder() - .where('address != :address', { address: 'pending' }) - .andWhere('token_name = :identifier', { identifier }); - return await query.getCount(); - } - - async getTransfersCount(filter: TransactionFilter): Promise { - const query = this.indexerHelper.buildTransferFilterQuery(filter); - return await query.getCount(); - } - - async getTokenCountForAddress(address: string): Promise { - const query = this.accountsEsdtRepository - .createQueryBuilder() - .where('address = :address', { address }) - .andWhere(`(token_identifier IS NULL OR token_identifier = '')`); - - return await query.getCount(); - } - - async getTokenAccountsCount(identifier: string): Promise { - const query = this.accountsEsdtRepository - .createQueryBuilder() - .where('token_name = :identifier', { identifier }); - - return await query.getCount(); - } - - async getTokenAccounts(pagination: QueryPagination, identifier: string): Promise { - const query = this.accountsEsdtRepository - .createQueryBuilder() - .skip(pagination.from).take(pagination.size) - .where(`token_name = :identifier AND address != 'pending'`, { identifier }) - .orderBy('balance_num', 'DESC'); - - return await query.getMany(); - } - - async getTokensWithRolesForAddressCount(address: string, filter: TokenWithRolesFilter): Promise { - const query = this.indexerHelper.buildTokensWithRolesForAddressQuery(address, filter); - return await query.getCount(); - } - - async getNftTagCount(search?: string | undefined): Promise { - let query = this.tagsRepository.createQueryBuilder(); - if (search) { - query = query.where(`tag like :search`, { search: `%${search}%` }); - } - - return await query.getCount(); - } - - async getRoundCount(filter: RoundFilter): Promise { - const query = await this.indexerHelper.buildElasticRoundsFilter(filter); - return await query.getCount(); - } - - async getAccountScResultsCount(address: string): Promise { - const query = this.indexerHelper.buildSmartContractResultFilterQuery(address); - return await query.getCount(); - } - - async getTransactionCountForAddress(address: string): Promise { - const query = this.transactionsRepository - .createQueryBuilder() - .where('sender = :address OR receiver = :address', { address }); - - return await query.getCount(); - } - - async getTransactionCount(filter: TransactionFilter, address?: string): Promise { - const query = this.indexerHelper.buildTransactionFilterQuery(filter, address); - return await query.getCount(); - } - - async getRound(shard: number, round: number): Promise { - return await this.roundsRepository.findOneByOrFail({ shardId: shard, index: round }); - } - - async getToken(identifier: string): Promise { - return await this.tokensRepository.findOneByOrFail({ identifier }); - } - - async getCollection(identifier: string): Promise { - return await this.tokensRepository.findOneByOrFail({ token: identifier }); - } - - async getTransaction(txHash: string): Promise { - return await this.transactionsRepository.findOneBy({ hash: txHash }); - } - - async getScDeploy(_address: string): Promise { - // TODO the "address" column does not exist in "sc_deploy_infos" table - return await this.scDeploysRepository.findOneByOrFail({}); - } - - async getScResult(scHash: string): Promise { - return await this.scResultsRepository.findOneByOrFail({ hash: scHash }); - } - - async getBlock(hash: string): Promise { - return await this.blocksRepository.findOneByOrFail({ hash }); - } - - async getMiniBlock(miniBlockHash: string): Promise { - const query = this.miniBlocksRepository - .createQueryBuilder() - .where('hash = :hash', { hash: miniBlockHash }); - - return await query.getOneOrFail(); - } - - async getTag(tag: string): Promise { - const query = this.tagsRepository - .createQueryBuilder() - .where('tag = :tag', { tag: BinaryUtils.base64Encode(tag) }); - - return await query.getOneOrFail(); - } - - async getTransfers(filter: TransactionFilter, pagination: QueryPagination): Promise { - const sortOrder = !filter.order || filter.order === SortOrder.desc ? 'DESC' : 'ASC'; - - const query = this.indexerHelper.buildTransferFilterQuery(filter) - .skip(pagination.from).take(pagination.size) - .orderBy('timestamp', sortOrder) - .addOrderBy('nonce', sortOrder); - - const operations = await query.getMany(); - return operations; - } - - async getTokensWithRolesForAddress(address: string, filter: TokenWithRolesFilter, pagination: QueryPagination): Promise { - const query = this.indexerHelper.buildTokensWithRolesForAddressQuery(address, filter, pagination); - const tokenList = await query.getMany(); - return tokenList; - } - - async getRounds(filter: RoundFilter): Promise { - let query = this.roundsRepository.createQueryBuilder(); - - if (filter.condition !== undefined) { - query = await this.indexerHelper.buildElasticRoundsFilter(filter); - } - - query = query - .skip(filter.from).take(filter.size) - .orderBy('timestamp', 'DESC'); - - return await query.getMany(); - } - - async getNftCollections({ from, size }: QueryPagination, filter: CollectionFilter, address?: string): Promise { - const query = this.indexerHelper - .buildCollectionRolesFilter(filter, address) - .skip(from).take(size) - .orderBy('timestamp', 'DESC'); - - return await query.getMany(); - } - - async getMiniBlocks(pagination: QueryPagination, filter: MiniBlockFilter): Promise { - let query = this.miniBlocksRepository.createQueryBuilder() - .skip(pagination.from).take(pagination.size); - - if (filter.hashes) { - query = query.andWhere('mb_hash = :hash IN (:...hashes)', { hashes: filter.hashes }); - } - - return await query.getMany(); - } - - async getAccountEsdtByAddressesAndIdentifier(identifier: string, addresses: string[]): Promise { - const query = this.accountsEsdtRepository - .createQueryBuilder() - .skip(0) - .take(addresses.length) - .where(`address != 'pending'`) - .andWhere('token_name = :identifier', { identifier }) - .andWhere('address IN (:...addresses)', { addresses }) - .andWhere('balance_num >= 0'); - - return await query.getMany(); - } - - async getNftTags(pagination: QueryPagination, search?: string | undefined): Promise { - let query = this.tagsRepository - .createQueryBuilder() - .skip(pagination.from) - .take(pagination.size) - .orderBy('count', 'DESC'); - if (search) { - query = query.where('tag like :tag', { tag: `%${search}%` }); - } - return await query.getMany(); - } - - async getScResults({ from, size }: QueryPagination, filter: SmartContractResultFilter): Promise { - let query = this.scResultsRepository - .createQueryBuilder() - .skip(from).take(size); - - if (filter.miniBlockHash) { - query = query.andWhere('mb_hash = :hash', { hash: filter.miniBlockHash }); - } - - if (filter.originalTxHashes) { - query = query.andWhere('original_tx_hash IN (:...hashes)', { hashes: filter.originalTxHashes }); - } - - return await query.getMany(); - } - - async getAccountScResults(address: string, { from, size }: QueryPagination): Promise { - const query = this.indexerHelper.buildSmartContractResultFilterQuery(address) - .skip(from).take(size) - .orderBy('timestamp', 'DESC'); - - return await query.getMany(); - } - - async getAccount(address: string): Promise { - return await this.accountsRepository.findOneByOrFail({ address }); - } - - async getAccounts({ from, size }: QueryPagination): Promise { - const query = this.accountsRepository - .createQueryBuilder() - .skip(from).take(size) - .orderBy('balance_num', 'DESC'); - - return await query.getMany(); - } - - getAccountContracts(): Promise { - throw new Error("Method not implemented."); - } - - getAccountContractsCount(): Promise { - throw new Error("Method not implemented."); - } - - async getAccountHistory(address: string, { from, size }: QueryPagination): Promise { - const query = this.indexerHelper.buildAccountHistoryFilterQuery(address) - .skip(from).take(size) - .orderBy('timestamp', 'DESC'); - - return await query.getMany(); - } - - async getAccountTokenHistory(address: string, tokenIdentifier: string, { from, size }: QueryPagination): Promise { - const query = this.indexerHelper.buildAccountHistoryFilterQuery(address, tokenIdentifier) - .skip(from).take(size) - .orderBy('timestamp', 'DESC'); - - return await query.getMany(); - } - - async getTransactions(filter: TransactionFilter, { from, size }: QueryPagination, address?: string): Promise { - const sortOrder = !filter.order || filter.order === SortOrder.desc ? 'DESC' : 'ASC'; - - const query = this.indexerHelper - .buildTransactionFilterQuery(filter, address) - .skip(from).take(size) - .orderBy('timestamp', sortOrder) - .addOrderBy('nonce', sortOrder); - - return await query.getMany(); - } - - async getTokensForAddress(address: string, { from, size }: QueryPagination, filter: TokenFilter): Promise { - let query = this.accountsEsdtRepository.createQueryBuilder() - .skip(from).take(size) - .where(`(token_identifier IS NULL OR token_identifier = '')`) - .andWhere('address = :address', { address }); - - if (filter.identifier) { - query = query.andWhere('token_name = :token', { token: filter.identifier }); - } - - if (filter.identifiers) { - query = query.andWhere('token_name IN (:...tokens)', { tokens: filter.identifiers }); - } - - // if (filter.name) { - // query = query.withMustCondition(QueryType.Nested('data.name', filter.name)); - // } - - // if (filter.search) { - // query = query.withMustCondition(QueryType.Nested('data.name', filter.search)); - // } - - return await query.getMany(); - } - - async getTransactionLogs(hashes: string[]): Promise { - const query = this.logsRepository - .createQueryBuilder() - .skip(0).take(10000) - .where('id IN (:...hashes)', { hashes }); - - return await query.getMany(); - } - - async getTransactionScResults(txHash: string): Promise { - const query = this.scResultsRepository - .createQueryBuilder() - .skip(0).take(100) - .where('original_tx_hash = :hash', { hash: txHash }) - .orderBy('timestamp', 'ASC'); - - return await query.getMany(); - } - - async getScResultsForTransactions(elasticTransactions: any[]): Promise { - const query = this.scResultsRepository - .createQueryBuilder() - .skip(0).take(10000) - .where('original_tx_hash IN (:...hashes)', { hashes: elasticTransactions.filter(x => x.hasScResults === true).map(x => x.txHash) }) - .orderBy('timestamp', 'ASC'); - - return await query.getMany(); - } - - async getAccountEsdtByIdentifiers(identifiers: string[], pagination?: QueryPagination): Promise { - if (identifiers.length === 0) { - return []; - } - - let query = this.accountsEsdtRepository - .createQueryBuilder() - .where(`address != 'pending'`) - .andWhere('token_identifier IN (:...identifiers)', { identifiers }) - .orderBy('balance_num', 'DESC') - .addOrderBy('timestamp', 'DESC'); - - - if (pagination) { - query = query.skip(pagination.from).take(pagination.size); - } - - return await query.getMany(); - } - - async getAccountsEsdtByCollection(identifiers: string[], pagination?: QueryPagination): Promise { - if (identifiers.length === 0) { - return []; - } - - let query = this.accountsEsdtRepository - .createQueryBuilder() - .where(`address != 'pending'`) - .andWhere('collection IN (:...identifiers)', { identifiers }) - .orderBy('balance_num', 'DESC') - .addOrderBy('timestamp', 'DESC'); - - - if (pagination) { - query = query.skip(pagination.from).take(pagination.size); - } - - return await query.getMany(); - } - - async getNftsForAddress(address: string, filter: NftFilter, { from, size }: QueryPagination): Promise { - const query = this.indexerHelper - .buildElasticNftFilter(this.accountsEsdtRepository, filter, undefined, address) - .skip(from).take(size) - .orderBy('timestamp', 'DESC') - .addOrderBy('token_nonce', 'DESC'); - - return await query.getMany(); - } - - async getNfts({ from, size }: QueryPagination, filter: NftFilter, identifier?: string): Promise { - const tokensQuery = this.indexerHelper - .buildElasticNftFilter(this.tokensRepository, filter, identifier) - .skip(from).take(size) - .orderBy('timestamp', 'DESC') - .addOrderBy('nonce', 'DESC'); - - let elasticNfts = await tokensQuery.getMany(); - if (elasticNfts.length === 0 && identifier !== undefined) { - const accountsesdtQuery = this.indexerHelper - .buildElasticNftFilter(this.accountsEsdtRepository, filter, identifier) - .skip(from).take(size) - .where('identifier = :identifier', { identifier }) - .orderBy('timestamp', 'DESC') - .addOrderBy('nonce', 'DESC'); - - elasticNfts = await accountsesdtQuery.getMany(); - } - return elasticNfts; - } - - async getTransactionBySenderAndNonce(sender: string, nonce: number): Promise { - const query = this.transactionsRepository - .createQueryBuilder() - .skip(0).take(1) - .where('sender = :sender AND nonce = :nonce', { sender, nonce }); - - return await query.getMany(); - } - - async getTransactionReceipts(txHash: string): Promise { - const query = this.receiptsRepository - .createQueryBuilder() - .skip(0).take(1) - .where('tx_hash = :txHash', { txHash }); - - return await query.getMany(); - } - - async getAllTokensMetadata(action: (items: any[]) => Promise): Promise { - // TODO could not find a relationship between the "token_infos" and "token_meta_data" tables - - let from = 0; - const size = 10000; - - let query = this.tokensRepository - .createQueryBuilder() - .where('type IN (:...types)', { types: [TokenType.NonFungibleESDT, TokenType.SemiFungibleESDT] }) - .andWhere(`identifier IS NOT NULL AND identifier != ''`); - - let count = 0; - do { - query = query.skip(from).take(size); - const items = await query.getMany(); - - if (items.length > 0) { - await action(items); - } - - count = items.length; - from = from + size; - } while (count >= size); - } - - async getEsdtAccountsCount(identifier: string): Promise { - const query = this.accountsEsdtRepository - .createQueryBuilder() - .andWhere('token_name = :identifier', { identifier }); - - return await query.getCount(); - } - - async getAllAccountsWithToken(identifier: string, action: (items: any[]) => Promise): Promise { - let from = 0; - const size = 10000; - - let query = this.accountsEsdtRepository - .createQueryBuilder() - .where('token_name = :identifier', { identifier }); - - let count = 0; - do { - query = query.skip(from).take(size); - const items = await query.getMany(); - - if (items.length > 0) { - await action(items); - } - - count = items.length; - from = from + size; - } while (count >= size); - } - - async getPublicKeys(shard: number, epoch: number): Promise { - const query = this.validatorPublicKeysRepository.createQueryBuilder() - .where('id = :id', { id: `${shard}_${epoch}` }); - - const result = await query.getOne(); - if (result !== null && result?.pubKeys.length > 0) { - return result.pubKeys; - } - - return undefined; - } - - // eslint-disable-next-line require-await - async getCollectionsForAddress(_address: string, _filter: CollectionFilter, _pagination: QueryPagination): Promise<{ collection: string; count: number; balance: number; }[]> { - // TODO not implemented - return []; - } - - // eslint-disable-next-line require-await - async getBlockByTimestampAndShardId(_timestamp: number, _shardId: number): Promise { - // TODO not implemented - return undefined; - } - - // eslint-disable-next-line require-await - async getAssetsForToken(_identifier: string): Promise { - // TODO custom columns cannot be added - return {}; - } - - async setAssetsForToken(_identifier: string, _value: any): Promise { - // TODO custom columns cannot be added - } - - async setIsWhitelistedStorageForToken(_identifier: string, _value: boolean): Promise { - // TODO custom columns cannot be added - } - - async setMediaForToken(_identifier: string, _value: any[]): Promise { - // TODO custom columns cannot be added - } - - async setMetadataForToken(_identifier: string, _value: any): Promise { - // TODO custom columns cannot be added - } - - async setExtraCollectionFields(_identifier: string, _isVerified: boolean, _holderCount: number, _nftCount: number): Promise { - // TODO custom columns cannot be added - } - - async setAccountTransfersLast24h(_address: string, _transfersLast24h: number): Promise { - // TODO custom columns cannot be added - } -}