Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/scan 432 parse ethereum executed event #166

Merged
merged 3 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
evm transactions resolver
  • Loading branch information
AzgatG committed Nov 24, 2022
commit cf59cff213fce313ab5eea52bdb577a804829fec
2 changes: 2 additions & 0 deletions apps/web-api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { TransactionModule } from './transaction/transaction.module';
import { SentryModule } from '@ntegral/nestjs-sentry';
import { ContractModule } from './contract/contract.module';
import { AttributesModule } from './attributes/attributes.module';
import { EvmTransactionModule } from './evm-transactions/evm-transaction.module';

@Module({
imports: [
Expand Down Expand Up @@ -59,6 +60,7 @@ import { AttributesModule } from './attributes/attributes.module';
StatisticsModule,
TransactionModule,
AttributesModule,
EvmTransactionModule,
],
providers: [
{
Expand Down
50 changes: 50 additions & 0 deletions apps/web-api/src/evm-transactions/evm-transaction.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Field, Float, Int, ObjectType } from '@nestjs/graphql';
import { EvmTransaction } from '@entities/EvmTransaction';

@ObjectType('evmTransaction')
export class EvmTransactionDTO implements Partial<EvmTransaction> {
@Field()
to?: string;

@Field()
from?: string;

@Field({ nullable: true })
contract_address?: string | null;

@Field(() => Int)
transaction_index?: number;

@Field(() => Float)
gas_used?: number;

@Field()
logs_bloom?: string;

@Field()
block_hash?: string;

@Field()
transaction_hash?: string;

@Field(() => Int)
block_number?: number;

@Field(() => Int)
confirmations?: number;

@Field(() => Float)
cumulative_gas_used?: number;

@Field(() => Float)
effective_gas_price?: number;

@Field(() => Int)
status?: number;

@Field(() => Int)
type?: number;

@Field(() => Boolean)
byzantium?: boolean;
}
11 changes: 11 additions & 0 deletions apps/web-api/src/evm-transactions/evm-transaction.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { EvmTransaction } from '@entities/EvmTransaction';
import { EvmTransactionResolver } from './evm-transaction.resolver';
import { EvmTransactionService } from './evm-transaction.service';

@Module({
imports: [TypeOrmModule.forFeature([EvmTransaction])],
providers: [EvmTransactionResolver, EvmTransactionService],
})
export class EvmTransactionModule {}
81 changes: 81 additions & 0 deletions apps/web-api/src/evm-transactions/evm-transaction.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {
Args,
ArgsType,
Field,
Info,
InputType,
ObjectType,
Query,
Resolver,
} from '@nestjs/graphql';
import {
GQLOrderByParamsArgs,
GQLQueryPaginationArgs,
GQLWhereOpsInt,
GQLWhereOpsString,
IDataListResponse,
IGQLQueryArgs,
ListDataType,
TOrderByParams,
TWhereParams,
} from '../utils/gql-query-args';
import { EvmTransactionDTO } from './evm-transaction.dto';
import { EvmTransactionService } from './evm-transaction.service';

@InputType()
class EvmTransactionWhereParams implements TWhereParams<EvmTransactionDTO> {
@Field(() => GQLWhereOpsString, { nullable: true })
from?: GQLWhereOpsString;

@Field(() => GQLWhereOpsString, { nullable: true })
to?: GQLWhereOpsString;

@Field(() => GQLWhereOpsInt, { nullable: true })
block_number?: GQLWhereOpsInt;

@Field(() => GQLWhereOpsString, { nullable: true })
block_hash?: GQLWhereOpsString;

@Field(() => GQLWhereOpsString, { nullable: true })
transaction_hash?: GQLWhereOpsString;

@Field(() => [EvmTransactionWhereParams], { nullable: true })
_and?: EvmTransactionWhereParams[];

@Field(() => [EvmTransactionWhereParams], { nullable: true })
_or?: EvmTransactionWhereParams[];
}

@InputType()
class EvmTransactionOrderByParams implements TOrderByParams<EvmTransactionDTO> {
@Field(() => GQLOrderByParamsArgs, { nullable: true })
block_number?: GQLOrderByParamsArgs;
}

@ObjectType()
class EmvTransactionDataResponse extends ListDataType(EvmTransactionDTO) {}

@ArgsType()
export class QueryArgs
extends GQLQueryPaginationArgs
implements IGQLQueryArgs<EvmTransactionDTO>
{
@Field(() => EvmTransactionWhereParams, { nullable: true })
where?: EvmTransactionWhereParams;

@Field(() => EvmTransactionOrderByParams, { nullable: true })
order_by?: EvmTransactionOrderByParams;
}

@Resolver(() => EvmTransactionDTO)
export class EvmTransactionResolver {
constructor(private service: EvmTransactionService) {}

@Query(() => EmvTransactionDataResponse)
public async evmTransactions(
@Args() args: QueryArgs,
@Info() info,
): Promise<IDataListResponse<EvmTransactionDTO>> {
return this.service.find(args, info);
}
}
62 changes: 62 additions & 0 deletions apps/web-api/src/evm-transactions/evm-transaction.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, SelectQueryBuilder } from 'typeorm';
import { EvmTransaction } from '@entities/EvmTransaction';
import { GraphQLResolveInfo } from 'graphql';
import { FieldsListOptions } from 'graphql-fields-list';
import { BaseService } from '../utils/base.service';
import { IDataListResponse } from '../utils/gql-query-args';
import { SentryWrapper } from '../utils/sentry.decorator';
import { EvmTransactionDTO } from './evm-transaction.dto';
import { QueryArgs } from './evm-transaction.resolver';

@Injectable()
export class EvmTransactionService extends BaseService<
EvmTransaction,
EvmTransactionDTO
> {
constructor(
@InjectRepository(EvmTransaction) private repo: Repository<EvmTransaction>,
) {
super();
}

@SentryWrapper({ data: [], count: 0 })
public async find(
queryArgs: QueryArgs,
queryInfo: GraphQLResolveInfo,
): Promise<IDataListResponse<EvmTransaction>> {
const qb = this.repo.createQueryBuilder();

this.applyArgs(qb, queryArgs, queryInfo);

return this.getDataAndCount(qb, queryArgs);
}

private applyArgs(
qb: SelectQueryBuilder<EvmTransaction>,
queryArgs: QueryArgs,
queryInfo: GraphQLResolveInfo,
): void {
this.select(qb, queryArgs, queryInfo);

this.applyDistinctOn(qb, queryArgs);

this.applyLimitOffset(qb, queryArgs);

this.applyWhereCondition(qb, queryArgs);

this.applyOrderCondition(qb, queryArgs);
}

private select(
qb: SelectQueryBuilder<EvmTransaction>,
queryArgs: QueryArgs,
queryInfo: GraphQLResolveInfo,
queryFieldsOptions?: FieldsListOptions,
): void {
const queryFields = this.getQueryFields(queryInfo, queryFieldsOptions);

this.applySelect(qb, queryArgs, queryFields);
}
}