func (i *ShardBlockIndex) AddToIndex(block primitives.ShardBlock) (*ShardBlockNode, error) {
	i.Lock.Lock()
	defer i.Lock.Unlock()
	parent, found := i.Index[block.Header.PreviousBlockHash]

	if !found {
		return nil, fmt.Errorf("missing parent block %s", block.Header.PreviousBlockHash)
	}

	blockHash, err := ssz.HashTreeRoot(block)
	if err != nil {
		return nil, err
	}

	node := &ShardBlockNode{
		Parent:    parent,
		BlockHash: blockHash,
		StateRoot: block.Header.StateRoot,
		Slot:      block.Header.Slot,
		Height:    parent.Height + 1,
	}

	i.Index[blockHash] = node

	return node, nil
}
// AddToIndex adds a block to the block index.
AddToIndex adds a block to the block index.
// AddToIndex adds a block to the block index .
func (i *ShardBlockIndex) AddToIndex(block primitives.ShardBlock) (*ShardBlockNode, error) {
	i.Lock.Lock()
	defer i.Lock.Unlock()
	parent, found := i.Index[block.Header.PreviousBlockHash]
	if !found {
		return nil, fmt.Errorf("missing parent block %s", block.Header.PreviousBlockHash)
	}
	blockHash, err := ssz.HashTreeRoot(block)
	if err != nil {
		return nil, err
	}
	node := &ShardBlockNode{
		Parent:    parent,
		BlockHash: blockHash,
		StateRoot: block.Header.StateRoot,
		Slot:      block.Header.Slot,
		Height:    parent.Height + 1,
	}
	i.Index[blockHash] = node
	return node, nil
}
func ( i * ShardBlockIndex ) AddToIndex ( block primitives . ShardBlock ) ( * ShardBlockNode , error ) { i . Lock . Lock ( ) defer i . Lock . Unlock ( ) parent , found := i . Index [ block . Header . PreviousBlockHash ] if ! found { return nil , fmt . Errorf ( " " , block . Header . PreviousBlockHash ) } blockHash , err := ssz . HashTreeRoot ( block ) if err != nil { return nil , err } node := & ShardBlockNode { Parent : parent , BlockHash : blockHash , StateRoot : block . Header . StateRoot , Slot : block . Header . Slot , Height : parent . Height + 1 , } i . Index [ blockHash ] = node return node , nil }
AddToIndex adds a block to the block index.
AddToIndex adds a block to the block index .