diff --git a/__tests__/unit/core-kernel/services/attributes/attribute-service.test.ts b/__tests__/unit/core-kernel/services/attributes/attribute-service.test.ts deleted file mode 100644 index d2d735c4e2..0000000000 --- a/__tests__/unit/core-kernel/services/attributes/attribute-service.test.ts +++ /dev/null @@ -1,71 +0,0 @@ -import "jest-extended"; - -import { AttributeService } from "@packages/core-kernel/src/services/attributes/attribute-service"; -import { AttributeSet } from "@packages/core-kernel/src/services/attributes/attribute-set"; -import { AttributeMap } from "@packages/core-kernel/src/services/attributes/attribute-map"; - -let indexes: AttributeService; - -beforeEach(() => (indexes = new AttributeService())); - -describe("AttributeService", () => { - it("should throw if the given index does not exist in the given scope", () => { - indexes.set("block", new AttributeSet(), { scope: "queued" }); - - expect(() => indexes.get("block")).toThrow('Expected value which is "non-null and non-undefined".'); - }); - - it("should return the given index", () => { - indexes.set("block", new AttributeSet()); - - expect(indexes.get("block")).toBeInstanceOf(AttributeMap); - }); - - it("should throw if the given index is undefined", () => { - expect(() => indexes.get("block")).toThrow('Expected value which is "non-null and non-undefined".'); - }); - - it("should throw if the given index is already set", () => { - indexes.set("block", new AttributeSet()); - - expect(() => indexes.set("block", new AttributeSet())).toThrow("Duplicate index: block"); - }); - - it("should forget all attributes of the given index", () => { - indexes.set("block", new AttributeSet()); - - expect(indexes.get("block")).toBeInstanceOf(AttributeMap); - expect(indexes.has("block")).toBeTrue(); - - indexes.forget("block"); - - expect(() => indexes.get("block")).toThrow('Expected value which is "non-null and non-undefined".'); - expect(indexes.has("block")).toBeFalse(); - }); - - it("should forget all indexes of the default scope", () => { - indexes.set("block", new AttributeSet()); - - expect(indexes.get("block")).toBeInstanceOf(AttributeMap); - expect(indexes.has("block")).toBeTrue(); - - indexes.flush(); - - expect(() => indexes.get("block")).toThrow('Expected value which is "non-null and non-undefined".'); - expect(indexes.has("block")).toBeFalse(); - }); - - it("should forget all attributes of the given scope", () => { - const opts: { scope: string } = { scope: "special" }; - - indexes.set("block", new AttributeSet(), opts); - - expect(indexes.get("block", opts)).toBeInstanceOf(AttributeMap); - expect(indexes.has("block", opts)).toBeTrue(); - - indexes.flush("special"); - - expect(() => indexes.get("block", opts)).toThrow('Expected value which is "non-null and non-undefined".'); - expect(indexes.has("block", opts)).toBeFalse(); - }); -}); diff --git a/__tests__/unit/core-kernel/services/attributes/service-provider.test.ts b/__tests__/unit/core-kernel/services/attributes/service-provider.test.ts deleted file mode 100644 index 5356b543ea..0000000000 --- a/__tests__/unit/core-kernel/services/attributes/service-provider.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import "jest-extended"; - -import { Application } from "@packages/core-kernel/src/application"; -import { Container, Identifiers } from "@packages/core-kernel/src/ioc"; -import { ServiceProvider } from "@packages/core-kernel/src/services/attributes/service-provider"; -import { AttributeService } from "@packages/core-kernel/src/services/attributes/attribute-service"; - -let app: Application; - -beforeEach(() => (app = new Application(new Container()))); - -describe("AttributeServiceProvider", () => { - it(".register", async () => { - expect(app.isBound(Identifiers.AttributeService)).toBeFalse(); - - await app.resolve(ServiceProvider).register(); - - expect(app.isBound(Identifiers.AttributeService)).toBeTrue(); - expect(app.get(Identifiers.AttributeService)).toBeInstanceOf(AttributeService); - }); -}); diff --git a/__tests__/unit/core-kernel/utils/delegate-calculator.test.ts b/__tests__/unit/core-kernel/utils/delegate-calculator.test.ts index e98a879d13..b2e1bb57ad 100644 --- a/__tests__/unit/core-kernel/utils/delegate-calculator.test.ts +++ b/__tests__/unit/core-kernel/utils/delegate-calculator.test.ts @@ -3,8 +3,6 @@ import "jest-extended"; import { Container, Services } from "@arkecosystem/core-kernel"; import { Sandbox } from "@arkecosystem/core-test-framework"; -import { Identifiers } from "@packages/core-kernel/src/ioc"; -import { AttributeService } from "@packages/core-kernel/src/services/attributes"; import { Wallet } from "@packages/core-state/src/wallets"; import { Managers, Utils } from "@arkecosystem/crypto"; import { calculateApproval, calculateForgedTotal } from "@packages/core-kernel/src/utils/delegate-calculator"; @@ -14,11 +12,6 @@ let sandbox: Sandbox; beforeAll(() => { sandbox = new Sandbox(); - sandbox.app - .bind(Identifiers.AttributeService) - .to(AttributeService) - .inSingletonScope(); - sandbox.app .bind(Container.Identifiers.WalletAttributes) .to(Services.Attributes.AttributeSet) diff --git a/packages/core-kernel/src/bootstrap/app/register-base-service-providers.ts b/packages/core-kernel/src/bootstrap/app/register-base-service-providers.ts index 6fc2b84578..015982b70f 100644 --- a/packages/core-kernel/src/bootstrap/app/register-base-service-providers.ts +++ b/packages/core-kernel/src/bootstrap/app/register-base-service-providers.ts @@ -1,6 +1,6 @@ import { Application } from "../../contracts/kernel"; import { Identifiers, inject, injectable } from "../../ioc"; -import { Actions, Attributes, Cache, Filesystem, Log, Queue, Schedule, Validation } from "../../services"; +import { Actions, Cache, Filesystem, Log, Queue, Schedule, Validation } from "../../services"; import { Bootstrapper } from "../interfaces"; /** @@ -28,8 +28,6 @@ export class RegisterBaseServiceProviders implements Bootstrapper { public async bootstrap(): Promise { await this.app.resolve(Actions.ServiceProvider).register(); - await this.app.resolve(Attributes.ServiceProvider).register(); - await this.app.resolve(Log.ServiceProvider).register(); await this.app.resolve(Filesystem.ServiceProvider).register(); diff --git a/packages/core-kernel/src/ioc/identifiers.ts b/packages/core-kernel/src/ioc/identifiers.ts index e4e68cc091..d7dcaeae03 100644 --- a/packages/core-kernel/src/ioc/identifiers.ts +++ b/packages/core-kernel/src/ioc/identifiers.ts @@ -23,7 +23,6 @@ export const Identifiers: Record = { ValidationManager: Symbol.for("Manager"), // Services ActionService: Symbol.for("Service"), - AttributeService: Symbol.for("Service"), BlockchainService: Symbol.for("Service"), CacheService: Symbol.for("Service"), ConfigService: Symbol.for("Service"), diff --git a/packages/core-kernel/src/services/attributes/attribute-service.ts b/packages/core-kernel/src/services/attributes/attribute-service.ts deleted file mode 100644 index 102631123d..0000000000 --- a/packages/core-kernel/src/services/attributes/attribute-service.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { strictEqual } from "assert"; - -import { injectable } from "../../ioc"; -import { assert } from "../../utils"; -import { AttributeMap } from "./attribute-map"; -import { AttributeSet } from "./attribute-set"; - -interface AttributeMapOptions { - scope: string; -} - -@injectable() -export class AttributeService { - /** - * @private - * @type {Map>} - * @memberof AttributeService - */ - private readonly scopes: Map> = new Map>(); - - /** - * @param {string} name - * @param {AttributeMapOptions} [options={ scope: "default" }] - * @returns {AttributeMap} - * @memberof AttributeService - */ - public get(name: string, options: AttributeMapOptions = { scope: "default" }): AttributeMap { - const scope: AttributeMap | undefined = this.scope(options.scope).get(name); - - assert.defined(scope); - - return scope; - } - - /** - * @param {string} name - * @param {AttributeSet} knownAttributes - * @param {AttributeMapOptions} [options={ scope: "default" }] - * @returns {boolean} - * @memberof AttributeService - */ - public set( - name: string, - knownAttributes: AttributeSet, - options: AttributeMapOptions = { scope: "default" }, - ): boolean { - const scope: Map = this.scope(options.scope); - - strictEqual(scope.has(name), false, `Duplicate index: ${name}`); - - scope.set(name, new AttributeMap(knownAttributes)); - - return scope.has(name); - } - - /** - * @param {string} name - * @param {AttributeMapOptions} [options={ scope: "default" }] - * @returns {boolean} - * @memberof AttributeService - */ - public forget(name: string, options: AttributeMapOptions = { scope: "default" }): boolean { - return this.scope(options.scope).delete(name); - } - - /** - * @param {string} [name] - * @returns {boolean} - * @memberof AttributeService - */ - public flush(name?: string): boolean { - const scope: Map> | Map = name - ? this.scope(name) - : this.scopes; - - scope.clear(); - - return scope.size === 0; - } - - /** - * @param {string} name - * @param {AttributeMapOptions} [options={ scope: "default" }] - * @returns {boolean} - * @memberof AttributeService - */ - public has(name: string, options: AttributeMapOptions = { scope: "default" }): boolean { - return this.scope(options.scope).has(name); - } - - /** - * @private - * @param {string} name - * @returns {Map} - * @memberof AttributeService - */ - private scope(name: string): Map { - if (!this.scopes.has(name)) { - this.scopes.set(name, new Map()); - } - - const scope: Map | undefined = this.scopes.get(name); - - assert.defined>(scope); - - return scope; - } -} diff --git a/packages/core-kernel/src/services/attributes/index.ts b/packages/core-kernel/src/services/attributes/index.ts index 8eccdc39eb..abdeaa0d24 100644 --- a/packages/core-kernel/src/services/attributes/index.ts +++ b/packages/core-kernel/src/services/attributes/index.ts @@ -1,5 +1,3 @@ export * from "./attribute-map"; -export * from "./attribute-service"; export * from "./attribute-set"; export * from "./contracts"; -export * from "./service-provider"; diff --git a/packages/core-kernel/src/services/attributes/service-provider.ts b/packages/core-kernel/src/services/attributes/service-provider.ts deleted file mode 100644 index c7bd8b9bac..0000000000 --- a/packages/core-kernel/src/services/attributes/service-provider.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Identifiers } from "../../ioc"; -import { ServiceProvider as BaseServiceProvider } from "../../providers"; -import { AttributeService } from "./attribute-service"; - -export class ServiceProvider extends BaseServiceProvider { - /** - * Register the service provider. - * - * @returns {Promise} - * @memberof ServiceProvider - */ - public async register(): Promise { - this.app - .bind(Identifiers.AttributeService) - .to(AttributeService) - .inSingletonScope(); - } -}