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

relayed v3 features #1299

Merged
merged 20 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 21 additions & 0 deletions src/common/gateway/entities/transaction.inner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export class TransactionInner {
constructor(init?: Partial<TransactionInner>) {
Object.assign(this, init);
}

nonce: number = 0;
value: string = '';
receiver: string = '';
sender: string = '';
gasPrice: number = 0;
gasLimit: number = 0;
data: string = '';
signature: string = '';
chainID: string = '';
version: number = 0;
cfaur09 marked this conversation as resolved.
Show resolved Hide resolved
relayer: string = '';
options: number = 0;
guardianSignature: string = '';
senderUsername: string = '';
cfaur09 marked this conversation as resolved.
Show resolved Hide resolved
receiverUsername: string = '';
}
4 changes: 4 additions & 0 deletions src/common/indexer/elastic/elastic.indexer.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ export class ElasticIndexerHelper {
]));
}

if (filter.relayer) {
elasticQuery = elasticQuery.withMustMatchCondition('relayerAddr', filter.relayer);
}

if (filter.type) {
elasticQuery = elasticQuery.withCondition(QueryConditionOptions.must, QueryType.Match('type', filter.type === TransactionType.Transaction ? 'normal' : 'unsigned'));
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/indexer/entities/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ export interface Transaction {
receiversShardIDs: number[];
operation: string;
scResults: any[];
version: number;
relayerAddr: string;
}
3 changes: 3 additions & 0 deletions src/endpoints/accounts/account.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ export class AccountController {
@ApiQuery({ name: 'before', description: 'Before timestamp', required: false })
@ApiQuery({ name: 'after', description: 'After timestamp', required: false })
@ApiQuery({ name: 'fields', description: 'List of fields to filter by', required: false })
@ApiQuery({ name: 'relayer', description: 'Address of the relayer', required: false })
@ApiQuery({ name: 'withScamInfo', description: 'Returns scam information', required: false, type: Boolean })
@ApiQuery({ name: 'withUsername', description: 'Integrates username in assets for all addresses present in the transactions', required: false, type: Boolean })
@ApiQuery({ name: 'withBlockInfo', description: 'Returns sender / receiver block details', required: false, type: Boolean })
Expand All @@ -963,6 +964,7 @@ export class AccountController {
@Query('after', ParseIntPipe) after?: number,
@Query('fields', ParseArrayPipe) fields?: string[],
@Query('order', new ParseEnumPipe(SortOrder)) order?: SortOrder,
@Query('relayer', ParseAddressPipe) relayer?: string,
@Query('withScamInfo', new ParseBoolPipe) withScamInfo?: boolean,
@Query('withUsername', new ParseBoolPipe) withUsername?: boolean,
@Query('withBlockInfo', new ParseBoolPipe) withBlockInfo?: boolean,
Expand All @@ -989,6 +991,7 @@ export class AccountController {
after,
order,
senderOrReceiver,
relayer,
}),
new QueryPagination({ from, size }),
options,
Expand Down
4 changes: 4 additions & 0 deletions src/endpoints/sc-results/entities/smart.contract.result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@ export class SmartContractResult {
@Field(() => String, { description: 'Function call', nullable: true })
@ApiProperty({ type: String, nullable: true })
function: string | undefined = undefined;

@Field(() => String, { description: 'Result status', nullable: true })
@ApiProperty({ type: String, nullable: true })
status: string | undefined = undefined;
}
6 changes: 5 additions & 1 deletion src/endpoints/transactions/entities/transaction.detailed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TransactionReceipt } from './transaction.receipt';
import { TransactionLog } from './transaction.log';
import { TransactionOperation } from './transaction.operation';
import { ComplexityEstimation } from '@multiversx/sdk-nestjs-common';
import { TransactionInner } from 'src/common/gateway/entities/transaction.inner';

@ObjectType(TransactionDetailed.name, { description: 'Detailed Transaction object type that extends Transaction.' })
export class TransactionDetailed extends Transaction {
Expand Down Expand Up @@ -64,5 +65,8 @@ export class TransactionDetailed extends Transaction {
@Field(() => String, { description: "Relayed transaction version.", nullable: true })
@ApiProperty({ type: String, nullable: true })
relayedVersion: string | undefined = undefined;
}

@Field(() => [TransactionInner], { description: 'Inner transactions list details.', nullable: true })
@ApiProperty({ type: TransactionInner, isArray: true })
innerTransactions: TransactionInner[] | undefined = undefined;
}
1 change: 1 addition & 0 deletions src/endpoints/transactions/entities/transaction.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ export class TransactionFilter {
tokens?: string[];
senderOrReceiver?: string;
isRelayed?: boolean;
relayer?: string;
}
4 changes: 4 additions & 0 deletions src/endpoints/transactions/entities/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export class Transaction {
@ApiProperty({ type: String, nullable: true })
isRelayed: boolean | undefined = undefined;

@Field(() => String, { description: "Relayer address for the given transaction.", nullable: true })
@ApiProperty({ type: String, nullable: true })
relayer: string | undefined = undefined;

getDate(): Date | undefined {
if (this.timestamp) {
return new Date(this.timestamp * 1000);
Expand Down
18 changes: 9 additions & 9 deletions src/endpoints/transactions/transaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,16 +552,16 @@ export class TransactionService {
}

private extractRelayedVersion(transaction: TransactionDetailed): string | undefined {
if (transaction.isRelayed == true && transaction.data) {
const decodedData = BinaryUtils.base64Decode(transaction.data);
if (transaction.isRelayed == true && transaction.data) {
const decodedData = BinaryUtils.base64Decode(transaction.data);

if (decodedData.startsWith('relayedTx@')) {
return 'v1';
} else if (decodedData.startsWith('relayedTxV2@')) {
return 'v2';
if (decodedData.startsWith('relayedTx@')) {
return 'v1';
} else if (decodedData.startsWith('relayedTxV2@')) {
return 'v2';
}
}
}

return undefined;
}
return undefined;
}
}
5 changes: 4 additions & 1 deletion src/endpoints/transfers/transfer.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ParseBlockHashPipe, ParseEnumPipe, ParseIntPipe, ParseArrayPipe, ParseAddressArrayPipe, ParseBoolPipe, ApplyComplexity } from "@multiversx/sdk-nestjs-common";
import { ParseBlockHashPipe, ParseEnumPipe, ParseIntPipe, ParseArrayPipe, ParseAddressArrayPipe, ParseBoolPipe, ApplyComplexity, ParseAddressPipe } from "@multiversx/sdk-nestjs-common";
import { Controller, DefaultValuePipe, Get, Query } from "@nestjs/common";
import { ApiExcludeEndpoint, ApiOkResponse, ApiOperation, ApiQuery, ApiTags } from "@nestjs/swagger";
import { QueryPagination } from "src/common/entities/query.pagination";
Expand Down Expand Up @@ -37,6 +37,7 @@ export class TransferController {
@ApiQuery({ name: 'before', description: 'Before timestamp', required: false })
@ApiQuery({ name: 'after', description: 'After timestamp', required: false })
@ApiQuery({ name: 'function', description: 'Filter transfers by function name', required: false })
@ApiQuery({ name: 'relayer', description: 'Filter by relayer address', required: false })
@ApiQuery({ name: 'withScamInfo', description: 'Returns scam information', required: false, type: Boolean })
@ApiQuery({ name: 'withUsername', description: 'Integrates username in assets for all addresses present in the transactions', required: false, type: Boolean })
@ApiQuery({ name: 'withBlockInfo', description: 'Returns sender / receiver block details', required: false, type: Boolean })
Expand All @@ -59,6 +60,7 @@ export class TransferController {
@Query('after', ParseIntPipe) after?: number,
@Query('order', new ParseEnumPipe(SortOrder)) order?: SortOrder,
@Query('fields', ParseArrayPipe) fields?: string[],
@Query('relayer', ParseAddressPipe) relayer?: string,
@Query('withScamInfo', new ParseBoolPipe) withScamInfo?: boolean,
@Query('withUsername', new ParseBoolPipe) withUsername?: boolean,
@Query('withBlockInfo', new ParseBoolPipe) withBlockInfo?: boolean,
Expand All @@ -83,6 +85,7 @@ export class TransferController {
before,
after,
order,
relayer,
}),
new QueryPagination({ from, size }),
options,
Expand Down
1 change: 1 addition & 0 deletions src/endpoints/transfers/transfer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class TransferService {
for (const elasticOperation of elasticOperations) {
const transaction = ApiUtils.mergeObjects(new TransactionDetailed(), elasticOperation);
transaction.type = elasticOperation.type === 'normal' ? TransactionType.Transaction : TransactionType.SmartContractResult;
transaction.relayer = elasticOperation.relayerAddr;

if (transaction.type === TransactionType.SmartContractResult) {
delete transaction.gasLimit;
Expand Down
2 changes: 2 additions & 0 deletions src/test/unit/services/accounts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ describe('Account Service', () => {
receiversShardIDs: [],
operation: '',
scResults: [],
relayerAddr: '',
version: 2,
});

const result = await service.getAccountDeployedAtRaw(address);
Expand Down
4 changes: 4 additions & 0 deletions src/test/unit/services/transactions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ describe('TransactionService', () => {
receiversShardIDs: [1],
operation: 'transfer',
scResults: [''],
relayerAddr: 'erd1sdrjn0uuulydacwjam3v5afl427ptk797fpcujpfcsakfck8aqjquq9afc',
version: 1,
},
{
hash: '2b1ce5558f5faa533afd437a42a5aeadea8302dc3cca778c0ed50d19c0a047a4',
Expand Down Expand Up @@ -218,6 +220,8 @@ describe('TransactionService', () => {
receiversShardIDs: [1],
operation: 'transfer',
scResults: [''],
relayerAddr: 'erd1sdrjn0uuulydacwjam3v5afl427ptk797fpcujpfcsakfck8aqjquq9afc',
version: 1,
},
];

Expand Down
Loading