Get the path (as a list of hashes) from the leaf hash to the root.
        leaf_hash_hex is hex-encoded, little-endian.

        The returned path will be a list of {'hash': hex-encoded little-endian hash, 'order': 'l' or 'r'}

        Raise ValueError if leaf_hash is not present in the tree.

def path(self, leaf_hash_hex, serialize=True):
        """
        Get the path (as a list of hashes) from the leaf hash to the root.
        leaf_hash_hex is hex-encoded, little-endian.

        The returned path will be a list of {'hash': hex-encoded little-endian hash, 'order': 'l' or 'r'}

        Raise ValueError if leaf_hash is not present in the tree.
        """
        
        leaf_hash = hex_to_bin_reversed(leaf_hash_hex)

        # sanity check
        found = False
        ri = None       # index into self.rows where leaf_hash occurs.  Note that self.rows[0] is the bottom (leaves) of the Merkle tree.
        for ri, row in enumerate(self.rows):
            found = found or (leaf_hash in row)
            if found:
                break

        if not found:
            raise ValueError("Hash {} is not present in Merkle tree {}".format(leaf_hash, self.root()))

        path = []
        cur_hash = leaf_hash
        for i in range(ri, len(self.rows)-1):
            # find sibling
            sibling = {}
            leaf_index = self.rows[i].index(cur_hash)
            if leaf_index % 2 == 0:
                # append left sibling
                sibling_hash = None
                if leaf_index+1 >= len(self.rows[i]):
                    # double-up the last hash
                    assert leaf_index+1 == len(self.rows[i]), 'leaf_index = {}, i = {}, len(rows[i]) = {}, rows[0] = {}'.format(leaf_index, i, len(self.rows[i]), ','.join(r.encode('hex') for r in self.rows[0]))
                    sibling_hash = self.rows[i][-1]
                else:
                    sibling_hash = self.rows[i][leaf_index+1]

                sibling['hash'] = bin_to_hex_reversed(sibling_hash)
                sibling['order'] = 'r'
            else:
                # append right sibling
                sibling['hash'] = bin_to_hex_reversed(self.rows[i][leaf_index-1])
                sibling['order'] = 'l'

            path.append(sibling)

            # find parent
            cur_hash = self.rows[i+1][leaf_index/2]
        
        if len(path) == 0:
            # single-node merkle tree
            path = [{'hash': bin_to_hex_reversed(self.rows[-1][0]), 'order': 'm'}]

        if not serialize:
            return path
        else:
            return self.path_serialize(path)