Skip to content

Commit

Permalink
fix(origin-247-transfer): don't issue zero volume certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Koteja committed Jul 27, 2021
1 parent ffab534 commit 7147004
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/origin-247-transfer/src/transfer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
UpdateStatusCode
} from './EnergyTransferRequest';
import { ValidatedTransferRequestEvent } from './events';
import { BigNumber } from 'ethers';

interface IIssueCommand extends GenerationReadingStoredPayload<unknown> {}

Expand Down Expand Up @@ -66,6 +67,13 @@ export class TransferService {
transferDate
});

if (BigNumber.from(energyValue).eq(0)) {
this.logger.debug(
`Skipping certificate issuance for ETR ${request.id}. Received zero reading for ${generatorId} for ${transferDate}.`
);
return;
}

const certificate = await this.certificateService.issue({
deviceId: generatorId,
energyValue: energyValue,
Expand Down Expand Up @@ -99,11 +107,13 @@ export class TransferService {
);

if (!request) {
this.logger.warn(`
No transfer request found for certificate: ${certificateId}.
This can mean, that there was a race condition, and CertificatePersisted event was received,
before we could save the certificate id on ETR.
`);
/**
* No transfer request found.
* This can mean, that there was a race condition,
* and CertificatePersisted event was received,
* before we could save the certificate id on ETR.
* It usually happens fairly often, so it's expected
*/

return;
}
Expand Down

0 comments on commit 7147004

Please sign in to comment.