2.2 KiB
2.2 KiB
Functions
encode
▸ encode(pairs: Trie$Pairs, preLength: number): Array<any>
Defined in encode/index.ts:36
name: encode
signature: encode (pairs: Trie$Pairs, preLength: number): Array
summary: Encodes Trie Pairs depending on a provided Prefix Length and the amount of pairs
description: * encode is called and provided arguments including Trie Pairs and Prefix Length.
- If the Trie Pairs have no length then return an empty array
- If the Trie Pairs have a length of 1 then we call
encodeSingleto return a single encoded array with two elements. The first element is a u8a calculated from callingencodeHexPrefixwith arguments including a slice up to the Prefix Length of the pair's key (aka nibbles), and whether it's a leaf. The second element is the pair's value. - If the Trie Pairs have a length > 1 and we calculate that their Shared Prefix Length > Prefix Length then we return early with the results of calling
encodeSharedto return a single encoded array with two elements. The first element is a u8a calculated as previously withencodeHexPrefixand whereas second element is calculated from callingencodeAux, which recursively calls this functionencodeto obtain an encoded value, and then Recursive Length Prefix (RLP) encodes it. If the length of the RLP encoded u8a is less than 32 then return the RLP encoded value, otherwise return call the Keccak-256 hash function from js-sha3 library on the RLP encoded value and return the result. - If the Trie Pairs have a length > 1 and the calculated Share Prefix Length <= Prefix Length then we return the array result of calling
encodePairsand push the pair's value onto the end of the array if the Prefix Length !== Pair's Key Length.
description: Refer to Merkle Patricia Trie specification
Parameters:
| Param | Type |
|---|---|
| pairs | Trie$Pairs |
| preLength | number |
Returns: Array<any>