Skip to content

Commit

Permalink
feat: extend irec claim data (#3336)
Browse files Browse the repository at this point in the history
  • Loading branch information
soanvig authored Mar 14, 2022
1 parent ab7c502 commit 051544d
Show file tree
Hide file tree
Showing 52 changed files with 3,068 additions and 979 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ common/autoinstallers/*/.npmrc
# Vscode
.vscode

# Emacs
.#*
#*

# !Ignore
!.env.example
!.env.test
Expand Down
3,189 changes: 2,433 additions & 756 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ export class CreateConnectionHandler implements ICommandHandler<CreateConnection
]);
} else if (isParticipant) {
await this.createAccounts(clientId, clientSecret, tokens, organization, [
AccountType.Trade
AccountType.Trade,
AccountType.Redemption
]);
} else {
if (!isRegistrant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,26 @@ export class IrecMockService implements IIrecService {
sender: 'TPOTRADE1',
recipient: 'TRUPOWER',
verificationKey: 'S4ELosCw',
encryptedKey: 'S4ELosCw'
encryptedKey: 'S4ELosCw',
items: {
[assetId]: {
start_cert_num: '0000-0000-0000-0001',
end_cert_num: '0000-0000-0000-1000',
volume: '1000'
}
},
periodStart: {
date: '2020-01-01 12:32:34.000000',
timezone_type: 3,
timezone: 'UTC'
},
periodEnd: {
date: '2020-02-02 12:32:34.000000',
timezone_type: 3,
timezone: 'UTC'
},
verificationUrl:
'https://baseUrl/public/certificates/en/PwC0IE2x+ugRPJRYhwlGCTjEqk7RDz0x+zzp6Ks0k1M='
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
ForbiddenException,
Injectable,
NotFoundException,
UnauthorizedException
UnauthorizedException,
Logger
} from '@nestjs/common';
import { CommandBus } from '@nestjs/cqrs';
import { ConfigService } from '@nestjs/config';
Expand Down Expand Up @@ -159,6 +160,7 @@ export interface IIrecService {
@Injectable()
export class IrecService implements IIrecService {
private platformAdmin: TUserBaseEntity;
private logger = new Logger(IrecService.name);

constructor(
private readonly commandBus: CommandBus,
Expand Down Expand Up @@ -316,7 +318,9 @@ export class IrecService implements IIrecService {

async getRedemptionAccountCode(user: UserIdentifier): Promise<string> {
const accounts = await this.getAccountInfo(user);
return accounts.find((account: Account) => account.type === AccountType.Issue)?.code || '';
return (
accounts.find((account: Account) => account.type === AccountType.Redemption)?.code || ''
);
}

async createAccount(user: UserIdentifier, params: CreateAccountParams): Promise<void> {
Expand Down Expand Up @@ -445,7 +449,9 @@ export class IrecService implements IIrecService {
const item = items.find((i) => i.asset === assetId);

if (!item) {
throw new NotFoundException('IREC item not found');
const availableAssets = items.map((i) => i.asset).join(', ');
this.logger.debug(`Asset ${assetId} not found. Available assets: ${availableAssets}`);
throw new NotFoundException(`IREC item not found.`);
}

const claimItem = new ReservationItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@ export class GetAllCertificatesHandler implements IQueryHandler<GetAllCertificat
const creationTimeFrom = dateToSeconds(options.creationTimeFrom ?? new Date(0));
const creationTimeTo = dateToSeconds(options.creationTimeTo ?? futureDate);

process.stdout.write(
JSON.stringify({
where: {
generationEndTime: Between(generationEndFrom, generationEndTo),
generationStartTime: Between(generationStartFrom, generationStartTo),
creationTime: Between(creationTimeFrom, creationTimeTo),
...(options.deviceId ? { deviceId: options.deviceId } : {})
},
order: {
id: 'ASC'
}
})
);

return this.repository.find({
where: {
generationEndTime: Between(generationEndFrom, generationEndTo),
Expand Down
28 changes: 26 additions & 2 deletions packages/traceability/issuer-irec-api-wrapper/src/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,34 @@ export class RedeemTransaction extends Transaction {
end: Date;
}

export interface RedeemTransactionPeriod {
date: string;
timezone_type: number;
timezone: string;
}

export interface RedeemTransactionItem {
start_cert_num: string;
end_cert_num: string;
volume: string;
}

export class RedeemTransactionResult extends TransactionResult {
@Expose({ name: 'encrypted_key', toClassOnly: true })
encryptedKey: string;
@Expose({ name: 'period_start', toClassOnly: true })
periodStart: RedeemTransactionPeriod;

@Expose({ name: 'period_end', toClassOnly: true })
periodEnd: RedeemTransactionPeriod;

/** Key = item id */
items: Record<string, RedeemTransactionItem>;

@Expose({ name: 'verification_url', toClassOnly: true })
verificationUrl: string;

@Expose({ name: 'verification_key', toClassOnly: true })
verificationKey: string;

@Expose({ name: 'encrypted_key', toClassOnly: true })
encryptedKey?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -604,13 +604,10 @@ export class IRECAPIClient {
(res) => res,
(err) => {
const status = err?.response?.data?.status ?? err?.response?.status ?? 500;
return Promise.reject(
new HttpException(
'IREC API Error:' +
(err?.response?.data?.msg ?? err?.response?.data?.title ?? err.message),
status
)
const message = JSON.stringify(
err?.response?.data ?? err.message ?? 'unknown error'
);
return Promise.reject(new HttpException('IREC API Error:' + message, status));
}
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,20 @@
import { ApiBearerAuth, ApiBody, ApiResponse, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import {
Body,
Controller,
HttpStatus,
Param,
ParseIntPipe,
Put,
UseGuards,
UseInterceptors,
UsePipes,
ValidationPipe
} from '@nestjs/common';

import {
ActiveUserGuard,
BlockchainAccountGuard,
ExceptionInterceptor,
UserDecorator
} from '@energyweb/origin-backend-utils';
import { CertificateController, TxHashDTO } from '@energyweb/issuer-api';
import { ClaimIrecCertificateDTO } from './dto/claim-irec-certificate.dto';
import { ILoggedInUser } from '@energyweb/origin-backend-core';
import { ClaimIRECCertificateCommand } from './command';
import { CertificateController } from '@energyweb/issuer-api';

@ApiTags('irec-certificates')
@ApiBearerAuth('access-token')
@Controller('/irec/certificate')
@UseInterceptors(ExceptionInterceptor)
@UsePipes(ValidationPipe)
export class IrecCertificateController extends CertificateController {
@Put('/:id/claim')
@UseGuards(AuthGuard(), ActiveUserGuard, BlockchainAccountGuard)
@ApiBody({ type: ClaimIrecCertificateDTO })
@ApiResponse({
status: HttpStatus.OK,
type: TxHashDTO,
description: 'Returns whether the claim succeeded'
})
public async claimIREC(
@UserDecorator() user: ILoggedInUser,
@Param('id', new ParseIntPipe()) certificateId: number,
@Body() dto: ClaimIrecCertificateDTO
): Promise<TxHashDTO> {
const tx = await this.commandBus.execute(
new ClaimIRECCertificateCommand(user, certificateId, dto.claimData)
);

return { txHash: tx.hash };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { CqrsModule } from '@nestjs/cqrs';
import { ConfigModule } from '@nestjs/config';

import { IrecCertificateController } from './certificate.controller';
import {
BlockchainPropertiesModule,
Certificate,
Expand All @@ -12,8 +12,6 @@ import {
} from '@energyweb/issuer-api';
import { IrecModule } from '@energyweb/origin-organization-irec-api';

import { IrecCertificateController } from './certificate.controller';
import { CertificateHandlers } from './handler';

@Module({
imports: [
Expand All @@ -23,8 +21,8 @@ import { CertificateHandlers } from './handler';
IrecModule,
ConfigModule
],
controllers: [IrecCertificateController, CertificateBatchController],
providers: [...CertificateHandlers, OnChainCertificateWatcher],
exports: [...CertificateHandlers, OnChainCertificateWatcher]
controllers: [CertificateBatchController, IrecCertificateController],
providers: [OnChainCertificateWatcher],
exports: [OnChainCertificateWatcher]
})
export class CertificateModule {}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ export * from '@energyweb/issuer-api/dist/js/src/pods/certificate/queries';
export * from '@energyweb/issuer-api/dist/js/src/pods/certificate/utils';
export * from '@energyweb/issuer-api/dist/js/src/pods/certificate/dto';
export * from '@energyweb/issuer-api/dist/js/src/pods/certificate/certificate.entity';
export * from './certificate.controller';
export * from './certificate.module';
export * from './dto';
export * from './command';
export * from './handler';
export * from './certificate.controller';
1 change: 1 addition & 0 deletions packages/trade/exchange-io-erc1888/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"chai": "4.3.4",
"class-validator": "0.13.2",
"eslint-plugin-jest": "25.3.4",
"ganache-cli": "6.12.2",
"jest": "27.4.5",
"mocha": "9.1.3",
"polly-js": "1.8.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class WithdrawalProcessorService implements OnModuleInit {
const certificate = await new Certificate(
Number(transfer.asset.tokenId),
this.blockchainProperties,
CertificateSchemaVersion.V1
CertificateSchemaVersion.Latest
).sync();

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ describe('Deposits using deployed registry', () => {
issuer,
web3: getProviderWithFallback(web3)
},
CertificateSchemaVersion.V1
CertificateSchemaVersion.Latest
).sync();

const [claimDetails] = await certificate.getClaimedData();
Expand Down
Loading

0 comments on commit 051544d

Please sign in to comment.