Properly encode empty trie (#100)
This commit is contained in:
@@ -13,7 +13,7 @@ describe('trieRoot', () => {
|
||||
trieRoot([])
|
||||
).toEqual(
|
||||
hexToU8a(
|
||||
'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'
|
||||
'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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([])
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user