Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ jobs:
name: core-logger-winston
command: 'cd ~/ark-core/packages/core-logger-winston && yarn test:coverage'
- run:
name: core-graphql
command: 'cd ~/ark-core/packages/core-graphql && yarn test:coverage'
name: core-api
command: 'cd ~/ark-core/packages/core-api && yarn test:coverage'
- run:
name: core-debugger-cli
command: 'cd ~/ark-core/packages/core-debugger-cli && yarn test:coverage'
- run:
name: core-container
command: 'cd ~/ark-core/packages/core-container && yarn test:coverage'
- run:
name: core
command: 'cd ~/ark-core/packages/core && yarn test:coverage'
name: core-graphql
command: 'cd ~/ark-core/packages/core-graphql && yarn test:coverage'
- run:
name: Last 1000 lines of test output
when: on_fail
Expand Down Expand Up @@ -164,17 +164,17 @@ jobs:
name: core-logger-winston
command: 'cd ~/ark-core/packages/core-logger-winston && yarn test:coverage'
- run:
name: core-graphql
command: 'cd ~/ark-core/packages/core-graphql && yarn test:coverage'
name: core-api
command: 'cd ~/ark-core/packages/core-api && yarn test:coverage'
- run:
name: core-debugger-cli
command: 'cd ~/ark-core/packages/core-debugger-cli && yarn test:coverage'
- run:
name: core-container
command: 'cd ~/ark-core/packages/core-container && yarn test:coverage'
- run:
name: core
command: 'cd ~/ark-core/packages/core && yarn test:coverage'
name: core-graphql
command: 'cd ~/ark-core/packages/core-graphql && yarn test:coverage'
- run:
name: Last 1000 lines of test output
when: on_fail
Expand Down Expand Up @@ -343,8 +343,8 @@ jobs:
name: core-database
command: 'cd ~/ark-core/packages/core-database && yarn test:coverage'
- run:
name: core-api
command: 'cd ~/ark-core/packages/core-api && yarn test:coverage'
name: core
command: 'cd ~/ark-core/packages/core && yarn test:coverage'
- run:
name: Last 1000 lines of test output
when: on_fail
Expand Down Expand Up @@ -601,8 +601,8 @@ jobs:
name: core-database
command: 'cd ~/ark-core/packages/core-database && yarn test:coverage'
- run:
name: core-api
command: 'cd ~/ark-core/packages/core-api && yarn test:coverage'
name: core
command: 'cd ~/ark-core/packages/core && yarn test:coverage'
- run:
name: Last 1000 lines of test output
when: on_fail
Expand Down
8 changes: 6 additions & 2 deletions packages/core-database-postgres/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ import { camelizeColumns } from "./utils";
const { Block, Transaction } = models;

