Skip to content

Commit

Permalink
refactor: rename core-interfaces to prefix an 'I'
Browse files Browse the repository at this point in the history
fix: shared.Config class having buggy 'init' method
  • Loading branch information
paroxysm committed Jan 2, 2019
1 parent ae1effe commit 38a31a9
Show file tree
Hide file tree
Showing 107 changed files with 356 additions and 244 deletions.
8 changes: 4 additions & 4 deletions packages/core-api/src/index.ts
Expand Up @@ -6,9 +6,9 @@ export const plugin : Container.PluginDescriptor = {
pkg: require("../package.json"),
defaults,
alias: "api",
async register(container: Container.Container, options) {
async register(container: Container.IContainer, options) {
if (!options.enabled) {
container.resolvePlugin<Logger.Logger>("logger").info("Public API is disabled :grey_exclamation:");
container.resolvePlugin<Logger.ILogger>("logger").info("Public API is disabled :grey_exclamation:");

return false;
}
Expand All @@ -18,9 +18,9 @@ export const plugin : Container.PluginDescriptor = {

return server;
},
async deregister(container: Container.Container, options) {
async deregister(container: Container.IContainer, options) {
if (options.enabled) {
container.resolvePlugin<Logger.Logger>("logger").info(`Stopping Public API`);
container.resolvePlugin<Logger.ILogger>("logger").info(`Stopping Public API`);

return container.resolvePlugin("api").stop();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core-api/src/repositories/repository.ts
Expand Up @@ -7,7 +7,7 @@ import { IRepository } from "../interfaces/repository";
export abstract class Repository implements IRepository {
public database = app.resolvePlugin<PostgresConnection>("database");
public cache = this.database.getCache();
public transactionPool = app.resolvePlugin<TransactionPool.TransactionPool>("transactionPool");
public transactionPool = app.resolvePlugin<TransactionPool.ITransactionPool>("transactionPool");
public model = this.getModel();
public query = this.model.query();
public columns: string[] = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/core-api/src/versions/1/blocks/transformer.ts
Expand Up @@ -3,7 +3,7 @@ import { Blockchain } from "@arkecosystem/core-interfaces";
import { bignumify } from "@arkecosystem/core-utils";

export function transformBlockLegacy(model) {
const lastBlock = app.resolvePlugin<Blockchain.Blockchain>("blockchain").getLastBlock();
const lastBlock = app.resolvePlugin<Blockchain.IBlockchain>("blockchain").getLastBlock();

return {
id: model.id,
Expand Down
2 changes: 1 addition & 1 deletion packages/core-api/src/versions/1/delegates/schema.ts
@@ -1,7 +1,7 @@
import { app } from "@arkecosystem/core-container";
import { Blockchain } from "@arkecosystem/core-interfaces";

const lastBlock = app.resolvePlugin<Blockchain.Blockchain>("blockchain").getLastBlock();
const lastBlock = app.resolvePlugin<Blockchain.IBlockchain>("blockchain").getLastBlock();

export const forgingStatus: object = {
type: "object",
Expand Down
4 changes: 2 additions & 2 deletions packages/core-api/src/versions/1/peers/controller.ts
Expand Up @@ -5,12 +5,12 @@ import Hapi from "hapi";
import { Controller } from "../shared/controller";

export class PeersController extends Controller {
protected p2p: P2P.Monitor;
protected p2p: P2P.IMonitor;

public constructor() {
super();

this.p2p = app.resolvePlugin<P2P.Monitor>("p2p");
this.p2p = app.resolvePlugin<P2P.IMonitor>("p2p");
}

public async index(request: Hapi.Request, h: Hapi.ResponseToolkit) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core-api/src/versions/1/shared/controller.ts
Expand Up @@ -6,9 +6,9 @@ import { paginate, respondWith, respondWithCache, toCollection, toResource } fro

export class Controller {
protected config = app.getConfig();
protected blockchain = app.resolvePlugin<Blockchain.Blockchain>("blockchain");
protected blockchain = app.resolvePlugin<Blockchain.IBlockchain>("blockchain");
protected database = app.resolvePlugin<PostgresConnection>("database");
protected logger = app.resolvePlugin<Logger.Logger>("logger");
protected logger = app.resolvePlugin<Logger.ILogger>("logger");

protected paginate(request: Hapi.Request): any {
return paginate(request);
Expand Down
Expand Up @@ -5,7 +5,7 @@ import Hapi from "hapi";
import { Controller } from "../shared/controller";

export class TransactionsController extends Controller {
protected transactionPool = app.resolvePlugin<TransactionPool.TransactionPool>("transactionPool");
protected transactionPool = app.resolvePlugin<TransactionPool.ITransactionPool>("transactionPool");

public constructor() {
super();
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { crypto, models } from "@arkecosystem/crypto";

export function transformTransactionLegacy(model) {
const config = app.getConfig();
const blockchain = app.resolvePlugin<Blockchain.Blockchain>("blockchain");
const blockchain = app.resolvePlugin<Blockchain.IBlockchain>("blockchain");

const data: any = new models.Transaction(model.serialized.toString("hex"));

Expand Down
2 changes: 1 addition & 1 deletion packages/core-api/src/versions/2/peers/controller.ts
Expand Up @@ -69,7 +69,7 @@ export class PeersController extends Controller {

public async suspended(request: Hapi.Request, h: Hapi.ResponseToolkit) {
try {
const peers = app.resolvePlugin<P2P.Monitor>("p2p").getSuspendedPeers();
const peers = app.resolvePlugin<P2P.IMonitor>("p2p").getSuspendedPeers();

return super.respondWithCollection(
request,
Expand Down
2 changes: 1 addition & 1 deletion packages/core-api/src/versions/2/shared/controller.ts
Expand Up @@ -15,7 +15,7 @@ import {

export class Controller {
protected config = app.getConfig();
protected blockchain = app.resolvePlugin<Blockchain.Blockchain>("blockchain");
protected blockchain = app.resolvePlugin<Blockchain.IBlockchain>("blockchain");
protected database = app.resolvePlugin<PostgresConnection>("database");

protected paginate(request: Hapi.Request): any {
Expand Down
8 changes: 4 additions & 4 deletions packages/core-api/src/versions/2/transactions/controller.ts
Expand Up @@ -4,11 +4,11 @@ import Boom from "boom";
import Hapi from "hapi";
import { Controller } from "../shared/controller";

import { TransactionGuardImpl, TransactionPoolImpl } from "@arkecosystem/core-transaction-pool";
import { TransactionGuard, TransactionPool } from "@arkecosystem/core-transaction-pool";
import { constants } from "@arkecosystem/crypto";

export class TransactionsController extends Controller {
private transactionPool = app.resolvePlugin<TransactionPoolImpl>("transactionPool");
private transactionPool = app.resolvePlugin<TransactionPool>("transactionPool");

public constructor() {
super();
Expand All @@ -30,12 +30,12 @@ export class TransactionsController extends Controller {
return Boom.serverUnavailable("Transaction pool is disabled.");
}

const guard = new TransactionGuardImpl(this.transactionPool);
const guard = new TransactionGuard(this.transactionPool);

const result = await guard.validate(request.payload.transactions);

if (result.broadcast.length > 0) {
app.resolvePlugin<P2P.Monitor>("p2p").broadcastTransactions(guard.getBroadcastTransactions());
app.resolvePlugin<P2P.IMonitor>("p2p").broadcastTransactions(guard.getBroadcastTransactions());
}

return {
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { crypto, models } from "@arkecosystem/crypto";

export function transformTransaction(model) {
const config = app.getConfig();
const blockchain = app.resolvePlugin<Blockchain.Blockchain>("blockchain");
const blockchain = app.resolvePlugin<Blockchain.IBlockchain>("blockchain");

const data: any = new models.Transaction(model.serialized.toString("hex"));
const lastBlock = blockchain.getLastBlock();
Expand Down
6 changes: 3 additions & 3 deletions packages/core-blockchain/__tests__/blockchain.test.ts
Expand Up @@ -8,8 +8,8 @@ import { asValue } from "awilix";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import delay from "delay";
import { BlockchainImpl } from "../src/blockchain";
import { defaults } from "../src/defaults";
import { Blockchain } from "../dist/blockchain";
import { defaults } from "../dist/defaults";
import { setUp, tearDown } from "./__support__/setup";

const axiosMock = new MockAdapter(axios);
Expand All @@ -18,7 +18,7 @@ const { Block, Wallet } = models;
let genesisBlock;
let configManager;
let container;
let blockchain: BlockchainImpl;
let blockchain: Blockchain;
let logger;
let loggerDebugBackup;
let peerMock;
Expand Down
4 changes: 2 additions & 2 deletions packages/core-blockchain/__tests__/state-machine.test.ts
@@ -1,11 +1,11 @@
import "@arkecosystem/core-test-utils";
import { asValue } from "awilix";
import { BlockchainImpl } from "../src/blockchain";
import { Blockchain } from "../src/blockchain";
import { setUp, tearDown } from "./__support__/setup";

let stateMachine;
let container;
let blockchain: BlockchainImpl;
let blockchain: Blockchain;

beforeAll(async () => {
container = await setUp();
Expand Down
12 changes: 6 additions & 6 deletions packages/core-blockchain/src/blockchain.ts
@@ -1,20 +1,20 @@
/* tslint:disable:max-line-length */
import { app } from "@arkecosystem/core-container";
import { PostgresConnection } from "@arkecosystem/core-database-postgres";
import { Blockchain, EventEmitter, Logger, P2P, TransactionPool } from "@arkecosystem/core-interfaces";
import { Blockchain as blockchain, EventEmitter, Logger, P2P, TransactionPool } from "@arkecosystem/core-interfaces";
import { models, slots } from "@arkecosystem/crypto";

import delay from "delay";
import pluralize from "pluralize";
import { ProcessQueue, Queue, RebuildQueue } from "./queue";
import { stateMachine } from "./state-machine";

const logger = app.resolvePlugin<Logger.Logger>("logger");
const logger = app.resolvePlugin<Logger.ILogger>("logger");
const config = app.getConfig();
const emitter = app.resolvePlugin<EventEmitter.EventEmitter>("event-emitter");
const { Block } = models;

export class BlockchainImpl implements Blockchain.Blockchain {
export class Blockchain implements blockchain.IBlockchain {
public isStopped: boolean;
public options: any;
public processQueue: ProcessQueue;
Expand Down Expand Up @@ -664,7 +664,7 @@ export class BlockchainImpl implements Blockchain.Blockchain {

/**
* Get the state of the blockchain.
* @return {StateStorage}
* @return {IStateStorage}
*/
get state() {
return stateMachine.state;
Expand All @@ -675,15 +675,15 @@ export class BlockchainImpl implements Blockchain.Blockchain {
* @return {P2PInterface}
*/
get p2p() {
return app.resolvePlugin<P2P.Monitor>("p2p");
return app.resolvePlugin<P2P.IMonitor>("p2p");
}

/**
* Get the transaction handler.
* @return {TransactionPool}
*/
get transactionPool() {
return app.resolvePlugin<TransactionPool.TransactionPool>("transactionPool");
return app.resolvePlugin<TransactionPool.ITransactionPool>("transactionPool");
}

/**
Expand Down
14 changes: 7 additions & 7 deletions packages/core-blockchain/src/index.ts
@@ -1,6 +1,6 @@
import { Blockchain, Container } from "@arkecosystem/core-interfaces";
import { Container } from "@arkecosystem/core-interfaces";
import { asValue } from "awilix";
import { BlockchainImpl } from "./blockchain";
import { Blockchain } from "./blockchain";
import { config } from "./config";
import { defaults } from "./defaults";
import { stateStorage } from "./state-storage";
Expand All @@ -13,8 +13,8 @@ export const plugin : Container.PluginDescriptor = {
pkg: require("../package.json"),
defaults,
alias: "blockchain",
async register(container: Container.Container, options) {
const blockchain = new BlockchainImpl(options);
async register(container: Container.IContainer, options) {
const blockchain = new Blockchain(options);

config.init(options);

Expand All @@ -26,13 +26,13 @@ export const plugin : Container.PluginDescriptor = {

return blockchain;
},
async deregister(container: Container.Container, options) {
await container.resolvePlugin<Blockchain.Blockchain>("blockchain").stop();
async deregister(container: Container.IContainer, options) {
await container.resolvePlugin<Blockchain>("blockchain").stop();
},
};

/**
* Access to the state.
* @type {StateStorage}
* @type {IStateStorage}
*/
export { stateStorage };
2 changes: 1 addition & 1 deletion packages/core-blockchain/src/queue/index.ts
Expand Up @@ -10,7 +10,7 @@ export class Queue {

/**
* Create an instance of the queue.
* @param {BlockchainImpl} blockchain
* @param {Blockchain} blockchain
* @param {Object} events
* @return {void}
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/core-blockchain/src/queue/interface.ts
Expand Up @@ -5,7 +5,7 @@ export abstract class QueueInterface {

/**
* Create an instance of the process queue.
* @param {BlockchainImpl} blockchain
* @param {Blockchain} blockchain
* @param {String} event
* @return {void}
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/core-blockchain/src/queue/process.ts
Expand Up @@ -4,13 +4,13 @@ import { models } from "@arkecosystem/crypto";
import async from "async";
import { QueueInterface } from "./interface";

const logger = app.resolvePlugin<Logger.Logger>("logger");
const logger = app.resolvePlugin<Logger.ILogger>("logger");
const { Block } = models;

export class ProcessQueue extends QueueInterface {
/**
* Create an instance of the process queue.
* @param {BlockchainImpl} blockchain
* @param {Blockchain} blockchain
* @return {void}
*/
constructor(blockchain, event) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core-blockchain/src/queue/rebuild.ts
Expand Up @@ -4,13 +4,13 @@ import { models } from "@arkecosystem/crypto";
import async from "async";
import { QueueInterface } from "./interface";

const logger = app.resolvePlugin<Logger.Logger>("logger");
const logger = app.resolvePlugin<Logger.ILogger>("logger");
const { Block } = models;

export class RebuildQueue extends QueueInterface {
/**
* Create an instance of the process queue.
* @param {BlockchainImpl} blockchain
* @param {Blockchain} blockchain
* @return {void}
*/
constructor(blockchain, event) {
Expand Down
10 changes: 5 additions & 5 deletions packages/core-blockchain/src/state-machine.ts
Expand Up @@ -12,24 +12,24 @@ import { blockchainMachine } from "./machines/blockchain";
import { stateStorage } from "./state-storage";
import { tickSyncTracker } from "./utils/tick-sync-tracker";

import { BlockchainImpl } from "./blockchain";
import { Blockchain } from "./blockchain";

const { Block } = models;
const config = app.getConfig();
const emitter = app.resolvePlugin<EventEmitter.EventEmitter>("event-emitter");
const logger = app.resolvePlugin<Logger.Logger>("logger");
const logger = app.resolvePlugin<Logger.ILogger>("logger");

/**
* @type {StateStorage}
* @type {IStateStorage}
*/
blockchainMachine.state = stateStorage;

/**
* The blockchain actions.
* @param {BlockchainImpl} blockchain
* @param {Blockchain} blockchain
* @return {Object}
*/
blockchainMachine.actionMap = (blockchain: BlockchainImpl) => ({
blockchainMachine.actionMap = (blockchain: Blockchain) => ({
blockchainReady: () => {
if (!stateStorage.started) {
stateStorage.started = true;
Expand Down
2 changes: 1 addition & 1 deletion packages/core-blockchain/src/state-storage.ts
Expand Up @@ -9,7 +9,7 @@ import { config } from "./config";
import { blockchainMachine } from "./machines/blockchain";

const { Block } = models;
const logger = app.resolvePlugin<Logger.Logger>("logger");
const logger = app.resolvePlugin<Logger.ILogger>("logger");

// Stores the last n blocks in ascending height. The amount of last blocks
// can be configured with the option `state.maxLastBlocks`.
Expand Down
4 changes: 2 additions & 2 deletions packages/core-blockchain/src/utils/tick-sync-tracker.ts
Expand Up @@ -2,14 +2,14 @@ import { app } from "@arkecosystem/core-container";
import { Logger, P2P } from "@arkecosystem/core-interfaces";
import prettyMs from "pretty-ms";

const logger = app.resolvePlugin<Logger.Logger>("logger");
const logger = app.resolvePlugin<Logger.ILogger>("logger");
let tracker = null;

export function tickSyncTracker(blockCount, count) {
if (!tracker) {
tracker = {
start: new Date().getTime(),
networkHeight: app.resolvePlugin<P2P.Monitor>("p2p").getNetworkHeight(),
networkHeight: app.resolvePlugin<P2P.IMonitor>("p2p").getNetworkHeight(),
blocksInitial: +count,
blocksDownloaded: +count,
blocksSession: 0,
Expand Down
4 changes: 2 additions & 2 deletions packages/core-container/__tests__/registrars/plugin.test.ts
@@ -1,7 +1,7 @@
import "jest-extended";

import { resolve } from "path";
import { ContainerImpl } from "../../src/container";
import { Container } from "../../src/container";
import { PluginRegistrar } from "../../src/registrars/plugin";

const stubPluginPath = resolve(__dirname, "../__stubs__");
Expand All @@ -10,7 +10,7 @@ let instance;
beforeEach(() => {
process.env.ARK_PATH_CONFIG = stubPluginPath;

instance = new PluginRegistrar(new ContainerImpl());
instance = new PluginRegistrar(new Container());
});

describe("Plugin Registrar", () => {
Expand Down

0 comments on commit 38a31a9

Please sign in to comment.