diff --git a/packages/trie-db/src/BaseTrie.ts b/packages/trie-db/src/BaseTrie.ts index 2445a19c8..adefe4740 100644 --- a/packages/trie-db/src/BaseTrie.ts +++ b/packages/trie-db/src/BaseTrie.ts @@ -99,7 +99,7 @@ export default class BaseTrie { * @returns {Function} Promise */ async put (key: Uint8Array, value: Uint8Array) { - l.debug(() => ['put', 'key ->', u8aToHex(key), 'value ->', u8aToHex(value)]); + l.debug(() => ['put', 'key ->', u8aToHex(key), 'value ->', u8aToHex(value, 256)]); if (!value || value.toString() === '') { return this.del(key); @@ -244,7 +244,7 @@ export default class BaseTrie { const stack: any[] = []; // FIXME const targetKey = nibblesFromU8a(_targetKey); - l.debug(() => ['findPath', targetKey.join(', ')]); + // l.debug(() => ['findPath', targetKey.join(', ')]); // @ts-ignore FIXME, we need to properly check the full file const processNode = (nodeRef, node, keyProgress, walkController) => { diff --git a/packages/trie-db/src/nodeFactory.ts b/packages/trie-db/src/nodeFactory.ts index f8fb4959e..b2f2c4b9c 100644 --- a/packages/trie-db/src/nodeFactory.ts +++ b/packages/trie-db/src/nodeFactory.ts @@ -7,10 +7,10 @@ import { Logger } from '@polkadot/util/types'; import { HashFn, DecodedRlp, NodeFactory, Trie$Node, Trie$Node$Type } from './types'; import logger from '@polkadot/util/logger'; -import u8aToHex from '@polkadot/util/u8a/toHex'; +// import u8aToHex from '@polkadot/util/u8a/toHex'; import nibblesFromU8a from './nibbles/fromU8a'; -import rlpToString from './util/rlpToString'; +// import rlpToString from './util/rlpToString'; import TrieNode from './Node'; @@ -43,7 +43,7 @@ function getNodeType (node: DecodedRlp): Trie$Node$Type { function fromBranch (l: Logger, hashing: HashFn) { return (rlp: DecodedRlp): Trie$Node => { - l.debug(() => ['fromBranch']); + // l.debug(() => ['fromBranch']); const node = new TrieNode(hashing, 'branch', Array.apply(null, Array(17))); @@ -62,7 +62,7 @@ function fromBranch (l: Logger, hashing: HashFn) { function fromRaw (l: Logger, hashing: HashFn) { return (rlp: DecodedRlp): Trie$Node => { - l.debug(() => ['fromRaw ->', rlpToString(rlp)]); + // l.debug(() => ['fromRaw ->', rlpToString(rlp)]); const node = new TrieNode(hashing, getNodeType(rlp), rlp); @@ -72,7 +72,7 @@ function fromRaw (l: Logger, hashing: HashFn) { function fromType (l: Logger, hashing: HashFn, type: Trie$Node$Type) { return (key: Uint8Array, value: Uint8Array): Trie$Node => { - l.debug(() => ['fromType', 'type ->', type, 'key ->', u8aToHex(key), 'value ->', u8aToHex(value)]); + // l.debug(() => ['fromType', 'type ->', type, 'key ->', u8aToHex(key), 'value ->', u8aToHex(value, 256)]); const node = new TrieNode(hashing, type, Array(2)); diff --git a/packages/trie-db/src/streams/ScratchRead.ts b/packages/trie-db/src/streams/ScratchRead.ts index 7f4fdac61..4c283802d 100644 --- a/packages/trie-db/src/streams/ScratchRead.ts +++ b/packages/trie-db/src/streams/ScratchRead.ts @@ -8,9 +8,9 @@ import { Trie$Base } from '../types'; // @ts-ignore FIXME, we need to properly check the full file import { Readable } from 'readable-stream'; import logger from '@polkadot/util/logger'; -import u8aToHex from '@polkadot/util/u8a/toHex'; +// import u8aToHex from '@polkadot/util/u8a/toHex'; -import rlpToString from '../util/rlpToString'; +// import rlpToString from '../util/rlpToString'; const l = logger('trie/scratch'); @@ -39,7 +39,7 @@ export default class ScratchReadStream extends Readable { }; // @ts-ignore FIXME, we need to properly check the full file const onFound = (nodeRef, node, key, next) => { - l.debug(() => ['onFound', u8aToHex(nodeRef), node.type, rlpToString(node.raw)]); + // l.debug(() => ['onFound', u8aToHex(nodeRef), node.type, rlpToString(node.raw)]); // @ts-ignore FIXME, we need to properly check the full file this.push({ diff --git a/packages/trie-db/src/streams/TrieRead.ts b/packages/trie-db/src/streams/TrieRead.ts index 7f9e84374..9842ea58f 100644 --- a/packages/trie-db/src/streams/TrieRead.ts +++ b/packages/trie-db/src/streams/TrieRead.ts @@ -8,7 +8,7 @@ import { Trie$Base } from '../types'; // @ts-ignore FIXME, we need to properly check the full file import { Readable } from 'readable-stream'; import logger from '@polkadot/util/logger'; -import u8aToHex from '@polkadot/util/u8a/toHex'; +// import u8aToHex from '@polkadot/util/u8a/toHex'; import { nibblesToU8a } from '../nibbles'; @@ -40,7 +40,7 @@ export default class TrieReadStream extends Readable { }; // @ts-ignore FIXME, we need to properly check the full file const onFound = (nodeRef, node, nibbles, next) => { - l.debug(() => ['onFound', nibbles, u8aToHex(node.value)]); + // l.debug(() => ['onFound', nibbles, u8aToHex(node.value)]); // @ts-ignore FIXME, we need to properly check the full file this.push({ diff --git a/packages/util-triedb/LICENSE b/packages/util-triedb/LICENSE deleted file mode 100644 index cef2b7fe5..000000000 --- a/packages/util-triedb/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -ISC License (ISC) - -Copyright 2017-2018 @polkadot/util-triedb authors & contributors - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. diff --git a/packages/util-triedb/README.md b/packages/util-triedb/README.md deleted file mode 100644 index 12b08ecf6..000000000 --- a/packages/util-triedb/README.md +++ /dev/null @@ -1,13 +0,0 @@ -[![polkadotjs](https://img.shields.io/badge/polkadot-js-orange.svg?style=flat-square)](https://polkadot.js.org) -![isc](https://img.shields.io/badge/license-ISC-lightgrey.svg?style=flat-square) -[![style](https://img.shields.io/badge/code%20style-semistandard-lightgrey.svg?style=flat-square)](https://github.com/Flet/semistandard) -[![npm](https://img.shields.io/npm/v/@polkadot/util-triedb.svg?style=flat-square)](https://www.npmjs.com/package/@polkadot/util-triedb) -[![travis](https://img.shields.io/travis/polkadot-js/common.svg?style=flat-square)](https://travis-ci.org/polkadot-js/common) -[![maintainability](https://img.shields.io/codeclimate/maintainability/polkadot-js/common.svg?style=flat-square)](https://codeclimate.com/github/polkadot-js/common/maintainability) -[![coverage](https://img.shields.io/coveralls/polkadot-js/common.svg?style=flat-square)](https://coveralls.io/github/polkadot-js/common?branch=master) -[![dependency](https://david-dm.org/polkadot-js/common.svg?style=flat-square&path=packages/util)](https://david-dm.org/polkadot-js/common?path=packages/util-triedb) -[![devDependency](https://david-dm.org/polkadot-js/common/dev-status.svg?style=flat-square&path=packages/util-triedb)](https://david-dm.org/polkadot-js/common?path=packages/util-triedb#info=devDependencies) - -# @polkadot/util-triedb - -DEPRECTATED, but still used until converted diff --git a/packages/util-triedb/docs/README.md b/packages/util-triedb/docs/README.md deleted file mode 100644 index 5a6959625..000000000 --- a/packages/util-triedb/docs/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Available interfaces - - - -- [temp](temp.md) - -# Available methods \ No newline at end of file diff --git a/packages/util-triedb/docs/temp.md b/packages/util-triedb/docs/temp.md deleted file mode 100644 index 0f88ce95e..000000000 --- a/packages/util-triedb/docs/temp.md +++ /dev/null @@ -1,3 +0,0 @@ -# temp - - diff --git a/packages/util-triedb/package.json b/packages/util-triedb/package.json deleted file mode 100644 index d03583161..000000000 --- a/packages/util-triedb/package.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "name": "@polkadot/util-triedb", - "version": "0.26.11", - "description": "Creation of triehash values", - "main": "index.js", - "keywords": [ - "Polkadot" - ], - "author": "Jaco Greeff ", - "maintainers": [ - "Jaco Greeff " - ], - "contributors": [], - "license": "ISC", - "engines": { - "node": ">=6.4" - }, - "publishConfig": { - "access": "public", - "registry": "https://registry.npmjs.org" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/polkadot-js/common.git" - }, - "bugs": { - "url": "https://github.com/polkadot-js/common/issues" - }, - "homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-hash#readme", - "scripts": { - "build": "polkadot-dev-build-babel && polkadot-dev-build-docs", - "check": "eslint src && flow check", - "test": "echo \"Tests only available from root wrapper\"" - }, - "dependencies": { - "@babel/runtime": "^7.0.0-beta.51", - "@polkadot/trie-hash": "^0.26.11", - "@polkadot/util": "^0.26.11", - "@polkadot/util-crypto": "^0.26.11", - "@polkadot/util-rlp": "^0.26.11", - "leveldown": "^4.0.1", - "levelup": "^3.0.1", - "memdown": "^3.0.0" - } -} diff --git a/packages/util-triedb/src/clear.ts b/packages/util-triedb/src/clear.ts deleted file mode 100644 index 462ada99e..000000000 --- a/packages/util-triedb/src/clear.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { TrieDbState } from './types'; - -export default function clear (self: TrieDbState): void { - // TODO -} diff --git a/packages/util-triedb/src/commit.ts b/packages/util-triedb/src/commit.ts deleted file mode 100644 index 0e8854b3c..000000000 --- a/packages/util-triedb/src/commit.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { TrieDbState } from './types'; - -export default function commit (self: TrieDbState): void { - // TODO -} diff --git a/packages/util-triedb/src/index.ts b/packages/util-triedb/src/index.ts deleted file mode 100644 index 2fc522bd3..000000000 --- a/packages/util-triedb/src/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -// import { LevelUp$AbstractStorage } from 'levelup'; -// import { TrieDb } from './types'; - -// const clear from './clear'); -// const commit from './commit'); -// const state from './state'); - -// export default function triedb (db: LevelUp$AbstractStorage): TrieDb { -// const self = state(db); - -// return { -// clear: (): void => -// clear(self), -// commit: (): void => -// commit(self) -// }; -// }; diff --git a/packages/util-triedb/src/state.ts b/packages/util-triedb/src/state.ts deleted file mode 100644 index cc5fe94e1..000000000 --- a/packages/util-triedb/src/state.ts +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { TrieDbState } from './types'; - -import logger from '@polkadot/util/logger'; - -import createTemp from './temp'; - -export default function state (db: {}): TrieDbState { - const storage = createTemp(); - - return { - db, - l: logger('triedb'), - storage - }; -} diff --git a/packages/util-triedb/src/temp/clear.spec.js b/packages/util-triedb/src/temp/clear.spec.js deleted file mode 100644 index e112ab673..000000000 --- a/packages/util-triedb/src/temp/clear.spec.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import factory from './index'; - -describe('clear', () => { - let memory; - - beforeEach(() => { - memory = factory(); - }); - - it('clears all values', () => { - memory.set(new Uint8Array([1]), new Uint8Array([2])); - memory.clear(); - - expect( - memory.isEmpty() - ).toEqual(true); - }); -}); diff --git a/packages/util-triedb/src/temp/commit.spec.js b/packages/util-triedb/src/temp/commit.spec.js deleted file mode 100644 index 957fb6715..000000000 --- a/packages/util-triedb/src/temp/commit.spec.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import factory from './index'; - -describe('commit', () => { - let memory; - const k1 = new Uint8Array([1]); - const k2 = new Uint8Array([2]); - const v1 = new Uint8Array([9]); - const v2 = new Uint8Array([8]); - - beforeEach(() => { - memory = factory(); - memory.commit([ - { k: k1, v: v1 } - ]); - }); - - it('sets values to back-end', () => { - expect( - memory.get(k1) - ).toEqual(v1); - }); - - it('removes empty values from storage', () => { - memory.commit([ - { k: k1, v: null }, - { k: k2, v: v2 } - ]); - - expect( - memory.get(k1) - ).toEqual(null); - expect( - memory.get(k2) - ).toEqual(v2); - expect( - memory.pairs() - ).toEqual([ - { k: k2, v: v2 } - ]); - }); - - it('ignores empty values, not in storage', () => { - memory.commit([ - { k: k2, v: null } - ]); - - expect( - memory.get(k2) - ).toEqual(null); - }); - - it('ignores empty array', () => { - memory.commit(); - - expect( - memory.get(k1) - ).toEqual(v1); - }); -}); diff --git a/packages/util-triedb/src/temp/commit.ts b/packages/util-triedb/src/temp/commit.ts deleted file mode 100644 index 0ce138901..000000000 --- a/packages/util-triedb/src/temp/commit.ts +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { Trie$Pairs } from '@polkadot/trie-hash/types'; -import { Temp$Storage } from './types'; - -import del from './del'; -import set from './set'; - -export default function commit (storage: Temp$Storage, values: Trie$Pairs): void { - values.forEach(({ k, v }) => { - if (v && v.length) { - set(storage, k, v); - } else { - del(storage, k); - } - }); -} diff --git a/packages/util-triedb/src/temp/del.spec.js b/packages/util-triedb/src/temp/del.spec.js deleted file mode 100644 index 2e43bc37d..000000000 --- a/packages/util-triedb/src/temp/del.spec.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import factory from './index'; - -describe('del', () => { - let memory; - - beforeEach(() => { - memory = factory(); - }); - - it('removes a value', () => { - memory.set(new Uint8Array([1]), new Uint8Array([2])); - memory.del(new Uint8Array([1])); - - expect( - memory.isEmpty() - ).toEqual(true); - }); -}); diff --git a/packages/util-triedb/src/temp/del.ts b/packages/util-triedb/src/temp/del.ts deleted file mode 100644 index 04bae137d..000000000 --- a/packages/util-triedb/src/temp/del.ts +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { Temp$Storage } from './types'; - -export default function del (storage: Temp$Storage, k: Uint8Array): void { - // @ts-ignore yes, U8a index - delete storage[k]; -} diff --git a/packages/util-triedb/src/temp/get.ts b/packages/util-triedb/src/temp/get.ts deleted file mode 100644 index 2b18d17dd..000000000 --- a/packages/util-triedb/src/temp/get.ts +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { Temp$Storage } from './types'; - -export default function get (storage: Temp$Storage, k: Uint8Array): Uint8Array | null { - // @ts-ignore yes, U8a index - const value = storage[k]; - - return value && value.v - ? value.v.slice() - : null; -} diff --git a/packages/util-triedb/src/temp/index.ts b/packages/util-triedb/src/temp/index.ts deleted file mode 100644 index 494794aed..000000000 --- a/packages/util-triedb/src/temp/index.ts +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { Trie$Pairs } from '@polkadot/trie-hash/types'; -import { TrieDb } from '../types'; -import { Temp$Storage } from './types'; - -import trieRoot from '@polkadot/trie-hash/root'; - -import commit from './commit'; -import del from './del'; -import get from './get'; -import pairs from './pairs'; -import set from './set'; - -export default function temp (): TrieDb { - let storage: Temp$Storage = {}; - - return { - clear: (): void => { - storage = {}; - }, - commit: (values: Trie$Pairs = []): void => - commit(storage, values), - del: (k: Uint8Array): void => - del(storage, k), - isEmpty: (): boolean => - Object.keys(storage).length === 0, - get: (k: Uint8Array): Uint8Array | null => - get(storage, k), - pairs: (): Trie$Pairs => - pairs(storage), - set: (k: Uint8Array, v: Uint8Array): void => - set(storage, k, v), - trieRoot: (): Uint8Array => - trieRoot(pairs(storage)) - }; -} diff --git a/packages/util-triedb/src/temp/pairs.ts b/packages/util-triedb/src/temp/pairs.ts deleted file mode 100644 index 359294c82..000000000 --- a/packages/util-triedb/src/temp/pairs.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { Trie$Pairs } from '@polkadot/trie-hash/types'; -import { Temp$Storage } from './types'; - -export default function pairs (storage: Temp$Storage): Trie$Pairs { - return Object - .keys(storage) - .map((k) => storage[k]); -} diff --git a/packages/util-triedb/src/temp/set.ts b/packages/util-triedb/src/temp/set.ts deleted file mode 100644 index 629a5dd96..000000000 --- a/packages/util-triedb/src/temp/set.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { Temp$Storage } from './types'; - -export default function set (storage: Temp$Storage, k: Uint8Array, v: Uint8Array): void { - // @ts-ignore we coax into string here, bad I know - storage[k] = { - k: k.slice(), - v: v.slice() - }; -} diff --git a/packages/util-triedb/src/temp/trieRoot.spec.js b/packages/util-triedb/src/temp/trieRoot.spec.js deleted file mode 100644 index 671328a63..000000000 --- a/packages/util-triedb/src/temp/trieRoot.spec.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import u8aFromString from '@polkadot/util/u8a/fromString'; -import hexToU8a from '@polkadot/util/hex/toU8a'; - -import factory from './index'; - -describe('trieRoot', () => { - let temp; - - beforeEach(() => { - temp = factory(); - }); - - it('calculates the correct trieRoot', () => { - temp.set(u8aFromString('doe'), u8aFromString('reindeer')); - temp.set(u8aFromString('dog'), u8aFromString('puppy')); - temp.set(u8aFromString('dogglesworth'), u8aFromString('cat')); - - expect( - temp.trieRoot() - ).toEqual( - hexToU8a( - '0x8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3' - ) - ); - }); -}); diff --git a/packages/util-triedb/src/temp/types.d.ts b/packages/util-triedb/src/temp/types.d.ts deleted file mode 100644 index e6c523bf0..000000000 --- a/packages/util-triedb/src/temp/types.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { Trie$Pair } from '@polkadot/trie-hash/types'; - -export type Temp$Storage = { - [index: string]: Trie$Pair -}; diff --git a/packages/util-triedb/src/types.d.ts b/packages/util-triedb/src/types.d.ts deleted file mode 100644 index a9015a683..000000000 --- a/packages/util-triedb/src/types.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017-2018 @polkadot/util-triedb authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { Logger } from '@polkadot/util/types'; -import { Trie$Pairs } from '@polkadot/trie-hash/types'; - -export type TrieDb = { - clear: () => void, - commit: (values?: Trie$Pairs) => void, - del: (key: Uint8Array) => void, - isEmpty: () => boolean, - get: (key: Uint8Array) => Uint8Array | null, - pairs: () => Trie$Pairs, - set: (key: Uint8Array, value: Uint8Array) => void, - trieRoot: () => Uint8Array -} - -export type TrieDbState = { - db: {}, - l: Logger, - storage: TrieDb -};