Skip to content

Commit

Permalink
linters and prettier as top level packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kosecki123 committed Aug 21, 2019
1 parent 646e8a5 commit 36d9b9c
Show file tree
Hide file tree
Showing 161 changed files with 3,723 additions and 3,042 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,5 @@ node_modules
.DS_Store
dist
db.json
.vscode
.vscode
*.log
File renamed without changes.
8 changes: 7 additions & 1 deletion package.json
Expand Up @@ -3,11 +3,17 @@
"private": true,
"devDependencies": {
"lerna": "^3.16.4",
"prettier": "^1.18.2",
"tslint": "^5.19.0",
"tslint-config-prettier": "^1.18.0",
"tslint-lines-between-class-members": "^1.3.6",
"tslint-sonarts": "^1.9.0",
"typescript": "^3.5.3"
},
"scripts": {
"build": "lerna run build",
"run:ui": "lerna run start --scope ew-origin-ui --stream"
"run:ui": "lerna run start --scope ew-origin-ui --stream",
"lint": "lerna run lint --parallel --stream"
},
"workspaces": [
"packages/*"
Expand Down
5 changes: 0 additions & 5 deletions packages/ew-asset-registry-lib/package.json
Expand Up @@ -55,12 +55,7 @@
"ganache-cli": "6.1.8",
"lint-staged": "8.1.7",
"mocha": "5.2.0",
"prettier": "1.17.1",
"truffle": "5.0.18",
"tslint": "5.16.0",
"tslint-config-prettier": "1.18.0",
"tslint-lines-between-class-members": "1.3.1",
"tslint-sonarts": "1.9.0",
"typescript-json-schema": "0.31.0"
},
"postinstall": "rm -f node_modules/web3/index.d.ts",
Expand Down
10 changes: 2 additions & 8 deletions packages/ew-asset-registry-lib/src/Logger.ts
Expand Up @@ -18,12 +18,6 @@ import * as Winston from 'winston';

export const logger = Winston.createLogger({
level: 'debug',
format: Winston.format.combine(
Winston.format.colorize(),
Winston.format.simple(),
),
transports: [

new Winston.transports.Console({ level: 'silly' }),
],
format: Winston.format.combine(Winston.format.colorize(), Winston.format.simple()),
transports: [new Winston.transports.Console({ level: 'silly' })]
});
2 changes: 0 additions & 2 deletions packages/ew-asset-registry-lib/src/blockchain-facade/Asset.ts
Expand Up @@ -42,7 +42,6 @@ export interface IOffChainProperties {

export abstract class Entity extends BlockchainDataModelEntity.Entity
implements IOnChainProperties {

offChainProperties: IOffChainProperties;
certificatesUsedForWh: number;
smartMeter: Configuration.EthAccount;
Expand All @@ -63,5 +62,4 @@ export abstract class Entity extends BlockchainDataModelEntity.Entity

this.initialized = false;
}

}
Expand Up @@ -17,38 +17,36 @@
import { Configuration } from 'ew-utils-general-lib';
import * as Winston from 'winston';
import Web3 from 'web3';
import { createBlockchainProperties as userCreateBlockchainProperties} from 'ew-user-registry-lib';
import { createBlockchainProperties as userCreateBlockchainProperties } from 'ew-user-registry-lib';
import { AssetContractLookup, AssetConsumingRegistryLogic, AssetProducingRegistryLogic } from '..';

export const createBlockchainProperties = async (
logger: Winston.Logger,
web3: Web3,
assetContractLookupAddress: string,
assetContractLookupAddress: string
): Promise<Configuration.BlockchainProperties> => {

const assetLookupContractInstance: AssetContractLookup = new AssetContractLookup(
web3,
assetContractLookupAddress);
assetContractLookupAddress
);

const userBlockchainProperties: Configuration.BlockchainProperties =
await userCreateBlockchainProperties(
logger,
web3 as any,
await assetLookupContractInstance.userRegistry(),
) as any;
const userBlockchainProperties: Configuration.BlockchainProperties = (await userCreateBlockchainProperties(
logger,
web3 as any,
await assetLookupContractInstance.userRegistry()
)) as any;

return {
consumingAssetLogicInstance: new AssetConsumingRegistryLogic(
web3,
await assetLookupContractInstance.assetConsumingRegistry(),
await assetLookupContractInstance.assetConsumingRegistry()
),
producingAssetLogicInstance: new AssetProducingRegistryLogic(
web3,
await assetLookupContractInstance.assetProducingRegistry(),
),
await assetLookupContractInstance.assetProducingRegistry()
),
userLogicInstance: userBlockchainProperties.userLogicInstance,

web3: web3 as any,

web3: web3 as any
};
};
Expand Up @@ -24,72 +24,79 @@ export interface IOnChainProperties extends Asset.IOnChainProperties {
certificatesUsedForWh: number;
}

