diff --git a/packages/core-api/src/handlers/bridgechains/controller.ts b/packages/core-api/src/handlers/bridgechains/controller.ts index be26a40a79..806efb322f 100644 --- a/packages/core-api/src/handlers/bridgechains/controller.ts +++ b/packages/core-api/src/handlers/bridgechains/controller.ts @@ -1,5 +1,6 @@ import Boom from "@hapi/boom"; import Hapi from "@hapi/hapi"; + import { Controller } from "../shared/controller"; export class BridgechainController extends Controller { diff --git a/packages/core-api/src/handlers/bridgechains/index.ts b/packages/core-api/src/handlers/bridgechains/index.ts index f4e378c48a..9c7adaaedd 100644 --- a/packages/core-api/src/handlers/bridgechains/index.ts +++ b/packages/core-api/src/handlers/bridgechains/index.ts @@ -1,4 +1,5 @@ import Hapi from "@hapi/hapi"; + import { registerMethods } from "./methods"; import { registerRoutes } from "./routes"; diff --git a/packages/core-api/src/handlers/bridgechains/methods.ts b/packages/core-api/src/handlers/bridgechains/methods.ts index ff98a02031..eec82c2355 100644 --- a/packages/core-api/src/handlers/bridgechains/methods.ts +++ b/packages/core-api/src/handlers/bridgechains/methods.ts @@ -1,5 +1,6 @@ import { app, Container, Contracts } from "@arkecosystem/core-kernel"; import Boom from "@hapi/boom"; + import { ServerCache } from "../../services"; import { paginate, respondWithResource, toPagination } from "../utils"; diff --git a/packages/core-api/src/handlers/bridgechains/routes.ts b/packages/core-api/src/handlers/bridgechains/routes.ts index ff1335aa49..73cafc8435 100644 --- a/packages/core-api/src/handlers/bridgechains/routes.ts +++ b/packages/core-api/src/handlers/bridgechains/routes.ts @@ -1,4 +1,5 @@ import Hapi from "@hapi/hapi"; + import { BridgechainController } from "./controller"; import * as Schema from "./schema"; diff --git a/packages/core-api/src/handlers/bridgechains/schema.ts b/packages/core-api/src/handlers/bridgechains/schema.ts index 970982b953..8af93c63bf 100644 --- a/packages/core-api/src/handlers/bridgechains/schema.ts +++ b/packages/core-api/src/handlers/bridgechains/schema.ts @@ -1,4 +1,5 @@ import Joi from "@hapi/joi"; + import { pagination } from "../shared/schemas/pagination"; export const index: object = { diff --git a/packages/core-api/src/handlers/businesses/controller.ts b/packages/core-api/src/handlers/businesses/controller.ts index a19430fb85..aae57af4ed 100644 --- a/packages/core-api/src/handlers/businesses/controller.ts +++ b/packages/core-api/src/handlers/businesses/controller.ts @@ -1,5 +1,6 @@ import Boom from "@hapi/boom"; import Hapi from "@hapi/hapi"; + import { Controller } from "../shared/controller"; export class BusinessController extends Controller { diff --git a/packages/core-api/src/handlers/businesses/index.ts b/packages/core-api/src/handlers/businesses/index.ts index f4e378c48a..9c7adaaedd 100644 --- a/packages/core-api/src/handlers/businesses/index.ts +++ b/packages/core-api/src/handlers/businesses/index.ts @@ -1,4 +1,5 @@ import Hapi from "@hapi/hapi"; + import { registerMethods } from "./methods"; import { registerRoutes } from "./routes"; diff --git a/packages/core-api/src/handlers/businesses/methods.ts b/packages/core-api/src/handlers/businesses/methods.ts index e181299704..1738c310a8 100644 --- a/packages/core-api/src/handlers/businesses/methods.ts +++ b/packages/core-api/src/handlers/businesses/methods.ts @@ -1,5 +1,6 @@ import { app, Container, Contracts } from "@arkecosystem/core-kernel"; import Boom from "@hapi/boom"; + import { ServerCache } from "../../services"; import { paginate, respondWithResource, toPagination } from "../utils"; diff --git a/packages/core-api/src/handlers/businesses/routes.ts b/packages/core-api/src/handlers/businesses/routes.ts index b7a80db9b7..3b8c0fa7c1 100644 --- a/packages/core-api/src/handlers/businesses/routes.ts +++ b/packages/core-api/src/handlers/businesses/routes.ts @@ -1,4 +1,5 @@ import Hapi from "@hapi/hapi"; + import { BusinessController } from "./controller"; import * as Schema from "./schema"; diff --git a/packages/core-api/src/handlers/businesses/schema.ts b/packages/core-api/src/handlers/businesses/schema.ts index 0eaf2049a9..7175c1971a 100644 --- a/packages/core-api/src/handlers/businesses/schema.ts +++ b/packages/core-api/src/handlers/businesses/schema.ts @@ -1,4 +1,5 @@ import Joi from "@hapi/joi"; + import { pagination } from "../shared/schemas/pagination"; export const index: object = { diff --git a/packages/core-api/src/handlers/locks/controller.ts b/packages/core-api/src/handlers/locks/controller.ts index 1e81a69872..1e1b057339 100644 --- a/packages/core-api/src/handlers/locks/controller.ts +++ b/packages/core-api/src/handlers/locks/controller.ts @@ -1,5 +1,6 @@ import Boom from "@hapi/boom"; import Hapi from "@hapi/hapi"; + import { Controller } from "../shared/controller"; export class LocksController extends Controller { diff --git a/packages/core-api/src/handlers/locks/index.ts b/packages/core-api/src/handlers/locks/index.ts index f4e378c48a..9c7adaaedd 100644 --- a/packages/core-api/src/handlers/locks/index.ts +++ b/packages/core-api/src/handlers/locks/index.ts @@ -1,4 +1,5 @@ import Hapi from "@hapi/hapi"; + import { registerMethods } from "./methods"; import { registerRoutes } from "./routes"; diff --git a/packages/core-api/src/handlers/locks/methods.ts b/packages/core-api/src/handlers/locks/methods.ts index 6022c42378..477ca702e9 100644 --- a/packages/core-api/src/handlers/locks/methods.ts +++ b/packages/core-api/src/handlers/locks/methods.ts @@ -1,5 +1,6 @@ import { app, Container, Contracts } from "@arkecosystem/core-kernel"; import Boom from "@hapi/boom"; + import { ServerCache } from "../../services"; import { paginate, respondWithResource, toPagination } from "../utils"; diff --git a/packages/core-api/src/handlers/locks/routes.ts b/packages/core-api/src/handlers/locks/routes.ts index 2d9195950b..8c5cc4ad2b 100644 --- a/packages/core-api/src/handlers/locks/routes.ts +++ b/packages/core-api/src/handlers/locks/routes.ts @@ -1,4 +1,5 @@ import Hapi from "@hapi/hapi"; + import { LocksController } from "./controller"; import * as Schema from "./schema"; diff --git a/packages/core-api/src/handlers/locks/schema.ts b/packages/core-api/src/handlers/locks/schema.ts index e82c0fe79f..9fbdb78863 100644 --- a/packages/core-api/src/handlers/locks/schema.ts +++ b/packages/core-api/src/handlers/locks/schema.ts @@ -1,4 +1,5 @@ import Joi from "@hapi/joi"; + import { pagination } from "../shared/schemas/pagination"; export const index: object = { diff --git a/packages/core-api/src/handlers/node/controller.ts b/packages/core-api/src/handlers/node/controller.ts index 81680bfd0a..c24c8c58ca 100644 --- a/packages/core-api/src/handlers/node/controller.ts +++ b/packages/core-api/src/handlers/node/controller.ts @@ -1,9 +1,10 @@ -import { app, Container, Contracts } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Providers } from "@arkecosystem/core-kernel"; import { Crypto, Managers } from "@arkecosystem/crypto"; import Boom from "@hapi/boom"; import Hapi from "@hapi/hapi"; import { spawnSync } from "child_process"; import { existsSync } from "fs"; + import { Controller } from "../shared/controller"; // todo: remove the abstract and use dependency injection if needed @@ -53,7 +54,11 @@ export class NodeController extends Controller { public async configuration(request: Hapi.Request, h: Hapi.ResponseToolkit) { try { const network = this.config.get("network"); - const dynamicFees = app.get("transactionPool.options").dynamicFees; + const dynamicFees = app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-transaction-pool") + .config() + .get<{ enabled?: boolean }>("dynamicFees"); return { data: { diff --git a/packages/core-api/src/handlers/peers/transformer.ts b/packages/core-api/src/handlers/peers/transformer.ts index 2fdb5b5e1a..4513761a4f 100644 --- a/packages/core-api/src/handlers/peers/transformer.ts +++ b/packages/core-api/src/handlers/peers/transformer.ts @@ -1,10 +1,14 @@ -import { app } from "@arkecosystem/core-kernel"; +import { app, Container, Providers } from "@arkecosystem/core-kernel"; // todo: review the implementation export const transformPeer = model => { return { ip: model.ip, - port: +app.get("p2p.options").server.port, + port: +app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-p2p") + .config() + .get("server.port"), ports: model.ports, version: model.version, height: model.state ? model.state.height : model.height, diff --git a/packages/core-api/src/handlers/transactions/controller.ts b/packages/core-api/src/handlers/transactions/controller.ts index a1da680ae6..2bad885dc3 100644 --- a/packages/core-api/src/handlers/transactions/controller.ts +++ b/packages/core-api/src/handlers/transactions/controller.ts @@ -1,6 +1,6 @@ import { app, Container, Contracts } from "@arkecosystem/core-kernel"; -import { Enums, Interfaces } from "@arkecosystem/crypto"; import { Handlers } from "@arkecosystem/core-transactions"; +import { Enums, Interfaces } from "@arkecosystem/crypto"; import Boom from "@hapi/boom"; import Hapi from "@hapi/hapi"; diff --git a/packages/core-api/src/handlers/transactions/schema.ts b/packages/core-api/src/handlers/transactions/schema.ts index ad0b35f5fb..0ea3b48275 100644 --- a/packages/core-api/src/handlers/transactions/schema.ts +++ b/packages/core-api/src/handlers/transactions/schema.ts @@ -62,8 +62,12 @@ export const store: object = { $ref: "transactions", minItems: 1, maxItems: 40, - // @fixme: the container is not available at the time this file is loaded - // maxItems: app.get("transactionPool.options").maxTransactionsPerRequest, + // todo: the container is not available at the time this file is loaded + // maxItems: app + // .get(Container.Identifiers.ServiceProviderRepository) + // .get("@arkecosystem/core-transaction-pool") + // .config() + // .get("maxTransactionsPerRequest"), }, }, }; diff --git a/packages/core-api/src/handlers/utils.ts b/packages/core-api/src/handlers/utils.ts index 4e9b2926ee..80e9f9a34f 100644 --- a/packages/core-api/src/handlers/utils.ts +++ b/packages/core-api/src/handlers/utils.ts @@ -1,4 +1,4 @@ -import { app } from "@arkecosystem/core-kernel"; +import { app, Container, Providers } from "@arkecosystem/core-kernel"; import Boom from "@hapi/boom"; import Hapi from "@hapi/hapi"; @@ -34,7 +34,13 @@ export const respondWithCollection = (data, transformer, transform = true): obje }; export const respondWithCache = (data, h): any => { - if (!app.get("api.options").get("plugins.cache.enabled")) { + if ( + !app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-state") + .config() + .get("plugins.cache.enabled") + ) { return data; } diff --git a/packages/core-api/src/plugins/pagination/ext.ts b/packages/core-api/src/plugins/pagination/ext.ts index 33aa1aa5d9..22aadfd825 100644 --- a/packages/core-api/src/plugins/pagination/ext.ts +++ b/packages/core-api/src/plugins/pagination/ext.ts @@ -97,7 +97,7 @@ export class Ext { const currentPage = query.page; const currentLimit = query.limit; - const { totalCount } = !!source.totalCount ? source : request; + const { totalCount } = source.totalCount ? source : request; let pageCount: number; if (totalCount) { diff --git a/packages/core-api/src/service-provider.ts b/packages/core-api/src/service-provider.ts index 5b9ea1af3f..d8456719e3 100644 --- a/packages/core-api/src/service-provider.ts +++ b/packages/core-api/src/service-provider.ts @@ -6,8 +6,6 @@ import { Server } from "./server"; export class ServiceProvider extends Providers.ServiceProvider { public async register(): Promise { - this.app.bind("api.options").toConstantValue(this.config()); - if (this.config().get("server.http.enabled")) { await this.buildServer("http"); } diff --git a/packages/core-api/src/services/cache.ts b/packages/core-api/src/services/cache.ts index 4ff8240379..fafcf08b79 100644 --- a/packages/core-api/src/services/cache.ts +++ b/packages/core-api/src/services/cache.ts @@ -1,4 +1,4 @@ -import { app } from "@arkecosystem/core-kernel"; +import { app, Container, Providers } from "@arkecosystem/core-kernel"; import { Crypto } from "@arkecosystem/crypto"; import Hapi, { ServerMethod } from "@hapi/hapi"; @@ -13,7 +13,7 @@ export class ServerCache { public method(name: string, method: ServerMethod, expiresIn: number, argsCallback?: any): this { let options = {}; - if (app.get("api.options").get("plugins.cache.enabled")) { + if (this.getConfig("plugins.cache.enabled")) { options = { cache: { expiresIn: expiresIn * 1000, @@ -34,8 +34,16 @@ export class ServerCache { } private getCacheTimeout(): number | boolean { - const { generateTimeout } = app.get("api.options").get("plugins.cache"); + const { generateTimeout } = this.getConfig("plugins.cache"); return JSON.parse(generateTimeout); } + + private getConfig(key: string): T { + return app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-api") + .config() + .get(key); + } } diff --git a/packages/core-blockchain/src/service-provider.ts b/packages/core-blockchain/src/service-provider.ts index 27d8e020cc..bd7b8c5c79 100644 --- a/packages/core-blockchain/src/service-provider.ts +++ b/packages/core-blockchain/src/service-provider.ts @@ -6,9 +6,7 @@ import { ReplayBlockchain } from "./replay"; export class ServiceProvider extends Providers.ServiceProvider { public async register(): Promise { - this.app.bind("blockchain.options").toConstantValue(this.config().all()); - - // blockchain + // Blockchain const blockchain: Blockchain = this.config().get("replay") ? new ReplayBlockchain() : this.app.resolve(Blockchain); @@ -17,7 +15,7 @@ export class ServiceProvider extends Providers.ServiceProvider { blockchain.init(this.config().all()); - // state + // State this.app.get(Container.Identifiers.StateStore).reset(blockchainMachine); if (!process.env.CORE_SKIP_BLOCKCHAIN && !this.config().get("replay")) { diff --git a/packages/core-blockchain/src/state-machine.ts b/packages/core-blockchain/src/state-machine.ts index 6391563699..17eca15776 100644 --- a/packages/core-blockchain/src/state-machine.ts +++ b/packages/core-blockchain/src/state-machine.ts @@ -1,4 +1,4 @@ -import { app, Container, Contracts, Enums, Utils as AppUtils } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Enums, Providers, Utils as AppUtils } from "@arkecosystem/core-kernel"; import { Interfaces, Managers, Utils } from "@arkecosystem/crypto"; import { Blockchain } from "./blockchain"; @@ -277,7 +277,11 @@ blockchainMachine.actionMap = (blockchain: Blockchain) => ({ async rollbackDatabase() { logger.info("Trying to restore database integrity"); - const { maxBlockRewind, steps } = app.get("blockchain.options").databaseRollback; + const { maxBlockRewind, steps } = app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-blockchain") + .config() + .get>("databaseRollback"); for (let i = maxBlockRewind; i >= 0; i -= steps) { await blockchain.removeTopBlocks(steps); diff --git a/packages/core-database-postgres/src/migrations/index.ts b/packages/core-database-postgres/src/migrations/index.ts index 7ad9d35903..0b20dca526 100644 --- a/packages/core-database-postgres/src/migrations/index.ts +++ b/packages/core-database-postgres/src/migrations/index.ts @@ -1,7 +1,8 @@ -import { loadQueryFile } from "../utils"; import { readdirSync } from "fs"; +import { loadQueryFile } from "../utils"; + export const migrations = readdirSync(__dirname) - .filter(name => name.substr(-4).toLowerCase() === '.sql') + .filter(name => name.substr(-4).toLowerCase() === ".sql") .sort() .map(name => loadQueryFile(__dirname, name)); diff --git a/packages/core-database/src/repositories/transactions-business-repository.ts b/packages/core-database/src/repositories/transactions-business-repository.ts index 8ebdc11954..db202f77a8 100644 --- a/packages/core-database/src/repositories/transactions-business-repository.ts +++ b/packages/core-database/src/repositories/transactions-business-repository.ts @@ -1,4 +1,4 @@ -import { app, Contracts } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Providers } from "@arkecosystem/core-kernel"; import { Enums, Interfaces } from "@arkecosystem/crypto"; import { SearchParameterConverter } from "./utils/search-parameter-converter"; @@ -83,7 +83,11 @@ export class TransactionsBusinessRepository implements Contracts.Database.Transa > { return this.databaseServiceProvider().connection.transactionsRepository.getFeeStatistics( days, - app.get("transactionPool.options").dynamicFees.minFeeBroadcast, + app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-state") + .config() + .get("dynamicFees.minFeeBroadcast"), ); } diff --git a/packages/core-database/src/repositories/utils/filter-rows.ts b/packages/core-database/src/repositories/utils/filter-rows.ts index fdfefee639..c60074bbc9 100644 --- a/packages/core-database/src/repositories/utils/filter-rows.ts +++ b/packages/core-database/src/repositories/utils/filter-rows.ts @@ -1,4 +1,5 @@ import { Contracts } from "@arkecosystem/core-kernel"; + import { getProperty } from "./get-property"; /** diff --git a/packages/core-database/src/repositories/utils/search-entries.ts b/packages/core-database/src/repositories/utils/search-entries.ts index d393cbe3dc..d7a0d35d0d 100644 --- a/packages/core-database/src/repositories/utils/search-entries.ts +++ b/packages/core-database/src/repositories/utils/search-entries.ts @@ -1,4 +1,5 @@ import { Contracts, Utils } from "@arkecosystem/core-kernel"; + import filterRows from "./filter-rows"; import limitRows from "./limit-rows"; import { sortEntries } from "./sort-entries"; diff --git a/packages/core-kernel/src/application.ts b/packages/core-kernel/src/application.ts index 2485256892..ee0aa52e79 100644 --- a/packages/core-kernel/src/application.ts +++ b/packages/core-kernel/src/application.ts @@ -47,24 +47,19 @@ export class Application implements Contracts.Kernel.Application { * @memberof Application */ public async bootstrap({ flags, plugins }: { flags: JsonObject; plugins?: JsonObject }): Promise { - await this.registerEventDispatcher(); - - // todo: move into a bootstrapper this.bind(Identifiers.ConfigRepository) .to(ConfigRepository) .inSingletonScope(); - // todo: move into a bootstrapper - this.bind(Identifiers.ConfigFlags).toConstantValue(flags); - - // todo: move into a bootstrapper - this.bind(Identifiers.ConfigPlugins).toConstantValue(plugins); - - // todo: move into a bootstrapper this.bind(Identifiers.ServiceProviderRepository) .to(ServiceProviderRepository) .inSingletonScope(); + this.bind(Identifiers.ConfigFlags).toConstantValue(flags); + this.bind(Identifiers.ConfigPlugins).toConstantValue(plugins); + + await this.registerEventDispatcher(); + await this.bootstrapWith("app"); } diff --git a/packages/core-kernel/src/services/config/drivers/local.ts b/packages/core-kernel/src/services/config/drivers/local.ts index b7130860d9..4de2bd7be5 100644 --- a/packages/core-kernel/src/services/config/drivers/local.ts +++ b/packages/core-kernel/src/services/config/drivers/local.ts @@ -1,6 +1,7 @@ import { dotenv, get, set } from "@arkecosystem/utils"; import { existsSync, readFileSync } from "fs"; import importFresh from "import-fresh"; +import { extname } from "path"; import { Application } from "../../../contracts/kernel"; import { ConfigLoader } from "../../../contracts/kernel/config"; @@ -12,7 +13,6 @@ import { import { Identifiers, inject, injectable } from "../../../ioc"; import { JsonObject, KeyValuePair, Primitive } from "../../../types"; import { ConfigRepository } from "../repository"; -import { extname } from "path"; /** * @export diff --git a/packages/core-kernel/src/utils/expiration-calculator.ts b/packages/core-kernel/src/utils/expiration-calculator.ts index 85d2085f91..713fca59e5 100644 --- a/packages/core-kernel/src/utils/expiration-calculator.ts +++ b/packages/core-kernel/src/utils/expiration-calculator.ts @@ -39,4 +39,4 @@ export const calculateTransactionExpiration = ( const createdAtHeight: number = context.currentHeight - createdBlocksAgo; return createdAtHeight + context.maxTransactionAge; -} +}; diff --git a/packages/core-magistrate-crypto/src/builders/bridgechain-registration.ts b/packages/core-magistrate-crypto/src/builders/bridgechain-registration.ts index ba18318476..1e5597514a 100644 --- a/packages/core-magistrate-crypto/src/builders/bridgechain-registration.ts +++ b/packages/core-magistrate-crypto/src/builders/bridgechain-registration.ts @@ -1,4 +1,5 @@ import { Interfaces, Transactions, Utils } from "@arkecosystem/crypto"; + import { MagistrateTransactionGroup, MagistrateTransactionType } from "../enums"; import { IBridgechainRegistrationAsset } from "../interfaces"; import { BridgechainRegistrationTransaction } from "../transactions"; diff --git a/packages/core-magistrate-crypto/src/builders/bridgechain-resignation.ts b/packages/core-magistrate-crypto/src/builders/bridgechain-resignation.ts index 886111b129..c35c1cc941 100644 --- a/packages/core-magistrate-crypto/src/builders/bridgechain-resignation.ts +++ b/packages/core-magistrate-crypto/src/builders/bridgechain-resignation.ts @@ -1,4 +1,5 @@ import { Interfaces, Transactions, Utils } from "@arkecosystem/crypto"; + import { MagistrateTransactionGroup, MagistrateTransactionType } from "../enums"; import { BridgechainResignationTransaction } from "../transactions"; diff --git a/packages/core-magistrate-crypto/src/builders/bridgechain-update.ts b/packages/core-magistrate-crypto/src/builders/bridgechain-update.ts index c172fe49a3..214cb0d740 100644 --- a/packages/core-magistrate-crypto/src/builders/bridgechain-update.ts +++ b/packages/core-magistrate-crypto/src/builders/bridgechain-update.ts @@ -1,4 +1,5 @@ import { Interfaces, Transactions, Utils } from "@arkecosystem/crypto"; + import { MagistrateTransactionGroup, MagistrateTransactionType } from "../enums"; import { IBridgechainUpdateAsset } from "../interfaces"; import { BridgechainUpdateTransaction } from "../transactions"; diff --git a/packages/core-magistrate-crypto/src/builders/business-registration.ts b/packages/core-magistrate-crypto/src/builders/business-registration.ts index 07561b9d42..20176f7d2e 100644 --- a/packages/core-magistrate-crypto/src/builders/business-registration.ts +++ b/packages/core-magistrate-crypto/src/builders/business-registration.ts @@ -1,4 +1,5 @@ import { Interfaces, Transactions, Utils } from "@arkecosystem/crypto"; + import { MagistrateTransactionGroup, MagistrateTransactionType } from "../enums"; import { IBusinessRegistrationAsset } from "../interfaces"; import { BusinessRegistrationTransaction } from "../transactions"; diff --git a/packages/core-magistrate-crypto/src/builders/business-resignation.ts b/packages/core-magistrate-crypto/src/builders/business-resignation.ts index f7337fdd55..8ab52812b7 100644 --- a/packages/core-magistrate-crypto/src/builders/business-resignation.ts +++ b/packages/core-magistrate-crypto/src/builders/business-resignation.ts @@ -1,4 +1,5 @@ import { Interfaces, Transactions, Utils } from "@arkecosystem/crypto"; + import { MagistrateTransactionGroup, MagistrateTransactionType } from "../enums"; import { BusinessResignationTransaction } from "../transactions"; diff --git a/packages/core-magistrate-crypto/src/builders/business-update.ts b/packages/core-magistrate-crypto/src/builders/business-update.ts index 496144bcd1..5412b5126e 100644 --- a/packages/core-magistrate-crypto/src/builders/business-update.ts +++ b/packages/core-magistrate-crypto/src/builders/business-update.ts @@ -1,4 +1,5 @@ import { Interfaces, Transactions, Utils } from "@arkecosystem/crypto"; + import { MagistrateTransactionGroup, MagistrateTransactionType } from "../enums"; import { IBusinessUpdateAsset } from "../interfaces"; import { BusinessUpdateTransaction } from "../transactions"; diff --git a/packages/core-magistrate-crypto/src/transactions/bridgechain-registration.ts b/packages/core-magistrate-crypto/src/transactions/bridgechain-registration.ts index 9bbb87b12a..be3c5500ee 100644 --- a/packages/core-magistrate-crypto/src/transactions/bridgechain-registration.ts +++ b/packages/core-magistrate-crypto/src/transactions/bridgechain-registration.ts @@ -1,5 +1,6 @@ import { Transactions, Utils } from "@arkecosystem/crypto"; import ByteBuffer from "bytebuffer"; + import { MagistrateTransactionGroup, MagistrateTransactionStaticFees, MagistrateTransactionType } from "../enums"; import { IBridgechainRegistrationAsset } from "../interfaces"; import { seedNodesSchema } from "./utils/bridgechain-schemas"; diff --git a/packages/core-magistrate-crypto/src/transactions/bridgechain-resignation.ts b/packages/core-magistrate-crypto/src/transactions/bridgechain-resignation.ts index 80a881fccd..b44b18b938 100644 --- a/packages/core-magistrate-crypto/src/transactions/bridgechain-resignation.ts +++ b/packages/core-magistrate-crypto/src/transactions/bridgechain-resignation.ts @@ -1,6 +1,7 @@ import { Transactions, Utils } from "@arkecosystem/crypto"; import ByteBuffer from "bytebuffer"; import Long from "long"; + import { MagistrateTransactionGroup, MagistrateTransactionStaticFees, MagistrateTransactionType } from "../enums"; import { IBridgechainResignationAsset } from "../interfaces"; diff --git a/packages/core-magistrate-crypto/src/transactions/bridgechain-update.ts b/packages/core-magistrate-crypto/src/transactions/bridgechain-update.ts index 399c514c21..419d8178fb 100644 --- a/packages/core-magistrate-crypto/src/transactions/bridgechain-update.ts +++ b/packages/core-magistrate-crypto/src/transactions/bridgechain-update.ts @@ -1,6 +1,7 @@ import { Transactions, Utils } from "@arkecosystem/crypto"; import ByteBuffer from "bytebuffer"; import Long from "long"; + import { MagistrateTransactionGroup, MagistrateTransactionStaticFees, MagistrateTransactionType } from "../enums"; import { IBridgechainUpdateAsset } from "../interfaces"; import { seedNodesSchema } from "./utils/bridgechain-schemas"; diff --git a/packages/core-magistrate-crypto/src/transactions/business-registration.ts b/packages/core-magistrate-crypto/src/transactions/business-registration.ts index e9129b1312..47a158d1ad 100644 --- a/packages/core-magistrate-crypto/src/transactions/business-registration.ts +++ b/packages/core-magistrate-crypto/src/transactions/business-registration.ts @@ -1,5 +1,6 @@ import { Transactions, Utils } from "@arkecosystem/crypto"; import ByteBuffer from "bytebuffer"; + import { MagistrateTransactionGroup, MagistrateTransactionStaticFees, MagistrateTransactionType } from "../enums"; import { IBusinessRegistrationAsset } from "../interfaces"; import { businessSchema } from "./utils/business-schema"; diff --git a/packages/core-magistrate-crypto/src/transactions/business-resignation.ts b/packages/core-magistrate-crypto/src/transactions/business-resignation.ts index ee3342a250..638b404985 100644 --- a/packages/core-magistrate-crypto/src/transactions/business-resignation.ts +++ b/packages/core-magistrate-crypto/src/transactions/business-resignation.ts @@ -1,5 +1,6 @@ import { Transactions, Utils } from "@arkecosystem/crypto"; import ByteBuffer from "bytebuffer"; + import { MagistrateTransactionGroup, MagistrateTransactionStaticFees, MagistrateTransactionType } from "../enums"; const { schemas } = Transactions; diff --git a/packages/core-magistrate-crypto/src/transactions/business-update.ts b/packages/core-magistrate-crypto/src/transactions/business-update.ts index 15dcf752a5..f36dd8f467 100644 --- a/packages/core-magistrate-crypto/src/transactions/business-update.ts +++ b/packages/core-magistrate-crypto/src/transactions/business-update.ts @@ -1,5 +1,6 @@ import { Transactions, Utils } from "@arkecosystem/crypto"; import ByteBuffer from "bytebuffer"; + import { MagistrateTransactionGroup, MagistrateTransactionStaticFees, MagistrateTransactionType } from "../enums"; import { IBusinessUpdateAsset } from "../interfaces"; import { businessSchema } from "./utils/business-schema"; diff --git a/packages/core-magistrate-transactions/src/service-provider.ts b/packages/core-magistrate-transactions/src/service-provider.ts index 633695f947..27300f8720 100644 --- a/packages/core-magistrate-transactions/src/service-provider.ts +++ b/packages/core-magistrate-transactions/src/service-provider.ts @@ -1,4 +1,4 @@ -import { Container, Contracts, Providers, Enums } from "@arkecosystem/core-kernel"; +import { Container, Contracts, Enums, Providers } from "@arkecosystem/core-kernel"; import { BridgechainRegistrationTransactionHandler, diff --git a/packages/core-p2p/src/network-monitor.ts b/packages/core-p2p/src/network-monitor.ts index a379abc7ce..dd0ae4199b 100644 --- a/packages/core-p2p/src/network-monitor.ts +++ b/packages/core-p2p/src/network-monitor.ts @@ -1,4 +1,4 @@ -import { app, Container, Contracts, Enums, Utils } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Enums, Providers, Utils } from "@arkecosystem/core-kernel"; import { Interfaces } from "@arkecosystem/crypto"; import delay from "delay"; import prettyMs from "pretty-ms"; @@ -38,7 +38,11 @@ export class NetworkMonitor implements Contracts.P2P.INetworkMonitor { private readonly rateLimiter: RateLimiter; public constructor() { - this.config = app.get("p2p.options"); + this.config = app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-p2p") + .config() + .all(); this.rateLimiter = buildRateLimiter(this.config); } @@ -129,7 +133,7 @@ export class NetworkMonitor implements Contracts.P2P.INetworkMonitor { let max = peers.length; let unresponsivePeers = 0; - const pingDelay = fast ? 1500 : app.get("p2p.options").verifyTimeout; + const pingDelay = fast ? 1500 : this.config.verifyTimeout; if (peerCount) { peers = Utils.shuffle(peers).slice(0, peerCount); @@ -396,7 +400,7 @@ export class NetworkMonitor implements Contracts.P2P.INetworkMonitor { public async broadcastTransactions(transactions: Interfaces.ITransaction[]): Promise { const peers: Contracts.P2P.Peer[] = Utils.take( Utils.shuffle(this.storage.getPeers()), - app.get("p2p.options").maxPeersBroadcast, + this.config.maxPeersBroadcast, ); this.logger.debug( @@ -478,7 +482,7 @@ export class NetworkMonitor implements Contracts.P2P.INetworkMonitor { return true; } - return Object.keys(this.storage.getPeers()).length >= app.get("p2p.options").minimumNetworkReach; + return Object.keys(this.storage.getPeers()).length >= this.config.minimumNetworkReach; } private async populateSeedPeers(): Promise { diff --git a/packages/core-p2p/src/network-state.ts b/packages/core-p2p/src/network-state.ts index 93509085c6..3911a1684d 100644 --- a/packages/core-p2p/src/network-state.ts +++ b/packages/core-p2p/src/network-state.ts @@ -1,4 +1,4 @@ -import { app, Container, Contracts } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Providers } from "@arkecosystem/core-kernel"; import { Crypto, Interfaces } from "@arkecosystem/crypto"; import { NetworkStateStatus } from "./enums"; @@ -45,7 +45,12 @@ export class NetworkState implements Contracts.P2P.NetworkState { const lastBlock: Interfaces.IBlock = app.get(Container.Identifiers.BlockchainService).getLastBlock(); const peers: Contracts.P2P.Peer[] = storage.getPeers(); - const minimumNetworkReach: number = app.get("p2p.options").minimumNetworkReach || 20; + const minimumNetworkReach: number = + app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-p2p") + .config() + .get("minimumNetworkReach") || 20; if (monitor.isColdStart()) { monitor.completeColdStart(); diff --git a/packages/core-p2p/src/peer-communicator.ts b/packages/core-p2p/src/peer-communicator.ts index 79e8c9cbf3..5659fd887c 100644 --- a/packages/core-p2p/src/peer-communicator.ts +++ b/packages/core-p2p/src/peer-communicator.ts @@ -1,4 +1,4 @@ -import { app, Container, Contracts, Enums, Utils } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Enums, Providers, Utils } from "@arkecosystem/core-kernel"; import { Interfaces, Managers, Transactions, Validation } from "@arkecosystem/crypto"; import dayjs from "dayjs"; import { SCClientSocket } from "socketcluster-client"; @@ -178,7 +178,11 @@ export class PeerCommunicator implements Contracts.P2P.PeerCommunicator { "Content-Type": "application/json", }, }, - app.get("p2p.options").getBlocksTimeout, + app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-p2p") + .config() + .get("getBlocksTimeout"), ); if (!peerBlocks) { diff --git a/packages/core-p2p/src/peer-connector.ts b/packages/core-p2p/src/peer-connector.ts index 12fe0385a5..9b8a7021a4 100644 --- a/packages/core-p2p/src/peer-connector.ts +++ b/packages/core-p2p/src/peer-connector.ts @@ -1,4 +1,4 @@ -import { app, Container, Contracts, Utils } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Providers, Utils } from "@arkecosystem/core-kernel"; import { create, SCClientSocket } from "socketcluster-client"; // todo: review the implementation @@ -27,8 +27,16 @@ export class PeerConnector implements Contracts.P2P.PeerConnector { port: peer.port, hostname: peer.ip, ackTimeout: Math.max( - app.get("p2p.options").getBlocksTimeout, - app.get("p2p.options").verifyTimeout, + app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-state") + .config() + .get("getBlocksTimeout"), + app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-state") + .config() + .get("verifyTimeout"), ), perMessageDeflate: true, }); diff --git a/packages/core-p2p/src/peer-processor.ts b/packages/core-p2p/src/peer-processor.ts index bdf6ee43be..01a6fa7152 100644 --- a/packages/core-p2p/src/peer-processor.ts +++ b/packages/core-p2p/src/peer-processor.ts @@ -1,4 +1,4 @@ -import { app, Container, Contracts, Enums } from "@arkecosystem/core-kernel"; +import { Container, Contracts, Enums, Providers } from "@arkecosystem/core-kernel"; import { Utils } from "@arkecosystem/crypto"; import { Peer } from "./peer"; @@ -25,6 +25,9 @@ export class PeerProcessor implements Contracts.P2P.PeerProcessor { @Container.inject(Container.Identifiers.PeerStorage) private readonly storage: Contracts.P2P.PeerStorage; + @Container.inject(Container.Identifiers.ServiceProviderRepository) + private readonly serviceProviderRepository: Providers.ServiceProviderRepository; + public init() { this.emitter.listen("internal.milestone.changed", () => this.updatePeersAfterMilestoneChange()); } @@ -39,7 +42,7 @@ export class PeerProcessor implements Contracts.P2P.PeerProcessor { } public validatePeerIp(peer, options: Contracts.P2P.AcceptNewPeerOptions = {}): boolean { - if (app.get("p2p.options").disableDiscovery && !this.storage.hasPendingPeer(peer.ip)) { + if (this.getConfig("disableDiscovery") && !this.storage.hasPendingPeer(peer.ip)) { this.logger.warning(`Rejected ${peer.ip} because the relay is in non-discovery mode.`); return false; } @@ -48,19 +51,16 @@ export class PeerProcessor implements Contracts.P2P.PeerProcessor { return false; } - if (!isWhitelisted(app.get("p2p.options").whitelist, peer.ip)) { + if (!isWhitelisted(this.getConfig("whitelist"), peer.ip)) { return false; } - if ( - this.storage.getSameSubnetPeers(peer.ip).length >= app.get("p2p.options").maxSameSubnetPeers && - !options.seed - ) { + if (this.storage.getSameSubnetPeers(peer.ip).length >= this.getConfig("maxSameSubnetPeers") && !options.seed) { if (process.env.CORE_P2P_PEER_VERIFIER_DEBUG_EXTRA) { this.logger.warning( - `Rejected ${peer.ip} because we are already at the ${ - app.get("p2p.options").maxSameSubnetPeers - } limit for peers sharing the same /24 subnet.`, + `Rejected ${peer.ip} because we are already at the ${this.getConfig( + "maxSameSubnetPeers", + )} limit for peers sharing the same /24 subnet.`, ); } @@ -89,7 +89,7 @@ export class PeerProcessor implements Contracts.P2P.PeerProcessor { try { this.storage.setPendingPeer(peer); - await this.communicator.ping(newPeer, app.get("p2p.options").verifyTimeout); + await this.communicator.ping(newPeer, this.getConfig("verifyTimeout")); this.storage.setPeer(newPeer); @@ -106,4 +106,11 @@ export class PeerProcessor implements Contracts.P2P.PeerProcessor { return; } + + private getConfig(key: string): T { + return this.serviceProviderRepository + .get("@arkecosystem/core-p2p") + .config() + .get(key); + } } diff --git a/packages/core-p2p/src/peer.ts b/packages/core-p2p/src/peer.ts index a2b4f28c2e..1c5508f264 100644 --- a/packages/core-p2p/src/peer.ts +++ b/packages/core-p2p/src/peer.ts @@ -1,4 +1,4 @@ -import { app, Contracts } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Providers } from "@arkecosystem/core-kernel"; import dayjs, { Dayjs } from "dayjs"; import { PeerVerificationResult } from "./peer-verifier"; @@ -6,7 +6,11 @@ import { PeerVerificationResult } from "./peer-verifier"; // todo: review the implementation export class Peer implements Contracts.P2P.Peer { public readonly ports: Contracts.P2P.PeerPorts = {}; - public readonly port: number = +app.get("p2p.options").server.port; + public readonly port: number = +app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-state") + .config() + .get("server.port"); public version: string; public latency: number; diff --git a/packages/core-p2p/src/schemas.ts b/packages/core-p2p/src/schemas.ts index f365845323..ebedfc08cd 100644 --- a/packages/core-p2p/src/schemas.ts +++ b/packages/core-p2p/src/schemas.ts @@ -1,4 +1,4 @@ -import { app, Container } from "@arkecosystem/core-kernel"; +import { app, Container, Providers } from "@arkecosystem/core-kernel"; export const requestSchemas = { peer: { @@ -44,7 +44,11 @@ export const requestSchemas = { $ref: "transactions", minItems: 1, maxItems: app.isBound(Container.Identifiers.TransactionPoolService) - ? app.get("transactionPool.options").maxTransactionsPerRequest || 40 + ? app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-p2p") + .config() + .get("maxTransactionsPerRequest") || 40 : 40, }, }, diff --git a/packages/core-p2p/src/service-provider.ts b/packages/core-p2p/src/service-provider.ts index 4efd2519f0..9d089ea5b9 100644 --- a/packages/core-p2p/src/service-provider.ts +++ b/packages/core-p2p/src/service-provider.ts @@ -10,10 +10,6 @@ import { startSocketServer } from "./socket-server"; export class ServiceProvider extends Providers.ServiceProvider { public async register(): Promise { - this.app.bind("p2p.options").toConstantValue(this.config().all()); - - this.app.log.info("Starting P2P Interface"); - this.registerServices(); if (process.env.DISABLE_P2P_SERVER) { @@ -35,8 +31,6 @@ export class ServiceProvider extends Providers.ServiceProvider { } public async dispose(): Promise { - this.app.log.info("Stopping P2P Interface"); - this.app.get(Container.Identifiers.PeerNetworkMonitor).stopServer(); } diff --git a/packages/core-p2p/src/socket-server/index.ts b/packages/core-p2p/src/socket-server/index.ts index df0d7463ac..783877ff21 100644 --- a/packages/core-p2p/src/socket-server/index.ts +++ b/packages/core-p2p/src/socket-server/index.ts @@ -1,4 +1,4 @@ -import { app } from "@arkecosystem/core-kernel"; +import { app, Container, Providers } from "@arkecosystem/core-kernel"; import SocketCluster from "socketcluster"; import { SocketErrors } from "../enums"; @@ -29,8 +29,16 @@ export const startSocketServer = async (service: PeerService, config: Record("p2p.options").getBlocksTimeout, - app.get("p2p.options").verifyTimeout, + app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-p2p") + .config() + .get("getBlocksTimeout"), + app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-p2p") + .config() + .get("verifyTimeout"), ), perMessageDeflate: true, }, diff --git a/packages/core-p2p/src/socket-server/utils/get-headers.ts b/packages/core-p2p/src/socket-server/utils/get-headers.ts index baa47abbef..9f7fb3876e 100644 --- a/packages/core-p2p/src/socket-server/utils/get-headers.ts +++ b/packages/core-p2p/src/socket-server/utils/get-headers.ts @@ -1,9 +1,13 @@ -import { app, Container, Contracts } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Providers } from "@arkecosystem/core-kernel"; export const getHeaders = () => { const headers = { version: app.version(), - port: app.get("p2p.options").port, + port: app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-p2p") + .config() + .get("port"), height: undefined, }; diff --git a/packages/core-p2p/src/socket-server/versions/peer.ts b/packages/core-p2p/src/socket-server/versions/peer.ts index d9ef1197c1..f57feae84f 100644 --- a/packages/core-p2p/src/socket-server/versions/peer.ts +++ b/packages/core-p2p/src/socket-server/versions/peer.ts @@ -1,4 +1,4 @@ -import { app, Container, Contracts, Utils } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Providers, Utils } from "@arkecosystem/core-kernel"; import { Crypto, Interfaces } from "@arkecosystem/crypto"; import { MissingCommonBlockError } from "../../errors"; @@ -66,7 +66,14 @@ export const postBlock = async ({ req }): Promise => { ); const block: Interfaces.IBlockData = req.data.block; - const fromForger: boolean = isWhitelisted(app.get("p2p.options").remoteAccess, req.headers.remoteAddress); + const fromForger: boolean = isWhitelisted( + app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-p2p") + .config() + .get("remoteAccess"), + req.headers.remoteAddress, + ); if (!fromForger) { if (blockchain.pingBlock(block)) { diff --git a/packages/core-p2p/src/socket-server/versions/utils.ts b/packages/core-p2p/src/socket-server/versions/utils.ts index e328e0f428..016f5cbc2f 100644 --- a/packages/core-p2p/src/socket-server/versions/utils.ts +++ b/packages/core-p2p/src/socket-server/versions/utils.ts @@ -1,4 +1,4 @@ -import { app, Container } from "@arkecosystem/core-kernel"; +import { app, Container, Providers } from "@arkecosystem/core-kernel"; import { isWhitelisted } from "../../utils/is-whitelisted"; import * as internalHandlers from "./internal"; @@ -21,7 +21,19 @@ export const getHandlers = (): { [key: string]: string[] } => ({ export const log = ({ req }): void => app.log[req.data.level](req.data.message); export const isForgerAuthorized = ({ req }): { authorized: boolean } => ({ - authorized: isWhitelisted(app.get("p2p.options").remoteAccess, req.data.ip), + authorized: isWhitelisted( + app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-p2p") + .config() + .get("remoteAccess"), + req.data.ip, + ), }); -export const getConfig = (): Record => app.get("p2p.options"); +export const getConfig = (): Record => + app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-p2p") + .config() + .all(); diff --git a/packages/core-p2p/src/utils/build-rate-limiter.ts b/packages/core-p2p/src/utils/build-rate-limiter.ts index fb11a0b688..38e08d7ecb 100644 --- a/packages/core-p2p/src/utils/build-rate-limiter.ts +++ b/packages/core-p2p/src/utils/build-rate-limiter.ts @@ -1,13 +1,7 @@ -import { app } from "@arkecosystem/core-kernel"; - import { RateLimiter } from "../rate-limiter"; -export const buildRateLimiter = options => { - if (!options || Object.keys(options).length === 0) { - options = app.get("p2p.options"); - } - - return new RateLimiter({ +export const buildRateLimiter = options => + new RateLimiter({ whitelist: [...options.whitelist, ...options.remoteAccess], configurations: { global: { @@ -38,4 +32,3 @@ export const buildRateLimiter = options => { ], }, }); -}; diff --git a/packages/core-p2p/src/utils/is-valid-version.ts b/packages/core-p2p/src/utils/is-valid-version.ts index 2e59657dea..6601b9a69b 100644 --- a/packages/core-p2p/src/utils/is-valid-version.ts +++ b/packages/core-p2p/src/utils/is-valid-version.ts @@ -1,4 +1,4 @@ -import { app, Contracts } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Providers } from "@arkecosystem/core-kernel"; import { Managers } from "@arkecosystem/crypto"; import semver from "semver"; @@ -16,7 +16,11 @@ export const isValidVersion = (peer: Contracts.P2P.Peer): boolean => { if (p2p && Array.isArray(p2p.minimumVersions) && p2p.minimumVersions.length > 0) { minimumVersions = p2p.minimumVersions; } else { - minimumVersions = app.get<{ minimumVersions: string[] }>("p2p.options").minimumVersions; + minimumVersions = app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-p2p") + .config() + .get("minimumVersions"); } const includePrerelease: boolean = Managers.configManager.get("network.name") !== "mainnet"; diff --git a/packages/core-state/src/service-provider.ts b/packages/core-state/src/service-provider.ts index b43a0bdc69..f89f220bf9 100644 --- a/packages/core-state/src/service-provider.ts +++ b/packages/core-state/src/service-provider.ts @@ -16,7 +16,5 @@ export class ServiceProvider extends Providers.ServiceProvider { .bind(Container.Identifiers.StateStore) .to(StateStore) .inSingletonScope(); - - this.app.bind("state.options").toConstantValue(this.config().all()); } } diff --git a/packages/core-state/src/stores/state.ts b/packages/core-state/src/stores/state.ts index 657e1378c4..27cf0f2379 100644 --- a/packages/core-state/src/stores/state.ts +++ b/packages/core-state/src/stores/state.ts @@ -1,4 +1,4 @@ -import { app, Container, Contracts, Enums } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Enums, Providers } from "@arkecosystem/core-kernel"; import { Interfaces, Managers } from "@arkecosystem/crypto"; import assert from "assert"; import { OrderedMap, OrderedSet, Seq } from "immutable"; @@ -102,7 +102,14 @@ export class StateStore implements Contracts.State.StateStore { } // Delete oldest block if size exceeds the maximum - if (this.lastBlocks.size > app.get("state.options").storage.maxLastBlocks) { + if ( + this.lastBlocks.size > + app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-state") + .config() + .get("storage.maxLastBlocks") + ) { this.lastBlocks = this.lastBlocks.delete(this.lastBlocks.first().data.height); } @@ -190,7 +197,12 @@ export class StateStore implements Contracts.State.StateStore { }); // Cap the Set of last transaction ids to maxLastTransactionIds - const limit = app.get("state.options").storage.maxLastTransactionIds; + const limit = app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-state") + .config() + .get("storage.maxLastTransactionIds"); + if (this.cachedTransactionIds.size > limit) { this.cachedTransactionIds = this.cachedTransactionIds.takeLast(limit); } diff --git a/packages/core-state/src/wallets/wallet.ts b/packages/core-state/src/wallets/wallet.ts index 9215f4035a..b5ce112d69 100644 --- a/packages/core-state/src/wallets/wallet.ts +++ b/packages/core-state/src/wallets/wallet.ts @@ -3,11 +3,11 @@ import { Errors } from "@arkecosystem/core-transactions"; import { Crypto, Enums, + Errors as CryptoErrors, Identities, Interfaces, Transactions, Utils, - Errors as CryptoErrors, } from "@arkecosystem/crypto"; // todo: review the implementation diff --git a/packages/core-test-framework/src/helpers/block-factory.ts b/packages/core-test-framework/src/helpers/block-factory.ts index 8cae0446e7..a041ccd56a 100644 --- a/packages/core-test-framework/src/helpers/block-factory.ts +++ b/packages/core-test-framework/src/helpers/block-factory.ts @@ -1,5 +1,6 @@ import { Delegate } from "@arkecosystem/core-forger"; import { Interfaces, Networks, Utils } from "@arkecosystem/crypto"; + import { delegates, genesisBlock } from "../utils/fixtures"; export class BlockFactory { diff --git a/packages/core-test-framework/src/helpers/index.ts b/packages/core-test-framework/src/helpers/index.ts index e18eaa08be..2e854d3f6a 100644 --- a/packages/core-test-framework/src/helpers/index.ts +++ b/packages/core-test-framework/src/helpers/index.ts @@ -1,3 +1,3 @@ export * from "./rest-client"; export * from "./transaction-factory"; -export * from "./block-factory"; \ No newline at end of file +export * from "./block-factory"; diff --git a/packages/core-transaction-pool/src/dynamic-fee.ts b/packages/core-transaction-pool/src/dynamic-fee.ts index 2af0daf6b3..de56f0bfd8 100644 --- a/packages/core-transaction-pool/src/dynamic-fee.ts +++ b/packages/core-transaction-pool/src/dynamic-fee.ts @@ -1,4 +1,4 @@ -import { app } from "@arkecosystem/core-kernel"; +import { app, Container, Providers } from "@arkecosystem/core-kernel"; import { Handlers } from "@arkecosystem/core-transactions"; import { Interfaces, Utils } from "@arkecosystem/crypto"; @@ -9,7 +9,11 @@ export const dynamicFeeMatcher = (transaction: Interfaces.ITransaction): Dynamic const fee: Utils.BigNumber = transaction.data.fee; const id: string = transaction.id; - const { dynamicFees } = app.get("transactionPool.options"); + const dynamicFees = app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-transaction-pool") + .config() + .get>("dynamicFees"); let broadcast: boolean; let enterPool: boolean; @@ -18,7 +22,7 @@ export const dynamicFeeMatcher = (transaction: Interfaces.ITransaction): Dynamic const handler: Handlers.TransactionHandler = app .get("transactionHandlerRegistry") .get(transaction.type, transaction.typeGroup); - const addonBytes: number = app.get("transactionPool.options").dynamicFees.addonBytes[transaction.key]; + const addonBytes: number = dynamicFees.addonBytes[transaction.key]; const minFeeBroadcast: Utils.BigNumber = handler.dynamicFee( transaction, addonBytes, diff --git a/packages/core-transaction-pool/src/memory.ts b/packages/core-transaction-pool/src/memory.ts index 2b6e8ca260..ff530e65d3 100644 --- a/packages/core-transaction-pool/src/memory.ts +++ b/packages/core-transaction-pool/src/memory.ts @@ -1,5 +1,5 @@ import { app, Container, Utils as AppUtils } from "@arkecosystem/core-kernel"; -import { Crypto, Interfaces, Managers, Utils, Transactions } from "@arkecosystem/crypto"; +import { Crypto, Interfaces, Managers, Transactions, Utils } from "@arkecosystem/crypto"; import assert from "assert"; // todo: review implementation and reduce the complexity of all methods as it is quite high diff --git a/packages/core-transaction-pool/src/processor.ts b/packages/core-transaction-pool/src/processor.ts index 6d01815996..967fd9fdc2 100644 --- a/packages/core-transaction-pool/src/processor.ts +++ b/packages/core-transaction-pool/src/processor.ts @@ -1,4 +1,4 @@ -import { app, Container, Contracts, Utils } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts, Providers, Utils } from "@arkecosystem/core-kernel"; import { Errors, Handlers } from "@arkecosystem/core-transactions"; import { Crypto, Enums, Errors as CryptoErrors, Interfaces, Managers, Transactions } from "@arkecosystem/crypto"; @@ -93,7 +93,11 @@ export class Processor implements Contracts.TransactionPool.Processor { } private async filterAndTransformTransactions(transactions: Interfaces.ITransactionData[]): Promise { - const { maxTransactionBytes } = app.get("transactionPool.options"); + const maxTransactionBytes = app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-transaction-pool") + .config() + .get("maxTransactionBytes"); for (const transaction of transactions) { const exists: boolean = await this.pool.has(transaction.id); @@ -179,7 +183,11 @@ export class Processor implements Contracts.TransactionPool.Processor { blockTime: Managers.configManager.getMilestone(lastHeight).blocktime, currentHeight: lastHeight, now: Crypto.Slots.getTime(), - maxTransactionAge: app.get("transactionPool.options").maxTransactionAge, + maxTransactionAge: app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-transaction-pool") + .config() + .get("maxTransactionAge"), }; const expiration: number = Utils.expirationCalculator.calculateTransactionExpiration( diff --git a/packages/core-transaction-pool/src/service-provider.ts b/packages/core-transaction-pool/src/service-provider.ts index 37f41df57c..c8b8e72d59 100644 --- a/packages/core-transaction-pool/src/service-provider.ts +++ b/packages/core-transaction-pool/src/service-provider.ts @@ -20,7 +20,6 @@ export class ServiceProvider extends Providers.ServiceProvider { ); this.app.bind(Container.Identifiers.TransactionPoolService).toConstantValue(connection); - this.app.bind("transactionPool.options").toConstantValue(this.config().all()); } public async dispose(): Promise { diff --git a/packages/core-transaction-pool/src/wallet-repository.ts b/packages/core-transaction-pool/src/wallet-repository.ts index 4629834cae..e43ce4d718 100644 --- a/packages/core-transaction-pool/src/wallet-repository.ts +++ b/packages/core-transaction-pool/src/wallet-repository.ts @@ -1,4 +1,4 @@ -import { app, Contracts, Container } from "@arkecosystem/core-kernel"; +import { app, Container, Contracts } from "@arkecosystem/core-kernel"; import { Wallets } from "@arkecosystem/core-state"; import { Handlers } from "@arkecosystem/core-transactions"; import { Identities, Interfaces } from "@arkecosystem/crypto"; diff --git a/packages/core-transactions/src/handlers/handler-registry.ts b/packages/core-transactions/src/handlers/handler-registry.ts index 1bb529a130..643dbc58ba 100644 --- a/packages/core-transactions/src/handlers/handler-registry.ts +++ b/packages/core-transactions/src/handlers/handler-registry.ts @@ -1,7 +1,7 @@ import { app, Container, Services } from "@arkecosystem/core-kernel"; import { Enums, Errors, Transactions } from "@arkecosystem/crypto"; -import { InvalidTransactionTypeError, DeactivatedTransactionHandlerError } from "../errors"; +import { DeactivatedTransactionHandlerError, InvalidTransactionTypeError } from "../errors"; import { DelegateRegistrationTransactionHandler } from "./delegate-registration"; import { DelegateResignationTransactionHandler } from "./delegate-resignation"; import { HtlcClaimTransactionHandler } from "./htlc-claim"; diff --git a/packages/core-transactions/src/handlers/htlc-lock.ts b/packages/core-transactions/src/handlers/htlc-lock.ts index b129caf702..5932d99d42 100644 --- a/packages/core-transactions/src/handlers/htlc-lock.ts +++ b/packages/core-transactions/src/handlers/htlc-lock.ts @@ -1,8 +1,8 @@ import { app, Container, Contracts } from "@arkecosystem/core-kernel"; -import { Interfaces, Managers, Transactions, Utils, Enums } from "@arkecosystem/crypto"; +import { Enums, Interfaces, Managers, Transactions, Utils } from "@arkecosystem/crypto"; -import { TransactionHandler, TransactionHandlerConstructor } from "./transaction"; import { HtlcLockExpiredError } from "../errors"; +import { TransactionHandler, TransactionHandlerConstructor } from "./transaction"; // todo: revisit the implementation, container usage and arguments after core-database rework // todo: replace unnecessary function arguments with dependency injection to avoid passing around references diff --git a/packages/core-transactions/src/handlers/ipfs.ts b/packages/core-transactions/src/handlers/ipfs.ts index ea38724897..54c718c585 100644 --- a/packages/core-transactions/src/handlers/ipfs.ts +++ b/packages/core-transactions/src/handlers/ipfs.ts @@ -1,5 +1,6 @@ import { Contracts } from "@arkecosystem/core-kernel"; import { Interfaces, Managers, Transactions } from "@arkecosystem/crypto"; + import { TransactionReader } from "../transaction-reader"; import { TransactionHandler, TransactionHandlerConstructor } from "./transaction"; diff --git a/packages/core-webhooks/src/conditions.ts b/packages/core-webhooks/src/conditions.ts index dafb725296..e08fb84042 100644 --- a/packages/core-webhooks/src/conditions.ts +++ b/packages/core-webhooks/src/conditions.ts @@ -16,7 +16,6 @@ const compareBigNumber = (value, expected, comparison): boolean => { } }; -export const between = (actual, expected): boolean => gt(actual, expected.min) && lt(actual, expected.max); export const contains = (actual, expected): boolean => actual.includes(expected); export const eq = (actual, expected): boolean => JSON.stringify(actual) === JSON.stringify(expected); export const falsy = (actual): boolean => actual === false || !toBoolean(actual); @@ -24,6 +23,7 @@ export const gt = (actual, expected): boolean => compareBigNumber(actual, expect export const gte = (actual, expected): boolean => compareBigNumber(actual, expected, "isGreaterThanEqual"); export const lt = (actual, expected): boolean => compareBigNumber(actual, expected, "isLessThan"); export const lte = (actual, expected): boolean => compareBigNumber(actual, expected, "isLessThanEqual"); +export const between = (actual, expected): boolean => gt(actual, expected.min) && lt(actual, expected.max); export const ne = (actual, expected): boolean => !eq(actual, expected); export const notBetween = (actual, expected): boolean => !between(actual, expected); export const regexp = (actual, expected): boolean => new RegExp(expected).test(actual); diff --git a/packages/core-webhooks/src/listener.ts b/packages/core-webhooks/src/listener.ts index f7c8aa3842..f49b6f1384 100644 --- a/packages/core-webhooks/src/listener.ts +++ b/packages/core-webhooks/src/listener.ts @@ -1,4 +1,4 @@ -import { Contracts, Enums, Utils } from "@arkecosystem/core-kernel"; +import { Container, Contracts, Enums, Providers, Utils } from "@arkecosystem/core-kernel"; import * as conditions from "./conditions"; import { Database } from "./database"; @@ -47,7 +47,11 @@ export const startListeners = (app: Contracts.Kernel.Application): void => { headers: { Authorization: webhook.token, }, - timeout: app.get("webhooks.options").timeout, + timeout: app + .get(Container.Identifiers.ServiceProviderRepository) + .get("@arkecosystem/core-webhooks") + .config() + .get("timeout"), }); app.log.debug( diff --git a/packages/core-webhooks/src/service-provider.ts b/packages/core-webhooks/src/service-provider.ts index c2a2bceb88..e5a9e62fca 100644 --- a/packages/core-webhooks/src/service-provider.ts +++ b/packages/core-webhooks/src/service-provider.ts @@ -21,7 +21,6 @@ export class ServiceProvider extends Providers.ServiceProvider { startListeners(this.app); this.app.bind("webhooks").toConstantValue(await startServer(this.app, this.config().get("server"))); - this.app.bind("webhooks.options").toConstantValue(this.config().all()); } public async dispose(): Promise { diff --git a/packages/core/bin/config/devnet/app.js b/packages/core/bin/config/devnet/app.js index e14163f34a..7a0b76b697 100644 --- a/packages/core/bin/config/devnet/app.js +++ b/packages/core/bin/config/devnet/app.js @@ -36,4 +36,4 @@ module.exports = { }, }, }, -} \ No newline at end of file +}; diff --git a/packages/core/bin/config/mainnet/app.js b/packages/core/bin/config/mainnet/app.js index e14163f34a..7a0b76b697 100644 --- a/packages/core/bin/config/mainnet/app.js +++ b/packages/core/bin/config/mainnet/app.js @@ -36,4 +36,4 @@ module.exports = { }, }, }, -} \ No newline at end of file +}; diff --git a/packages/core/bin/config/testnet/app.js b/packages/core/bin/config/testnet/app.js index 7c9eab818f..292b697669 100644 --- a/packages/core/bin/config/testnet/app.js +++ b/packages/core/bin/config/testnet/app.js @@ -17,7 +17,8 @@ module.exports = { }, flags: {}, services: {}, - plugins: [{ + plugins: [ + { package: "@arkecosystem/core-transactions", }, { @@ -32,7 +33,8 @@ module.exports = { connection: { host: process.env.CORE_DB_HOST || "localhost", port: process.env.CORE_DB_PORT || 5432, - database: process.env.CORE_DB_DATABASE || `${process.env.CORE_TOKEN}_${process.env.CORE_NETWORK_NAME}`, + database: + process.env.CORE_DB_DATABASE || `${process.env.CORE_TOKEN}_${process.env.CORE_NETWORK_NAME}`, user: process.env.CORE_DB_USERNAME || process.env.CORE_TOKEN, password: process.env.CORE_DB_PASSWORD || "password", }, diff --git a/packages/crypto/src/blocks/serializer.ts b/packages/crypto/src/blocks/serializer.ts index 90d39c1961..80abb53cb6 100644 --- a/packages/crypto/src/blocks/serializer.ts +++ b/packages/crypto/src/blocks/serializer.ts @@ -1,5 +1,6 @@ import ByteBuffer from "bytebuffer"; import Long from "long"; + import { PreviousBlockIdFormatError } from "../errors"; import { IBlockData, ITransactionData } from "../interfaces"; import { configManager } from "../managers/config"; diff --git a/packages/crypto/src/interfaces/transactions.ts b/packages/crypto/src/interfaces/transactions.ts index a461554792..1216682437 100644 --- a/packages/crypto/src/interfaces/transactions.ts +++ b/packages/crypto/src/interfaces/transactions.ts @@ -1,4 +1,5 @@ import { ErrorObject } from "ajv"; + import { Enums } from ".."; import { BigNumber } from "../utils"; diff --git a/packages/crypto/src/transactions/serializer.ts b/packages/crypto/src/transactions/serializer.ts index fbf99394c3..da609f5bd3 100644 --- a/packages/crypto/src/transactions/serializer.ts +++ b/packages/crypto/src/transactions/serializer.ts @@ -1,5 +1,6 @@ import ByteBuffer from "bytebuffer"; import Long from "long"; + import { Utils } from ".."; import { TransactionType, TransactionTypeGroup } from "../enums"; import { TransactionVersionError } from "../errors"; diff --git a/packages/crypto/src/transactions/types/htlc-lock.ts b/packages/crypto/src/transactions/types/htlc-lock.ts index 73de2b422c..ab9747ade4 100644 --- a/packages/crypto/src/transactions/types/htlc-lock.ts +++ b/packages/crypto/src/transactions/types/htlc-lock.ts @@ -1,5 +1,6 @@ import ByteBuffer from "bytebuffer"; import Long from "long"; + import { TransactionType, TransactionTypeGroup } from "../../enums"; import { Address } from "../../identities"; import { ISerializeOptions } from "../../interfaces"; diff --git a/packages/crypto/src/transactions/types/multi-payment.ts b/packages/crypto/src/transactions/types/multi-payment.ts index 81ac010a72..9caf4a5bde 100644 --- a/packages/crypto/src/transactions/types/multi-payment.ts +++ b/packages/crypto/src/transactions/types/multi-payment.ts @@ -1,5 +1,6 @@ import ByteBuffer from "bytebuffer"; import Long from "long"; + import { TransactionType, TransactionTypeGroup } from "../../enums"; import { Address } from "../../identities"; import { IMultiPaymentItem, ISerializeOptions } from "../../interfaces"; diff --git a/packages/crypto/src/transactions/types/transfer.ts b/packages/crypto/src/transactions/types/transfer.ts index d513356dd0..653d9ceb82 100644 --- a/packages/crypto/src/transactions/types/transfer.ts +++ b/packages/crypto/src/transactions/types/transfer.ts @@ -1,5 +1,6 @@ import ByteBuffer from "bytebuffer"; import Long from "long"; + import { TransactionType, TransactionTypeGroup } from "../../enums"; import { Address } from "../../identities"; import { ISerializeOptions } from "../../interfaces"; diff --git a/packages/crypto/src/utils/base58.ts b/packages/crypto/src/utils/base58.ts index 4c4b9742e3..bbf667add9 100644 --- a/packages/crypto/src/utils/base58.ts +++ b/packages/crypto/src/utils/base58.ts @@ -1,5 +1,6 @@ import { base58 } from "bstring"; import moize from "fast-memoize"; + import { HashAlgorithms } from "../crypto"; const encodeCheck = (buffer: Buffer): string => { diff --git a/packages/crypto/src/validation/formats.ts b/packages/crypto/src/validation/formats.ts index 813c59b8ff..62d726b399 100644 --- a/packages/crypto/src/validation/formats.ts +++ b/packages/crypto/src/validation/formats.ts @@ -1,4 +1,5 @@ import { Ajv } from "ajv"; + import { isValidPeer, maxVendorFieldLength } from "../utils"; const vendorField = (ajv: Ajv) => { diff --git a/packages/crypto/src/validation/keywords.ts b/packages/crypto/src/validation/keywords.ts index e158bf5d78..0bea6f0070 100644 --- a/packages/crypto/src/validation/keywords.ts +++ b/packages/crypto/src/validation/keywords.ts @@ -1,5 +1,6 @@ import { Ajv } from "ajv"; import ajvKeywords from "ajv-keywords"; + import { TransactionType } from "../enums"; import { ITransactionData } from "../interfaces"; import { configManager } from "../managers";