func (bi *BlockIndex) AddBlockNodeToIndex(block *primitives.Block, blockHash chainhash.Hash, stateRoot chainhash.Hash, validatorRoot chainhash.Hash) (*BlockNode, error) {
	bi.lock.Lock()
	defer bi.lock.Unlock()

	if node := bi.getBlockNodeByHash(blockHash); node != nil {
		return node, nil
	}

	parentRoot := block.BlockHeader.ParentRoot
	parentNode := bi.getBlockNodeByHash(parentRoot)
	if block.BlockHeader.SlotNumber == 0 {
		parentNode = nil
	} else if parentNode == nil {
		return nil, ErrNoParent
	}

	height := uint64(0)
	if parentNode != nil {
		height = parentNode.Height + 1
	}

	node := &BlockNode{
		Hash:          blockHash,
		Height:        height,
		Slot:          block.BlockHeader.SlotNumber,
		Parent:        parentNode,
		StateRoot:     stateRoot,
		Children:      []*BlockNode{},
		ValidatorRoot: validatorRoot,
	}

	bi.index[blockHash] = node

	if parentNode != nil {
		parentNode.Children = append(parentNode.Children, node)
	}

	return node, nil
}
// AddBlockNodeToIndex adds a new block ot the blockchain.
AddBlockNodeToIndex adds a new block ot the blockchain.
// AddBlockNodeToIndex adds a new block ot the blockchain .
func (bi *BlockIndex) AddBlockNodeToIndex(block *primitives.Block, blockHash chainhash.Hash, stateRoot chainhash.Hash, validatorRoot chainhash.Hash) (*BlockNode, error) {
	bi.lock.Lock()
	defer bi.lock.Unlock()
	if node := bi.getBlockNodeByHash(blockHash); node != nil {
		return node, nil
	}
	parentRoot := block.BlockHeader.ParentRoot
	parentNode := bi.getBlockNodeByHash(parentRoot)
	if block.BlockHeader.SlotNumber == 0 {
		parentNode = nil
	} else if parentNode == nil {
		return nil, ErrNoParent
	}
	height := uint64(0)
	if parentNode != nil {
		height = parentNode.Height + 1
	}
	node := &BlockNode{
		Hash:          blockHash,
		Height:        height,
		Slot:          block.BlockHeader.SlotNumber,
		Parent:        parentNode,
		StateRoot:     stateRoot,
		Children:      []*BlockNode{},
		ValidatorRoot: validatorRoot,
	}
	bi.index[blockHash] = node
	if parentNode != nil {
		parentNode.Children = append(parentNode.Children, node)
	}
	return node, nil
}
func ( bi * BlockIndex ) AddBlockNodeToIndex ( block * primitives . Block , blockHash chainhash . Hash , stateRoot chainhash . Hash , validatorRoot chainhash . Hash ) ( * BlockNode , error ) { bi . lock . Lock ( ) defer bi . lock . Unlock ( ) if node := bi . getBlockNodeByHash ( blockHash ) ; node != nil { return node , nil } parentRoot := block . BlockHeader . ParentRoot parentNode := bi . getBlockNodeByHash ( parentRoot ) if block . BlockHeader . SlotNumber == 0 { parentNode = nil } else if parentNode == nil { return nil , ErrNoParent } height := uint64 ( 0 ) if parentNode != nil { height = parentNode . Height + 1 } node := & BlockNode { Hash : blockHash , Height : height , Slot : block . BlockHeader . SlotNumber , Parent : parentNode , StateRoot : stateRoot , Children : [ ] * BlockNode { } , ValidatorRoot : validatorRoot , } bi . index [ blockHash ] = node if parentNode != nil { parentNode . Children = append ( parentNode . Children , node ) } return node , nil }
AddBlockNodeToIndex adds a new block ot the blockchain.
AddBlockNodeToIndex adds a new block ot the blockchain .