diff --git a/src/tokens/tokens.interfaces.ts b/src/tokens/tokens.interfaces.ts index 4c6af14..eef1946 100644 --- a/src/tokens/tokens.interfaces.ts +++ b/src/tokens/tokens.interfaces.ts @@ -15,7 +15,7 @@ // limitations under the License. import { ApiProperty } from '@nestjs/swagger'; -import { IsDefined, IsInt, IsNotEmpty, Min } from 'class-validator'; +import { IsDefined, IsInt, IsNotEmpty, IsOptional, Min } from 'class-validator'; import { Event } from '../event-stream/event-stream.interfaces'; // Ethconnect interfaces @@ -73,6 +73,10 @@ export class TokenPool { @ApiProperty() @IsNotEmpty() clientId: string; + + @ApiProperty() + @IsOptional() + requestId?: string; } export class TokenMint { @@ -88,6 +92,10 @@ export class TokenMint { @IsInt() @Min(1) amount: number; + + @ApiProperty() + @IsOptional() + requestId?: string; } export class TokenBalanceQuery { @@ -130,6 +138,10 @@ export class TokenTransfer { @IsInt() @Min(1) amount: number; + + @ApiProperty() + @IsOptional() + requestId?: string; } // Websocket notifications diff --git a/src/tokens/tokens.service.ts b/src/tokens/tokens.service.ts index 426e169..29a5b77 100644 --- a/src/tokens/tokens.service.ts +++ b/src/tokens/tokens.service.ts @@ -66,13 +66,15 @@ export class TokensService { this.shortPrefix = shortPrefix; } - private get postOptions() { + private postOptions(requestId?: string) { const from = `${this.shortPrefix}-from`; const sync = `${this.shortPrefix}-sync`; + const id = `${this.shortPrefix}-id`; return { params: { [from]: this.identity, [sync]: 'false', + [id]: requestId, }, }; } @@ -92,7 +94,7 @@ export class TokensService { data: packTokenData(dto.namespace, dto.name, dto.clientId), is_fungible: dto.type === TokenType.FUNGIBLE, }, - this.postOptions, + this.postOptions(dto.requestId), ) .toPromise(); return { id: response.data.id }; @@ -110,7 +112,7 @@ export class TokensService { amounts: [dto.amount], data: [0], }, - this.postOptions, + this.postOptions(dto.requestId), ) .toPromise(); return { id: response.data.id }; @@ -128,7 +130,7 @@ export class TokensService { to, data: [0], }, - this.postOptions, + this.postOptions(dto.requestId), ) .toPromise(); return { id: response.data.id }; @@ -158,7 +160,7 @@ export class TokensService { amount: dto.amount, data: [0], }, - this.postOptions, + this.postOptions(dto.requestId), ) .toPromise(); return { id: response.data.id }; diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts index ede087f..afd0f33 100644 --- a/test/app.e2e-spec.ts +++ b/test/app.e2e-spec.ts @@ -128,15 +128,16 @@ describe('AppController (e2e)', () => { namespace: 'testns', name: 'token1', clientId: '1', + requestId: '12345', }; const response: EthConnectAsyncResponse = { - id: '1', + id: '12345', sent: true, }; http.post = jest.fn(() => new FakeObservable(response)); - await server.post('/pool').send(request).expect(202).expect({ id: '1' }); + await server.post('/pool').send(request).expect(202).expect({ id: '12345' }); expect(http.post).toHaveBeenCalledTimes(1); expect(http.post).toHaveBeenCalledWith( @@ -145,7 +146,13 @@ describe('AppController (e2e)', () => { data: '0x746573746e7300746f6b656e310031', is_fungible: true, }, - OPTIONS, + { + ...OPTIONS, + params: { + ...OPTIONS.params, + 'fly-id': '12345', + }, + }, ); });