bool get_aux_block_header_hash(const Block& b, Hash& res) {
  BinaryArray blob;
  if (!get_block_hashing_blob(b, blob)) {
    return false;
  }

  return getObjectHash(blob, res);
}
bool get_aux_block_header_hash(const Block& b, crypto::hash& res) {
  blobdata blob;
  if (!get_block_hashing_blob(b, blob)) {
    return false;
  }

  return get_object_hash(blob, res);
}
bool get_block_longhash(cn_context &context, const Block& b, Hash& res) {
  BinaryArray bd;
  if (b.majorVersion == BLOCK_MAJOR_VERSION_1 || b.majorVersion >= BLOCK_MAJOR_VERSION_4) {
    if (!get_block_hashing_blob(b, bd)) {
      return false;
    }
  } else if (b.majorVersion == BLOCK_MAJOR_VERSION_2 || b.majorVersion == BLOCK_MAJOR_VERSION_3) {
    if (!get_parent_block_hashing_blob(b, bd)) {
      return false;
    }
  } else {
    return false;
  }
  cn_slow_hash(context, bd.data(), bd.size(), res);
  return true;
}
bool get_block_longhash(crypto::cn_context &context, const Block& b, crypto::hash& res) {
  blobdata bd;
  if (b.majorVersion == BLOCK_MAJOR_VERSION_1) {
    if (!get_block_hashing_blob(b, bd)) {
      return false;
    }
  } else if (b.majorVersion == BLOCK_MAJOR_VERSION_2) {
    if (!get_parent_block_hashing_blob(b, bd)) {
      return false;
    }
  } else {
    return false;
  }
  crypto::cn_slow_hash(context, bd.data(), bd.size(), res);
  return true;
}
bool get_block_hash(const Block& b, crypto::hash& res) {
  blobdata blob;
  if (!get_block_hashing_blob(b, blob)) {
    return false;
  }

  if (BLOCK_MAJOR_VERSION_2 <= b.majorVersion) {
    blobdata parent_blob;
    auto serializer = makeParentBlockSerializer(b, true, false);
    if (!t_serializable_object_to_blob(serializer, parent_blob))
      return false;

    blob.append(parent_blob);
  }

  return get_object_hash(blob, res);
}
bool get_block_hash(const Block& b, Hash& res) {
  BinaryArray ba;
  if (!get_block_hashing_blob(b, ba)) {
    return false;
  }

  // The header of block version 1 differs from headers of blocks starting from v.2
  if (BLOCK_MAJOR_VERSION_2 == b.majorVersion || BLOCK_MAJOR_VERSION_3 == b.majorVersion) {
    BinaryArray parent_blob;
    auto serializer = makeParentBlockSerializer(b, true, false);
    if (!toBinaryArray(serializer, parent_blob))
      return false;

    ba.insert(ba.end(), parent_blob.begin(), parent_blob.end());
  }

  return getObjectHash(ba, res);
}