Skip to content

Commit

Permalink
chore: leave comments for things that need reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian authored and Brian Faust committed Oct 7, 2019
1 parent 6645c13 commit a60734a
Show file tree
Hide file tree
Showing 119 changed files with 185 additions and 46 deletions.
1 change: 1 addition & 0 deletions packages/core-api/src/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Managers, Utils } from "@arkecosystem/crypto";
import { Ajv } from "ajv";
import * as ipAddress from "ip";

// todo: review the implementation - still needed at all or some unused?
export const registerFormats = (ajv: Ajv) => {
ajv.addFormat("address", {
type: "string",
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/blockchain/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Hapi from "@hapi/hapi";

import { Controller } from "../shared/controller";

// todo: remove the abstract and use dependency injection if needed
export class BlockchainController extends Controller {
public async index(request: Hapi.Request, h: Hapi.ResponseToolkit) {
try {
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/blocks/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Hapi from "@hapi/hapi";

import { Controller } from "../shared/controller";

// todo: remove the abstract and use dependency injection if needed
export class BlocksController extends Controller {
public async index(request: Hapi.Request, h: Hapi.ResponseToolkit) {
try {
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/blocks/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { app, Container, Contracts, Utils as AppUtils } from "@arkecosystem/core-kernel";
import { Interfaces, Utils } from "@arkecosystem/crypto";

// todo: review the implementation
export const transformBlock = (model, transform) => {
if (!transform) {
model.reward = Utils.BigNumber.make(model.reward).toFixed();
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/delegates/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Hapi from "@hapi/hapi";

import { Controller } from "../shared/controller";

// todo: remove the abstract and use dependency injection if needed
export class DelegatesController extends Controller {
public async index(request: Hapi.Request, h: Hapi.ResponseToolkit) {
try {
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/delegates/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Contracts, Utils as AppUtils } from "@arkecosystem/core-kernel";
import { Utils } from "@arkecosystem/crypto";

// todo: turn into class so that ioc can be used
// todo: review the implementation
export const transformDelegate = (delegate: Contracts.State.Wallet) => {
const attributes: Contracts.State.WalletDelegateAttributes = delegate.getAttribute("delegate");

Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/node/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Hapi from "@hapi/hapi";

import { Controller } from "../shared/controller";

// todo: remove the abstract and use dependency injection if needed
export class NodeController extends Controller {
public async status(request: Hapi.Request, h: Hapi.ResponseToolkit) {
try {
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/peers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import semver from "semver";

import { Controller } from "../shared/controller";

// todo: remove the abstract and use dependency injection if needed
export class PeersController extends Controller {
public async index(request: Hapi.Request, h: Hapi.ResponseToolkit) {
// todo: inject from container
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/peers/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { app } from "@arkecosystem/core-kernel";

// todo: review the implementation
export const transformPeer = model => {
return {
ip: model.ip,
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/rounds/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Hapi from "@hapi/hapi";

import { Controller } from "../shared/controller";

// todo: remove the abstract and use dependency injection if needed
export class RoundsController extends Controller {
public async delegates(request: Hapi.Request, h: Hapi.ResponseToolkit) {
try {
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/rounds/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Utils } from "@arkecosystem/crypto";

// todo: review the implementation
export const transformRoundDelegate = model => {
return {
publicKey: model.publicKey,
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/shared/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
toResource,
} from "../utils";

// todo: remove this class and expose helpers as functions
export class Controller {
// todo: remove
protected readonly config = Managers.configManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export const pagination = {
limit: Joi.number()
.integer()
.min(1),
// @fixme: the container is not available at the time this file is loaded
// todo: the container is not available at the time this file is loaded
// .max(app.get<any>("api.options").get("plugins.pagination.limit")),
};
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/transactions/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Hapi from "@hapi/hapi";

import { Controller } from "../shared/controller";

// todo: remove the abstract and use dependency injection if needed
export class TransactionsController extends Controller {
// todo: inject from container
private readonly transactionPool = app.get<Contracts.TransactionPool.Connection>(
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/transactions/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { app, Container, Contracts, Utils } from "@arkecosystem/core-kernel";
import { Interfaces, Transactions } from "@arkecosystem/crypto";

// todo: review the implementation
export const transformTransaction = (model, transform) => {
const blockchain = app.get<Contracts.Blockchain.Blockchain>(Container.Identifiers.BlockchainService);
const databaseService = app.get<Contracts.Database.DatabaseService>(Container.Identifiers.DatabaseService);
Expand Down
2 changes: 2 additions & 0 deletions packages/core-api/src/handlers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Hapi from "@hapi/hapi";

import { transformerService } from "../services/transformer";

// todo: review the implementation of all methods

export const paginate = (request: Hapi.Request): any => {
const pagination = {
// @ts-ignore
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/votes/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Hapi from "@hapi/hapi";

import { Controller } from "../shared/controller";

// todo: remove the abstract and use dependency injection if needed
export class VotesController extends Controller {
public async index(request: Hapi.Request, h: Hapi.ResponseToolkit) {
try {
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/wallets/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Hapi from "@hapi/hapi";

import { Controller } from "../shared/controller";

// todo: remove the abstract and use dependency injection if needed
export class WalletsController extends Controller {
public async index(request: Hapi.Request, h: Hapi.ResponseToolkit) {
try {
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/handlers/wallets/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Contracts } from "@arkecosystem/core-kernel";
import { Utils } from "@arkecosystem/crypto";

// todo: review the implementation
export const transformWallet = (wallet: Contracts.State.Wallet) => {
const username: string = wallet.getAttribute("delegate.username");

Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/plugins/hapi-ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Hapi from "@hapi/hapi";

const name = "hapi-ajv";

// todo: review implementation - still needed?
export const hapiAjv = {
name,
version: "1.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/plugins/set-headers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Hapi from "@hapi/hapi";

// todo: review the implementation - still needed?
export = {
name: "set-headers",
version: "1.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { badData } from "@hapi/boom";
import { Server as HapiServer, ServerInjectOptions, ServerInjectResponse, ServerRoute } from "@hapi/hapi";
import { readFileSync } from "fs";

// todo: review the implementation
@Container.injectable()
export class Server {
/**
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/services/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { app } from "@arkecosystem/core-kernel";
import { Crypto } from "@arkecosystem/crypto";
import Hapi, { ServerMethod } from "@hapi/hapi";

// todo: review the implementation
export class ServerCache {
public static make(server: Hapi.Server): ServerCache {
return new ServerCache(server);
Expand Down
19 changes: 14 additions & 5 deletions packages/core-blockchain/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,31 @@ import { stateMachine } from "./state-machine";

const { BlockFactory } = Blocks;

// todo: reduce the overall complexity of this class and remove all helpers and getters that just serve as proxies
@Container.injectable()
export class Blockchain implements Contracts.Blockchain.Blockchain {
// todo: make this private
public isStopped: boolean;
// todo: make this private
public options: any;
// todo: make this private and use a queue instance from core-kernel
public queue: async.AsyncQueue<any>;
// todo: make this private
protected blockProcessor: BlockProcessor;
// todo: add type
private actions: any;

// todo: make this private, only protected because of replay
@Container.inject(Container.Identifiers.StateStore)
protected readonly state: Contracts.State.StateStore; // todo: make this private? only protected because of replay
protected readonly state: Contracts.State.StateStore;

// todo: make this private, only protected because of replay
@Container.inject(Container.Identifiers.DatabaseService)
protected readonly database: Contracts.Database.DatabaseService; // todo: make this private? only protected because of replay
protected readonly database: Contracts.Database.DatabaseService;

// todo: make this private, only protected because of replay
@Container.inject(Container.Identifiers.TransactionPoolService)
protected readonly transactionPool: Contracts.TransactionPool.Connection; // todo: make this private? only protected because of replay
protected readonly transactionPool: Contracts.TransactionPool.Connection;

/**
* Create a new blockchain manager instance.
Expand All @@ -38,8 +47,6 @@ export class Blockchain implements Contracts.Blockchain.Blockchain {
app.log.warning(
"ARK Core is launched in Genesis Start mode. This is usually for starting the first node on the blockchain. Unless you know what you are doing, this is likely wrong.",
);

app.log.info("Starting ARK Core for a new world, welcome aboard");
}

this.actions = stateMachine.actionMap(this);
Expand All @@ -52,7 +59,9 @@ export class Blockchain implements Contracts.Blockchain.Blockchain {
app.log.error(
`Failed to process ${blockList.blocks.length} blocks from height ${blockList.blocks[0].height} in queue.`,
);

app.log.error(error.stack);

return cb();
}
}, 1);
Expand Down
1 change: 1 addition & 0 deletions packages/core-blockchain/src/machines/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Machine } from "xstate";
import { fork } from "./actions/fork";
import { syncWithNetwork } from "./actions/sync-with-network";

// todo: move this into a class based state machine that triggers actions on this
export const blockchainMachine: any = Machine({
key: "blockchain",
initial: "uninitialised",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Interfaces } from "@arkecosystem/crypto";
import { BlockProcessorResult } from "../block-processor";
import { BlockHandler } from "./block-handler";

// todo: remove the abstract and instead require a contract to be implemented
@Container.injectable()
export class AcceptBlockHandler extends BlockHandler {
@Container.inject(Container.Identifiers.LogService)
Expand Down Expand Up @@ -56,6 +57,7 @@ export class AcceptBlockHandler extends BlockHandler {
this.logger.warning(`Refused new block ${JSON.stringify(block.data)}`);
this.logger.debug(error.stack);

// todo: replace this with an actual implementation after the abstract is gone
return super.execute(block);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { Interfaces } from "@arkecosystem/crypto";
import { BlockProcessorResult } from "../block-processor";
import { BlockHandler } from "./block-handler";

// todo: remove the abstract and instead require a contract to be implemented
@Container.injectable()
export class AlreadyForgedHandler extends BlockHandler {
public async execute(block: Interfaces.IBlock): Promise<BlockProcessorResult> {
// todo: replace this with an actual implementation after the abstract is gone
await super.execute(block);

return BlockProcessorResult.DiscardedButCanBeBroadcasted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Interfaces } from "@arkecosystem/crypto";

import { BlockProcessorResult } from "../block-processor";

// todo: remove this abstract and require a contract to be implemented by children instead
@Container.injectable()
export abstract class BlockHandler {
@Container.inject(Container.Identifiers.BlockchainService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BlockProcessorResult } from "../block-processor";
import { AcceptBlockHandler } from "./accept-block-handler";
import { BlockHandler } from "./block-handler";

// todo: remove the abstract and instead require a contract to be implemented
@Container.injectable()
export class ExceptionHandler extends BlockHandler {
@Container.inject(Container.Identifiers.LogService)
Expand All @@ -18,6 +19,7 @@ export class ExceptionHandler extends BlockHandler {
const forgedBlock: Interfaces.IBlock = await this.database.getBlock(block.data.id);

if (forgedBlock) {
// todo: replace this with an actual implementation after the abstract is gone
return super.execute(block);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { Container } from "@arkecosystem/core-kernel";

import { BlockHandler } from "./block-handler";

// todo: remove the abstract and instead require a contract to be implemented
@Container.injectable()
export class InvalidGeneratorHandler extends BlockHandler {}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class BlockNotReadyCounter {
}
}

// todo: remove the abstract and instead require a contract to be implemented
export class UnchainedHandler extends BlockHandler {
public static notReadyCounter = new BlockNotReadyCounter();

Expand All @@ -57,6 +58,7 @@ export class UnchainedHandler extends BlockHandler {

private isValidGenerator: boolean;

// todo: remove the need for this method
public init(isValidGenerator: boolean): this {
this.isValidGenerator = isValidGenerator;

Expand Down Expand Up @@ -104,6 +106,7 @@ export class UnchainedHandler extends BlockHandler {
private checkUnchainedBlock(block: Interfaces.IBlock): UnchainedBlockStatus {
const lastBlock: Interfaces.IBlock = this.blockchain.getLastBlock();

// todo: clean up this if-else-if-else-if-else mess
if (block.data.height > lastBlock.data.height + 1) {
this.logger.debug(
`Blockchain not ready to accept new block at height ${block.data.height.toLocaleString()}. Last block: ${lastBlock.data.height.toLocaleString()}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { Container } from "@arkecosystem/core-kernel";

import { BlockHandler } from "./block-handler";

// todo: remove the abstract and instead require a contract to be implemented
@Container.injectable()
export class VerificationFailedHandler extends BlockHandler {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DatabaseService } from "@arkecosystem/core-database";
import { Contracts } from "@arkecosystem/core-kernel";
import { Interfaces } from "@arkecosystem/crypto";

// todo: review the implementation
export class MemoryDatabaseService extends DatabaseService {
public constructor(public walletRepository: Contracts.State.WalletRepository) {
super(undefined, undefined, undefined, undefined, undefined, undefined, undefined);
Expand Down
1 change: 1 addition & 0 deletions packages/core-blockchain/src/replay/replay-blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Blockchain } from "../blockchain";
import { FailedToReplayBlocksError } from "./errors";
import { MemoryDatabaseService } from "./memory-database-service";

// todo: review the implementation
export class ReplayBlockchain extends Blockchain {
private logger: Contracts.Kernel.Log.Logger;
private localDatabase: Contracts.Database.DatabaseService;
Expand Down
1 change: 1 addition & 0 deletions packages/core-blockchain/src/utils/validate-generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { app, Container, Contracts, Utils } from "@arkecosystem/core-kernel";
import { Crypto, Interfaces } from "@arkecosystem/crypto";

// todo: review the implementation
export const validateGenerator = async (block: Interfaces.IBlock): Promise<boolean> => {
const database: Contracts.Database.DatabaseService = app.get<Contracts.Database.DatabaseService>(
Container.Identifiers.DatabaseService,
Expand Down
1 change: 1 addition & 0 deletions packages/core-database-postgres/src/service-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Wallets } from "@arkecosystem/core-state";

import { PostgresConnection } from "./postgres-connection";

// todo: review the implementation
export class ServiceProvider extends Providers.ServiceProvider {
public async register(): Promise<void> {
this.app.log.info("Establishing Database Connection");
Expand Down
1 change: 1 addition & 0 deletions packages/core-database-postgres/src/state-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { app, Container, Contracts, Enums } from "@arkecosystem/core-kernel";
import { Handlers } from "@arkecosystem/core-transactions";
import { Interfaces, Managers, Utils } from "@arkecosystem/crypto";

// todo: review the implementation
export class StateBuilder {
private readonly logger: Contracts.Kernel.Log.Logger = app.log;
private readonly emitter: Contracts.Kernel.Events.EventDispatcher = app.get<
Expand Down
3 changes: 2 additions & 1 deletion packages/core-database/src/block-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { Wallets } from "@arkecosystem/core-state";
import { Handlers, Interfaces as TransactionInterfaces } from "@arkecosystem/core-transactions";
import { Enums, Identities, Interfaces, Utils } from "@arkecosystem/crypto";

// @todo: ioc
// todo: review the implementation and make use of ioc
@Container.injectable()
export class BlockState {
private walletRepository: Contracts.State.WalletRepository;

// todo: remove the need for this method
public init(walletRepository: Contracts.State.WalletRepository): this {
this.walletRepository = walletRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getProperty } from "./get-property";
* @param {Object} filters
* @return {Array}
*/
// todo: review implementation - quite a mess at the moment
export = (rows: ReadonlyArray<Contracts.State.Wallet>, params, filters): Contracts.State.Wallet[] => {
return rows.filter(item => {
if (filters.hasOwnProperty("exact")) {
Expand Down
Loading

0 comments on commit a60734a

Please sign in to comment.