// GetCachedBlockByHashStr attempts to fetch a CachedBlock with the given hash.
// The return is nil if no block with that hash is cached.
174763
func (apic *APICache) GetCachedBlockByHashStr(hashStr string) *CachedBlock {
	// Validate the hash string, and get a *chainhash.Hash
	hash, err := chainhash.NewHashFromStr(hashStr)
	if err != nil {
		fmt.Printf("that's not a real hash!")
		return nil
	}

	apic.mtx.Lock()
	defer apic.mtx.Unlock()
	return apic.getCachedBlockByHash(*hash)
}
3541
func GetBlockHeaderVerboseByString(client BlockFetcher, hash string) *dcrjson.GetBlockHeaderVerboseResult {
	blockhash, err := chainhash.NewHashFromStr(hash)
	if err != nil {
		log.Errorf("Invalid block hash %s: %v", blockhash, err)
		return nil
	}

	blockHeaderVerbose, err := client.GetBlockHeaderVerbose(blockhash)
	if err != nil {
		log.Errorf("GetBlockHeaderVerbose(%v) failed: %v", blockhash, err)
		return nil
	}

	return blockHeaderVerbose
}
1120288
func (apic *APICache) GetStakeInfoByHash(hash string) *StakeInfoExtended {
	if !apic.IsEnabled() {
		return nil
	}
	cachedBlock := apic.GetCachedBlockByHashStr(hash)
	if cachedBlock != nil {
		return cachedBlock.stakeInfo
	}
	return nil
}
83911
func (c *Client) GetBlockHashAsync(blockHeight int64) FutureGetBlockHashResult {
	cmd := btcjson.NewGetBlockHashCmd(blockHeight)
	return c.sendCmd(cmd)
}
1290085
func dbFetchHeightByHash(dbTx database.Tx, hash *chainhash.Hash) (int32, error) {
	meta := dbTx.Metadata()
	hashIndex := meta.Bucket(hashIndexBucketName)
	serializedHeight := hashIndex.Get(hash[:])
	if serializedHeight == nil {
		str := fmt.Sprintf("block %s is not in the main chain", hash)
		return 0, errNotInMainChain(str)
	}

	return int32(byteOrder.Uint32(serializedHeight)), nil
}
211185
func (db *DB) RetrieveBlockHash(ind int64) (string, error) {
	// First try the block summary cache.
	usingBlockCache := db.BlockCache != nil && db.BlockCache.IsEnabled()
	if usingBlockCache {
		hash := db.BlockCache.GetBlockHash(ind)
		if hash != "" {
			// Cache hit!
			return hash, nil
		}
		// Cache miss necessitates a DB query.
	}

	var blockHash string
	err := db.QueryRow(db.getBlockHashSQL, ind).Scan(&blockHash)
	return blockHash, err
}
607897
func (lc *LightChain) GetBlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) {
	number := lc.hc.GetBlockNumber(hash)
	if number == nil {
		return nil, errors.New("unknown block")
	}
	return lc.GetBlock(ctx, hash, *number)
}
1373581
func (cache *DiskBlockCacheService) GetBlock(ctx context.Context,
	arg kbgitkbfs.GetBlockArg) (kbgitkbfs.GetBlockRes, error) {
	// TODO: make sure this isn't remote.
	dbc := cache.config.DiskBlockCache()
	if dbc == nil {
		return kbgitkbfs.GetBlockRes{},
			DiskBlockCacheError{"Disk cache is nil"}
	}
	tlfID := tlf.ID{}
	err := tlfID.UnmarshalBinary(arg.TlfID)
	if err != nil {
		return kbgitkbfs.GetBlockRes{}, newDiskBlockCacheError(err)
	}
	blockID := kbfsblock.ID{}
	err = blockID.UnmarshalBinary(arg.BlockID)
	if err != nil {
		return kbgitkbfs.GetBlockRes{}, newDiskBlockCacheError(err)
	}
	buf, serverHalf, prefetchStatus, err := dbc.Get(
		ctx, tlfID, blockID, DiskBlockAnyCache)
	if err != nil {
		return kbgitkbfs.GetBlockRes{}, newDiskBlockCacheError(err)
	}
	protocolPrefetchStatus := prefetchStatus.ToProtocol()

	return kbgitkbfs.GetBlockRes{
		Buf:            buf,
		ServerHalf:     serverHalf.Bytes(),
		PrefetchStatus: protocolPrefetchStatus,
	}, nil
}
71720
func (p *BlockPrefetchClient) GetBestBlock() (*chainhash.Hash, int64, error) {
	return p.f.GetBestBlock()
}
47488
func dbFetchHeaderByHash(dbTx database.Tx, hash *chainhash.Hash) (*wire.BlockHeader, error) {
	headerBytes, err := dbTx.FetchBlockHeader(hash)
	if err != nil {
		return nil, err
	}

	var header wire.BlockHeader
	err = header.Deserialize(bytes.NewReader(headerBytes))
	if err != nil {
		return nil, err
	}

	return &header, nil
}
906511
func (c DiskBlockCacheClient) GetBlock(ctx context.Context, __arg GetBlockArg) (res GetBlockRes, err error) {
	err = c.Cli.Call(ctx, "kbgitkbfs.1.DiskBlockCache.GetBlock", []interface{}{__arg}, &res)
	return
}
1321345
func (bg *Reader) cacheHasBlockFor(base int64) (exists bool, next int64) {
	bg.mu.RLock()
	defer bg.mu.RUnlock()
	if bg.cache == nil {
		return false, -1
	}
	return bg.cache.Peek(base)
}
1304317
func ReadHeadFastBlockHash(db ethdb.Reader) common.Hash {
	data, _ := db.Get(headFastBlockKey)
	if len(data) == 0 {
		return common.Hash{}
	}
	return common.BytesToHash(data)
}
351205
func (c *BitcoindClient) GetBlockHeaderVerbose(
	hash *chainhash.Hash) (*btcjson.GetBlockHeaderVerboseResult, error) {

	return c.chainConn.client.GetBlockHeaderVerbose(hash)
}
1066185
func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block {
	hash := rawdb.ReadCanonicalHash(bc.db, number)
	if hash == (common.Hash{}) {
		return nil
	}
	return bc.GetBlock(hash, number)
}
590618
func (s *NeutrinoClient) GetBlockHeader(
	blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
	return s.CS.GetBlockHeader(blockHash)
}
1295456
func (db *DB) RetrieveBestBlockHash() (string, error) {
	var blockHash string
	err := db.QueryRow(db.getBestBlockHashSQL).Scan(&blockHash)
	return blockHash, err
}