Skip to content

Commit

Permalink
Lint warning fixes (#1) (#318)
Browse files Browse the repository at this point in the history
* Fixed lint warning in chaincode

* Fixed linting warnings in typescript_app

* Fixed lint warning due to prettier auto save

Signed-off-by: Amarbir Singh <amarbir1800@gmail.com>

Lint warning fixes (#2)

* Fixed lint warning in chaincode

* Fixed linting warnings in typescript_app

* Fixed lint warning due to prettier auto save

* Fixed no-return-type lint warnings

Signed-off-by: Amarbir Singh <amarbir1800@gmail.com>

Update emissionsRecordContract.ts

Bug fix while merge request

Signed-off-by: Amarbir Singh <amarbir1800@gmail.com>

Typo fix

Signed-off-by: Amarbir Singh <amarbir1800@gmail.com>

Fixed two more typos

Signed-off-by: Amarbir Singh <amarbir1800@gmail.com>
  • Loading branch information
A-5ingh committed Oct 14, 2021
1 parent d652dfd commit afb687e
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 18 deletions.
2 changes: 2 additions & 0 deletions utility-emissions-channel/chaincode/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
import { logger, stringToBytes } from './util/util';

class EmissionsChaincode {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
private methods: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[key: string]: (stub: ChaincodeStub, args: string[]) => Promise<ChaincodeResponse>;
} = {
importUtilityIdentifier: this.importUtilityIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class EmissionsRecordContract {
energyUseUom: string,
url: string,
md5: string,
) {
): Promise<Uint8Array> {
// get emissions factors from eGRID database; convert energy use to emissions factor UOM; calculate energy use
const lookup = await this.utilityLookupState.getUtilityLookupItem(utilityId);
const factor = await this.utilityEmissionsFactorState.getEmissionsFactorByLookupItem(
Expand Down Expand Up @@ -154,12 +154,12 @@ export class EmissionsRecordContract {
);
return Buffer.from(JSON.stringify(records));
}
async importUtilityFactor(factorI: UtilityEmissionsFactorInterface) {
async importUtilityFactor(factorI: UtilityEmissionsFactorInterface): Promise<Uint8Array> {
const factor = new UtilityEmissionsFactor(factorI);
await this.utilityEmissionsFactorState.addUtilityEmissionsFactor(factor, factorI.uuid);
return factor.toBuffer();
}
async updateUtilityFactor(factorI: UtilityEmissionsFactorInterface) {
async updateUtilityFactor(factorI: UtilityEmissionsFactorInterface): Promise<Uint8Array> {
const factor = new UtilityEmissionsFactor(factorI);
await this.utilityEmissionsFactorState.updateUtilityEmissionsFactor(factor, factorI.uuid);
return factor.toBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ export interface IUtilityemissionchannelEmissionData {
tokenId: string;
}

export interface IUtilityemissionchannelEmissionMetadata {
org: string;
type: string;
partyId: string[];
renewableEnergyUseAmount: number;
nonrenewableEnergyUseAmount: number;
utilityIds: string[];
factorSources: string[];
urls: string[];
md5s: string[];
fromDates: string[];
thruDates: string[];
}

export interface IUtilityemissionchannelGetEMissionsRecordsInput {
utilityId: string;
partyId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class BCGatewayConfig {
{
Checks.nonBlankString(ccAddress, `${fnTag} LEDGER_EMISSION_TOKEN_CONTRACT_ADDRESS`);
}
const networks: { [key: number]: any } = {};
const networks: { [key: number]: Record<string, string> } = {};
networks[this.__getEthNetworkID(network)] = {
address: ccAddress,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export default class EthNetEmissionsTokenGateway implements IEthNetEmissionsToke
private readonly className = 'EthNetEmissionsTokenGateway';
private readonly tokenTypeId = 3;
private readonly web3 = new Web3();
private readonly EventTokenCreatedInput: any[];
private readonly EventTokenCreatedInput: {
internalType: string;
name: string;
type: string;
}[];
constructor(private readonly opts: IEthNetEmissionsTokenGatewayOptions) {
const tokenCreatedABI = contractABI.find((value) => {
return value.type === 'event' && value.name === 'TokenCreated';
Expand All @@ -43,7 +47,7 @@ export default class EthNetEmissionsTokenGateway implements IEthNetEmissionsToke
ledgerLogger.debug(`${fnTag} getting signer for client`);
const signer = this.opts.signer.ethereum(caller);
ledgerLogger.debug(`${fnTag} calling issue method input = %o`, input);
let result: any;
let result;
try {
const automaticRetireDate = +input.automaticRetireDate.toFixed();
result = await this.opts.ethClient.invokeContract({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ export default class UtilityemissionchannelGateway implements IUtilityemissionch
params: [input.utilityId, input.partyId],
});
ledgerLogger.debug(`${fnTag} returned emissions record data : ${resp.functionOutput}`);
const json: any[] = JSON.parse(resp.functionOutput);
const json: Record<string, IUtilityemissionchannelEmissionData>[] = JSON.parse(
resp.functionOutput,
);
const out: IUtilityemissionchannelEmissionData[] = [];
for (const emission of json) {
out.push(this.__toEmissionRecord(emission.Record));
Expand Down Expand Up @@ -169,7 +171,9 @@ export default class UtilityemissionchannelGateway implements IUtilityemissionch
params: [input.fromDate, input.thruDate],
});
ledgerLogger.debug(`${fnTag} returned emissions record data : ${resp.functionOutput}`);
const json: any[] = JSON.parse(resp.functionOutput);
const json: Record<string, IUtilityemissionchannelEmissionData>[] = JSON.parse(
resp.functionOutput,
);
const out: IUtilityemissionchannelEmissionData[] = [];
for (const emission of json) {
out.push(this.__toEmissionRecord(emission.Record));
Expand All @@ -183,7 +187,9 @@ export default class UtilityemissionchannelGateway implements IUtilityemissionch
}
}

private __toEmissionRecord(json: any): IUtilityemissionchannelEmissionData {
private __toEmissionRecord(
json: IUtilityemissionchannelEmissionData,
): IUtilityemissionchannelEmissionData {
return {
uuid: json.uuid,
utilityId: json.utilityId,
Expand Down
8 changes: 4 additions & 4 deletions utility-emissions-channel/typescript_app/src/service/input.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface Input {

This comment has been minimized.

Copy link
@brioux

brioux Oct 20, 2021

Member

@A-5ingh
This commit is causing build errors on my machine.

src/controllers/registerEnroll.ts:8:13 - error TS2322: Type 'IncomingHttpHeaders' is not assignable to type 'Record<string, string>'.
'string' index signatures are incompatible.
Type 'string | string[]' is not assignable to type 'string'.
Type 'string[]' is not assignable to type 'string'.

8 header: req.headers,
~~~~~~

src/service/input.ts:3:5
3 header: Record<string, string>;
~~~~~~
The expected type comes from property 'header' which is declared here on type 'Input'

This comment has been minimized.

Copy link
@A-5ingh

A-5ingh Oct 21, 2021

Author Contributor

oh I guess in that case we can revert back to any type. We will probably have to ignore the lint warnings here.

body: any;
header: any;
query: any;
body: Record<string, string>;
header: Record<string, string>;
query: Record<string, string>;
file?: Buffer;
params?: any;
params?: Record<string, string>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ITxDetails,
IDataChaincodeInput,
IUtilityemissionchannelEmissionData,
IUtilityemissionchannelEmissionMetadata,
} from '../blockchain-gateway/I-gateway';
import AWSS3 from '../datasource/awsS3';
import Joi from 'joi';
Expand All @@ -31,7 +32,7 @@ interface IRecordAuditedEmissionsTokenResponse {
fromDate: number;
thruDate: number;
automaticRetireDate: string;
metadata: any;
metadata: string;
manifest: string;
description: string;
}
Expand All @@ -48,7 +49,7 @@ export default class UtilityEmissionsChannelService {
const partyId: string = input.body.partyId;
const fromDate: string = input.body.fromDate;
const thruDate: string = input.body.thruDate;
const energyUseAmount: number = input.body.energyUseAmount as number;
const energyUseAmount: number = parseInt(input.body.energyUseAmount);
const energyUseUom: string = input.body.energyUseUom;

const fabricCaller: IFabricTxCaller = {
Expand Down Expand Up @@ -346,7 +347,7 @@ export default class UtilityEmissionsChannelService {
throw error;
}
}
private async emissionsRecordChecksum(record: any) {
private async emissionsRecordChecksum(record: IUtilityemissionchannelEmissionData) {
const fnTag = `${this.className}.EmissionsRecordChecksum`;
if (record.url && record.url.length > 0) {
const url = record.url;
Expand Down Expand Up @@ -374,8 +375,14 @@ export default class UtilityEmissionsChannelService {
}
}

private async tokenMetadata(records: IUtilityemissionchannelEmissionData[]): Promise<any> {
const metadata: any = {
private async tokenMetadata(records: IUtilityemissionchannelEmissionData[]): Promise<{
metadata: IUtilityemissionchannelEmissionMetadata;
manifest: string;
quantity: number;
fromDate: number;
thruDate: number;
}> {
const metadata: IUtilityemissionchannelEmissionMetadata = {
org: this.opts.orgName,
type: 'Utility Emissions',
partyId: [],
Expand Down

1 comment on commit afb687e

@brioux
Copy link
Member

@brioux brioux commented on afb687e Oct 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@A-5ingh I have merged this commit into my PR 325 and the checks are passing, but can't get it to build on my local. Type changes to export interface Input{} are causing issues with an example reference in the inline comment above.

Please sign in to comment.