diff --git a/src/main.ts b/src/main.ts index aec7a35..f84360e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,6 +7,7 @@ import { AppModule } from './app.module'; import { WinstonLoggerService } from './common/logger/winston-logger.service'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; import { StrUtil } from './utilz/strUtil'; +import { json } from 'body-parser'; function fixDatabaseUrl() { if (StrUtil.isEmpty(process.env.DATABASE_URL)) { @@ -24,6 +25,8 @@ async function bootstrap() { const app = await NestFactory.create(AppModule, { logger: new WinstonLoggerService(), }); + const MAX_HTTP_PAYLOAD = EnvLoader.getPropertyOrDefault('MAX_HTTP_PAYLOAD', '20mb'); + app.use(json({ limit: MAX_HTTP_PAYLOAD })); app.enableCors({ origin: '*', // Specify the client origin or use '*' for wide open access diff --git a/src/modules/block/block.service.ts b/src/modules/block/block.service.ts index 48cebef..55120e7 100644 --- a/src/modules/block/block.service.ts +++ b/src/modules/block/block.service.ts @@ -12,6 +12,7 @@ import { StrUtil } from '../../utilz/strUtil'; import { DateUtil } from '../../utilz/dateUtil'; import { Check } from '../../utilz/check'; import { NumUtil } from '../../utilz/numUtil'; +import { CaipAddr, ChainUtil } from '../../utilz/chainUtil'; @Injectable() export class BlockService { @@ -224,6 +225,7 @@ export class BlockService { if (StrUtil.isEmpty(sort)) { sort = 'DESC'; } + Check.isTrue(ChainUtil.isFullCAIPAddress(walletInCaip), 'invalid wallet, only caip10 format is supported' + walletInCaip); Check.isTrue(sort === 'ASC' || sort === 'DESC', 'invalid sort'); Check.isTrue(pageSize > 0 && pageSize <= 1000, 'invalid pageSize'); const isFirstQuery = StrUtil.isEmpty(firstTs); @@ -231,10 +233,12 @@ export class BlockService { let firstTsMillis = DateUtil.unixFloatToMillis(firstTsSeconds); Check.isTrue(isFirstQuery || firstTsSeconds != null); const comparator = sort === 'ASC' ? '>' : '<'; + const recipientJson = JSON.stringify({ recipients: [{ address: walletInCaip }] }); + let sql = `select ts, txn_hash, data_as_json from "Transaction" - where category=$1 and sender=$2 - ${isFirstQuery ? '' : `and ts ${comparator} $3`} + where category=$1 and (sender=$2 OR recipients @> $3::jsonb) + ${isFirstQuery ? '' : `and ts ${comparator} $4`} order by ts ${sort} FETCH FIRST ${pageSize} ROWS WITH TIES`; this.log.debug('query: %s', sql); @@ -242,9 +246,7 @@ export class BlockService { Array<{ ts: BigInt; txn_hash: string, data_as_json: any }> >( sql, - category, - walletInCaip, - firstTsMillis + category, walletInCaip, recipientJson, firstTsMillis ); const itemsArr = rows.map((row) => { let tx:{ fee: string, data: string, type: number, sender: string, category: string, recipientsList: string} = row.data_as_json.tx;