func (h *handler) PutBlock(ctx context.Context, req *models.PutBlockRequest) (*models.PutResponse, error) {
	for i, ref := range req.Refs {
		err := h.handle.PutBlock(ctx, torus.BlockFromProto(ref), req.Blocks[i])
		if err != nil {
			return nil, err
		}
	}
	return &models.PutResponse{Ok: true}, nil
}
func (h *handler) Block(ctx context.Context, req *models.BlockRequest) (*models.BlockResponse, error) {
	data, err := h.handle.Block(ctx, torus.BlockFromProto(req.BlockRef))
	if err != nil {
		return nil, err
	}
	return &models.BlockResponse{
		Ok:   true,
		Data: data,
	}, nil
}
func (g *mockBlockGRPC) RebalanceCheck(ctx context.Context, req *models.RebalanceCheckRequest) (*models.RebalanceCheckResponse, error) {
	out := make([]bool, len(req.BlockRefs))
	for i, x := range req.BlockRefs {
		p := torus.BlockFromProto(x)
		if p.INode%2 == 1 {
			out[i] = true
		}
	}
	return &models.RebalanceCheckResponse{
		Valid: out,
	}, nil
}
func (h *handler) RebalanceCheck(ctx context.Context, req *models.RebalanceCheckRequest) (*models.RebalanceCheckResponse, error) {
	check := make([]torus.BlockRef, len(req.BlockRefs))
	for i, x := range req.BlockRefs {
		check[i] = torus.BlockFromProto(x)
	}
	out, err := h.handle.RebalanceCheck(ctx, check)
	if err != nil {
		return nil, err
	}
	return &models.RebalanceCheckResponse{
		Valid: out,
	}, nil
}
func (g *mockBlockGRPC) PutBlock(ctx context.Context, req *models.PutBlockRequest) (*models.PutResponse, error) {
	ref := torus.BlockFromProto(req.Refs[0])
	if ref.INode != 2 && ref.Index != 3 {
		return &models.PutResponse{
			Err: "bad ref",
		}, nil
	}
	if bytes.Equal(g.data, req.Blocks[0]) {
		return &models.PutResponse{
			Ok: true,
		}, nil
	}
	return &models.PutResponse{
		Err: "mismatch",
	}, nil
}