Files
common/packages/trie-db-old/src/encoder/decode.ts
T
Jaco Greeff e1135a665b 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?)
2018-09-01 22:17:57 +02:00

30 lines
903 B
TypeScript

// Copyright 2017-2018 @polkadot/trie-db authors & contributors
// This software may be modified and distributed under the terms
// of the MPL-2.0 license. See the LICENSE file for details.
import { Logger } from '@polkadot/util/types';
import assert from '@polkadot/util/assert';
import isBuffer from '@polkadot/util/is/buffer';
import isU8a from '@polkadot/util/is/u8a';
import toU8a from '@polkadot/util/u8a/toU8a';
export default function decode (l: Logger) {
return (value: Buffer | Uint8Array | null): Uint8Array => {
// l.debug(() => ['decoding', value]);
if (!value || !value.length) {
return new Uint8Array(0);
}
const isBufferIn = isBuffer(value);
const isU8aIn = isU8a(value);
assert(isBufferIn || isU8aIn, `Expected a Buffer | Uint8Array | null input type, received '${typeof value}'`);
return isBufferIn
? toU8a(value)
: value;
};
}