Re-implementation of Patricia-Merkle Trie (#203)
* Start of trie-db re-implementation * WIP commit * More WIP * WIP, seems complete, untested * Ported trie-db operational * Add Ethereum trie tests * Use u8aConcat to construct u8a * Basic RocksDb interface * Combine engines into DB, expand tests * Update Trie with transaction wrapper * LevelDb (sync) interface * Remove unused (for now) package (compatibility) * trie-d -> trie-db-old, trie-db-ext -> trie-db * Version bump * Skip old trie tests (package to be removed) * Skip tests (fixed) * Remove non-used RocksDb spec * Skip FileFlat tests (deprecated?)
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
type ObjectIndexed = {
|
||||
[index: string]: any
|
||||
};
|
||||
|
||||
/**
|
||||
* @name isObject
|
||||
* @signature isObject (value: any): boolean
|
||||
@@ -14,6 +18,6 @@
|
||||
* isObject({}); // => true
|
||||
* isObject('something'); // => false
|
||||
*/
|
||||
export default function isObject (value: any): value is object {
|
||||
export default function isObject (value: any): value is ObjectIndexed {
|
||||
return typeof value === 'object';
|
||||
}
|
||||
|
||||
@@ -7,7 +7,14 @@ import { Logger, Logger$Data } from './types';
|
||||
import chalk from 'chalk';
|
||||
import moment from 'moment';
|
||||
|
||||
import isBn from './is/bn';
|
||||
import isBuffer from './is/buffer';
|
||||
import isFunction from './is/function';
|
||||
import isObject from './is/object';
|
||||
import isNull from './is/null';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import isUndefined from './is/undefined';
|
||||
import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
|
||||
type ConsoleType = 'error' | 'log' | 'warn';
|
||||
type LogType = ConsoleType | 'debug';
|
||||
@@ -26,11 +33,45 @@ const chalked = {
|
||||
warn: chalk.yellow
|
||||
};
|
||||
|
||||
function formatValue (value: any): any {
|
||||
if (isNull(value)) {
|
||||
return null;
|
||||
} else if (isUndefined(value)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(formatValue);
|
||||
}
|
||||
|
||||
if (isBn(value)) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
if (isBuffer(value)) {
|
||||
return `0x${value.toString('hex')}`;
|
||||
}
|
||||
|
||||
if (isU8a(value)) {
|
||||
return u8aToHex(value);
|
||||
}
|
||||
|
||||
if (isObject(value) && value.constructor === Object) {
|
||||
return Object.keys(value).reduce((result, key) => {
|
||||
result[key] = formatValue(value[key]);
|
||||
|
||||
return result;
|
||||
}, {} as { [index: string]: any });
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function apply (log: LogType, type: string, values: Logger$Data): void {
|
||||
if (values.length === 1 && isFunction(values[0])) {
|
||||
const fnResult = (values[0] as Function)();
|
||||
|
||||
return apply(log, type, fnResult);
|
||||
return apply(log, type, Array.isArray(fnResult) ? fnResult : [fnResult]);
|
||||
}
|
||||
|
||||
const chalk = (value: string): string =>
|
||||
@@ -40,7 +81,9 @@ function apply (log: LogType, type: string, values: Logger$Data): void {
|
||||
console[logTo[log]].apply(
|
||||
console, [
|
||||
chalk(moment().format('YYYY-MM-DD HH:mm:ss')), chalk(type)
|
||||
].concat(values)
|
||||
].concat(
|
||||
values.map(formatValue)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user