From bf2d7ba042fee7be64185967f86f17f041493e1c Mon Sep 17 00:00:00 2001 From: tekhit Date: Thu, 3 Jan 2019 22:35:55 -0600 Subject: [PATCH] refactor: use Shared.Config in core-blockchain, core-p2p and core-transaction-pool due to similar functionality refactor: export core-blockchain types --- packages/core-blockchain/package.json | 3 +- packages/core-blockchain/src/config.ts | 17 +------- packages/core-blockchain/src/index.ts | 43 +++----------------- packages/core-blockchain/src/plugin.ts | 32 +++++++++++++++ packages/core-interfaces/package.json | 2 +- packages/core-p2p/src/config.ts | 21 +--------- packages/core-transaction-pool/src/config.ts | 22 +--------- packages/core/src/utils.ts | 1 - 8 files changed, 46 insertions(+), 95 deletions(-) create mode 100644 packages/core-blockchain/src/plugin.ts diff --git a/packages/core-blockchain/package.json b/packages/core-blockchain/package.json index 196d111d61..a15e76899b 100644 --- a/packages/core-blockchain/package.json +++ b/packages/core-blockchain/package.json @@ -8,7 +8,8 @@ "Brian Faust " ], "license": "MIT", - "main": "dist/index.js", + "main": "dist/index", + "types": "dist/index", "files": [ "dist" ], diff --git a/packages/core-blockchain/src/config.ts b/packages/core-blockchain/src/config.ts index 8dd4a3f6c9..1b95990a82 100644 --- a/packages/core-blockchain/src/config.ts +++ b/packages/core-blockchain/src/config.ts @@ -1,15 +1,2 @@ -import get from "lodash/get"; - -class Config { - private config: any; - - public init(options: any): void { - this.config = options; - } - - public get(key: string, defaultValue: any = null): any { - return get(this.config, key, defaultValue); - } -} - -export const config = new Config(); +import { Shared } from "@arkecosystem/core-interfaces"; +export const config = new Shared.Config(); diff --git a/packages/core-blockchain/src/index.ts b/packages/core-blockchain/src/index.ts index 9025b74e3f..727dae7ba7 100644 --- a/packages/core-blockchain/src/index.ts +++ b/packages/core-blockchain/src/index.ts @@ -1,38 +1,5 @@ -import { Container } from "@arkecosystem/core-interfaces"; -import { asValue } from "awilix"; -import { Blockchain } from "./blockchain"; -import { config } from "./config"; -import { defaults } from "./defaults"; -import { stateStorage } from "./state-storage"; - -/** - * The struct used by the plugin container. - * @type {Object} - */ -export const plugin: Container.PluginDescriptor = { - pkg: require("../package.json"), - defaults, - alias: "blockchain", - async register(container: Container.IContainer, options) { - const blockchain = new Blockchain(options); - - config.init(options); - - container.register("state", asValue(stateStorage)); - - if (!process.env.ARK_SKIP_BLOCKCHAIN) { - await blockchain.start(); - } - - return blockchain; - }, - async deregister(container: Container.IContainer, options) { - await container.resolvePlugin("blockchain").stop(); - }, -}; - -/** - * Access to the state. - * @type {IStateStorage} - */ -export { stateStorage }; +export * from "./defaults"; +export * from "./config"; +export * from "./blockchain"; +export * from "./state-storage"; +export * from "./plugin"; diff --git a/packages/core-blockchain/src/plugin.ts b/packages/core-blockchain/src/plugin.ts new file mode 100644 index 0000000000..22db657d2e --- /dev/null +++ b/packages/core-blockchain/src/plugin.ts @@ -0,0 +1,32 @@ +import { Container } from "@arkecosystem/core-interfaces"; +import { asValue } from "awilix"; +import { Blockchain } from "./blockchain"; +import { config } from "./config"; +import { defaults } from "./defaults"; +import { stateStorage } from "./state-storage"; + +/** + * The struct used by the plugin container. + * @type {Object} + */ +export const plugin: Container.PluginDescriptor = { + pkg: require("../package.json"), + defaults, + alias: "blockchain", + async register(container: Container.IContainer, options) { + const blockchain = new Blockchain(options); + + config.init(options); + + container.register("state", asValue(stateStorage)); + + if (!process.env.ARK_SKIP_BLOCKCHAIN) { + await blockchain.start(); + } + + return blockchain; + }, + async deregister(container: Container.IContainer, options) { + await container.resolvePlugin("blockchain").stop(); + }, +}; diff --git a/packages/core-interfaces/package.json b/packages/core-interfaces/package.json index 48b45f5659..64f4e0b3f7 100644 --- a/packages/core-interfaces/package.json +++ b/packages/core-interfaces/package.json @@ -9,7 +9,7 @@ "Alex Barnsley " ], "license": "MIT", - "main": "", + "main": "dist/index", "types": "dist/index", "files": [ "dist" diff --git a/packages/core-p2p/src/config.ts b/packages/core-p2p/src/config.ts index 89130a6208..3a4c096ad0 100644 --- a/packages/core-p2p/src/config.ts +++ b/packages/core-p2p/src/config.ts @@ -1,20 +1,3 @@ -import get from "lodash/get"; -import set from "lodash/set"; +import { Shared } from "@arkecosystem/core-interfaces"; -class Config { - private config: any; - - public init(options: any): void { - this.config = options; - } - - public get(key: string, defaultValue: any = null): any { - return get(this.config, key, defaultValue); - } - - public set(key: string, value: any): void { - set(this.config, key, value); - } -} - -export const config = new Config(); +export const config = new Shared.Config(); diff --git a/packages/core-transaction-pool/src/config.ts b/packages/core-transaction-pool/src/config.ts index 89130a6208..1b95990a82 100644 --- a/packages/core-transaction-pool/src/config.ts +++ b/packages/core-transaction-pool/src/config.ts @@ -1,20 +1,2 @@ -import get from "lodash/get"; -import set from "lodash/set"; - -class Config { - private config: any; - - public init(options: any): void { - this.config = options; - } - - public get(key: string, defaultValue: any = null): any { - return get(this.config, key, defaultValue); - } - - public set(key: string, value: any): void { - set(this.config, key, value); - } -} - -export const config = new Config(); +import { Shared } from "@arkecosystem/core-interfaces"; +export const config = new Shared.Config(); diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index 12e805e8c1..efa2390650 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -1,4 +1,3 @@ -import { app } from "@arkecosystem/core-container"; export function buildPeerOptions(options) { const config = {