Skip to content

Commit

Permalink
Merge branch 'develop' into feat/batch-block-db
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian authored Apr 29, 2019
2 parents 277d9e2 + eeab766 commit c59d771
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bootstrap": "yarn lerna bootstrap",
"clean": "yarn lerna clean --yes",
"build": "yarn lerna run build",
"lint": "./node_modules/tslint/bin/tslint -c ./tslint.json './packages/**/*/src/**/*.ts' --fix",
"lint": "./node_modules/tslint/bin/tslint -c ./tslint.json --project tsconfig.json './packages/**/*/src/**/*.ts' --fix",
"format": "yarn lint && yarn prettier",
"prettier": "prettier --write \"./*.{ts,js,json,md}\" \"./packages/**/*.{ts,js,json,md}\" \"./__tests__/**/*.{ts,js,json,md}\"",
"lint:tests": "./node_modules/tslint/bin/tslint -c ./tslint.json '__tests__/**/*.ts' --fix",
Expand Down
28 changes: 14 additions & 14 deletions packages/core-p2p/src/utils/is-valid-peer.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
import { parse, process } from "ipaddr.js";
import os from "os";

export const isValidPeer = (peer: { ip: string; status?: string | number }): boolean => {
peer.ip = sanitizeRemoteAddress(peer.ip);

if (!peer.ip) {
return false;
}

if (isLocalHost(peer.ip)) {
return false;
}

return true;
};

export const isLocalHost = (ip: string): boolean => {
try {
const parsed = parse(ip);
Expand Down Expand Up @@ -47,3 +33,17 @@ const sanitizeRemoteAddress = (ip: string): string | null => {
return null;
}
};

export const isValidPeer = (peer: { ip: string; status?: string | number }): boolean => {
peer.ip = sanitizeRemoteAddress(peer.ip);

if (!peer.ip) {
return false;
}

if (isLocalHost(peer.ip)) {
return false;
}

return true;
};
6 changes: 4 additions & 2 deletions packages/core/src/process-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ProcessManager {

public status(name: string): ProcessState {
try {
return processManager.describe(name).pm2_env.status;
return this.describe(name).pm2_env.status;
} catch (error) {
return undefined;
}
Expand Down Expand Up @@ -77,7 +77,9 @@ class ProcessManager {
try {
const { stdout } = shellSync("pm2 jlist");

return Object.values(JSON.parse(stdout.split("\n").pop())).filter((p: ProcessDescription) => p.name.startsWith(token));
return Object.values(JSON.parse(stdout.split("\n").pop())).filter((p: ProcessDescription) =>
p.name.startsWith(token),
);
} catch (error) {
return undefined;
}
Expand Down
46 changes: 23 additions & 23 deletions packages/crypto/src/transactions/types/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import deepmerge = require("deepmerge");
import { TransactionTypes } from "../../enums";

export type TransactionSchema = typeof transactionBaseSchema;

export function extend(parent, properties): TransactionSchema {
return deepmerge(parent, properties);
}

export function signedSchema(schema: TransactionSchema): TransactionSchema {
const signed = extend(schema, signedTransaction);
signed.$id = `${schema.$id}Signed`;
return signed;
}
const signedTransaction = {
required: ["id", "signature"],
};

export function strictSchema(schema: TransactionSchema): TransactionSchema {
const signed = signedSchema(schema);
const strict = extend(signed, strictTransaction);
strict.$id = `${schema.$id}Strict`;
return strict;
}
const strictTransaction = {
additionalProperties: false,
};

export const transactionBaseSchema = {
$id: null,
Expand All @@ -39,13 +28,22 @@ export const transactionBaseSchema = {
},
};

const signedTransaction = {
required: ["id", "signature"],
};
export function extend(parent, properties): TransactionSchema {
return deepmerge(parent, properties);
}

const strictTransaction = {
additionalProperties: false,
};
export function signedSchema(schema: TransactionSchema): TransactionSchema {
const signed = extend(schema, signedTransaction);
signed.$id = `${schema.$id}Signed`;
return signed;
}

export function strictSchema(schema: TransactionSchema): TransactionSchema {
const signed = signedSchema(schema);
const strict = extend(signed, strictTransaction);
strict.$id = `${schema.$id}Strict`;
return strict;
}

export const transfer = extend(transactionBaseSchema, {
$id: "transfer",
Expand Down Expand Up @@ -167,3 +165,5 @@ export const delegateResignation = extend(transactionBaseSchema, {
amount: { bignumber: { minimum: 0, maximum: 0 } },
},
});

export type TransactionSchema = typeof transactionBaseSchema;
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"interface-name": false,
"no-console": false,
"no-default-export": true,
"no-use-before-declare": true,
"no-shadowed-variable": false,
"object-literal-sort-keys": false,
"radix": false
Expand Down

0 comments on commit c59d771

Please sign in to comment.