Skip to content

Commit

Permalink
add relayed transaction version
Browse files Browse the repository at this point in the history
  • Loading branch information
cfaur09 committed Oct 2, 2023
1 parent 0243332 commit 3b2c389
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/endpoints/transactions/entities/transaction.detailed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@ export class TransactionDetailed extends Transaction {
@Field(() => Boolean, { description: "InTransit transaction details.", nullable: true })
@ApiProperty({ type: Boolean, nullable: true })
inTransit: boolean | undefined = undefined;

@Field(() => String, { description: "Relayed transaction version.", nullable: true })
@ApiProperty({ type: String, nullable: true })
relayedVersion: string | undefined = undefined;
}

2 changes: 1 addition & 1 deletion src/endpoints/transactions/entities/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class Transaction {
@ApiProperty({ type: String, nullable: true })
guardianSignature: string | undefined = undefined;

@Field(() => String, { description: "Is relayed transaction.", nullable: true })
@Field(() => Boolean, { description: "Is relayed transaction.", nullable: true })
@ApiProperty({ type: String, nullable: true })
isRelayed: boolean | undefined = undefined;

Expand Down
27 changes: 26 additions & 1 deletion src/endpoints/transactions/transaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { GatewayComponentRequest } from 'src/common/gateway/entities/gateway.com
import { TransactionActionService } from './transaction-action/transaction.action.service';
import { TransactionDecodeDto } from './entities/dtos/transaction.decode.dto';
import { TransactionStatus } from './entities/transaction.status';
import { AddressUtils, Constants, PendingExecuter } from '@multiversx/sdk-nestjs-common';
import { AddressUtils, BinaryUtils, Constants, PendingExecuter } from '@multiversx/sdk-nestjs-common';
import { ApiUtils } from "@multiversx/sdk-nestjs-http";
import { CacheService } from "@multiversx/sdk-nestjs-cache";
import { TransactionUtils } from './transaction.utils';
Expand Down Expand Up @@ -176,6 +176,15 @@ export class TransactionService {
transactions = await this.getExtraDetailsForTransactions(elasticTransactions, transactions, queryOptions);
}

transactions = transactions.map(transaction => {
const relayedVersion = this.extractRelayedVersion(transaction);
if (relayedVersion) {
transaction.relayedVersion = relayedVersion;
}

return transaction;
});

await this.processTransactions(transactions, {
withScamInfo: queryOptions?.withScamInfo ?? false,
withUsername: queryOptions?.withUsername ?? false,
Expand Down Expand Up @@ -540,4 +549,20 @@ export class TransactionService {
}
}
}

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

const relayedMatch = decodedData.match(/relayedTx(V\d+)?/);
if (relayedMatch) {
if (relayedMatch[1]) {
return relayedMatch[1].toLowerCase();
} else {
return 'v1';
}
}
}
return null;
}
}

0 comments on commit 3b2c389

Please sign in to comment.