export const createAsset =
async (assetProperties: IOnChainProperties,
assetPropertiesOffChain: Asset.IOffChainProperties,
configuration: Configuration.Entity): Promise<Asset.Entity> => {
const consumingAsset = new Entity(null, configuration);
const offChainStorageProperties =
consumingAsset.prepareEntityCreation(assetProperties, assetPropertiesOffChain, AssetPropertiesOffchainSchema);

if (configuration.offChainDataSource) {
assetProperties.url = consumingAsset.getUrl();
assetProperties.propertiesDocumentHash = offChainStorageProperties.rootHash;
}

const tx = await configuration.blockchainProperties.consumingAssetLogicInstance.createAsset(
assetProperties.smartMeter.address,
assetProperties.owner.address,
assetProperties.active,
assetProperties.matcher.map((matcher) => matcher.address),
assetProperties.propertiesDocumentHash,
assetProperties.url,
{
from: configuration.blockchainProperties.activeUser.address,
privateKey: configuration.blockchainProperties.activeUser.privateKey,
});
export const createAsset = async (
assetProperties: IOnChainProperties,
assetPropertiesOffChain: Asset.IOffChainProperties,
configuration: Configuration.Entity
): Promise<Asset.Entity> => {
const consumingAsset = new Entity(null, configuration);
const offChainStorageProperties = consumingAsset.prepareEntityCreation(
assetProperties,
assetPropertiesOffChain,
AssetPropertiesOffchainSchema
);

if (configuration.offChainDataSource) {
assetProperties.url = consumingAsset.getUrl();
assetProperties.propertiesDocumentHash = offChainStorageProperties.rootHash;
}

consumingAsset.id = configuration.blockchainProperties.web3.utils.hexToNumber(tx.logs[0].topics[1]).toString();
const tx = await configuration.blockchainProperties.consumingAssetLogicInstance.createAsset(
assetProperties.smartMeter.address,
assetProperties.owner.address,
assetProperties.active,
assetProperties.matcher.map(matcher => matcher.address),
assetProperties.propertiesDocumentHash,
assetProperties.url,
{
from: configuration.blockchainProperties.activeUser.address,
privateKey: configuration.blockchainProperties.activeUser.privateKey
}
);

await consumingAsset.putToOffChainStorage(assetPropertiesOffChain, offChainStorageProperties);
consumingAsset.id = configuration.blockchainProperties.web3.utils
.hexToNumber(tx.logs[0].topics[1])
.toString();

if (configuration.logger) {
configuration.logger.info(`Consuming asset ${consumingAsset.id} created`);
}
await consumingAsset.putToOffChainStorage(assetPropertiesOffChain, offChainStorageProperties);

return consumingAsset.sync();
if (configuration.logger) {
configuration.logger.info(`Consuming asset ${consumingAsset.id} created`);
}

};
return consumingAsset.sync();
};

export const getAssetListLength = async (configuration: Configuration.Entity) => {

return parseInt(await configuration.blockchainProperties.consumingAssetLogicInstance.getAssetListLength(), 10);
return parseInt(
await configuration.blockchainProperties.consumingAssetLogicInstance.getAssetListLength(),
10
);
};

export const getAllAssets = async (configuration: Configuration.Entity) => {

const assetsPromises = Array(await getAssetListLength(configuration))
.fill(null)
.map((item, index) => (new Entity(index.toString(), configuration)).sync());
.map((item, index) => new Entity(index.toString(), configuration).sync());

return Promise.all(assetsPromises);

};

export const getAllAssetsOwnedBy = async (owner: string, configuration: Configuration.Entity) => {
return (await getAllAssets(configuration))
.filter((asset: Entity) => asset.owner.address.toLowerCase() === owner.toLowerCase());
return (await getAllAssets(configuration)).filter(
(asset: Entity) => asset.owner.address.toLowerCase() === owner.toLowerCase()
);
};

export class Entity extends Asset.Entity implements Asset.IOnChainProperties {

getUrl(): string {

return `${this.configuration.offChainDataSource.baseUrl}/ConsumingAsset`;
}

async sync(): Promise<Entity> {
const asset = await this.configuration.blockchainProperties.consumingAssetLogicInstance.getAssetById(this.id);
const asset = await this.configuration.blockchainProperties.consumingAssetLogicInstance.getAssetById(
this.id
);

if (this.id != null) {
this.smartMeter = { address: asset.assetGeneral.smartMeter };
Expand All @@ -112,7 +119,7 @@ export class Entity extends Asset.Entity implements Asset.IOnChainProperties {
}

async saveSmartMeterRead(
newMeterReading: number,
newMeterReading: number,
fileHash: string,
timestamp: number = moment().unix()
): Promise<TransactionReceipt> {
Expand All @@ -122,10 +129,9 @@ export class Entity extends Asset.Entity implements Asset.IOnChainProperties {
newMeterReading,
fileHash,
timestamp,
{ privateKey: this.configuration.blockchainProperties.activeUser.privateKey },
{ privateKey: this.configuration.blockchainProperties.activeUser.privateKey }
);
}
else {
} else {
return this.configuration.blockchainProperties.consumingAssetLogicInstance.saveSmartMeterRead(
this.id,
newMeterReading,
Expand All @@ -134,7 +140,5 @@ export class Entity extends Asset.Entity implements Asset.IOnChainProperties {
{ from: this.configuration.blockchainProperties.activeUser.address }
);
}

}

}

0 comments on commit 36d9b9c

Please sign in to comment.