Beispiel #1
0
// HaveBlockInDB returns whether or not the chain instance has the block represented
// by the passed hash.  This includes checking the various places a block can
// be like part of the main chain, on a side chain, or in the orphan pool.
//
// This function is NOT safe for concurrent access.
func HaveBlockInDB(hash *common.Hash) (bool, error) {
	//util.Trace(spew.Sdump(hash))
	blk, _ := db.FetchDBlockByHash(hash)
	if blk != nil {
		fmt.Println("HaveBlockInDB. true. ", hash.BTCString())
		return true, nil
	}
	return false, nil

	/*
		if hash == nil || dchain.Blocks == nil || len(dchain.Blocks) == 0 {
			return false, nil
		}

		// double check the block ids
		for i := 0; i < len(dchain.Blocks); i = i + 1 {
			if dchain.Blocks[i] == nil {
				continue
			}
			if dchain.Blocks[i].DBHash == nil {
				dchain.Blocks[i].DBHash, _ = common.CreateHash(dchain.Blocks[i])
			}
			if dchain.Blocks[i].DBHash.IsSameAs(hash) {
				return true, nil
			}
		}

		return false, nil */
}