Properly encode empty trie (#100)

This commit is contained in:
Jaco Greeff
2018-02-26 15:29:38 +01:00
committed by GitHub
parent 6f94f21b4c
commit b03f9f735f
2 changed files with 6 additions and 2 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ describe('trieRoot', () => {
trieRoot([])
).toEqual(
hexToU8a(
'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'
'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'
)
);
});
+5 -1
View File
@@ -11,9 +11,13 @@ const rlpEncode = require('@polkadot/util-rlp/encode');
const encode = require('./encode');
module.exports = function genRoot (pairs: Trie$Pairs): Uint8Array {
const encoded = encode(pairs, 0);
return keccakAsU8a(
rlpEncode(
encode(pairs, 0)
encoded.length
? encoded
: new Uint8Array([])
)
);
};