export class PostgresConnection extends ConnectionInterface {
public models: {};
public query: QueryExecutor;
private db: any;
private cache: Map<any, any>;
private models: {};
private query: QueryExecutor;
private pgp: any;
private spvFinished: boolean;

public constructor(readonly options: any) {
super(options);
}

/**
* Make the database connection instance.
* @return {PostgresConnection}
Expand Down
3 changes: 2 additions & 1 deletion packages/core-database-postgres/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Container } from "@arkecosystem/core-container";
import { DatabaseManager } from "@arkecosystem/core-database";
import { AbstractLogger } from "@arkecosystem/core-logger";
import { PostgresConnection } from "./connection";
import { defaults } from "./defaults";
Expand All @@ -18,7 +19,7 @@ export const plugin = {

const postgres = new PostgresConnection(options);

const databaseManager = container.resolvePlugin("databaseManager");
const databaseManager = container.resolvePlugin<DatabaseManager>("databaseManager");
await databaseManager.makeConnection(postgres);

return databaseManager.connection();
Expand Down
16 changes: 6 additions & 10 deletions packages/core-database-postgres/src/spv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { Transaction } = models;

import { app } from "@arkecosystem/core-container";
import { AbstractLogger } from "@arkecosystem/core-logger";
import {PostgresConnection} from "./connection";
import { queries } from "./queries";

const logger = app.resolvePlugin<AbstractLogger>("logger");
Expand All @@ -17,16 +18,11 @@ export class SPV {
private query: any;
private activeDelegates: [];

/**
* Create a new wallet builder instance.
* @param {SequelizeConnection} database
* @return {void}
*/
constructor(database) {
this.connection = database.connection;
this.models = database.models;
this.walletManager = database.walletManager;
this.query = database.query;
constructor(connectionInterface : PostgresConnection) {
this.connection = connectionInterface.connection;
this.models = connectionInterface.models;
this.walletManager = connectionInterface.walletManager;
this.query = connectionInterface.query;
}

/**
Expand Down
11 changes: 10 additions & 1 deletion packages/core-database/__tests__/__fixtures__/dummy-class.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// tslint:disable:no-empty

import { ConnectionInterface } from "../../src/interface";
import { ConnectionInterface } from "../../src";

export class DummyConnection extends ConnectionInterface {

constructor(options: any) {
super(options);
}

public async connect(): Promise<void> {}

public async disconnect(): Promise<void> {}
Expand Down Expand Up @@ -60,4 +65,8 @@ export class DummyConnection extends ConnectionInterface {
public async getTransaction(id): Promise<any> {
return true;
}

public async make(): Promise<ConnectionInterface> {
return this;
}
}
3 changes: 2 additions & 1 deletion packages/core-database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"Brian Faust <brian@ark.io>"
],
"license": "MIT",
"main": "dist/index.js",
"main": "dist/index",
"types": "dist/index",
"files": [
"dist"
],
Expand Down
39 changes: 6 additions & 33 deletions packages/core-database/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
import { Container } from "@arkecosystem/core-container";
import { AbstractLogger } from "@arkecosystem/core-logger";
import { defaults } from "./defaults";
import { DatabaseManager } from "./manager";

/**
* The interface used by concrete implementations.
* @type {ConnectionInterface}
*/
import { ConnectionInterface } from "./interface";

/**
* The Wallet Manager.
* @type {WalletManager}
*/
import { WalletManager } from "./wallet-manager";

/**
* The struct used by the plugin container.
* @type {Object}
*/
export const plugin = {
pkg: require("../package.json"),
defaults,
alias: "databaseManager",
async register(container: Container, options) {
container.resolvePlugin<AbstractLogger>("logger").info("Starting Database Manager");

return new DatabaseManager();
},
};

export { ConnectionInterface, WalletManager };
export * from "./manager";
export * from "./interface";
export * from "./wallet-manager";
export * from "./repositories/delegates";
export * from "./repositories/wallets";
export * from "./plugin";
33 changes: 13 additions & 20 deletions packages/core-database/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,34 @@ const { Block } = models;
const { TransactionTypes } = constants;

export abstract class ConnectionInterface {
// TODO: Convert these to protected/private and provide the appropriate get/setters
public config: any;
public logger: AbstractLogger;
public emitter: any;

public connection: any;
public blocksInCurrentRound: any[];
public stateStarted: boolean;
public restoredDatabaseIntegrity: boolean;
public walletManager: WalletManager;
public forgingDelegates: any[];
public wallets: WalletsRepository;
public delegates: DelegatesRepository;
protected queuedQueries: any[];
public connection: any = null;
public blocksInCurrentRound: any[] = null;
public stateStarted: boolean = false;
public restoredDatabaseIntegrity: boolean = false;
public walletManager: WalletManager = null;
public forgingDelegates: any[] = null;
public wallets: WalletsRepository = null;
public delegates: DelegatesRepository = null;
public queuedQueries: any[] = null;

/**
* @constructor
* @param {Object} options
*/
public constructor(public readonly options) {
protected constructor(public readonly options: any) {
this.config = app.getConfig();
this.logger = app.resolvePlugin<AbstractLogger>("logger");
this.emitter = app.resolvePlugin("event-emitter");

this.connection = null;
this.blocksInCurrentRound = null;
this.stateStarted = false;
this.restoredDatabaseIntegrity = false;
this.walletManager = null;
this.wallets = null;
this.delegates = null;
this.queuedQueries = null;

this.__registerListeners();
}

public abstract async make(): Promise<ConnectionInterface>;

/**
* Get the current connection.
* @return {ConnectionInterface}
Expand Down
8 changes: 5 additions & 3 deletions packages/core-database/src/manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ConnectionInterface } from "./interface";

export class DatabaseManager {
public connections: { [key: string]: any };
public connections: { [key: string]: ConnectionInterface };

/**
* Create a new database manager instance.
Expand All @@ -14,7 +16,7 @@ export class DatabaseManager {
* @param {String} name
* @return {ConnectionInterface}
*/
public connection(name = "default") {
public connection(name = "default"): ConnectionInterface {
return this.connections[name];
}

Expand All @@ -24,7 +26,7 @@ export class DatabaseManager {
* @param {String} name
* @return {void}
*/
public async makeConnection(connection, name = "default") {
public async makeConnection(connection: ConnectionInterface, name = "default") {
this.connections[name] = await connection.make();
}
}
15 changes: 15 additions & 0 deletions packages/core-database/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Container } from "@arkecosystem/core-container";
import { AbstractLogger } from "@arkecosystem/core-logger";
import { defaults } from "./defaults";
import { DatabaseManager } from "./manager";

export const plugin = {
pkg: require("../package.json"),
defaults,
alias: "databaseManager",
async register(container: Container, options) {
container.resolvePlugin<AbstractLogger>("logger").info("Starting Database Manager");

return new DatabaseManager();
},
};