func parseTrieNodeBranch(i []interface{}, codec uint64) ([]interface{}, error) {
	var out []interface{}
	for _, vi := range i {
		v := vi.([]byte)
		switch len(v) {
		case 0:
			out = append(out, nil)
		case 32:
			out = append(out, keccak256ToCid(codec, v))
		default:
			return nil, fmt.Errorf("unrecognized object: %v", v)
		}
	}
	return out, nil
}
parseTrieNodeBranch helper improves readability
package ipldeth
import (
	"encoding/json"
	"fmt"
	cid "github.com/ipfs/go-cid"
	node "github.com/ipfs/go-ipld-format"
	"github.com/ethereum/go-ethereum/rlp"
)
type TrieNode struct {
	nodeKind string
	elements []interface{}
	cid     *cid.Cid
	rawdata []byte
}
type trieNodeLeafDecoder func([]interface{}) ([]interface{}, error)
func decodeTrieNode(c *cid.Cid, b []byte,
	leafDecoder trieNodeLeafDecoder) (*TrieNode, error) {
	var (
		i, decoded, elements []interface{}
		nodeKind             string
		err                  error
	)
	err = rlp.DecodeBytes(b, &i)
	if err != nil {
		return nil, err
	}
	codec := c.Type()
	switch len(i) {
	case 2:
		nodeKind, decoded, err = decodeCompactKey(i)
		if err != nil {
			return nil, err
		}
		if nodeKind == "extension" {
			elements, err = parseTrieNodeExtension(decoded, codec)
		}
		if nodeKind == "leaf" {
			elements, err = leafDecoder(decoded)
		}
		if nodeKind != "extension" && nodeKind != "leaf" {
			return nil, fmt.Errorf("unexpected nodeKind returned from decoder")
		}
	case 17:
		nodeKind = "branch"
		elements, err = parseTrieNodeBranch(i, codec)
		if err != nil {
			return nil, err
		}
	default:
		return nil, fmt.Errorf("unknown trie node type")
	}
	return &TrieNode{
		nodeKind: nodeKind,
		elements: elements,
		rawdata:  b,
		cid:      c,
	}, nil
}
func decodeCompactKey(i []interface{}) (string, []interface{}, error) {
	first := i[0].([]byte)
	last := i[1].([]byte)
	switch first[0] / 16 {
	case '\x00':
		return "extension", []interface{}{
			nibbleToByte(first)[2:],
			last,
		}, nil
	case '\x01':
		return "extension", []interface{}{
			nibbleToByte(first)[1:],
			last,
		}, nil
	case '\x02':
		return "leaf", []interface{}{
			nibbleToByte(first)[2:],
			last,
		}, nil
	case '\x03':
		return "leaf", []interface{}{
			nibbleToByte(first)[1:],
			last,
		}, nil
	default:
		return "", nil, fmt.Errorf("unknown hex prefix")
	}
}
func parseTrieNodeExtension(i []interface{}, codec uint64) ([]interface{}, error) {
	return []interface{}{
		i[0].([]byte),
		keccak256ToCid(codec, i[1].([]byte)),
	}, nil
}